Moves only; no behaviour changes. Every file now lives under the part of the project it belongs to, each section has a README, and docs/PRIVACY.md collects the rules all parts follow. core/ engine.js, graph.js, solver.js, python/clean.py collection/ sources/ (form, register, PDF check, daily update), bot/ (importer) analysis/ stats/ (Python statistics), network/ (build-graph.js), reports/ (POLICY.md) planner/ build-policy.js, policy-report.js site/ atlas/ (the page), build.js, qa/ tests/ core/ (unit), parity/ (JS vs Python), fixtures/ Checked against the previous layout: tests pass; coded runs, test outputs, graph.json and policy.json are byte-identical; the built site differs only in comments that name file paths. The published file names Ken's bot downloads (solver.js, graph.js, data/policy.json) are unchanged. Also removes the undefined/ folder of QA screenshots committed by mistake (the QA scripts now default to a temp folder) and test.txt, and drops the unused npm workspaces. Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
3.3 KiB
JavaScript
73 lines
3.3 KiB
JavaScript
// node --test tests/
|
|
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const path = require("path");
|
|
const { importBot, assertPublicSafe } = require("../../collection/bot/bot");
|
|
const G = require("../../core/graph");
|
|
|
|
const fx = path.join(__dirname, "../fixtures/bot");
|
|
const { scenes, trajectories } = importBot({ dataDir: path.join(fx, "data"), logsDir: path.join(fx, "logs"), salt: "test-salt" });
|
|
|
|
test("one trajectory per attempt, duplicates and repeated burns collapsed", () => {
|
|
assert.strictEqual(trajectories.length, 2);
|
|
const [t1, t2] = trajectories;
|
|
assert.strictEqual(t1.steps.length, 3);
|
|
assert.deepStrictEqual(t1.steps.map((s) => s.to).slice(-1), ["BURNED"]);
|
|
assert.strictEqual(t1.steps[0].to, t1.steps[1].scene);
|
|
assert.strictEqual(t2.outcome.type, "BONDED");
|
|
assert.strictEqual(t2.steps.at(-1).to, "BONDED:green");
|
|
assert.strictEqual(t2.steps[0].manual, true, "manual picks are flagged");
|
|
});
|
|
|
|
test("run metadata attached, account id hashed with the salt", () => {
|
|
const t1 = trajectories[0];
|
|
assert.strictEqual(t1.meta.target, "black");
|
|
assert.strictEqual(t1.meta.decisionMode, "explore");
|
|
assert.strictEqual(t1.outcome.intentional, true);
|
|
assert.match(t1.meta.accountKey, /^[0-9a-f]{10}$/);
|
|
assert.ok(!JSON.stringify(trajectories).includes("acct-1"));
|
|
});
|
|
|
|
test("public export contains no prose", () => {
|
|
assertPublicSafe(scenes);
|
|
assertPublicSafe(trajectories);
|
|
assert.ok(!JSON.stringify({ scenes, trajectories }).includes("Synthetic"));
|
|
assert.throws(() => assertPublicSafe({ prose: "x" }));
|
|
assert.throws(() => assertPublicSafe({ note: "y".repeat(201) }));
|
|
});
|
|
|
|
test("crosswalk maps bot choices to form variables", () => {
|
|
const { vars } = G.trajectoryVariables(trajectories[0]);
|
|
assert.strictEqual(vars.company, "Alone");
|
|
assert.strictEqual(vars.direction, "Center");
|
|
assert.strictEqual(vars.outcome, "Incinerated");
|
|
const v2 = G.trajectoryVariables(trajectories[1]).vars;
|
|
assert.strictEqual(v2.company, "1 Squadmate");
|
|
assert.strictEqual(v2.outcome_color, "Green");
|
|
});
|
|
|
|
test("variable graph counts by source", () => {
|
|
const recs = trajectories.map((t) => ({ source: "bot", vars: G.trajectoryVariables(t).vars }));
|
|
recs.push({ source: "form", vars: { company: "Alone", direction: "Center", outcome: "Bonded", outcome_color: "Blue" } });
|
|
const g = G.buildVariableGraph(recs);
|
|
const e = g.edges.find((x) => x.from === "company=Alone" && x.to === "direction=Center");
|
|
assert.deepStrictEqual(e.bySource, { bot: 1, form: 1 });
|
|
assert.ok(Math.abs(e.p.mean - 2.5 / 3) < 1e-12);
|
|
});
|
|
|
|
test("scene graph marks chance, burns and untested options", () => {
|
|
const g = G.buildSceneGraph(scenes, trajectories);
|
|
const start = Object.values(g).find((n) => Object.values(n.options).some((o) => /alone/i.test(o.text)));
|
|
assert.strictEqual(Object.values(start.options).every((o) => o.n === 1), true);
|
|
const dragon = Object.values(g).find((n) => Object.values(n.options).some((o) => /hide behind/i.test(o.text)));
|
|
const hide = Object.values(dragon.options).find((o) => /hide/i.test(o.text));
|
|
const respect = Object.values(dragon.options).find((o) => /respect/i.test(o.text));
|
|
assert.strictEqual(hide.to.BURNED, 1);
|
|
assert.strictEqual(respect.untested, true);
|
|
});
|
|
|
|
test("Beta credible interval", () => {
|
|
const p = G.betaPosterior(0, 4);
|
|
assert.ok(p.lo >= 0 && p.hi < 0.5 && p.mean === 0.1);
|
|
});
|