Commit 19b2703
authored
feat: HITL continuation recording/replay support (#233)
## Summary
Closes #232. Adds `toolCallId`-based fixture matching so aimock can
record and replay HITL (Human-in-the-Loop) continuation requests — the
second leg of a `useHumanInTheLoop` flow where the last message is
`role: "tool"` instead of `role: "user"`.
- Add `toolCallId?: string` to `AGUIFixtureMatch` and
`AGUIConfigFixture`
- Add `getLastMessageIfToolResult` helper (checks absolute last message
only)
- Add `toolCallId` check in `matchesFixture` (AND logic with existing
fields)
- Recorder uses tool-result-first priority: `toolCallId` → user message
→ sentinel fallback
- Add `onToolResult(toolCallId, events, delayMs?)` fluent API method
- Config loader passes through `toolCallId` in events path, warns on
text shorthand misuse
- Export `getLastMessageIfToolResult` from both entry points
Also hardens the recorder against pre-existing robustness issues
surfaced during CR:
- Guard against recording fixtures from error (non-2xx) upstream
responses
- Add `settled` flag to prevent double-settle on error+end race
- Skip disk write for predicate fixtures (`__NO_USER_MESSAGE__` sentinel
was semantically broken on reload)
- Include parse error reason in SSE warning log
## Test plan
- 19 new tests (51 total), all passing
- Matcher: toolCallId match, wrong ID, non-tool message, absent
toolCallId, AND logic with message, AND logic with stateKey
- Fluent API: onToolResult registers and matches, onToolResult with
delayMs
- Recorder: continuation writes toolCallId fixture, continuation replay,
normal request still writes message, sentinel fallback, priority test
(tool result wins over user message in history)
- Integration: full HITL round-trip — record both legs, replay both
without upstream
🤖 Generated with [Claude Code](https://claude.com/claude-code)13 files changed
Lines changed: 615 additions & 62 deletions
File tree
- .claude-plugin
- charts/aimock
- src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 7 | + | |
11 | 8 | | |
12 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
13 | 12 | | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments