forked from laurentenhoor/devclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.test.ts
More file actions
60 lines (52 loc) · 2.19 KB
/
version.test.ts
File metadata and controls
60 lines (52 loc) · 2.19 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
/**
* version.test.ts — Tests for version tracking.
*
* Run: npx tsx --test lib/setup/version.test.ts
*/
import { describe, it, afterEach } from "node:test";
import assert from "node:assert";
import fs from "node:fs/promises";
import path from "node:path";
import os from "node:os";
import { getCurrentVersion, readVersionFile, writeVersionFile, detectUpgrade } from "./version.js";
let tmpDir: string;
afterEach(async () => {
if (tmpDir) await fs.rm(tmpDir, { recursive: true, force: true });
});
describe("version tracking", () => {
it("getCurrentVersion returns a non-empty string", () => {
const version = getCurrentVersion();
assert.ok(version.length > 0);
assert.ok(/^\d+\.\d+\.\d+/.test(version), `Expected semver, got: ${version}`);
});
it("readVersionFile returns null when no file exists", async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-ver-test-"));
const result = await readVersionFile(tmpDir);
assert.strictEqual(result, null);
});
it("writeVersionFile creates a .version file", async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-ver-test-"));
await writeVersionFile(tmpDir);
const content = await fs.readFile(path.join(tmpDir, ".version"), "utf-8");
assert.strictEqual(content.trim(), getCurrentVersion());
});
it("detectUpgrade returns null on first run", async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-ver-test-"));
const result = await detectUpgrade(tmpDir);
assert.strictEqual(result, null);
});
it("detectUpgrade returns null when versions match", async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-ver-test-"));
await writeVersionFile(tmpDir);
const result = await detectUpgrade(tmpDir);
assert.strictEqual(result, null);
});
it("detectUpgrade detects version change", async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-ver-test-"));
await fs.writeFile(path.join(tmpDir, ".version"), "1.0.0\n", "utf-8");
const result = await detectUpgrade(tmpDir);
assert.ok(result !== null);
assert.strictEqual(result!.from, "1.0.0");
assert.strictEqual(result!.to, getCurrentVersion());
});
});