import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import { test } from 'node:test'; import { createGeneratedArtifacts } from '../../src/index.js'; import { generateDocumentation } from '../../src/generators/documentation.js'; import { validateSchematronXml } from '../../src/validator/schematron-validator.js'; const bootstrapUrl = new URL('../../../../bootstrap.xml', import.meta.url); const schematronUrl = new URL('../../../../schemas/ProjectOS.sch', import.meta.url); test('validates bootstrap and generates the MCP server and profile registries', async () => { const xml = await readFile(bootstrapUrl, 'utf8'); const schematron = await readFile(schematronUrl, 'utf8'); assert.deepEqual(validateSchematronXml(xml, schematron), []); const artifacts = createGeneratedArtifacts(xml); assert.deepEqual(artifacts['mcp.generated.json'], [ { name: 'filesystem', adapter: 'filesystem', trust: 'High', enabled: true, authMode: 'none', accessMode: 'read-only' }, { name: 'git', adapter: 'git', trust: 'High', enabled: false, authMode: 'none', accessMode: 'read-only' }, { name: 'github-readonly', adapter: 'github', trust: 'Verified', enabled: true, authMode: 'oauth', accessMode: 'read-only' }, { name: 'github-write', adapter: 'github', trust: 'High', enabled: false, authMode: 'oauth', accessMode: 'read-write' }, { name: 'postgres-readonly', adapter: 'postgres', trust: 'Verified', enabled: true, authMode: 'keyring', credentialRef: 'PROJECTOS_POSTGRES_READ_PROFILE', accessMode: 'read-only' }, { name: 'postgres-write', adapter: 'postgres', trust: 'High', enabled: false, authMode: 'keyring', credentialRef: 'PROJECTOS_POSTGRES_WRITE_PROFILE', accessMode: 'read-write' }, { name: 'fetch', adapter: 'fetch', trust: 'Medium', enabled: true, authMode: 'none', accessMode: 'read-only' }, { name: 'memory', adapter: 'memory', trust: 'High', enabled: true, authMode: 'none', accessMode: 'read-only' } ]); assert.deepEqual(artifacts['mcp-profiles.generated.json'].map(({ name, servers, enabled }) => ({ name, servers, enabled })), [ { name: 'workspace', servers: ['filesystem', 'memory'], enabled: true }, { name: 'research', servers: ['fetch', 'github-readonly'], enabled: true }, { name: 'implementation', servers: ['filesystem', 'github-readonly'], enabled: true }, { name: 'database-readonly', servers: ['postgres-readonly'], enabled: true }, { name: 'database-write', servers: ['postgres-write'], enabled: false } ]); }); test('rejects a bootstrap that has no declared MCP servers', async () => { const xml = await readFile(bootstrapUrl, 'utf8'); const schematron = await readFile(schematronUrl, 'utf8'); const invalid = xml.replace(/[\s\S]*?<\/mcpServers>/, ''); assert.ok(validateSchematronXml(invalid, schematron).some((issue) => issue.includes('At least one MCP server'))); }); test('provides a generated documentation template for every enabled manifest output', async () => { const xml = await readFile(bootstrapUrl, 'utf8'); const artifacts = createGeneratedArtifacts(xml); const names = [...xml.matchAll(//g)].map((match) => match[1]); const docs = generateDocumentation({ project: artifacts['projectos.generated.json'], storage: artifacts['generated/storage.generated.json'], symbols: artifacts['generated/symbol-aliases.generated.json'], bootstrap: { schema: 'schemas/ProjectOS.xsd', schematron: 'schemas/ProjectOS.sch', output: 'configs' } }, names); assert.equal(Object.keys(docs).length, names.length); for (const name of names) { const file = docs[`docs/${name.toUpperCase()}.md`]; assert.ok(file?.startsWith('