|
| 1 | +// cd src && npx vitest run core/task-persistence/__tests__/taskMetadata.spec.ts |
| 2 | +// |
| 3 | +// DTE series 2/5: taskMetadata() persists the active task-local thinking effort |
| 4 | +// (and its provenance) on the history item via |
| 5 | +// ...(thinkingEffort && { thinkingEffort }), |
| 6 | +// ...(thinkingEffortSource && { thinkingEffortSource }), |
| 7 | +// so that reopening the task from history restores it. |
| 8 | +// |
| 9 | +// These tests drive the real taskMetadata() with both truthy and falsy effort |
| 10 | +// values so both sides of the logical-AND spread are covered. |
| 11 | +import { describe, it, expect, vi, beforeEach } from "vitest" |
| 12 | +import * as os from "os" |
| 13 | +import * as path from "path" |
| 14 | +import * as fs from "fs/promises" |
| 15 | + |
| 16 | +import type { ClineMessage, ReasoningEffortExtended } from "@roo-code/types" |
| 17 | + |
| 18 | +vi.mock("get-folder-size", () => ({ |
| 19 | + __esModule: true, |
| 20 | + default: { loose: vi.fn().mockResolvedValue(0) }, |
| 21 | +})) |
| 22 | +vi.mock("../../../utils/storage", () => ({ |
| 23 | + getTaskDirectoryPath: vi |
| 24 | + .fn() |
| 25 | + .mockImplementation((globalStoragePath, taskId) => Promise.resolve(`${globalStoragePath}/tasks/${taskId}`)), |
| 26 | +})) |
| 27 | + |
| 28 | +// Import after mocks |
| 29 | +import { taskMetadata } from "../taskMetadata" |
| 30 | + |
| 31 | +let tmpBaseDir: string |
| 32 | + |
| 33 | +beforeEach(async () => { |
| 34 | + // Unique writable temp dir as the global storage path (mirrors taskMessages.spec.ts). |
| 35 | + tmpBaseDir = await fs.mkdtemp(path.join(os.tmpdir(), "roo-taskmetadata-")) |
| 36 | +}) |
| 37 | + |
| 38 | +function taskSayMessage(text: string): ClineMessage { |
| 39 | + return { |
| 40 | + ts: 1_700_000_000_000, |
| 41 | + type: "say", |
| 42 | + say: "task", |
| 43 | + text, |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +async function runMetadata(overrides: { thinkingEffort?: ReasoningEffortExtended; thinkingEffortSource?: string }) { |
| 48 | + return taskMetadata({ |
| 49 | + taskId: "task-meta-1", |
| 50 | + taskNumber: 7, |
| 51 | + messages: [taskSayMessage("Do the thing")], |
| 52 | + globalStoragePath: tmpBaseDir, |
| 53 | + workspace: "workspace", |
| 54 | + ...overrides, |
| 55 | + }) |
| 56 | +} |
| 57 | + |
| 58 | +describe("taskMetadata thinkingEffort persistence", () => { |
| 59 | + it("omits the effort fields from the history item when not provided", async () => { |
| 60 | + const { historyItem } = await runMetadata({}) |
| 61 | + |
| 62 | + expect(historyItem.thinkingEffort).toBeUndefined() |
| 63 | + expect(historyItem.thinkingEffortSource).toBeUndefined() |
| 64 | + // The rest of the history item is still written. |
| 65 | + expect(historyItem.id).toBe("task-meta-1") |
| 66 | + expect(historyItem.task).toBe("Do the thing") |
| 67 | + }) |
| 68 | + |
| 69 | + it("persists the effort and its provenance on the history item when provided", async () => { |
| 70 | + const { historyItem } = await runMetadata({ thinkingEffort: "low", thinkingEffortSource: "you" }) |
| 71 | + |
| 72 | + expect(historyItem.thinkingEffort).toBe("low") |
| 73 | + expect(historyItem.thinkingEffortSource).toBe("you") |
| 74 | + }) |
| 75 | +}) |
0 commit comments