Skip to content

Commit 8da9745

Browse files
cameroncookeCodex
andcommitted
fix(ui-automation): Report ambiguous gone text waits
Propagate ambiguity from selector-free gone text waits instead of dropping the recoverable error and timing out. This keeps gone text waits aligned with textContains when partial text matches multiple distinct elements. Co-Authored-By: Codex <noreply@example.com>
1 parent 7463a11 commit 8da9745

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/mcp/tools/ui-automation/__tests__/wait_for_ui.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,32 @@ describe('Wait for UI Plugin', () => {
460460
});
461461
});
462462

463+
it('returns TARGET_AMBIGUOUS for selector-free gone with ambiguous partial text', async () => {
464+
const { executor } = createSequencedExecutor([
465+
{
466+
success: true,
467+
output: hierarchyJson([
468+
createNode({ AXLabel: 'Ready' }),
469+
createNode({ AXLabel: 'Ready now' }),
470+
]),
471+
},
472+
]);
473+
474+
const result = await runWaitForUi(
475+
{ simulatorId, predicate: 'gone', text: 'Ready', timeoutMs: 0 },
476+
executor,
477+
);
478+
479+
expect(result.didError).toBe(true);
480+
expect(result.uiError).toMatchObject({
481+
code: 'TARGET_AMBIGUOUS',
482+
candidates: [
483+
expect.objectContaining({ label: 'Ready' }),
484+
expect.objectContaining({ label: 'Ready now' }),
485+
],
486+
});
487+
});
488+
463489
it('succeeds for gone when selector matches remain but none contain text', async () => {
464490
const { executor } = createSequencedExecutor([
465491
{

src/mcp/tools/ui-automation/wait_for_ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function evaluateWaitPredicate(args: {
198198
return {
199199
matched: (textMatch.candidates ?? []).length === 0,
200200
candidates: textMatch.candidates ?? [],
201-
uiError: undefined,
201+
uiError: textMatch.uiError,
202202
};
203203
}
204204

0 commit comments

Comments
 (0)