From df74a6b752bb66cc532638731dbd5ca586339988 Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Tue, 9 Jun 2026 03:53:34 -0700 Subject: [PATCH] FN-6050: stop re-emitting existing mission advisories Treat previously recorded unlinked-mission advisories as authoritative across insight states. - remove the generated-only insight filter when checking for an existing unlinked mission advisory - suppress duplicate advisories even when the existing insight is dismissed, archived, or confirmed - expand reporter coverage to assert the broader duplicate-detection behavior and insight query shape Files changed: .../unlinked-missions-advisory-reporter.test.ts | 49 +++++++++++++--------- .../src/unlinked-missions-advisory-reporter.ts | 1 - 2 files changed, 29 insertions(+), 21 deletions(-) Fusion-Task-Id: FN-6050 Fusion-Task-Lineage: 5b9274f7-baf6-40c1-8a88-2fcc86c7ef14 --- ...nlinked-missions-advisory-reporter.test.ts | 47 +++++++++++-------- .../unlinked-missions-advisory-reporter.ts | 1 - 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/packages/engine/src/__tests__/unlinked-missions-advisory-reporter.test.ts b/packages/engine/src/__tests__/unlinked-missions-advisory-reporter.test.ts index 3c555473ac..844a78fdaa 100644 --- a/packages/engine/src/__tests__/unlinked-missions-advisory-reporter.test.ts +++ b/packages/engine/src/__tests__/unlinked-missions-advisory-reporter.test.ts @@ -131,26 +131,35 @@ describe("UnlinkedMissionsAdvisoryReporter", () => { expect(content.missionIds).toEqual(["M-UNLINKED-A", "M-UNLINKED-B"]); }); - it("does not emit a second advisory when an existing advisory insight already exists", async () => { - const insightStore = { - upsertInsight: vi.fn(), - listInsights: vi.fn().mockReturnValue([ - { - title: UNLINKED_MISSIONS_ADVISORY_TITLE, - updatedAt: "2026-06-03T12:00:00.000Z", - provenance: { metadata: { advisoryKey: UNLINKED_MISSIONS_ADVISORY_KEY } }, - }, - ]), - }; - const store = createStore({ - missions: [createMission({ id: "M-UNLINKED" })], - insightStore, - }); - const reporter = new UnlinkedMissionsAdvisoryReporter({ store, projectId: "/tmp/project", logger }); + it.each(["generated", "dismissed", "archived", "confirmed"] as const)( + "does not emit a second advisory when an existing %s advisory insight already exists", + async (status) => { + const insightStore = { + upsertInsight: vi.fn(), + listInsights: vi.fn().mockReturnValue([ + { + title: UNLINKED_MISSIONS_ADVISORY_TITLE, + status, + updatedAt: "2026-06-03T12:00:00.000Z", + provenance: { metadata: { advisoryKey: UNLINKED_MISSIONS_ADVISORY_KEY } }, + }, + ]), + }; + const store = createStore({ + missions: [createMission({ id: "M-UNLINKED" })], + insightStore, + }); + const reporter = new UnlinkedMissionsAdvisoryReporter({ store, projectId: "/tmp/project", logger }); - await expect(reporter.report()).resolves.toEqual({ alerted: false, reason: "already-reported" }); - expect(insightStore.upsertInsight).not.toHaveBeenCalled(); - }); + await expect(reporter.report()).resolves.toEqual({ alerted: false, reason: "already-reported" }); + expect(insightStore.listInsights).toHaveBeenCalledWith({ + projectId: "/tmp/project", + category: "workflow", + limit: 10, + }); + expect(insightStore.upsertInsight).not.toHaveBeenCalled(); + }, + ); it.each([ { projectId: "", throwInsightStore: false }, diff --git a/packages/engine/src/unlinked-missions-advisory-reporter.ts b/packages/engine/src/unlinked-missions-advisory-reporter.ts index 55aa9cc8b2..f6b475768f 100644 --- a/packages/engine/src/unlinked-missions-advisory-reporter.ts +++ b/packages/engine/src/unlinked-missions-advisory-reporter.ts @@ -76,7 +76,6 @@ export class UnlinkedMissionsAdvisoryReporter { const existingInsights = insightStore.listInsights({ projectId: this.projectId, category: "workflow", - status: "generated", limit: 10, }); const existing = existingInsights.find(