forked from laurentenhoor/devclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.test.ts
More file actions
58 lines (50 loc) · 1.89 KB
/
instance.test.ts
File metadata and controls
58 lines (50 loc) · 1.89 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
import { describe, it, expect, afterEach } from "vitest";
import fs from "node:fs/promises";
import path from "node:path";
import os from "node:os";
import { loadInstanceName } from "./instance.js";
import { DATA_DIR } from "./setup/migrate-layout.js";
describe("loadInstanceName", () => {
let tmpDir: string;
async function createWorkspace(): Promise<string> {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-instance-test-"));
await fs.mkdir(path.join(tmpDir, DATA_DIR), { recursive: true });
return tmpDir;
}
afterEach(async () => {
if (tmpDir) {
await fs.rm(tmpDir, { recursive: true, force: true });
}
});
it("auto-generates and persists a name on first call", async () => {
const ws = await createWorkspace();
const name = await loadInstanceName(ws);
expect(name).toBeTruthy();
expect(typeof name).toBe("string");
// Persisted to file
const raw = await fs.readFile(path.join(ws, DATA_DIR, "instance.json"), "utf-8");
const data = JSON.parse(raw);
expect(data.name).toBe(name);
expect(data.createdAt).toBeTruthy();
});
it("returns the same name on subsequent calls", async () => {
const ws = await createWorkspace();
const first = await loadInstanceName(ws);
const second = await loadInstanceName(ws);
expect(first).toBe(second);
});
it("uses config override when provided", async () => {
const ws = await createWorkspace();
const name = await loadInstanceName(ws, "CustomBot");
expect(name).toBe("CustomBot");
});
it("config override takes precedence over persisted name", async () => {
const ws = await createWorkspace();
// Generate and persist a name
const autoName = await loadInstanceName(ws);
// Override should win
const overrideName = await loadInstanceName(ws, "Override");
expect(overrideName).toBe("Override");
expect(overrideName).not.toBe(autoName);
});
});