stdlib / tests / init.test.mjsmain at 41005ca
// tests/init.test.mjs — the publish hook's steps (../init.ts): a step that throws does not stop
// the steps after it, and the agents are installed from this repo's own module.
// Run from the repo's root: node --test "tests/*.test.mjs"
import assert from "node:assert/strict";
import { test } from "node:test";
import { init, step } from "../init.ts";
test("a step that throws does not stop the steps after it", async () => {
const ran = [];
await step("first", async () => {
throw new Error("this step is broken");
});
await step("second", async () => void ran.push("second"));
assert.deepEqual(ran, ["second"]);
});
test("init installs the agents: the collection's class is the one stdlib/agents.ts exports", async () => {
const enabled = [];
const appended = [];
const context = (path) => ({
append: async (...events) => void appended.push(...events.map((event) => ({ path, event }))),
processors: {
enable: async (name, spec) => void enabled.push({ path, name, spec }),
disable: async () => {},
list: async () => [],
},
});
await init({ ...context("/"), cd: context });
assert.deepEqual(
enabled.map(({ path, name, spec }) => ({
path,
name,
className: spec.className,
mainModule: spec.mainModule,
source: spec.source,
})),
[
{
path: "/agents",
name: "agents",
className: "AgentCollectionDurableObject",
// the module's name in the mind's code: the repo's folder, then the file
mainModule: "stdlib/agents.ts",
source: ["itx", ["cd", "/"], "config"],
},
],
);
// the root's rule for `itx.agents` names the same module
const rule = appended.find(
({ path, event }) => path === "/" && event.payload.match === "itx.agents",
);
assert.deepEqual(rule.event.payload.target, [
"itx",
["cd", "/agents"],
"facets",
[
"get",
"agents",
{
className: "AgentCollectionDurableObject",
mainModule: "stdlib/agents.ts",
source: ["itx", ["cd", "/"], "config"],
},
],
]);
});