From b7d51b93e0aff0920c049594725d9678df9b50b3 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 27 Oct 2026 20:13:35 -0500 Subject: [PATCH] fix(aggregator): a rejected restore no longer cancels its target (#1474) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cancelledActionIds cancelled a restore supersedes target for any non-superseded restore, including one the consumer REJECTED — so a dismissed/snoozed/acked card resurfaced even though the restore never took effect, contradicting the module contract that rejections are non-effective (every other verb family already excludes rejected). Exclude state === rejected from cancelling, and add regression tests: rejected restore of a dismiss (suppression stands, dismiss stays in effectiveActions), of a snooze (still snoozed), of an ack (still acked), plus an applied restore still cancelling. --- pm-stack/aggregator/src/card-state.ts | 8 +-- .../test/dashboard-overhaul.test.ts | 53 ++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/pm-stack/aggregator/src/card-state.ts b/pm-stack/aggregator/src/card-state.ts index 02c1bb892b..8d15df69fb 100644 --- a/pm-stack/aggregator/src/card-state.ts +++ b/pm-stack/aggregator/src/card-state.ts @@ -48,12 +48,14 @@ export interface CardState { answeredOptionId?: string; } -/** Ids cancelled by a restore: any non-superseded restore action - * cancels the action it names in `supersedes`. */ +/** Ids cancelled by a restore: any non-superseded, non-rejected + * restore action cancels the action it names in `supersedes` + * (a consumer rejection is non-effective, as for every other verb). */ export function cancelledActionIds(actions: DashAction[]): Set { const out = new Set(); for (const a of actions) { - if (a.verb === "restore" && a.state !== "superseded" && a.supersedes) out.add(a.supersedes); + if (a.verb === "restore" && a.state !== "superseded" && a.state !== "rejected" && a.supersedes) + out.add(a.supersedes); } return out; } diff --git a/pm-stack/aggregator/test/dashboard-overhaul.test.ts b/pm-stack/aggregator/test/dashboard-overhaul.test.ts index b323a6d659..131481aea4 100644 --- a/pm-stack/aggregator/test/dashboard-overhaul.test.ts +++ b/pm-stack/aggregator/test/dashboard-overhaul.test.ts @@ -6,7 +6,7 @@ // and the Needs-you order is a saved preference. import { describe, expect, test } from "bun:test"; import { validateNewAction, type DashAction } from "../src/actions.ts"; -import { cardState } from "../src/card-state.ts"; +import { cardState, effectiveActions } from "../src/card-state.ts"; import { buildAttention } from "../src/derive.ts"; import type { OrchestrationSection, TierItem } from "../src/model.ts"; import { STANDING_IDENTITIES } from "../src/registry.ts"; @@ -127,6 +127,57 @@ describe("card-state derivation (#1443/#1450)", () => { expect(cs.suppressed).toBeNull(); expect(cs.pending.map((a) => a.verb)).toContain("restore"); }); + test("a REJECTED restore does NOT cancel its target — the dismissal stands (#1474)", () => { + const dismiss = mkAction({ id: "da-dismiss", verb: "dismiss", state: "applied", payload: { reason: "x" } }); + const restore = mkAction({ + id: "da-restore", + verb: "restore", + state: "rejected", + supersedes: "da-dismiss", + createdAt: iso(NOW), + }); + const cs = cardState([dismiss, restore], NOW); + expect(cs.suppressed?.kind).toBe("dismissed"); + expect(effectiveActions([dismiss, restore]).map((a) => a.id)).toContain("da-dismiss"); + }); + test("a REJECTED restore of a snooze leaves the card snoozed (#1474)", () => { + const snooze = mkAction({ + id: "da-snooze", + verb: "snooze", + state: "applied", + payload: { until: iso(NOW + 3_600_000) }, + }); + const restore = mkAction({ + id: "da-restore", + verb: "restore", + state: "rejected", + supersedes: "da-snooze", + createdAt: iso(NOW), + }); + expect(cardState([snooze, restore], NOW).suppressed?.kind).toBe("snoozed"); + }); + test("a REJECTED restore of an ack leaves the card acked (#1474)", () => { + const ack = mkAction({ id: "da-ack", verb: "acknowledge", state: "applied" }); + const restore = mkAction({ + id: "da-restore", + verb: "restore", + state: "rejected", + supersedes: "da-ack", + createdAt: iso(NOW), + }); + expect(cardState([ack, restore], NOW).acked).toBe(true); + }); + test("an APPLIED restore still cancels its target (#1474)", () => { + const dismiss = mkAction({ id: "da-dismiss", verb: "dismiss", state: "applied", payload: { reason: "x" } }); + const restore = mkAction({ + id: "da-restore", + verb: "restore", + state: "applied", + supersedes: "da-dismiss", + createdAt: iso(NOW), + }); + expect(cardState([dismiss, restore], NOW).suppressed).toBeNull(); + }); test("survey answers merge across submits, latest per question wins (#1451)", () => { const a1 = mkAction({ verb: "answer",