mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
59eb245a1c
The specs and QA markdowns had drifted from the demos they describe.
This commit brings every test contract into line with the actual demo
source — eliminating false-greens, false-fails, and stale assertions.
False-fail spec assertions (would fail every run):
- `agentic-chat.spec.ts` — rewrote from the old `change_background` /
`weather-card` / `useAgentContext` flow that no longer exists. New
spec exercises the vanilla `<CopilotChat>` + three suggestion pills
contract the simplified demo actually exposes.
- `gen-ui-tool-based.spec.ts` — asserted on UI text ("Use the sidebar
to generate charts", "Chart Generator") that doesn't exist; switched
to suggestion-pill assertions and scoped the SVG check to inside the
assistant-message bubble (was matching CopilotChat's send-button
SVG).
- `agent-config.spec.ts` — asserted heading "Agent Config Object" but
the demo has "Agent Config".
- `multimodal.spec.ts` — asserted a non-existent "Multimodal
attachments" heading; switched to the `multimodal-demo-root` testid.
- `chat-slots.spec.ts` — asserted `[data-testid="custom-assistant-
message"]` and the bare text "slot" — neither exists. The actual
signal is `data-slot-label="MessageView.AssistantMessage"` from the
SlotMarker wrapper.
- `reasoning-default.spec.ts` — asserted `[data-testid="copilot-
reasoning-message"]` and `[data-message-role="reasoning"]`; neither
is emitted by `CopilotChatReasoningMessage`. Switched to the text-
based "Thinking…/Thought for…" header label.
False-green spec assertions (passed for the wrong reason):
- `shared-state-read.spec.ts` — was a complete false-green: asserted
on "Sales Pipeline", "Total Pipeline", "Active Deals" but the demo
has been a Recipe Editor for some time. Rewrote against the
recipe-card / ingredients-container / instructions-container testids.
- 11 specs (agent-config, beautiful-chat, frontend-tools-async,
gen-ui-tool-based, gen-ui-agent, gen-ui-interrupt, hitl-in-chat,
hitl-in-app, multimodal, readonly-state-agent-context, voice) used
`[data-role="assistant"]` to gate "agent responded" — but the v2
react-core bundle never emits that attribute (it ships
`data-testid="copilot-assistant-message"`). Mechanical sweep to the
correct testid.
- Deleted `shared-state-write.spec.ts` (route consolidated into
`shared-state-read-write` earlier on this branch — spec targeted a
removed demo) and `renderer-selector.spec.ts` (asserted on a radio-
pill UI that no longer exists; the four "Declarative UI" variants
are now separate manifest demos).
QA drift:
- `qa/gen-ui-tool-based.md` documented a "Haiku Generator" demo with
haiku-card / japanese-line / english-line / haiku-image testids — a
demo that doesn't exist anywhere on this branch. Rewrote to match
the chart-rendering demo's actual testids and pill prompts.
- `qa/chat-slots.md` referenced "Custom Slot" pill / "Welcome to the
Slots demo" heading / "This welcome card is rendered via the
welcomeScreen slot." body text — all of which the slot-wrappers
refactor on this branch removed. Updated to match the
`custom-welcome-message` sub-slot that's actually rendered. Also
fixed max-w-4xl → max-w-5xl to match the page.
- `qa/shared-state-read.md` said default instruction is "Preheat oven
to 350 F" but the source has "Preheat oven to 350°F (175°C)".
- `qa/agentic-chat.md` rewrote to match the simplified vanilla-chat
demo (the previous QA documented `change_background` / `WeatherCard`
flows that no longer exist).
- `qa/reasoning-default.md` cited `kind: "testing"` in feature-
registry.json for the `reasoning-default` entry; the registry entry
has no `kind` field. Rewrote without the false cross-file claim.
- Deleted 4 orphan QA files for demos that don't exist:
`agentic-chat-reasoning.md`, `hitl.md`, `hitl-in-chat-booking.md`,
`shared-state-write.md`.
- Renamed `qa/reasoning-default-render.md` → `qa/reasoning-default.md`
to match the manifest cell name.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
116 lines
4.3 KiB
TypeScript
116 lines
4.3 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
|
|
// Each custom slot wraps the default in a `SlotMarker` that emits
|
|
// `data-slot-label="<slot-path>"`. That attribute is the canonical
|
|
// signal that a slot override wired through end-to-end (the welcome
|
|
// screen + disclaimer also expose dedicated `data-testid` attributes
|
|
// for ergonomics).
|
|
const SLOT_LABEL_ASSISTANT = '[data-slot-label="MessageView.AssistantMessage"]';
|
|
|
|
test.describe("Chat Slots", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto("/demos/chat-slots");
|
|
});
|
|
|
|
test("custom welcome screen slot renders on first load", async ({ page }) => {
|
|
// The custom welcomeScreen slot replaces the default welcome. Both its
|
|
// own testid and the nested welcomeMessage sub-slot's testid prove the
|
|
// override wired through end-to-end. Asserting both catches accidental
|
|
// fallback to the default CopilotChat welcome.
|
|
const welcome = page.locator('[data-testid="custom-welcome-screen"]');
|
|
await expect(welcome).toBeVisible();
|
|
|
|
await expect(
|
|
welcome.locator('[data-testid="custom-welcome-message"]'),
|
|
).toBeVisible();
|
|
});
|
|
|
|
test("both suggestion pills render with verbatim titles", async ({
|
|
page,
|
|
}) => {
|
|
// useConfigureSuggestions registers exactly two pills with available: "always".
|
|
// Both should be visible immediately on the welcome screen.
|
|
await expect(
|
|
page
|
|
.locator('[data-testid="copilot-suggestion"]')
|
|
.filter({ hasText: "Write a sonnet" }),
|
|
).toBeVisible({ timeout: 15000 });
|
|
|
|
await expect(
|
|
page
|
|
.locator('[data-testid="copilot-suggestion"]')
|
|
.filter({ hasText: "Tell me a joke" }),
|
|
).toBeVisible({ timeout: 15000 });
|
|
});
|
|
|
|
test('clicking "Tell me a joke" shows the custom assistant message slot', async ({
|
|
page,
|
|
}) => {
|
|
// Click the suggestion pill — this sends "Tell me a short joke." The
|
|
// assistant responds with text (neutral agent, no tools), and its
|
|
// bubble must be wrapped in the CustomAssistantMessage SlotMarker.
|
|
await page
|
|
.locator('[data-testid="copilot-suggestion"]')
|
|
.filter({ hasText: "Tell me a joke" })
|
|
.first()
|
|
.click();
|
|
|
|
// The MessageView.AssistantMessage slot-marker wraps every assistant
|
|
// bubble; its presence proves the slot override took effect rather
|
|
// than the default CopilotChatAssistantMessage rendering bare.
|
|
await expect(page.locator(SLOT_LABEL_ASSISTANT).first()).toBeVisible({
|
|
timeout: 45000,
|
|
});
|
|
});
|
|
|
|
test("custom disclaimer slot renders after the first user message", async ({
|
|
page,
|
|
}) => {
|
|
// Type and send via the send button — Enter-on-textarea was intermittently
|
|
// dropping the submit on this deployment. We assert the disclaimer +
|
|
// custom assistant wrapper appear once we transition out of the welcome
|
|
// state.
|
|
const input = page.getByPlaceholder("Type a message");
|
|
await input.fill("Hello");
|
|
await page.locator('[data-testid="copilot-send-button"]').first().click();
|
|
|
|
// Assistant replies and is wrapped in the custom slot.
|
|
await expect(page.locator(SLOT_LABEL_ASSISTANT).first()).toBeVisible({
|
|
timeout: 45000,
|
|
});
|
|
|
|
// The custom disclaimer slot lives below the input on the post-welcome
|
|
// chat view. The welcome-screen state hides it; once the assistant
|
|
// responds the welcome is gone and the disclaimer should be visible.
|
|
await expect(page.locator('[data-testid="custom-disclaimer"]')).toBeVisible(
|
|
{ timeout: 10000 },
|
|
);
|
|
});
|
|
|
|
test("second assistant turn is also wrapped in the custom slot", async ({
|
|
page,
|
|
}) => {
|
|
const input = page.getByPlaceholder("Type a message");
|
|
const sendBtn = () =>
|
|
page.locator('[data-testid="copilot-send-button"]').first();
|
|
|
|
// Turn 1
|
|
await input.fill("Hi");
|
|
await sendBtn().click();
|
|
await expect(page.locator(SLOT_LABEL_ASSISTANT).first()).toBeVisible({
|
|
timeout: 45000,
|
|
});
|
|
|
|
// Turn 2 — the slot should wrap every assistant turn, not just the first.
|
|
await input.fill("Say something short");
|
|
await sendBtn().click();
|
|
|
|
// Expect at least two custom-wrapped assistant messages.
|
|
await expect
|
|
.poll(async () => await page.locator(SLOT_LABEL_ASSISTANT).count(), {
|
|
timeout: 45000,
|
|
})
|
|
.toBeGreaterThanOrEqual(2);
|
|
});
|
|
});
|