Files
pepa-pi-bot/runtime/goal/skill-graph.test.js
T
mayatnikovandClaude Opus 4.7 c963ab3ecb feat(v0.4.0): finish vNext plan — anti-loop, skill-graph, worldDelta diff, flee→motion
Completes the remaining v0.4.0 plan items and one fix motivated by a live
in-game observation (flee hanging 30s against a persistent zombie).

- flee → MotionService.gotoSafe: structured {stuck|timeout|nopath} in ~4s with
  a blind-retreat fallback, instead of the observed 30s pathfinder hang + 3
  watchdog replans. Movements setup guarded so it is unit-testable.
- QW5 anti-loop (runtime/anti-loop.js): same skill failing >=3x in 5min →
  30min blacklist (reflex shouldSkip) + one-shot improvement_request
  (bot.js drainFired -> writeProposal).
- 4.1 closed-loop worldDelta: runSkill snapshots inventory before execute and
  attaches the real delta (_invObserved) to every successful result; opt-in
  skill.expectGain asserts the claimed gain or returns world_unchanged.
- 3.6 skill-graph (Plan4MC): declarative requires/produces for ~20 skills;
  prerequisitesMet/canRun/runnableFrontier; GoalManager annotates suggestions
  with blockedBy when prereqs are unmet.

+22 tests (472 total green). Live smoke confirmed dig-in works and no new
errors; flee loop is what this commit's flee migration addresses.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 11:20:52 +03:00

57 lines
2.1 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("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"));
});