| |
| |
| |
| |
| |
| import "./run.overflow-compaction.mocks.shared.js"; |
| import { beforeEach, describe, expect, it, vi } from "vitest"; |
| import { runEmbeddedPiAgent } from "./run.js"; |
| import { makeAttemptResult } from "./run.overflow-compaction.fixture.js"; |
| import { mockedGlobalHookRunner } from "./run.overflow-compaction.mocks.shared.js"; |
| import { |
| mockedRunEmbeddedAttempt, |
| overflowBaseRunParams, |
| } from "./run.overflow-compaction.shared-test.js"; |
| import { isEmbeddedPiRunActive, queueEmbeddedPiMessage } from "./runs.js"; |
|
|
| describe("sessions_yield orchestration", () => { |
| beforeEach(() => { |
| vi.clearAllMocks(); |
| mockedGlobalHookRunner.hasHooks.mockImplementation(() => false); |
| }); |
|
|
| it("parent session is idle after yield — end_turn, no pendingToolCalls", async () => { |
| const sessionId = "yield-parent-session"; |
|
|
| |
| mockedRunEmbeddedAttempt.mockResolvedValueOnce( |
| makeAttemptResult({ |
| promptError: null, |
| sessionIdUsed: sessionId, |
| yieldDetected: true, |
| }), |
| ); |
|
|
| const result = await runEmbeddedPiAgent({ |
| ...overflowBaseRunParams, |
| sessionId, |
| runId: "run-yield-orchestration", |
| }); |
|
|
| |
| expect(result.meta.stopReason).toBe("end_turn"); |
|
|
| |
| expect(result.meta.pendingToolCalls).toBeUndefined(); |
|
|
| |
| expect(isEmbeddedPiRunActive(sessionId)).toBe(false); |
|
|
| |
| expect(queueEmbeddedPiMessage(sessionId, "subagent result")).toBe(false); |
| }); |
|
|
| it("clientToolCall takes precedence over yieldDetected", async () => { |
| |
| mockedRunEmbeddedAttempt.mockResolvedValueOnce( |
| makeAttemptResult({ |
| promptError: null, |
| yieldDetected: true, |
| clientToolCall: { name: "hosted_tool", params: { arg: "value" } }, |
| }), |
| ); |
|
|
| const result = await runEmbeddedPiAgent({ |
| ...overflowBaseRunParams, |
| runId: "run-yield-vs-client-tool", |
| }); |
|
|
| |
| expect(result.meta.stopReason).toBe("tool_calls"); |
| expect(result.meta.pendingToolCalls).toHaveLength(1); |
| expect(result.meta.pendingToolCalls![0].name).toBe("hosted_tool"); |
| }); |
|
|
| it("normal attempt without yield has no stopReason override", async () => { |
| mockedRunEmbeddedAttempt.mockResolvedValueOnce(makeAttemptResult({ promptError: null })); |
|
|
| const result = await runEmbeddedPiAgent({ |
| ...overflowBaseRunParams, |
| runId: "run-no-yield", |
| }); |
|
|
| |
| expect(result.meta.stopReason).toBeUndefined(); |
| expect(result.meta.pendingToolCalls).toBeUndefined(); |
| }); |
| }); |
|
|