import { spawnSync } from 'node:child_process'; import { mkdir, mkdtemp, readFile, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; const repoRoot = path.resolve( path.dirname(fileURLToPath(import.meta.url)), '..', ); const cliPath = path.join(repoRoot, 'dist', 'cli.js'); const projectRoot = await mkdtemp( path.join(tmpdir(), 'mancode-dist-adapters-'), ); try { await mkdir(projectRoot, { recursive: true }); runCli(['init', '--empty', '--platform', 'all', '--lang', 'en']); const bootstrapFiles = new Set([ 'CLAUDE.md', '.cursor/rules/mancode-continuity.mdc', 'AGENTS.md', '.github/copilot-instructions.md', ]); const manFiles = new Set([ '.claude/skills/man/SKILL.md', '.cursor/commands/man.md', '.agents/skills/man/SKILL.md', '.dsh/skills/man/SKILL.md', '.github/prompts/man.prompt.md', '.qoder/commands/man.md', ]); const manteamFiles = new Set([ '.claude/skills/manteam/SKILL.md', '.cursor/commands/manteam.md', '.agents/skills/manteam/SKILL.md', '.dsh/skills/manteam/SKILL.md', '.github/prompts/manteam.prompt.md', '.qoder/commands/manteam.md', ]); const manbaFiles = new Set([ '.claude/skills/manba/SKILL.md', '.cursor/commands/manba.md', '.agents/skills/manba/SKILL.md', '.dsh/skills/manba/SKILL.md', '.github/prompts/manba.prompt.md', '.qoder/commands/manba.md', ]); const generatedFiles = [...bootstrapFiles, ...manFiles, ...manteamFiles, ...manbaFiles]; for (const relativePath of generatedFiles) { const content = await readFile( path.join(projectRoot, relativePath), 'utf8', ); assertGeneratedContract(relativePath, content); if (manFiles.has(relativePath) || manbaFiles.has(relativePath)) { assertContainsAll(relativePath, content, [ 'mancode review inspect --base --json', 'Keep every actionable required finding', 'npm run check', 'unverified acceptance', ]); } if (manbaFiles.has(relativePath)) { assertContainsAll(relativePath, content, [ 'A standalone audit needs no actor, session, TaskRef or workflow', 'An audit of a Man task never changes it into manba', 'does not replace its parent task acceptance', ]); } if (bootstrapFiles.has(relativePath)) { assertContainsAll(relativePath, content, [ 'accepted target', 'task-owned diff', 'Rejected session-only proposals', 'mark them unverified', ]); } if (manFiles.has(relativePath)) { assertContainsAll(relativePath, content, [ 'completion, a commit, or a PR', 'accepted requirements and plan', 'task-owned diff from the bound `baseHead`', 'Preserve failures, blockers', 'report it as unverified', ]); } if (manteamFiles.has(relativePath)) { assertContainsAll(relativePath, content, [ 'Before any handoff, commit, or PR', 'current authoritative task and handoff state plus the task-owned diff', 'every formal handoff status and resolution reason', 'mark it unverified', ]); } } const status = runCli(['status', '--brief', '--json']); const parsed = JSON.parse(status.stdout); assert( parsed.runtime === 'mancode-continuity' && parsed.state === 'active', `compiled status returned an unexpected runtime: ${status.stdout}`, ); assert( !status.stdout.includes('"v3"') && !status.stdout.includes('v3_active'), `compiled brief status exposed internal version fields: ${status.stdout}`, ); console.log( `Verified ${generatedFiles.length} adapters generated by dist/cli.js.`, ); } finally { await rm(projectRoot, { recursive: true, force: true }); } function runCli(args) { const result = spawnSync(process.execPath, [cliPath, ...args], { cwd: projectRoot, encoding: 'utf8', }); assert( result.status === 0, `compiled CLI failed (${result.status}): ${result.stderr || result.stdout}`, ); return result; } function assertGeneratedContract(relativePath, content) { for (const required of [ 'mancode status --brief --json', 'snapshot already obtained in this conversation', 'mancode Continuity', ]) { assert( content.includes(required), `${relativePath} is missing compiled guidance: ${required}`, ); } for (const forbidden of [ 'mancode status --json', 'authority: "v3"', 'v3_active', 'mancode-v3', 'mancode:v3', ]) { assert( !content.includes(forbidden), `${relativePath} exposes stale guidance: ${forbidden}`, ); } } function assertContainsAll(relativePath, content, requiredValues) { for (const required of requiredValues) { assert( content.includes(required), `${relativePath} is missing compiled delivery guidance: ${required}`, ); } } function assert(condition, message) { if (!condition) throw new Error(message); }