kernel / core / itx / src / context / worker-loader.test.tsmain at 949894f
import { expect, test } from "vitest";
import { namedWorkerLoad } from "./worker-loader.ts";
test("a module of the published config is found by its name in the tree and by its name from the entry repo's root", () => {
const byRootName = namedWorkerLoad(
{ spec: pointer(), vouched: true },
"apps/agents/backend.ts",
"test",
"AgentsDurableObject",
);
const byTreeName = namedWorkerLoad(
{ spec: pointer(), vouched: true },
"config/apps/agents/backend.ts",
"test",
);
expect(byRootName).toMatchObject({ moduleIdentity: "identity of the backend", generation: 7 });
expect(byTreeName).toMatchObject({ moduleIdentity: "identity of the backend", generation: 7 });
// a name that two repos have: with no folder it is the entry repo's, with a folder that repo's
expect(namedWorkerLoad({ spec: pointer(), vouched: true }, "agents.ts", "test")).toMatchObject({
moduleIdentity: "identity of config's agents",
});
expect(
namedWorkerLoad({ spec: pointer(), vouched: true }, "stdlib/agents.ts", "test"),
).toMatchObject({ moduleIdentity: "identity of stdlib's agents" });
expect(() => namedWorkerLoad({ spec: pointer(), vouched: true }, "apps/none.ts", "test")).toThrow(
'test: the worker its source names publishes no module "apps/none.ts"',
);
expect(() =>
namedWorkerLoad({ spec: pointer(), vouched: true }, "apps/agents/backend.ts", "test", "Other"),
).toThrow('publishes no Durable Object class "Other" in "apps/agents/backend.ts"');
});
/** The config pointer of a mind whose entry repo is `config`, as a publication writes it. */
function pointer() {
return {
source: ["itx", "config", ["modules", {}]],
cacheKey: "tree",
mainModule: "config/worker.ts",
manifest: {
generation: 7,
modules: {
"config/worker.ts": { identity: "identity of the entry", classes: [] },
"config/agents.ts": { identity: "identity of config's agents", classes: [] },
"stdlib/agents.ts": { identity: "identity of stdlib's agents", classes: [] },
"config/apps/agents/backend.ts": {
identity: "identity of the backend",
classes: ["AgentsDurableObject"],
},
},
},
};
}