diff --git a/pm-stack/aggregator/src/actions.ts b/pm-stack/aggregator/src/actions.ts index 2557aad71c..f8d7ed445b 100644 --- a/pm-stack/aggregator/src/actions.ts +++ b/pm-stack/aggregator/src/actions.ts @@ -136,7 +136,7 @@ export const VERBS_BY_KIND: Record = }; const ACTION_KINDS = new Set(["triage", "status-request", "session", "preference"]); -const ACTION_STATES = new Set(["new", "applied", "rejected", "superseded"]); +export const ACTION_STATES = new Set(["new", "applied", "rejected", "superseded"]); function actionRecordProblem(value: unknown): string | null { if (!isRecord(value)) return "record must be an object"; diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index 48215ec2cf..88df1203df 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -10,7 +10,7 @@ import { stat } from "node:fs/promises"; import { createQuotaRefresher, systemdTrigger } from "./quota-refresh.ts"; import { decodePathSegment } from "./path-segment.ts"; import { errorBoundaryResponse, notFoundResponse } from "./error-boundary.ts"; -import { ActionsStore, validateNewAction, type DashAction } from "./actions.ts"; +import { ACTION_STATES, ActionsStore, validateNewAction, type DashAction } from "./actions.ts"; import { checkActionAgainstItem, effectiveNeedsOrder, @@ -1352,10 +1352,19 @@ async function handler(req: Request): Promise { const object = url.searchParams.get("object"); const kind = url.searchParams.get("kind"); const state = url.searchParams.get("state"); + // #4620: state=all is the explicit all-history read (audit and + // retrospective consumers). It must not fall through to the literal + // state filter, which silently returned an empty list while the + // store held applied/rejected history — a false zero. Any other + // value that is not a real action state is a 400, never an empty + // list, so a mistyped filter cannot masquerade as "no history". + if (state && state !== "all" && !ACTION_STATES.has(state)) { + return json({ error: `state must be one of: all, ${[...ACTION_STATES].join(", ")}` }, 400); + } let list = await actionsStore.all(); if (object) list = list.filter((a) => a.objectRef === object); if (kind) list = list.filter((a) => a.kind === kind); - if (state) list = list.filter((a) => a.state === state); + if (state && state !== "all") list = list.filter((a) => a.state === state); return json({ actions: list, pending: await actionsStore.pendingCounts() }); } diff --git a/pm-stack/aggregator/test/actions.test.ts b/pm-stack/aggregator/test/actions.test.ts index f22e1f6498..c230024d98 100644 --- a/pm-stack/aggregator/test/actions.test.ts +++ b/pm-stack/aggregator/test/actions.test.ts @@ -770,6 +770,40 @@ describe("actions HTTP round-trip (fixture consumer)", () => { expect((await post("/api/actions", { ...body, clientToken: "ct-http-bad-2", author: undefined })).status).toBe(400); }); + test("/api/actions.json?state=all returns applied history; unknown state 400s (#4620)", async () => { + const body = { + clientToken: "ct-http-state-all-1", + kind: "triage", + verb: "acknowledge", + objectRef: "orch:state-all-item", + author: drew, + payload: {}, + }; + const created = await post("/api/actions", body); + expect(created.status).toBe(201); + const { action } = (await created.json()) as { action: DashAction }; + const result = await post("/api/actions/result", { + id: action.id, + outcome: "applied", + byRun: "orch-fixture-state-all", + note: "applied for the #4620 history-read regression test", + }); + expect(result.status).toBe(200); + + const listFor = async (qs: string) => + ((await (await fetch(`http://127.0.0.1:${port}/api/actions.json?${qs}`)).json()) as { actions: DashAction[] }) + .actions.map((a) => a.id); + + // The regression: state=all must return the applied record, not []. + expect(await listFor("state=all")).toContain(action.id); + // Concrete history states return history too. + expect(await listFor("state=applied")).toContain(action.id); + // state=new behaviour is unchanged: the applied record is not pending. + expect(await listFor("state=new")).not.toContain(action.id); + // An unknown state is a 400, never a silent false zero. + expect((await fetch(`http://127.0.0.1:${port}/api/actions.json?state=bogus`)).status).toBe(400); + }); + test("duplicate answer response includes the persisted audit pointer", async () => { const body = { clientToken: "ct-session-answer-1",