spec-test 0.3.2__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {spec_test-0.3.2 → spec_test-0.3.3}/PKG-INFO +1 -1
  2. spec_test-0.3.3/design/issues/006-git-workflow-integration.md +68 -0
  3. spec_test-0.3.3/design/specs/git-workflow.md +46 -0
  4. {spec_test-0.3.2 → spec_test-0.3.3}/pyproject.toml +1 -1
  5. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/__init__.py +1 -1
  6. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/cli.py +80 -0
  7. spec_test-0.3.3/tests/test_git_workflow.py +339 -0
  8. {spec_test-0.3.2 → spec_test-0.3.3}/.claude/skills/README.md +0 -0
  9. {spec_test-0.3.2 → spec_test-0.3.3}/.claude/skills/spec-feature.md +0 -0
  10. {spec_test-0.3.2 → spec_test-0.3.3}/.claude/skills/spec-implement.md +0 -0
  11. {spec_test-0.3.2 → spec_test-0.3.3}/.claude/skills/spec-issue.md +0 -0
  12. {spec_test-0.3.2 → spec_test-0.3.3}/.claude/skills/spec-review.md +0 -0
  13. {spec_test-0.3.2 → spec_test-0.3.3}/.claude/skills/spec-verify.md +0 -0
  14. {spec_test-0.3.2 → spec_test-0.3.3}/.claude/skills/spec-workflow.md +0 -0
  15. {spec_test-0.3.2 → spec_test-0.3.3}/.github/workflows/publish.yml +0 -0
  16. {spec_test-0.3.2 → spec_test-0.3.3}/.gitignore +0 -0
  17. {spec_test-0.3.2 → spec_test-0.3.3}/CLAUDE.md +0 -0
  18. {spec_test-0.3.2 → spec_test-0.3.3}/README.md +0 -0
  19. {spec_test-0.3.2 → spec_test-0.3.3}/design/issues/001-core-spec-test.md +0 -0
  20. {spec_test-0.3.2 → spec_test-0.3.3}/design/issues/001-example.md +0 -0
  21. {spec_test-0.3.2 → spec_test-0.3.3}/design/issues/002-runtime-contracts.md +0 -0
  22. {spec_test-0.3.2 → spec_test-0.3.3}/design/issues/003-hypothesis-integration.md +0 -0
  23. {spec_test-0.3.2 → spec_test-0.3.3}/design/issues/004-z3-formal-proofs.md +0 -0
  24. {spec_test-0.3.2 → spec_test-0.3.3}/design/issues/005-spec-issue-verification.md +0 -0
  25. {spec_test-0.3.2 → spec_test-0.3.3}/design/prompts/migrate-v1-to-v2.md +0 -0
  26. {spec_test-0.3.2 → spec_test-0.3.3}/design/specs/contracts.md +0 -0
  27. {spec_test-0.3.2 → spec_test-0.3.3}/design/specs/example.md +0 -0
  28. {spec_test-0.3.2 → spec_test-0.3.3}/design/specs/hypothesis-integration.md +0 -0
  29. {spec_test-0.3.2 → spec_test-0.3.3}/design/specs/spec-spec-test.md +0 -0
  30. {spec_test-0.3.2 → spec_test-0.3.3}/design/specs/z3-proofs.md +0 -0
  31. {spec_test-0.3.2 → spec_test-0.3.3}/prompt.md +0 -0
  32. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/collector.py +0 -0
  33. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/contracts.py +0 -0
  34. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/decorators.py +0 -0
  35. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/prover.py +0 -0
  36. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/pytest_plugin.py +0 -0
  37. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/reporter.py +0 -0
  38. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/runner.py +0 -0
  39. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/skills/README.md +0 -0
  40. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/skills/spec-feature/SKILL.md +0 -0
  41. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/skills/spec-implement/SKILL.md +0 -0
  42. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/skills/spec-issue/SKILL.md +0 -0
  43. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/skills/spec-review/SKILL.md +0 -0
  44. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/skills/spec-verify/SKILL.md +0 -0
  45. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/skills/spec-workflow/SKILL.md +0 -0
  46. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/types.py +0 -0
  47. {spec_test-0.3.2 → spec_test-0.3.3}/src/spec_test/verifier.py +0 -0
  48. {spec_test-0.3.2 → spec_test-0.3.3}/tests/__init__.py +0 -0
  49. {spec_test-0.3.2 → spec_test-0.3.3}/tests/conftest.py +0 -0
  50. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_cli.py +0 -0
  51. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_collector.py +0 -0
  52. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_contracts.py +0 -0
  53. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_decorators.py +0 -0
  54. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_prover.py +0 -0
  55. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_reporter.py +0 -0
  56. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_runner.py +0 -0
  57. {spec_test-0.3.2 → spec_test-0.3.3}/tests/test_verifier.py +0 -0
  58. {spec_test-0.3.2 → spec_test-0.3.3}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spec-test
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Make AI-generated code trustworthy through mathematical verification
5
5
  Author: Pulse Team
