Files
threshing-atlas/tests/core/graph.test.js
T
ekcSchianoandClaude Opus 5.5 3b24a11f5a Collection as an ETL pipeline; runs_clean.csv from every source; Report a run
- collection/pipeline.yaml declares every source (extract kind, transform,
  privacy rules, load target, run source); `python -m collection update|build`
- extract keeps data/raw/<source>/current + previous only (git-ignored);
  data/manifest.json records the current raw checksum and change date
- transforms are pure; validate checks runs against data/dictionary.yaml
  before load; load writes byte-stable files only when they change
- data/public/runs_clean.csv: every run from every source with a new
  `source` column (reddit spreadsheet, reddit thread, reported, bot,
  reddit pdf); the sheet's own row label moves to `entry`; run_id is text
- bot importer ported to Python (same output as bot.js on the fixture);
  labels and crosswalk in collection/specs/bot.yaml, written into graph.js
- Reddit through the official API (result links to add by hand); the 12
  result pages move to collection/manual/reddit_results.yaml
- "Report a run": a GitHub issue form generated from
  collection/specs/report_form.yaml, collected as source "reported", plus a
  site tab pointing to it, the community spreadsheet and the megathread
- analysis and the route model read runs_clean.csv (sources in
  measures.yaml); stats.json and policy.json unchanged apart from the
  factor's new name
- daily workflow runs the pipeline; the raw store is kept between runs in
  the Actions cache, encrypted with RAW_ARCHIVE_KEY

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

56 lines
2.7 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);
});
test("every choice the bot has seen maps onto a form variable, except answers inside a bonding encounter", () => {
const scenes = require("../../data/bot/scenes.json");
const unmapped = [];
for (const s of Object.values(scenes)) {
if (s.options.length < 2) continue; // nothing to choose
if (/two Greens in the clearing/.test(s.label)) continue; // answers at the Greens' encounter: not modelled yet
for (const o of s.options) if (!G.CROSSWALK.some(([re]) => re.test(G.norm(o.text)))) unmapped.push(`${s.label}: ${o.text}`);
}
assert.deepStrictEqual(unmapped, []);
});