mirror of
https://github.com/github/spec-kit.git
synced 2026-08-03 06:26:30 +08:00
* feat: update Bob integration to skills-based layout for Bob 2.0 Bob 2.0 replaces the command-based workflow (.bob/commands/*.md) with a skills-based layout (.bob/skills/speckit-<name>/SKILL.md), matching the pattern used by Claude Code, Codex, and other skills-first agents. - Switch BobIntegration from MarkdownIntegration to SkillsIntegration - Update folder/dir from .bob/commands to .bob/skills - Change extension from .md to /SKILL.md (skills layout) - Add --skills option (default: True) consistent with Codex pattern - Update tests to inherit from SkillsIntegrationTests (28 tests pass) - Bump catalog entry to version 2.0.0 with updated description Assisted-by: IBM Bob (model: claude-sonnet-4-5, autonomous) * PR comments fix: keep old Bob 1 commands till next release * Copilot suggested change Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * feat(bob): address copilot comments, make skills layout default, demote legacy commands to opt-in * fix(bob): honor legacy_commands in ai_skills persistence and add bob to ALWAYS_SLASH_AGENTS - init.py: suppress ai_skills=True when --legacy-commands is passed so extensions and presets target .bob/commands, not .bob/skills - _invocation_style.py: add 'bob' to ALWAYS_SLASH_AGENTS so init next-steps and hook invocations always show /speckit-<name> (skills is the default layout; no ai_skills flag required) * Copilot suggestion Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix(bob): extend IntegrationBase directly to avoid false isinstance(SkillsIntegration) - bob/__init__.py: switch BobIntegration base from SkillsIntegration to IntegrationBase; add _BobSkillsHelper for skills-mode delegation; set invoke_separator='-' explicitly; set _skills_mode flag in setup() so consumers can derive the effective mode without isinstance checks - _helpers.py: replace isinstance(integration, SkillsIntegration) guard with getattr(_skills_mode) so legacy-commands mode does not persist ai_skills=True - _invocation_style.py: remove 'bob' from ALWAYS_SLASH_AGENTS — Bob 2.0 skills are invoked via natural language, not /skill-name slash commands - integrations/catalog.json: advance updated_at to 2026-07-15 * fix(lint): remove unused SkillsIntegration import from _helpers.py * Copilot suggested change Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * feat(bob): add bob skills integration with registrar-based mode detection * address 3 comments from copilot * feat(bob): update registrar config to use legacy commands layout * fix lint * Suggested fix from Copilot Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix pr comment * fix pr comment * fix pr comment * refactor(bob): resolve skills mode via base-class hooks + fix command-ref separators Rework the dual-mode handling introduced for Bob 2.0 so an integration's internal representation never leaks into shared init/install/upgrade code, and fix the legacy command-reference separator surfaced in review. Base-class contract: - Add IntegrationBase.is_skills_mode(parsed_options) — the single hook the shared machinery consults to decide whether to persist ai_skills and render skill invocations. SkillsIntegration returns True; Copilot honors --skills / self._skills_mode; Bob returns `not legacy_commands`. - Add IntegrationBase.invoke_separator_for_mode(skills_enabled) — resolves the command-ref separator from a project's persisted mode for registration paths that only have the ai_skills flag (no CLI parsed_options). Default is behavior-preserving; Bob maps skills->"-", legacy->".". - BobIntegration stays on IntegrationBase (mirroring Copilot, the other dual-mode agent) and delegates setup() to internal _BobSkillsHelper / _BobMarkdownHelper. Removes the _skills_mode method and all isinstance(SkillsIntegration) / callable(_skills_mode) probing from _helpers.py and init.py. Fix legacy separator (review feedback): CommandRegistrar.register_commands and PresetManager._resolve_skill_command_refs previously read the single static AGENT_CONFIGS[key]["invoke_separator"], so legacy .bob/commands/ extension and preset command refs rendered /speckit-<cmd> instead of Bob 1.x /speckit.<cmd>. Both now resolve the separator per project mode via invoke_separator_for_mode. Tests: add regression coverage for the is_skills_mode / invoke_separator_for_mode hooks and legacy extension command-ref separators; normalize a width-sensitive workflow assertion to match its siblings. Full suite green. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob,copilot): address review — preserve legacy layout, dual-mode separators, extension-skill token resolution Addresses PR review 4716036212 (3 comments): 1. Bob legacy-install regression: `use`/`switch`/`upgrade` on an existing Bob 1.x project (only `.bob/commands/` on disk, no stored `legacy_commands`) called `is_skills_mode(None)` -> True and rewrote `ai_skills=True`, silently switching extension/command-reference handling to the skills layout. `is_skills_mode` now takes an optional `project_root`; Bob preserves an already-installed legacy layout until an explicit upgrade creates `.bob/skills/`. A fresh project still defaults to skills. 2. Copilot dual-mode separator: `invoke_separator_for_mode` was inherited from the base (mode-independent) and returned Copilot's static `.`, so preset/extension command refs in a Copilot skills project rendered `/speckit.<name>` instead of `/speckit-<name>`. Override it on Copilot to track the persisted `ai_skills` state, consistent with `build_command_invocation` and `effective_invoke_separator`. 3. Bob extension-skill command-ref tokens: verified that merging main's generic `_resolve_command_ref_tokens` (#3544) resolves Bob's tokens via the `CONDITIONAL_SLASH_AGENTS` path (`/speckit-<name>`); added Bob to the command-ref regression parametrize plus dedicated Bob use-path tests. All tests pass (full suite green; merged with current main incl. #3544). Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): resolve command-ref separator with project-aware mode before shared-infra refresh (review #3415) The `use`/`switch` paths refresh shared infrastructure via `_with_integration_setting()` / `_invoke_separator_for_integration()`, which previously resolved the invoke separator through `effective_invoke_separator` / `is_skills_mode` WITHOUT a project_root. For a pre-PR Bob 1.x project (.bob/commands/ on disk, no stored options), this defaulted to the skills "-" separator and rewrote rendered shared-template command refs to /speckit-*, even though ai_skills stayed false. Thread project_root through effective_invoke_separator, the two runtime helpers, and every call site so Bob's on-disk legacy detection governs the separator before shared infra is refreshed. Add a rendered-shared-template regression test covering `use --force`. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): scope persisted ai_skills flag to active agent when resolving command-ref separator (review #3415) `register_commands` runs once per detected agent, but the persisted `ai_skills` flag describes only the active integration (`opts["ai"]`). When another agent (e.g. Copilot) is active in skills mode while a legacy `.bob/commands` layout is also present, the previous code passed that global `True` to Bob's `invoke_separator_for_mode`, rewriting Bob 1.x command refs to `/speckit-*` instead of `/speckit.*`. Only consult the persisted flag for the agent it describes (`opts["ai"] == agent_name`); otherwise resolve the separator from the agent's own project-aware `effective_invoke_separator(None, project_root)`. Add regression tests covering the mismatched-active-agent case and a control for Bob-active skills mode. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): detect Spec Kit layout from managed artifacts, not any skills dir (review #3415) Two related mis-detections from review 4723246468: 1. `BobIntegration.is_skills_mode` treated the mere presence of a `.bob/skills/` directory as proof the project is skills-based. A legacy Spec Kit install (managed `.bob/commands/speckit.*.md`) that also carried unrelated Bob 2 skills would be misclassified as skills, so `integration use bob` persisted `ai_skills` and rewrote shared refs. Now the layout is inferred from managed Spec Kit artifacts: legacy/command mode only when managed `speckit.*.md` command files exist and no managed `speckit-*` skill dirs do. 2. The `register_commands` separator for an inactive agent used a disk-based `effective_invoke_separator(None, project_root)` fallback that could pick the skills separator even though the registrar writes the static command layout (`.bob/commands/*.md`). Inactive agents now resolve the separator from the registrar's actual output layout (`extension == "/SKILL.md"`), so command-layout files keep `/speckit.*` refs regardless of sibling dirs. Update the affected hook/E2E tests to use managed artifacts and add regression tests for the mixed-layout and inactive-registrar scenarios. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): apply managed-artifact detection on upgrade + consistent skill post-processing (review #3415) Two issues from review 4723782860: 1. `BobIntegration.setup()` resolved the layout via `is_skills_mode(parsed_options)` WITHOUT `project_root`, so `integration upgrade bob` on a Bob 1.x install (managed `.bob/commands/speckit.*.md`, no stored options) ignored the existing command files, generated skills, and stale-deleted the legacy commands — silently migrating the project. Pass `project_root` so the same managed-artifact detection used by `use` also governs upgrades. 2. Only `_BobSkillsHelper` overrode `post_process_skill_content` to suppress the shared slash-command hook note. Preset/extension skill generators call that hook on the registered `BobIntegration`, which inherited `IntegrationBase`'s note-injecting default. Repeat the no-op (delegating to the skills helper) on the registered class so every Bob skill-generation path is consistent with intent-activated core Bob skills. Add regression tests for the upgrade-preservation and post-processing paths. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * feat(bob): add --skills migration opt-in; fix separator + manifest loss (review #3415) Address review #3415 (4724160183): - Comment 1: Add an explicit `--skills` opt-in to BobIntegration. It forces the skills layout over on-disk auto-detection, giving legacy Bob 1.x installs a supported migration path (`integration upgrade bob --integration-options="--skills"`). `--skills` and `--legacy-commands` are mutually exclusive (clean exit-1 error). - Comment 2: In CommandRegistrar.register_commands, derive the command-ref separator from the output layout (agent_config["extension"]) for the active agent too, not the persisted ai_skills flag. A command-layout file (.bob/commands/*.md, .github/agents/*.agent.md) always renders /speckit.*; only a /SKILL.md scaffold uses /speckit-*. Dual-layout agents (Bob, Copilot) write skills via their own setup()/skills path, so register_commands only ever emits their command-layout files. - Comment 3: Update docs/reference/integrations.md Bob entry to document the skills-based default (.bob/skills/), the deprecated --legacy-commands opt-out, and the --skills migration path. Also fix a latent manifest-loss bug surfaced by the migration path: the upgrade Phase 2 stale-file cleanup built a throwaway manifest sharing the integration key and called uninstall(), which always deleted {key}.manifest.json. Any layout-shrinking upgrade (e.g. legacy->skills) thus wiped the freshly-saved manifest, leaving the project untracked and un-upgradeable. uninstall() now takes remove_manifest (default True); the stale-cleanup pass passes False. Adds regression tests for the --skills opt-in, mutual exclusion, corrected active-agent separator, remove_manifest=False, and an end-to-end legacy->skills migration that verifies the manifest survives and the project remains upgradeable. Full suite: 4555 passed, 5 skipped. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * docs(agents): align token-resolution comment with output-layout separator rule (review #3415) Address review #3415 (4725516805). The comment above resolve_command_refs still described the removed state-based behavior ("resolve it from the integration using the project's persisted skills state"). Update it to describe the output-layout rule that register_commands now uses: _sep is derived from the layout this registrar writes (a /SKILL.md scaffold uses the skills separator; a command-layout file uses the command separator), not the persisted ai_skills state. Comment-only change; no behavior change. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): reconcile extension artifacts on layout change (review #3415) When a dual-mode agent (Bob) flips between the legacy commands layout and the skills layout during `integration upgrade` (via `--skills` / `--legacy-commands`), the old layout's extension command/skill files were left orphaned: Phase 2 stale cleanup only removes files tracked by the *integration* manifest, while extension artifacts are tracked in the extension registry. Detect the layout flip by comparing whether the old vs new manifest tracks a `/SKILL.md` scaffold, and when it changed, unregister the agent's extension artifacts before the existing re-registration so they are recreated in the new layout (and the per-agent registry is updated). Preset artifacts are documented as a known, pre-existing cross-cutting gap: no agent-scoped preset re-registration exists in use/switch/upgrade for any agent, so reconciling them is out of scope for this Bob migration. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): reject layout migration when preset overrides are installed (review #3415) A command↔skills layout change during `integration upgrade` cannot reconcile preset artifacts: presets track their command/skill files in per-preset `registered_commands`/`registered_skills` metadata, and there is no agent-scoped preset re-registration anywhere in the CLI. Migrating would delete a preset's old-layout files without recreating them in the new layout and leave the preset registry claiming artifacts that no longer exist. Detect the intended layout via `is_skills_mode` (so a plain same-layout upgrade is unaffected) and, when it flips while preset overrides are installed for the agent, reject the upgrade *before any mutation* with an actionable error pointing at the remove → upgrade → reinstall workaround. Extension artifacts are still reconciled for the safe (no-preset) case. Adds a regression test and documents the migration caveat in the Bob integration reference entry. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): restrict layout reconciliation to the active integration (review #3415) `integration_upgrade` supports upgrading a secondary (non-active) integration, but the layout-change extension reconciliation was unsafe there. `ExtensionManager.unregister_agent_artifacts()` treats the unscoped per-extension `registered_skills` list as belonging to the passed agent and, when that agent's skills directory is absent, falls back to scanning every agent's skills directory — so reconciling a secondary Bob layout flip could delete or untrack the *active* agent's extension skills. The subsequent re-registration cannot repair that because extension skill rendering is intentionally scoped to the active agent (#2948). Gate the unregister-before-register reconciliation on `installed_key == key` so it only runs for the active integration. Secondary agents only ever have extension command files (skills are active-agent-only), which the existing re-registration rewrites in place, so skipping the unregister orphans nothing new. Adds a regression test asserting a secondary Bob layout change leaves the active agent's extension skill intact on disk and in the registry. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): fail closed when preset registry is unreadable (review #3415) Address review 4744636079: - _migrate_commands: the preset guard previously failed *open* — a registry read/parse error returned an empty "no presets" list, so a --force layout-changing upgrade could delete preset-overridden command files while their registry state was unknown. Read the registry file directly and raise _PresetRegistryUnreadableError on any read/parse failure or malformed structure, rejecting the migration before any mutation. A genuinely absent registry still returns [] (safe). - bob: correct the is_skills_mode docstring — upgrade *does* run setup(); disk detection is needed because legacy Bob 1.x installs never persisted a legacy_commands option, so the stored mode is unavailable. - tests: add fail-closed E2E (corrupted registry rejected, valid-empty allowed) plus a unit test for _installed_presets_affecting_agent covering absent / corrupted / malformed / valid / affecting-agent cases. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf * fix(bob): fail closed on malformed preset entries too (review #3415) Address review 4745191015: the preset guard read a parseable registry but silently skipped malformed per-preset metadata and treated a malformed registered_commands value as "no matching artifacts". A registry such as {"presets":{"p1":[]}} therefore allowed a layout migration even though p1's ownership is unknown, risking deletion of preset-managed files. Now raise _PresetRegistryUnreadableError for a non-dict preset entry, a non-dict registered_commands, or a non-list registered_skills. Extend the unit test to cover these malformed shapes. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63f93544-a77f-4f01-bf04-c88806a97dbf --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Manfred Riem <15701806+mnriem@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1910 lines
74 KiB
Python
1910 lines
74 KiB
Python
"""
|
|
Unit tests for extension skill auto-registration.
|
|
|
|
Tests cover:
|
|
- SKILL.md generation when skills mode was used during init
|
|
- No skills created when ai_skills not active
|
|
- SKILL.md content correctness
|
|
- Existing user-modified skills not overwritten
|
|
- Skill cleanup on extension removal
|
|
- Registry metadata includes registered_skills
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import pytest
|
|
import tempfile
|
|
import shutil
|
|
import yaml
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from specify_cli.extensions import (
|
|
ExtensionManifest,
|
|
ExtensionManager,
|
|
)
|
|
|
|
|
|
# ===== Helpers =====
|
|
|
|
def _create_init_options(
|
|
project_root: Path, ai: str = "claude", ai_skills: Any = True
|
|
):
|
|
"""Write a .specify/init-options.json file."""
|
|
opts_dir = project_root / ".specify"
|
|
opts_dir.mkdir(parents=True, exist_ok=True)
|
|
opts_file = opts_dir / "init-options.json"
|
|
opts_file.write_text(json.dumps({
|
|
"ai": ai,
|
|
"ai_skills": ai_skills,
|
|
"script": "sh",
|
|
}), encoding="utf-8")
|
|
|
|
|
|
def _create_skills_dir(project_root: Path, ai: str = "claude") -> Path:
|
|
"""Create and return the expected skills directory for the given agent."""
|
|
# Match the logic in _get_skills_dir() from specify_cli
|
|
from specify_cli import AGENT_CONFIG
|
|
|
|
agent_config = AGENT_CONFIG.get(ai, {})
|
|
agent_folder = agent_config.get("folder", "")
|
|
if agent_folder:
|
|
skills_dir = project_root / agent_folder.rstrip("/") / "skills"
|
|
else:
|
|
skills_dir = project_root / ".agents" / "skills"
|
|
|
|
skills_dir.mkdir(parents=True, exist_ok=True)
|
|
return skills_dir
|
|
|
|
|
|
def _create_extension_dir(temp_dir: Path, ext_id: str = "test-ext") -> Path:
|
|
"""Create a complete extension directory with manifest and command files."""
|
|
ext_dir = temp_dir / ext_id
|
|
ext_dir.mkdir()
|
|
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": ext_id,
|
|
"name": "Test Extension",
|
|
"version": "1.0.0",
|
|
"description": "A test extension for skill registration",
|
|
},
|
|
"requires": {
|
|
"speckit_version": ">=0.1.0",
|
|
},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": f"speckit.{ext_id}.hello",
|
|
"file": "commands/hello.md",
|
|
"description": "Test hello command",
|
|
},
|
|
{
|
|
"name": f"speckit.{ext_id}.world",
|
|
"file": "commands/world.md",
|
|
"description": "Test world command",
|
|
},
|
|
]
|
|
},
|
|
}
|
|
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
commands_dir = ext_dir / "commands"
|
|
commands_dir.mkdir()
|
|
|
|
(commands_dir / "hello.md").write_text(
|
|
"---\n"
|
|
"description: \"Test hello command\"\n"
|
|
"---\n"
|
|
"\n"
|
|
"# Hello Command\n"
|
|
"\n"
|
|
"Run this to say hello.\n"
|
|
"$ARGUMENTS\n"
|
|
)
|
|
|
|
(commands_dir / "world.md").write_text(
|
|
"---\n"
|
|
"description: \"Test world command\"\n"
|
|
"---\n"
|
|
"\n"
|
|
"# World Command\n"
|
|
"\n"
|
|
"Run this to greet the world.\n"
|
|
)
|
|
|
|
return ext_dir
|
|
|
|
|
|
def _create_unicode_extension_dir(temp_dir: Path, ext_id: str = "uni-ext") -> Path:
|
|
"""Create an extension whose command description contains non-ASCII characters."""
|
|
ext_dir = temp_dir / ext_id
|
|
ext_dir.mkdir()
|
|
description = "Prüfe Konformität der Implementierung"
|
|
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": ext_id,
|
|
"name": "Unicode Extension",
|
|
"version": "1.0.0",
|
|
"description": description,
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": f"speckit.{ext_id}.hello",
|
|
"file": "commands/hello.md",
|
|
"description": description,
|
|
},
|
|
]
|
|
},
|
|
}
|
|
|
|
with open(ext_dir / "extension.yml", "w", encoding="utf-8") as f:
|
|
yaml.safe_dump(manifest_data, f, allow_unicode=True)
|
|
|
|
commands_dir = ext_dir / "commands"
|
|
commands_dir.mkdir()
|
|
(commands_dir / "hello.md").write_text(
|
|
"---\n"
|
|
f'description: "{description}"\n'
|
|
"---\n"
|
|
"\n"
|
|
"# Hello\n"
|
|
"\n"
|
|
"Body.\n",
|
|
encoding="utf-8",
|
|
)
|
|
return ext_dir
|
|
|
|
|
|
def _can_create_symlink(temp_dir: Path) -> bool:
|
|
"""Return True when the current platform/user can create file symlinks."""
|
|
target = temp_dir / "symlink-target.txt"
|
|
link = temp_dir / "symlink-link.txt"
|
|
target.write_text("ok", encoding="utf-8")
|
|
try:
|
|
os.symlink(target, link)
|
|
except OSError:
|
|
return False
|
|
return link.is_symlink()
|
|
|
|
|
|
# ===== Fixtures =====
|
|
|
|
@pytest.fixture
|
|
def temp_dir():
|
|
"""Create a temporary directory for tests."""
|
|
tmpdir = tempfile.mkdtemp()
|
|
yield Path(tmpdir)
|
|
shutil.rmtree(tmpdir)
|
|
|
|
|
|
@pytest.fixture
|
|
def project_dir(temp_dir):
|
|
"""Create a mock spec-kit project directory."""
|
|
proj_dir = temp_dir / "project"
|
|
proj_dir.mkdir()
|
|
|
|
# Create .specify directory
|
|
specify_dir = proj_dir / ".specify"
|
|
specify_dir.mkdir()
|
|
|
|
return proj_dir
|
|
|
|
|
|
@pytest.fixture
|
|
def extension_dir(temp_dir):
|
|
"""Create a complete extension directory."""
|
|
return _create_extension_dir(temp_dir)
|
|
|
|
|
|
@pytest.fixture
|
|
def skills_project(project_dir):
|
|
"""Create a project with skills mode enabled and skills directory."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="claude")
|
|
return project_dir, skills_dir
|
|
|
|
|
|
@pytest.fixture
|
|
def no_skills_project(project_dir):
|
|
"""Create a project without skills mode."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=False)
|
|
return project_dir
|
|
|
|
|
|
# ===== ExtensionManager._get_skills_dir Tests =====
|
|
|
|
class TestExtensionManagerGetSkillsDir:
|
|
"""Test _get_skills_dir() on ExtensionManager."""
|
|
|
|
def test_returns_skills_dir_when_active(self, skills_project):
|
|
"""Should return skills dir when ai_skills is true and dir exists."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
result = manager._get_skills_dir()
|
|
assert result == skills_dir
|
|
|
|
def test_returns_none_when_no_ai_skills(self, no_skills_project):
|
|
"""Should return None when ai_skills is false and not create the dir."""
|
|
manager = ExtensionManager(no_skills_project)
|
|
result = manager._get_skills_dir()
|
|
assert result is None
|
|
# Ensure the directory was NOT created on disk
|
|
from specify_cli import _get_skills_dir as resolve_skills_dir
|
|
skills_path = resolve_skills_dir(no_skills_project, "claude")
|
|
assert not skills_path.exists()
|
|
|
|
def test_returns_none_when_no_init_options(self, project_dir):
|
|
"""Should return None when init-options.json is missing and not create any dir."""
|
|
manager = ExtensionManager(project_dir)
|
|
result = manager._get_skills_dir()
|
|
assert result is None
|
|
# No agent skills directory should have been created
|
|
assert not (project_dir / ".claude" / "skills").exists()
|
|
assert not (project_dir / ".agents" / "skills").exists()
|
|
|
|
def test_creates_skills_dir_on_demand(self, project_dir):
|
|
"""Should create skills dir when ai_skills is enabled but dir is missing."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
# Don't create the skills directory — _get_skills_dir should do it
|
|
manager = ExtensionManager(project_dir)
|
|
result = manager._get_skills_dir()
|
|
assert result is not None
|
|
assert result.is_dir()
|
|
|
|
def test_returns_kimi_skills_dir_when_ai_skills_disabled(self, project_dir):
|
|
"""Kimi should still use its native skills dir when ai_skills is false."""
|
|
_create_init_options(project_dir, ai="kimi", ai_skills=False)
|
|
skills_dir = _create_skills_dir(project_dir, ai="kimi")
|
|
manager = ExtensionManager(project_dir)
|
|
result = manager._get_skills_dir()
|
|
assert result == skills_dir
|
|
|
|
def test_returns_none_when_ai_skills_is_non_boolean_truthy(self, project_dir):
|
|
"""Corrupted truthy ai_skills values should not enable skills mode."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills="false")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
result = manager._get_skills_dir()
|
|
assert result is None
|
|
assert not (project_dir / ".claude" / "skills").exists()
|
|
|
|
def test_returns_none_for_non_dict_init_options(self, project_dir):
|
|
"""Corrupted-but-parseable init-options should not crash skill-dir lookup."""
|
|
opts_file = project_dir / ".specify" / "init-options.json"
|
|
opts_file.parent.mkdir(parents=True, exist_ok=True)
|
|
opts_file.write_text("[]", encoding="utf-8")
|
|
_create_skills_dir(project_dir, ai="claude")
|
|
manager = ExtensionManager(project_dir)
|
|
result = manager._get_skills_dir()
|
|
assert result is None
|
|
|
|
|
|
# ===== Extension Skill Registration Tests =====
|
|
|
|
class TestExtensionSkillRegistration:
|
|
"""Test _register_extension_skills() on ExtensionManager."""
|
|
|
|
def test_skills_created_when_ai_skills_active(self, skills_project, extension_dir):
|
|
"""Skills should be created when ai_skills is enabled."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Check that skill directories were created
|
|
skill_dirs = sorted([d.name for d in skills_dir.iterdir() if d.is_dir()])
|
|
assert "speckit-test-ext-hello" in skill_dirs
|
|
assert "speckit-test-ext-world" in skill_dirs
|
|
|
|
def test_skill_md_content_correct(self, skills_project, extension_dir):
|
|
"""SKILL.md should have correct agentskills.io structure."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
assert skill_file.exists()
|
|
content = skill_file.read_text()
|
|
|
|
# Check structure
|
|
assert content.startswith("---\n")
|
|
assert "name: speckit-test-ext-hello" in content
|
|
assert "description:" in content
|
|
assert "Test hello command" in content
|
|
assert "source: extension:test-ext" in content
|
|
assert "author: github-spec-kit" in content
|
|
assert "compatibility:" in content
|
|
assert "Run this to say hello." in content
|
|
|
|
def test_skill_md_has_parseable_yaml(self, skills_project, extension_dir):
|
|
"""Generated SKILL.md should contain valid, parseable YAML frontmatter."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
content = skill_file.read_text()
|
|
|
|
assert content.startswith("---\n")
|
|
parts = content.split("---", 2)
|
|
assert len(parts) >= 3
|
|
parsed = yaml.safe_load(parts[1])
|
|
assert isinstance(parsed, dict)
|
|
assert parsed["name"] == "speckit-test-ext-hello"
|
|
assert "description" in parsed
|
|
assert parsed["disable-model-invocation"] is False
|
|
|
|
def test_argument_hint_preserved_for_extension_command(
|
|
self, skills_project, temp_dir
|
|
):
|
|
"""argument-hint from an extension command must survive into SKILL.md.
|
|
|
|
Regression for #2903: the field was dropped for extension-provided
|
|
commands while being kept for core template commands. The source
|
|
description is intentionally long so it folds across multiple lines
|
|
when serialized, guarding against an in-place string injection that
|
|
would split the folded scalar and produce invalid YAML.
|
|
"""
|
|
project_dir, skills_dir = skills_project
|
|
|
|
long_description = (
|
|
"Build and maintain a lean, static context/ knowledge folder so "
|
|
"coding agents load only what is relevant and save tokens"
|
|
)
|
|
arg_hint = "<init | update | list | check> [area] [slug] [-- notes]"
|
|
|
|
ext_dir = temp_dir / "hint-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "hint-ext",
|
|
"name": "Hint Extension",
|
|
"version": "1.0.0",
|
|
"description": "Extension exercising argument-hint preservation",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.hint-ext.build-context",
|
|
"file": "commands/build-context.md",
|
|
"description": long_description,
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.dump(manifest_data, f)
|
|
commands_dir = ext_dir / "commands"
|
|
commands_dir.mkdir()
|
|
(commands_dir / "build-context.md").write_text(
|
|
"---\n"
|
|
f'description: "{long_description}"\n'
|
|
f'argument-hint: "{arg_hint}"\n'
|
|
"---\n"
|
|
"\n"
|
|
"# Build Context\n"
|
|
"\n"
|
|
"Do the thing.\n"
|
|
"$ARGUMENTS\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
skill_file = skills_dir / "speckit-hint-ext-build-context" / "SKILL.md"
|
|
assert skill_file.exists()
|
|
content = skill_file.read_text(encoding="utf-8")
|
|
|
|
# Frontmatter must parse cleanly even though the description folds.
|
|
parts = content.split("---", 2)
|
|
assert len(parts) >= 3
|
|
parsed = yaml.safe_load(parts[1])
|
|
assert parsed["argument-hint"] == arg_hint
|
|
assert parsed["description"] == long_description
|
|
|
|
def test_argument_hint_not_added_for_non_claude_agent(self, project_dir, temp_dir):
|
|
"""argument-hint must stay Claude-only — other skills agents are untouched.
|
|
|
|
The hint is carried only for integrations that support it (currently
|
|
Claude, the sole integration defining inject_argument_hint). A non-Claude
|
|
skills agent such as kimi must keep the shared build_skill_frontmatter
|
|
shape (name/description/compatibility/metadata) with no argument-hint.
|
|
"""
|
|
_create_init_options(project_dir, ai="kimi", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="kimi")
|
|
|
|
arg_hint = "<init | update | list | check> [area]"
|
|
ext_dir = temp_dir / "hint-ext-kimi"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "hint-ext-kimi",
|
|
"name": "Hint Extension Kimi",
|
|
"version": "1.0.0",
|
|
"description": "Extension exercising argument-hint gating",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.hint-ext-kimi.build-context",
|
|
"file": "commands/build-context.md",
|
|
"description": "Build context",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.dump(manifest_data, f)
|
|
commands_dir = ext_dir / "commands"
|
|
commands_dir.mkdir()
|
|
(commands_dir / "build-context.md").write_text(
|
|
"---\n"
|
|
'description: "Build context"\n'
|
|
f'argument-hint: "{arg_hint}"\n'
|
|
"---\n"
|
|
"\n"
|
|
"# Build Context\n"
|
|
"\n"
|
|
"Do the thing.\n"
|
|
"$ARGUMENTS\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
skill_file = skills_dir / "speckit-hint-ext-kimi-build-context" / "SKILL.md"
|
|
assert skill_file.exists()
|
|
parsed = yaml.safe_load(skill_file.read_text(encoding="utf-8").split("---", 2)[1])
|
|
assert "argument-hint" not in parsed
|
|
|
|
def test_skill_md_unicode(self, skills_project, temp_dir):
|
|
"""SKILL.md generation should preserve non-ASCII characters."""
|
|
project_dir, skills_dir = skills_project
|
|
ext_dir = _create_unicode_extension_dir(temp_dir)
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
skill_file = skills_dir / "speckit-uni-ext-hello" / "SKILL.md"
|
|
content = skill_file.read_text(encoding="utf-8")
|
|
|
|
assert "Prüfe Konformität" in content
|
|
|
|
def test_no_skills_when_ai_skills_disabled(self, no_skills_project, extension_dir):
|
|
"""No skills should be created when ai_skills is false."""
|
|
manager = ExtensionManager(no_skills_project)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Verify registry
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_no_skills_when_init_options_missing(self, project_dir, extension_dir):
|
|
"""No skills should be created when init-options.json is absent."""
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_existing_skill_not_overwritten(self, skills_project, extension_dir):
|
|
"""Pre-existing SKILL.md should not be overwritten."""
|
|
project_dir, skills_dir = skills_project
|
|
|
|
# Pre-create a custom skill
|
|
custom_dir = skills_dir / "speckit-test-ext-hello"
|
|
custom_dir.mkdir(parents=True)
|
|
custom_content = "# My Custom Hello Skill\nUser-modified content\n"
|
|
(custom_dir / "SKILL.md").write_text(custom_content)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Custom skill should be untouched
|
|
assert (custom_dir / "SKILL.md").read_text() == custom_content
|
|
|
|
# But the other skill should still be created
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert "speckit-test-ext-world" in metadata["registered_skills"]
|
|
# The pre-existing one should NOT be in registered_skills (it was skipped)
|
|
assert "speckit-test-ext-hello" not in metadata["registered_skills"]
|
|
|
|
def test_dev_skill_symlink_refreshes_existing_cache(
|
|
self, skills_project, extension_dir, temp_dir
|
|
):
|
|
"""Dev-mode skill symlinks should refresh rendered cache content."""
|
|
if not _can_create_symlink(temp_dir):
|
|
pytest.skip("Current platform/user cannot create symlinks")
|
|
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = ExtensionManifest(extension_dir / "extension.yml")
|
|
|
|
manager._register_extension_skills(
|
|
manifest,
|
|
extension_dir,
|
|
link_outputs=True,
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
assert skill_file.is_symlink()
|
|
assert "Run this to say hello." in skill_file.read_text(encoding="utf-8")
|
|
|
|
(extension_dir / "commands" / "hello.md").write_text(
|
|
"---\n"
|
|
"description: \"Updated test hello command\"\n"
|
|
"---\n"
|
|
"\n"
|
|
"# Hello Command\n"
|
|
"\n"
|
|
"Run this updated hello.\n"
|
|
)
|
|
|
|
written = manager._register_extension_skills(
|
|
manifest,
|
|
extension_dir,
|
|
link_outputs=True,
|
|
)
|
|
|
|
assert "speckit-test-ext-hello" in written
|
|
assert "Run this updated hello." in skill_file.read_text(encoding="utf-8")
|
|
|
|
def test_codex_dev_skill_registration_replaces_existing_dev_symlink(
|
|
self, project_dir, extension_dir, temp_dir
|
|
):
|
|
"""Codex dev skill registration should migrate prior dev symlinks to files."""
|
|
if not _can_create_symlink(temp_dir):
|
|
pytest.skip("Current platform/user cannot create symlinks")
|
|
|
|
_create_init_options(project_dir, ai="codex", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="codex")
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = ExtensionManifest(extension_dir / "extension.yml")
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
skill_file.parent.mkdir(parents=True, exist_ok=True)
|
|
cache_file = (
|
|
extension_dir
|
|
/ ".specify-dev"
|
|
/ "extension-skills"
|
|
/ "speckit-test-ext-hello"
|
|
/ "SKILL.md"
|
|
)
|
|
cache_file.parent.mkdir(parents=True)
|
|
cache_file.write_text("old linked content", encoding="utf-8")
|
|
os.symlink(os.path.relpath(cache_file, skill_file.parent), skill_file)
|
|
|
|
written = manager._register_extension_skills(
|
|
manifest,
|
|
extension_dir,
|
|
link_outputs=True,
|
|
)
|
|
|
|
assert "speckit-test-ext-hello" in written
|
|
assert skill_file.exists()
|
|
assert not skill_file.is_symlink()
|
|
assert "Run this to say hello." in skill_file.read_text(encoding="utf-8")
|
|
assert cache_file.read_text(encoding="utf-8") == "old linked content"
|
|
|
|
def test_codex_dev_skill_registration_preserves_unrelated_symlink(
|
|
self, project_dir, extension_dir, temp_dir
|
|
):
|
|
"""Codex dev registration should not overwrite user-owned symlinks."""
|
|
if not _can_create_symlink(temp_dir):
|
|
pytest.skip("Current platform/user cannot create symlinks")
|
|
|
|
_create_init_options(project_dir, ai="codex", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="codex")
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = ExtensionManifest(extension_dir / "extension.yml")
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
skill_file.parent.mkdir(parents=True, exist_ok=True)
|
|
unrelated_cache_file = (
|
|
temp_dir
|
|
/ "other-extension"
|
|
/ ".specify-dev"
|
|
/ "extension-skills"
|
|
/ "speckit-test-ext-hello"
|
|
/ "SKILL.md"
|
|
)
|
|
unrelated_cache_file.parent.mkdir(parents=True)
|
|
unrelated_cache_file.write_text("user-owned linked content", encoding="utf-8")
|
|
os.symlink(
|
|
os.path.relpath(unrelated_cache_file, skill_file.parent), skill_file
|
|
)
|
|
|
|
written = manager._register_extension_skills(
|
|
manifest,
|
|
extension_dir,
|
|
link_outputs=True,
|
|
)
|
|
|
|
assert "speckit-test-ext-hello" not in written
|
|
assert skill_file.is_symlink()
|
|
assert skill_file.resolve(strict=True) == unrelated_cache_file.resolve()
|
|
assert unrelated_cache_file.read_text(encoding="utf-8") == (
|
|
"user-owned linked content"
|
|
)
|
|
|
|
def test_dev_skill_registration_falls_back_to_copy_when_symlink_fails(
|
|
self, skills_project, extension_dir, monkeypatch
|
|
):
|
|
"""Dev-mode skill registration works when Windows cannot create symlinks."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = ExtensionManifest(extension_dir / "extension.yml")
|
|
|
|
def raise_windows_symlink_error(target, link):
|
|
raise OSError("A required privilege is not held by the client")
|
|
|
|
monkeypatch.setattr(
|
|
"specify_cli.extensions.os.symlink", raise_windows_symlink_error
|
|
)
|
|
|
|
written = manager._register_extension_skills(
|
|
manifest,
|
|
extension_dir,
|
|
link_outputs=True,
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
assert "speckit-test-ext-hello" in written
|
|
assert skill_file.exists()
|
|
assert not skill_file.is_symlink()
|
|
assert "Run this to say hello." in skill_file.read_text(encoding="utf-8")
|
|
assert (
|
|
extension_dir
|
|
/ ".specify-dev"
|
|
/ "extension-skills"
|
|
/ "speckit-test-ext-hello"
|
|
/ "SKILL.md"
|
|
).exists()
|
|
|
|
def test_dev_skill_registration_falls_back_to_copy_when_relpath_fails(
|
|
self, skills_project, extension_dir, monkeypatch
|
|
):
|
|
"""Dev-mode skill registration stays functional across Windows drive roots."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = ExtensionManifest(extension_dir / "extension.yml")
|
|
|
|
def raise_relpath_error(path, start=None):
|
|
raise ValueError("path is on mount 'D:', start on mount 'C:'")
|
|
|
|
monkeypatch.setattr(
|
|
"specify_cli.extensions.os.path.relpath", raise_relpath_error
|
|
)
|
|
|
|
written = manager._register_extension_skills(
|
|
manifest,
|
|
extension_dir,
|
|
link_outputs=True,
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
assert "speckit-test-ext-hello" in written
|
|
assert skill_file.exists()
|
|
assert not skill_file.is_symlink()
|
|
assert "Run this to say hello." in skill_file.read_text(encoding="utf-8")
|
|
assert (
|
|
extension_dir
|
|
/ ".specify-dev"
|
|
/ "extension-skills"
|
|
/ "speckit-test-ext-hello"
|
|
/ "SKILL.md"
|
|
).exists()
|
|
|
|
def test_dev_skill_registration_falls_back_to_copy_when_cache_write_fails(
|
|
self, skills_project, extension_dir, monkeypatch
|
|
):
|
|
"""Dev-mode skill registration stays functional when the dev cache is unwritable."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = ExtensionManifest(extension_dir / "extension.yml")
|
|
original_write_text = Path.write_text
|
|
|
|
def raise_cache_write_error(path, *args, **kwargs):
|
|
if ".specify-dev" in path.parts:
|
|
raise OSError("cache is not writable")
|
|
return original_write_text(path, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(Path, "write_text", raise_cache_write_error)
|
|
|
|
written = manager._register_extension_skills(
|
|
manifest,
|
|
extension_dir,
|
|
link_outputs=True,
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-test-ext-hello" / "SKILL.md"
|
|
assert "speckit-test-ext-hello" in written
|
|
assert skill_file.exists()
|
|
assert not skill_file.is_symlink()
|
|
assert "Run this to say hello." in skill_file.read_text(encoding="utf-8")
|
|
assert not (
|
|
extension_dir
|
|
/ ".specify-dev"
|
|
/ "extension-skills"
|
|
/ "speckit-test-ext-hello"
|
|
/ "SKILL.md"
|
|
).exists()
|
|
|
|
def test_registered_skills_in_registry(self, skills_project, extension_dir):
|
|
"""Registry should contain registered_skills list."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert "registered_skills" in metadata
|
|
assert len(metadata["registered_skills"]) == 2
|
|
assert "speckit-test-ext-hello" in metadata["registered_skills"]
|
|
assert "speckit-test-ext-world" in metadata["registered_skills"]
|
|
|
|
def test_kimi_uses_hyphenated_skill_names(self, project_dir, temp_dir):
|
|
"""Kimi agent should use the same hyphenated skill names as hooks."""
|
|
_create_init_options(project_dir, ai="kimi", ai_skills=True)
|
|
_create_skills_dir(project_dir, ai="kimi")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="test-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert "speckit-test-ext-hello" in metadata["registered_skills"]
|
|
assert "speckit-test-ext-world" in metadata["registered_skills"]
|
|
|
|
def test_kimi_creates_skills_when_ai_skills_disabled(self, project_dir, temp_dir):
|
|
"""Kimi should still auto-register extension skills in native-skills mode."""
|
|
_create_init_options(project_dir, ai="kimi", ai_skills=False)
|
|
skills_dir = _create_skills_dir(project_dir, ai="kimi")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="test-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert "speckit-test-ext-hello" in metadata["registered_skills"]
|
|
assert "speckit-test-ext-world" in metadata["registered_skills"]
|
|
assert (skills_dir / "speckit-test-ext-hello" / "SKILL.md").exists()
|
|
|
|
def test_skill_registration_resolves_script_placeholders(self, project_dir, temp_dir):
|
|
"""Auto-registered extension skills should resolve script placeholders."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="claude")
|
|
|
|
ext_dir = temp_dir / "scripted-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "scripted-ext",
|
|
"name": "Scripted Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.scripted-ext.plan",
|
|
"file": "commands/plan.md",
|
|
"description": "Scripted plan command",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
(ext_dir / "commands" / "plan.md").write_text(
|
|
"---\n"
|
|
"description: Scripted plan command\n"
|
|
"scripts:\n"
|
|
" sh: ../../scripts/bash/setup-plan.sh --json \"{ARGS}\"\n"
|
|
"---\n\n"
|
|
"Run {SCRIPT}\n"
|
|
"Review templates/checklist.md and memory/constitution.md for __AGENT__.\n"
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
content = (skills_dir / "speckit-scripted-ext-plan" / "SKILL.md").read_text()
|
|
assert "{SCRIPT}" not in content
|
|
assert "{ARGS}" not in content
|
|
assert "__AGENT__" not in content
|
|
assert '.specify/scripts/bash/setup-plan.sh --json "$ARGUMENTS"' in content
|
|
assert ".specify/templates/checklist.md" in content
|
|
assert ".specify/memory/constitution.md" in content
|
|
|
|
def test_skill_registration_uses_extension_local_script_paths(self, project_dir, temp_dir):
|
|
"""Auto-registered skills should not rewrite extension scripts into core scripts."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="claude")
|
|
|
|
ext_dir = temp_dir / "scripted-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "scripted-ext",
|
|
"name": "Scripted Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.scripted-ext.check",
|
|
"file": "commands/check.md",
|
|
"description": "Scripted check command",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
(ext_dir / "scripts" / "bash").mkdir(parents=True)
|
|
(ext_dir / "scripts" / "bash" / "resolve-skill.sh").write_text(
|
|
"#!/usr/bin/env bash\n"
|
|
)
|
|
(ext_dir / "scripts" / "bash" / "ensure-skills.sh").write_text(
|
|
"#!/usr/bin/env bash\n"
|
|
)
|
|
(ext_dir / "commands" / "check.md").write_text(
|
|
"---\n"
|
|
"description: Scripted check command\n"
|
|
"scripts:\n"
|
|
' sh: scripts/bash/resolve-skill.sh "{ARGS}"\n'
|
|
"---\n\n"
|
|
"Run {SCRIPT}\n"
|
|
"Then run scripts/bash/ensure-skills.sh.\n"
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
content = (skills_dir / "speckit-scripted-ext-check" / "SKILL.md").read_text()
|
|
assert "{SCRIPT}" not in content
|
|
assert "{ARGS}" not in content
|
|
assert (
|
|
'.specify/extensions/scripted-ext/scripts/bash/resolve-skill.sh "$ARGUMENTS"'
|
|
in content
|
|
)
|
|
assert ".specify/extensions/scripted-ext/scripts/bash/ensure-skills.sh" in content
|
|
assert ".specify/scripts/bash/resolve-skill.sh" not in content
|
|
assert ".specify/scripts/bash/ensure-skills.sh" not in content
|
|
|
|
def test_skill_registration_rewrites_extension_subdir_paths(self, project_dir, temp_dir):
|
|
"""Auto-registered skills should resolve extension-relative subdir
|
|
references (agents/, knowledge-base/) to their installed location,
|
|
matching the rewrite already applied by register_commands() (#2101)."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="claude")
|
|
|
|
ext_dir = temp_dir / "path-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "path-ext",
|
|
"name": "Path Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.path-ext.run",
|
|
"file": "commands/run.md",
|
|
"description": "Run command",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
(ext_dir / "agents" / "control").mkdir(parents=True)
|
|
(ext_dir / "agents" / "control" / "commander.md").write_text("# Commander\n")
|
|
(ext_dir / "knowledge-base").mkdir()
|
|
(ext_dir / "knowledge-base" / "agent-scores.yaml").write_text("scores: {}\n")
|
|
(ext_dir / "templates").mkdir()
|
|
(ext_dir / "templates" / "kill-report.md").write_text("# Kill Report\n")
|
|
|
|
(ext_dir / "commands" / "run.md").write_text(
|
|
"---\n"
|
|
"description: Run command\n"
|
|
"---\n\n"
|
|
"Read agents/control/commander.md and knowledge-base/agent-scores.yaml.\n"
|
|
"Use templates/kill-report.md as the report template.\n"
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
content = (skills_dir / "speckit-path-ext-run" / "SKILL.md").read_text()
|
|
assert ".specify/extensions/path-ext/agents/control/commander.md" in content
|
|
assert ".specify/extensions/path-ext/knowledge-base/agent-scores.yaml" in content
|
|
# extension's own templates/ dir must resolve under the extension,
|
|
# not the project-level .specify/templates/
|
|
assert ".specify/extensions/path-ext/templates/kill-report.md" in content
|
|
assert "Read agents/control" not in content
|
|
assert "and knowledge-base/" not in content
|
|
|
|
@pytest.mark.parametrize(
|
|
("ai", "expected_invocation"),
|
|
[
|
|
("claude", "/speckit-plan"),
|
|
("copilot", "/speckit-plan"),
|
|
("codex", "$speckit-plan"),
|
|
("kimi", "/skill:speckit-plan"),
|
|
("zcode", "$speckit-plan"),
|
|
("bob", "/speckit-plan"),
|
|
],
|
|
)
|
|
def test_skill_registration_resolves_command_ref_tokens(
|
|
self, project_dir, temp_dir, ai, expected_invocation
|
|
):
|
|
"""Auto-registered skills should resolve explicit command ref tokens."""
|
|
_create_init_options(project_dir, ai=ai, ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai=ai)
|
|
|
|
ext_dir = temp_dir / "command-ref-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "command-ref-ext",
|
|
"name": "Command Ref Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.command-ref-ext.run",
|
|
"file": "commands/run.md",
|
|
"description": "Run command",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
(ext_dir / "commands" / "run.md").write_text(
|
|
"---\n"
|
|
"description: Run command\n"
|
|
"---\n\n"
|
|
"Use __SPECKIT_COMMAND_PLAN__ before proceeding.\n"
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
content = (skills_dir / "speckit-command-ref-ext-run" / "SKILL.md").read_text()
|
|
assert "__SPECKIT_COMMAND_PLAN__" not in content
|
|
assert expected_invocation in content
|
|
|
|
def test_skill_registration_does_not_rewrite_literal_speckit_text(
|
|
self, project_dir, temp_dir
|
|
):
|
|
"""Auto-registered skills should leave literal speckit text untouched."""
|
|
_create_init_options(project_dir, ai="codex", ai_skills=True)
|
|
skills_dir = _create_skills_dir(project_dir, ai="codex")
|
|
|
|
ext_dir = temp_dir / "literal-ref-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "literal-ref-ext",
|
|
"name": "Literal Ref Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.literal-ref-ext.run",
|
|
"file": "commands/run.md",
|
|
"description": "Run command",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
(ext_dir / "commands" / "run.md").write_text(
|
|
"---\n"
|
|
"description: Run command\n"
|
|
"---\n\n"
|
|
"Literal slash form: /speckit.foo.bar\n"
|
|
"Literal skill form: /speckit-plan\n"
|
|
"Literal bare form: speckit.foo.bar\n"
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(ext_dir, "0.1.0", register_commands=False)
|
|
|
|
content = (skills_dir / "speckit-literal-ref-ext-run" / "SKILL.md").read_text()
|
|
assert "/speckit.foo.bar" in content
|
|
assert "/speckit-plan" in content
|
|
assert "speckit.foo.bar" in content
|
|
assert "/speckit-foo-bar" not in content
|
|
assert "$speckit-plan" not in content
|
|
|
|
def test_missing_command_file_skipped(self, skills_project, temp_dir):
|
|
"""Commands with missing source files should be skipped gracefully."""
|
|
project_dir, skills_dir = skills_project
|
|
|
|
ext_dir = temp_dir / "missing-cmd-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "missing-cmd-ext",
|
|
"name": "Missing Cmd Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.missing-cmd-ext.exists",
|
|
"file": "commands/exists.md",
|
|
"description": "Exists",
|
|
},
|
|
{
|
|
"name": "speckit.missing-cmd-ext.ghost",
|
|
"file": "commands/ghost.md",
|
|
"description": "Does not exist",
|
|
},
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
(ext_dir / "commands" / "exists.md").write_text(
|
|
"---\ndescription: Exists\n---\n\n# Exists\n\nBody.\n"
|
|
)
|
|
# Intentionally do NOT create ghost.md
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert "speckit-missing-cmd-ext-exists" in metadata["registered_skills"]
|
|
assert "speckit-missing-cmd-ext-ghost" not in metadata["registered_skills"]
|
|
|
|
@pytest.mark.parametrize("ai", ["claude", "codex"])
|
|
def test_skills_registered_when_dir_missing(self, project_dir, temp_dir, ai):
|
|
"""Extension add should create skills dir on demand and register skills.
|
|
|
|
Regression test for https://github.com/github/spec-kit/issues/2682:
|
|
when an extension is installed before the agent skills directory exists,
|
|
skills must still be materialized (the directory is created on demand).
|
|
"""
|
|
_create_init_options(project_dir, ai=ai, ai_skills=True)
|
|
# Deliberately do NOT create the skills directory
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Skills dir should have been created automatically
|
|
from specify_cli import _get_skills_dir as resolve_skills_dir
|
|
skills_dir = resolve_skills_dir(project_dir, ai)
|
|
assert skills_dir.is_dir()
|
|
|
|
# SKILL.md files should exist
|
|
assert (skills_dir / "speckit-early-ext-hello" / "SKILL.md").exists()
|
|
assert (skills_dir / "speckit-early-ext-world" / "SKILL.md").exists()
|
|
|
|
# Registry should record them
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert len(metadata["registered_skills"]) == 2
|
|
assert "speckit-early-ext-hello" in metadata["registered_skills"]
|
|
assert "speckit-early-ext-world" in metadata["registered_skills"]
|
|
|
|
def test_commands_registered_when_claude_skills_dir_missing(self, project_dir, temp_dir):
|
|
"""Extension install should not silently skip Claude when skills dir is missing."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
(project_dir / ".claude").mkdir()
|
|
# Deliberately do NOT create .claude/skills
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
skills_dir = project_dir / ".claude" / "skills"
|
|
assert skills_dir.is_dir()
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_commands"] == {
|
|
"claude": [
|
|
"speckit.early-ext.hello",
|
|
"speckit.early-ext.world",
|
|
]
|
|
}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
skill_file = skills_dir / "speckit-early-ext-hello" / "SKILL.md"
|
|
assert skill_file.exists()
|
|
content = skill_file.read_text(encoding="utf-8")
|
|
assert "source: early-ext:commands/hello.md" in content
|
|
|
|
def test_hermes_global_skills_dir_used_when_marker_is_recovered(
|
|
self, project_dir, temp_dir, monkeypatch
|
|
):
|
|
"""Hermes recovery must not use the project marker as the output dir."""
|
|
home = temp_dir / "home"
|
|
home.mkdir()
|
|
monkeypatch.setattr(Path, "home", lambda: home)
|
|
_create_init_options(project_dir, ai="hermes", ai_skills=True)
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {
|
|
"hermes": [
|
|
"speckit.early-ext.hello",
|
|
"speckit.early-ext.world",
|
|
]
|
|
}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
global_skills_dir = home / ".hermes" / "skills"
|
|
assert (
|
|
global_skills_dir / "speckit-early-ext-hello" / "SKILL.md"
|
|
).exists()
|
|
assert (
|
|
global_skills_dir / "speckit-early-ext-world" / "SKILL.md"
|
|
).exists()
|
|
|
|
marker = project_dir / ".hermes" / "skills"
|
|
assert marker.is_dir()
|
|
assert list(marker.glob("speckit-*/SKILL.md")) == []
|
|
|
|
def test_hermes_get_skills_dir_creates_global_output_dir(
|
|
self, project_dir, temp_dir, monkeypatch
|
|
):
|
|
"""ExtensionManager should create the agent-specific output dir it returns."""
|
|
home = temp_dir / "home"
|
|
home.mkdir()
|
|
monkeypatch.setattr(Path, "home", lambda: home)
|
|
_create_init_options(project_dir, ai="hermes", ai_skills=True)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
skills_dir = manager._get_skills_dir()
|
|
|
|
assert skills_dir == home / ".hermes" / "skills"
|
|
assert skills_dir.is_dir()
|
|
assert (project_dir / ".hermes" / "skills").is_dir()
|
|
|
|
def test_unusable_hermes_global_skills_dir_skips_skill_registration(
|
|
self, project_dir, temp_dir, monkeypatch, capsys
|
|
):
|
|
"""An unusable agent-specific output dir should warn and skip skills."""
|
|
home = temp_dir / "home"
|
|
hermes_dir = home / ".hermes"
|
|
hermes_dir.mkdir(parents=True)
|
|
(hermes_dir / "skills").write_text("not a directory", encoding="utf-8")
|
|
monkeypatch.setattr(Path, "home", lambda: home)
|
|
_create_init_options(project_dir, ai="hermes", ai_skills=True)
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="blocked-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_skills"] == []
|
|
captured = capsys.readouterr()
|
|
assert "Warning:" in captured.out
|
|
assert "Continuing without skill registration." in captured.out
|
|
|
|
def test_detect_dir_marker_file_does_not_register_hermes_commands(
|
|
self, project_dir, temp_dir, monkeypatch
|
|
):
|
|
"""Regular files at detect_dir marker paths should not detect agents."""
|
|
home = temp_dir / "home"
|
|
global_skills_dir = home / ".hermes" / "skills"
|
|
global_skills_dir.mkdir(parents=True)
|
|
monkeypatch.setattr(Path, "home", lambda: home)
|
|
_create_init_options(project_dir, ai="hermes", ai_skills=True)
|
|
marker_parent = project_dir / ".hermes"
|
|
marker_parent.mkdir()
|
|
marker_file = marker_parent / "skills"
|
|
marker_file.write_text("not a directory", encoding="utf-8")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
assert marker_file.is_file()
|
|
assert marker_file.read_text(encoding="utf-8") == "not a directory"
|
|
assert not (
|
|
global_skills_dir / "speckit-early-ext-hello" / "SKILL.md"
|
|
).exists()
|
|
assert not (
|
|
global_skills_dir / "speckit-early-ext-world" / "SKILL.md"
|
|
).exists()
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_non_boolean_ai_skills_does_not_recover_missing_skills_dir(
|
|
self, project_dir, temp_dir
|
|
):
|
|
"""Corrupted truthy ai_skills values should not recover skills dirs."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills="false")
|
|
(project_dir / ".claude").mkdir()
|
|
# Deliberately do NOT create .claude/skills.
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {}
|
|
assert metadata["registered_skills"] == []
|
|
assert not (project_dir / ".claude" / "skills").exists()
|
|
|
|
def test_non_boolean_ai_skills_does_not_skip_default_agent_reregistration(
|
|
self, project_dir, temp_dir
|
|
):
|
|
"""Corrupted ai_skills values should not trigger skills-mode skips."""
|
|
_create_init_options(project_dir, ai="copilot", ai_skills="false")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
manager.register_enabled_extensions_for_agent("copilot")
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {
|
|
"copilot": [
|
|
"speckit.early-ext.hello",
|
|
"speckit.early-ext.world",
|
|
]
|
|
}
|
|
assert metadata["registered_skills"] == []
|
|
assert (project_dir / ".github" / "agents").is_dir()
|
|
|
|
def test_one_failing_extension_does_not_abort_the_rest(
|
|
self, project_dir, temp_dir, monkeypatch
|
|
):
|
|
"""A single failing extension must not block registration of the others.
|
|
|
|
Regression for #2950: ``register_enabled_extensions_for_agent`` iterates
|
|
enabled extensions; before the per-extension isolation, the first one
|
|
that raised (e.g. an OSError writing a command file) aborted the loop and
|
|
the exception propagated, so every later extension was silently skipped.
|
|
"""
|
|
from specify_cli.extensions import CommandRegistrar
|
|
|
|
_create_init_options(project_dir, ai="claude", ai_skills=False)
|
|
manager = ExtensionManager(project_dir)
|
|
# Two enabled extensions; the first one iterated ("aaa-fail") will raise.
|
|
manager.install_from_directory(
|
|
_create_extension_dir(temp_dir, ext_id="aaa-fail"), "0.1.0",
|
|
register_commands=False,
|
|
)
|
|
manager.install_from_directory(
|
|
_create_extension_dir(temp_dir, ext_id="bbb-ok"), "0.1.0",
|
|
register_commands=False,
|
|
)
|
|
|
|
original = CommandRegistrar.register_commands_for_agent
|
|
|
|
def flaky(self, agent_name, manifest, ext_dir, project_root, link_outputs=False):
|
|
if manifest.id == "aaa-fail":
|
|
raise OSError("simulated command-file write failure")
|
|
return original(
|
|
self, agent_name, manifest, ext_dir, project_root,
|
|
link_outputs=link_outputs,
|
|
)
|
|
|
|
monkeypatch.setattr(CommandRegistrar, "register_commands_for_agent", flaky)
|
|
|
|
# Must not propagate, despite the first extension failing.
|
|
manager.register_enabled_extensions_for_agent("claude")
|
|
|
|
# The healthy extension was still registered for the agent...
|
|
ok_meta = manager.registry.get("bbb-ok")
|
|
assert "claude" in ok_meta["registered_commands"], (
|
|
"a later extension must still register after an earlier one fails (#2950)"
|
|
)
|
|
# ...and the failing one was not.
|
|
fail_meta = manager.registry.get("aaa-fail")
|
|
assert "claude" not in fail_meta.get("registered_commands", {})
|
|
|
|
def test_skill_registration_failure_preserves_registered_commands(
|
|
self, project_dir, temp_dir, monkeypatch, capsys
|
|
):
|
|
"""Persist successful command registration even if skills fail.
|
|
|
|
If command files are written but skill generation raises, the command
|
|
registry must still be updated so later unregister/cleanup can find the
|
|
command files.
|
|
"""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=False)
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(
|
|
_create_extension_dir(temp_dir, ext_id="skill-fail"), "0.1.0",
|
|
register_commands=False,
|
|
)
|
|
|
|
def fail_skills(self, manifest, ext_dir, link_outputs=False):
|
|
raise OSError("simulated skill directory failure")
|
|
|
|
monkeypatch.setattr(
|
|
ExtensionManager, "_register_extension_skills", fail_skills
|
|
)
|
|
|
|
manager.register_enabled_extensions_for_agent("claude")
|
|
|
|
metadata = manager.registry.get("skill-fail")
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {
|
|
"claude": [
|
|
"speckit.skill-fail.hello",
|
|
"speckit.skill-fail.world",
|
|
]
|
|
}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
captured = capsys.readouterr()
|
|
assert "register extension skills for extension 'skill-fail'" in captured.out
|
|
assert "Continuing with available registration results" in captured.out
|
|
|
|
def test_existing_agent_command_path_file_is_not_detected(
|
|
self, project_dir, temp_dir
|
|
):
|
|
"""Existing files at command-dir paths should not count as detected agents."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=False)
|
|
claude_dir = project_dir / ".claude"
|
|
claude_dir.mkdir()
|
|
skills_file = claude_dir / "skills"
|
|
skills_file.write_text("not a directory", encoding="utf-8")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
assert skills_file.read_text(encoding="utf-8") == "not a directory"
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_missing_shared_skills_dir_registers_only_active_agent(self, project_dir, temp_dir):
|
|
"""Recreating shared skills dirs should not activate unrelated agents."""
|
|
_create_init_options(project_dir, ai="agy", ai_skills=True)
|
|
(project_dir / ".agents").mkdir()
|
|
# Deliberately do NOT create .agents/skills, shared by agy and codex.
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
skills_dir = project_dir / ".agents" / "skills"
|
|
assert skills_dir.is_dir()
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_commands"] == {
|
|
"agy": [
|
|
"speckit.early-ext.hello",
|
|
"speckit.early-ext.world",
|
|
]
|
|
}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_missing_shared_skills_dir_uses_normalized_guard_for_later_agents(
|
|
self, project_dir, temp_dir, monkeypatch
|
|
):
|
|
"""Shared-dir suppression should tolerate lexical path differences."""
|
|
_create_init_options(project_dir, ai="agy", ai_skills=True)
|
|
(project_dir / ".agents").mkdir()
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
from specify_cli.agents import CommandRegistrar as AgentRegistrar
|
|
|
|
original_resolve_agent_dir = AgentRegistrar._resolve_agent_dir
|
|
original_register_commands = AgentRegistrar.register_commands
|
|
attempted_agents = []
|
|
|
|
def resolve_codex_with_parent_segment(self, agent_name, agent_config, root):
|
|
if agent_name == "codex":
|
|
return root / ".agents" / ".." / ".agents" / "skills"
|
|
return original_resolve_agent_dir(agent_name, agent_config, root)
|
|
|
|
def record_registration(self, agent_name, *args, **kwargs):
|
|
attempted_agents.append(agent_name)
|
|
return original_register_commands(self, agent_name, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(
|
|
AgentRegistrar, "_resolve_agent_dir", resolve_codex_with_parent_segment
|
|
)
|
|
monkeypatch.setattr(AgentRegistrar, "register_commands", record_registration)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
assert attempted_agents == ["agy"]
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {
|
|
"agy": [
|
|
"speckit.early-ext.hello",
|
|
"speckit.early-ext.world",
|
|
]
|
|
}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_missing_shared_skills_dir_write_oserror_does_not_register_other_agents(
|
|
self, project_dir, temp_dir, monkeypatch
|
|
):
|
|
"""Failed active registration must not make shared skills dirs detected."""
|
|
_create_init_options(project_dir, ai="agy", ai_skills=True)
|
|
(project_dir / ".agents").mkdir()
|
|
# Deliberately do NOT create .agents/skills, shared by agy and codex.
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
from specify_cli.agents import CommandRegistrar as AgentRegistrar
|
|
|
|
original_register_commands = AgentRegistrar.register_commands
|
|
attempted_agents = []
|
|
|
|
def fail_recovered_agy_registration(self, agent_name, *args, **kwargs):
|
|
attempted_agents.append(agent_name)
|
|
if agent_name == "agy":
|
|
raise PermissionError("denied")
|
|
return original_register_commands(self, agent_name, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(
|
|
AgentRegistrar, "register_commands", fail_recovered_agy_registration
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
skills_dir = project_dir / ".agents" / "skills"
|
|
assert skills_dir.is_dir()
|
|
assert attempted_agents == ["agy"]
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata is not None
|
|
assert metadata["registered_commands"] == {}
|
|
assert "speckit-early-ext-hello" in metadata["registered_skills"]
|
|
assert "speckit-early-ext-world" in metadata["registered_skills"]
|
|
|
|
def test_missing_active_skills_dir_does_not_follow_symlinked_parent(
|
|
self, project_dir, temp_dir
|
|
):
|
|
"""Recovered command registration must reuse active skills-dir safety checks."""
|
|
if not hasattr(os, "symlink"):
|
|
pytest.skip("symlinks are unavailable")
|
|
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
outside = temp_dir / "outside-claude"
|
|
outside.mkdir()
|
|
try:
|
|
os.symlink(outside, project_dir / ".claude", target_is_directory=True)
|
|
except OSError:
|
|
pytest.skip("Current platform/user cannot create directory symlinks")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_commands"] == {}
|
|
assert metadata["registered_skills"] == []
|
|
assert not (outside / "skills").exists()
|
|
|
|
def test_missing_active_skills_dir_invalid_parent_skips_without_aborting(
|
|
self, project_dir, temp_dir
|
|
):
|
|
"""Invalid active skill parents should not abort extension installation."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
(project_dir / ".claude").write_text("not a directory", encoding="utf-8")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_commands"] == {}
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_missing_active_skills_dir_write_oserror_skips_without_aborting(
|
|
self, project_dir, temp_dir, monkeypatch
|
|
):
|
|
"""Filesystem failures in recovered command registration should skip safely."""
|
|
_create_init_options(project_dir, ai="claude", ai_skills=True)
|
|
(project_dir / ".claude").mkdir()
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="early-ext")
|
|
|
|
from specify_cli.agents import CommandRegistrar as AgentRegistrar
|
|
|
|
original_register_commands = AgentRegistrar.register_commands
|
|
|
|
def fail_recovered_claude_registration(self, agent_name, *args, **kwargs):
|
|
if agent_name == "claude":
|
|
raise PermissionError("denied")
|
|
return original_register_commands(self, agent_name, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(
|
|
AgentRegistrar, "register_commands", fail_recovered_claude_registration
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=True
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_commands"] == {}
|
|
assert "speckit-early-ext-hello" in metadata["registered_skills"]
|
|
assert "speckit-early-ext-world" in metadata["registered_skills"]
|
|
|
|
|
|
# ===== Extension Skill Unregistration Tests =====
|
|
|
|
class TestExtensionSkillUnregistration:
|
|
"""Test _unregister_extension_skills() on ExtensionManager."""
|
|
|
|
def test_skills_removed_on_extension_remove(self, skills_project, extension_dir):
|
|
"""Removing an extension should clean up its skill directories."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Verify skills exist
|
|
assert (skills_dir / "speckit-test-ext-hello" / "SKILL.md").exists()
|
|
assert (skills_dir / "speckit-test-ext-world" / "SKILL.md").exists()
|
|
|
|
# Remove extension
|
|
result = manager.remove(manifest.id, keep_config=False)
|
|
assert result is True
|
|
|
|
# Skills should be gone
|
|
assert not (skills_dir / "speckit-test-ext-hello").exists()
|
|
assert not (skills_dir / "speckit-test-ext-world").exists()
|
|
|
|
def test_other_skills_preserved_on_remove(self, skills_project, extension_dir):
|
|
"""Non-extension skills should not be affected by extension removal."""
|
|
project_dir, skills_dir = skills_project
|
|
|
|
# Pre-create a custom skill
|
|
custom_dir = skills_dir / "my-custom-skill"
|
|
custom_dir.mkdir(parents=True)
|
|
(custom_dir / "SKILL.md").write_text("# My Custom Skill\n")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
manager.remove(manifest.id, keep_config=False)
|
|
|
|
# Custom skill should still exist
|
|
assert (custom_dir / "SKILL.md").exists()
|
|
assert (custom_dir / "SKILL.md").read_text() == "# My Custom Skill\n"
|
|
|
|
def test_remove_handles_already_deleted_skills(self, skills_project, extension_dir):
|
|
"""Gracefully handle case where skill dirs were already deleted."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Manually delete skill dirs before calling remove
|
|
shutil.rmtree(skills_dir / "speckit-test-ext-hello")
|
|
shutil.rmtree(skills_dir / "speckit-test-ext-world")
|
|
|
|
# Should not raise
|
|
result = manager.remove(manifest.id, keep_config=False)
|
|
assert result is True
|
|
|
|
def test_remove_no_skills_when_not_active(self, no_skills_project, extension_dir):
|
|
"""Removal without active skills should not attempt skill cleanup."""
|
|
manager = ExtensionManager(no_skills_project)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Should not raise even though no skills exist
|
|
result = manager.remove(manifest.id, keep_config=False)
|
|
assert result is True
|
|
|
|
|
|
# ===== Command File Without Frontmatter =====
|
|
|
|
class TestExtensionSkillEdgeCases:
|
|
"""Test edge cases in extension skill registration."""
|
|
|
|
def test_install_with_non_dict_init_options_does_not_crash(self, project_dir, extension_dir):
|
|
"""Corrupted init-options payloads should disable skill registration, not crash install."""
|
|
opts_file = project_dir / ".specify" / "init-options.json"
|
|
opts_file.parent.mkdir(parents=True, exist_ok=True)
|
|
opts_file.write_text("[]", encoding="utf-8")
|
|
_create_skills_dir(project_dir, ai="claude")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
metadata = manager.registry.get(manifest.id)
|
|
assert metadata["registered_skills"] == []
|
|
|
|
def test_command_without_frontmatter(self, skills_project, temp_dir):
|
|
"""Commands without YAML frontmatter should still produce valid skills."""
|
|
project_dir, skills_dir = skills_project
|
|
|
|
ext_dir = temp_dir / "nofm-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "nofm-ext",
|
|
"name": "No Frontmatter Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.nofm-ext.plain",
|
|
"file": "commands/plain.md",
|
|
"description": "Plain command",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
(ext_dir / "commands" / "plain.md").write_text(
|
|
"# Plain Command\n\nBody without frontmatter.\n"
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-nofm-ext-plain" / "SKILL.md"
|
|
assert skill_file.exists()
|
|
content = skill_file.read_text()
|
|
assert "name: speckit-nofm-ext-plain" in content
|
|
# Fallback description when no frontmatter description
|
|
assert "Extension command: speckit.nofm-ext.plain" in content
|
|
assert "Body without frontmatter." in content
|
|
|
|
def test_gemini_agent_skills(self, project_dir, temp_dir):
|
|
"""Gemini agent should use .gemini/skills/ for skill directory."""
|
|
_create_init_options(project_dir, ai="gemini", ai_skills=True)
|
|
_create_skills_dir(project_dir, ai="gemini")
|
|
ext_dir = _create_extension_dir(temp_dir, ext_id="test-ext")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
skills_dir = project_dir / ".gemini" / "skills"
|
|
assert (skills_dir / "speckit-test-ext-hello" / "SKILL.md").exists()
|
|
assert (skills_dir / "speckit-test-ext-world" / "SKILL.md").exists()
|
|
|
|
def test_multiple_extensions_independent_skills(self, skills_project, temp_dir):
|
|
"""Installing and removing different extensions should be independent."""
|
|
project_dir, skills_dir = skills_project
|
|
|
|
ext_dir_a = _create_extension_dir(temp_dir, ext_id="ext-a")
|
|
ext_dir_b = _create_extension_dir(temp_dir, ext_id="ext-b")
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
manager.install_from_directory(
|
|
ext_dir_a, "0.1.0", register_commands=False
|
|
)
|
|
manager.install_from_directory(
|
|
ext_dir_b, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Both should have skills
|
|
assert (skills_dir / "speckit-ext-a-hello" / "SKILL.md").exists()
|
|
assert (skills_dir / "speckit-ext-b-hello" / "SKILL.md").exists()
|
|
|
|
# Remove ext-a
|
|
manager.remove("ext-a", keep_config=False)
|
|
|
|
# ext-a skills gone, ext-b skills preserved
|
|
assert not (skills_dir / "speckit-ext-a-hello").exists()
|
|
assert (skills_dir / "speckit-ext-b-hello" / "SKILL.md").exists()
|
|
|
|
def test_malformed_frontmatter_handled(self, skills_project, temp_dir):
|
|
"""Commands with invalid YAML frontmatter should still produce valid skills."""
|
|
project_dir, skills_dir = skills_project
|
|
|
|
ext_dir = temp_dir / "badfm-ext"
|
|
ext_dir.mkdir()
|
|
manifest_data = {
|
|
"schema_version": "1.0",
|
|
"extension": {
|
|
"id": "badfm-ext",
|
|
"name": "Bad Frontmatter Extension",
|
|
"version": "1.0.0",
|
|
"description": "Test",
|
|
},
|
|
"requires": {"speckit_version": ">=0.1.0"},
|
|
"provides": {
|
|
"commands": [
|
|
{
|
|
"name": "speckit.badfm-ext.broken",
|
|
"file": "commands/broken.md",
|
|
"description": "Broken frontmatter",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
with open(ext_dir / "extension.yml", "w") as f:
|
|
yaml.safe_dump(manifest_data, f)
|
|
|
|
(ext_dir / "commands").mkdir()
|
|
# Malformed YAML: invalid key-value syntax
|
|
(ext_dir / "commands" / "broken.md").write_text(
|
|
"---\n"
|
|
"description: [invalid yaml\n"
|
|
" unclosed: bracket\n"
|
|
"---\n"
|
|
"\n"
|
|
"# Broken Command\n"
|
|
"\n"
|
|
"This body should still be used.\n"
|
|
)
|
|
|
|
manager = ExtensionManager(project_dir)
|
|
# Should not raise
|
|
manager.install_from_directory(
|
|
ext_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
skill_file = skills_dir / "speckit-badfm-ext-broken" / "SKILL.md"
|
|
assert skill_file.exists()
|
|
content = skill_file.read_text()
|
|
# Fallback description since frontmatter was invalid
|
|
assert "Extension command: speckit.badfm-ext.broken" in content
|
|
assert "This body should still be used." in content
|
|
|
|
def test_remove_cleans_up_when_init_options_deleted(self, skills_project, extension_dir):
|
|
"""Skills should be cleaned up even if init-options.json is deleted after install."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Verify skills exist
|
|
assert (skills_dir / "speckit-test-ext-hello" / "SKILL.md").exists()
|
|
|
|
# Delete init-options.json to simulate user change
|
|
init_opts = project_dir / ".specify" / "init-options.json"
|
|
init_opts.unlink()
|
|
|
|
# Remove should still clean up via fallback scan
|
|
result = manager.remove(manifest.id, keep_config=False)
|
|
assert result is True
|
|
assert not (skills_dir / "speckit-test-ext-hello").exists()
|
|
assert not (skills_dir / "speckit-test-ext-world").exists()
|
|
|
|
def test_remove_cleans_up_when_ai_skills_toggled(self, skills_project, extension_dir):
|
|
"""Skills should be cleaned up even if ai_skills is toggled to false after install."""
|
|
project_dir, skills_dir = skills_project
|
|
manager = ExtensionManager(project_dir)
|
|
manifest = manager.install_from_directory(
|
|
extension_dir, "0.1.0", register_commands=False
|
|
)
|
|
|
|
# Verify skills exist
|
|
assert (skills_dir / "speckit-test-ext-hello" / "SKILL.md").exists()
|
|
|
|
# Toggle ai_skills to false
|
|
_create_init_options(project_dir, ai="claude", ai_skills=False)
|
|
|
|
# Remove should still clean up via fallback scan
|
|
result = manager.remove(manifest.id, keep_config=False)
|
|
assert result is True
|
|
assert not (skills_dir / "speckit-test-ext-hello").exists()
|
|
assert not (skills_dir / "speckit-test-ext-world").exists()
|