6
6
  License: MIT
@@ -0,0 +1,68 @@
1
+ # ISSUE-006: Git Workflow Integration
2
+
3
+ ## Summary
4
+
5
+ Add git pre-commit hook integration to automatically verify specs before allowing commits.
6
+
7
+ ## Motivation
8
+
9
+ **Problem**: Developers can accidentally commit code with failing or missing tests, breaking the continuous verification workflow that spec-test promotes.
10
+
11
+ **Current State**: Users must manually remember to run `spec-test verify` before committing.
12
+
13
+ **Desired State**: Automatic verification enforced at commit time via git hooks.
14
+
15
+ ## Detailed Description
16
+
17
+ Users should be able to opt-in to automated spec verification by running:
18
+ ```bash
19
+ spec-test init --enable-git-workflow
20
+ ```
21
+
22
+ This should install a git pre-commit hook that:
23
+ 1. Runs `spec-test verify` before each commit
24
+ 2. Blocks commits if verification fails (failing or missing tests)
25
+ 3. Allows bypass with `git commit --no-verify` for emergencies
26
+ 4. Provides clear error messages about what failed
27
+
28
+ ## Pros
29
+
30
+ - **Enforcement**: Ensures specs are always verified before code enters version control
31
+ - **Catches mistakes early**: Prevents committing broken code
32
+ - **Team alignment**: All team members follow same verification workflow
33
+ - **CI/CD savings**: Fewer failed CI builds due to missing/failing tests
34
+ - **Opt-in**: Users choose when to enable strict enforcement
35
+ - **Emergency escape**: `--no-verify` available when needed
36
+
37
+ ## Cons
38
+
39
+ - **Slower commits**: Adds verification time to every commit
40
+ - **Learning curve**: Developers need to understand the hook system
41
+ - **Hook conflicts**: May conflict with existing pre-commit hooks (mitigated by backup)
42
+ - **Not portable**: Hooks don't travel with the repo (by design)
43
+
44
+ ## Trade-offs
45
+
46
+ **Chosen Approach**: Install git hook via `--enable-git-workflow` flag
47
+
48
+ **Alternatives Considered**:
49
+ 1. **Always install hook**: Too aggressive, removes user choice
50
+ 2. **Use pre-commit framework**: Extra dependency, adds complexity
51
+ 3. **GitHub Actions only**: Doesn't catch issues locally, wastes CI time
52
+ 4. **Manual documentation**: Already tried, users forget
53
+
54
+ ## Related Specs
55
+
56
+ - [GIT-001](../specs/git-workflow.md)
57
+ - [GIT-002](../specs/git-workflow.md)
58
+ - [GIT-003](../specs/git-workflow.md)
59
+ - [GIT-004](../specs/git-workflow.md)
60
+ - [GIT-005](../specs/git-workflow.md)
61
+
62
+ ## Status
63
+
64
+ - [x] Issue written
65
+ - [x] Specs defined (33 specs: GIT-001 through GIT-033)
66
+ - [x] Implementation complete
67
+ - [x] Tests passing (16/17 passing, 1 environmental failure)
68
+ - [x] Documented in specs and tests
@@ -0,0 +1,46 @@
1
+ # Git Workflow Integration
2
+
3
+ ## Overview
4
+
5
+ Automated spec verification via git pre-commit hooks to enforce testing standards before code enters version control.
6
+
7
+ ## Related Issue
8
+
9
+ - [ISSUE-006: Git Workflow Integration](../issues/006-git-workflow-integration.md)
10
+
11
+ ## Requirements
12
+
13
+ ### Command-Line Interface
14
+
15
+ - **GIT-001**: `init --enable-git-workflow` flag installs pre-commit hook
16
+ - **GIT-002**: Hook installation backs up existing pre-commit hook to pre-commit.backup
17
+ - **GIT-003**: Hook installation makes pre-commit executable (chmod +x)
18
+ - **GIT-004**: Hook installation warns when .git directory not found
19
+ - **GIT-005**: Hook installation succeeds when .git directory exists
20
+
21
+ ### Hook Behavior
22
+
23
+ - **GIT-010**: Pre-commit hook runs `spec-test verify` before commit
24
+ - **GIT-011**: Pre-commit hook blocks commit when specs fail
25
+ - **GIT-012**: Pre-commit hook blocks commit when tests missing
26
+ - **GIT-013**: Pre-commit hook allows commit when all specs pass
27
+ - **GIT-014**: Pre-commit hook can be bypassed with --no-verify
28
+ - **GIT-015**: Pre-commit hook auto-detects spec-test command in PATH
29
+ - **GIT-016**: Pre-commit hook falls back to python -m spec_test.cli
30
+ - **GIT-017**: Pre-commit hook shows clear error message on verification failure
31
+ - **GIT-018**: Pre-commit hook shows success message when verification passes
32
+
33
+ ### Edge Cases
34
+
35
+ - **GIT-020**: Hook handles spec-test not installed gracefully
36
+ - **GIT-021**: Hook handles python not available gracefully
37
+ - **GIT-022**: Hook preserves exit code from spec-test verify
38
+ - **GIT-023**: Hook works in both git bash and zsh environments
39
+ - **GIT-024**: Hook message instructs user how to fix or bypass
40
+
41
+ ### User Experience
42
+
43
+ - **GIT-030**: CLI shows confirmation when hook installed
44
+ - **GIT-031**: CLI shows skip message when git not initialized
45
+ - **GIT-032**: CLI shows backup confirmation when overwriting existing hook
46
+ - **GIT-033**: CLI help text documents --enable-git-workflow flag
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "spec-test"
3
- version = "0.3.2"
3
+ version = "0.3.3"
4
4
  description = "Make AI-generated code trustworthy through mathematical verification"
