Skip to content

Commit eb30491

Browse files
committed
fix: simplify snapshot intent and prove disposal lock retention
Address #3760 (comment). Read explicit recording from the existing action flags, retain authored provenance, add the Unreleased notes, and synchronize lock tests with queue insertion.
1 parent 49a4033 commit eb30491

7 files changed

Lines changed: 39 additions & 16 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Healed scripts retain authored snapshot steps and snapshots explicitly included with `--record` during repair. Diagnostic snapshots remain excluded.
6+
- Requests that share a session or device now queue until the preceding request finishes disposing its runtime binding and releasing its device claim, including after failure or cancellation.
57
- Add `uninstall <app>` and `client.apps.uninstall({ app })` to remove an installed app on adb-backed Android targets, iOS simulators, and CoreDevice iOS devices. Both report `wasInstalled`. A package name or bundle id that is not installed succeeds with `wasInstalled: false`. Other targets, Appium and Limrun sessions included, refuse it before anything runs.
68
- Add `settings mobile-data on|off` for adb-backed Android targets. It switches mobile data through `svc data` and reports the `mobileData` state stored in the global `mobile_data` row; multi-SIM read-back is not covered yet. Every other target refuses it before anything runs, and `--app` is refused because the switch is device-wide.
79
- On iOS, a `fill` that runs under a degraded XCTest snapshot channel now aims at a point, including ref, selector and replay fills. When the runner identifies no text input under that point, it refuses with `NO_TEXT_INPUT_AT_POINT` (`error.details.reason: no_text_input_at_point`, `dispatched: no`) before dispatching its focus tap, and no field changes; when the input lookup itself cannot answer, it refuses with `TEXT_INPUT_PROBE_UNAVAILABLE` (`error.details.reason: text_input_probe_unavailable`). Previously such a fill cleared and typed through the app-level first responder, so it could rewrite a field the caller never named, or report a clear failure after emptying it. A ref or selector fill whose rect centre misses the real field (an outer container, a non-input node) now needs a point inside the input's own rect.

‎packages/contracts/src/session-action.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export type SessionAction = {
2828
noRecord?: boolean;
2929
};
3030
result?: Record<string, unknown>;
31-
/** Retain authored plan observations and explicitly recorded corrections during publication. */
32-
publicationIntent?: 'authored' | 'explicit-record';
31+
/** Retain authored plan observations during publication. */
32+
publicationIntent?: 'authored';
3333
/**
3434
* ADR 0012 decision 3: parsed or record-time-computed `target-v1`
3535
* evidence, written as a comment immediately before this action's line.

‎packages/daemon/src/core/__tests__/request-runtime-binding-router.test.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { makeSessionStore } from '../../__tests__/support/store-factory.ts';
2323
import { LeaseRegistry } from '../../resources/lease-registry.ts';
2424
import { createRequestHandler } from '../../__tests__/support/test-device-runtime-gateway.ts';
2525
import { fakeCreateCommandSurface } from '../../__tests__/support/command-surface-fake.ts';
26+
import { getLeaseRegistryExecutionLocks } from '../../server/request-execution-scope.ts';
2627

2728
test('request binding disposes once after response while adopted app-log handle survives', async () => {
2829
const runtime = makeGateway();
@@ -61,7 +62,7 @@ for (const outcome of ['success', 'throw', 'cancellation'] as const) {
6162
for (const key of ['session', 'device'] as const) {
6263
test(`binding cleanup holds the ${key} execution lock after ${outcome}`, async () => {
6364
const runtime = makeGateway();
64-
const { handler, sessionStore } = makeHandler(runtime.gateway);
65+
const { handler, sessionStore, leaseRegistry } = makeHandler(runtime.gateway);
6566
const current = sessionStore.get('session')!;
6667
sessionStore.publish('other-session', { ...current, name: 'other-session', actions: [] });
6768
const requestId = `cleanup-${key}-${outcome}`;
@@ -89,17 +90,30 @@ for (const outcome of ['success', 'throw', 'cancellation'] as const) {
8990
});
9091
const first = handler({ ...request(['doctor']), meta: { requestId } });
9192
await cleanupStarted;
93+
const locks = getLeaseRegistryExecutionLocks(leaseRegistry);
94+
const sharedKey = key === 'session' ? 'session:session' : 'device:emulator-5554';
95+
let markQueued: (entry: { previous: Promise<unknown> | undefined }) => void = () => {};
96+
const queued = new Promise<{ previous: Promise<unknown> | undefined }>((resolve) => {
97+
markQueued = resolve;
98+
});
99+
const setLock = locks.set.bind(locks);
100+
const queueSpy = vi.spyOn(locks, 'set').mockImplementation((lockKey, completion) => {
101+
if (lockKey === sharedKey) markQueued({ previous: locks.get(lockKey) });
102+
return setLock(lockKey, completion);
103+
});
92104
const second = handler({
93105
...request(['doctor']),
94106
session: key === 'session' ? 'session' : 'other-session',
95107
meta: { requestId: `${requestId}-queued` },
96108
});
97109
try {
98-
await new Promise<void>((resolve) => setImmediate(resolve));
110+
expect((await queued).previous).toBeDefined();
99111
expect(runtime.bind).toHaveBeenCalledTimes(1);
100112
} finally {
113+
queueSpy.mockRestore();
101114
finishCleanup();
102115
clearRequestCanceled(requestId);
116+
await Promise.all([first, second]);
103117
}
104118
const [firstResponse, secondResponse] = await Promise.all([first, second]);
105119
expect(firstResponse.ok).toBe(outcome === 'success');
@@ -118,6 +132,7 @@ for (const outcome of ['success', 'throw', 'cancellation'] as const) {
118132

119133
function makeHandler(gateway: DeviceRuntimeGateway<PlatformRuntimeOperations>) {
120134
const sessionStore = makeSessionStore('request-runtime-binding-router-');
135+
const leaseRegistry = new LeaseRegistry();
121136
sessionStore.publish('session', {
122137
name: 'session',
123138
device: { platform: 'android', id: 'emulator-5554', name: 'Pixel', kind: 'emulator' },
@@ -127,12 +142,13 @@ function makeHandler(gateway: DeviceRuntimeGateway<PlatformRuntimeOperations>) {
127142
});
128143
return {
129144
sessionStore,
145+
leaseRegistry,
130146
handler: createRequestHandler({
131147
createCommandSurface: fakeCreateCommandSurface,
132148
logPath: '/tmp/daemon.log',
133149
token: 'token',
134150
sessionStore,
135-
leaseRegistry: new LeaseRegistry(),
151+
leaseRegistry,
136152
deviceInventoryGateways: createTestDeviceInventoryGateways(),
137153
deviceRuntimeGateway: gateway,
138154
trackDownloadableArtifact: () => 'artifact',

‎packages/daemon/src/core/__tests__/session-action-recorder.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ test('--record forces an observation-only action through while repair-armed', ()
7575
interactiveObservation: true,
7676
});
7777
expect(action).toBeDefined();
78+
expect(action?.flags.record).toBe(true);
79+
expect(action?.publicationIntent).toBeUndefined();
7880
expect(session.actions.map((a) => a.command)).toEqual(['get']);
7981
});
8082

‎packages/daemon/src/core/__tests__/session-script-writer.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,13 @@ test('#1533: an ARMED authoring recording is untouched by the abort gate', () =>
864864
expect(parsed.actions.map((a) => a.command)).toEqual(['click']);
865865
});
866866

867-
test.each([undefined, true])(
868-
'ordinary authoring strips diagnostic snapshots with effective record=%s',
869-
(record) => {
867+
test.each([
868+
{ record: undefined, replayPlanStep: false },
869+
{ record: true, replayPlanStep: false },
870+
{ record: true, replayPlanStep: true },
871+
])(
872+
'ordinary authoring strips snapshots with record=$record and replayPlanStep=$replayPlanStep',
873+
({ record, replayPlanStep }) => {
870874
const root = mkdtempForTestSync('agent-device-script-writer-authoring-snapshot-');
871875
const writer = new SessionScriptWriter(path.join(root, 'sessions'));
872876
const session = makeAuthoringSession('default', {
@@ -876,7 +880,7 @@ test.each([undefined, true])(
876880
command: 'snapshot',
877881
positionals: [],
878882
flags: { record, snapshotInteractiveOnly: true },
879-
interactiveObservation: true,
883+
interactiveObservation: !replayPlanStep,
880884
});
881885

882886
const { parsed } = writeAndParse(writer, session);

‎packages/daemon/src/core/session-action-recorder.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ export function recordActionEntry(
8686
runtime: recordedEntry.runtime,
8787
flags: sanitizeFlags(recordedEntry.flags),
8888
result: recordedEntry.result,
89-
...(recordedEntry.flags.record === true
90-
? { publicationIntent: 'explicit-record' as const }
91-
: OBSERVATION_ONLY_COMMANDS.has(recordedEntry.command) &&
92-
recordedEntry.interactiveObservation === false
93-
? { publicationIntent: 'authored' as const }
94-
: {}),
89+
...(recordedEntry.flags.record !== true &&
90+
OBSERVATION_ONLY_COMMANDS.has(recordedEntry.command) &&
91+
recordedEntry.interactiveObservation === false
92+
? { publicationIntent: 'authored' as const }
93+
: {}),
9594
...(recordedEntry.targetEvidence ? { targetEvidence: recordedEntry.targetEvidence } : {}),
9695
...(recordedEntry.targetEvidences ? { targetEvidences: recordedEntry.targetEvidences } : {}),
9796
};

‎packages/daemon/src/core/session-script-writer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function buildOptimizedActions(
315315
if (
316316
action.command === 'snapshot' &&
317317
action.publicationIntent !== 'authored' &&
318-
!(repairArmed && action.publicationIntent === 'explicit-record')
318+
!(repairArmed && action.flags.record === true)
319319
) {
320320
continue;
321321
}

0 commit comments

Comments
 (0)