// Guards Eleven's knowledge base. node test/knowledge.test.mjs // This text is injected into Eleven's system prompt and is effectively extractable // by anyone chatting with it, so the critical invariant is: it contains OPEN // design knowledge and NO operational secrets. This test fails loudly if a future // edit ever pastes an address, token, key, or instance name into it. import assert from "node:assert/strict"; import { APP_KNOWLEDGE } from "../agent/knowledge.mjs"; let failures = 0; function test(name, fn) { try { fn(); console.log(`PASS ${name}`); } catch (e) { failures++; console.log(`FAIL ${name} — ${e && e.message}`); } } test("the knowledge base is substantial (not accidentally emptied)", () => { assert.equal(typeof APP_KNOWLEDGE, "string"); assert.ok(APP_KNOWLEDGE.length > 10000, `too short: ${APP_KNOWLEDGE.length} chars`); // Spot-check that it actually covers the core topics. for (const topic of [/end-to-end/i, /thread/i, /invite/i, /remind/i, /Announcer/, /passkey|backup/i]) { assert.match(APP_KNOWLEDGE, topic); } }); test("the knowledge base leaks NO operational secrets", () => { const forbidden = [ [/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/, "an IP address"], [/run\.garden|elevenmessenger\.com|paulca/i, "a real hostname/instance"], [/hetzner|\bmiren\b|1password|\bop\b\s+(?:read|item)/i, "an operator/tooling name"], [/\.p8\b|J5NDF5|ZKYQ9|9X6NKTF|admintok|LCHAT_ADMIN_TOKEN|Bearer\s+\w/i, "a key/token"], [/BEGIN (?:EC |RSA |OPENSSH )?PRIVATE KEY/i, "a private key"], [/ssh\s+root@|root@\d/i, "an SSH target"], ]; for (const [re, what] of forbidden) { assert.doesNotMatch(APP_KNOWLEDGE, re, `knowledge base appears to contain ${what}`); } }); console.log(failures === 0 ? "\nALL PASSED" : `\n${failures} FAILED`); process.exit(failures === 0 ? 0 : 1);