Skip to content

Commit be5a05f

Browse files
cameroncookecodex
andcommitted
test(ui-automation): Stabilize key sequence snapshot polling
Inject deterministic post-action snapshot timing into the key sequence executor test. This keeps the exact polling assertion stable under CI scheduler jitter. Co-Authored-By: OpenAI Codex <noreply@openai.com>
1 parent 164727c commit be5a05f

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ import {
1212
simulatorId,
1313
} from './ui-action-test-helpers.ts';
1414

15+
function createImmediatePostActionTiming() {
16+
let nowMs = 0;
17+
18+
return {
19+
now: () => nowMs,
20+
sleep: async (durationMs: number) => {
21+
nowMs += durationMs;
22+
},
23+
};
24+
}
25+
1526
describe('Key Sequence Tool', () => {
1627
beforeEach(() => {
1728
sessionStore.clear();
@@ -194,7 +205,12 @@ describe('Key Sequence Tool', () => {
194205
describe('Handler Behavior (Complete Literal Returns)', () => {
195206
it('captures a fresh runtime snapshot after a successful key sequence', async () => {
196207
const { calls, executor } = createTrackingExecutor();
197-
const executeKeySequence = createKeySequenceExecutor(executor, createMockAxeHelpers());
208+
const executeKeySequence = createKeySequenceExecutor(
209+
executor,
210+
createMockAxeHelpers(),
211+
undefined,
212+
createImmediatePostActionTiming(),
213+
);
198214

199215
const result = await executeKeySequence({ simulatorId, keyCodes: [40, 42, 44] });
200216

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import {
2222
clearRuntimeSnapshot,
2323
withSimulatorUiAutomationTransaction,
2424
} from './shared/snapshot-ui-state.ts';
25-
import { captureRuntimeSnapshotAfterActionSafely } from './shared/post-action-snapshot.ts';
25+
import {
26+
captureRuntimeSnapshotAfterActionSafely,
27+
type PostActionSnapshotTiming,
28+
} from './shared/post-action-snapshot.ts';
2629
import type { AxeHelpers } from './shared/axe-command.ts';
2730
import type { NonStreamingExecutor } from '../../../types/tool-execution.ts';
2831
import type { UiActionResultDomainResult } from '../../../types/domain-results.ts';
@@ -57,6 +60,7 @@ export function createKeySequenceExecutor(
5760
executor: CommandExecutor,
5861
axeHelpers: AxeHelpers = defaultAxeHelpers,
5962
debuggerManager: DebuggerManager = getDefaultDebuggerManager(),
63+
postActionSnapshotTiming?: PostActionSnapshotTiming,
6064
): NonStreamingExecutor<KeySequenceParams, KeySequenceResult> {
6165
return async (params) =>
6266
withSimulatorUiAutomationTransaction(params.simulatorId, async () => {
@@ -91,6 +95,7 @@ export function createKeySequenceExecutor(
9195
simulatorId,
9296
executor,
9397
axeHelpers,
98+
timing: postActionSnapshotTiming,
9499
});
95100
return createUiActionSuccessResult(
96101
action,

0 commit comments

Comments
 (0)