mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
* Initial plan * Add workflow engine with step registry, expression engine, catalog system, and CLI commands Agent-Logs-Url: https://github.com/github/spec-kit/sessions/72a7bb5d-071f-4d67-a507-7e1abae2384d Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com> * Add comprehensive tests for workflow engine (94 tests) Agent-Logs-Url: https://github.com/github/spec-kit/sessions/72a7bb5d-071f-4d67-a507-7e1abae2384d Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com> * Address review feedback: do-while condition preservation and URL scheme validation Agent-Logs-Url: https://github.com/github/spec-kit/sessions/72a7bb5d-071f-4d67-a507-7e1abae2384d Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com> * Address review feedback, add CLI dispatch, interactive gates, and docs Review comments (7/7): - Add explanatory comment to empty except block - Implement workflow catalog download with cleanup on failure - Add input type coercion for number/boolean/enum - Fix example workflow to remove non-existent output references - Fix while_loop and if_then condition defaults (string 'false' → bool False) - Fix resume step index tracking with step_offset parameter CLI dispatch: - Add build_exec_args() and dispatch_command() to IntegrationBase - Override for Claude (skills: /speckit-specify), Gemini (-m flag), Codex (codex exec), Copilot (--agent speckit.specify) - CommandStep invokes installed commands by name via integration CLI - Add PromptStep for arbitrary inline prompts (10th step type) - Stream CLI output live to terminal (no silent blocking) - Remove timeout when streaming (user can Ctrl+C) - Ctrl+C saves state as PAUSED for clean resume Interactive gates: - Gate steps prompt [1] approve [2] reject in TTY - Fall back to PAUSED in non-interactive environments - Resume re-executes the gate for interactive prompting Documentation: - workflows/README.md — user guide - workflows/ARCHITECTURE.md — internals with Mermaid diagrams - workflows/PUBLISHING.md — catalog submission guide Tests: 94 → 122 workflow tests, 1362 total (all passing) * Fix ruff lint errors: unused imports, f-string placeholders, undefined name * Address second review: registry-backed validation, shell failures, loop/fan-out execution, URL validation - VALID_STEP_TYPES now queries STEP_REGISTRY dynamically - Shell step returns FAILED on non-zero exit code - Persist workflow YAML in run directory for reliable resume - Resume loads from run copy, falls back to installed workflow - Engine iterates while/do-while loops up to max_iterations - Engine expands fan-out per item with context.item - HTTPS URL validation for catalog workflow installs (HTTP allowed for localhost) - Fix catalog merge priority docstring (lower number wins) - Fix dispatch_command docstring (no build_exec_args_for_command) - Gate on_reject=retry pauses for re-prompt on resume - Update docs to 10 step types, add prompt step to tables and README * Potential fix for pull request finding 'Empty except' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Address third review: fan-out IDs, catalog guards, shell coercion, docs - Fan-out generates unique per-item step IDs and collects results - Catalog merge skips non-dict workflow entries (malformed data guard) - Shell step coerces run_cmd to str after expression evaluation - urlopen timeout=30 for catalog workflow installs - yaml.dump with sort_keys=False, allow_unicode=True for catalog configs - Document streaming timeout as intentionally unbounded (user Ctrl+C) - Document --allow-all-tools as required for non-interactive + future enhancement - Update test docstring and PUBLISHING.md to 10 step types with prompt * Validate final URL after redirects in catalog fetch urlopen follows redirects, so validate the response URL against the same HTTPS/localhost rules to prevent redirect-based downgrade attacks. * Address fourth review: filter arg eval, tags normalization, install redirect check - Filter arguments now evaluated via _evaluate_simple_expression() so default(42) returns int not string - Tags normalized: non-list/non-string values handled gracefully - Install URL redirect validation (same as catalog fetch) - Remove unused 'skipped' variable in catalog config parsing - Author 'github' → 'GitHub' in example workflow - Document nested step resume limitation (re-runs parent step) * Add explanatory comment to empty except ValueError block * Address fifth review: expression parsing, fan-out output, URL install, gate options - Move string literal parsing before operator detection in expressions so quoted strings with operators (e.g. 'a in b') are not mis-parsed - Fan-out: remove max_concurrency from persisted output, fix docstring to reflect sequential execution - workflow add: support URL sources with HTTPS/redirect validation, validate workflow ID is non-empty before writing files - Deduplicate local install logic via _validate_and_install_local() - Remove 'edit' gate option from speckit workflow (not implemented) * Add comments to empty except ValueError blocks in URL install * Address sixth review: operator precedence, fan_in cleanup, registry resilience, docs - Fix or/and operator precedence (or parsed first = lower precedence) - Restore context.fan_in after fan-in step completes - Catch JSONDecodeError in registry load for corrupted files - Replace print() with on_step_start callback (library-safe) - Gate validation warns when on_reject set but no reject option - Shell step: document shell=True security tradeoff - README: sdd-pipeline → speckit, parallel → sequential for fan-out - ARCHITECTURE.md: parallel → fan-out/fan-in in diagram * Address seventh review: string literal before pipe, type annotations, validate on install - Move string literal check above pipe filter parsing so 'a | b' works - Fix type annotations: input_values list[str] | None, run_id str | None - Run validate_workflow() before installing from local path/URL - Remove duplicate string literal check from expression parser * Address eighth review: fan-out namespaced IDs, early return, catalog validation - Fan-out per-item step IDs use _fanout_{step_id}_{base}_{idx} namespace to avoid collisions with user-defined step IDs - Early return after fan-out loop when state is paused/failed/aborted - Catalog installs parse + validate downloaded YAML before registering, using definition metadata instead of catalog entry for registry * Address ninth review: populate catalog, fix indentation, priority, README - Add speckit workflow entry to catalog.json so it's discoverable - Fix shell step output dict indentation - Catalog add_catalog priority derived from max existing + 1 - README Quick Start clarified with install + local file examples * Address tenth review: max_iterations validation, catalog config guard, version alignment - Validate max_iterations is int >= 1 in while and do-while steps - Guard add_catalog against corrupted config (non-dict/non-list) - Align speckit_version requirement to >=0.6.1 (current package version) - Fan-out template validation uses separate seen_ids set to avoid false duplication errors with user-defined step IDs * Address eleventh review: command step fails without CLI, ID mismatch warning, state persistence - Command step returns FAILED when CLI not installed (was silent COMPLETED) - Catalog install warns on workflow ID vs catalog key mismatch - Engine persists state.save() before returning on unknown step type - Update tests to expect FAILED for command steps without CLI - Integration tests use shell steps for CLI-independent execution * Address twelfth review: type annotations, version examples, streaming docs, requires - Fix workflow_search type annotations (str | None) - PUBLISHING.md: speckit_version >=0.15.0 → >=0.6.1 - Document that exit_code is captured and referenceable by later steps - Mark requires as declared-but-not-enforced (planned enhancement) - Note full stdout/stderr capture as planned enhancement * Enforce catalog key matches workflow ID (fail instead of warn) * Bundle speckit workflow: auto-install during specify init - Add workflows/speckit to pyproject.toml force-include for wheel builds - Add _locate_bundled_workflow() helper (mirrors _locate_bundled_extension) - Auto-install speckit workflow during specify init (after git extension) - Update all integration file inventory tests to expect workflow files * Address fourteenth review: prompt fails without CLI, resolved step data, fan-out normalization - PromptStep returns FAILED when CLI not installed (was silent COMPLETED) - Engine step_data prefers resolved values from step output - Fan-out normalizes output.results=[] for empty item lists - subprocess.run inherits stdout/stderr (no explicit sys.stdout) - Registry tests use issubset for extensibility * Address fifteenth review: fan_in docstring, gate defaults, validation guards, reserved prefix - FanInStep docstring: aggregate-only, no blocking semantics - FanInStep: guard output_config as dict, handle None - Gate validate: use same default options as execute - Validate inputs is dict and steps is list before iterating - Reserve _fanout_ prefix in step ID validation - PUBLISHING.md: remove unenforced checklist items, add _fanout_ note * Address sixteenth review: docs regex, fan_in try/finally, hyphenated dot-path keys - PUBLISHING.md: update ID regex docs to match implementation (single-char OK) - FanInStep: wrap expression evaluation in try/finally for context.fan_in - Expression dot-path: allow hyphens in keys before list index (e.g. run-tests[0]) * Make speckit workflow integration-agnostic, document Copilot CLI requirement - Workflow integration selectable via input (default: claude) - Each command step uses {{ inputs.integration }} instead of hardcoded copilot - Copilot docstring documents CLI requirement for workflow dispatch - Added install_url for Copilot CLI docs * Address seventeenth review: project checks, catalog robustness - Add .specify/ project check to workflow run/resume/status/search/info - remove_catalog validates config shape (dict + list) before indexing - _fetch_single_catalog validates response is a dict - _get_merged_workflows raises when all catalogs fail to fetch - add_catalog guards against non-dict catalog entries in config * Address eighteenth review: condition coercion, gate abort result, while default, cache guard, resume log - evaluate_condition treats plain 'false'/'true' strings as booleans - Gate abort returns StepResult(FAILED) instead of raising exception so step output is persisted in state for inspection - while_loop max_iterations optional (default 10), validation aligned - Catalog cache fallback catches invalid JSON gracefully - resume() appends workflow_finished log entry like execute() * Address nineteenth review: allow-all-tools opt-in, empty catalogs, abort dead code, while docstring - --allow-all-tools controlled by SPECKIT_ALLOW_ALL_TOOLS env var (default: 1) Set to 0 to disable automatic tool approval for Copilot CLI - Empty catalogs list falls back to built-in defaults (not an error) - Remove unreachable WorkflowAbortError catches from execute/resume (gate abort now returns StepResult(FAILED) instead of raising) - while_loop docstring updated: max_iterations is optional (default 10) * Address twentieth review: gate abort maps to ABORTED status, do-while max_iterations optional - Engine detects output.aborted from gate step and sets RunStatus.ABORTED (was unreachable — gate abort returned FAILED but status was always FAILED) - do-while max_iterations now optional (default 10), aligned with while_loop - do-while docstring and validation updated accordingly * Coerce default_options to dict, align bundled workflow ID regex with validator * Gate validates string options, prompt uses resolved integration, loop normalizes max_iterations * Use parentId:childId convention for nested step IDs - Fan-out per-item IDs use parentId:templateId:index (e.g. parallel:impl:0) - Reserve ':' in user step IDs (validation rejects) - Replaces _fanout_ prefix with cleaner namespacing - Expressions like {{ steps.parallel:impl:0.output.file }} work naturally * Validate workflow version is semantic versioning (X.Y.Z) * Schema version validation, strict semver, load_workflow docstring, preserve max_concurrency - Validate schema_version is '1.0' (reject unknown future schemas) - Strict semver regex: ^\d+\.\d+\.\d+$ (rejects 1.0.0beta etc.) - load_workflow docstring: 'parsed' not 'validated' - Keep max_concurrency in fan-out output (was dropped) - do_while docstring: engine re-evaluates step_config condition - ARCHITECTURE.md: document nested resume limitation * Path traversal prevention, loop step ID namespacing - RunState validates run_id is alphanumeric+hyphens (no path separators) - workflow_add validates catalog source doesn't escape workflows_dir - Loop iterations namespace nested step IDs as parentId:childId:iteration so multiple iterations don't overwrite each other in context/state --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
410 lines
17 KiB
Python
410 lines
17 KiB
Python
"""Reusable test mixin for standard SkillsIntegration subclasses.
|
|
|
|
Each per-agent test file sets ``KEY``, ``FOLDER``, ``COMMANDS_SUBDIR``,
|
|
``REGISTRAR_DIR``, and ``CONTEXT_FILE``, then inherits all verification
|
|
logic from ``SkillsIntegrationTests``.
|
|
|
|
Mirrors ``MarkdownIntegrationTests`` / ``TomlIntegrationTests`` closely,
|
|
adapted for the ``speckit-<name>/SKILL.md`` skills layout.
|
|
"""
|
|
|
|
import os
|
|
|
|
import yaml
|
|
|
|
from specify_cli.integrations import INTEGRATION_REGISTRY, get_integration
|
|
from specify_cli.integrations.base import SkillsIntegration
|
|
from specify_cli.integrations.manifest import IntegrationManifest
|
|
|
|
|
|
class SkillsIntegrationTests:
|
|
"""Mixin — set class-level constants and inherit these tests.
|
|
|
|
Required class attrs on subclass::
|
|
|
|
KEY: str — integration registry key
|
|
FOLDER: str — e.g. ".agents/"
|
|
COMMANDS_SUBDIR: str — e.g. "skills"
|
|
REGISTRAR_DIR: str — e.g. ".agents/skills"
|
|
CONTEXT_FILE: str — e.g. "AGENTS.md"
|
|
"""
|
|
|
|
KEY: str
|
|
FOLDER: str
|
|
COMMANDS_SUBDIR: str
|
|
REGISTRAR_DIR: str
|
|
CONTEXT_FILE: str
|
|
|
|
# -- Registration -----------------------------------------------------
|
|
|
|
def test_registered(self):
|
|
assert self.KEY in INTEGRATION_REGISTRY
|
|
assert get_integration(self.KEY) is not None
|
|
|
|
def test_is_skills_integration(self):
|
|
assert isinstance(get_integration(self.KEY), SkillsIntegration)
|
|
|
|
# -- Config -----------------------------------------------------------
|
|
|
|
def test_config_folder(self):
|
|
i = get_integration(self.KEY)
|
|
assert i.config["folder"] == self.FOLDER
|
|
|
|
def test_config_commands_subdir(self):
|
|
i = get_integration(self.KEY)
|
|
assert i.config["commands_subdir"] == self.COMMANDS_SUBDIR
|
|
|
|
def test_registrar_config(self):
|
|
i = get_integration(self.KEY)
|
|
assert i.registrar_config["dir"] == self.REGISTRAR_DIR
|
|
assert i.registrar_config["format"] == "markdown"
|
|
assert i.registrar_config["args"] == "$ARGUMENTS"
|
|
assert i.registrar_config["extension"] == "/SKILL.md"
|
|
|
|
def test_context_file(self):
|
|
i = get_integration(self.KEY)
|
|
assert i.context_file == self.CONTEXT_FILE
|
|
|
|
# -- Setup / teardown -------------------------------------------------
|
|
|
|
def test_setup_creates_files(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
assert len(created) > 0
|
|
skill_files = [f for f in created if "scripts" not in f.parts]
|
|
for f in skill_files:
|
|
assert f.exists()
|
|
assert f.name == "SKILL.md"
|
|
assert f.parent.name.startswith("speckit-")
|
|
|
|
def test_setup_writes_to_correct_directory(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
expected_dir = i.skills_dest(tmp_path)
|
|
assert expected_dir.exists(), f"Expected directory {expected_dir} was not created"
|
|
skill_files = [f for f in created if "scripts" not in f.parts]
|
|
assert len(skill_files) > 0, "No skill files were created"
|
|
for f in skill_files:
|
|
# Each SKILL.md is in speckit-<name>/ under the skills directory
|
|
assert f.resolve().parent.parent == expected_dir.resolve(), (
|
|
f"{f} is not under {expected_dir}"
|
|
)
|
|
|
|
def test_skill_directory_structure(self, tmp_path):
|
|
"""Each command produces speckit-<name>/SKILL.md."""
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
skill_files = [f for f in created if "scripts" not in f.parts]
|
|
|
|
expected_commands = {
|
|
"analyze", "checklist", "clarify", "constitution",
|
|
"implement", "plan", "specify", "tasks", "taskstoissues",
|
|
}
|
|
|
|
# Derive command names from the skill directory names
|
|
actual_commands = set()
|
|
for f in skill_files:
|
|
skill_dir_name = f.parent.name # e.g. "speckit-plan"
|
|
assert skill_dir_name.startswith("speckit-")
|
|
actual_commands.add(skill_dir_name.removeprefix("speckit-"))
|
|
|
|
assert actual_commands == expected_commands
|
|
|
|
def test_skill_frontmatter_structure(self, tmp_path):
|
|
"""SKILL.md must have name, description, compatibility, metadata."""
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
skill_files = [f for f in created if "scripts" not in f.parts]
|
|
|
|
for f in skill_files:
|
|
content = f.read_text(encoding="utf-8")
|
|
assert content.startswith("---\n"), f"{f} missing frontmatter"
|
|
parts = content.split("---", 2)
|
|
fm = yaml.safe_load(parts[1])
|
|
assert "name" in fm, f"{f} frontmatter missing 'name'"
|
|
assert "description" in fm, f"{f} frontmatter missing 'description'"
|
|
assert "compatibility" in fm, f"{f} frontmatter missing 'compatibility'"
|
|
assert "metadata" in fm, f"{f} frontmatter missing 'metadata'"
|
|
assert fm["metadata"]["author"] == "github-spec-kit"
|
|
assert "source" in fm["metadata"]
|
|
|
|
def test_skill_uses_template_descriptions(self, tmp_path):
|
|
"""SKILL.md should use the original template description for ZIP parity."""
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
skill_files = [f for f in created if "scripts" not in f.parts]
|
|
|
|
for f in skill_files:
|
|
content = f.read_text(encoding="utf-8")
|
|
parts = content.split("---", 2)
|
|
fm = yaml.safe_load(parts[1])
|
|
# Description must be a non-empty string (from the template)
|
|
assert isinstance(fm["description"], str)
|
|
assert len(fm["description"]) > 0, f"{f} has empty description"
|
|
|
|
def test_templates_are_processed(self, tmp_path):
|
|
"""Skill body must have placeholders replaced, not raw templates."""
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
skill_files = [f for f in created if "scripts" not in f.parts]
|
|
assert len(skill_files) > 0
|
|
for f in skill_files:
|
|
content = f.read_text(encoding="utf-8")
|
|
assert "{SCRIPT}" not in content, f"{f.name} has unprocessed {{SCRIPT}}"
|
|
assert "__AGENT__" not in content, f"{f.name} has unprocessed __AGENT__"
|
|
assert "{ARGS}" not in content, f"{f.name} has unprocessed {{ARGS}}"
|
|
|
|
def test_skill_body_has_content(self, tmp_path):
|
|
"""Each SKILL.md body should contain template content after the frontmatter."""
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
skill_files = [f for f in created if "scripts" not in f.parts]
|
|
for f in skill_files:
|
|
content = f.read_text(encoding="utf-8")
|
|
# Body is everything after the second ---
|
|
parts = content.split("---", 2)
|
|
body = parts[2].strip() if len(parts) >= 3 else ""
|
|
assert len(body) > 0, f"{f} has empty body"
|
|
|
|
def test_all_files_tracked_in_manifest(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
for f in created:
|
|
rel = f.resolve().relative_to(tmp_path.resolve()).as_posix()
|
|
assert rel in m.files, f"{rel} not tracked in manifest"
|
|
|
|
def test_install_uninstall_roundtrip(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.install(tmp_path, m)
|
|
assert len(created) > 0
|
|
m.save()
|
|
for f in created:
|
|
assert f.exists()
|
|
removed, skipped = i.uninstall(tmp_path, m)
|
|
assert len(removed) == len(created)
|
|
assert skipped == []
|
|
|
|
def test_modified_file_survives_uninstall(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.install(tmp_path, m)
|
|
m.save()
|
|
modified_file = created[0]
|
|
modified_file.write_text("user modified this", encoding="utf-8")
|
|
removed, skipped = i.uninstall(tmp_path, m)
|
|
assert modified_file.exists()
|
|
assert modified_file in skipped
|
|
|
|
def test_pre_existing_skills_not_removed(self, tmp_path):
|
|
"""Pre-existing non-speckit skills should be left untouched."""
|
|
i = get_integration(self.KEY)
|
|
skills_dir = i.skills_dest(tmp_path)
|
|
foreign_dir = skills_dir / "other-tool"
|
|
foreign_dir.mkdir(parents=True)
|
|
(foreign_dir / "SKILL.md").write_text("# Foreign skill\n")
|
|
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
i.setup(tmp_path, m)
|
|
|
|
assert (foreign_dir / "SKILL.md").exists(), "Foreign skill was removed"
|
|
|
|
# -- Scripts ----------------------------------------------------------
|
|
|
|
def test_setup_installs_update_context_scripts(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
i.setup(tmp_path, m)
|
|
scripts_dir = tmp_path / ".specify" / "integrations" / self.KEY / "scripts"
|
|
assert scripts_dir.is_dir(), f"Scripts directory not created for {self.KEY}"
|
|
assert (scripts_dir / "update-context.sh").exists()
|
|
assert (scripts_dir / "update-context.ps1").exists()
|
|
|
|
def test_scripts_tracked_in_manifest(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
i.setup(tmp_path, m)
|
|
script_rels = [k for k in m.files if "update-context" in k]
|
|
assert len(script_rels) >= 2
|
|
|
|
def test_sh_script_is_executable(self, tmp_path):
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
i.setup(tmp_path, m)
|
|
sh = tmp_path / ".specify" / "integrations" / self.KEY / "scripts" / "update-context.sh"
|
|
assert os.access(sh, os.X_OK)
|
|
|
|
# -- CLI auto-promote -------------------------------------------------
|
|
|
|
def test_ai_flag_auto_promotes(self, tmp_path):
|
|
from typer.testing import CliRunner
|
|
from specify_cli import app
|
|
|
|
project = tmp_path / f"promote-{self.KEY}"
|
|
project.mkdir()
|
|
old_cwd = os.getcwd()
|
|
try:
|
|
os.chdir(project)
|
|
runner = CliRunner()
|
|
result = runner.invoke(app, [
|
|
"init", "--here", "--ai", self.KEY, "--script", "sh", "--no-git",
|
|
"--ignore-agent-tools",
|
|
], catch_exceptions=False)
|
|
finally:
|
|
os.chdir(old_cwd)
|
|
assert result.exit_code == 0, f"init --ai {self.KEY} failed: {result.output}"
|
|
i = get_integration(self.KEY)
|
|
skills_dir = i.skills_dest(project)
|
|
assert skills_dir.is_dir(), f"--ai {self.KEY} did not create skills directory"
|
|
|
|
def test_integration_flag_creates_files(self, tmp_path):
|
|
from typer.testing import CliRunner
|
|
from specify_cli import app
|
|
|
|
project = tmp_path / f"int-{self.KEY}"
|
|
project.mkdir()
|
|
old_cwd = os.getcwd()
|
|
try:
|
|
os.chdir(project)
|
|
runner = CliRunner()
|
|
result = runner.invoke(app, [
|
|
"init", "--here", "--integration", self.KEY, "--script", "sh", "--no-git",
|
|
"--ignore-agent-tools",
|
|
], catch_exceptions=False)
|
|
finally:
|
|
os.chdir(old_cwd)
|
|
assert result.exit_code == 0, f"init --integration {self.KEY} failed: {result.output}"
|
|
i = get_integration(self.KEY)
|
|
skills_dir = i.skills_dest(project)
|
|
assert skills_dir.is_dir(), f"Skills directory {skills_dir} not created"
|
|
|
|
# -- IntegrationOption ------------------------------------------------
|
|
|
|
def test_options_include_skills_flag(self):
|
|
i = get_integration(self.KEY)
|
|
opts = i.options()
|
|
skills_opts = [o for o in opts if o.name == "--skills"]
|
|
assert len(skills_opts) == 1
|
|
assert skills_opts[0].is_flag is True
|
|
|
|
# -- Complete file inventory ------------------------------------------
|
|
|
|
_SKILL_COMMANDS = [
|
|
"analyze", "checklist", "clarify", "constitution",
|
|
"implement", "plan", "specify", "tasks", "taskstoissues",
|
|
]
|
|
|
|
def _expected_files(self, script_variant: str) -> list[str]:
|
|
"""Build the full expected file list for a given script variant."""
|
|
i = get_integration(self.KEY)
|
|
skills_prefix = i.config["folder"].rstrip("/") + "/" + i.config.get("commands_subdir", "skills")
|
|
|
|
files = []
|
|
# Skill files
|
|
for cmd in self._SKILL_COMMANDS:
|
|
files.append(f"{skills_prefix}/speckit-{cmd}/SKILL.md")
|
|
# Integration metadata
|
|
files += [
|
|
".specify/init-options.json",
|
|
".specify/integration.json",
|
|
f".specify/integrations/{self.KEY}.manifest.json",
|
|
f".specify/integrations/{self.KEY}/scripts/update-context.ps1",
|
|
f".specify/integrations/{self.KEY}/scripts/update-context.sh",
|
|
".specify/integrations/speckit.manifest.json",
|
|
".specify/memory/constitution.md",
|
|
]
|
|
# Script variant
|
|
if script_variant == "sh":
|
|
files += [
|
|
".specify/scripts/bash/check-prerequisites.sh",
|
|
".specify/scripts/bash/common.sh",
|
|
".specify/scripts/bash/create-new-feature.sh",
|
|
".specify/scripts/bash/setup-plan.sh",
|
|
".specify/scripts/bash/update-agent-context.sh",
|
|
]
|
|
else:
|
|
files += [
|
|
".specify/scripts/powershell/check-prerequisites.ps1",
|
|
".specify/scripts/powershell/common.ps1",
|
|
".specify/scripts/powershell/create-new-feature.ps1",
|
|
".specify/scripts/powershell/setup-plan.ps1",
|
|
".specify/scripts/powershell/update-agent-context.ps1",
|
|
]
|
|
# Templates
|
|
files += [
|
|
".specify/templates/agent-file-template.md",
|
|
".specify/templates/checklist-template.md",
|
|
".specify/templates/constitution-template.md",
|
|
".specify/templates/plan-template.md",
|
|
".specify/templates/spec-template.md",
|
|
".specify/templates/tasks-template.md",
|
|
]
|
|
# Bundled workflow
|
|
files += [
|
|
".specify/workflows/speckit/workflow.yml",
|
|
".specify/workflows/workflow-registry.json",
|
|
]
|
|
return sorted(files)
|
|
|
|
def test_complete_file_inventory_sh(self, tmp_path):
|
|
"""Every file produced by specify init --integration <key> --script sh."""
|
|
from typer.testing import CliRunner
|
|
from specify_cli import app
|
|
|
|
project = tmp_path / f"inventory-sh-{self.KEY}"
|
|
project.mkdir()
|
|
old_cwd = os.getcwd()
|
|
try:
|
|
os.chdir(project)
|
|
result = CliRunner().invoke(app, [
|
|
"init", "--here", "--integration", self.KEY,
|
|
"--script", "sh", "--no-git", "--ignore-agent-tools",
|
|
], catch_exceptions=False)
|
|
finally:
|
|
os.chdir(old_cwd)
|
|
assert result.exit_code == 0, f"init failed: {result.output}"
|
|
actual = sorted(
|
|
p.relative_to(project).as_posix()
|
|
for p in project.rglob("*") if p.is_file()
|
|
)
|
|
expected = self._expected_files("sh")
|
|
assert actual == expected, (
|
|
f"Missing: {sorted(set(expected) - set(actual))}\n"
|
|
f"Extra: {sorted(set(actual) - set(expected))}"
|
|
)
|
|
|
|
def test_complete_file_inventory_ps(self, tmp_path):
|
|
"""Every file produced by specify init --integration <key> --script ps."""
|
|
from typer.testing import CliRunner
|
|
from specify_cli import app
|
|
|
|
project = tmp_path / f"inventory-ps-{self.KEY}"
|
|
project.mkdir()
|
|
old_cwd = os.getcwd()
|
|
try:
|
|
os.chdir(project)
|
|
result = CliRunner().invoke(app, [
|
|
"init", "--here", "--integration", self.KEY,
|
|
"--script", "ps", "--no-git", "--ignore-agent-tools",
|
|
], catch_exceptions=False)
|
|
finally:
|
|
os.chdir(old_cwd)
|
|
assert result.exit_code == 0, f"init failed: {result.output}"
|
|
actual = sorted(
|
|
p.relative_to(project).as_posix()
|
|
for p in project.rglob("*") if p.is_file()
|
|
)
|
|
expected = self._expected_files("ps")
|
|
assert actual == expected, (
|
|
f"Missing: {sorted(set(expected) - set(actual))}\n"
|
|
f"Extra: {sorted(set(actual) - set(expected))}"
|
|
)
|