mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
* feat(init)!: make git extension opt-in and remove --no-git at v0.10.0 - Remove --no-git parameter from specify init command - Remove git extension auto-installation from init flow - Git repository initialization (git init) still runs when git is available - Remove --no-git from all test invocations across the test suite - Update docs to reflect opt-in git extension behavior - Replace TestGitExtensionAutoInstall with TestGitExtensionOptIn tests BREAKING CHANGE: specify init no longer auto-installs the git extension. Use `specify extension add git` to install it explicitly. The --no-git flag has been removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(scripts): remove git operations from core scripts Git functionality is now entirely managed by the git extension. Core scripts only handle directory-based feature creation and numbering. - Remove has_git(), check_feature_branch(), git branch creation from core - Simplify number detection to use only spec directory scanning - Remove HAS_GIT output from get_feature_paths() - Remove git remote fetching and branch querying - Keep BRANCH_NAME output key for backward compatibility Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor: remove all git operations from core - Remove is_git_repo() and init_git_repo() dead code from _utils.py - Remove --branch-numbering from init command - Remove git from 'specify check' (now extension-only) - Update docs: git is optional prerequisite, check command description - Fix tests to reflect no-git-in-core reality (fallback to main) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(scripts): remove directory scanning and branch fallback from core Core scripts now resolve feature context exclusively from: 1. SPECIFY_FEATURE env var (set by git extension) 2. .specify/feature.json (persisted by specify command) Removed find_feature_dir_by_prefix() and directory scanning heuristics — these are the git extension's responsibility. Scripts error clearly when no feature context is available. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat: introduce feature_numbering, deprecate branch_numbering in init-options - specify command template now reads feature_numbering (preferred) with fallback to branch_numbering (deprecated) from init-options.json - Git extension reads git-config.yml > feature_numbering > branch_numbering - init now writes feature_numbering: sequential to init-options.json - Deprecation warning emitted when branch_numbering is used as fallback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: remove trailing whitespace in common.ps1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat(scripts): persist SPECIFY_FEATURE_DIRECTORY env var to feature.json When SPECIFY_FEATURE_DIRECTORY is set, get_feature_paths() now writes the value to .specify/feature.json so future sessions without the env var can still resolve the feature directory. The write is idempotent — it skips when the file already contains the same value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: address review feedback — error messages and docs - Update error messages in common.sh and common.ps1 to reference SPECIFY_FEATURE_DIRECTORY instead of SPECIFY_FEATURE (which no longer resolves feature directories) - Fix get_current_branch comment (returns empty string, not error) - Update upgrade.md to reference SPECIFY_FEATURE_DIRECTORY with correct example paths - Update local-development.md troubleshooting: replace stale 'Git step skipped' row with actionable git extension guidance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): harden feature.json persistence - Use json_escape in printf fallback when jq is unavailable (common.sh) - Replace utf8NoBOM encoding with UTF8Encoding($false) for PowerShell 5.1 compatibility (common.ps1) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(scripts): remove dead feature_json_matches_feature_dir functions These guards are no longer needed since the branch-name validation they protected against has been removed from check-prerequisites. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(git-ext): rename create-new-feature to create-new-feature-branch The git extension's script only creates the git branch — rename it to reflect that responsibility. The core create-new-feature.sh/.ps1 handles feature directory creation and feature.json persistence. Also includes fixes from review feedback: - common.sh: _persist_feature_json uses json_escape fallback - common.ps1: Save-FeatureJson uses UTF8Encoding for PS 5.1 compat - common.ps1: case-sensitive path stripping on non-Windows - create-new-feature.sh/ps1: output both SPECIFY_FEATURE and SPECIFY_FEATURE_DIRECTORY - setup-tasks.sh: fix stale 'Validate branch' comment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(tests): update references to renamed git extension scripts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(tests): remove duplicate EXT_CREATE_FEATURE assignments Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Manfred Riem <mnriem@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
223 lines
8.3 KiB
Python
223 lines
8.3 KiB
Python
"""Tests for ClineIntegration."""
|
|
|
|
import os
|
|
import pytest
|
|
|
|
from specify_cli.integrations import get_integration
|
|
from specify_cli.integrations.cline import format_cline_command_name
|
|
from .test_integration_base_markdown import MarkdownIntegrationTests
|
|
|
|
|
|
class TestClineCommandNameFormatter:
|
|
"""Test the Cline command name formatter."""
|
|
|
|
def test_simple_name_without_prefix(self):
|
|
"""Test formatting a simple name without 'speckit.' prefix."""
|
|
assert format_cline_command_name("plan") == "speckit-plan"
|
|
assert format_cline_command_name("tasks") == "speckit-tasks"
|
|
assert format_cline_command_name("specify") == "speckit-specify"
|
|
|
|
def test_name_with_speckit_prefix(self):
|
|
"""Test formatting a name that already has 'speckit.' prefix."""
|
|
assert format_cline_command_name("speckit.plan") == "speckit-plan"
|
|
assert format_cline_command_name("speckit.tasks") == "speckit-tasks"
|
|
|
|
def test_extension_command_name(self):
|
|
"""Test formatting extension command names with dots."""
|
|
assert (
|
|
format_cline_command_name("speckit.my-extension.example")
|
|
== "speckit-my-extension-example"
|
|
)
|
|
assert (
|
|
format_cline_command_name("my-extension.example")
|
|
== "speckit-my-extension-example"
|
|
)
|
|
|
|
def test_idempotent_already_hyphenated(self):
|
|
"""Test that already-hyphenated names are returned unchanged (idempotent)."""
|
|
assert format_cline_command_name("speckit-plan") == "speckit-plan"
|
|
assert (
|
|
format_cline_command_name("speckit-my-extension-example")
|
|
== "speckit-my-extension-example"
|
|
)
|
|
|
|
|
|
class TestClineIntegration(MarkdownIntegrationTests):
|
|
KEY = "cline"
|
|
FOLDER = ".clinerules/"
|
|
COMMANDS_SUBDIR = "workflows"
|
|
REGISTRAR_DIR = ".clinerules/workflows"
|
|
CONTEXT_FILE = ".clinerules/specify-rules.md"
|
|
|
|
@pytest.mark.parametrize(
|
|
"cmd_name, expected_filename",
|
|
[
|
|
("plan", "speckit-plan.md"),
|
|
("speckit.plan", "speckit-plan.md"),
|
|
("speckit.git.commit", "speckit-git-commit.md"),
|
|
("speckit", "speckit-speckit.md"),
|
|
("speckitfoo", "speckit-speckitfoo.md"),
|
|
],
|
|
)
|
|
def test_cline_command_filename(self, cmd_name, expected_filename):
|
|
"""Verify Cline uses hyphenated filenames."""
|
|
cline = get_integration("cline")
|
|
assert cline.command_filename(cmd_name) == expected_filename
|
|
|
|
def test_cline_invoke_separator(self):
|
|
"""Verify Cline uses hyphen as invoke separator."""
|
|
cline = get_integration("cline")
|
|
assert cline.invoke_separator == "-"
|
|
assert cline.registrar_config["invoke_separator"] == "-"
|
|
|
|
def test_cline_name_injection_and_formatting(self):
|
|
"""Verify Cline has inject_name and format_name configured."""
|
|
cline = get_integration("cline")
|
|
assert cline.registrar_config["inject_name"] is True
|
|
assert cline.registrar_config["format_name"] == format_cline_command_name
|
|
|
|
def test_cline_handoff_rewrite(self):
|
|
"""Verify Cline rewrites agent: speckit.foo to agent: speckit-foo."""
|
|
cline = get_integration("cline")
|
|
content = "---\nagent: speckit.plan\n---\n"
|
|
rewritten = cline._rewrite_handoff_references(content)
|
|
assert rewritten == "---\nagent: speckit-plan\n---\n"
|
|
|
|
def test_cline_hook_instruction_injection(self):
|
|
"""Verify Cline injects the dot-to-hyphen note for hooks."""
|
|
cline = get_integration("cline")
|
|
content = "- For each executable hook, output the following:\n"
|
|
injected = cline._inject_hook_command_note(content)
|
|
assert "replace dots (`.`) with hyphens (`-`)" in injected
|
|
assert "- For each executable hook, output the following:" in injected
|
|
|
|
# -- Overrides for MarkdownIntegrationTests ---------------------------
|
|
|
|
def test_setup_creates_files(self, tmp_path):
|
|
from specify_cli.integrations.manifest import IntegrationManifest
|
|
|
|
i = get_integration(self.KEY)
|
|
m = IntegrationManifest(self.KEY, tmp_path)
|
|
created = i.setup(tmp_path, m)
|
|
assert len(created) > 0
|
|
cmd_files = [
|
|
f
|
|
for f in created
|
|
if "scripts" not in f.parts
|
|
and f.suffix == ".md"
|
|
and f.name != i.context_file
|
|
]
|
|
for f in cmd_files:
|
|
assert f.exists()
|
|
assert f.name.startswith("speckit-")
|
|
assert f.name.endswith(".md")
|
|
|
|
specify_file = next(
|
|
(f for f in cmd_files if f.name == "speckit-specify.md"), None
|
|
)
|
|
assert specify_file is not None
|
|
specify_contents = specify_file.read_text(encoding="utf-8")
|
|
assert "/speckit-plan" in specify_contents
|
|
assert "/speckit.plan" not in specify_contents
|
|
|
|
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",
|
|
"--ignore-agent-tools",
|
|
],
|
|
catch_exceptions=False,
|
|
)
|
|
finally:
|
|
os.chdir(old_cwd)
|
|
assert result.exit_code == 0
|
|
i = get_integration(self.KEY)
|
|
cmd_dir = i.commands_dest(project)
|
|
assert cmd_dir.is_dir()
|
|
commands = sorted(cmd_dir.glob("speckit-*"))
|
|
assert len(commands) > 0
|
|
|
|
def _expected_files(self, script_variant: str) -> list[str]:
|
|
"""Override to expect hyphenated speckit- prefix."""
|
|
i = get_integration(self.KEY)
|
|
cmd_dir = i.registrar_config["dir"]
|
|
files = []
|
|
|
|
# Command files
|
|
for stem in (
|
|
self.COMMANDS_SUBDIR_STEMS
|
|
if hasattr(self, "COMMANDS_SUBDIR_STEMS")
|
|
else self.COMMAND_STEMS
|
|
):
|
|
files.append(f"{cmd_dir}/speckit-{stem.replace('.', '-')}.md")
|
|
|
|
# Framework files
|
|
files.append(".specify/integration.json")
|
|
files.append(".specify/init-options.json")
|
|
files.append(f".specify/integrations/{self.KEY}.manifest.json")
|
|
files.append(".specify/integrations/speckit.manifest.json")
|
|
|
|
if script_variant == "sh":
|
|
for name in [
|
|
"check-prerequisites.sh",
|
|
"common.sh",
|
|
"create-new-feature.sh",
|
|
"setup-plan.sh",
|
|
"setup-tasks.sh",
|
|
]:
|
|
files.append(f".specify/scripts/bash/{name}")
|
|
else:
|
|
for name in [
|
|
"check-prerequisites.ps1",
|
|
"common.ps1",
|
|
"create-new-feature.ps1",
|
|
"setup-plan.ps1",
|
|
"setup-tasks.ps1",
|
|
]:
|
|
files.append(f".specify/scripts/powershell/{name}")
|
|
|
|
for name in [
|
|
"checklist-template.md",
|
|
"constitution-template.md",
|
|
"plan-template.md",
|
|
"spec-template.md",
|
|
"tasks-template.md",
|
|
]:
|
|
files.append(f".specify/templates/{name}")
|
|
|
|
files.append(".specify/memory/constitution.md")
|
|
# Bundled workflow
|
|
files.append(".specify/workflows/speckit/workflow.yml")
|
|
files.append(".specify/workflows/workflow-registry.json")
|
|
|
|
# Bundled agent-context extension
|
|
files.append(".specify/extensions.yml")
|
|
files.append(".specify/extensions/.registry")
|
|
files.append(".specify/extensions/agent-context/README.md")
|
|
files.append(".specify/extensions/agent-context/agent-context-config.yml")
|
|
files.append(".specify/extensions/agent-context/commands/speckit.agent-context.update.md")
|
|
files.append(".specify/extensions/agent-context/extension.yml")
|
|
files.append(".specify/extensions/agent-context/scripts/bash/update-agent-context.sh")
|
|
files.append(".specify/extensions/agent-context/scripts/powershell/update-agent-context.ps1")
|
|
|
|
# Agent context file (if set)
|
|
if i.context_file:
|
|
files.append(i.context_file)
|
|
|
|
return sorted(files)
|