|
| 1 | +import * as assert from "assert" |
| 2 | +import * as fs from "fs/promises" |
| 3 | +import * as os from "os" |
| 4 | +import * as path from "path" |
| 5 | + |
| 6 | +import * as vscode from "vscode" |
| 7 | + |
| 8 | +import { setDefaultSuiteTimeout } from "./test-utils" |
| 9 | + |
| 10 | +function makeHandoff(overrides: Record<string, unknown> = {}) { |
| 11 | + return { |
| 12 | + schemaVersion: 1, |
| 13 | + createdAt: new Date().toISOString(), |
| 14 | + source: { |
| 15 | + extensionId: "RooVeterinaryInc.roo-cline", |
| 16 | + publisher: "RooVeterinaryInc", |
| 17 | + name: "roo-cline", |
| 18 | + version: "3.53.1", |
| 19 | + globalStoragePath: "", |
| 20 | + storageBasePath: "", |
| 21 | + }, |
| 22 | + zoo: { |
| 23 | + repositoryUrl: "https://github.com/Zoo-Code-Org/Zoo-Code", |
| 24 | + announcementUrl: "", |
| 25 | + extensionId: "ZooCodeOrganization.zoo-code", |
| 26 | + }, |
| 27 | + containsSecrets: false, |
| 28 | + globalSettings: {}, |
| 29 | + vscodeConfiguration: {}, |
| 30 | + copiedData: {}, |
| 31 | + ...overrides, |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +suite("Roo Import", function () { |
| 36 | + setDefaultSuiteTimeout(this) |
| 37 | + |
| 38 | + let tmpDir: string |
| 39 | + |
| 40 | + suiteSetup(async () => { |
| 41 | + tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "zoo-e2e-roo-import-")) |
| 42 | + }) |
| 43 | + |
| 44 | + suiteTeardown(async () => { |
| 45 | + await fs.rm(tmpDir, { recursive: true, force: true }) |
| 46 | + }) |
| 47 | + |
| 48 | + test("importRooHandoff command is registered", async () => { |
| 49 | + const commands = await vscode.commands.getCommands(true) |
| 50 | + assert.ok( |
| 51 | + commands.includes("roo-cline.importRooHandoff"), |
| 52 | + "roo-cline.importRooHandoff should be a registered command", |
| 53 | + ) |
| 54 | + }) |
| 55 | + |
| 56 | + test("imports a valid handoff and copies tasks", async () => { |
| 57 | + const api = globalThis.api |
| 58 | + const storagePath = api.storagePath |
| 59 | + |
| 60 | + // Build a minimal handoff with one task directory. |
| 61 | + const handoffDir = path.join(tmpDir, "handoff") |
| 62 | + const tasksSource = path.join(handoffDir, "data", "tasks") |
| 63 | + const taskId = `e2e-test-task-${Date.now()}` |
| 64 | + await fs.mkdir(path.join(tasksSource, taskId), { recursive: true }) |
| 65 | + await fs.writeFile(path.join(tasksSource, taskId, "history_item.json"), JSON.stringify({ id: taskId })) |
| 66 | + |
| 67 | + const handoffPath = path.join(handoffDir, "handoff-v1.json") |
| 68 | + await fs.writeFile(handoffPath, JSON.stringify(makeHandoff({ copiedData: { tasks: "data/tasks" } }))) |
| 69 | + |
| 70 | + // Execute the command with an explicit path to skip the file picker. |
| 71 | + const result = await vscode.commands.executeCommand<{ success: boolean; tasksCopied?: number; error?: string }>( |
| 72 | + "roo-cline.importRooHandoff", |
| 73 | + handoffPath, |
| 74 | + ) |
| 75 | + |
| 76 | + assert.ok(result, "Command should return a result") |
| 77 | + assert.strictEqual(result.success, true, `Import should succeed (error: ${result.error})`) |
| 78 | + assert.strictEqual(result.tasksCopied, 1, "One task should have been copied") |
| 79 | + |
| 80 | + // Verify the task directory was actually written to Zoo's storage. |
| 81 | + const copiedTaskFile = path.join(storagePath, "tasks", taskId, "history_item.json") |
| 82 | + const contents = JSON.parse(await fs.readFile(copiedTaskFile, "utf-8")) |
| 83 | + assert.strictEqual(contents.id, taskId, "Task file content should match what was exported") |
| 84 | + }) |
| 85 | + |
| 86 | + test("skips import when handoff was already imported", async () => { |
| 87 | + const handoffPath = path.join(tmpDir, "handoff-duplicate.json") |
| 88 | + const createdAt = new Date().toISOString() |
| 89 | + await fs.writeFile(handoffPath, JSON.stringify(makeHandoff({ createdAt }))) |
| 90 | + |
| 91 | + // First import. |
| 92 | + const first = await vscode.commands.executeCommand<{ success: boolean }>( |
| 93 | + "roo-cline.importRooHandoff", |
| 94 | + handoffPath, |
| 95 | + ) |
| 96 | + assert.ok(first?.success, "First import should succeed") |
| 97 | + |
| 98 | + // Second import of the same handoff should also succeed (command accepts an |
| 99 | + // explicit path so it doesn't check the "already imported" state — that check |
| 100 | + // only runs in the activation notice path). Verify the command at least runs |
| 101 | + // without throwing. |
| 102 | + const second = await vscode.commands.executeCommand<{ success: boolean }>( |
| 103 | + "roo-cline.importRooHandoff", |
| 104 | + handoffPath, |
| 105 | + ) |
| 106 | + assert.ok(second?.success, "Re-running the command with the same file should still succeed") |
| 107 | + }) |
| 108 | +}) |
0 commit comments