mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-06-10 01:15:58 +00:00
799bef6d9d
* fix(replay-e2e): match by conversation, not the living system prompt The model-replay match key hashed the full input including the lead-agent system prompt. That prompt is edited frequently (e.g. #3195 added a "File Editing Workflow" section), so the committed fixture went stale the moment the prompt changed on main — turning the Layer-2 render gate RED on every unrelated PR (#3430, #3432, ...). This was a self-inflicted false positive. Root-cause fix: - replay_provider._canonical_messages now EXCLUDES the system message from the hash. The conversation (human/ai/tool) is the stable contract that identifies a recorded turn; the system prompt is an internal detail not part of the front-back contract under test. (Mirrors how open-design keys its mock picker on the user prompt, not the system internals.) Proven robust: injecting a prompt edit no longer causes a replay miss. - Layer-1 golden was BLIND to replay misses: the gateway swallows a miss into an assistant error message, so the shape-only golden stayed green on a stale fixture. It now inspects replay_provider.replay_misses() and fails loud. (Layer-2 already fails on a miss.) - Re-recorded write_read_file.ultra fixture + regenerated golden under the new conversation-only hash. - Layer-2 render spec: assert the in-graph auto-title (deterministic); the follow-up suggestion is fired async and depends on a clean JSON model output, so assert it only when the fixture captured one — never gate on its absence (recording flakiness must not block CI). - docs: REPLAY_E2E.md updated. Verified: Layer-1 golden green (no miss), Layer-2 both specs green, CI=true make test 4033 passed / 0 failed, frontend pnpm check clean. * test(replay-e2e): restore suggestions coverage with a reliable capture Addresses review feedback (the suggestion path was dropped from Layer-2): - record spec now waits for the `/suggestions` response before checking capture stability, so the recorded fixture reliably includes the frontend-fired suggestions turn (previously the stability window could return before suggestions fired, yielding a fixture without it). - Re-recorded write_read_file.ultra: 5 turns (write_file, auto-title, read_file, answer, suggestions). Golden unchanged — suggestions is a separate /suggestions call, not part of the /runs/stream SSE sequence. - Layer-2 spec: restore the hard `EXPECTED_SUGGESTION` assertion. With the record spec now waiting for /suggestions, a fixture missing the suggestion turn means a broken recording and must fail loud, not pass silently. Verified: Layer-1 golden green (no miss), Layer-2 both specs green (auto-title + suggestion render), frontend pnpm check clean. * ci: re-trigger (flaky Docker Hub image pull in sandbox e2e, unrelated) backend-unit-tests failed only in test_sandbox_orphan_reconciliation_e2e.py with 'docker pull busybox:latest ... context deadline exceeded' — a CI-runner network flake reaching Docker Hub, not related to this docs/tests-only change. Empty commit to re-run CI. --------- Co-authored-by: DanielWalnut <45447813+hetaoBackend@users.noreply.github.com>
128 lines
5.1 KiB
TypeScript
128 lines
5.1 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
|
|
/**
|
|
* Layer 2: drive the REAL frontend against the REAL gateway (replay model, no
|
|
* API key) and assert the browser renders the backend's data correctly.
|
|
*
|
|
* The prompt is read from the same fixture the gateway replays, so the input
|
|
* hash matches and the recorded turns (write_file -> auto-title -> read_file ->
|
|
* final answer) reproduce deterministically.
|
|
*/
|
|
// Register through the frontend origin (same-origin proxy) so the auth cookies
|
|
// are stored for and sent to localhost:3000 — the gateway is reached via the
|
|
// next.config rewrite, never cross-origin from the browser.
|
|
const APP = "http://localhost:3000";
|
|
const fixture = JSON.parse(
|
|
readFileSync(
|
|
join(
|
|
here,
|
|
"../../../backend/tests/fixtures/replay/write_read_file.ultra.json",
|
|
),
|
|
"utf-8",
|
|
),
|
|
) as {
|
|
prompt: string;
|
|
turns: Array<{ output: { data: { content?: unknown } } }>;
|
|
};
|
|
|
|
const PROMPT = fixture.prompt;
|
|
// Derive the assertions from the fixture so a re-record auto-updates them. Both
|
|
// are model-generated strings absent from the user prompt, so a pass proves the
|
|
// replay drove the render (not a prompt echo): the first plain-text turn is the
|
|
// in-graph auto-title; the JSON-array turn is the follow-up suggestions.
|
|
const textTurns = fixture.turns
|
|
.map((t) => t.output?.data?.content)
|
|
.filter((c): c is string => typeof c === "string" && c.trim().length > 0);
|
|
const suggestionsRaw = textTurns.find((c) => c.trim().startsWith("["));
|
|
// Guarded parse: a bracket-prefixed turn that isn't a valid JSON string array
|
|
// falls back to "" so the `not.toBe("")` assertion below fails with a clear
|
|
// message instead of a generic JSON.parse throw.
|
|
const EXPECTED_SUGGESTION = ((): string => {
|
|
if (!suggestionsRaw) return "";
|
|
try {
|
|
const arr: unknown = JSON.parse(suggestionsRaw);
|
|
return Array.isArray(arr) && typeof arr[0] === "string" ? arr[0] : "";
|
|
} catch {
|
|
return "";
|
|
}
|
|
})();
|
|
const EXPECTED_TITLE = textTurns.find((c) => !c.trim().startsWith("[")) ?? "";
|
|
|
|
test.describe("real backend render (replay, no API key)", () => {
|
|
test.beforeEach(async ({ context }) => {
|
|
// Throwaway test account: register sets access_token + csrf_token cookies in
|
|
// the browser context (host-scoped to localhost, shared across ports), so
|
|
// the frontend's SDK (credentials:include + X-CSRF-Token) authenticates.
|
|
const email = `e2e-${Date.now()}-${Math.floor(Math.random() * 1e6)}@example.com`;
|
|
const resp = await context.request.post(`${APP}/api/v1/auth/register`, {
|
|
data: { email, password: "very-strong-password-123" },
|
|
});
|
|
expect(resp.status(), await resp.text()).toBe(201);
|
|
});
|
|
|
|
test("renders the replayed auto-title + suggestions from a real backend", async ({
|
|
page,
|
|
}) => {
|
|
// ultra mode so the context the frontend sends (is_plan_mode + subagent_enabled)
|
|
// matches the recorded fixture; otherwise the replay input hash would miss.
|
|
await page.addInitScript(() => {
|
|
window.localStorage.setItem(
|
|
"deerflow.local-settings",
|
|
JSON.stringify({ context: { mode: "ultra" } }),
|
|
);
|
|
});
|
|
|
|
await page.goto("/workspace/chats/new");
|
|
|
|
const textarea = page.getByPlaceholder(/how can i assist you/i);
|
|
await expect(textarea).toBeVisible({ timeout: 30_000 });
|
|
await textarea.fill(PROMPT);
|
|
await textarea.press("Enter");
|
|
|
|
// Replay-only DOM assertions (derived from the fixture): both are
|
|
// model-generated strings absent from the user prompt, so they render only if
|
|
// the recorded turns replayed AND the real frontend rendered them — the
|
|
// in-graph auto-title and the post-answer follow-up suggestion. Together they
|
|
// prove the whole pipeline (replay backend -> real frontend render). The
|
|
// record spec waits for the /suggestions response, so a re-recorded fixture
|
|
// always captures the suggestion turn — a missing one is a broken recording
|
|
// and must fail loud here, not pass silently.
|
|
expect(
|
|
EXPECTED_TITLE,
|
|
"fixture should contain an auto-title turn",
|
|
).not.toBe("");
|
|
expect(
|
|
EXPECTED_SUGGESTION,
|
|
"fixture should contain a suggestions turn (re-record; the record spec waits for /suggestions)",
|
|
).not.toBe("");
|
|
await expect(page.getByText(EXPECTED_TITLE)).toBeVisible({
|
|
timeout: 60_000,
|
|
});
|
|
await expect(page.getByText(EXPECTED_SUGGESTION)).toBeVisible({
|
|
timeout: 30_000,
|
|
});
|
|
|
|
// Visual regression is OS-sensitive (a macOS baseline won't match CI's
|
|
// Linux render), so it's a local dev gate only; in CI we capture the render
|
|
// as an artifact for human review instead of hard-asserting a cross-OS
|
|
// baseline. The DOM assertions above are the CI gate.
|
|
if (process.env.CI) {
|
|
await page.screenshot({
|
|
path: "test-results/real-backend-render.png",
|
|
fullPage: true,
|
|
});
|
|
} else {
|
|
await expect(page).toHaveScreenshot("real-backend-render.png", {
|
|
maxDiffPixelRatio: 0.02,
|
|
fullPage: true,
|
|
});
|
|
}
|
|
});
|
|
});
|