Third day of "bot just walks back and forth burning tokens". Root
causes were mechanical, not the manifesto:
1. SATED BOT CHASING FOOD (the big one)
Bot had food=17 (nearly full) but storyline first_food + manifesto
L1 required 2+ food ITEMS in inventory, so it looped scout-food /
acquire-food for hours instead of working. Now both treat a hunger
bar >= 14 (SATED_FOOD) as satisfied even with empty food inventory —
a full bot chops wood / makes tools and grabs food opportunistically,
only hard-pursuing food when actually hungry (< 14).
manifesto/needs.js foodDetect + goal/storyline.js first_food.completed.
2. perf_hooks MEMORY LEAK (overnight OOM suspect)
"MaxPerformanceEntryBufferExceededWarning: 1,000,001 measure entries".
mineflayer/pathfinder emit perf marks we never consume. Added a
60s reaper in bot.js (performance.clearMeasures/clearMarks). unref'd.
3. IMPROVEMENT QUEUE SELF-DUPLICATING
The LLM re-filed closed gaps with reworded titles (#5/#8/#9 were
dupes of implemented #1/#2/#3). Exact-title dedup missed them.
Replaced with token-set fuzzy match (isDuplicateTitle): jaccard>=0.75
OR >=3 shared meaningful tokens with jaccard>=0.5. Also: a re-filed
gap that's already implemented/rejected is NOT resurrected as a new
open row. Cleared all 5 open requests (now genuinely implemented).
Also confirmed (no change needed):
- canDig=true is a DELIBERATE codebase-wide choice ("without it the bot
gets permanently stuck", actions.js). The stale memory recommending
canDig=false is updated. ViaBackwards dig works partially (dug:1
moved:1.8 observed); false would trap the bot in every pit.
- scout-food already has blind/tunnel fallback + 12s step timeout
(operator's earlier edits) so trapped-pathfinder degrades instead of
hanging 30s.
Tests: 407 green (was 404). Updated needs/state/storyline tests for the
SATED_FOOD threshold; added fuzzy-dedup + tokenize/jaccard tests.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
211 lines
7.7 KiB
JavaScript
211 lines
7.7 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { STORYLINE, getStep, __testing } from "./storyline.js";
|
|
import { pickCurrentStep, progressSummary, _resetForTest } from "./state.js";
|
|
|
|
function snap(overrides = {}) {
|
|
return {
|
|
connected: true,
|
|
health: 20,
|
|
food: 20,
|
|
hasFood: false,
|
|
inventory: {},
|
|
equipment: { hand: null, head: null, torso: null, legs: null, feet: null },
|
|
nearbyBlocks: {},
|
|
hazards: { footBlock: "grass_block", belowBlock: "dirt", headBlock: "air" },
|
|
isDay: true,
|
|
hostileCount: 0,
|
|
closestHostile: null,
|
|
_sessionMs: 60_000,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
test("STORYLINE: 11 steps, all have id/title/narration/completed/suggestSkill", () => {
|
|
assert.equal(STORYLINE.length, 11);
|
|
for (const s of STORYLINE) {
|
|
assert.ok(s.id, `step missing id`);
|
|
assert.ok(s.title);
|
|
assert.ok(s.narration_ru);
|
|
assert.equal(typeof s.completed, "function");
|
|
assert.equal(typeof s.suggestSkill, "function");
|
|
}
|
|
// Ids unique
|
|
const ids = STORYLINE.map((s) => s.id);
|
|
assert.equal(new Set(ids).size, ids.length);
|
|
});
|
|
|
|
test("getStep: lookup by id", () => {
|
|
assert.equal(getStep("first_wood").title, "Собрать стартовое дерево");
|
|
assert.equal(getStep("does-not-exist"), null);
|
|
});
|
|
|
|
test("emergencyPause: low hp + close hostile → true", () => {
|
|
const { emergencyPause } = __testing;
|
|
assert.equal(emergencyPause(snap({ health: 4, closestHostile: { name: "zombie", distance: 3 } })), true);
|
|
assert.equal(emergencyPause(snap()), false);
|
|
assert.equal(emergencyPause(snap({ hazards: { footBlock: "lava" } })), true);
|
|
assert.equal(emergencyPause(snap({ food: 0 })), true);
|
|
});
|
|
|
|
test("step first_wood: completed when bootstrap wood budget is enough", () => {
|
|
const s = getStep("first_wood");
|
|
assert.equal(s.completed(snap()), false);
|
|
assert.equal(s.completed(snap({ inventory: { oak_log: 4 } })), true);
|
|
assert.equal(s.completed(snap({ inventory: { oak_log: 2, oak_planks: 8 } })), true);
|
|
assert.equal(s.completed(snap({ inventory: { wooden_pickaxe: 1 } })), true);
|
|
});
|
|
|
|
test("step first_wood: suggest gather.logs if trees nearby, explore.far otherwise", () => {
|
|
const s = getStep("first_wood");
|
|
assert.equal(s.suggestSkill(snap({ nearbyBlocks: { logs: 5 } })).skillId, "gather.logs");
|
|
assert.equal(s.suggestSkill(snap({ nearbyBlocks: { logs: { count: 1 } } })).skillId, "gather.logs");
|
|
assert.equal(s.suggestSkill(snap()).skillId, "explore.far");
|
|
});
|
|
|
|
test("step first_tools: requires all three wood tools", () => {
|
|
const s = getStep("first_tools");
|
|
assert.equal(s.completed(snap({ inventory: { wooden_pickaxe: 1 } })), false);
|
|
assert.equal(s.completed(snap({ inventory: { wooden_pickaxe: 1, wooden_axe: 1 } })), false);
|
|
assert.equal(s.completed(snap({ inventory: { wooden_pickaxe: 1, wooden_axe: 1, wooden_sword: 1 } })), true);
|
|
// Higher tier also counts
|
|
assert.equal(s.completed(snap({ inventory: { stone_pickaxe: 1, stone_axe: 1, stone_sword: 1 } })), true);
|
|
});
|
|
|
|
test("step first_food: completed at ≥2 food items, OR when sated (food≥14)", () => {
|
|
const s = getStep("first_food");
|
|
// hungry + no food → not done
|
|
assert.equal(s.completed(snap({ food: 8 })), false);
|
|
// hungry + 2 food items → done (have a stock)
|
|
assert.equal(s.completed(snap({ food: 8, inventory: { bread: 2 } })), true);
|
|
// sated (food≥14) + no food → done (don't chase food while full)
|
|
assert.equal(s.completed(snap({ food: 17 })), true);
|
|
});
|
|
|
|
test("step first_food: local hunt only for edible passive mobs within acquire range", () => {
|
|
const s = getStep("first_food");
|
|
assert.equal(
|
|
s.suggestSkill(snap({ nearbyEntities: { passives: [{ name: "chicken", distance: 18 }] } })).skillId,
|
|
"survive.acquire-food",
|
|
);
|
|
assert.equal(
|
|
s.suggestSkill(snap({ nearbyEntities: { passives: [{ name: "chicken", distance: 51 }] } })).skillId,
|
|
"survive.scout-food",
|
|
);
|
|
assert.equal(
|
|
s.suggestSkill(snap({ nearbyEntities: { passives: [{ name: "cod", distance: 12 }] } })).skillId,
|
|
"survive.scout-food",
|
|
);
|
|
});
|
|
|
|
test("step shelter_minimal: completed when bed placed nearby", () => {
|
|
const s = getStep("shelter_minimal");
|
|
assert.equal(s.completed(snap()), false);
|
|
assert.equal(s.completed(snap({ nearbyBlocks: { beds: 1 } })), true);
|
|
assert.equal(s.completed(snap({ nearbyBlocks: { beds: { count: 1 } } })), true);
|
|
});
|
|
|
|
test("step stone_tier: needs cobblestone first", () => {
|
|
const s = getStep("stone_tier");
|
|
assert.equal(s.completed(snap()), false);
|
|
assert.equal(s.suggestSkill(snap()).skillId, "gather.stone");
|
|
assert.equal(s.suggestSkill(snap({ inventory: { cobblestone: 6, stick: 4 } })).skillId, "craft.stone-pickaxe");
|
|
});
|
|
|
|
test("village_grow: never auto-completes (ongoing)", () => {
|
|
const s = getStep("village_grow");
|
|
assert.equal(s.completed(snap({ inventory: { iron_pickaxe: 1, diamond_pickaxe: 1 } })), false);
|
|
});
|
|
|
|
test("pickCurrentStep: disconnected → null", () => {
|
|
_resetForTest();
|
|
assert.equal(pickCurrentStep({ connected: false }), null);
|
|
});
|
|
|
|
test("pickCurrentStep: fresh spawn → first non-completed step", () => {
|
|
_resetForTest();
|
|
const s = snap({ _sessionMs: 5_000, nearbyBlocks: {} });
|
|
const r = pickCurrentStep(s);
|
|
assert.ok(r);
|
|
// orient_self is the first; with no nearby blocks and short session,
|
|
// completed() returns false → picked.
|
|
assert.equal(r.step.id, "orient_self");
|
|
assert.equal(r.index, 0);
|
|
});
|
|
|
|
test("orient_self: barren biome timeout fallback completes step after 120s", () => {
|
|
const n = getStep("orient_self");
|
|
// path (a): full HP + no visible blocks + short session → NOT done (would block).
|
|
assert.equal(n.completed(snap({ _sessionMs: 30_000, nearbyBlocks: {} })), false);
|
|
// path (b): full HP + no visible blocks + long session → done (timeout fallback).
|
|
assert.equal(n.completed(snap({ _sessionMs: 150_000, nearbyBlocks: {} })), true);
|
|
// always: low HP → not done
|
|
assert.equal(n.completed(snap({ health: 8, _sessionMs: 150_000 })), false);
|
|
});
|
|
|
|
test("pickCurrentStep: bot with 8+ logs → first_wood done, picks crafting_basics", () => {
|
|
_resetForTest();
|
|
const r = pickCurrentStep(snap({
|
|
_sessionMs: 60_000,
|
|
nearbyBlocks: { logs: 3 },
|
|
inventory: { oak_log: 10 },
|
|
}));
|
|
assert.ok(r);
|
|
assert.equal(r.step.id, "crafting_basics");
|
|
assert.equal(r.completedSteps, 2, "orient_self + first_wood done");
|
|
});
|
|
|
|
test("pickCurrentStep: bot with planks and sticks advances to first_tools", () => {
|
|
_resetForTest();
|
|
const r = pickCurrentStep(snap({
|
|
_sessionMs: 60_000,
|
|
nearbyBlocks: { logs: { count: 3 } },
|
|
inventory: { oak_planks: 16, stick: 4 },
|
|
}));
|
|
assert.ok(r);
|
|
assert.equal(r.step.id, "first_tools");
|
|
assert.equal(r.suggestion.skillId, "craft.wooden-pickaxe");
|
|
});
|
|
|
|
test("pickCurrentStep: emergency pauses suggestion", () => {
|
|
_resetForTest();
|
|
const r = pickCurrentStep(snap({
|
|
health: 4,
|
|
closestHostile: { name: "zombie", distance: 3 },
|
|
nearbyBlocks: { logs: 2 },
|
|
}));
|
|
assert.ok(r);
|
|
assert.equal(r.emergency, true);
|
|
assert.equal(r.suggestion, null, "no concrete suggestion while emergency holds");
|
|
});
|
|
|
|
test("pickCurrentStep: rejects unknown skill ids from suggestSkill", () => {
|
|
_resetForTest();
|
|
// Inject a synthetic step with bogus skill — but STORYLINE is frozen,
|
|
// so we just verify that real ids are valid (sanity check).
|
|
const r = pickCurrentStep(snap({
|
|
_sessionMs: 60_000,
|
|
nearbyBlocks: { logs: 2 },
|
|
}));
|
|
if (r?.suggestion?.skillId) {
|
|
// All real STORYLINE skill ids should be registered.
|
|
// (skill-registry imports a frozen list of skills/index.js.)
|
|
assert.ok(r.suggestion.skillId.includes("."), "skill id is namespaced");
|
|
}
|
|
});
|
|
|
|
test("progressSummary: formats step n/N + skill + emergency tag", () => {
|
|
_resetForTest();
|
|
const s1 = progressSummary(snap({ _sessionMs: 5_000 }));
|
|
assert.match(s1, /step 1\/11/);
|
|
assert.match(s1, /orient_self/);
|
|
|
|
_resetForTest();
|
|
const s2 = progressSummary(snap({
|
|
health: 3,
|
|
closestHostile: { name: "creeper", distance: 2 },
|
|
}));
|
|
assert.match(s2, /EMERGENCY/);
|
|
});
|