node-tools hands each bundle its own environment (hq ADR 0192)
The mesh composes every served module's words into MESH_TOOL_ENV; the runtime takes it at start and removes it from its own environment, then gives each registration's contributor and each launched child the runtime's words plus its own module's, never another's. Against an SDK without collectToolsEach it says so and serves with the runtime's words only. The test serves two imported bundles and one launched, each answering with its own words and none of the others'.
This commit is contained in:
@@ -21,7 +21,7 @@ import { resetTools } from "@novox/mesh-sdk/tools";
|
||||
import { connectNats, membershipSubject } from "../dist/broker-nats.js";
|
||||
import { callTool, toolsOn } from "../dist/client.js";
|
||||
import { servedModulesFrom } from "../dist/main.js";
|
||||
import { runTools } from "../dist/runtime.js";
|
||||
import { runTools, takeToolEnvs } from "../dist/runtime.js";
|
||||
|
||||
const url = process.env.MESH_TEST_NATS;
|
||||
const fixture = (name: string) => fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url));
|
||||
@@ -241,3 +241,51 @@ test("a bundle carrying its own copy of the SDK registers into the runtime's reg
|
||||
resetTools();
|
||||
}
|
||||
});
|
||||
|
||||
test("each bundle is given its own environment and none of another's, imported or launched (ADR 0192)", async (t) => {
|
||||
if (!url) return t.skip("MESH_TEST_NATS unset");
|
||||
resetTools();
|
||||
const mesh = await aMesh();
|
||||
for (const m of ["gamma", "delta", "zeta"]) await mesh.issue(membershipOf(m, "anchor"));
|
||||
const credential = { url, node: "anchor", module: "node-tools" };
|
||||
const nodeTools = await connectNats(credential);
|
||||
const asker = await connectNats({ url, module: "console", node: "workstation" });
|
||||
const log = console.log;
|
||||
let stop = () => {};
|
||||
const before = process.env.MESH_TOOL_ENV;
|
||||
try {
|
||||
process.env.MESH_OPERATOR_ACCOUNT = "somebody";
|
||||
process.env.MESH_TOOL_ENV = JSON.stringify({
|
||||
gamma: { GAMMA_CONFIG_FILE: "/var/lib/mesh/gamma/config.json" },
|
||||
delta: { DELTA_TOKEN_FILE: "/var/lib/mesh/delta/token" },
|
||||
zeta: { ZETA_URL: "http://127.0.0.1:3000" },
|
||||
});
|
||||
const envs = takeToolEnvs();
|
||||
assert.equal(process.env.MESH_TOOL_ENV, undefined, "the composed environments were left in the process's");
|
||||
console.log = () => {};
|
||||
stop = await runTools({
|
||||
broker: nodeTools, credential, envs,
|
||||
serves: [
|
||||
{ module: "gamma", entrypoints: [fixture("env-gamma.mjs")] },
|
||||
{ module: "delta", entrypoints: [fixture("env-delta.mjs")] },
|
||||
{ module: "zeta", entrypoints: [fixture("env-zeta.mjs")] },
|
||||
],
|
||||
});
|
||||
console.log = log;
|
||||
assert.deepEqual((await callTool(asker, "gamma.given@anchor", {})).result,
|
||||
{ mine: "/var/lib/mesh/gamma/config.json", theirs: null, runtime: "somebody", composed: null });
|
||||
assert.deepEqual((await callTool(asker, "delta.given@anchor", {})).result,
|
||||
{ mine: "/var/lib/mesh/delta/token", theirs: null });
|
||||
assert.deepEqual((await callTool(asker, "zeta.given@anchor", {})).result,
|
||||
{ mine: "http://127.0.0.1:3000", theirs: null, composed: null });
|
||||
} finally {
|
||||
console.log = log;
|
||||
if (before === undefined) delete process.env.MESH_TOOL_ENV; else process.env.MESH_TOOL_ENV = before;
|
||||
delete process.env.MESH_OPERATOR_ACCOUNT;
|
||||
stop();
|
||||
await asker.close();
|
||||
await nodeTools.close();
|
||||
await mesh.close();
|
||||
resetTools();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user