Skip to content

Commit a47c287

Browse files
committed
test: pin daemon wait fallback ownership
1 parent d411742 commit a47c287

3 files changed

Lines changed: 24 additions & 30 deletions

File tree

‎packages/daemon/src/execution/wait-runtime.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,28 @@ test('a text wait returns a native owner hit without capturing a snapshot', asyn
342342
expect(harness.captureSnapshot).not.toHaveBeenCalled();
343343
});
344344

345+
test('native text failure cannot hide a canonical capture failure', async () => {
346+
const harness = waitRuntimeHarness({ findText: available });
347+
harness.findText.mockRejectedValueOnce(new Error('native observation failed'));
348+
harness.captureSnapshot.mockRejectedValueOnce(
349+
new AppError('COMMAND_FAILED', 'canonical capture failed', {
350+
reason: 'capture_failed',
351+
}),
352+
);
353+
354+
const { response } = await runWait(['text', 'Ready'], harness);
355+
356+
expect(response.ok).toBe(false);
357+
if (response.ok) return;
358+
expect(response.error).toMatchObject({
359+
code: 'COMMAND_FAILED',
360+
message: 'canonical capture failed',
361+
details: { reason: 'capture_failed' },
362+
});
363+
expect(harness.findText).toHaveBeenCalledTimes(1);
364+
expect(harness.captureSnapshot).toHaveBeenCalledTimes(1);
365+
});
366+
345367
test('a selector wait binds the capture use once and polls through the bound operation', async () => {
346368
const harness = waitRuntimeHarness();
347369

‎src/commands/interaction/runtime/wait-text.test.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,6 @@ test('runtime wait surfaces a canonical capture failure after a native text miss
125125
assert.equal(captureSnapshot.mock.calls.length, 1);
126126
});
127127

128-
test('runtime wait surfaces a canonical capture failure after native text reading throws', async () => {
129-
const captureSnapshot = vi.fn(async (): Promise<BackendSnapshotResult> => {
130-
throw new AppError('COMMAND_FAILED', 'canonical capture failed', {
131-
reason: 'capture_failed',
132-
});
133-
});
134-
const findText = vi.fn(async () => {
135-
throw new Error('native observation failed');
136-
});
137-
const device = textWaitDevice({ captureSnapshot, findText });
138-
139-
await assert.rejects(
140-
device.selectors.wait({
141-
session: 'default',
142-
target: { kind: 'text', text: 'Ready', timeoutMs: 10_000 },
143-
}),
144-
(error: AppError) =>
145-
error.message === 'canonical capture failed' && error.details?.reason === 'capture_failed',
146-
);
147-
148-
assert.equal(findText.mock.calls.length, 1);
149-
assert.equal(captureSnapshot.mock.calls.length, 1);
150-
});
151-
152128
test('a native text hit does not make an older captured tree fresh for the next read', async () => {
153129
const snapshots = [
154130
makeSnapshotState([{ index: 0, type: 'StaticText', label: 'Home' }]),

‎src/commands/interaction/runtime/wait-text.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ async function observeText<Runtime extends SelectorWaitRuntime>(
4040
text: string,
4141
): Promise<boolean> {
4242
if (runtime.backend.findText) {
43-
try {
44-
const native = await runtime.backend.findText(backendContext(runtime, options), text);
45-
if (native.found) return true;
46-
} catch (error) {
47-
if (options.signal?.aborted || runtime.signal?.aborted) throw error;
48-
}
43+
const native = await runtime.backend.findText(backendContext(runtime, options), text);
44+
if (native.found) return true;
4945
}
5046
return await snapshotContainsText(operations, runtime, options, text);
5147
}

0 commit comments

Comments
 (0)