|
6 | 6 | captureLkgSlot, |
7 | 7 | projectLkgEntry, |
8 | 8 | replayLkg, |
| 9 | + validateAnthropicReasoningRuns, |
9 | 10 | validateLkgEntry, |
10 | 11 | validateLkgSeam, |
11 | 12 | } from "./lkg-replay"; |
@@ -298,6 +299,69 @@ describe("LKG transform replay", () => { |
298 | 299 | expect(getSlot("anthropic-invalid")).toBeUndefined(); |
299 | 300 | }); |
300 | 301 |
|
| 302 | + test("serves a new Anthropic thinking run after a completed tool result", () => { |
| 303 | + resetLkgSlotsForTest(); |
| 304 | + const prefix = assistant("a-prefix", 1, [ |
| 305 | + { type: "step-start" }, |
| 306 | + { type: "thinking", thinking: "first signed trace", signature: "sig-a" }, |
| 307 | + { type: "text", text: "calling a tool" }, |
| 308 | + { |
| 309 | + type: "tool", |
| 310 | + callID: "call-1", |
| 311 | + tool: "read", |
| 312 | + providerExecuted: false, |
| 313 | + state: { status: "completed", input: {}, output: "result" }, |
| 314 | + }, |
| 315 | + { type: "step-finish" }, |
| 316 | + ]); |
| 317 | + captureSlot("anthropic-tool-boundary", { |
| 318 | + jsonPrefix: JSON.stringify([prefix]), |
| 319 | + inputIdSeq: ["u-anchor"], |
| 320 | + inputContentDigests: [ |
| 321 | + lkgContentDigest( |
| 322 | + user("u-anchor", 2, { providerID: "anthropic", modelID: "claude-test" }), |
| 323 | + )!, |
| 324 | + ], |
| 325 | + lastInputMessageId: "u-anchor", |
| 326 | + modelKey: "anthropic/claude-test", |
| 327 | + providerKey: "anthropic", |
| 328 | + capturedAt: 1, |
| 329 | + }); |
| 330 | + const current = [ |
| 331 | + user("u-anchor", 2, { providerID: "anthropic", modelID: "claude-test" }), |
| 332 | + assistant("a-tail", 3, [ |
| 333 | + { type: "thinking", thinking: "second signed trace", signature: "sig-b" }, |
| 334 | + { type: "text", text: "second response" }, |
| 335 | + ]), |
| 336 | + ]; |
| 337 | + |
| 338 | + const replay = replayLkg({ |
| 339 | + sessionId: "anthropic-tool-boundary", |
| 340 | + messages: current, |
| 341 | + modelKey: "anthropic/claude-test", |
| 342 | + providerKey: "anthropic", |
| 343 | + }); |
| 344 | + expect(replay).toEqual({ ok: true, messages: [prefix, current[1]] }); |
| 345 | + }); |
| 346 | + |
| 347 | + test("declines a new thinking run after a provider-executed tool", () => { |
| 348 | + const first = assistant("a-prefix", 1, [ |
| 349 | + { type: "thinking", thinking: "first signed trace", signature: "sig-a" }, |
| 350 | + { |
| 351 | + type: "tool", |
| 352 | + callID: "call-1", |
| 353 | + tool: "provider-tool", |
| 354 | + providerExecuted: true, |
| 355 | + state: { status: "completed", input: {}, output: "result" }, |
| 356 | + }, |
| 357 | + ]); |
| 358 | + const second = assistant("a-tail", 2, [ |
| 359 | + { type: "thinking", thinking: "second signed trace", signature: "sig-b" }, |
| 360 | + ]); |
| 361 | + |
| 362 | + expect(validateAnthropicReasoningRuns([first, second])).toBe(false); |
| 363 | + }); |
| 364 | + |
301 | 365 | test("serves an Anthropic replay with one leading thinking block in an assistant run", () => { |
302 | 366 | resetLkgSlotsForTest(); |
303 | 367 | captureSlot("anthropic-valid", { |
|
0 commit comments