From 24266ca1bd30b26835607f40b29355a91ec11cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 1 Aug 2026 11:14:02 +0200 Subject: [PATCH] test(daemon): pin resolveScriptTarget's retention table directly The repair suites pin these rules transitively (they caught the bare-re-arm collapse during the P4a migration), but only through healed-sibling path assertions downstream. A direct table on the transition makes a regression name the retention rule it broke. Refs #1478, #1258 Co-Authored-By: Claude --- .../session-script-publication-state.test.ts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/daemon/__tests__/session-script-publication-state.test.ts diff --git a/src/daemon/__tests__/session-script-publication-state.test.ts b/src/daemon/__tests__/session-script-publication-state.test.ts new file mode 100644 index 000000000..feb119d31 --- /dev/null +++ b/src/daemon/__tests__/session-script-publication-state.test.ts @@ -0,0 +1,57 @@ +import { expect, test } from 'vitest'; +import { armRepair, resolveScriptTarget } from '../session-script-publication-state.ts'; + +// The retention table for the per-target force model (#1258). The repair suites pin these +// transitively through healed-sibling paths; this pins the transition itself, so a regression +// names the rule it broke instead of a downstream path assertion. + +test('a bare re-arm keeps a materialized explicit target and its grant', () => { + const previous = { kind: 'explicit', path: '/flows/a.healed.ad', force: true } as const; + expect(resolveScriptTarget(previous, { force: false })).toEqual(previous); +}); + +test('a bare re-arm with live force adds the grant without touching the path', () => { + expect( + resolveScriptTarget( + { kind: 'explicit', path: '/flows/a.healed.ad', force: false }, + { force: true }, + ), + ).toEqual({ kind: 'explicit', path: '/flows/a.healed.ad', force: true }); +}); + +test('re-arming the same explicit path keeps an existing grant', () => { + expect( + resolveScriptTarget( + { kind: 'explicit', path: '/flows/a.ad', force: true }, + { path: '/flows/a.ad', force: false }, + ), + ).toEqual({ kind: 'explicit', path: '/flows/a.ad', force: true }); +}); + +test('retargeting to a different explicit path without live force drops the grant', () => { + expect( + resolveScriptTarget( + { kind: 'explicit', path: '/flows/a.ad', force: true }, + { path: '/flows/b.ad', force: false }, + ), + ).toEqual({ kind: 'explicit', path: '/flows/b.ad', force: false }); +}); + +test('moving from default to an explicit path keeps the grant (#1258 flagged retention)', () => { + expect( + resolveScriptTarget({ kind: 'default', force: true }, { path: '/flows/out.ad', force: false }), + ).toEqual({ kind: 'explicit', path: '/flows/out.ad', force: true }); +}); + +test('per-step repair re-arms never move the boundary or wipe the healed sibling', () => { + const armed = armRepair( + { kind: 'none' }, + { + requested: { path: '/flows/login.healed.ad', force: false }, + boundary: 3, + sourcePath: '/flows/login.ad', + }, + ); + const rearmed = armRepair(armed, { requested: { force: false }, boundary: 0 }); + expect(rearmed).toEqual(armed); +});