Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pm-stack/aggregator/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const VERBS_BY_KIND: Record<DashActionKind, readonly DashActionVerb[]> =
};

const ACTION_KINDS = new Set<DashActionKind>(["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";
Expand Down
13 changes: 11 additions & 2 deletions pm-stack/aggregator/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1352,10 +1352,19 @@ async function handler(req: Request): Promise<Response> {
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() });
}

Expand Down
34 changes: 34 additions & 0 deletions pm-stack/aggregator/test/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading