Skip to content

Commit 1fc9169

Browse files
thymikeeclaude
andauthored
refactor(daemon): consolidate session-script test factories and drop saveScriptDefaultedHealedPath (#1508)
Preparatory slice for P4a (#1478). No aggregate, no transaction type, no publication-writer migration — those land separately. Two things: 1. Name the session-script session states in the shared test factories (`makeAuthoringSession`, `makeRepairArmedSession`, `makeRepairCompleteSession`) and route 40 inline session literals across 11 test files through them. The `saveScript*` fields are not independent — recording without a boundary is ordinary authoring, a boundary without `saveScriptComplete` is an ARMED-but-uncommittable repair, and only the COMPLETE combination publishes — so re-deriving the combination per test buried the distinction each test was actually about. Pure refactor: the factories write today's fields and no assertion was weakened. 2. Delete `saveScriptDefaultedHealedPath`. It had zero production readers: the writer's refuse-on-exist guard has been uniform since #1235, so the flag was written in three places and never consulted. Removing it takes its R7 owner row with it and lowers the R10 baseline from 30/42 to 29/40 (the ratchet fails on a drop too, so this cannot be deferred). Claude-Session: https://claude.ai/code/session_01RXQLYV7etZx3gcXsUsrQJ8 Co-authored-by: Claude <[email protected]>
1 parent 6067b9a commit 1fc9169

20 files changed

Lines changed: 226 additions & 244 deletions

‎scripts/layering/daemon-modularity.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const LARGEST_TYPE_CYCLE_ZONE_CEILINGS: Readonly<Record<string, number>> = {
1313

1414
export const DAEMON_MODULARITY_BASELINE = {
1515
sessionState: {
16-
writerOwnedFields: 30,
17-
ownerFileClaims: 42,
16+
writerOwnedFields: 29,
17+
ownerFileClaims: 40,
1818
},
1919
largestTypeCycle: {
2020
zoneMembers: LARGEST_TYPE_CYCLE_ZONE_CEILINGS,

‎scripts/layering/session-state.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ export const SESSION_STATE_FIELD_OWNERS: Readonly<Record<string, readonly string
7373
'src/daemon/handlers/session-script-publication.ts',
7474
'src/daemon/session-action-recorder.ts',
7575
],
76-
saveScriptDefaultedHealedPath: [
77-
'src/daemon/handlers/session-replay-runtime.ts',
78-
'src/daemon/session-action-recorder.ts',
79-
],
8076
saveScriptBoundary: ['src/daemon/handlers/session-replay-runtime.ts'],
8177
saveScriptCommitted: ['src/daemon/session-script-writer.ts'],
8278
repairSourcePath: ['src/daemon/handlers/session-replay-runtime.ts'],

‎src/__tests__/test-utils/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export {
1515
makeAndroidSession,
1616
makeIosSession,
1717
makeMacOsSession,
18+
makeAuthoringSession,
1819
makeSession,
1920
} from './session-factories.ts';
2021

‎src/__tests__/test-utils/session-factories.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,63 @@ export function makeAndroidSession(name: string, overrides?: Partial<SessionStat
2222
export function makeMacOsSession(name: string, overrides?: Partial<SessionState>): SessionState {
2323
return makeSession(name, { device: MACOS_DEVICE, ...overrides });
2424
}
25+
26+
// --- Script-authoring session states ---
27+
//
28+
// The three factories below name the states a session-script session can be in,
29+
// instead of leaving each test to re-derive them from a pile of `saveScript*`
30+
// booleans. They exist because the fields are NOT independent: `recordSession`
31+
// without a boundary is an ordinary recording, a boundary without
32+
// `saveScriptComplete` is an ARMED-but-uncommittable repair, and only the
33+
// COMPLETE combination publishes. Spelling that out per test made the
34+
// distinction the tests are actually about (ordinary vs repair, armed vs
35+
// complete) the hardest thing to see in them.
36+
//
37+
// A test that deliberately exercises an odd combination (a boundary with no
38+
// recording, say) should still build it inline — these are for the states
39+
// production actually produces.
40+
41+
/**
42+
* ADR 0016 ordinary authoring recording: `recordSession` armed, NO repair
43+
* boundary. This is a plain `open --save-script` / `close --save-script`
44+
* session, and the baseline for every authoring-side handler test (target-v1
45+
* evidence, parameterized fills, landmark waits) that only needs the session to
46+
* be recording its actions.
47+
*
48+
* "Authoring", not "recording": `session.recording` is the unrelated
49+
* screen-capture state.
50+
*/
51+
export function makeAuthoringSession(
52+
name: string,
53+
overrides?: Partial<SessionState>,
54+
): SessionState {
55+
return makeIosSession(name, { recordSession: true, ...overrides });
56+
}
57+
58+
/**
59+
* ADR 0012 decision 6: a session ARMED for repair by `replay --save-script` —
60+
* recording plus the repair-run boundary watermark, which is what the writer's
61+
* `repairArmed` actually keys off (`saveScriptBoundary !== undefined`).
62+
*
63+
* ARMED, not COMPLETE: a writer handed this session ABORTS (publishes no
64+
* prefix) rather than committing. Use `makeRepairCompleteSession` for a
65+
* committable one.
66+
*/
67+
export function makeRepairArmedSession(
68+
name: string,
69+
overrides?: Partial<SessionState>,
70+
): SessionState {
71+
return makeAuthoringSession(name, { saveScriptBoundary: 0, ...overrides });
72+
}
73+
74+
/**
75+
* The same repair transaction advanced to COMPLETE — the plan reached its last
76+
* executable step with no outstanding divergence — so a writer commits it
77+
* (ARMED -> COMPLETE -> COMMITTED).
78+
*/
79+
export function makeRepairCompleteSession(
80+
name: string,
81+
overrides?: Partial<SessionState>,
82+
): SessionState {
83+
return makeRepairArmedSession(name, { saveScriptComplete: true, ...overrides });
84+
}

‎src/daemon/__tests__/request-router-typed-error.test.ts‎

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,36 @@ import { createRequestHandler } from '../request-router.ts';
2121
import type { DaemonRequest, SessionState } from '../types.ts';
2222
import { LeaseRegistry } from '../lease-registry.ts';
2323
import { makeSessionStore } from '../../__tests__/test-utils/store-factory.ts';
24+
import {
25+
makeAuthoringSession,
26+
makeRepairCompleteSession,
27+
makeSession,
28+
} from '../../__tests__/test-utils/session-factories.ts';
29+
import type { DeviceInfo } from '@agent-device/kernel/device';
2430
import { AppError, retriableForErrorCode } from '@agent-device/kernel/errors';
2531
import { supportedPlatformsForCommand } from '../../core/capabilities.ts';
2632

2733
const mockDispatch = vi.mocked(dispatchCommand);
2834

35+
/**
36+
* This file pins its own simulator rather than reusing the shared iOS fixture:
37+
* the tenant-scoped `simulatorSetPath` is part of what the router under test
38+
* carries through. Everything else comes from the shared session factories.
39+
*/
40+
const TENANT_SIMULATOR: DeviceInfo = {
41+
platform: 'apple',
42+
target: 'mobile',
43+
id: 'SIM-001',
44+
name: 'iPhone 16',
45+
kind: 'simulator',
46+
booted: true,
47+
simulatorSetPath: '/tmp/tenant-a/set',
48+
};
49+
50+
const TENANT_SESSION_DEFAULTS = { device: TENANT_SIMULATOR, createdAt: 1_700_000_000_000 } as const;
51+
2952
function makeIosSession(name: string): SessionState {
30-
return {
31-
name,
32-
createdAt: 1_700_000_000_000,
33-
actions: [],
34-
device: {
35-
platform: 'apple',
36-
target: 'mobile',
37-
id: 'SIM-001',
38-
name: 'iPhone 16',
39-
kind: 'simulator',
40-
booted: true,
41-
simulatorSetPath: '/tmp/tenant-a/set',
42-
},
43-
};
53+
return makeSession(name, TENANT_SESSION_DEFAULTS);
4454
}
4555

4656
function makeHandler(sessionStore = makeSessionStore('agent-device-router-typed-error-')) {
@@ -135,11 +145,10 @@ test('deterministic errors (INVALID_ARGS) are returned with the default shape
135145
// `error.retriable ?? retriableForErrorCode(error.code)` fallback is caught.
136146
test('BLOCKER 2 (second follow-up): a repair-close platform-close failure surfaces retriable:true and diagnosticId/logPath/details at the TOP level through the router', async () => {
137147
const { sessionStore, handler } = makeHandler();
138-
const session = makeIosSession('typed-error');
139-
session.recordSession = true;
140-
session.saveScriptBoundary = 0;
141-
session.saveScriptComplete = true;
142-
session.actions = [{ ts: 1, command: 'open', positionals: ['Demo'], flags: {} }];
148+
const session = makeRepairCompleteSession('typed-error', {
149+
...TENANT_SESSION_DEFAULTS,
150+
actions: [{ ts: 1, command: 'open', positionals: ['Demo'], flags: {} }],
151+
});
143152
sessionStore.set('typed-error', session);
144153

145154
// DEVICE_NOT_FOUND is not in `retriableForErrorCode`'s conservative allow
@@ -174,8 +183,7 @@ test('BLOCKER 2 (second follow-up): a repair-close platform-close failure surfac
174183
// details.retriable hoisting.
175184
test('#1391: an ordinary close-time script-save failure surfaces details.reason/path and retriable:false through the router, and the session is torn down', async () => {
176185
const { sessionStore, handler } = makeHandler();
177-
const session = makeIosSession('typed-error');
178-
session.recordSession = true;
186+
const session = makeAuthoringSession('typed-error', TENANT_SESSION_DEFAULTS);
179187
const targetPath = path.join(
180188
os.tmpdir(),
181189
`agent-device-router-typed-error-${Date.now()}-${Math.random().toString(36).slice(2)}.ad`,

0 commit comments

Comments
 (0)