|
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | + |
| 3 | +vi.mock("@atlas/integrations", () => ({ |
| 4 | + interpretWriteTurnWithResponses: vi.fn(), |
| 5 | +})); |
| 6 | + |
| 7 | +import { interpretWriteTurnWithResponses } from "@atlas/integrations"; |
| 8 | + |
| 9 | +import { interpretWriteTurn } from "./interpret-write-turn"; |
| 10 | + |
| 11 | +const mockInterpretWriteTurnWithResponses = vi.mocked( |
| 12 | + interpretWriteTurnWithResponses, |
| 13 | +); |
| 14 | + |
| 15 | +beforeEach(() => { |
| 16 | + vi.clearAllMocks(); |
| 17 | +}); |
| 18 | + |
| 19 | +describe("interpretWriteTurn", () => { |
| 20 | + it("forwards entityContext to the integrations layer", async () => { |
| 21 | + mockInterpretWriteTurnWithResponses.mockResolvedValueOnce({ |
| 22 | + operationKind: "plan", |
| 23 | + actionDomain: "task", |
| 24 | + targetRef: { entityId: "task-1", description: null, entityKind: null }, |
| 25 | + taskName: null, |
| 26 | + fields: { |
| 27 | + scheduleFields: null, |
| 28 | + taskFields: null, |
| 29 | + }, |
| 30 | + confidence: {}, |
| 31 | + unresolvedFields: [], |
| 32 | + }); |
| 33 | + |
| 34 | + await interpretWriteTurn({ |
| 35 | + currentTurnText: "move gym", |
| 36 | + turnType: "edit_request", |
| 37 | + entityContext: 'Known entities:\n- "Gym" (task, scheduled) [id: task-1]', |
| 38 | + }); |
| 39 | + |
| 40 | + expect(mockInterpretWriteTurnWithResponses).toHaveBeenCalledWith( |
| 41 | + expect.objectContaining({ |
| 42 | + entityContext: |
| 43 | + 'Known entities:\n- "Gym" (task, scheduled) [id: task-1]', |
| 44 | + }), |
| 45 | + undefined, |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + it("falls back cleanly when the integrations layer returns malformed output", async () => { |
| 50 | + mockInterpretWriteTurnWithResponses.mockResolvedValueOnce({ |
| 51 | + operationKind: "plan", |
| 52 | + actionDomain: "task", |
| 53 | + targetRef: null, |
| 54 | + taskName: null, |
| 55 | + fields: { |
| 56 | + scheduleFields: null, |
| 57 | + taskFields: null, |
| 58 | + }, |
| 59 | + confidence: { |
| 60 | + bad: 2, |
| 61 | + }, |
| 62 | + unresolvedFields: [], |
| 63 | + } as never); |
| 64 | + |
| 65 | + await expect( |
| 66 | + interpretWriteTurn({ |
| 67 | + currentTurnText: "schedule gym", |
| 68 | + turnType: "planning_request", |
| 69 | + }), |
| 70 | + ).resolves.toMatchObject({ |
| 71 | + operationKind: "plan", |
| 72 | + targetRef: null, |
| 73 | + sourceText: "schedule gym", |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments