-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstinct-packs.test.mjs
More file actions
68 lines (68 loc) · 3.46 KB
/
instinct-packs.test.mjs
File metadata and controls
68 lines (68 loc) · 3.46 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
import assert from "node:assert/strict";
import { existsSync, readFileSync, readdirSync } from "node:fs";
import { join } from "node:path";
import { describe, it } from "node:test";
import { fileURLToPath } from "node:url";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
const PACKS_DIR = join(__dirname, "..", "instinct-packs");
describe("instinct-packs directory", () => {
it("exists", () => {
assert.ok(existsSync(PACKS_DIR), "instinct-packs/ directory should exist");
});
it("contains at least 3 packs", () => {
const packs = readdirSync(PACKS_DIR).filter((file) => file.endsWith(".json"));
assert.ok(packs.length >= 3, `Expected at least 3 packs, got ${packs.length}`);
});
});
for (const packName of ["react", "python", "go"]) {
describe(`instinct-packs/${packName}.json`, () => {
let instincts = [];
it("is valid JSON", () => {
const content = readFileSync(join(PACKS_DIR, `${packName}.json`), "utf8");
instincts = JSON.parse(content);
});
it("is a non-empty array", () => {
assert.ok(Array.isArray(instincts), "Should be an array");
assert.ok(instincts.length >= 5, `Expected at least 5 instincts, got ${instincts.length}`);
});
it("each instinct has required fields", () => {
for (const instinct of instincts) {
assert.ok(instinct.id, `Instinct missing id: ${JSON.stringify(instinct)}`);
assert.ok(instinct.trigger, `Instinct ${instinct.id} missing trigger`);
assert.ok(instinct.body, `Instinct ${instinct.id} missing body`);
assert.ok(typeof instinct.confidence === "number", `Instinct ${instinct.id} confidence must be a number`);
}
});
it("all IDs are unique", () => {
const ids = instincts.map((instinct) => instinct.id);
const unique = new Set(ids);
assert.equal(unique.size, ids.length, `Duplicate IDs found: ${ids.filter((id, index) => ids.indexOf(id) !== index)}`);
});
it("IDs are kebab-case", () => {
for (const instinct of instincts) {
assert.match(instinct.id, /^[a-z][a-z0-9-]+$/, `ID "${instinct.id}" should be kebab-case`);
}
});
it("confidence values are in valid range (0.0-0.9)", () => {
for (const instinct of instincts) {
assert.ok(instinct.confidence >= 0 && instinct.confidence <= 0.9, `Instinct ${instinct.id} confidence ${instinct.confidence} out of range`);
}
});
it("domain is a valid value", () => {
const validDomains = ["workflow", "patterns", "testing", "tooling", "code-style"];
for (const instinct of instincts) {
assert.ok(validDomains.includes(instinct.domain), `Instinct ${instinct.id} has invalid domain "${instinct.domain}". Valid: ${validDomains.join(", ")}`);
}
});
it("body is substantive (at least 20 chars)", () => {
for (const instinct of instincts) {
assert.ok(instinct.body.length >= 20, `Instinct ${instinct.id} body too short: "${instinct.body}"`);
}
});
it("trigger starts with 'when'", () => {
for (const instinct of instincts) {
assert.match(instinct.trigger.toLowerCase(), /^when/, `Instinct ${instinct.id} trigger should start with "when": "${instinct.trigger}"`);
}
});
});
}