-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.test.ts
More file actions
82 lines (65 loc) · 2.48 KB
/
debugger.test.ts
File metadata and controls
82 lines (65 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { AgentRuntime } from '../src/agent-runtime';
import { SentienceDebugger } from '../src/debugger';
import { TraceSink } from '../src/tracing/sink';
import { Tracer } from '../src/tracing/tracer';
import { MockPage } from './mocks/browser-mock';
class MockSink extends TraceSink {
emit(): void {
// no-op
}
async close(): Promise<void> {
// no-op
}
getSinkType(): string {
return 'MockSink';
}
}
describe('SentienceDebugger', () => {
it('attaches via AgentRuntime.fromPlaywrightPage()', () => {
const sink = new MockSink();
const tracer = new Tracer('test-run', sink);
const page = new MockPage('https://example.com') as any;
const runtime = {} as AgentRuntime;
const spy = jest.spyOn(AgentRuntime, 'fromPlaywrightPage').mockReturnValue(runtime);
const dbg = SentienceDebugger.attach(page, tracer, { apiKey: 'sk', apiUrl: 'https://api' });
expect(spy).toHaveBeenCalledWith(page, tracer, { apiKey: 'sk', apiUrl: 'https://api' });
expect(dbg.runtime).toBe(runtime);
spy.mockRestore();
});
it('step() calls beginStep and emitStepEnd', async () => {
const runtime = {
beginStep: jest.fn().mockReturnValue('step-1'),
emitStepEnd: jest.fn().mockResolvedValue({}),
} as unknown as AgentRuntime;
const dbg = new SentienceDebugger(runtime);
await dbg.step('verify-cart', async () => {
// no-op
});
expect(runtime.beginStep).toHaveBeenCalledWith('verify-cart', undefined);
expect(runtime.emitStepEnd).toHaveBeenCalled();
});
it('check() auto-opens a step if missing', () => {
const runtime = {
beginStep: jest.fn().mockReturnValue('step-1'),
check: jest.fn().mockReturnValue('handle'),
} as unknown as AgentRuntime;
const dbg = new SentienceDebugger(runtime);
const handle = dbg.check(
(_ctx: any) => ({ passed: true, reason: '', details: {} }),
'has_cart'
);
expect(runtime.beginStep).toHaveBeenCalledWith('verify:has_cart', undefined);
expect(runtime.check).toHaveBeenCalled();
expect(handle).toBe('handle');
});
it('can disable auto-step (strict mode)', () => {
const runtime = {
beginStep: jest.fn().mockReturnValue('step-1'),
check: jest.fn().mockReturnValue('handle'),
} as unknown as AgentRuntime;
const dbg = new SentienceDebugger(runtime, { autoStep: false } as any);
expect(() =>
dbg.check((_ctx: any) => ({ passed: true, reason: '', details: {} }), 'has_cart')
).toThrow(/No active step/i);
});
});