Files
threshing-atlas/tests/core/graph.test.js
T
ekcSchianoandClaude Opus 5.5 43066ad67f Bot import: one folder per account, run records with steps
- the importer reads data/accounts/*/runs.jsonl and logs/accounts/*/encounters.jsonl;
  with account folders, the top-level files (a mirror of the first account) are skipped
- run records that carry their steps (schema 2) become trajectories directly, keeping
  what the bot saw (shadow, meadow dragons), propensities, decision mode and policy id;
  older runs are still rebuilt from the decision log; bonded runs without steps are kept
- account names become salted hashes (DK_ACCOUNT_SALT, or a private salt in data/raw)
- runs_clean.csv: new bot_mode column; saw_shadow and saw_blue_meadow from what the bot
  saw; deliberate burns say why
- crosswalk: the valley Red, leaving squadmates, squad direction, hold your ground,
  hide/approach reactions, the wounded cadet's other two choices

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
2026-11-10 02:08:57 +00:00

47 lines
2.2 KiB
JavaScript

// node --test tests/
const test = require("node:test");
const assert = require("node:assert");
const path = require("path");
const G = require("../../core/graph");
// the bot importer's output on tests/fixtures/bot (the importer is Python now: tests/collection/test_bot.py checks
// that it still produces exactly this file)
const { scenes, trajectories } = require(path.join(__dirname, "../fixtures/bot/expected.json"));
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);
});
// every route choice the bot has seen maps onto a column: tests/collection/test_collection.py (Bot)