Repository navigation
Expand file tree
/
Copy pathWebCryptCLI.test.js
More file actions
130 lines (105 loc) · 4.3 KB
/
Copy pathWebCryptCLI.test.js
File metadata and controls
130 lines (105 loc) · 4.3 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
120
121
122
123
124
125
126
127
128
129
130
import fs from "fs";
import path from "path";
import os from "os";
import { runInit, runInitGlobal } from "../src/cli/init.js";
import { runDoctor, runDoctorGlobal } from "../src/cli/doctor.js";
import {
getRegistry,
registerProject,
unregisterProject,
pruneStaleProjects,
} from "../src/cli/registry.js";
describe("WebCrypt CLI, Registry & Doctor", () => {
let tmpDir;
let origEnv;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "webcrypt-test-"));
origEnv = process.env.WEBCRYPT_REGISTRY_PATH;
process.env.WEBCRYPT_REGISTRY_PATH = path.join(tmpDir, "projects.json");
});
afterEach(() => {
process.env.WEBCRYPT_REGISTRY_PATH = origEnv;
fs.rmSync(tmpDir, { recursive: true, force: true });
});
test("registers, unregisters, and prunes projects", () => {
const p1 = path.join(tmpDir, "proj1");
fs.mkdirSync(p1, { recursive: true });
registerProject("proj1", p1);
let reg = getRegistry();
expect(reg["proj1"]).toBe(p1);
unregisterProject("proj1");
reg = getRegistry();
expect(reg["proj1"]).toBeUndefined();
registerProject("proj-stale", path.join(tmpDir, "nonexistent"));
const pruneRes = pruneStaleProjects();
expect(pruneRes.removed.length).toBe(1);
expect(pruneRes.removed[0].slug).toBe("proj-stale");
});
test("runInit creates skill, mcp config, and instruction markers", async () => {
const projDir = path.join(tmpDir, "my-app");
fs.mkdirSync(projDir, { recursive: true });
const res = await runInit(projDir, { silent: true });
expect(res.projectName).toBe("my-app");
const skillPath = path.join(projDir, ".agents", "skills", "webcrypt-mcp", "SKILL.md");
expect(fs.existsSync(skillPath)).toBe(true);
const skillContent = fs.readFileSync(skillPath, "utf-8");
expect(skillContent).toContain("name: webcrypt-mcp");
const cursorMcp = path.join(projDir, ".cursor", "mcp.json");
expect(fs.existsSync(cursorMcp)).toBe(true);
const mcpJson = JSON.parse(fs.readFileSync(cursorMcp, "utf-8"));
expect(mcpJson.mcpServers.webcrypt).toBeDefined();
const agentsMd = path.join(projDir, ".agents", "AGENTS.md");
expect(fs.existsSync(agentsMd)).toBe(true);
const agentsContent = fs.readFileSync(agentsMd, "utf-8");
expect(agentsContent).toContain("<!-- webcrypt-mcp:start -->");
});
test("runDoctor verifies healthy project setup", async () => {
const projDir = path.join(tmpDir, "healthy-app");
fs.mkdirSync(projDir, { recursive: true });
await runInit(projDir, { silent: true });
const docRes = await runDoctor(projDir, { json: true });
expect(docRes.allPassed).toBe(true);
expect(docRes.checks.length).toBeGreaterThanOrEqual(4);
});
test("runDoctorGlobal audits registered projects", async () => {
const projDir = path.join(tmpDir, "global-app");
fs.mkdirSync(projDir, { recursive: true });
await runInit(projDir, { silent: true });
// Output capture
const logs = [];
const origLog = console.log;
console.log = (...args) => logs.push(args.join(" "));
try {
await runDoctorGlobal({ json: false, cleanStale: true });
} finally {
console.log = origLog;
}
const output = logs.join("\n");
expect(output).toContain("Global Audit Summary");
});
test("runDoctorGlobal audits mixed valid and missing projects", async () => {
const pValid = path.join(tmpDir, "valid-app");
fs.mkdirSync(pValid, { recursive: true });
await runInit(pValid, { silent: true });
registerProject("missing-app", path.join(tmpDir, "does-not-exist-dir"));
const logs = [];
const origLog = console.log;
console.log = (...args) => logs.push(args.join(" "));
try {
await runDoctorGlobal({ json: false, cleanStale: false });
} finally {
console.log = origLog;
}
const output = logs.join("\n");
expect(output).toContain("Missing Directory");
expect(output).toContain("Global Audit Summary");
});
test("runInitGlobal ignores subdirectories without package.json or .git", async () => {
const workspaceDir = path.join(tmpDir, "workspace-misc");
const emptySub = path.join(workspaceDir, "empty-sub");
fs.mkdirSync(emptySub, { recursive: true });
await runInitGlobal({ scan: workspaceDir });
const reg = getRegistry();
expect(reg["empty-sub"]).toBeUndefined();
});
});