Files
pepa-pi-bot/runtime/goal/skill-graph.test.js
mayatnikovandClaude Opus 4.8 cd63edfeaf feat(v0.4.1): make the Settlement Contract honest end-to-end
Patches each link of the closed-loop chain (world-truth -> invariant ->
dispatch -> worldDelta -> milestone) so the contract can no longer advance
on a lie or stall on an unreachable milestone, and surfaces the result on
the monitor.

- Unblock M6_lighting: add gather.coal producer (mirrors gather.stone,
  strict expectGain), register it, add the skill-graph node, and make
  curriculum.shelter.torch two-step (gather coal -> craft torch). craft.torch
  needed coal but no skill produced it, so the contract pinned on M6 forever
  and starved M7/M8/M9. One curriculum edit fixes both rails.
- M8 no longer falsely satisfied: build-shelter records locations.shelter
  only on real progress (setLocation moved below the no_progress guard).
- M2_bed made monotonic: sleepInBed writes locations.bed when the bot places
  its own bed, so M2 stays met after the carried bed item is consumed.
- Observability: new ink-free tui/format.js helper renders per-tick
  state / firing rail / active skill / blocked prerequisite / stall reason
  in the monitor header (fields bot.js already computes but never showed).
- Harden the valid-skill-id guardrail: skillRegistryPrompt preserves the
  "NEVER invent" footer when truncating (a growing registry was dropping it),
  and fix the stale "tech-tree > autonomous" reflex chain in the escalation
  prompt.

Tests: 494/494 passing; new build-shelter / invariants / format suites plus
skill-graph, curriculum, skill-registry cases. lint-patch clean. Deferred
audit findings recorded in plans/v0.4.0-vnext.md (local).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 12:33:45 +03:00

75 lines
3.0 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { prerequisitesMet, canRun, runnableFrontier, _internal } from "./skill-graph.js";
function world(inv = {}) {
return { inventory: inv };
}
test("gather.logs needs nothing", () => {
assert.equal(canRun("gather.logs", world()), true);
});
test("gather.stone needs a pickaxe (any tier)", () => {
assert.equal(canRun("gather.stone", world({})), false);
assert.equal(canRun("gather.stone", world({ wooden_pickaxe: 1 })), true);
assert.equal(canRun("gather.stone", world({ stone_pickaxe: 1 })), true);
});
test("craft.planks needs a log (semantic group)", () => {
assert.equal(canRun("craft.planks", world({})), false);
assert.equal(canRun("craft.planks", world({ birch_log: 1 })), true);
assert.equal(canRun("craft.planks", world({ mangrove_stem: 2 })), true);
});
test("craft.furnace needs 8 cobblestone", () => {
assert.equal(canRun("craft.furnace", world({ cobblestone: 7 })), false);
assert.equal(canRun("craft.furnace", world({ cobblestone: 8 })), true);
assert.equal(canRun("craft.furnace", world({ cobbled_deepslate: 8 })), true);
});
test("prerequisitesMet reports the missing requirement detail", () => {
const r = prerequisitesMet("craft.wooden-pickaxe", world({ stick: 2 }));
assert.equal(r.ok, false);
assert.deepEqual(r.missing, [{ item: "planks", min: 3, have: 0 }]);
});
test("unknown skill is treated as runnable (known:false)", () => {
const r = prerequisitesMet("explore.far", world());
assert.equal(r.ok, true);
assert.equal(r.known, false);
});
test("gather.coal needs a pickaxe and produces coal (closes the M6 dead-end)", () => {
assert.equal(canRun("gather.coal", world({})), false);
assert.equal(canRun("gather.coal", world({ wooden_pickaxe: 1 })), true);
assert.equal(canRun("gather.coal", world({ stone_pickaxe: 1 })), true);
});
test("craft.torch is blocked without coal but runnable once coal is gathered", () => {
assert.equal(canRun("craft.torch", world({ stick: 1 })), false);
assert.equal(canRun("craft.torch", world({ stick: 1, coal: 1 })), true);
// charcoal counts as coal (semantic group)
assert.equal(canRun("craft.torch", world({ stick: 1, charcoal: 1 })), true);
});
test("runnableFrontier includes gather.coal once a pickaxe is held", () => {
assert.ok(!runnableFrontier(world()).includes("gather.coal"));
assert.ok(runnableFrontier(world({ wooden_pickaxe: 1 })).includes("gather.coal"));
});
test("axe matcher excludes pickaxe", () => {
assert.equal(_internal.TOOL.axe("wooden_axe"), true);
assert.equal(_internal.TOOL.axe("wooden_pickaxe"), false);
assert.equal(_internal.TOOL.pickaxe("stone_pickaxe"), true);
});
test("runnableFrontier grows as inventory fills", () => {
const empty = runnableFrontier(world());
const stocked = runnableFrontier(world({ oak_planks: 8, stick: 4, cobblestone: 8, wooden_pickaxe: 1 }));
assert.ok(stocked.length > empty.length);
assert.ok(stocked.includes("gather.stone"));
assert.ok(stocked.includes("craft.furnace"));
});