| import { test } from "node:test"; |
| import assert from "node:assert/strict"; |
| import { promises as fs } from "node:fs"; |
| import path from "node:path"; |
| import os from "node:os"; |
| import { loadRegisteredCapabilities } from "../loader.js"; |
| import { getCapability, listCapabilities } from "../registry.js"; |
|
|
| |
| |
| |
| |
| |
| |
| void test("capability/loader: scans manifest files and auto-registers them", async () => { |
| |
| const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "cap-loader-test-")); |
| try { |
| const m1 = path.join(tmp, "alpha.manifest.mjs"); |
| const m2 = path.join(tmp, "beta.manifest.mjs"); |
| const ignored = path.join(tmp, "readme.txt"); |
| await fs.writeFile( |
| m1, |
| `export default { |
| id: "cap_loader_test_alpha", |
| name: "loader_test_alpha", |
| domain: "test", |
| boundNetworkName: null, |
| manifestVersion: 1, |
| };\n`, |
| ); |
| await fs.writeFile( |
| m2, |
| `export default { |
| id: "cap_loader_test_beta", |
| name: "loader_test_beta", |
| domain: "test", |
| boundNetworkName: null, |
| manifestVersion: 1, |
| };\n`, |
| ); |
| await fs.writeFile(ignored, "not a manifest\n"); |
|
|
| const result = await loadRegisteredCapabilities(tmp); |
|
|
| assert.equal(result.errors.length, 0, `unexpected errors: ${JSON.stringify(result.errors)}`); |
| assert.deepEqual( |
| [...result.loaded].sort(), |
| ["cap_loader_test_alpha", "cap_loader_test_beta"], |
| "both manifests should be loaded; the .txt file should be ignored", |
| ); |
|
|
| |
| |
| |
| const alpha = getCapability("cap_loader_test_alpha"); |
| const beta = getCapability("cap_loader_test_beta"); |
| assert.ok(alpha, "alpha capability missing from registry after boot scan"); |
| assert.ok(beta, "beta capability missing from registry after boot scan"); |
| assert.equal(alpha!.manifest.name, "loader_test_alpha"); |
| assert.equal(beta!.manifest.name, "loader_test_beta"); |
|
|
| |
| const ids = listCapabilities().map((m) => m.id); |
| assert.ok(ids.includes("cap_loader_test_alpha")); |
| assert.ok(ids.includes("cap_loader_test_beta")); |
| } finally { |
| await fs.rm(tmp, { recursive: true, force: true }); |
| } |
| }); |
|
|
| void test("capability/loader: DOATLAS_CAPABILITY_LAYER_ENABLED=false short-circuits", async () => { |
| const prev = process.env["DOATLAS_CAPABILITY_LAYER_ENABLED"]; |
| process.env["DOATLAS_CAPABILITY_LAYER_ENABLED"] = "false"; |
| try { |
| const result = await loadRegisteredCapabilities("/this/path/does/not/exist"); |
| assert.deepEqual(result, { loaded: [], errors: [] }); |
| } finally { |
| if (prev === undefined) delete process.env["DOATLAS_CAPABILITY_LAYER_ENABLED"]; |
| else process.env["DOATLAS_CAPABILITY_LAYER_ENABLED"] = prev; |
| } |
| }); |
|
|