/** * Manifest-group feature e2e scenarios: compliance (S-series) and tracker (T-series). * * Both features are manifest-group state converged by `devflow init`, and both * fan out across several artifacts, so they share one driver and one set of * assertion rules. * * Each scenario drives `node dist/cli.js` against an isolated temp HOME so no * developer files are touched. $HOME/.claude is seeded before any * init invocation (unseeded → "Claude Code not detected" → vacuous pass). * Assertions check WHOLE end-states (file sets, file content), * never per-step booleans. * * Skipped: * S13 — Advanced-mode init requires TTY for the wizard; non-interactive driver * cannot feed keystrokes. The seeding layer (resolveInitSeed) is covered * by tests/init-seed.test.ts and tests/compliance-cli.test.ts. * * Guard: throws when dist/cli.js is absent (no silent vacuous pass) — see requireBuiltCli. */ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import { spawnSync } from 'child_process'; import { promises as fs } from 'fs'; import * as os from 'os'; import * as path from 'path'; import { requireBuiltCli } from './helpers.js'; import { ALWAYS_PRESENT_REFS, COMPLIANCE_FRAMEWORKS } from '../src/core/compliance.js'; import { COMPLIANCE_VARIANT_HOSTS, POSTING_OPERATIONS } from './fixtures/mds-manifest.js'; const CLI = requireBuiltCli(); /** The bound on one spawned child: a child that outlives it is killed. */ const SUBPROCESS_TIMEOUT_MS = 30_000; /** * Up to four `node dist/cli.js` spawns run in the body of one scenario (S23b), so the * 5 s and 10 s defaults are not a budget under load: a scenario gets four spawn * bounds. Its `beforeEach` runs up to three more spawns under `hookTimeout`, which * gets the same budget. */ const SPAWNS_PER_SCENARIO = 4; const CLI_SCENARIO_TIMEOUT_MS = SPAWNS_PER_SCENARIO * SUBPROCESS_TIMEOUT_MS; vi.setConfig({ testTimeout: CLI_SCENARIO_TIMEOUT_MS, hookTimeout: CLI_SCENARIO_TIMEOUT_MS }); /** * What every install carries, whatever the selection (D-COMPLIANCE-INSTALL-ALWAYS): * SKILL.md and every reference. The machine switch owns the rule and the stamp. */ const EVERY_SKILL_FILE: readonly string[] = [ 'SKILL.md', ...ALWAYS_PRESENT_REFS.map(r => `references/${r}`), ...COMPLIANCE_FRAMEWORKS.map(fw => `references/${fw.id}.md`), ].sort(); /** The neutral stamp a compliance-off machine's SKILL.md carries. */ const NEUTRAL_STAMP = 'The machine declares no framework.'; /** The fixed local line a compliance-off prompt records once under the required evidence policy (AC-18). */ const OFF_DEGRADED_LINE = 'TRACEABILITY: DEGRADED (compliance off on this machine; the repository requires evidence)'; /** * The posting documents outside the per-operation trees that a compliance-off install * never holds (AC-41), as paths below `~/.claude/skills/`. Spelled out here so that a * name dropped from the production removal list turns this scenario red. */ const POSTING_DOCUMENTS: readonly string[] = [ 'devflow:git/references/publication-gate.md', 'devflow:git/references/github-posting.md', 'devflow:agent-references/references/commands/implement-evidence-asks.md', ]; // ── Shared helper ───────────────────────────────────────────────────────────── interface RunResult { status: number | null; stdout: string; stderr: string; } function makeRunner(tmpHome: string) { return function runCli(...args: string[]): RunResult { const result = spawnSync('node', [CLI, ...args], { encoding: 'utf-8', timeout: SUBPROCESS_TIMEOUT_MS, // A temp HOME alone does not isolate `init`: a user-scope install resolves the // project git root from its cwd, and an inherited cwd is the developer's repo, so // every run rewrote that repo's .devflow/config.json, root .gitignore and // .claudeignore. tmpHome is a fresh mkdtemp, never inside a repo. cwd: tmpHome, env: { ...process.env, HOME: tmpHome, FORCE_COLOR: '0', NO_COLOR: '1', // Suppress interactive mode in non-TTY CI: '1', }, }); return { status: result.status, stdout: result.stdout ?? '', stderr: result.stderr ?? '', }; }; } // ── Fixture: dir listing ────────────────────────────────────────────────────── /** List relative paths under a directory, recursively. Returns [] if absent. */ async function listDir(dir: string): Promise { const results: string[] = []; async function walk(current: string, rel: string) { let entries; try { entries = await fs.readdir(current, { withFileTypes: true }); } catch { return; } for (const e of entries) { const r = rel ? `${rel}/${e.name}` : e.name; if (e.isDirectory()) { await walk(path.join(current, e.name), r); } else { results.push(r); } } } await walk(dir, ''); return results.sort(); } /** Read JSON manifest from devflowDir. Throws if absent. */ async function readManifest(devflowDir: string): Promise> { const raw = await fs.readFile(path.join(devflowDir, 'manifest.json'), 'utf-8'); return JSON.parse(raw) as Record; } // ── S1 ──────────────────────────────────────────────────────────────────────── describe('S1: fresh init --recommended → disabled compliance manifest', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s1-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); // Seed .claude so init doesn't bail with "Claude Code not detected" await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S1: manifest has compliance {enabled:false, frameworks:[]}; skill neutral, no rule', async () => { const result = run('init', '--recommended'); expect(result.status, `init failed:\n${result.stderr}`).toBe(0); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: false, frameworks: [] }); // The skill and every reference are installed on a compliance-off machine too — a // repository can turn the lens on by itself — with the neutral stamp; no rule. const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); expect(await listDir(skillDir)).toEqual(EVERY_SKILL_FILE); expect(await fs.readFile(path.join(skillDir, 'SKILL.md'), 'utf-8')).toContain(NEUTRAL_STAMP); await expect(fs.access(path.join(claudeDir, 'rules', 'devflow', 'compliance.md'))).rejects.toThrow(); }); }); // ── S2 ──────────────────────────────────────────────────────────────────────── describe('S2: compliance --set gdpr,soc2 → artifacts installed', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s2-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); // Setup: init to create manifest const initResult = run('init', '--recommended'); expect(initResult.status, `init failed:\n${initResult.stderr}`).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S2: skill dir has exactly the expected files; rule is stamped with GDPR, SOC 2', async () => { const result = run('compliance', '--set', 'gdpr,soc2'); expect(result.status, `compliance --set failed:\n${result.stderr}`).toBe(0); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); const files = await listDir(skillDir); expect(files).toEqual(EVERY_SKILL_FILE); const ruleContent = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleContent).toContain('GDPR, SOC 2'); // Composed SKILL.md: no unresolved tokens; framework refs present. const skillContent = await fs.readFile( path.join(skillDir, 'SKILL.md'), 'utf-8', ); expect(skillContent).not.toContain('${DEVFLOW_COMPLIANCE_'); expect(skillContent).toContain('**Machine frameworks: GDPR, SOC 2.**'); expect(skillContent).toContain('references/gdpr.md'); expect(skillContent).toContain('references/soc2.md'); // Rule: per-framework bullets composed; no unresolved tokens. expect(ruleContent).not.toContain('${DEVFLOW_COMPLIANCE_RULE_BULLETS}'); expect(ruleContent).toContain('Apply GDPR'); expect(ruleContent).toContain('Apply SOC 2'); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: true, frameworks: ['gdpr', 'soc2'] }); }); }); // ── S3 ──────────────────────────────────────────────────────────────────────── describe('S3: from S2 state + --set hipaa → skill re-stamped, rule stamped HIPAA only', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s3-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S3: skill re-stamped HIPAA with every reference kept; rule stamped HIPAA only', async () => { const result = run('compliance', '--set', 'hipaa'); expect(result.status, `compliance --set hipaa failed:\n${result.stderr}`).toBe(0); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); const files = await listDir(skillDir); expect(files).toEqual(EVERY_SKILL_FILE); const ruleContent = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleContent).toContain('HIPAA'); expect(ruleContent).not.toContain('GDPR'); expect(ruleContent).not.toContain('SOC 2'); // Composed SKILL.md: only the hipaa reference row; no unresolved tokens. const skillContent = await fs.readFile( path.join(skillDir, 'SKILL.md'), 'utf-8', ); expect(skillContent).not.toContain('${DEVFLOW_COMPLIANCE_'); expect(skillContent).toContain('references/hipaa.md'); expect(skillContent).not.toContain('references/gdpr.md'); expect(skillContent).not.toContain('references/soc2.md'); // Rule: HIPAA bullet present; no unresolved tokens. expect(ruleContent).not.toContain('${DEVFLOW_COMPLIANCE_RULE_BULLETS}'); expect(ruleContent).toContain('Apply HIPAA'); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: true, frameworks: ['hipaa'] }); }); }); // ── S4 ──────────────────────────────────────────────────────────────────────── describe('S4: from S3 state + --disable → rule gone, skill neutral, frameworks remembered', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s4-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'hipaa').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S4: --disable removes the rule and re-stamps the skill neutral; manifest.frameworks still lists hipaa', async () => { const result = run('compliance', '--disable'); expect(result.status, `compliance --disable failed:\n${result.stderr}`).toBe(0); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); expect(await listDir(skillDir)).toEqual(EVERY_SKILL_FILE); const skill = await fs.readFile(path.join(skillDir, 'SKILL.md'), 'utf-8'); expect(skill).toContain(NEUTRAL_STAMP); expect(skill, 'the remembered selection never reaches an off machine\'s stamp').not.toContain('HIPAA.**'); await expect(fs.access(path.join(claudeDir, 'rules', 'devflow', 'compliance.md'))).rejects.toThrow(); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: false, frameworks: ['hipaa'] }); }); }); // ── S5 ──────────────────────────────────────────────────────────────────────── describe('S5: from S4 state + --enable → hipaa restored exactly', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s5-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'hipaa').status).toBe(0); expect(run('compliance', '--disable').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S5: --enable restores hipaa artifacts exactly', async () => { const result = run('compliance', '--enable'); expect(result.status, `compliance --enable failed:\n${result.stderr}`).toBe(0); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); const files = await listDir(skillDir); expect(files).toEqual(EVERY_SKILL_FILE); const ruleContent = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleContent).toContain('HIPAA'); // Composed SKILL.md: hipaa refs present; no unresolved tokens. const skillContent = await fs.readFile( path.join(skillDir, 'SKILL.md'), 'utf-8', ); expect(skillContent).not.toContain('${DEVFLOW_COMPLIANCE_'); expect(skillContent).toContain('references/hipaa.md'); // Rule: HIPAA bullet composed; no unresolved tokens. expect(ruleContent).not.toContain('${DEVFLOW_COMPLIANCE_RULE_BULLETS}'); expect(ruleContent).toContain('Apply HIPAA'); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: true, frameworks: ['hipaa'] }); }); }); // ── S6 ──────────────────────────────────────────────────────────────────────── describe('S6: from S2 state + rules --disable → skill present, rule absent', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s6-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S6: rules --disable removes rules dir; skill dir still present', async () => { const result = run('rules', '--disable'); expect(result.status, `rules --disable failed:\n${result.stderr}`).toBe(0); // Skill must still be present const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); await expect( fs.access(path.join(claudeDir, 'skills', COMPLIANCE_SKILL)), 'compliance skill must survive rules --disable', ).resolves.not.toThrow(); // Rule must be gone (rules dir removed) await expect( fs.access(path.join(claudeDir, 'rules', 'devflow', 'compliance.md')), 'compliance rule must be gone after rules --disable', ).rejects.toThrow(); // Status output should mention rule withheld const statusResult = run('compliance', '--status'); expect(statusResult.status).toBe(0); expect(statusResult.stdout + statusResult.stderr).toMatch(/withheld|rules disabled/i); }); }); // ── S7 ──────────────────────────────────────────────────────────────────────── describe('S7: from S6 state + rules --enable → compliance rule restored with GDPR, SOC 2', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s7-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); expect(run('rules', '--disable').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S7: rules --enable restores compliance rule stamped GDPR, SOC 2', async () => { const result = run('rules', '--enable'); expect(result.status, `rules --enable failed:\n${result.stderr}`).toBe(0); const ruleContent = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleContent).toContain('GDPR, SOC 2'); // Per-framework bullets composed by composeComplianceRule (not just stampComplianceRule). expect(ruleContent).not.toContain('${DEVFLOW_COMPLIANCE_RULE_BULLETS}'); expect(ruleContent).toContain('Apply GDPR'); expect(ruleContent).toContain('Apply SOC 2'); }); }); // ── S8 ──────────────────────────────────────────────────────────────────────── describe('S8: rules off + compliance --set pci-dss → skill yes, rule no', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s8-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('rules', '--disable').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S8: compliance --set pci-dss installs skill but no rule (rules disabled)', async () => { const result = run('compliance', '--set', 'pci-dss'); expect(result.status, `compliance --set pci-dss failed:\n${result.stderr}`).toBe(0); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); await expect( fs.access(path.join(claudeDir, 'skills', COMPLIANCE_SKILL)), 'compliance skill must be installed', ).resolves.not.toThrow(); await expect( fs.access(path.join(claudeDir, 'rules', 'devflow', 'compliance.md')), 'compliance rule must NOT be installed (rules disabled)', ).rejects.toThrow(); }); }); // ── S9 ──────────────────────────────────────────────────────────────────────── describe('S9: from S2 state + full init → artifacts survive sweep+converge', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s9-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S9: full init after enable leaves compliance artifacts intact', async () => { const result = run('init', '--recommended'); expect(result.status, `second init failed:\n${result.stderr}`).toBe(0); // End-state must match S2: skill installed with gdpr+soc2 refs const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); const files = await listDir(skillDir); expect(files).toEqual(EVERY_SKILL_FILE); const ruleContent = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleContent).toContain('GDPR, SOC 2'); }); }); // ── S10 ─────────────────────────────────────────────────────────────────────── describe('S10: from S2 state + init --plugin=devflow-code-review → compliance preserved', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s10-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S10: partial init --plugin=devflow-code-review preserves compliance artifacts', async () => { const result = run('init', '--plugin=devflow-code-review'); expect(result.status, `partial init failed:\n${result.stderr}`).toBe(0); // compliance artifacts must be present (convergeComplianceArtifacts re-materializes) const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); const files = await listDir(skillDir); expect(files).toEqual(EVERY_SKILL_FILE); }); }); // ── S11 ─────────────────────────────────────────────────────────────────────── describe('S11: legacy manifest with devflow-compliance → pruned on init', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s11-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); await fs.mkdir(devflowDir, { recursive: true }); run = makeRunner(tmpHome); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S11-notice: full init with legacy devflow-compliance manifest emits migration notice', async () => { // Craft a legacy manifest that includes devflow-compliance as a plugin. const legacyManifest = { version: '2.0.0', scope: 'user', installedAt: new Date().toISOString(), updatedAt: new Date().toISOString(), plugins: ['devflow-core-skills', 'devflow-implement', 'devflow-compliance'], features: { ambient: false, memory: false, learning: false, knowledge: false, hud: false, rules: false, proxy: false, compliance: { enabled: false, frameworks: [] }, }, }; await fs.writeFile( path.join(devflowDir, 'manifest.json'), JSON.stringify(legacyManifest, null, 2), 'utf-8', ); // Run a FULL init (no --plugin flag) — this triggers the legacy plugin detection notice. const result = run('init', '--recommended'); expect(result.status, `init failed:\n${result.stderr}`).toBe(0); // The output must contain the migration notice explaining that compliance moved from // a plugin to a built-in feature (printed only when existingManifest.plugins includes // 'devflow-compliance'). Combine stdout+stderr — clack directs log messages to stdout // but non-TTY CI environments may buffer differently. expect( result.stdout + result.stderr, 'output must contain the legacy plugin migration notice', ).toContain('Compliance has moved from a plugin to a built-in feature'); }); it('S11: devflow-compliance in manifest.plugins is pruned by DELETED_PLUGIN_NAMES on init', async () => { // Craft a legacy manifest that includes devflow-compliance as a plugin. // Must include `version` — readManifest returns null without it, // which collapses seed.features.compliance to FEATURE_DEFAULTS (disabled). const legacyManifest = { version: '2.0.0', scope: 'user', installedAt: new Date().toISOString(), updatedAt: new Date().toISOString(), plugins: ['devflow-core-skills', 'devflow-implement', 'devflow-compliance'], features: { ambient: true, memory: true, learning: true, knowledge: true, hud: true, rules: true, proxy: false, compliance: { enabled: true, frameworks: ['gdpr'] }, }, }; await fs.writeFile( path.join(devflowDir, 'manifest.json'), JSON.stringify(legacyManifest, null, 2), 'utf-8', ); // Run init (partial reinstall of devflow-implement to trigger resolvePluginList) const result = run('init', '--plugin=devflow-implement'); expect(result.status, `init failed:\n${result.stderr}`).toBe(0); // devflow-compliance must be pruned from manifest.plugins (DELETED_PLUGIN_NAMES filter) const manifest = await readManifest(devflowDir); const plugins = (manifest as Record).plugins as string[]; expect(plugins).not.toContain('devflow-compliance'); // Compliance artifacts converged per feature state (enabled:true, frameworks:[gdpr]) const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); await expect( fs.access(path.join(claudeDir, 'skills', COMPLIANCE_SKILL)), 'compliance skill must be installed (feature.compliance.enabled=true)', ).resolves.not.toThrow(); }); }); // ── S12 ─────────────────────────────────────────────────────────────────────── describe('S12: from S2 state + init --reset → compliance off, rule gone, skill neutral', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s12-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S12: init --reset resets compliance to disabled, removes the rule and re-stamps the skill neutral', async () => { const result = run('init', '--reset'); expect(result.status, `init --reset failed:\n${result.stderr}`).toBe(0); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: false, frameworks: [] }); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); expect(await listDir(skillDir)).toEqual(EVERY_SKILL_FILE); expect(await fs.readFile(path.join(skillDir, 'SKILL.md'), 'utf-8')).toContain(NEUTRAL_STAMP); await expect(fs.access(path.join(claudeDir, 'rules', 'devflow', 'compliance.md'))).rejects.toThrow(); }); }); // ── S13: Non-TTY guard + CLI-flag promptless contracts ──────────────────────── // S13a: --advanced requires a TTY — exits 1 in non-TTY environments. // S13b: --recommended re-init preserves prior compliance state (no wizard prompt). // S13c: --recommended --compliance hipaa applies framework without any wizard prompt. describe('S13a: --advanced in non-TTY exits 1', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s13a-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); // Establish a fresh install so seedManifest is non-null (re-init path) expect(run('init', '--recommended').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S13a: --advanced in a non-TTY env → exit 1 with clear error message', () => { // makeRunner uses spawnSync (no TTY) with CI=1 → process.stdin.isTTY = false. // The guard at init.ts rejects --advanced and directs the user to --recommended. const result = run('init', '--advanced'); expect(result.status, `Expected exit 1 but got ${result.status}:\n${result.stderr}`).toBe(1); expect(result.stderr + result.stdout).toContain('interactive terminal'); }); }); describe('S13b: --recommended re-init preserves prior compliance state (promptless)', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s13b-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); // Install, then enable compliance with two frameworks expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,sox').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S13b: second --recommended does not reset compliance — state preserved from manifest seed', async () => { // shouldRunComplianceStep returns false (--recommended flag → modePromptShown=false) // so the wizard step is skipped. The manifest seed carries the prior enabled/frameworks. const result = run('init', '--recommended'); expect(result.status, `re-init failed:\n${result.stderr}`).toBe(0); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: true, frameworks: ['gdpr', 'sox'] }); }); }); describe('S13c: --recommended --compliance hipaa → framework applied without prompts', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s13c-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S13c: --compliance hipaa applies on first install without a wizard prompt', async () => { // cliComplianceOverride is set → shouldRunComplianceStep returns false (hasCliOverride=true) // → the wizard is bypassed entirely; the CLI flag alone configures the feature. const result = run('init', '--recommended', '--compliance', 'hipaa'); expect(result.status, `init failed:\n${result.stderr}`).toBe(0); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: true, frameworks: ['hipaa'] }); // Compliance skill should be installed const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); await expect( fs.access(path.join(claudeDir, 'skills', COMPLIANCE_SKILL)), 'compliance skill must be installed when --compliance is passed', ).resolves.not.toThrow(); }); it('S13c: --no-compliance disables from an already-enabled manifest (promptless)', async () => { // First install with compliance enabled expect(run('init', '--recommended', '--compliance', 'hipaa').status).toBe(0); // Re-init with --no-compliance: hasCliOverride=true → wizard skipped, compliance disabled const result = run('init', '--recommended', '--no-compliance'); expect(result.status, `re-init failed:\n${result.stderr}`).toBe(0); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect((features.compliance as Record).enabled).toBe(false); }); }); // ── S14 ─────────────────────────────────────────────────────────────────────── describe('S14: from S2 state + uninstall --plugin=devflow-plan → compliance retained', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s14-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S14: uninstalling devflow-plan leaves compliance skill intact', async () => { const result = run('uninstall', '--plugin=devflow-plan'); expect(result.status, `uninstall failed:\n${result.stderr}`).toBe(0); // compliance skill must be intact (sweepDevflowNamespaces unions FEATURE_OWNED_SKILLS) const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); await expect( fs.access(path.join(claudeDir, 'skills', COMPLIANCE_SKILL)), 'compliance skill must survive selective uninstall of another plugin', ).resolves.not.toThrow(); }); }); // ── S15 ─────────────────────────────────────────────────────────────────────── describe('S15: from S2 state + bare compliance decoy + full uninstall', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s15-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr,soc2').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S15: full uninstall removes prefixed compliance skill but spares bare decoy', async () => { // Plant a bare 'compliance' dir (simulates a foreign skill from another tool) const bareDecoy = path.join(claudeDir, 'skills', 'compliance'); await fs.mkdir(bareDecoy, { recursive: true }); const sentinel = 'sentinel-compliance-bare-decoy'; await fs.writeFile(path.join(bareDecoy, 'SKILL.md'), sentinel, 'utf-8'); // Run full uninstall (non-TTY in CI mode; scope: user) const uninstallResult = run('uninstall', '--scope=user'); // Accept 0 or 1 (uninstall may warn about missing dirs); reject crashes (unhandled, ERR_, stack). expect([0, 1], `uninstall exited unexpectedly (${uninstallResult.status}):\n${uninstallResult.stderr}`).toContain(uninstallResult.status); expect(uninstallResult.stderr, 'uninstall must not crash').not.toMatch(/unhandled|ERR_|stack/i); // Prefixed devflow:compliance must be removed const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); await expect( fs.access(path.join(claudeDir, 'skills', COMPLIANCE_SKILL)), 'prefixed devflow:compliance must be removed by full uninstall', ).rejects.toThrow(); // Bare compliance/ decoy must survive (foreign dir — not in LEGACY_SKILL_NAMES) const survived = await fs.readFile(path.join(bareDecoy, 'SKILL.md'), 'utf-8'); expect( survived, 'bare compliance/ decoy (foreign dir) must not be deleted by full uninstall', ).toBe(sentinel); }); }); // ── S16 ─────────────────────────────────────────────────────────────────────── describe('S16: shadowed skill + rule shadow + --set gdpr → shadow SKILL.md verbatim', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s16-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S16: compliance --set uses shadow SKILL.md verbatim; rule from shadow (no placeholder)', async () => { // Create skill shadow (no devflow: prefix in shadow dir, per shadow convention) const shadowSkillDir = path.join(devflowDir, 'skills', 'compliance'); await fs.mkdir(shadowSkillDir, { recursive: true }); const customSkillContent = '# Custom Compliance Skill — shadowed'; await fs.writeFile(path.join(shadowSkillDir, 'SKILL.md'), customSkillContent, 'utf-8'); // Create rule shadow without placeholder (static content) const shadowRuleDir = path.join(devflowDir, 'rules'); await fs.mkdir(shadowRuleDir, { recursive: true }); const customRuleContent = '# Custom Compliance Rule — no placeholder'; await fs.writeFile(path.join(shadowRuleDir, 'compliance.md'), customRuleContent, 'utf-8'); const result = run('compliance', '--set', 'gdpr'); expect(result.status, `compliance --set failed:\n${result.stderr}`).toBe(0); // SKILL.md must be the shadow version verbatim const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const installedSkillMd = await fs.readFile( path.join(claudeDir, 'skills', COMPLIANCE_SKILL, 'SKILL.md'), 'utf-8', ); expect(installedSkillMd).toBe(customSkillContent); // Rule must be the shadow version (no placeholder stamping since no placeholder) const installedRule = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(installedRule).toBe(customRuleContent); }); }); // ── S16b ────────────────────────────────────────────────────────────────────── describe('S16b: rule shadow WITH placeholder → shadow stamped on --set and rules --enable', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s16b-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S16b: shadow rule with placeholder is stamped on --set gdpr AND on rules --enable', async () => { const shadowRuleDir = path.join(devflowDir, 'rules'); await fs.mkdir(shadowRuleDir, { recursive: true }); // Shadow uses the CURRENT template form: just the bare placeholder with no surrounding // clause. stampComplianceRule replaces only the placeholder; any prose around it is // template/shadow-owned. The old form ("...${PLACEHOLDER} — controls binding.") would // double the trailing clause once stamped. const shadowRuleWithPlaceholder = '# Custom rule\n- ${DEVFLOW_COMPLIANCE_FRAMEWORKS}'; await fs.writeFile(path.join(shadowRuleDir, 'compliance.md'), shadowRuleWithPlaceholder, 'utf-8'); // --set gdpr: should stamp the shadow content with the full GDPR sentence const result = run('compliance', '--set', 'gdpr'); expect(result.status, `compliance --set failed:\n${result.stderr}`).toBe(0); const ruleAfterSet = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleAfterSet).toContain('Active frameworks: GDPR — their controls are binding.'); expect(ruleAfterSet).not.toContain('${DEVFLOW_COMPLIANCE_FRAMEWORKS}'); // rules --enable should also re-stamp (runRulesEnable converges compliance) expect(run('rules', '--disable').status).toBe(0); const result2 = run('rules', '--enable'); expect(result2.status, `rules --enable failed:\n${result2.stderr}`).toBe(0); const ruleAfterEnable = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleAfterEnable).toContain('Active frameworks: GDPR — their controls are binding.'); expect(ruleAfterEnable).not.toContain('${DEVFLOW_COMPLIANCE_FRAMEWORKS}'); }); }); // ── S17 ─────────────────────────────────────────────────────────────────────── describe('S17: invalid framework IDs → non-zero exit, disk unchanged', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s17-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S17: --set gdrp,hippa exits non-zero and leaves the disk unchanged', async () => { const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillMd = path.join(claudeDir, 'skills', COMPLIANCE_SKILL, 'SKILL.md'); const skillBefore = await fs.readFile(skillMd, 'utf-8'); const result = run('compliance', '--set', 'gdrp,hippa'); expect(result.status, 'invalid IDs must produce non-zero exit').not.toBe(0); // Error output must mention valid IDs const output = result.stdout + result.stderr; expect(output).toMatch(/gdpr|hipaa/i); // Disk unchanged (command must fail before writing any files): the neutral skill // the first init installed is byte-identical, and no rule appeared. expect(await fs.readFile(skillMd, 'utf-8')).toBe(skillBefore); await expect(fs.access(path.join(claudeDir, 'rules', 'devflow', 'compliance.md'))).rejects.toThrow(); // Manifest unchanged (enabled:false, frameworks:[]) const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: false, frameworks: [] }); }); }); // ── S18 ─────────────────────────────────────────────────────────────────────── describe('S18: fresh non-TTY --enable with no prior frameworks → generic-only', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s18-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); // Do NOT set any frameworks — fresh state with frameworks:[] }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S18: non-TTY --enable with no frameworks → generic-only rule', async () => { // spawnSync is non-TTY by definition, so --enable skips the multiselect const result = run('compliance', '--enable'); expect(result.status, `compliance --enable failed:\n${result.stderr}`).toBe(0); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); await expect( fs.access(path.join(claudeDir, 'skills', COMPLIANCE_SKILL)), 'compliance skill must be installed', ).resolves.not.toThrow(); const ruleContent = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleContent).toContain('none declared'); // Composed SKILL.md: zero-framework case — no tokens, no framework refs. const skillContent = await fs.readFile( path.join(claudeDir, 'skills', COMPLIANCE_SKILL, 'SKILL.md'), 'utf-8', ); expect(skillContent).not.toContain('${DEVFLOW_COMPLIANCE_'); // No per-framework reference rows (zero frameworks selected) for (const id of ['gdpr', 'hipaa', 'pci-dss', 'soc2', 'iso-27001', 'sox']) { expect(skillContent, `references/${id}.md must not appear in zero-framework SKILL.md`).not.toContain(`references/${id}.md`); } // Rule: no per-framework bullets (empty), no unresolved tokens. expect(ruleContent).not.toContain('${DEVFLOW_COMPLIANCE_RULE_BULLETS}'); // Zero frameworks → no "Apply ..." bullets at all const bulletLines = ruleContent.split('\n').filter(l => l.startsWith('- Apply ')); expect(bulletLines, 'zero-framework rule must have no per-framework "Apply ..." bullets').toHaveLength(0); const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; expect(features.compliance).toEqual({ enabled: true, frameworks: [] }); }); }); // ── S19 ─────────────────────────────────────────────────────────────────────── describe('S19: manifest writeback deduplicates frameworks', () => { // normalizeFrameworks is applied at manifest writeback time so that a hand-edited // or migrated manifest with duplicate framework IDs is cleaned up on the next init. let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s19-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); await fs.mkdir(devflowDir, { recursive: true }); run = makeRunner(tmpHome); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S19: init with duplicate frameworks in seed manifest writes deduplicated manifest', async () => { // Write a manifest with duplicate framework IDs — simulates a hand-edited manifest // or migration artifact that normalizeFrameworks.dedup must clean up. const legacyManifest = { version: '2.0.0', scope: 'user', installedAt: new Date().toISOString(), updatedAt: new Date().toISOString(), plugins: ['devflow-core-skills', 'devflow-implement'], features: { ambient: false, memory: false, learning: false, knowledge: false, hud: false, rules: false, proxy: false, compliance: { enabled: true, frameworks: ['gdpr', 'soc2', 'gdpr', 'gdpr'] }, }, }; await fs.writeFile( path.join(devflowDir, 'manifest.json'), JSON.stringify(legacyManifest, null, 2), 'utf-8', ); // Run full init — manifest writeback applies normalizeFrameworks const result = run('init', '--recommended'); expect(result.status, `init failed:\n${result.stderr}`).toBe(0); // The written manifest.features.compliance.frameworks must have no duplicates const manifest = await readManifest(devflowDir); const features = (manifest as Record).features as Record; const compliance = features.compliance as { enabled: boolean; frameworks: string[] }; expect(compliance.enabled).toBe(true); // After dedup: ['gdpr', 'soc2'] — each appears exactly once, insertion order preserved expect(compliance.frameworks).toEqual(['gdpr', 'soc2']); }); }); // ── S21 ─────────────────────────────────────────────────────────────────────── describe('S21: all-six frameworks → SKILL.md fully composed; rule bullets within budget', () => { let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s21-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S21: --set all-six → SKILL.md tokens resolved; rule has 6 bullets each ≤200 chars', async () => { const result = run('compliance', '--set', 'gdpr,hipaa,pci-dss,soc2,iso-27001,sox'); expect(result.status, `compliance --set failed:\n${result.stderr}`).toBe(0); const COMPLIANCE_SKILL = ['devflow', 'compliance'].join(':'); const skillDir = path.join(claudeDir, 'skills', COMPLIANCE_SKILL); // Skill: no unresolved tokens; all 6 framework refs present. const skillContent = await fs.readFile(path.join(skillDir, 'SKILL.md'), 'utf-8'); expect(skillContent).not.toContain('${DEVFLOW_COMPLIANCE_'); for (const fw of ['gdpr', 'hipaa', 'pci-dss', 'soc2', 'iso-27001', 'sox']) { expect(skillContent, `missing references/${fw}.md in composed SKILL.md`).toContain(`references/${fw}.md`); } // Rule: no unresolved tokens; exactly 6 "Apply ..." bullets, each ≤200 chars. const ruleContent = await fs.readFile( path.join(claudeDir, 'rules', 'devflow', 'compliance.md'), 'utf-8', ); expect(ruleContent).not.toContain('${DEVFLOW_COMPLIANCE_RULE_BULLETS}'); const bulletLines = ruleContent.split('\n').filter(l => l.startsWith('- Apply ')); expect(bulletLines, 'rule must have exactly 6 per-framework "Apply ..." bullets').toHaveLength(6); for (const bullet of bulletLines) { expect( bullet.length, `Rule bullet exceeds 200-char budget: "${bullet}"`, ).toBeLessThanOrEqual(200); } }); }); // ── S22 ─────────────────────────────────────────────────────────────────────── describe('S22: --status flags composition-skipped skill shadow', () => { // A skill shadow whose SKILL.md has NO ${DEVFLOW_COMPLIANCE_...} tokens passes through // byte-identical (C1). The --status output must warn the user that per-framework sections // are absent from the installed skill, so they know why framework-specific guidance is missing. let tmpHome: string; let devflowDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s22-')); devflowDir = path.join(tmpHome, '.devflow'); const claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S22a: skill shadow with tokens → --status shows [shadowed] (composition runs)', async () => { // Shadow contains a token → composition runs normally → "shadowed" label only. const shadowSkillDir = path.join(devflowDir, 'skills', 'compliance'); await fs.mkdir(shadowSkillDir, { recursive: true }); await fs.writeFile( path.join(shadowSkillDir, 'SKILL.md'), '# Shadow compliance\n${DEVFLOW_COMPLIANCE_SCOPE}\n', 'utf-8', ); const result = run('compliance', '--status'); expect(result.status, `compliance --status failed:\n${result.stderr}`).toBe(0); const out = result.stdout + result.stderr; expect(out).toMatch(/shadowed/i); expect(out).not.toMatch(/composition skipped/i); }); it('S22b: token-free skill shadow → --status warns "composition skipped"', async () => { // Shadow has NO tokens → C1 passthrough → per-framework sections absent. const shadowSkillDir = path.join(devflowDir, 'skills', 'compliance'); await fs.mkdir(shadowSkillDir, { recursive: true }); await fs.writeFile( path.join(shadowSkillDir, 'SKILL.md'), '# Custom static compliance skill — no composition tokens', 'utf-8', ); const result = run('compliance', '--status'); expect(result.status, `compliance --status failed:\n${result.stderr}`).toBe(0); const out = result.stdout + result.stderr; expect(out).toMatch(/composition skipped/i); }); }); // ── S20 ─────────────────────────────────────────────────────────────────────── describe('S20: compliance skill lifecycle is managed by converge, not the orphan sweep', () => { // After I09: the installer's knownNames unions FEATURE_OWNED_SKILLS, so devflow:compliance // is never swept as an orphan. Its lifecycle is owned exclusively by convergeComplianceArtifacts: // converge installs it in both states (D-COMPLIANCE-INSTALL-ALWAYS) and removes only the rule // when disabled. The sweep report must never mention compliance in either case. let tmpHome: string; let devflowDir: string; let claudeDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s20-')); devflowDir = path.join(tmpHome, '.devflow'); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); // Base state: init with compliance enabled (gdpr) expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr').status).toBe(0); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('S20a: re-init with compliance still enabled does NOT surface compliance in sweep report', async () => { // After I09: compliance skill is protected by FEATURE_OWNED_SKILLS in knownNames — it is // never swept. Converge re-installs it when enabled. The sweep report must never mention it. const result = run('init', '--recommended'); expect(result.status, `second init failed:\n${result.stderr}`).toBe(0); const combined = result.stdout + result.stderr; // The sweep report must not mention compliance — it is no longer a sweep target (I09). expect(combined).not.toMatch(/skill compliance/); // Compliance skill must still be present (converge re-materialized it). await expect( fs.access(path.join(claudeDir, 'skills', 'devflow:compliance')), 'compliance skill must survive re-init with compliance enabled', ).resolves.not.toThrow(); }); it('S20b: re-init with --no-compliance keeps the skill neutral and removes the rule (via converge, not sweep)', async () => { // After I09: compliance skill is NOT swept by the orphan sweep (FEATURE_OWNED_SKILLS guards it). // The disable path is converge's. The sweep report must NOT mention compliance. const result = run('init', '--no-compliance'); expect(result.status, `init --no-compliance failed:\n${result.stderr}`).toBe(0); const combined = result.stdout + result.stderr; // Sweep report must not surface compliance — it is no longer a sweep target (I09). expect(combined).not.toMatch(/no longer in the registry:[^\n]*skill compliance/); // The skill stays, re-stamped neutral; the rule is gone (converge disable path, not sweep). const skillMd = await fs.readFile(path.join(claudeDir, 'skills', 'devflow:compliance', 'SKILL.md'), 'utf-8'); expect(skillMd).toContain(NEUTRAL_STAMP); await expect(fs.access(path.join(claudeDir, 'rules', 'devflow', 'compliance.md'))).rejects.toThrow(); }); }); // ── S23 (TP-43, AC-37) ───────────────────────────────────────────────────────── // // A repository declares hipaa on a machine whose own compliance is off. The lens // comes from the settings line (COMPLIANCE=hipaa), the installed skill carries // references/hipaa.md for the reviewer to load, and the MACHINE rule — the one // artifact Claude Code loads into every prompt — is untouched: absent on an off // machine, byte-identical on an on machine, however often init runs from the repo. // On the off machine the lens never brings a posting reference back, and the installed // compliance-off prompts carry the fixed local DEGRADED line (AC-46). describe('S23 (TP-43, AC-37): a hipaa repository never changes the machine compliance rule', () => { let tmpHome: string; let claudeDir: string; let repo: string; let run: ReturnType; const RULE = () => path.join(claudeDir, 'rules', 'devflow', 'compliance.md'); /** `init` run from inside the repository — the strongest place for a repo layer to leak. */ function initFromRepo(...args: string[]): RunResult { const result = spawnSync('node', [CLI, 'init', ...args], { encoding: 'utf-8', timeout: SUBPROCESS_TIMEOUT_MS, cwd: repo, env: { ...process.env, HOME: tmpHome, FORCE_COLOR: '0', NO_COLOR: '1', CI: '1' }, }); return { status: result.status, stdout: result.stdout ?? '', stderr: result.stderr ?? '' }; } /** The installed settings resolver, run as a prompt runs it. */ function settingsLine(): string { const result = spawnSync('node', [path.join(tmpHome, '.devflow', 'scripts', 'resolve-settings.cjs'), repo], { encoding: 'utf-8', timeout: SUBPROCESS_TIMEOUT_MS, cwd: repo, env: { ...process.env, HOME: tmpHome }, }); expect(result.status, `resolve-settings failed:\n${result.stderr}`).toBe(0); return result.stdout.trim(); } beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-s23-')); claudeDir = path.join(tmpHome, '.claude'); await fs.mkdir(claudeDir, { recursive: true }); run = makeRunner(tmpHome); repo = path.join(tmpHome, 'repo'); await fs.mkdir(path.join(repo, '.devflow'), { recursive: true }); expect(spawnSync('git', ['init', '-q'], { cwd: repo }).status).toBe(0); await fs.writeFile( path.join(repo, '.devflow', 'project.json'), JSON.stringify({ version: 1, compliance: ['hipaa'] }), 'utf-8', ); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); /** Every skill file below `~/.claude/skills/` that is a posting reference, or an empty list when none is installed (AC-41, AC-46). */ async function installedPostingReferences(): Promise { const skills = path.join(claudeDir, 'skills'); const gitRefs = await listDir(path.join(skills, 'devflow:git', 'references')); expect(gitRefs, 'the kept git references install, or the absence check proves nothing').toContain('pr/check-merge-readiness.md'); const found = gitRefs .filter(rel => POSTING_OPERATIONS.includes(path.basename(rel, '.md'))) .map(rel => `devflow:git/references/${rel}`); for (const rel of POSTING_DOCUMENTS) { const exists = await fs.lstat(path.join(skills, ...rel.split('/'))).then(() => true, () => false); if (exists) found.push(rel); } return found; } /** * The compliance-off command prompts that the machine installs: every compliance-armed command * host whose plugin the recommended install selects. */ async function installedOffCommandNames(): Promise { const installed = await listDir(path.join(claudeDir, 'commands', 'devflow')); const names = COMPLIANCE_VARIANT_HOSTS .filter(host => host.startsWith('commands/')) .map(host => host.slice('commands/'.length)) .filter(name => installed.includes(`${name}.md`)); expect(names, 'the compliance-armed commands of the core plugins install').toEqual(expect.arrayContaining(['implement', 'resolve', 'code-review'])); return names; } it('S23a: compliance-off machine — lens is hipaa, hipaa.md is installed, no rule and no posting reference ever appear', async () => { expect(run('init', '--recommended').status).toBe(0); await expect(fs.access(RULE())).rejects.toThrow(); const line = settingsLine(); expect(line).toMatch(/ COMPLIANCE=hipaa /); const skillDir = path.join(claudeDir, 'skills', 'devflow:compliance'); expect(await listDir(skillDir)).toContain('references/hipaa.md'); const skill = await fs.readFile(path.join(skillDir, 'SKILL.md'), 'utf-8'); expect(skill).toContain(NEUTRAL_STAMP); expect(skill).toContain('Load `references/{id}.md` for each given id and no other'); expect(await installedPostingReferences(), 'the hipaa lens must not bring a posting reference back').toEqual([]); for (const name of await installedOffCommandNames()) { const prompt = await fs.readFile(path.join(claudeDir, 'commands', 'devflow', `${name}.md`), 'utf-8'); expect(prompt.split(OFF_DEGRADED_LINE).length - 1, `${name}: the fixed local line appears once`).toBe(1); } const reinit = initFromRepo('--recommended'); expect(reinit.status, `init from the repository failed:\n${reinit.stderr}`).toBe(0); await expect(fs.access(RULE()), 'the repository must never install the machine rule').rejects.toThrow(); expect(await installedPostingReferences(), 'init from the repository must not bring a posting reference back').toEqual([]); }); it('S23b: compliance-on machine (gdpr) — the lens folds hipaa in, and the rule bytes are unchanged', async () => { expect(run('init', '--recommended').status).toBe(0); expect(run('compliance', '--set', 'gdpr').status).toBe(0); const before = await fs.readFile(RULE()); expect(settingsLine()).toMatch(/ COMPLIANCE=gdpr,hipaa /); expect(await installedPostingReferences(), 'the compliance-on machine holds the posting documents, so the scan in S23a can find one').toEqual( expect.arrayContaining([...POSTING_DOCUMENTS]), ); const reinit = initFromRepo('--recommended'); expect(reinit.status, `init from the repository failed:\n${reinit.stderr}`).toBe(0); const after = await fs.readFile(RULE()); expect(after.equals(before), 'the machine rule must stay byte-identical').toBe(true); expect(after.toString('utf-8')).not.toContain('HIPAA'); }); }); // ── T1 ──────────────────────────────────────────────────────────────────────── // // The tracker selection lifecycle, driven through the real entry point. // // A convergence test that reconstructs init's sequence certifies // the author's model of the ordering rather than the shipped ordering, so these // arms run `devflow init` and read the directory it left behind. describe('T1: init --reset collapses the provider and converges every tracker artifact', () => { let tmpHome: string; let devflowDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-t1-')); devflowDir = path.join(tmpHome, '.devflow'); // Seed .claude so init doesn't bail with "Claude Code not detected" await fs.mkdir(path.join(tmpHome, '.claude'), { recursive: true }); run = makeRunner(tmpHome); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('T1: a jira install + --reset → sentinel gone, manifest github, jira conventions kept', async () => { // Seeded BEFORE the first init: an earlier release's single conventions file, // which that init's migration moves to jira's own file (TP-39, end to end). await fs.mkdir(devflowDir, { recursive: true }); const legacy = path.join(devflowDir, 'tracker.md'); const conventions = path.join(devflowDir, 'tracker', 'jira.md'); const seededConventions = '---\nprovider: jira\ninferred-from: seed\n---\n\n## Project\nsite: example\n'; await fs.writeFile(legacy, seededConventions, 'utf-8'); // Base state: a real jira install, not a hand-written manifest. expect(run('init', '--recommended', '--tracker', 'jira').status).toBe(0); const sentinel = path.join(devflowDir, '.tracker.enabled'); // The pre-state is asserted, or the post-state below is the state // the temp dir started in and the run proved nothing. expect( ((await readManifest(devflowDir)).features as Record).tracker, ).toEqual({ provider: 'jira' }); await expect(fs.readFile(sentinel, 'utf-8')).resolves.toBe('jira\n'); await expect(fs.readFile(conventions, 'utf-8'), 'the migration moved the legacy file') .resolves.toBe(seededConventions); await expect(fs.access(legacy)).rejects.toThrow(); const result = run('init', '--reset'); expect(result.status, `init --reset failed:\n${result.stderr}`).toBe(0); // The provider collapses to the off position, and the sentinel converges on it. expect( ((await readManifest(devflowDir)).features as Record).tracker, ).toEqual({ provider: 'github' }); await expect(fs.access(sentinel)).rejects.toThrow(); // D-TRACKER-PER-PROVIDER-CONVENTIONS: nothing is moved aside. jira's // conventions are jira's, still correct for every repository that uses jira. await expect(fs.readFile(conventions, 'utf-8')).resolves.toBe(seededConventions); await expect(fs.access(path.join(devflowDir, 'tracker.md.jira.bak'))).rejects.toThrow(); // D-INSTALL-ALL-PROVIDERS: the agent stays — a repository can still select jira. await expect(fs.access(path.join(tmpHome, '.claude', 'agents', 'devflow', 'tracker.md'))).resolves.toBeUndefined(); }); }); // ── T2 ──────────────────────────────────────────────────────────────────────── describe('T2: a failed manifest write converges no tracker artifact', () => { let tmpHome: string; let devflowDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-t2-')); devflowDir = path.join(tmpHome, '.devflow'); await fs.mkdir(path.join(tmpHome, '.claude'), { recursive: true }); run = makeRunner(tmpHome); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('T2: manifest path is a directory → warned, and .tracker.enabled is never written', async () => { // A directory at the manifest path makes the atomic write's final rename // fail — a real I/O failure at the one step the three owners are gated on, // rather than a stub standing in for one. const manifestPath = path.join(devflowDir, 'manifest.json'); await fs.mkdir(manifestPath, { recursive: true }); const result = run('init', '--recommended', '--tracker', 'jira'); // A feature-state failure must never fail the install itself. expect(result.status, `init exited non-zero:\n${result.stderr}`).toBe(0); const output = result.stdout + result.stderr; expect(output).toContain('Failed to write installation manifest'); expect(output).toContain('was not persisted'); // The gate: an unpersisted selection converges nothing, so the // on-disk state stays internally consistent and the next init retries the // whole transition from an unchanged starting point. A sentinel written for // a provider the manifest never recorded is a per-session fork cost forever. await expect(fs.access(path.join(devflowDir, '.tracker.enabled'))).rejects.toThrow(); await expect(fs.access(path.join(devflowDir, '.tracker.attempts'))).rejects.toThrow(); // Still a directory: nothing smuggled a selection past the failed write. await expect(fs.stat(manifestPath)).resolves.toMatchObject({}); expect((await fs.stat(manifestPath)).isDirectory()).toBe(true); }); }); // ── T3 ──────────────────────────────────────────────────────────────────────── describe('T3: --hud-only preserves the tracker selection it did not ask about', () => { let tmpHome: string; let devflowDir: string; let run: ReturnType; beforeEach(async () => { tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), 'df-e2e-t3-')); devflowDir = path.join(tmpHome, '.devflow'); await fs.mkdir(path.join(tmpHome, '.claude'), { recursive: true }); run = makeRunner(tmpHome); }); afterEach(async () => { await fs.rm(tmpHome, { recursive: true, force: true }); }); it('T3: a prior linear selection survives a hud-only install', async () => { // --no-hud so the hud-only run has something observable to change below. expect(run('init', '--recommended', '--tracker', 'linear', '--no-hud').status).toBe(0); const prior = await readManifest(devflowDir); expect( (prior.features as Record).tracker, 'the pre-state must be the non-default provider, or the assertion below is satisfied by the default', ).toEqual({ provider: 'linear' }); const result = run('init', '--hud-only'); expect(result.status, `init --hud-only failed:\n${result.stderr}`).toBe(0); const features = (await readManifest(devflowDir)).features as Record; // Dropping the carry-over resets every Jira/Linear user to github with // nothing on screen. expect(features.tracker).toEqual({ provider: 'linear' }); // Non-vacuity: this really was the hud-only manifest write, not the full one // left untouched — the HUD it installs is now recorded, and nothing else // moved (D-HUD-ONLY-PRESERVE: the plugin list survives). expect(features.hud).toBe(true); expect((await readManifest(devflowDir)).plugins).toEqual(prior.plugins); }); });