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
4 changes: 2 additions & 2 deletions scripts/layering/daemon-modularity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const LARGEST_TYPE_CYCLE_ZONE_CEILINGS: Readonly<Record<string, number>> = {

export const DAEMON_MODULARITY_BASELINE = {
sessionState: {
writerOwnedFields: 30,
ownerFileClaims: 42,
writerOwnedFields: 29,
ownerFileClaims: 40,
},
largestTypeCycle: {
zoneMembers: LARGEST_TYPE_CYCLE_ZONE_CEILINGS,
Expand Down
4 changes: 0 additions & 4 deletions scripts/layering/session-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ export const SESSION_STATE_FIELD_OWNERS: Readonly<Record<string, readonly string
'src/daemon/handlers/session-script-publication.ts',
'src/daemon/session-action-recorder.ts',
],
saveScriptDefaultedHealedPath: [
'src/daemon/handlers/session-replay-runtime.ts',
'src/daemon/session-action-recorder.ts',
],
saveScriptBoundary: ['src/daemon/handlers/session-replay-runtime.ts'],
saveScriptCommitted: ['src/daemon/session-script-writer.ts'],
repairSourcePath: ['src/daemon/handlers/session-replay-runtime.ts'],
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {
makeAndroidSession,
makeIosSession,
makeMacOsSession,
makeAuthoringSession,
makeSession,
} from './session-factories.ts';

Expand Down
60 changes: 60 additions & 0 deletions src/__tests__/test-utils/session-factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,63 @@ export function makeAndroidSession(name: string, overrides?: Partial<SessionStat
export function makeMacOsSession(name: string, overrides?: Partial<SessionState>): SessionState {
return makeSession(name, { device: MACOS_DEVICE, ...overrides });
}

// --- Script-authoring session states ---
//
// The three factories below name the states a session-script session can be in,
// instead of leaving each test to re-derive them from a pile of `saveScript*`
// booleans. They exist because the fields are NOT independent: `recordSession`
// without a boundary is an ordinary recording, a boundary without
// `saveScriptComplete` is an ARMED-but-uncommittable repair, and only the
// COMPLETE combination publishes. Spelling that out per test made the
// distinction the tests are actually about (ordinary vs repair, armed vs
// complete) the hardest thing to see in them.
//
// A test that deliberately exercises an odd combination (a boundary with no
// recording, say) should still build it inline — these are for the states
// production actually produces.

/**
* ADR 0016 ordinary authoring recording: `recordSession` armed, NO repair
* boundary. This is a plain `open --save-script` / `close --save-script`
* session, and the baseline for every authoring-side handler test (target-v1
* evidence, parameterized fills, landmark waits) that only needs the session to
* be recording its actions.
*
* "Authoring", not "recording": `session.recording` is the unrelated
* screen-capture state.
*/
export function makeAuthoringSession(
name: string,
overrides?: Partial<SessionState>,
): SessionState {
return makeIosSession(name, { recordSession: true, ...overrides });
}

/**
* ADR 0012 decision 6: a session ARMED for repair by `replay --save-script` —
* recording plus the repair-run boundary watermark, which is what the writer's
* `repairArmed` actually keys off (`saveScriptBoundary !== undefined`).
*
* ARMED, not COMPLETE: a writer handed this session ABORTS (publishes no
* prefix) rather than committing. Use `makeRepairCompleteSession` for a
* committable one.
*/
export function makeRepairArmedSession(
name: string,
overrides?: Partial<SessionState>,
): SessionState {
return makeAuthoringSession(name, { saveScriptBoundary: 0, ...overrides });
}

/**
* The same repair transaction advanced to COMPLETE — the plan reached its last
* executable step with no outstanding divergence — so a writer commits it
* (ARMED -> COMPLETE -> COMMITTED).
*/
export function makeRepairCompleteSession(
name: string,
overrides?: Partial<SessionState>,
): SessionState {
return makeRepairArmedSession(name, { saveScriptComplete: true, ...overrides });
}
50 changes: 29 additions & 21 deletions src/daemon/__tests__/request-router-typed-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,36 @@ import { createRequestHandler } from '../request-router.ts';
import type { DaemonRequest, SessionState } from '../types.ts';
import { LeaseRegistry } from '../lease-registry.ts';
import { makeSessionStore } from '../../__tests__/test-utils/store-factory.ts';
import {
makeAuthoringSession,
makeRepairCompleteSession,
makeSession,
} from '../../__tests__/test-utils/session-factories.ts';
import type { DeviceInfo } from '@agent-device/kernel/device';
import { AppError, retriableForErrorCode } from '@agent-device/kernel/errors';
import { supportedPlatformsForCommand } from '../../core/capabilities.ts';

const mockDispatch = vi.mocked(dispatchCommand);

/**
* This file pins its own simulator rather than reusing the shared iOS fixture:
* the tenant-scoped `simulatorSetPath` is part of what the router under test
* carries through. Everything else comes from the shared session factories.
*/
const TENANT_SIMULATOR: DeviceInfo = {
platform: 'apple',
target: 'mobile',
id: 'SIM-001',
name: 'iPhone 16',
kind: 'simulator',
booted: true,
simulatorSetPath: '/tmp/tenant-a/set',
};

const TENANT_SESSION_DEFAULTS = { device: TENANT_SIMULATOR, createdAt: 1_700_000_000_000 } as const;

function makeIosSession(name: string): SessionState {
return {
name,
createdAt: 1_700_000_000_000,
actions: [],
device: {
platform: 'apple',
target: 'mobile',
id: 'SIM-001',
name: 'iPhone 16',
kind: 'simulator',
booted: true,
simulatorSetPath: '/tmp/tenant-a/set',
},
};
return makeSession(name, TENANT_SESSION_DEFAULTS);
}

function makeHandler(sessionStore = makeSessionStore('agent-device-router-typed-error-')) {
Expand Down Expand Up @@ -135,11 +145,10 @@ test('deterministic errors (INVALID_ARGS) are returned with the default shape
// `error.retriable ?? retriableForErrorCode(error.code)` fallback is caught.
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 () => {
const { sessionStore, handler } = makeHandler();
const session = makeIosSession('typed-error');
session.recordSession = true;
session.saveScriptBoundary = 0;
session.saveScriptComplete = true;
session.actions = [{ ts: 1, command: 'open', positionals: ['Demo'], flags: {} }];
const session = makeRepairCompleteSession('typed-error', {
...TENANT_SESSION_DEFAULTS,
actions: [{ ts: 1, command: 'open', positionals: ['Demo'], flags: {} }],
});
sessionStore.set('typed-error', session);

// DEVICE_NOT_FOUND is not in `retriableForErrorCode`'s conservative allow
Expand Down Expand Up @@ -174,8 +183,7 @@ test('BLOCKER 2 (second follow-up): a repair-close platform-close failure surfac
// details.retriable hoisting.
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 () => {
const { sessionStore, handler } = makeHandler();
const session = makeIosSession('typed-error');
session.recordSession = true;
const session = makeAuthoringSession('typed-error', TENANT_SESSION_DEFAULTS);
const targetPath = path.join(
os.tmpdir(),
`agent-device-router-typed-error-${Date.now()}-${Math.random().toString(36).slice(2)}.ad`,
Expand Down
Loading
Loading