test(e2e): cover prompt-history recall end to end

A14 (API) and B15 (browser) make the feature verifiable against a real daemon,
a real headless nvim and a real `pi`.

- A14: the prompt A4 sent through `prompt.send` is in the plugin's archive
  exactly once — the console → daemon → plugin → daemon → console round trip, and
  the guard for "a web send is recorded at all"; `?limit=1` answers the newest
  entry; a freshly added workspace with no instance answers
  `{live:false, supported:false, entries:[]}` and its `/workspaces` row still
  reports `instance: null`, which is the no-spawn rule a keystroke depends on
- B15: wipes the browser mirror, reloads, checks the console fetched
  `/prompt-history`, walks ↑ back to the prompt B6 sent, walks ↓ out to the empty
  draft, recalls with Ctrl+P from a mid-line caret, and asserts that browsing
  never sends anything
- `docs/e2e.md` documents both (A0–A14, B1–B15)

Attribution done while landing this: with the plugin change stashed, A14 fails
(the capability is absent) while A5 reproduces identically and B1/B2/B3/B9/B13
fail the same way — pre-existing, not this feature. A5 is the coalesced
`text_delta` after `agent_settled` the suite already lists as a suspected
product bug; A11 is model-dependent and passed on the rerun.
This commit is contained in:
yuez committed 2026-11-02 11:13:37 +08:00
1 parent b8f1fca5bd
commit ce87799b61
3 files changed
+220 -7

No files matched your search

+97
View File
@@ -597,6 +597,8 @@ function deviation(key, title, detail, scenarioId) {
const state = {
w1: null,
w2: null,
/** A workspace that must stay un-spawned (A14's live-only prompt-history read). */
w3: null,
sid: null, // backend session id of the W1 session
sidTmp: null, // placeholder id returned by session.create
sessionFile: null,
@@ -606,6 +608,8 @@ const state = {
childId: null,
routedWithWorkspace: false,
attentionFile: null,
/** A4 landed a `prompt.send`, so the plugin archive must hold that text. */
promptSent: false,
};
// ---------------------------------------------------------------------------
@@ -631,6 +635,25 @@ async function sessionsList(workspaceId) {
return { res, rows: rows ?? [] };
}
/**
* `GET /workspaces/:id/prompt-history` — the composer's ↑/↓ feed
* (`docs/protocol.md` §3.1.1). `query` is appended verbatim, so a caller can pass
* `"?limit=1"` without a second helper.
*/
async function promptHistory(workspaceId, query = "") {
const res = await http("GET", `/api/v1/workspaces/${workspaceId}/prompt-history${query}`, {
token: CLI_TOKEN,
});
const body = res.json ?? {};
return {
res,
body,
live: body.live,
supported: body.supported,
entries: Array.isArray(body.entries) ? body.entries : null,
};
}
async function addWorkspace(name, ctx) {
const cwd = join(WORKSPACE_ROOTS, name);
mkdirSync(cwd, { recursive: true });
@@ -1406,6 +1429,8 @@ scenario("A4", "Prompt + streaming (real model)", async (ctx) => {
observed: apiError(send),
});
if (send.status !== 202) return;
// A14 reads this prompt back out of the plugin's archive.
state.promptSent = true;
let settled;
try {
@@ -3023,6 +3048,78 @@ scenario("A13", "Console login handoff", async (ctx) => {
ctx.eq("the new token works → 200", freshToken.status, 200);
});
// ---------------------------------------------------------------------------
// A14 — prompt history recall (the composer's ↑/↓)
// ---------------------------------------------------------------------------
scenario("A14", "Prompt history recall", async (ctx) => {
if (!state.w1) skip("A1 did not produce a workspace id");
if (!state.promptSent) skip("A4 did not send a prompt");
// The read behind the composer's ↑/↓. A4 sent PONG_PROMPT through
// `prompt.send`, and only the plugin can answer this — the daemon stores
// nothing — so a hit here is the whole round trip proven:
// browser → daemon → plugin archive → daemon → browser.
const full = await promptHistory(state.w1);
ctx.eq("GET /workspaces/:id/prompt-history → 200", full.res.status, 200);
ctx.eq("the read is versioned (v=1)", full.body.v, 1);
ctx.eq("workspaceId is echoed", full.body.workspaceId, state.w1);
ctx.eq("a connected plugin answers the read", full.live, true);
ctx.eq("the plugin advertises the promptHistory capability", full.supported, true);
ctx.check("entries is a string[]", full.entries !== null, {
expected: "entries: string[]",
observed: fmt(full.body, 300),
});
const entries = full.entries ?? [];
const hits = entries.filter((entry) => entry === PONG_PROMPT).length;
ctx.check("the prompt sent from the console was recorded by the plugin, exactly once", hits === 1, {
expected: `"${PONG_PROMPT}" ×1`,
observed: { hits, total: entries.length, tail: entries.slice(-3) },
});
// `limit` trims from the newest end: the plugin's archive is oldest-first, so
// a recall feed asks for the tail.
const one = await promptHistory(state.w1, "?limit=1");
ctx.eq("?limit=1 → 200", one.res.status, 200);
const single = one.entries ?? [];
ctx.check("?limit=1 answers exactly one entry", single.length === 1, {
expected: 1,
observed: single.length,
});
ctx.eq("?limit=1 is the newest archived prompt", single[0], entries.at(-1));
// A workspace with no connected plugin answers `live:false` **without
// spawning**: recall is a convenience, never a lifecycle event. This is the
// assertion that would catch `instances.ensure()` creeping back into the read.
const cold = await addWorkspace("w3-history", ctx);
state.w3 = cold.workspaceId;
const coldRead = await promptHistory(state.w3);
ctx.eq("a workspace with no instance still answers 200", coldRead.res.status, 200);
ctx.eq("…with live:false", coldRead.live, false);
ctx.eq("…with supported:false", coldRead.supported, false);
ctx.check("…and no entries", coldRead.entries !== null && coldRead.entries.length === 0, {
expected: "entries: []",
observed: fmt(coldRead.body, 200),
});
const coldRow = await workspaceRow(state.w3);
ctx.check("the cold read did not spawn an instance", (coldRow?.instance ?? null) === null, {
expected: "instance: null",
observed: coldRow?.instance ?? null,
});
const coldAgain = await promptHistory(state.w3);
ctx.eq("a second cold read is equally idle", coldAgain.live, false);
const unknown = await promptHistory("0123456789abcdef");
ctx.eq("an unknown workspace → 404", unknown.res.status, 404);
ctx.evidence.promptHistory = {
workspaceId: state.w1,
archived: entries.length,
newest: entries.at(-1)?.slice(0, 80),
coldWorkspace: state.w3,
};
});
// ---------------------------------------------------------------------------
// reporting
// ---------------------------------------------------------------------------