kaizen-agent 1.64.2 → 1.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/install.ts +18 -1
- package/cli/roadmap.ts +74 -0
- package/cli/skills.ts +3 -3
- package/cli/web.ts +55 -1
- package/commands/kaizen-concept.md +6 -0
- package/commands/kaizen-plan.md +1 -1
- package/commands/kaizen-roadmap.md +6 -0
- package/package.json +4 -2
- package/skills/kaizen/SKILL.md +19 -5
- package/skills/kaizen/config.default.yml +2 -2
- package/skills/kaizen/roadmap.md +25 -0
- package/skills/kaizen/settings.md +4 -0
- package/skills/kaizen/spec-main.md +27 -0
- package/skills/kaizen/spec-plan.md +37 -11
- package/skills/kaizen-concept/SKILL.md +262 -0
- package/skills/kaizen-concept/skill.json +1 -0
- package/skills/kaizen-help/SKILL.md +14 -89
- package/skills/media/kaizen-book/skill.json +1 -1
- package/skills/media/kaizen-deck/SKILL.md +2 -3
- package/skills/media/kaizen-deck/skill.json +1 -1
- package/skills/media/kaizen-video/SKILL.md +2 -2
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/promo.json +3 -3
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/record.json +1 -1
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/seed.php +1 -1
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/seed.py +1 -1
- package/skills/media/kaizen-video/references/licensing.md +1 -1
- package/skills/media/kaizen-video/references/promo.md +2 -2
- package/skills/media/kaizen-video/skill.json +1 -1
- package/skills/optional/kaizen-computer/skill.json +1 -1
- package/web/board/chat.ts +4 -3
- package/web/board/run-view.ts +18 -3
- package/web/board/settings-skills.ts +2 -2
- package/web/board/ws-tabs.ts +9 -0
- package/web/board.html +1 -1
- package/web/board.js +102 -102
- package/web/notebook.js +1 -1
- package/web/term.js +1 -1
- package/web/video.js +1 -1
- package/cli/__pycache__/computer-helper.cpython-314.pyc +0 -0
- package/cli/accounts.test.ts +0 -126
- package/cli/add-project.test.ts +0 -169
- package/cli/agent-prefs.test.ts +0 -127
- package/cli/automations.test.ts +0 -167
- package/cli/backlog.test.ts +0 -133
- package/cli/board.test.ts +0 -381
- package/cli/browser.test.ts +0 -132
- package/cli/chat.test.ts +0 -274
- package/cli/chatgpt.test.ts +0 -158
- package/cli/computer.test.ts +0 -155
- package/cli/docs.test.ts +0 -94
- package/cli/handoff.test.ts +0 -133
- package/cli/html.test.ts +0 -19
- package/cli/install.test.ts +0 -237
- package/cli/knowledge.test.ts +0 -179
- package/cli/localsend.test.ts +0 -84
- package/cli/logo.test.ts +0 -18
- package/cli/notes.test.ts +0 -249
- package/cli/onboarding.test.ts +0 -70
- package/cli/project-tree.test.ts +0 -40
- package/cli/pty.test.ts +0 -330
- package/cli/release.test.ts +0 -12
- package/cli/report.test.ts +0 -59
- package/cli/resources.test.ts +0 -50
- package/cli/restart.test.ts +0 -222
- package/cli/settings.test.ts +0 -153
- package/cli/setup.test.ts +0 -78
- package/cli/shell-agent.test.ts +0 -23
- package/cli/skills.test.ts +0 -89
- package/cli/sources.test.ts +0 -851
- package/cli/state.test.ts +0 -1639
- package/cli/term-image.test.ts +0 -23
- package/cli/usage.test.ts +0 -291
- package/cli/versions.test.ts +0 -154
- package/cli/video.test.ts +0 -545
- package/cli/web-accept.test.ts +0 -55
- package/cli/web-decide.test.ts +0 -54
- package/cli/web-pr.test.ts +0 -52
- package/cli/web-skills.test.ts +0 -32
- package/cli/web-symlink.test.ts +0 -29
- package/cli/workers.test.ts +0 -319
- package/cli/worktree.test.ts +0 -452
- package/cli/writeback.test.ts +0 -102
- package/skills/media/kaizen-video/scripts/__pycache__/intake.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/make_film.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/make_tiktok.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/render_cut.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/sfx.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/srt.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/transcribe.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/vo.cpython-314.pyc +0 -0
- package/web/board/search.test.ts +0 -20
- package/web/board/settings-pages.test.ts +0 -28
- package/web/board/settings-voice.test.ts +0 -18
- package/web/board/toast.test.ts +0 -77
- package/web/board/ws-board.test.ts +0 -77
- package/web/board/ws-name.test.ts +0 -10
- package/web/board/ws-tabs.test.ts +0 -213
- package/web/term-font.test.ts +0 -22
package/cli/term-image.test.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { existsSync, mkdtempSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { imageExt, MAX_IMAGE, saveImage } from "./term-image.ts";
|
|
6
|
-
|
|
7
|
-
const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a]);
|
|
8
|
-
|
|
9
|
-
test("the type comes from the bytes", () => {
|
|
10
|
-
expect(imageExt(png)).toBe("png");
|
|
11
|
-
expect(imageExt(new TextEncoder().encode("RIFF0000WEBP"))).toBe("webp");
|
|
12
|
-
expect(imageExt(new TextEncoder().encode("<svg onload=x>"))).toBeNull();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("saves an image and refuses the rest", () => {
|
|
16
|
-
const dir = mkdtempSync(join(tmpdir(), "kz-img-"));
|
|
17
|
-
const f = saveImage(png, dir)!;
|
|
18
|
-
expect(f.endsWith(".png") && existsSync(f)).toBe(true);
|
|
19
|
-
expect(saveImage(new Uint8Array(4), dir)).toBeNull();
|
|
20
|
-
const big = new Uint8Array(MAX_IMAGE + 1);
|
|
21
|
-
big.set(png);
|
|
22
|
-
expect(saveImage(big, dir)).toBeNull();
|
|
23
|
-
});
|
package/cli/usage.test.ts
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
// The footer's usage and phone readers, and the run workspace's /shell route on a real
|
|
2
|
-
// board: guarded like /pty, an agent only from the known list, a pwd in the project.
|
|
3
|
-
import { test, expect } from "bun:test";
|
|
4
|
-
import { mkdtempSync, mkdirSync, writeFileSync, realpathSync, utimesSync, rmSync, readFileSync, symlinkSync, existsSync } from "node:fs";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { codexUsage, claudeUsage, phonePeers } from "./usage.ts";
|
|
8
|
-
|
|
9
|
-
const root = realpathSync(mkdtempSync(join(tmpdir(), "kaizen-usage-")));
|
|
10
|
-
const rl = (p: number, s: number) => JSON.stringify({ type: "event_msg", payload: { type: "token_count", rate_limits: { primary: { used_percent: p, window_minutes: 300, resets_at: 1800000000 }, secondary: { used_percent: s, window_minutes: 10080, resets_at: 1800500000 } } } });
|
|
11
|
-
|
|
12
|
-
test("codexUsage: the newest rollout's last rate_limits, windows by length; nothing when absent", () => {
|
|
13
|
-
const h = join(root, "codex");
|
|
14
|
-
expect(codexUsage(h)).toBeNull();
|
|
15
|
-
const d = join(h, ".codex", "sessions", "2026", "10", "28");
|
|
16
|
-
mkdirSync(d, { recursive: true });
|
|
17
|
-
const old = join(d, "rollout-a.jsonl"), nu = join(d, "rollout-b.jsonl");
|
|
18
|
-
writeFileSync(old, rl(99, 99) + "\n");
|
|
19
|
-
writeFileSync(nu, rl(10, 20) + "\n" + rl(42, 7) + "\n{\"torn");
|
|
20
|
-
utimesSync(old, new Date(1000), new Date(1000));
|
|
21
|
-
expect(codexUsage(h)).toEqual({ agent: "codex", five: { pct: 42, resetsAt: 1800000000000 }, week: { pct: 7, resetsAt: 1800500000000 } });
|
|
22
|
-
// A session just started, no rate_limits yet: the one before it still counts.
|
|
23
|
-
writeFileSync(nu, '{"type":"session_meta"}\n');
|
|
24
|
-
expect(codexUsage(h)?.five?.pct).toBe(99);
|
|
25
|
-
writeFileSync(old, '{"type":"session_meta"}\n');
|
|
26
|
-
expect(codexUsage(h)).toBeNull();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("claudeUsage: maps the windows; a failure is an error that never carries the token", async () => {
|
|
30
|
-
const h = join(root, "claude");
|
|
31
|
-
expect(await claudeUsage(h, (() => { throw new Error("no call"); }) as any)).toBeNull();
|
|
32
|
-
mkdirSync(join(h, ".claude"), { recursive: true });
|
|
33
|
-
writeFileSync(join(h, ".claude", ".credentials.json"), JSON.stringify({ claudeAiOauth: { accessToken: "sk-ant-oat-SECRET" } }));
|
|
34
|
-
let sent: any;
|
|
35
|
-
const ok = (async (_u: string, init: any) => { sent = init; return new Response(JSON.stringify({ five_hour: { utilization: 62, resets_at: "2026-10-28T12:00:00Z" }, seven_day: { utilization: 34.4, resets_at: null } })); }) as any;
|
|
36
|
-
expect(await claudeUsage(h, ok)).toEqual({ agent: "claude", five: { pct: 62, resetsAt: Date.parse("2026-10-28T12:00:00Z") }, week: { pct: 34, resetsAt: null } });
|
|
37
|
-
expect(sent.headers["anthropic-beta"]).toBe("oauth-2025-04-20");
|
|
38
|
-
const fail = (async () => { throw new Error("refused Bearer sk-ant-oat-SECRET"); }) as any;
|
|
39
|
-
const e = await claudeUsage(h, fail);
|
|
40
|
-
expect(e).toHaveProperty("error");
|
|
41
|
-
expect(JSON.stringify(e)).not.toContain("SECRET");
|
|
42
|
-
expect(await claudeUsage(h, (async () => new Response("", { status: 401 })) as any)).toEqual({ agent: "claude", error: "HTTP 401", expired: true });
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("phonePeers: online, offline, no phone, not running", () => {
|
|
46
|
-
const st = (peers: object, state = "Running") => JSON.stringify({ BackendState: state, Peer: peers });
|
|
47
|
-
expect(phonePeers(st({ a: { OS: "iOS", HostName: "iphone", Online: true }, b: { OS: "linux", HostName: "pc", DNSName: "pc.tail1.ts.net.", Online: true } }))).toEqual({ running: true, phones: [{ name: "iphone", online: true }], computers: [{ name: "pc", dns: "pc.tail1.ts.net", os: "linux", online: true }], self: null });
|
|
48
|
-
const me = JSON.stringify({ BackendState: "Running", Self: { OS: "linux", HostName: "me", DNSName: "me.ts.net." }, Peer: { m: { OS: "macOS", HostName: "mac", Online: false } } });
|
|
49
|
-
expect(phonePeers(me).self).toEqual({ name: "me", dns: "me.ts.net", os: "linux", online: true });
|
|
50
|
-
expect(phonePeers(me).computers).toEqual([{ name: "mac", dns: "", os: "macOS", online: false }]);
|
|
51
|
-
expect(phonePeers(st({ a: { OS: "android", HostName: "pixel", Online: false } })).phones).toEqual([{ name: "pixel", online: false }]);
|
|
52
|
-
expect(phonePeers(st({ b: { OS: "windows", Online: true } })).phones).toEqual([]);
|
|
53
|
-
expect(phonePeers(st({}, "Stopped")).running).toBe(false);
|
|
54
|
-
expect(phonePeers("").running).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test.skipIf(process.platform === "win32")("/shell: foreign origin, unknown project and unknown agent refused; a shell opens in the project; /usage and /phone answer", async () => {
|
|
58
|
-
const homeDir = join(root, "home"), proj = join(homeDir, "a"), st = join(proj, ".kaizen"), bin = join(root, "bin");
|
|
59
|
-
for (const d of [st, join(homeDir, ".kaizen"), bin]) mkdirSync(d, { recursive: true });
|
|
60
|
-
writeFileSync(join(homeDir, ".kaizen", "projects"), proj + "\n");
|
|
61
|
-
writeFileSync(join(st, "inbox.md"), "# Inbox\n");
|
|
62
|
-
// A shell that says where it is, then echoes.
|
|
63
|
-
const sh = join(bin, "fakesh");
|
|
64
|
-
writeFileSync(sh, '#!/bin/sh\necho "pwd:$(pwd)"\nwhile read x; do echo "got:$x"; done\n', { mode: 0o755 });
|
|
65
|
-
// Some agent must exist for the board to start; not claude or codex, so /usage has none.
|
|
66
|
-
writeFileSync(join(bin, "gemini"), "#!/bin/sh\n", { mode: 0o755 });
|
|
67
|
-
symlinkSync(Bun.which("git")!, join(bin, "git"));
|
|
68
|
-
const port = 20000 + Math.floor(Math.random() * 20000);
|
|
69
|
-
const repo = join(import.meta.dir, "..");
|
|
70
|
-
// PATH without tailscale, claude or codex: /phone and /usage must still answer.
|
|
71
|
-
const proc = Bun.spawn([process.execPath, join(repo, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
|
|
72
|
-
cwd: proj, stdout: "ignore", stderr: "ignore",
|
|
73
|
-
env: { ...process.env, HOME: homeDir, USERPROFILE: homeDir, KAIZEN_HOME: repo, PATH: bin, SHELL: sh, DISPLAY: "", WAYLAND_DISPLAY: "", TERMINAL: "", TMUX: "" },
|
|
74
|
-
});
|
|
75
|
-
try {
|
|
76
|
-
const at = `http://127.0.0.1:${port}`;
|
|
77
|
-
for (let i = 0; ; i++) { try { await fetch(at + "/state"); break; } catch { if (i > 100) throw new Error("board did not start"); await Bun.sleep(50); } }
|
|
78
|
-
const post = (body: object, origin?: string, type = "application/json") => fetch(at + "/shell", { method: "POST", headers: { "content-type": type, ...(origin ? { origin } : {}) }, body: JSON.stringify(body) });
|
|
79
|
-
expect((await post({ dir: st }, "https://evil.example")).status).toBe(403);
|
|
80
|
-
// Another local server's page: same hostname, other port.
|
|
81
|
-
expect((await post({ dir: st }, `http://127.0.0.1:${port + 1}`)).status).toBe(403);
|
|
82
|
-
expect((await post({ dir: st }, "http://localhost:3000")).status).toBe(403);
|
|
83
|
-
// A simple (no-preflight) POST body type.
|
|
84
|
-
expect((await post({ dir: st }, at, "text/plain")).status).toBe(415);
|
|
85
|
-
const kill = (body: object, origin?: string, type = "application/json") => fetch(at + "/pty/kill", { method: "POST", headers: { "content-type": type, ...(origin ? { origin } : {}) }, body: JSON.stringify(body) });
|
|
86
|
-
expect((await kill({ key: "x" }, "https://evil.example")).status).toBe(403);
|
|
87
|
-
expect((await kill({ key: "x" }, at, "text/plain")).status).toBe(415);
|
|
88
|
-
expect((await kill({ key: "no-such" }, at)).status).toBe(404);
|
|
89
|
-
expect((await kill({ key: "../x" }, at)).status).toBe(404);
|
|
90
|
-
const res = await (await fetch(at + "/resources")).json();
|
|
91
|
-
expect(res.system.total).toBeGreaterThan(0);
|
|
92
|
-
expect(res.kaizen).toBeGreaterThan(0);
|
|
93
|
-
const disk = await fetch(at + "/resources/storage");
|
|
94
|
-
expect(disk.status).toBe(200);
|
|
95
|
-
expect(typeof (await disk.json()).scanning).toBe("boolean");
|
|
96
|
-
expect((await post({ dir: join(root, "elsewhere", ".kaizen") })).status).toBe(404);
|
|
97
|
-
expect((await post({ dir: join(homeDir, ".kaizen") })).status).toBe(404);
|
|
98
|
-
expect((await post({ dir: st, agent: "rm -rf /" })).status).toBe(400);
|
|
99
|
-
expect((await post({ dir: st, agent: "codex" })).status).toBe(400); // known, not installed
|
|
100
|
-
|
|
101
|
-
// Resume: the session id comes only from the run's own state.json; a page-sent one is ignored.
|
|
102
|
-
const resume = (run: string, extra = {}) => post({ dir: st, run, resume: true, ...extra }, at);
|
|
103
|
-
mkdirSync(join(st, "runs", "r1"), { recursive: true });
|
|
104
|
-
writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ id: "r1", agent: "claude" }));
|
|
105
|
-
expect((await resume(`run:${st}:r1`, { session: "aaaaaaaa-page-chosen" })).status).toBe(404); // no session recorded
|
|
106
|
-
expect((await resume(`run:${st}:..`)).status).toBe(404);
|
|
107
|
-
expect((await resume(`run:${st}:../r1`)).status).toBe(404);
|
|
108
|
-
expect((await resume(`run:/elsewhere/.kaizen:r1`)).status).toBe(404); // a run of another dir
|
|
109
|
-
writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ id: "r1", agent: "codex", session: "abcdef12-3456" }));
|
|
110
|
-
expect((await resume(`run:${st}:r1`)).status).toBe(404); // not a Claude run
|
|
111
|
-
writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ id: "r1", agent: "claude", session: "abcdef12-3456" }));
|
|
112
|
-
expect((await resume(`run:${st}:r1`)).status).toBe(400); // claude is not on this test's PATH
|
|
113
|
-
|
|
114
|
-
// /open-url: the same guards, and only an http(s) address. No success case: it opens a real window.
|
|
115
|
-
const open = (body: object, origin?: string, type = "application/json") => fetch(at + "/open-url", { method: "POST", headers: { "content-type": type, ...(origin ? { origin } : {}) }, body: JSON.stringify(body) });
|
|
116
|
-
expect((await open({ url: "http://localhost:3000/" }, "http://localhost:3000")).status).toBe(403);
|
|
117
|
-
expect((await open({ url: "http://localhost:3000/" }, at, "text/plain")).status).toBe(415);
|
|
118
|
-
expect((await open({ url: "file:///etc/passwd" }, at)).status).toBe(400);
|
|
119
|
-
expect((await open({ url: "javascript:alert(1)" }, at)).status).toBe(400);
|
|
120
|
-
expect((await open({ url: "https://example.com/" }, at)).status).toBe(400); // loopback only
|
|
121
|
-
expect((await open({ url: "http://localhost.evil.test/" }, at)).status).toBe(400);
|
|
122
|
-
// /frameable: board pages only, http(s) only; the answer is a boolean (or null when unreachable).
|
|
123
|
-
expect((await fetch(`${at}/frameable?url=${encodeURIComponent(at + "/")}`, { headers: { origin: "https://evil.example" } })).status).toBe(403);
|
|
124
|
-
expect((await fetch(`${at}/frameable?url=${encodeURIComponent("file:///etc/passwd")}`)).status).toBe(400);
|
|
125
|
-
expect((await fetch(`${at}/frameable?url=${encodeURIComponent("http://example.com/")}`)).status).toBe(400);
|
|
126
|
-
expect(await (await fetch(`${at}/frameable?url=${encodeURIComponent(at + "/")}`)).json()).toEqual({ frameable: true });
|
|
127
|
-
// A loopback page that redirects elsewhere is unknown, and the target is never fetched.
|
|
128
|
-
let hit = 0;
|
|
129
|
-
const far = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => { hit++; return new Response("x"); } });
|
|
130
|
-
const hop = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => Response.redirect(`http://127.0.0.1:${far.port}/`, 302) });
|
|
131
|
-
expect(await (await fetch(`${at}/frameable?url=${encodeURIComponent(`http://127.0.0.1:${hop.port}/`)}`)).json()).toEqual({ frameable: null });
|
|
132
|
-
expect(hit).toBe(0);
|
|
133
|
-
far.stop(true); hop.stop(true);
|
|
134
|
-
|
|
135
|
-
// A workspace folder only from the project's own list (no git on this PATH: the project folder alone).
|
|
136
|
-
expect((await post({ dir: st, ws: root }, at)).status).toBe(400);
|
|
137
|
-
expect((await post({ dir: st, ws: join(proj, "..", "a", "..") }, at)).status).toBe(400);
|
|
138
|
-
expect((await post({ dir: st, ws: ["x"] }, at)).status).toBe(400);
|
|
139
|
-
// /worktree: the same guards; a folder that is not a repository gets none.
|
|
140
|
-
const wt = (body: object, origin?: string) => fetch(at + "/worktree", { method: "POST", headers: { "content-type": "application/json", ...(origin ? { origin } : {}) }, body: JSON.stringify(body) });
|
|
141
|
-
expect((await wt({ dir: st, branch: "x" }, "http://localhost:3000")).status).toBe(403);
|
|
142
|
-
expect((await wt({ dir: join(homeDir, ".kaizen"), branch: "x" })).status).toBe(404);
|
|
143
|
-
expect((await wt({ dir: st, branch: "x" })).status).toBe(400);
|
|
144
|
-
// The rail's + sheet: /add-project, /new-project and /clone start git or make folders, so /worktree's guards and validated input.
|
|
145
|
-
const sheet = (route: string, body: object, origin?: string, type = "application/json") => fetch(at + route, { method: "POST", headers: { "content-type": type, ...(origin ? { origin } : {}) }, body: JSON.stringify(body) });
|
|
146
|
-
const bodies: [string, object][] = [["/add-project", { path: join(homeDir, "z") }], ["/new-project", { name: "z" }], ["/clone", { url: "https://127.0.0.1:1/z.git" }]];
|
|
147
|
-
for (const [route, b] of bodies) {
|
|
148
|
-
expect((await sheet(route, b, "http://localhost:3000")).status).toBe(403);
|
|
149
|
-
expect((await sheet(route, b, "https://evil.example")).status).toBe(403);
|
|
150
|
-
expect((await sheet(route, b, at, "text/plain")).status).toBe(415);
|
|
151
|
-
expect((await sheet(route, b, at, "application/x-www-form-urlencoded")).status).toBe(415);
|
|
152
|
-
}
|
|
153
|
-
expect(existsSync(join(homeDir, "z"))).toBe(false);
|
|
154
|
-
// Bad paths: root, home, ~/.kaizen, .., kaizen's own folders, below an existing project.
|
|
155
|
-
for (const path of ["/", homeDir, "~", "~/.kaizen/x", homeDir + "/../etc", "/tmp/a/../../etc", join(proj, "sub"), join(proj, ".kaizen", "wt", "x"), "", "x\0y"]) {
|
|
156
|
-
expect((await sheet("/add-project", { path })).status, path).toBe(400);
|
|
157
|
-
if (!path) continue; // no `to` means the default folder, for these two
|
|
158
|
-
expect((await sheet("/new-project", { name: "n", to: path })).status, path).toBe(400);
|
|
159
|
-
expect((await sheet("/clone", { url: "https://127.0.0.1:1/z.git", to: path })).status, path).toBe(400);
|
|
160
|
-
}
|
|
161
|
-
expect((await sheet("/add-project", { path: join(homeDir, "missing") })).status).toBe(400); // not a folder
|
|
162
|
-
expect((await sheet("/add-project", { path: 5 })).status).toBe(400);
|
|
163
|
-
expect((await sheet("/new-project", { name: "con" })).status).toBe(400);
|
|
164
|
-
// Bad clone URLs: nothing runs, nothing is made.
|
|
165
|
-
for (const url of ["--upload-pack=touch /tmp/kz-pwn", "ext::sh -c id", "file:///etc", "http://example.com/o/r.git", "/etc", "https://example.com/o/r with space", 7, undefined]) {
|
|
166
|
-
expect((await sheet("/clone", { url, to: join(homeDir, "c1") })).status, String(url)).toBe(400);
|
|
167
|
-
}
|
|
168
|
-
expect(existsSync(join(homeDir, "c1")) || existsSync("/tmp/kz-pwn")).toBe(false);
|
|
169
|
-
// Bad branch, base, project.
|
|
170
|
-
expect((await wt({ dir: st, branch: "-x" })).status).toBe(400);
|
|
171
|
-
expect((await wt({ dir: st, branch: "a..b" })).status).toBe(400);
|
|
172
|
-
expect((await wt({ dir: st, branch: "x y", base: "main" })).status).toBe(400);
|
|
173
|
-
expect((await wt({ dir: st, branch: "x", base: "-x" })).status).toBe(400);
|
|
174
|
-
expect((await wt({ dir: join(root, "elsewhere", ".kaizen"), branch: "x", base: "main" })).status).toBe(404);
|
|
175
|
-
expect((await fetch(`${at}/branches?dir=${encodeURIComponent(join(root, "elsewhere", ".kaizen"))}`)).status).toBe(404);
|
|
176
|
-
expect((await fetch(`${at}/branches?dir=${encodeURIComponent(join(homeDir, ".kaizen"))}`)).status).toBe(404);
|
|
177
|
-
expect(await (await fetch(`${at}/branches?dir=${encodeURIComponent(st)}`)).json()).toEqual({ current: "", def: "", branches: [] }); // not a repository
|
|
178
|
-
// Happy paths in the scratch home: an existing folder registers once; a new project gets .kaizen and git.
|
|
179
|
-
const reg = () => readFileSync(join(homeDir, ".kaizen", "projects"), "utf8").split("\n").filter(Boolean);
|
|
180
|
-
mkdirSync(join(homeDir, "b"));
|
|
181
|
-
const add1 = await (await sheet("/add-project", { path: join(homeDir, "b") })).json() as any;
|
|
182
|
-
expect(add1).toMatchObject({ ok: true, dir: join(homeDir, "b", ".kaizen"), already: false });
|
|
183
|
-
expect(existsSync(join(homeDir, "b", ".kaizen"))).toBe(true);
|
|
184
|
-
expect(reg().filter((l) => l === join(homeDir, "b"))).toHaveLength(1);
|
|
185
|
-
expect(((await (await sheet("/add-project", { path: join(homeDir, "b") })).json()) as any).already).toBe(true);
|
|
186
|
-
expect(reg().filter((l) => l === join(homeDir, "b"))).toHaveLength(1);
|
|
187
|
-
const newp = await (await sheet("/new-project", { name: "d", to: join(homeDir, "d") })).json() as any;
|
|
188
|
-
expect(newp).toMatchObject({ ok: true, dir: join(homeDir, "d", ".kaizen"), git: true });
|
|
189
|
-
expect(existsSync(join(homeDir, "d", ".git")) && existsSync(join(homeDir, "d", ".kaizen"))).toBe(true);
|
|
190
|
-
expect((await sheet("/new-project", { name: "d", to: join(homeDir, "d") })).status).toBe(409);
|
|
191
|
-
const plain = await (await sheet("/new-project", { name: "e", to: join(homeDir, "e"), git: false })).json() as any;
|
|
192
|
-
expect(existsSync(join(homeDir, "e", ".git"))).toBe(false);
|
|
193
|
-
expect(plain.git).toBeUndefined();
|
|
194
|
-
// A clone that cannot connect (nothing listens on port 1): 500, and no folder left behind.
|
|
195
|
-
expect((await sheet("/clone", { url: "https://127.0.0.1:1/z.git", to: join(homeDir, "f") })).status).toBe(500);
|
|
196
|
-
expect(existsSync(join(homeDir, "f"))).toBe(false);
|
|
197
|
-
expect(await (await sheet("/clone", { url: "git@github.com:o/r.git", check: true })).json()).toMatchObject({ ok: true, name: "r" });
|
|
198
|
-
// /state: each card's workspace; a run whose worktree is gone falls back to the main checkout.
|
|
199
|
-
mkdirSync(join(st, "runs", "r2"), { recursive: true });
|
|
200
|
-
writeFileSync(join(st, "runs", "r2", "state.json"), JSON.stringify({ id: "r2", stage: "plan", awaiting: "approvals.plan", worktree: join(proj, ".kaizen", "wt", "gone") }));
|
|
201
|
-
const S = await (await fetch(at + "/state?all=1")).json() as any;
|
|
202
|
-
expect(S.cards.find((c: any) => c.id === "r2")?.ws).toBe(proj);
|
|
203
|
-
expect(S.projects.find((p: any) => p.dir === st)?.workspaces).toEqual([{ path: proj, branch: "", main: true }]);
|
|
204
|
-
rmSync(join(st, "runs", "r2"), { recursive: true });
|
|
205
|
-
// Projects folder set: the global queue is not in the picker, yet its waiting run still gets a rail row.
|
|
206
|
-
const g = join(homeDir, ".kaizen");
|
|
207
|
-
writeFileSync(join(g, "config.yml"), readFileSync(join(repo, "skills", "kaizen", "config.default.yml"), "utf8").replace('projects_dir: ""', "projects_dir: ~/Projects"));
|
|
208
|
-
mkdirSync(join(g, "runs", "g1"), { recursive: true });
|
|
209
|
-
writeFileSync(join(g, "runs", "g1", "state.json"), JSON.stringify({ id: "g1", stage: "plan", awaiting: "approvals.plan" }));
|
|
210
|
-
// The board's snapshot refreshes behind the request: wait for the run to appear.
|
|
211
|
-
let G: any;
|
|
212
|
-
for (let i = 0; i < 50; i++) {
|
|
213
|
-
G = await (await fetch(at + "/state?all=1")).json();
|
|
214
|
-
if (G.cards.some((c: any) => c.id === "g1")) break;
|
|
215
|
-
await Bun.sleep(100);
|
|
216
|
-
}
|
|
217
|
-
expect(G.cards.find((c: any) => c.id === "g1")?.ws).toBe(g);
|
|
218
|
-
expect(G.projects.some((p: any) => p.dir === g)).toBe(false);
|
|
219
|
-
expect(G.rail.find((p: any) => p.dir === g)?.workspaces).toEqual([{ path: g, branch: "", main: true }]);
|
|
220
|
-
rmSync(join(g, "runs"), { recursive: true });
|
|
221
|
-
rmSync(join(g, "config.yml"));
|
|
222
|
-
|
|
223
|
-
const inWs = await post({ dir: st, ws: proj }, at);
|
|
224
|
-
expect(inWs.status).toBe(200);
|
|
225
|
-
const made = (await inWs.json()) as any;
|
|
226
|
-
expect(made.ws).toBe(proj); // the tab lists a workspace's shells by it
|
|
227
|
-
await fetch(at + "/pty/exit", { method: "POST", body: JSON.stringify({ key: made.key }) });
|
|
228
|
-
for (let i = 0; i < 100; i++) { if (!((await (await fetch(`${at}/shells`)).json()) as any[]).length) break; await Bun.sleep(50); }
|
|
229
|
-
// A worktree made after the board cached the list (above) is let in, not refused for 10 s.
|
|
230
|
-
const g0 = (...a: string[]) => Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...a], { cwd: proj });
|
|
231
|
-
g0("init", "-q", "-b", "main"); g0("commit", "-q", "--allow-empty", "-m", "x");
|
|
232
|
-
const fresh = join(proj, ".kaizen", "wt", "late");
|
|
233
|
-
expect(g0("worktree", "add", "-q", "-b", "late", fresh).exitCode).toBe(0);
|
|
234
|
-
await Bun.sleep(1100); // the recheck waits for a cache older than 1 s
|
|
235
|
-
const late = await post({ dir: st, ws: fresh }, at);
|
|
236
|
-
expect(late.status).toBe(200);
|
|
237
|
-
await fetch(at + "/pty/exit", { method: "POST", body: JSON.stringify({ key: ((await late.json()) as any).key }) });
|
|
238
|
-
for (let i = 0; i < 100; i++) { if (!((await (await fetch(`${at}/shells`)).json()) as any[]).length) break; await Bun.sleep(50); }
|
|
239
|
-
// A burst of bad workspace paths runs git at most once.
|
|
240
|
-
const log = join(root, "git.log");
|
|
241
|
-
rmSync(join(bin, "git")); writeFileSync(join(bin, "git"), `#!/bin/sh\necho "$*" >> ${log}\nexec ${Bun.which("git")} "$@"\n`, { mode: 0o755 });
|
|
242
|
-
await Bun.sleep(1100);
|
|
243
|
-
for (let i = 0; i < 10; i++) expect((await post({ dir: st, ws: join(proj, "nope" + i) }, at)).status).toBe(400);
|
|
244
|
-
expect((existsSync(log) ? readFileSync(log, "utf8") : "").split("\n").filter((l) => l.startsWith("worktree list")).length).toBeLessThanOrEqual(1);
|
|
245
|
-
rmSync(join(bin, "git")); symlinkSync(Bun.which("git")!, join(bin, "git"));
|
|
246
|
-
rmSync(join(proj, ".git"), { recursive: true, force: true }); rmSync(join(proj, ".kaizen", "wt"), { recursive: true, force: true });
|
|
247
|
-
|
|
248
|
-
const r = await post({ dir: st }, at);
|
|
249
|
-
expect(r.status).toBe(200);
|
|
250
|
-
const sh1 = await r.json() as any;
|
|
251
|
-
expect(sh1).toMatchObject({ dir: st, title: "shell", agent: "", run: "" });
|
|
252
|
-
expect(sh1.key).toMatch(/^sh-[\w-]+$/);
|
|
253
|
-
const url = `${at}/pty?key=${sh1.key}`, up = { upgrade: "websocket", connection: "Upgrade", "sec-websocket-version": "13", "sec-websocket-key": "dGhlIHNhbXBsZSBub25jZQ==" };
|
|
254
|
-
expect((await fetch(url, { headers: { ...up, origin: "https://evil.example" } })).status).toBe(403);
|
|
255
|
-
let seen = "";
|
|
256
|
-
const ws = new WebSocket(url.replace("http", "ws"), { headers: { origin: at } } as any);
|
|
257
|
-
ws.onmessage = (e) => { seen += String(e.data); };
|
|
258
|
-
await new Promise((ok, no) => { ws.onopen = ok; ws.onerror = no; });
|
|
259
|
-
for (let i = 0; i < 100 && !seen.includes("pwd:"); i++) await Bun.sleep(30);
|
|
260
|
-
expect(seen).toContain(`pwd:${proj}`);
|
|
261
|
-
ws.close();
|
|
262
|
-
expect(((await (await fetch(`${at}/shells?dir=${encodeURIComponent(st)}`)).json()) as any[]).map((s) => s.key)).toEqual([sh1.key]);
|
|
263
|
-
expect((await fetch(at + "/pty/exit", { method: "POST", body: JSON.stringify({ key: sh1.key }) })).status).toBe(200);
|
|
264
|
-
for (let i = 0; i < 100; i++) { if (!((await (await fetch(`${at}/shells`)).json()) as any[]).length) break; await Bun.sleep(50); }
|
|
265
|
-
expect(await (await fetch(`${at}/shells`)).json()).toEqual([]);
|
|
266
|
-
|
|
267
|
-
// /state lists the open agents once (not plain shells); an ended one drops out.
|
|
268
|
-
writeFileSync(join(bin, "gemini"), '#!/bin/sh\necho "✦ Reading the parser source"\nread x\n', { mode: 0o755 });
|
|
269
|
-
const ag = (await (await post({ dir: st, agent: "gemini" }, at)).json()) as any, pl = (await (await post({ dir: st }, at)).json()) as any;
|
|
270
|
-
let A: any[] = [];
|
|
271
|
-
for (let i = 0; i < 60 && !A[0]?.last; i++) { await Bun.sleep(100); A = ((await (await fetch(at + "/state?all=1")).json()) as any).agents; }
|
|
272
|
-
expect(A.map((x) => x.key)).toEqual([ag.key]);
|
|
273
|
-
expect(A[0]).toMatchObject({ dir: st, agent: "gemini", name: "Gemini", asking: false, last: "Reading the parser source" });
|
|
274
|
-
for (const k of [ag.key, pl.key]) await fetch(at + "/pty/exit", { method: "POST", body: JSON.stringify({ key: k }) });
|
|
275
|
-
for (let i = 0; i < 100; i++) { if (!((await (await fetch(`${at}/shells`)).json()) as any[]).length) break; await Bun.sleep(50); }
|
|
276
|
-
expect(((await (await fetch(at + "/state?all=1")).json()) as any).agents).toEqual([]);
|
|
277
|
-
|
|
278
|
-
// At most 8 live terminals per project.
|
|
279
|
-
const keys: string[] = [];
|
|
280
|
-
for (let i = 0; i < 8; i++) { const x = await post({ dir: st }, at); expect(x.status).toBe(200); keys.push(((await x.json()) as any).key); }
|
|
281
|
-
expect((await post({ dir: st }, at)).status).toBe(429);
|
|
282
|
-
for (const k of keys) await fetch(at + "/pty/exit", { method: "POST", body: JSON.stringify({ key: k }) });
|
|
283
|
-
|
|
284
|
-
const u = await fetch(at + "/usage");
|
|
285
|
-
expect(u.status).toBe(200);
|
|
286
|
-
expect(await u.json()).toEqual([]);
|
|
287
|
-
const p = await fetch(at + "/phone");
|
|
288
|
-
expect(p.status).toBe(200);
|
|
289
|
-
expect(await p.json()).toEqual({ tailscale: false });
|
|
290
|
-
} finally { proc.kill(); }
|
|
291
|
-
}, 30_000);
|
package/cli/versions.test.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "bun:test";
|
|
2
|
-
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { createHash } from "node:crypto";
|
|
6
|
-
import * as v from "./versions.ts";
|
|
7
|
-
|
|
8
|
-
const md5 = (f: string) => createHash("md5").update(readFileSync(f)).digest("hex");
|
|
9
|
-
const LATER = Date.now() + 60_000; // "now" well past the settle time, so fresh test files file
|
|
10
|
-
|
|
11
|
-
// A place with one video "clip": a draft (film.json, lines.json, a voice line, footage that is never
|
|
12
|
-
// part of a recipe) and renders in the scripts' layout, output/clip/<preset>/clip.mp4.
|
|
13
|
-
function place() {
|
|
14
|
-
const p = mkdtempSync(join(tmpdir(), "kaizen-versions-"));
|
|
15
|
-
const vd = join(p, "videos", "clip");
|
|
16
|
-
mkdirSync(join(vd, "raw"), { recursive: true });
|
|
17
|
-
writeFileSync(join(vd, "film.json"), '{"preset":"film-a","title":"one"}');
|
|
18
|
-
writeFileSync(join(vd, "lines.json"), '{"v01":"hello"}');
|
|
19
|
-
writeFileSync(join(vd, "v01.mp3"), "voice");
|
|
20
|
-
writeFileSync(join(vd, "raw", "take.mp4"), "footage");
|
|
21
|
-
return p;
|
|
22
|
-
}
|
|
23
|
-
function render(p: string, preset: string, body: string, extras = true) {
|
|
24
|
-
const d = join(p, "output", "clip", preset);
|
|
25
|
-
mkdirSync(d, { recursive: true });
|
|
26
|
-
writeFileSync(join(d, "clip.mp4"), body);
|
|
27
|
-
if (extras) { writeFileSync(join(d, "clip.srt"), "srt " + body); writeFileSync(join(d, "clip-thumb.jpg"), "jpg"); writeFileSync(join(d, "CREDITS.txt"), "credits"); }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
test("first sight: existing renders become versions oldest first, previous/ copies their history, recipe unknown", () => {
|
|
31
|
-
const p = place();
|
|
32
|
-
render(p, "film-a", "A");
|
|
33
|
-
mkdirSync(join(p, "output", "clip", "film-a", "previous"), { recursive: true });
|
|
34
|
-
writeFileSync(join(p, "output", "clip", "film-a", "previous", "clip-20261020.mp4"), "A-old");
|
|
35
|
-
writeFileSync(join(p, "output", "clip", "film-a", "previous", "clip-thumb-20261020.jpg"), "old-jpg");
|
|
36
|
-
render(p, "film-b", "B");
|
|
37
|
-
v.fileRenders(p, "clip", LATER);
|
|
38
|
-
const s = v.readStore(p, "clip")!;
|
|
39
|
-
expect(s.versions.map((x) => [x.letter, x.preset, x.current, x.revs.length])).toEqual([["a", "film-a", 2, 2], ["b", "film-b", 1, 1]]);
|
|
40
|
-
expect(s.versions.every((x) => x.revs.every((r) => !r.recipe))).toBe(true);
|
|
41
|
-
const files = v.revFiles(p, "clip");
|
|
42
|
-
expect(files.map((f) => `${f.letter}${f.n}:${f.kind}`)).toEqual(["a1:history", "a2:current", "b1:current"]);
|
|
43
|
-
expect(readFileSync(join(p, "output", "clip", "versions", "a", "2", "clip.mp4"), "utf8")).toBe("A");
|
|
44
|
-
expect(readFileSync(join(p, "output", "clip", "versions", "a", "1", "clip-20261020.mp4"), "utf8")).toBe("A-old");
|
|
45
|
-
expect(files[0]!.thumb).toBe("o/versions/a/1/clip-20261020-thumb.jpg");
|
|
46
|
-
// Moved, not copied: nothing left in the old place but its CREDITS.txt.
|
|
47
|
-
expect(existsSync(join(p, "output", "clip", "film-a", "clip.mp4"))).toBe(false);
|
|
48
|
-
expect(v.revise(p, "clip", "a")).toContain("cannot be revised");
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("a render still settling is not filed", () => {
|
|
52
|
-
const p = place();
|
|
53
|
-
render(p, "film-a", "A");
|
|
54
|
-
v.fileRenders(p, "clip", Date.now());
|
|
55
|
-
expect(v.readStore(p, "clip")).toBe(null);
|
|
56
|
-
expect(existsSync(join(p, "output", "clip", "film-a", "clip.mp4"))).toBe(true);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("revise b, try, keep, restore, revert: a and the other files are never touched", () => {
|
|
60
|
-
const p = place();
|
|
61
|
-
// A store already exists, so new renders are filed with their recipe.
|
|
62
|
-
render(p, "film-a", "A"); v.fileRenders(p, "clip", LATER);
|
|
63
|
-
render(p, "film-b", "B"); v.fileRenders(p, "clip", LATER);
|
|
64
|
-
const aMp4 = join(p, "output", "clip", "versions", "b", "1", "clip.mp4");
|
|
65
|
-
expect(v.readStore(p, "clip")!.versions.map((x) => x.letter)).toEqual(["a", "b"]);
|
|
66
|
-
const b1 = v.readStore(p, "clip")!.versions[1]!.revs[0]!;
|
|
67
|
-
expect(b1.recipe).toBe(true);
|
|
68
|
-
const keepA = md5(join(p, "output", "clip", "versions", "a", "1", "clip.mp4"));
|
|
69
|
-
|
|
70
|
-
// Revise b: its recipe becomes the draft.
|
|
71
|
-
writeFileSync(join(p, "videos", "clip", "film.json"), '{"preset":"film-b","title":"changed elsewhere"}');
|
|
72
|
-
expect(v.revise(p, "clip", "b")).toBe(null);
|
|
73
|
-
expect(v.readStore(p, "clip")!.revising).toBe("b");
|
|
74
|
-
// (the recipe saved at b's filing held the film.json of that moment)
|
|
75
|
-
expect(readFileSync(join(p, "videos", "clip", "film.json"), "utf8")).toBe('{"preset":"film-a","title":"one"}');
|
|
76
|
-
expect(existsSync(join(p, "videos", "clip", "raw", "take.mp4"))).toBe(true);
|
|
77
|
-
|
|
78
|
-
// A change and a render: filed as b's try, from b1.
|
|
79
|
-
writeFileSync(join(p, "videos", "clip", "film.json"), '{"preset":"film-b","title":"horror"}');
|
|
80
|
-
render(p, "film-b", "B2"); v.fileRenders(p, "clip", LATER);
|
|
81
|
-
let b = v.readStore(p, "clip")!.versions.find((x) => x.letter === "b")!;
|
|
82
|
-
expect([b.current, b.trying, b.revs.at(-1)!.from]).toEqual([1, 2, "b1"]);
|
|
83
|
-
expect(v.revFiles(p, "clip").filter((f) => f.letter === "b").map((f) => `${f.n}:${f.kind}`)).toEqual(["1:current", "2:trying"]);
|
|
84
|
-
|
|
85
|
-
// A second try replaces the first (one try at a time).
|
|
86
|
-
render(p, "film-b", "B3"); v.fileRenders(p, "clip", LATER);
|
|
87
|
-
b = v.readStore(p, "clip")!.versions.find((x) => x.letter === "b")!;
|
|
88
|
-
expect([b.current, b.trying, b.revs.map((r) => r.n)]).toEqual([1, 3, [1, 3]]);
|
|
89
|
-
expect(existsSync(join(p, "output", "clip", "versions", "b", "2"))).toBe(false);
|
|
90
|
-
|
|
91
|
-
// Keep: the try is b; b1 is history.
|
|
92
|
-
expect(v.keep(p, "clip", "b")).toBe(null);
|
|
93
|
-
expect(v.revFiles(p, "clip").filter((f) => f.letter === "b").map((f) => `${f.n}:${f.kind}`)).toEqual(["1:history", "3:current"]);
|
|
94
|
-
// Restore b1: swapped back.
|
|
95
|
-
expect(v.restore(p, "clip", "b", 1)).toBe(null);
|
|
96
|
-
expect(v.revFiles(p, "clip").filter((f) => f.letter === "b").map((f) => `${f.n}:${f.kind}`)).toEqual(["1:current", "3:history"]);
|
|
97
|
-
expect(readFileSync(aMp4, "utf8")).toBe("B");
|
|
98
|
-
// b is being revised, so the draft followed b back to v1's recipe.
|
|
99
|
-
expect(readFileSync(join(p, "videos", "clip", "film.json"), "utf8")).toBe('{"preset":"film-a","title":"one"}');
|
|
100
|
-
|
|
101
|
-
// Another try, then Revert: its files go, the draft goes back to b's current recipe.
|
|
102
|
-
render(p, "film-b", "B4"); v.fileRenders(p, "clip", LATER);
|
|
103
|
-
expect(v.revert(p, "clip", "b")).toBe(null);
|
|
104
|
-
b = v.readStore(p, "clip")!.versions.find((x) => x.letter === "b")!;
|
|
105
|
-
expect([b.current, b.trying]).toEqual([1, null]);
|
|
106
|
-
expect(existsSync(join(p, "output", "clip", "versions", "b", "4"))).toBe(false);
|
|
107
|
-
expect(readFileSync(join(p, "videos", "clip", "film.json"), "utf8")).toBe('{"preset":"film-a","title":"one"}');
|
|
108
|
-
|
|
109
|
-
// a never moved or changed.
|
|
110
|
-
expect(md5(join(p, "output", "clip", "versions", "a", "1", "clip.mp4"))).toBe(keepA);
|
|
111
|
-
|
|
112
|
-
// Delete a history revision, then the whole version.
|
|
113
|
-
expect(v.remove(p, "clip", "b", 1)).toBe("only a history revision can be deleted on its own");
|
|
114
|
-
expect(v.remove(p, "clip", "b", 3)).toBe(null);
|
|
115
|
-
expect(v.remove(p, "clip", "b", undefined)).toBe("only a history revision can be deleted on its own");
|
|
116
|
-
expect(v.remove(p, "clip", "b", "all")).toBe(null);
|
|
117
|
-
expect(v.readStore(p, "clip")!.versions.map((x) => x.letter)).toEqual(["a"]);
|
|
118
|
-
expect(existsSync(join(p, "output", "clip", "versions", "b"))).toBe(false);
|
|
119
|
-
expect(existsSync(join(p, "videos", "clip", "versions", "b"))).toBe(false);
|
|
120
|
-
expect(v.readStore(p, "clip")!.revising).toBe(null);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test("two renders settling in one pass while revising: the first is the try, the second a new letter", () => {
|
|
124
|
-
const p = place();
|
|
125
|
-
writeFileSync(join(p, "videos", "clip", "versions.json"), '{"revising":null,"versions":[]}');
|
|
126
|
-
render(p, "film-a", "A"); v.fileRenders(p, "clip", LATER);
|
|
127
|
-
expect(v.revise(p, "clip", "a")).toBe(null);
|
|
128
|
-
render(p, "film-a", "A2"); render(p, "film-b", "B");
|
|
129
|
-
v.fileRenders(p, "clip", LATER);
|
|
130
|
-
const s = v.readStore(p, "clip")!;
|
|
131
|
-
expect(s.versions.map((x) => [x.letter, x.current, x.trying])).toEqual([["a", 1, 2], ["b", 1, null]]);
|
|
132
|
-
expect(readFileSync(join(p, "output", "clip", "versions", "a", "2", "clip.mp4"), "utf8")).toBe("A2");
|
|
133
|
-
expect(readFileSync(join(p, "output", "clip", "versions", "b", "1", "clip.mp4"), "utf8")).toBe("B");
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test("files a crashed filing left behind are kept on disk and never listed", () => {
|
|
137
|
-
const p = place();
|
|
138
|
-
mkdirSync(join(p, "output", "clip", "versions", "a", "1"), { recursive: true });
|
|
139
|
-
writeFileSync(join(p, "output", "clip", "versions", "a", "1", "aaa-orphan.mp4"), "orphan");
|
|
140
|
-
render(p, "film-a", "A"); v.fileRenders(p, "clip", LATER);
|
|
141
|
-
expect(v.revFiles(p, "clip").map((f) => f.mp4)).toEqual(["o/versions/b/1/clip.mp4"]);
|
|
142
|
-
expect(readFileSync(join(p, "output", "clip", "versions", "a", "1", "aaa-orphan.mp4"), "utf8")).toBe("orphan");
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test("bad letters and revisions are refused", () => {
|
|
146
|
-
const p = place();
|
|
147
|
-
render(p, "film-a", "A"); v.fileRenders(p, "clip", LATER);
|
|
148
|
-
for (const l of ["../a", "A", "", "abcd", 3, null]) expect(v.keep(p, "clip", l)).toBe("unknown version");
|
|
149
|
-
expect(v.keep(p, "clip", "z")).toBe("unknown version");
|
|
150
|
-
expect(v.keep(p, "clip", "a")).toBe("nothing is being tried on this version");
|
|
151
|
-
expect(v.restore(p, "clip", "a", 1)).toBe("not a history revision of this version");
|
|
152
|
-
expect(v.restore(p, "clip", "a", "../../x")).toBe("not a history revision of this version");
|
|
153
|
-
expect(readdirSync(join(p, "output", "clip", "versions"))).toEqual(["a"]);
|
|
154
|
-
});
|