import { describe, it, expect } from 'vitest'; import { readFileSync } from 'fs'; import * as path from 'path'; import { DEVFLOW_PLUGINS, WORKFLOW_FOLDER_NAMES, getAllCommandNames, getAllSkillNames, selectedWorkflowFolders, workflowFolderNames, getAllAgentNames, getAllRuleNames, buildAssetMaps, buildFullSkillsMap, partitionSelectablePlugins, prefixSkillName, resolveFeatureRedirect, parsePluginSelection, WORKFLOW_ORDER, EXCLUDED, DELETED_PLUGIN_NAMES, LEGACY_PLUGIN_NAMES, FEATURE_OWNED_SKILLS, FEATURE_OWNED_RULES, PRESENCE_GATED_SKILLS, skillsOf, skillOwners, buildScopedSkillsMap, resolveSkillInstallPlan, registeredPluginNames, type PluginDefinition, } from '../src/core/plugins.js'; import { LEGACY_SKILL_NAMES } from '../src/targets/claude-code/legacy.js'; import { resolvePluginsToInstall } from '../src/cli/commands/init-seed.js'; describe('getAllSkillNames', () => { it('returns a deduplicated list of skills across all plugins', () => { const skills = getAllSkillNames(); expect(skills.length).toBeGreaterThan(0); expect(new Set(skills).size).toBe(skills.length); }); it('includes skills from multiple plugins', () => { const skills = getAllSkillNames(); // 'accessibility' appears in devflow-accessibility (optional plugin) expect(skills).toContain('accessibility'); // 'worktree-support' appears in multiple plugins expect(skills).toContain('worktree-support'); }); }); describe('getAllAgentNames', () => { it('returns a deduplicated list of agents across all plugins', () => { const agents = getAllAgentNames(); expect(agents.length).toBeGreaterThan(0); expect(new Set(agents).size).toBe(agents.length); }); it('includes agents from multiple plugins', () => { const agents = getAllAgentNames(); // 'git' appears in implement, code-review, resolve, debug expect(agents).toContain('git'); expect(agents).toContain('synthesize'); }); }); describe('buildAssetMaps', () => { it('assigns each asset to the first plugin that declares it', () => { const { skillsMap, agentsMap } = buildAssetMaps(DEVFLOW_PLUGINS); // 'accessibility' first appears in devflow-accessibility (optional plugin) expect(skillsMap.get('accessibility')).toBe('devflow-accessibility'); // 'git' first appears in devflow-plan (plan.mds spawns Git for ensure-traceable-issue) expect(agentsMap.get('git')).toBe('devflow-plan'); // 'synthesize' first appears in devflow-plan expect(agentsMap.get('synthesize')).toBe('devflow-plan'); }); it('returns empty maps for empty input', () => { const { skillsMap, agentsMap } = buildAssetMaps([]); expect(skillsMap.size).toBe(0); expect(agentsMap.size).toBe(0); }); it('handles a single plugin', () => { const single: PluginDefinition[] = [{ name: 'test-plugin', description: 'Test', commands: [], agents: ['agent-a'], skills: ['skill-a', 'skill-b'], requires: [], }]; const { skillsMap, agentsMap } = buildAssetMaps(single); expect(skillsMap.size).toBe(2); expect(agentsMap.size).toBe(1); expect(skillsMap.get('skill-a')).toBe('test-plugin'); expect(agentsMap.get('agent-a')).toBe('test-plugin'); }); it('deduplicates overlapping skills/agents (first plugin wins)', () => { const plugins: PluginDefinition[] = [ { name: 'first', description: '', commands: [], agents: ['shared-agent'], skills: ['shared-skill'], requires: [] }, { name: 'second', description: '', commands: [], agents: ['shared-agent'], skills: ['shared-skill'], requires: [] }, ]; const { skillsMap, agentsMap } = buildAssetMaps(plugins); expect(skillsMap.get('shared-skill')).toBe('first'); expect(agentsMap.get('shared-agent')).toBe('first'); expect(skillsMap.size).toBe(1); expect(agentsMap.size).toBe(1); }); }); describe('buildFullSkillsMap', () => { it('includes skills from ALL plugins regardless of selection', () => { const fullMap = buildFullSkillsMap(); // Must include skills from optional plugins too expect(fullMap.has('accessibility')).toBe(true); expect(fullMap.has('typescript')).toBe(true); expect(fullMap.has('go')).toBe(true); // Must include shared skills from core plugins expect(fullMap.has('review-methodology')).toBe(true); expect(fullMap.has('patterns')).toBe(true); expect(fullMap.has('worktree-support')).toBe(true); }); it('covers more skills than buildAssetMaps with only non-optional plugins', () => { const nonOptional = DEVFLOW_PLUGINS.filter(p => !p.optional); const { skillsMap: partialMap } = buildAssetMaps(nonOptional); const fullMap = buildFullSkillsMap(); expect(fullMap.size).toBeGreaterThan(partialMap.size); }); it('matches getAllSkillNames count', () => { const fullMap = buildFullSkillsMap(); const allNames = getAllSkillNames(); expect(fullMap.size).toBe(allNames.length); }); }); // --------------------------------------------------------------------------- // Scoped skill closure (D-SCOPED-SKILLS) // --------------------------------------------------------------------------- describe('skillsOf', () => { const byName = (name: string): PluginDefinition => { const found = DEVFLOW_PLUGINS.find(p => p.name === name); if (found === undefined) throw new Error(`no such plugin: ${name}`); return found; }; it('is the union of skills AND requires, not either alone', () => { const explore = byName('devflow-explore'); const closure = skillsOf([explore]); for (const owned of explore.skills) expect(closure.has(owned)).toBe(true); for (const required of explore.requires) expect(closure.has(required)).toBe(true); expect(closure.size).toBe(new Set([...explore.skills, ...explore.requires]).size); }); it('apply-decisions reaches devflow-explore through its Knowledge agent and its own thread', () => { // The widened corpus (design review C1) is what puts it there: explore owns // no consumer skill, and knowledge.mds and explore.mds name apply-decisions. // Synthesize no longer preloads review-methodology, so neither that skill nor // the ten focus skills its body names is part of explore's closure any more. expect(byName('devflow-explore').requires).toContain('apply-decisions'); const closure = skillsOf([byName('devflow-explore')]); expect(closure.has('apply-decisions')).toBe(true); for (const gone of ['review-methodology', 'security', 'architecture', 'docs-framework']) { expect(closure.has(gone), `${gone} must not reach devflow-explore`).toBe(false); } }); it('deduplicates across plugins and is empty for an empty selection', () => { expect(skillsOf([]).size).toBe(0); const pair = skillsOf([byName('devflow-explore'), byName('devflow-research')]); expect(pair.size).toBeLessThan( skillsOf([byName('devflow-explore')]).size + skillsOf([byName('devflow-research')]).size, ); }); it('the full registry closure equals the full registry skill set', () => { // A requires entry is always some plugin's owned skill, so the closure adds // nothing at registry scope — the property buildFullSkillsMap relies on. expect([...skillsOf(DEVFLOW_PLUGINS)].sort()).toEqual([...getAllSkillNames()].sort()); }); it('scoping is real: the default (non-optional) selection is a strict subset', () => { const scoped = skillsOf(DEVFLOW_PLUGINS.filter(p => !p.optional)); expect(scoped.size).toBeLessThan(getAllSkillNames().length); for (const gated of PRESENCE_GATED_SKILLS) { expect(scoped.has(gated), `${gated} must not install by default`).toBe(false); } }); }); describe('docs-framework stays installed under every selection (AC-502)', () => { // Synthesize no longer preloads docs-framework and most plugins stopped requiring // it, so the skill now reaches a machine only through devflow-core-skills, which // init adds to every non-empty selection. The property is held at the registry: // one selection per plugin, resolved the way init resolves it. it('every single-plugin selection, with or without ambient, installs docs-framework', () => { for (const plugin of DEVFLOW_PLUGINS) { for (const ambient of [false, true]) { const installed = resolvePluginsToInstall([plugin.name], ambient, DEVFLOW_PLUGINS); expect(skillsOf(installed).has('docs-framework'), `${plugin.name} (ambient ${ambient})`).toBe(true); } } }); it('the default selection installs it, and devflow-core-skills owns it', () => { expect(skillsOf(resolvePluginsToInstall([], false, DEVFLOW_PLUGINS)).has('docs-framework')).toBe(true); expect(skillOwners('docs-framework')).toContain('devflow-core-skills'); }); }); describe('skillOwners', () => { it('returns every declaring plugin, not the first', () => { const owners = skillOwners('worktree-support'); expect(owners.length).toBeGreaterThan(1); for (const name of owners) { expect(DEVFLOW_PLUGINS.find(p => p.name === name)?.skills).toContain('worktree-support'); } }); it('preserves registry declaration order', () => { const owners = skillOwners('worktree-support'); const registryOrder = DEVFLOW_PLUGINS.map(p => p.name).filter(n => owners.includes(n)); expect(owners).toEqual(registryOrder); }); it('never reports a plugin that merely requires the skill', () => { // devflow-explore requires apply-decisions; devflow-core-skills owns it. expect(skillOwners('apply-decisions')).not.toContain('devflow-explore'); expect(skillOwners('apply-decisions')).toContain('devflow-core-skills'); }); it('is empty for an unknown name', () => { expect(skillOwners('no-such-skill')).toEqual([]); }); }); describe('buildScopedSkillsMap', () => { const explore = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-explore')!; it('keys on the closure, not on owned skills alone', () => { const map = buildScopedSkillsMap([explore]); expect([...map.keys()].sort()).toEqual([...skillsOf([explore])].sort()); }); it('attributes a required-but-unowned skill to its real owner', () => { const map = buildScopedSkillsMap([explore]); expect(map.get('apply-decisions')).toBe(skillOwners('apply-decisions')[0]); expect(map.get('apply-decisions')).not.toBe('devflow-explore'); }); it('attributes an owned skill to the selected plugin that owns it', () => { const map = buildScopedSkillsMap([explore]); expect(map.get('feature-knowledge')).toBe('devflow-explore'); }); it('installs no presence-gated language skill for a non-language selection', () => { const map = buildScopedSkillsMap([explore]); for (const gated of PRESENCE_GATED_SKILLS) expect(map.has(gated)).toBe(false); }); }); describe('resolveSkillInstallPlan', () => { const nonOptional = DEVFLOW_PLUGINS.filter(p => !p.optional); const explore = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-explore')!; it('a partial install removes nothing (AC-22)', () => { const plan = resolveSkillInstallPlan({ effectivePlugins: [explore], isPartialInstall: true, shadowedSkills: [], }); expect(plan.remove.size).toBe(0); expect([...plan.install].sort()).toEqual([...skillsOf([explore])].sort()); }); it('a full install removes exactly skillsOf(all) \\ skillsOf(selected) \\ FEATURE_OWNED', () => { const plan = resolveSkillInstallPlan({ effectivePlugins: nonOptional, isPartialInstall: false, shadowedSkills: [], }); const expected = [...skillsOf(DEVFLOW_PLUGINS)] .filter(s => !plan.install.has(s)) .filter(s => !(FEATURE_OWNED_SKILLS as readonly string[]).includes(s)) .sort(); expect([...plan.remove].sort()).toEqual(expected); expect(plan.remove.size).toBeGreaterThan(0); }); it('never removes a feature-owned skill even when no plugin claims it', () => { const plan = resolveSkillInstallPlan({ effectivePlugins: nonOptional, isPartialInstall: false, shadowedSkills: [], }); for (const owned of FEATURE_OWNED_SKILLS) { expect(plan.remove.has(owned), `${owned} belongs to its feature, not to this sweep`).toBe(false); } }); it('a shadow outside the install set is dormant, never removed', () => { const plan = resolveSkillInstallPlan({ effectivePlugins: [explore], isPartialInstall: false, shadowedSkills: ['typescript', 'feature-knowledge'], }); expect(plan.dormantShadows).toEqual(['typescript']); // Dormancy is a report, not a deletion instruction: the shadow directory // lives in ~/.devflow/skills/ and is user content. expect(plan.remove.has('typescript')).toBe(true); expect(plan.dormantShadows).not.toContain('feature-knowledge'); }); it('deduplicates and sorts dormant shadows', () => { const plan = resolveSkillInstallPlan({ effectivePlugins: [explore], isPartialInstall: true, shadowedSkills: ['rust', 'go', 'rust'], }); expect(plan.dormantShadows).toEqual(['go', 'rust']); }); }); describe('DEVFLOW_PLUGINS integrity', () => { it('has no duplicate plugin names', () => { const names = DEVFLOW_PLUGINS.map(p => p.name); expect(new Set(names).size).toBe(names.length); }); it('all plugins have required fields', () => { for (const plugin of DEVFLOW_PLUGINS) { expect(plugin.name).toBeTruthy(); expect(typeof plugin.name).toBe('string'); expect(plugin.description).toBeTruthy(); expect(typeof plugin.description).toBe('string'); expect(Array.isArray(plugin.commands)).toBe(true); expect(Array.isArray(plugin.agents)).toBe(true); expect(Array.isArray(plugin.skills)).toBe(true); expect(Array.isArray(plugin.requires)).toBe(true); expect(Array.isArray(plugin.rules)).toBe(true); } }); it('all skill and agent names are non-empty strings', () => { for (const plugin of DEVFLOW_PLUGINS) { for (const skill of plugin.skills) { expect(typeof skill).toBe('string'); expect(skill.length).toBeGreaterThan(0); } for (const agent of plugin.agents) { expect(typeof agent).toBe('string'); expect(agent.length).toBeGreaterThan(0); } for (const required of plugin.requires) { expect(typeof required).toBe('string'); expect(required.length).toBeGreaterThan(0); } } }); it('has at least 8 plugins', () => { expect(DEVFLOW_PLUGINS.length).toBeGreaterThanOrEqual(8); }); }); describe('optional plugin flag', () => { const languagePluginNames = [ 'devflow-typescript', 'devflow-react', 'devflow-accessibility', 'devflow-ui-design', 'devflow-go', 'devflow-java', 'devflow-python', 'devflow-rust', ]; it('all language/ecosystem plugins have optional: true', () => { for (const name of languagePluginNames) { const plugin = DEVFLOW_PLUGINS.find(p => p.name === name); expect(plugin, `${name} should exist`).toBeDefined(); expect(plugin!.optional, `${name} should be optional`).toBe(true); } }); it('non-language plugins do not have optional: true', () => { const allowedOptional = new Set(languagePluginNames); for (const plugin of DEVFLOW_PLUGINS) { if (!allowedOptional.has(plugin.name)) { expect(plugin.optional, `${plugin.name} should not be optional`).toBeFalsy(); } } }); it('new language skills exist in the registry', () => { const skills = getAllSkillNames(); for (const lang of ['go', 'java', 'python', 'rust']) { expect(skills, `skill '${lang}' should exist`).toContain(lang); } }); it('devflow-ambient declares review/resolve skill dependencies', () => { const ambient = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-ambient'); expect(ambient).toBeDefined(); // Ambient must declare review skills so uninstalling code-review doesn't break ambient review expect(ambient!.skills).toContain('review-methodology'); expect(ambient!.skills).toContain('security'); // Ambient must declare resolve dependencies expect(ambient!.skills).toContain('patterns'); // Ambient must declare all needed agents expect(ambient!.agents).toContain('git'); expect(ambient!.agents).toContain('synthesize'); expect(ambient!.agents).toContain('triage'); }); it('devflow-resolve declares triage, code, and validate agents (no resolver)', () => { const resolve = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-resolve'); expect(resolve).toBeDefined(); // Triage agent validates issues; Code agent fixes them; Validate agent runs the verification gate expect(resolve!.agents).toContain('triage'); expect(resolve!.agents).toContain('code'); expect(resolve!.agents).toContain('validate'); // resolver has been retired — should not appear in registry; retirements need // no manual list entry — the registry-diff sweep in the installer // (sweepOrphanedAssets) removes any installed file absent from getAllAgentNames() expect(resolve!.agents).not.toContain('resolver'); // apply-decisions skill declared so Triage agent can cite ADR/PF entries expect(resolve!.skills).toContain('apply-decisions'); }); it('devflow-implement declares evaluate and test agents and qa skill', () => { const implement = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-implement'); expect(implement).toBeDefined(); // evaluate and test agents are declared so uninstalling ambient doesn't break implement expect(implement!.agents).toContain('evaluate'); expect(implement!.agents).toContain('test'); // qa skill is required for the test agent expect(implement!.skills).toContain('qa'); }); it('devflow-ambient declares evaluate, test agents and qa skill', () => { const ambient = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-ambient'); expect(ambient).toBeDefined(); // Ambient orchestrates the full implement pipeline, so evaluate and test agents must be declared expect(ambient!.agents).toContain('evaluate'); expect(ambient!.agents).toContain('test'); // qa skill is required for the test agent expect(ambient!.skills).toContain('qa'); }); it('devflow-core-skills does not contain language/ecosystem skills', () => { const coreSkills = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-core-skills'); expect(coreSkills).toBeDefined(); const movedSkills = ['typescript', 'react', 'accessibility', 'ui-design']; for (const skill of movedSkills) { expect(coreSkills!.skills, `core-skills should not contain '${skill}'`).not.toContain(skill); } }); it('devflow-bug-analysis declares correct agents, skills, and command', () => { const bugAnalysis = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-bug-analysis'); expect(bugAnalysis, 'devflow-bug-analysis should exist in registry').toBeDefined(); // Core orchestration agents: git (pre-flight), debug (semantic analysis), synthesize (reporting) expect(bugAnalysis!.agents).toContain('git'); expect(bugAnalysis!.agents).toContain('debug'); expect(bugAnalysis!.agents).toContain('synthesize'); // Skills: worktree-support for discovery, apply-feature-knowledge for context expect(bugAnalysis!.skills).toContain('worktree-support'); expect(bugAnalysis!.skills).toContain('apply-feature-knowledge'); // Skills added in batch-2: apply-decisions + the 5 debug-agent category skills expect(bugAnalysis!.skills).toContain('apply-decisions'); expect(bugAnalysis!.skills).toContain('security'); expect(bugAnalysis!.skills).toContain('reliability'); expect(bugAnalysis!.skills).toContain('regression'); expect(bugAnalysis!.skills).toContain('consistency'); expect(bugAnalysis!.skills).toContain('complexity'); // Single command expect(bugAnalysis!.commands).toContain('/bug-analysis'); // Not optional — ships as a core plugin expect(bugAnalysis!.optional).toBeFalsy(); }); }); // --------------------------------------------------------------------------- // FEATURE_OWNED constants (step 1.5 de-registration) // --------------------------------------------------------------------------- describe('FEATURE_OWNED constants', () => { it('FEATURE_OWNED_SKILLS equals [compliance] — compliance skill is feature-owned, not plugin-owned', () => { expect(FEATURE_OWNED_SKILLS).toEqual(['compliance']); }); it('FEATURE_OWNED_RULES equals [compliance, behavior] — both rules are feature-owned, not plugin-owned', () => { expect(FEATURE_OWNED_RULES).toEqual(['compliance', 'behavior']); }); it('FEATURE_OWNED_SKILLS is disjoint from getAllSkillNames() — no double-ownership', () => { const pluginSkills = new Set(getAllSkillNames()); const overlap = [...FEATURE_OWNED_SKILLS].filter(s => pluginSkills.has(s)); expect(overlap, 'FEATURE_OWNED_SKILLS must not overlap with plugin-declared skills').toEqual([]); }); it('FEATURE_OWNED_RULES is disjoint from getAllRuleNames() — no double-ownership', () => { const pluginRules = new Set(getAllRuleNames()); const overlap = [...FEATURE_OWNED_RULES].filter(r => pluginRules.has(r)); expect(overlap, 'FEATURE_OWNED_RULES must not overlap with plugin-declared rules').toEqual([]); }); }); describe('DELETED_PLUGIN_NAMES consistency', () => { // DELETED_PLUGIN_NAMES is a PRUNING manifest, not an install-naming list: // resolvePluginList drops every listed name from the user's manifest.plugins on // partial reinstall. A LIVE plugin name listed here is therefore silently erased // from the user's recorded selection, and resolveSeedPlugins then omits it from // the next re-init seed — a plugin the user chose disappears with no error. // Same misread class as the LEGACY_SKILLS_* lists (deletion manifest that reads like a naming list); // guarded here because the state-aware-init contract forbids it. it('contains no name that is still a live plugin in the registry', () => { const liveNames = new Set(DEVFLOW_PLUGINS.map(p => p.name)); expect(liveNames.size, 'registry must be non-empty or this guard is vacuous').toBeGreaterThan(0); const stillLive = DELETED_PLUGIN_NAMES.filter(name => liveNames.has(name)); expect( stillLive, 'DELETED_PLUGIN_NAMES lists a plugin that still exists in DEVFLOW_PLUGINS — ' + 'it would be pruned from every user manifest on partial reinstall and dropped from the re-init seed', ).toEqual([]); }); it('contains devflow-compliance (compliance converted to built-in feature in B2)', () => { expect(DELETED_PLUGIN_NAMES).toContain('devflow-compliance'); }); it('contains devflow-dynamic, and the registry no longer carries it', () => { expect(DELETED_PLUGIN_NAMES).toContain('devflow-dynamic'); expect(DEVFLOW_PLUGINS.map(p => p.name)).not.toContain('devflow-dynamic'); }); it('gives a removed plugin no redirect: both spellings are unknown plugin names', () => { expect(resolveFeatureRedirect(['dynamic', 'devflow-dynamic'])).toEqual({ redirected: [], remaining: ['dynamic', 'devflow-dynamic'], notice: undefined, }); expect(parsePluginSelection('dynamic,devflow-dynamic', DEVFLOW_PLUGINS)).toEqual({ selected: ['devflow-dynamic', 'devflow-dynamic'], invalid: ['devflow-dynamic', 'devflow-dynamic'], }); }); it('keeps a removed plugin in a mixed list unknown and gives no notice, so the whole list is refused', () => { const redirect = resolveFeatureRedirect(['devflow-implement', 'dynamic']); expect(redirect.notice).toBeUndefined(); expect(redirect.redirected).toEqual([]); expect(redirect.remaining).toEqual(['devflow-implement', 'dynamic']); expect(parsePluginSelection(redirect.remaining.join(','), DEVFLOW_PLUGINS).invalid).toEqual(['devflow-dynamic']); }); it('does not overlap LEGACY_PLUGIN_NAMES keys (deletion would pre-empt the rename)', () => { // resolvePluginList filters deleted names BEFORE applying the rename map, so a // name in both lists is dropped rather than migrated to its new name. const overlap = DELETED_PLUGIN_NAMES.filter(name => name in LEGACY_PLUGIN_NAMES); expect( overlap, 'a name cannot be both renamed and deleted — the delete filter runs first and the rename would never apply', ).toEqual([]); }); }); describe('agent registry membership', () => { it("curate is in devflow-core-skills and devflow-ambient agents (not dream)", () => { const coreSkills = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-core-skills'); const ambient = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-ambient'); expect(coreSkills?.agents).toContain('curate'); expect(coreSkills?.agents).not.toContain('dream'); expect(ambient?.agents).toContain('curate'); expect(ambient?.agents).not.toContain('dream'); }); }); describe('LEGACY_SKILL_NAMES consistency', () => { it('no namespaced legacy skill name matches an active skill install path', () => { // Active skills install at the namespaced path devflow:. // Bare legacy entries (e.g. 'dream-decisions') are safe: they target pre-namespace // install dirs and are no-ops on current installs because active skills always install // under the devflow: prefix. Only namespaced legacy entries (those already carrying the // devflow: prefix) directly target an install path — so this guard asserts that no already-namespaced // entry in LEGACY_SKILL_NAMES collides with an active skill's install path. This // prevents a future namespaced legacy entry from silently deleting a live skill. const activeInstallPaths = new Set(getAllSkillNames().map(prefixSkillName)); const SKILL_NS = 'devflow:'; for (const legacyName of LEGACY_SKILL_NAMES) { if (!legacyName.startsWith(SKILL_NS)) continue; expect( activeInstallPaths, `LEGACY_SKILL_NAMES entry '${legacyName}' collides with an active skill install path — remove it from LEGACY_SKILL_NAMES or update the plugin registry`, ).not.toContain(legacyName); } }); }); describe('partitionSelectablePlugins', () => { // Independent oracle. Every other test in this describe derives its expectation // from the imported EXCLUDED, so they move with production and cannot detect a // change to the excluded set itself (dropping devflow-ambient leaves them green // while exposing an always-installed plugin as an uncheckable-by-accident entry // in the init language multiselect). This literal is the only assertion that // pins WHICH plugins are excluded, so a deliberate change must land here. it('EXCLUDED pins exactly the always-installed plugins (independent oracle)', () => { expect([...EXCLUDED].sort()).toEqual(['devflow-ambient', 'devflow-core-skills']); }); it('EXCLUDED ∩ optional === ∅ — no optional plugin is non-selectable (structural invariant)', () => { // This invariant ensures that every optional plugin is reachable via the init UI. // Adding an optional plugin to EXCLUDED would silently drop it on full re-inits // without a carry mechanism. Guards the structural requirement. const optionalNames = new Set(DEVFLOW_PLUGINS.filter(p => p.optional).map(p => p.name)); const intersection = [...EXCLUDED].filter(name => optionalNames.has(name)); expect(intersection, 'EXCLUDED contains an optional plugin — add a re-init carry mechanism to preserve it across full reinstalls').toEqual([]); }); it('command-bearing plugins land in workflow bucket', () => { const { workflow } = partitionSelectablePlugins(DEVFLOW_PLUGINS); const workflowNames = workflow.map(pl => pl.name); // Spot-check known workflow plugins expect(workflowNames).toContain('devflow-plan'); expect(workflowNames).toContain('devflow-bug-analysis'); expect(workflowNames).toContain('devflow-implement'); expect(workflowNames).toContain('devflow-code-review'); // All workflow plugins must have at least one command for (const pl of workflow) { expect(pl.commands.length, `${pl.name} in workflow bucket must have commands`).toBeGreaterThan(0); } }); it('command-less plugins land in language bucket', () => { const { language } = partitionSelectablePlugins(DEVFLOW_PLUGINS); const languageNames = language.map(pl => pl.name); // Spot-check known language plugins expect(languageNames).toContain('devflow-typescript'); expect(languageNames).toContain('devflow-react'); expect(languageNames).toContain('devflow-go'); expect(languageNames).toContain('devflow-python'); // All language plugins must have zero commands for (const pl of language) { expect(pl.commands.length, `${pl.name} in language bucket must have no commands`).toBe(0); } }); it('excluded plugins appear in neither bucket', () => { const { workflow, language } = partitionSelectablePlugins(DEVFLOW_PLUGINS); const allNames = new Set([...workflow, ...language].map(pl => pl.name)); for (const excluded of EXCLUDED) { expect(allNames.has(excluded), `${excluded} must not appear in any bucket`).toBe(false); } }); it('workflow + language covers all selectable (non-excluded) plugins', () => { const { workflow, language } = partitionSelectablePlugins(DEVFLOW_PLUGINS); const selectableCount = DEVFLOW_PLUGINS.filter(pl => !EXCLUDED.has(pl.name)).length; expect(workflow.length + language.length).toBe(selectableCount); }); it('buckets are disjoint', () => { const { workflow, language } = partitionSelectablePlugins(DEVFLOW_PLUGINS); const workflowNames = new Set(workflow.map(pl => pl.name)); for (const pl of language) { expect(workflowNames.has(pl.name), `${pl.name} must not appear in both buckets`).toBe(false); } }); it('does not mutate the input array', () => { const inputCopy = [...DEVFLOW_PLUGINS]; partitionSelectablePlugins(DEVFLOW_PLUGINS); expect(DEVFLOW_PLUGINS).toEqual(inputCopy); }); it('preserves DEVFLOW_PLUGINS ordering within each bucket', () => { const { workflow, language } = partitionSelectablePlugins(DEVFLOW_PLUGINS); // Collect the order of workflow and language plugins from the original registry const registryWorkflowOrder = DEVFLOW_PLUGINS .filter(pl => !EXCLUDED.has(pl.name) && pl.commands.length > 0) .map(pl => pl.name); const registryLanguageOrder = DEVFLOW_PLUGINS .filter(pl => !EXCLUDED.has(pl.name) && pl.commands.length === 0) .map(pl => pl.name); expect(workflow.map(pl => pl.name)).toEqual(registryWorkflowOrder); expect(language.map(pl => pl.name)).toEqual(registryLanguageOrder); }); it('returns empty buckets for empty input', () => { const { workflow, language } = partitionSelectablePlugins([]); expect(workflow).toHaveLength(0); expect(language).toHaveLength(0); }); }); describe('WORKFLOW_ORDER', () => { it('is exported and contains /bug-analysis', () => { expect(WORKFLOW_ORDER).toContain('/bug-analysis'); }); it('/bug-analysis appears after /self-review', () => { const selfReviewIdx = WORKFLOW_ORDER.indexOf('/self-review'); const bugAnalysisIdx = WORKFLOW_ORDER.indexOf('/bug-analysis'); expect(selfReviewIdx).toBeGreaterThanOrEqual(0); expect(bugAnalysisIdx).toBeGreaterThan(selfReviewIdx); }); it('every workflow plugin command appears in WORKFLOW_ORDER (regression guard)', () => { const { workflow } = partitionSelectablePlugins(DEVFLOW_PLUGINS); const workflowOrderSet = new Set(WORKFLOW_ORDER); for (const pl of workflow) { for (const cmd of pl.commands) { // Commands in plugin definitions use the /name format, matching WORKFLOW_ORDER entries expect( workflowOrderSet.has(cmd), `Command '${cmd}' from plugin '${pl.name}' must appear in WORKFLOW_ORDER`, ).toBe(true); } } }); it('every WORKFLOW_ORDER entry corresponds to a real command in the registry (reverse regression guard)', () => { // Build the full set of all commands across ALL plugins. const allCommands = new Set(DEVFLOW_PLUGINS.flatMap(pl => pl.commands)); for (const cmd of WORKFLOW_ORDER) { expect( allCommands.has(cmd), `WORKFLOW_ORDER entry '${cmd}' must correspond to a real command in DEVFLOW_PLUGINS`, ).toBe(true); } }); it('has no duplicate entries', () => { expect(new Set(WORKFLOW_ORDER).size).toBe(WORKFLOW_ORDER.length); }); }); // --------------------------------------------------------------------------- // dream-memory removal regression guards // --------------------------------------------------------------------------- describe('dream-memory skill removal (eager memory refresh)', () => { it('dream-memory is NOT in devflow-core-skills skills array', () => { const coreSkills = DEVFLOW_PLUGINS.find(p => p.name === 'devflow-core-skills'); expect(coreSkills).toBeDefined(); expect(coreSkills!.skills).not.toContain('dream-memory'); }); it('dream-memory bare name is in LEGACY_SKILL_NAMES for cleanup', () => { expect(LEGACY_SKILL_NAMES).toContain('dream-memory'); }); it('prefixed namespaced name (devflow: + dream-memory) is in LEGACY_SKILL_NAMES for installed-skill cleanup', () => { // Build the prefixed name at runtime to avoid skill-references scanner false-positive // (dream-memory is intentionally removed from canonical skills) const legacyPrefixedName = ['devflow', 'dream-memory'].join(':'); expect(LEGACY_SKILL_NAMES).toContain(legacyPrefixedName); }); it('getAllSkillNames does not include dream-memory', () => { const skills = getAllSkillNames(); expect(skills).not.toContain('dream-memory'); }); }); // --------------------------------------------------------------------------- // resolveFeatureRedirect (I30: mixed --plugin list must not silently no-op) // --------------------------------------------------------------------------- describe('resolveFeatureRedirect', () => { it('compliance-only: redirected, empty remaining, notice present', () => { const result = resolveFeatureRedirect(['devflow-compliance']); expect(result.redirected).toEqual(['devflow-compliance']); expect(result.remaining).toEqual([]); expect(result.notice).toMatch(/compliance.*built-in feature/i); }); it('compliance alias ("compliance") also redirects', () => { const result = resolveFeatureRedirect(['compliance']); expect(result.redirected).toEqual(['compliance']); expect(result.remaining).toEqual([]); expect(result.notice).toBeDefined(); }); it('mixed list: devflow-compliance stripped, other plugins remain (regression guard for I30)', () => { // This is the exact scenario that was silently no-oping before the fix: // devflow init --plugin=devflow-implement,devflow-code-review,devflow-compliance // should install devflow-implement and devflow-code-review, not exit 0 before parsing. const result = resolveFeatureRedirect(['devflow-implement', 'devflow-compliance', 'devflow-code-review']); expect(result.redirected).toEqual(['devflow-compliance']); expect(result.remaining).toEqual(['devflow-implement', 'devflow-code-review']); expect(result.notice).toBeDefined(); }); it('mixed list with shorthand alias: compliance alias stripped, other plugins remain', () => { const result = resolveFeatureRedirect(['devflow-plan', 'compliance']); expect(result.redirected).toEqual(['compliance']); expect(result.remaining).toEqual(['devflow-plan']); expect(result.notice).toBeDefined(); }); it('no feature redirects: all remain, no notice', () => { const result = resolveFeatureRedirect(['devflow-implement', 'devflow-plan']); expect(result.redirected).toEqual([]); expect(result.remaining).toEqual(['devflow-implement', 'devflow-plan']); expect(result.notice).toBeUndefined(); }); it('empty input returns empty result with no notice', () => { const result = resolveFeatureRedirect([]); expect(result.redirected).toEqual([]); expect(result.remaining).toEqual([]); expect(result.notice).toBeUndefined(); }); it('preserves order of remaining plugins', () => { const result = resolveFeatureRedirect(['devflow-plan', 'devflow-compliance', 'devflow-implement', 'devflow-resolve']); expect(result.remaining).toEqual(['devflow-plan', 'devflow-implement', 'devflow-resolve']); }); }); describe('registeredPluginNames', () => { it('keeps the names the registry has, in the order given', () => { expect(registeredPluginNames(['devflow-plan', 'devflow-implement', 'devflow-core-skills'])) .toEqual(['devflow-plan', 'devflow-implement', 'devflow-core-skills']); }); it('maps a legacy name to the plugin that replaced it', () => { const mapped = Object.entries(LEGACY_PLUGIN_NAMES).filter(([, current]) => DEVFLOW_PLUGINS.some(p => p.name === current)); expect(mapped.length, 'the legacy table maps at least one name to a plugin the registry has').toBeGreaterThan(0); for (const [legacy, current] of mapped) { expect(registeredPluginNames([legacy])).toEqual([current]); expect(registeredPluginNames([current])).toEqual([current]); } }); it('drops a name the registry does not have, a deleted name included', () => { expect(DELETED_PLUGIN_NAMES.length).toBeGreaterThan(0); expect(registeredPluginNames(['devflow-not-a-plugin', '', 'evil; rm -rf /', ...DELETED_PLUGIN_NAMES])).toEqual([]); }); it('never reads a key the legacy table inherits from Object as a mapping', () => { expect(registeredPluginNames(['constructor', '__proto__', 'toString', 'hasOwnProperty', 'devflow-plan'])) .toEqual(['devflow-plan']); }); it('returns the empty list for the empty list', () => { expect(registeredPluginNames([])).toEqual([]); }); }); // ── The target-layer set (workflows that ship as skill folders) ───────────── describe('the target-layer set of folder workflows (D-WORKFLOW-FOLDER-SET)', () => { const FLOW = new Set(['flow']); const flowPlugin: PluginDefinition = { name: 'devflow-flow', description: 'fixture owner of the folder workflow', commands: ['/flow', '/plan'], agents: [], skills: [], requires: [], rules: [], }; const otherPlugin: PluginDefinition = { ...flowPlugin, name: 'devflow-other', commands: ['/other'] }; it('the real set is empty, so every default reader answers as before the set existed', () => { expect(WORKFLOW_FOLDER_NAMES.size).toBe(0); expect(getAllCommandNames()).toEqual(getAllCommandNames(new Set())); expect(getAllSkillNames()).toEqual(getAllSkillNames(new Set())); const plan = resolveSkillInstallPlan({ effectivePlugins: DEVFLOW_PLUGINS, isPartialInstall: false, shadowedSkills: ['git'] }); expect(plan.removeFolders.size).toBe(0); expect(plan.ignoredFolderShadows).toEqual([]); }); it('the set derives from a folder registry by name', () => { expect([...workflowFolderNames([{ name: 'flow' }, { name: 'other' }])]).toEqual(['flow', 'other']); }); it('getAllCommandNames drops a name of the set and keeps every other command', () => { const all = getAllCommandNames(); expect(all).toContain('plan'); const without = getAllCommandNames(new Set(['plan'])); expect(without).not.toContain('plan'); expect(without).toEqual(all.filter(name => name !== 'plan')); }); it('getAllSkillNames gains a name of the set and keeps every other skill', () => { const all = getAllSkillNames(); expect(all).not.toContain('flow'); expect(getAllSkillNames(FLOW)).toEqual([...all, 'flow']); }); it('selectedWorkflowFolders names the folders a plugin owns as a command', () => { expect([...selectedWorkflowFolders([flowPlugin], FLOW)]).toEqual(['flow']); expect(selectedWorkflowFolders([otherPlugin], FLOW).size).toBe(0); expect(selectedWorkflowFolders([flowPlugin], new Set()).size).toBe(0); }); it('a full install removes the folder when its owner is not selected, and keeps it when it is', () => { const without = resolveSkillInstallPlan({ effectivePlugins: [otherPlugin], isPartialInstall: false, shadowedSkills: [], folderWorkflows: FLOW }); expect([...without.removeFolders]).toEqual(['flow']); const withOwner = resolveSkillInstallPlan({ effectivePlugins: [flowPlugin], isPartialInstall: false, shadowedSkills: [], folderWorkflows: FLOW }); expect(withOwner.removeFolders.size).toBe(0); }); it('a partial install removes no folder, with or without the owner (TP-25)', () => { for (const effectivePlugins of [[otherPlugin], [flowPlugin]]) { const plan = resolveSkillInstallPlan({ effectivePlugins, isPartialInstall: true, shadowedSkills: [], folderWorkflows: FLOW }); expect(plan.removeFolders.size).toBe(0); } }); it('a shadow of a folder is ignored, never dormant, and a library shadow is unaffected (TP-22)', () => { const plan = resolveSkillInstallPlan({ effectivePlugins: [otherPlugin], isPartialInstall: false, shadowedSkills: ['flow', 'git'], folderWorkflows: FLOW, }); expect(plan.ignoredFolderShadows).toEqual(['flow']); expect(plan.dormantShadows).toEqual(['git']); }); it('a folder name is in no plugin skills or requires, so it is not classified as a library skill (TP-24)', () => { expect(skillsOf(DEVFLOW_PLUGINS).has('flow')).toBe(false); const plan = resolveSkillInstallPlan({ effectivePlugins: [flowPlugin], isPartialInstall: false, shadowedSkills: [], folderWorkflows: FLOW }); expect(plan.install.has('flow')).toBe(false); expect(plan.remove.has('flow')).toBe(false); }); }); describe('core imports nothing from the target layer (TP-24)', () => { const ROOT = path.resolve(import.meta.dirname, '..'); const IMPORT_RE = /(?:^|\n)\s*(?:import|export)\s[^'"\n;]*?from\s+['"](\.{1,2}\/[^'"]+)['"]|(?:^|\n)\s*import\s+['"](\.{1,2}\/[^'"]+)['"]/g; /** The files the static relative imports of `entry` reach, `entry` included. */ function importClosure(entry: string): Set { const seen = new Set(); const queue = [entry]; while (queue.length > 0 && seen.size < 2000) { const file = queue.pop()!; if (seen.has(file)) continue; seen.add(file); const source = readFileSync(file, 'utf-8'); for (const match of source.matchAll(IMPORT_RE)) { const spec = match[1] ?? match[2]; queue.push(path.resolve(path.dirname(file), spec.replace(/\.js$/, '.ts'))); } } return seen; } it.each([ 'src/core/plugins.ts', 'src/core/mds-variants.ts', 'src/core/assets.ts', ])('%s reaches no file under src/targets', (entry) => { const closure = importClosure(path.join(ROOT, entry)); expect(closure.size, 'the scan followed the imports').toBeGreaterThan(1); const reached = [...closure].filter(file => file.startsWith(path.join(ROOT, 'src', 'targets') + path.sep)); expect(reached.map(file => path.relative(ROOT, file))).toEqual([]); }); it('the scan sees a target import where one exists', () => { const closure = importClosure(path.join(ROOT, 'src/core/agent-models.ts')); expect([...closure].some(file => file.includes(`${path.sep}src${path.sep}targets${path.sep}`))).toBe(true); }); });