-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsync-version.test.js
More file actions
74 lines (63 loc) · 4.34 KB
/
Copy pathsync-version.test.js
File metadata and controls
74 lines (63 loc) · 4.34 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
import assert from "node:assert/strict";
import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { syncVersion } from "../scripts/sync-version.mjs";
test("syncVersion stamps package and plugin manifests from the authoritative root version", async () => {
const repo = await mkdtemp(join(tmpdir(), "superloopy-sync-version-"));
await mkdir(join(repo, ".codex-plugin"), { recursive: true });
await writeFile(join(repo, "package.json"), `${JSON.stringify({ name: "superloopy", version: "0.2.0" }, null, 2)}\n`);
await writeFile(
join(repo, "package-lock.json"),
`${JSON.stringify({ name: "superloopy", version: "0.1.0", packages: { "": { name: "superloopy", version: "0.1.0" } } }, null, 2)}\n`
);
await writeFile(join(repo, ".codex-plugin", "plugin.json"), `${JSON.stringify({ name: "superloopy", version: "0.1.0" }, null, 2)}\n`);
const result = await syncVersion({ repoRoot: repo });
assert.equal(result.version, "0.2.0");
assert.deepEqual(result.changed, [join(repo, ".codex-plugin", "plugin.json"), join(repo, "package-lock.json")]);
assert.equal(JSON.parse(await readFile(join(repo, "package.json"), "utf8")).version, "0.2.0");
const packageLock = JSON.parse(await readFile(join(repo, "package-lock.json"), "utf8"));
assert.equal(packageLock.version, "0.2.0");
assert.equal(packageLock.packages[""].version, "0.2.0");
assert.equal(JSON.parse(await readFile(join(repo, ".codex-plugin", "plugin.json"), "utf8")).version, "0.2.0");
});
test("syncVersion honors an explicit release version", async () => {
const repo = await mkdtemp(join(tmpdir(), "superloopy-sync-version-explicit-"));
await mkdir(join(repo, ".codex-plugin"), { recursive: true });
await writeFile(join(repo, "package.json"), `${JSON.stringify({ name: "superloopy", version: "0.1.0" }, null, 2)}\n`);
await writeFile(
join(repo, "package-lock.json"),
`${JSON.stringify({ name: "superloopy", version: "0.1.0", packages: { "": { name: "superloopy", version: "0.1.0" } } }, null, 2)}\n`
);
await writeFile(join(repo, ".codex-plugin", "plugin.json"), `${JSON.stringify({ name: "superloopy", version: "0.1.0" }, null, 2)}\n`);
const result = await syncVersion({ repoRoot: repo, version: "0.3.0" });
assert.equal(result.version, "0.3.0");
assert.equal(JSON.parse(await readFile(join(repo, "package.json"), "utf8")).version, "0.3.0");
const packageLock = JSON.parse(await readFile(join(repo, "package-lock.json"), "utf8"));
assert.equal(packageLock.version, "0.3.0");
assert.equal(packageLock.packages[""].version, "0.3.0");
assert.equal(JSON.parse(await readFile(join(repo, ".codex-plugin", "plugin.json"), "utf8")).version, "0.3.0");
});
test("syncVersion stamps the Claude plugin manifest and the marketplace plugins[].version", async () => {
const repo = await mkdtemp(join(tmpdir(), "superloopy-sync-version-claude-"));
await mkdir(join(repo, ".codex-plugin"), { recursive: true });
await mkdir(join(repo, ".claude-plugin"), { recursive: true });
await writeFile(join(repo, "package.json"), `${JSON.stringify({ name: "superloopy", version: "0.4.0" }, null, 2)}\n`);
await writeFile(join(repo, ".codex-plugin", "plugin.json"), `${JSON.stringify({ name: "superloopy", version: "0.1.0" }, null, 2)}\n`);
await writeFile(join(repo, ".claude-plugin", "plugin.json"), `${JSON.stringify({ name: "superloopy", version: "0.1.0" }, null, 2)}\n`);
await writeFile(
join(repo, ".claude-plugin", "marketplace.json"),
`${JSON.stringify({ name: "beefiker", plugins: [{ name: "superloopy", version: "0.1.0" }] }, null, 2)}\n`
);
const result = await syncVersion({ repoRoot: repo });
assert.equal(result.version, "0.4.0");
assert.ok(result.changed.includes(join(repo, ".claude-plugin", "plugin.json")));
assert.ok(result.changed.includes(join(repo, ".claude-plugin", "marketplace.json")));
assert.equal(JSON.parse(await readFile(join(repo, ".claude-plugin", "plugin.json"), "utf8")).version, "0.4.0");
const marketplace = JSON.parse(await readFile(join(repo, ".claude-plugin", "marketplace.json"), "utf8"));
assert.equal(marketplace.plugins[0].version, "0.4.0");
// Idempotent: a second run makes no further changes.
const again = await syncVersion({ repoRoot: repo });
assert.doesNotMatch(JSON.stringify(again.changed), /marketplace\.json/);
});