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
9 changes: 4 additions & 5 deletions src/agent-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
*/

import { Page } from 'playwright';
import { v4 as uuidv4 } from 'uuid';
import { Snapshot } from './types';
import { AssertContext, Predicate } from './verification';
import { Tracer } from './tracing/tracer';
Expand Down Expand Up @@ -741,22 +740,22 @@ export class AgentRuntime {
*
* @param goal - Description of what this step aims to achieve
* @param stepIndex - Optional explicit step index (otherwise auto-increments)
* @returns Generated stepId
* @returns Generated stepId in format 'step-N' where N is the step index
*/
beginStep(goal: string, stepIndex?: number): string {
// Clear previous step state
this.assertionsThisStep = [];

// Generate new stepId
this.stepId = uuidv4();

// Update step index
if (stepIndex !== undefined) {
this.stepIndex = stepIndex;
} else {
this.stepIndex += 1;
}

// Generate stepId in 'step-N' format for Studio compatibility
this.stepId = `step-${this.stepIndex}`;

return this.stepId;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('Actions', () => {
} finally {
await browser.close();
}
}, 60000);
}, 90000); // 90 seconds - Windows CI can be slow

it('should take snapshot after scroll when requested', async () => {
const browser = await createTestBrowser();
Expand Down
46 changes: 46 additions & 0 deletions tests/agent-runtime-assertions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,52 @@ function makeElement(
} as Element;
}

describe('AgentRuntime.beginStep() stepId format', () => {
it('generates stepId in step-N format', () => {
const sink = new MockSink();
const tracer = new Tracer('test-run', sink);
const page = new MockPage('https://example.com') as any;
const browserLike = {
snapshot: async () => ({
status: 'success',
url: 'https://example.com',
elements: [],
timestamp: 't1',
}),
};

const runtime = new AgentRuntime(browserLike as any, page as any, tracer);

const stepId1 = runtime.beginStep('Step 1');
expect(stepId1).toBe('step-1');
expect(runtime.stepIndex).toBe(1);

const stepId2 = runtime.beginStep('Step 2');
expect(stepId2).toBe('step-2');
expect(runtime.stepIndex).toBe(2);
});

it('generates stepId matching explicit stepIndex', () => {
const sink = new MockSink();
const tracer = new Tracer('test-run', sink);
const page = new MockPage('https://example.com') as any;
const browserLike = {
snapshot: async () => ({
status: 'success',
url: 'https://example.com',
elements: [],
timestamp: 't1',
}),
};

const runtime = new AgentRuntime(browserLike as any, page as any, tracer);

const stepId = runtime.beginStep('Custom step', 10);
expect(stepId).toBe('step-10');
expect(runtime.stepIndex).toBe(10);
});
});

describe('AgentRuntime.assert() with state predicates', () => {
it('uses snapshot context for enabled/disabled/value assertions', () => {
const sink = new MockSink();
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Snapshot', () => {
} finally {
await browser.close();
}
}, 60000); // 60 seconds - browser startup can be slow
}, 90000); // 90 seconds - Windows CI can be slow

it('should have valid element structure', async () => {
const browser = await createTestBrowser();
Expand Down
2 changes: 1 addition & 1 deletion tests/video-recording.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,5 @@ describe('video recording', () => {
throw error;
}
}
});
}, 180000); // 180 seconds - tests 3 resolutions with browser start/stop each, Windows CI can be slow
});
Loading