fix: recover interrupted controller cycles
This commit is contained in:
parent
380fca2b9f
commit
05aeab4817
3 changed files with 49 additions and 3 deletions
|
|
@ -3,7 +3,11 @@ import fs from "node:fs";
|
|||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { ControllerEngine, bootEvent } from "./controller-engine.mjs";
|
||||
import {
|
||||
ControllerEngine,
|
||||
bootEvent,
|
||||
runRuntime,
|
||||
} from "./controller-engine.mjs";
|
||||
|
||||
class FixtureModelClient {
|
||||
async generate({ role, input }) {
|
||||
|
|
@ -167,3 +171,31 @@ test("resident engine completes a model-backed brain and controller cycle", asyn
|
|||
assert.equal(receipt.existence.living_ai_system_controller_running, 100);
|
||||
assert.equal(receipt.completed_cycles, 1);
|
||||
});
|
||||
|
||||
test("an interrupted technical cycle is preserved and restarted in a new state epoch", () => {
|
||||
const stateRoot = fs.mkdtempSync(path.join(os.tmpdir(), "bs-tcs-recovery-"));
|
||||
const first = new ControllerEngine({
|
||||
stateRoot,
|
||||
modelClient: new FixtureModelClient(),
|
||||
modelName: "fixture-model",
|
||||
});
|
||||
first.initialize();
|
||||
const eventFile = path.join(stateRoot, "interrupted-event.json");
|
||||
fs.writeFileSync(eventFile, `${JSON.stringify(bootEvent())}\n`);
|
||||
runRuntime("perceive", [
|
||||
"--state-dir",
|
||||
first.stateDir,
|
||||
"--event",
|
||||
eventFile,
|
||||
]);
|
||||
|
||||
const second = new ControllerEngine({
|
||||
stateRoot,
|
||||
modelClient: new FixtureModelClient(),
|
||||
modelName: "fixture-model",
|
||||
});
|
||||
const status = second.initialize();
|
||||
assert.notEqual(second.stateDir, first.stateDir);
|
||||
assert.equal(status.status, "ENTERED");
|
||||
assert.equal(fs.existsSync(path.join(first.stateDir, "state.json")), true);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue