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