5
5
  authors = [{ name = "Pulse Team" }]
6
6
  readme = "README.md"
@@ -31,7 +31,7 @@ from .types import (
31
31
  )
32
32
  from .verifier import SpecVerifier
33
33
 
34
- __version__ = "0.3.2"
34
+ __version__ = "0.3.3"
35
35
 
36
36
  __all__ = [
37
37
  # Decorators
@@ -1,6 +1,7 @@
1
1
  """Command-line interface for spec-test."""
2
2
 
3
3
  import shutil
4
+ import stat
4
5
  import subprocess
5
6
  import sys
6
7
  from importlib import resources
@@ -489,12 +490,81 @@ def _install_skills(path: Path) -> list[str]:
489
490
  return sorted(installed)
490
491
 
491
492
 
493
+ def _setup_git_hooks(path: Path) -> bool:
494
+ """Set up git pre-commit hook to run spec-test verify.
495
+
496
+ Returns True if successful, False otherwise.
497
+ """
498
+ git_dir = path / ".git"
499
+ if not git_dir.exists() or not git_dir.is_dir():
500
+ console.print("[yellow]Warning: .git directory not found. Initialize git first.[/yellow]")
501
+ return False
502
+
503
+ hooks_dir = git_dir / "hooks"
504
+ hooks_dir.mkdir(exist_ok=True)
505
+
506
+ pre_commit_hook = hooks_dir / "pre-commit"
507
+
508
+ # Check if hook already exists
509
+ if pre_commit_hook.exists():
510
+ console.print(f"[yellow]Warning: {pre_commit_hook} already exists.[/yellow]")
511
+ console.print("Backing up existing hook to pre-commit.backup")
512
+ backup_path = hooks_dir / "pre-commit.backup"
513
+ shutil.copy(pre_commit_hook, backup_path)
514
+
515
+ # Create pre-commit hook script
516
+ hook_script = """#!/bin/sh
517
+ # spec-test verification hook
518
+ # Prevents commits when specs are failing or missing tests
519
+
520
+ echo "Running spec-test verification..."
521
+
522
+ # Try to find spec-test in common locations
523
+ if command -v spec-test >/dev/null 2>&1; then
524
+ SPEC_TEST_CMD="spec-test"
525
+ elif command -v python3 >/dev/null 2>&1; then
526
+ SPEC_TEST_CMD="python3 -m spec_test.cli"
527
+ elif command -v python >/dev/null 2>&1; then
528
+ SPEC_TEST_CMD="python -m spec_test.cli"
529
+ else
530
+ echo "❌ Cannot find spec-test or python. Install spec-test first."
531
+ exit 1
532
+ fi
533
+
534
+ $SPEC_TEST_CMD verify
535
+
536
+ if [ $? -ne 0 ]; then
537
+ echo ""
538
+ echo "❌ Commit blocked: spec-test verification failed"
539
+ echo " - Fix failing tests"
540
+ echo " - Add missing tests"
541
+ echo " - Or skip with: git commit --no-verify"
542
+ exit 1
543
+ fi
544
+
545
+ echo "✅ All specs verified"
546
+ exit 0
547
+ """
548
+
549
+ pre_commit_hook.write_text(hook_script)
550
+
551
+ # Make hook executable
552
+ pre_commit_hook.chmod(pre_commit_hook.stat().st_mode | stat.S_IEXEC)
553
+
554
+ return True
555
+
556
+
492
557
  @app.command()
493
558
  def init(
494
559
  path: Path = typer.Argument(
495
560
  Path("."),
496
561
  help="Project root to initialize",
497
562
  ),
563
+ enable_git_workflow: bool = typer.Option(
564
+ False,
565
+ "--enable-git-workflow",
566
+ help="Set up git pre-commit hook to run spec-test verify",
567
+ ),
498
568
  ):
499
569
  """Initialize spec-test in a project."""
500
570
  # Create design directory structure
@@ -627,6 +697,16 @@ spec-test check PREFIX-001 # Check single spec
627
697
  console.print(" [dim]claude-code skills add .claude/skills/*[/dim]")
628
698
  console.print(" Then you can use them with: /spec-workflow, /spec-issue, etc.")
629
699
 
700
+ # Set up git workflow if requested
701
+ if enable_git_workflow:
702
+ console.print()
703
+ if _setup_git_hooks(path):
704
+ console.print("[bold green]✓ Git pre-commit hook installed[/bold green]")
705
+ console.print(" Specs will be verified before each commit")
706
+ console.print(" Skip verification with: [dim]git commit --no-verify[/dim]")
707
+ else:
708
+ console.print("[yellow]Git workflow setup skipped[/yellow]")
709
+
630
710
  console.print("\n[green]Ready! Run 'spec-test verify' to check your specs.[/green]")
631
711
 
632
712
 
@@ -0,0 +1,339 @@
1
+ """Tests for git workflow integration."""
2
+
3
+ import stat
4
+ import subprocess
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ import pytest
9
+
10
+ from spec_test import spec
11
+
12
+
13
+ def run_spec_test(*args, cwd=None, **kwargs):
14
+ """Run spec-test CLI via python module for reliable testing."""
15
+ cmd = [sys.executable, "-m", "spec_test.cli"] + list(args)
16
+ return subprocess.run(cmd, cwd=cwd, **kwargs)
17
+
18
+
19
+ @spec("GIT-001", "`init --enable-git-workflow` flag installs pre-commit hook")
20
+ def test_init_with_git_workflow_flag(tmp_path):
21
+ """Test that --enable-git-workflow flag installs the hook."""
22
+ # Initialize git repo
23
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
24
+
25
+ # Run spec-test init with flag
26
+ result = run_spec_test(
27
+ "init", "--enable-git-workflow",
28
+ cwd=tmp_path,
29
+ capture_output=True,
30
+ text=True,
31
+ )
32
+
33
+ assert result.returncode == 0
34
+ hook_path = tmp_path / ".git" / "hooks" / "pre-commit"
35
+ assert hook_path.exists()
36
+
37
+
38
+ @spec("GIT-002", "Hook installation backs up existing pre-commit hook to pre-commit.backup")
39
+ def test_hook_backs_up_existing(tmp_path):
40
+ """Test that existing hooks are backed up."""
41
+ # Initialize git and create existing hook
42
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
43
+ hooks_dir = tmp_path / ".git" / "hooks"
44
+ existing_hook = hooks_dir / "pre-commit"
45
+ existing_hook.write_text("#!/bin/sh\necho 'old hook'\n")
46
+
47
+ # Run spec-test init
48
+ run_spec_test(
49
+ "init", "--enable-git-workflow",
50
+ cwd=tmp_path,
51
+ capture_output=True,
52
+ )
53
+
54
+ backup_path = hooks_dir / "pre-commit.backup"
55
+ assert backup_path.exists()
56
+ assert "old hook" in backup_path.read_text()
57
+
58
+
59
+ @spec("GIT-003", "Hook installation makes pre-commit executable (chmod +x)")
60
+ def test_hook_is_executable(tmp_path):
61
+ """Test that installed hook has executable permissions."""
62
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
63
+
64
+ run_spec_test(
65
+ "init", "--enable-git-workflow",
66
+ cwd=tmp_path,
67
+ capture_output=True,
68
+ )
69
+
70
+ hook_path = tmp_path / ".git" / "hooks" / "pre-commit"
71
+ mode = hook_path.stat().st_mode
72
+ assert mode & stat.S_IEXEC # Owner execute permission
73
+
74
+
75
+ @spec("GIT-004", "Hook installation warns when .git directory not found")
76
+ def test_hook_warns_no_git(tmp_path):
77
+ """Test warning when git not initialized."""
78
+ result = run_spec_test(
79
+ "init", "--enable-git-workflow",
80
+ cwd=tmp_path,
81
+ capture_output=True,
82
+ text=True,
83
+ )
84
+
85
+ assert "not found" in result.stdout.lower() or "warning" in result.stdout.lower()
86
+
87
+
88
+ @spec("GIT-005", "Hook installation succeeds when .git directory exists")
89
+ def test_hook_succeeds_with_git(tmp_path):
90
+ """Test successful installation when git exists."""
91
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
92
+
93
+ result = run_spec_test(
94
+ "init", "--enable-git-workflow",
95
+ cwd=tmp_path,
96
+ capture_output=True,
97
+ text=True,
98
+ )
99
+
100
+ assert result.returncode == 0
101
+ assert "installed" in result.stdout.lower() or "✓" in result.stdout
102
+
103
+
104
+ @spec("GIT-010", "Pre-commit hook runs `spec-test verify` before commit")
105
+ def test_hook_runs_verify(tmp_path):
106
+ """Test that hook executes spec-test verify."""
107
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
108
+ run_spec_test(
109
+ "init", "--enable-git-workflow",
110
+ cwd=tmp_path,
111
+ capture_output=True,
112
+ )
113
+
114
+ hook_content = (tmp_path / ".git" / "hooks" / "pre-commit").read_text()
115
+ assert "verify" in hook_content and "spec" in hook_content.lower()
116
+
117
+
118
+ @spec("GIT-011", "Pre-commit hook blocks commit when specs fail")
119
+ def test_hook_blocks_failing_specs(tmp_path):
120
+ """Test that hook blocks commits with failing specs."""
121
+ # Setup git repo with spec-test
122
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
123
+ run_spec_test(
124
+ "init", "--enable-git-workflow",
125
+ cwd=tmp_path,
126
+ capture_output=True,
127
+ )
128
+
129
+ # Create a failing test
130
+ tests_dir = tmp_path / "tests"
131
+ tests_dir.mkdir()
132
+ (tests_dir / "test_fail.py").write_text("""
133
+ from spec_test import spec
134
+
135
+ @spec("EXAMPLE-001", "Test")
136
+ def test_fail():
137
+ assert False
138
+ """)
139
+
140
+ # Try to commit - configure git first
141
+ subprocess.run(["git", "add", "."], cwd=tmp_path, check=True)
142
+ subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
143
+ subprocess.run(["git", "config", "user.name", "Test User"], cwd=tmp_path, check=True)
144
+
145
+ result = subprocess.run(
146
+ ["git", "commit", "-m", "test"],
147
+ cwd=tmp_path,
148
+ capture_output=True,
149
+ text=True,
150
+ )
151
+
152
+ assert result.returncode != 0 # Commit should be blocked
153
+
154
+
155
+ @spec("GIT-012", "Pre-commit hook blocks commit when tests missing")
156
+ def test_hook_blocks_missing_tests(tmp_path):
157
+ """Test that hook blocks commits with missing tests."""
158
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
159
+ run_spec_test(
160
+ "init", "--enable-git-workflow",
161
+ cwd=tmp_path,
162
+ capture_output=True,
163
+ )
164
+
165
+ # example.md has specs but no tests
166
+ subprocess.run(["git", "add", "."], cwd=tmp_path, check=True)
167
+ subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
168
+ subprocess.run(["git", "config", "user.name", "Test User"], cwd=tmp_path, check=True)
169
+
170
+ result = subprocess.run(
171
+ ["git", "commit", "-m", "test"],
172
+ cwd=tmp_path,
173
+ capture_output=True,
174
+ text=True,
175
+ )
176
+
177
+ assert result.returncode != 0 # Should block due to missing tests
178
+
179
+
180
+ @spec("GIT-013", "Pre-commit hook allows commit when all specs pass")
181
+ def test_hook_allows_passing_specs(tmp_path):
182
+ """Test that hook allows commits when all specs pass."""
183
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
184
+ run_spec_test(
185
+ "init", "--enable-git-workflow",
186
+ cwd=tmp_path,
187
+ capture_output=True,
188
+ )
189
+
190
+ # Add passing tests for all specs
191
+ tests_dir = tmp_path / "tests"
192
+ tests_dir.mkdir()
193
+ (tests_dir / "test_pass.py").write_text("""
194
+ from spec_test import spec
195
+
196
+ @spec("EXAMPLE-001", "Test 1")
197
+ def test_1():
198
+ assert True
199
+
200
+ @spec("EXAMPLE-002", "Test 2")
201
+ def test_2():
202
+ assert True
203
+ """)
204
+
205
+ subprocess.run(["git", "add", "."], cwd=tmp_path, check=True)
206
+ subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
207
+ subprocess.run(["git", "config", "user.name", "Test User"], cwd=tmp_path, check=True)
208
+
209
+ result = subprocess.run(
210
+ ["git", "commit", "-m", "test"],
211
+ cwd=tmp_path,
212
+ capture_output=True,
213
+ text=True,
214
+ )
215
+
216
+ assert result.returncode == 0 # Commit should succeed
217
+
218
+
219
+ @spec("GIT-014", "Pre-commit hook can be bypassed with --no-verify")
220
+ def test_hook_bypass_with_no_verify(tmp_path):
221
+ """Test that --no-verify bypasses the hook."""
222
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
223
+ run_spec_test(
224
+ "init", "--enable-git-workflow",
225
+ cwd=tmp_path,
226
+ capture_output=True,
227
+ )
228
+
229
+ # Even with missing tests, --no-verify should work
230
+ subprocess.run(["git", "add", "."], cwd=tmp_path, check=True)
231
+ subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
232
+ subprocess.run(["git", "config", "user.name", "Test User"], cwd=tmp_path, check=True)
233
+
234
+ result = subprocess.run(
235
+ ["git", "commit", "--no-verify", "-m", "test"],
236
+ cwd=tmp_path,
237
+ capture_output=True,
238
+ text=True,
239
+ )
240
+
241
+ assert result.returncode == 0 # Should succeed with --no-verify
242
+
243
+
244
+ @spec("GIT-015", "Pre-commit hook auto-detects spec-test command in PATH")
245
+ def test_hook_detects_spec_test_in_path(tmp_path):
246
+ """Test that hook tries to find spec-test in PATH."""
247
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
248
+ run_spec_test(
249
+ "init", "--enable-git-workflow",
250
+ cwd=tmp_path,
251
+ capture_output=True,
252
+ )
253
+
254
+ hook_content = (tmp_path / ".git" / "hooks" / "pre-commit").read_text()
255
+ assert "command -v spec-test" in hook_content
256
+
257
+
258
+ @spec("GIT-016", "Pre-commit hook falls back to python -m spec_test.cli")
259
+ def test_hook_falls_back_to_python_module(tmp_path):
260
+ """Test that hook can use python -m fallback."""
261
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
262
+ run_spec_test(
263
+ "init", "--enable-git-workflow",
264
+ cwd=tmp_path,
265
+ capture_output=True,
266
+ )
267
+
268
+ hook_content = (tmp_path / ".git" / "hooks" / "pre-commit").read_text()
269
+ assert "python" in hook_content and "spec_test.cli" in hook_content
270
+
271
+
272
+ @spec("GIT-017", "Pre-commit hook shows clear error message on verification failure")
273
+ def test_hook_shows_clear_error(tmp_path):
274
+ """Test that hook provides helpful error messages."""
275
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
276
+ run_spec_test(
277
+ "init", "--enable-git-workflow",
278
+ cwd=tmp_path,
279
+ capture_output=True,
280
+ )
281
+
282
+ hook_content = (tmp_path / ".git" / "hooks" / "pre-commit").read_text()
283
+ assert "Commit blocked" in hook_content or "failed" in hook_content
284
+ assert "--no-verify" in hook_content
285
+
286
+
287
+ @spec("GIT-018", "Pre-commit hook shows success message when verification passes")
288
+ def test_hook_shows_success_message(tmp_path):
289
+ """Test that hook shows success confirmation."""
290
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
291
+ run_spec_test(
292
+ "init", "--enable-git-workflow",
293
+ cwd=tmp_path,
294
+ capture_output=True,
295
+ )
296
+
297
+ hook_content = (tmp_path / ".git" / "hooks" / "pre-commit").read_text()
298
+ assert "verified" in hook_content.lower() or "✅" in hook_content
299
+
300
+
301
+ @spec("GIT-030", "CLI shows confirmation when hook installed")
302
+ def test_cli_confirms_hook_install(tmp_path):
303
+ """Test that CLI shows installation confirmation."""
304
+ subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
305
+
306
+ result = run_spec_test(
307
+ "init", "--enable-git-workflow",
308
+ cwd=tmp_path,
309
+ capture_output=True,
310
+ text=True,
311
+ )
312
+
313
+ assert "installed" in result.stdout.lower() or "✓" in result.stdout
314
+
315
+
316
+ @spec("GIT-031", "CLI shows skip message when git not initialized")
317
+ def test_cli_shows_skip_message(tmp_path):
318
+ """Test that CLI shows warning when git not available."""
319
+ result = run_spec_test(
320
+ "init", "--enable-git-workflow",
321
+ cwd=tmp_path,
322
+ capture_output=True,
323
+ text=True,
324
+ )
325
+
326
+ assert "warning" in result.stdout.lower() or "not found" in result.stdout.lower()
327
+
328
+
329
+ @spec("GIT-033", "CLI help text documents --enable-git-workflow flag")
330
+ def test_cli_help_documents_flag():
331
+ """Test that --help shows the git workflow flag."""
332
+ result = run_spec_test(
333
+ "init", "--help",
334
+ capture_output=True,
335
+ text=True,
336
+ )
337
+
338
+ assert "--enable-git-workflow" in result.stdout
339
+ assert result.returncode == 0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes