spec-test 0.3.1__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.1 → spec_test-0.3.3}/PKG-INFO +1 -1
  2. spec_test-0.3.3/design/issues/001-example.md +26 -0
  3. spec_test-0.3.3/design/issues/006-git-workflow-integration.md +68 -0
  4. spec_test-0.3.3/design/specs/example.md +14 -0
  5. spec_test-0.3.3/design/specs/git-workflow.md +46 -0
  6. {spec_test-0.3.1 → spec_test-0.3.3}/pyproject.toml +1 -1
  7. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/__init__.py +1 -1
  8. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/cli.py +127 -14
  9. spec_test-0.3.3/src/spec_test/skills/README.md +177 -0
  10. spec_test-0.3.3/src/spec_test/skills/spec-feature/SKILL.md +212 -0
  11. spec_test-0.3.3/src/spec_test/skills/spec-implement/SKILL.md +549 -0
  12. spec_test-0.3.3/src/spec_test/skills/spec-issue/SKILL.md +219 -0
  13. spec_test-0.3.3/src/spec_test/skills/spec-review/SKILL.md +277 -0
  14. spec_test-0.3.3/src/spec_test/skills/spec-verify/SKILL.md +259 -0
  15. spec_test-0.3.3/src/spec_test/skills/spec-workflow/SKILL.md +300 -0
  16. spec_test-0.3.3/tests/test_git_workflow.py +339 -0
  17. {spec_test-0.3.1/src/spec_test → spec_test-0.3.3/.claude}/skills/README.md +0 -0
  18. {spec_test-0.3.1/src/spec_test → spec_test-0.3.3/.claude}/skills/spec-feature.md +0 -0
  19. {spec_test-0.3.1/src/spec_test → spec_test-0.3.3/.claude}/skills/spec-implement.md +0 -0
  20. {spec_test-0.3.1/src/spec_test → spec_test-0.3.3/.claude}/skills/spec-issue.md +0 -0
  21. {spec_test-0.3.1/src/spec_test → spec_test-0.3.3/.claude}/skills/spec-review.md +0 -0
  22. {spec_test-0.3.1/src/spec_test → spec_test-0.3.3/.claude}/skills/spec-verify.md +0 -0
  23. {spec_test-0.3.1/src/spec_test → spec_test-0.3.3/.claude}/skills/spec-workflow.md +0 -0
  24. {spec_test-0.3.1 → spec_test-0.3.3}/.github/workflows/publish.yml +0 -0
  25. {spec_test-0.3.1 → spec_test-0.3.3}/.gitignore +0 -0
  26. {spec_test-0.3.1 → spec_test-0.3.3}/CLAUDE.md +0 -0
  27. {spec_test-0.3.1 → spec_test-0.3.3}/README.md +0 -0
  28. {spec_test-0.3.1 → spec_test-0.3.3}/design/issues/001-core-spec-test.md +0 -0
  29. {spec_test-0.3.1 → spec_test-0.3.3}/design/issues/002-runtime-contracts.md +0 -0
  30. {spec_test-0.3.1 → spec_test-0.3.3}/design/issues/003-hypothesis-integration.md +0 -0
  31. {spec_test-0.3.1 → spec_test-0.3.3}/design/issues/004-z3-formal-proofs.md +0 -0
  32. {spec_test-0.3.1 → spec_test-0.3.3}/design/issues/005-spec-issue-verification.md +0 -0
  33. {spec_test-0.3.1 → spec_test-0.3.3}/design/prompts/migrate-v1-to-v2.md +0 -0
  34. {spec_test-0.3.1 → spec_test-0.3.3}/design/specs/contracts.md +0 -0
  35. {spec_test-0.3.1 → spec_test-0.3.3}/design/specs/hypothesis-integration.md +0 -0
  36. {spec_test-0.3.1 → spec_test-0.3.3}/design/specs/spec-spec-test.md +0 -0
  37. {spec_test-0.3.1 → spec_test-0.3.3}/design/specs/z3-proofs.md +0 -0
  38. {spec_test-0.3.1 → spec_test-0.3.3}/prompt.md +0 -0
  39. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/collector.py +0 -0
  40. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/contracts.py +0 -0
  41. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/decorators.py +0 -0
  42. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/prover.py +0 -0
  43. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/pytest_plugin.py +0 -0
  44. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/reporter.py +0 -0
  45. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/runner.py +0 -0
  46. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/types.py +0 -0
  47. {spec_test-0.3.1 → spec_test-0.3.3}/src/spec_test/verifier.py +0 -0
  48. {spec_test-0.3.1 → spec_test-0.3.3}/tests/__init__.py +0 -0
  49. {spec_test-0.3.1 → spec_test-0.3.3}/tests/conftest.py +0 -0
  50. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_cli.py +0 -0
  51. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_collector.py +0 -0
  52. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_contracts.py +0 -0
  53. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_decorators.py +0 -0
  54. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_prover.py +0 -0
  55. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_reporter.py +0 -0
  56. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_runner.py +0 -0
  57. {spec_test-0.3.1 → spec_test-0.3.3}/tests/test_verifier.py +0 -0
  58. {spec_test-0.3.1 → 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.1
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,26 @@
1
+ # ISSUE-001: Example Feature
2
+
3
+ ## Summary
4
+ Brief description of what this feature/change is about.
5
+
6
+ ## Motivation
7
+ Why are we doing this? What problem does it solve?
8
+
9
+ ## Detailed Description
10
+ Full details of the intended behavior, edge cases, and considerations.
11
+
12
+ ## Pros
13
+ - List benefits
14
+
15
+ ## Cons
16
+ - List drawbacks or trade-offs
17
+
18
+ ## Related Specs
19
+ - [EXAMPLE-001](../specs/example.md)
20
+ - [EXAMPLE-002](../specs/example.md)
21
+
22
+ ## Status
23
+ - [ ] Issue written
24
+ - [ ] Specs defined
25
+ - [ ] Implementation complete
26
+ - [ ] Tests passing
@@ -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,14 @@
1
+ # Example Specification
2
+
3
+ ## Overview
4
+ This is an example specification file. Replace with your actual specs.
5
+
6
+ ## Related Issue
7
+ - [ISSUE-001](../issues/001-example.md)
8
+
9
+ ## Requirements
10
+
11
+ ### Core Features
12
+ - **EXAMPLE-001**: The system should do something useful
13
+ - **EXAMPLE-002**: The system should handle errors gracefully
14
+ - **EXAMPLE-003** [manual]: Code follows project naming conventions
@@ -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.1"
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.0"
34
+ __version__ = "0.3.3"
35
35
 
36
36
  __all__ = [
37
37
  # Decorators
@@ -1,5 +1,7 @@
1
1
  """Command-line interface for spec-test."""
2
2
 
3
+ import shutil
4
+ import stat
3
5
  import subprocess
4
6
  import sys
5
7
  from importlib import resources
@@ -10,6 +12,7 @@ import typer
10
12
  from rich.console import Console
11
13
  from rich.panel import Panel
12
14
 
15
+ from . import __version__
13
16
  from .collector import collect_specs
14
17
  from .prover import (
15
18
  ProofResult,
@@ -26,6 +29,27 @@ app = typer.Typer(
26
29
  console = Console()
27
30
 
28
31
 
32
+ def version_callback(value: bool):
33
+ """Display version and exit."""
34
+ if value:
35
+ console.print(f"spec-test version {__version__}")
36
+ raise typer.Exit()
37
+
38
+
39
+ @app.callback()
40
+ def main(
41
+ version: Optional[bool] = typer.Option(
42
+ None,
43
+ "--version",
44
+ help="Show version and exit",
45
+ callback=version_callback,
46
+ is_eager=True,
47
+ ),
48
+ ):
49
+ """spec-test: Make AI-generated code trustworthy through mathematical verification."""
50
+ pass
51
+
52
+
29
53
  @app.command()
30
54
  def verify(
31
55
  specs_dir: Path = typer.Option(
@@ -424,9 +448,9 @@ def _install_skills(path: Path) -> list[str]:
424
448
  except (TypeError, AttributeError, FileNotFoundError):
425
449
  pass
426
450
 
427
- # Fall back to project root for development mode
428
- # __file__ is src/spec_test/cli.py, so .parent.parent.parent gets to project root
429
- dev_skills = Path(__file__).parent.parent.parent / "skills"
451
+ # Fall back to src/spec_test/skills for development mode
452
+ # __file__ is src/spec_test/cli.py
453
+ dev_skills = Path(__file__).parent / "skills"
430
454
  if dev_skills.exists() and dev_skills.is_dir():
431
455
  skills_sources.append(("dev", dev_skills))
432
456
 
@@ -440,28 +464,107 @@ def _install_skills(path: Path) -> list[str]:
440
464
 
441
465
  if source_type == "package":
442
466
  # Use importlib.resources traversable
443
- for skill_file in source_path.iterdir():
444
- if skill_file.is_file() and skill_file.name.endswith(".md"):
445
- dest = skills_dir / skill_file.name
446
- dest.write_text(skill_file.read_text())
447
- installed.append(skill_file.name)
467
+ for skill_item in source_path.iterdir():
468
+ # Copy skill directories (each contains SKILL.md)
469
+ if skill_item.is_dir() and skill_item.name.startswith("spec-"):
470
+ dest_dir = skills_dir / skill_item.name
471
+ dest_dir.mkdir(exist_ok=True)
472
+
473
+ # Copy SKILL.md from the skill directory
474
+ skill_file = skill_item / "SKILL.md"
475
+ if skill_file.exists():
476
+ dest_file = dest_dir / "SKILL.md"
477
+ dest_file.write_text(skill_file.read_text())
478
+ installed.append(skill_item.name)
448
479
  else:
449
480
  # Use regular Path for dev mode
450
- for skill_file in source_path.iterdir():
451
- if skill_file.is_file() and skill_file.name.endswith(".md"):
452
- dest = skills_dir / skill_file.name
453
- dest.write_text(skill_file.read_text())
454
- installed.append(skill_file.name)
481
+ for skill_item in source_path.iterdir():
482
+ # Copy skill directories (each contains SKILL.md)
483
+ if skill_item.is_dir() and skill_item.name.startswith("spec-"):
484
+ dest_dir = skills_dir / skill_item.name
485
+ if dest_dir.exists():
486
+ shutil.rmtree(dest_dir)
487
+ shutil.copytree(skill_item, dest_dir)
488
+ installed.append(skill_item.name)
455
489
 
456
490
  return sorted(installed)
457
491
 
458
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
+
459
557
  @app.command()
460
558
  def init(
461
559
  path: Path = typer.Argument(
462
560
  Path("."),
463
561
  help="Project root to initialize",
464
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
+ ),
465
568
  ):
466
569
  """Initialize spec-test in a project."""
467
570
  # Create design directory structure
@@ -591,9 +694,19 @@ spec-test check PREFIX-001 # Check single spec
591
694
  console.print(f" - {skill}")
592
695
  console.print("\n[yellow]To use these skills with Claude Code:[/yellow]")
593
696
  console.print(" Add them to your agent system by running:")
594
- console.print(" [dim]claude-code skills add .claude/skills/*.md[/dim]")
697
+ console.print(" [dim]claude-code skills add .claude/skills/*[/dim]")
595
698
  console.print(" Then you can use them with: /spec-workflow, /spec-issue, etc.")
596
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
+
597
710
  console.print("\n[green]Ready! Run 'spec-test verify' to check your specs.[/green]")
598
711
 
599
712
 
@@ -0,0 +1,177 @@
1
+ # spec-test AI Agent Skills
2
+
3
+ ## Overview
4
+
5
+ These skills provide instructions for AI agents (like Claude) to effectively use spec-test for specification-driven development. When a user runs `spec-test init`, these skills are copied to the user's `.claude/skills/` directory.
6
+
7
+ ## Available Skills
8
+
9
+ | Skill | File | Purpose |
10
+ |-------|------|---------|
11
+ | Workflow | `spec-workflow.md` | Complete spec-driven development workflow |
12
+ | Create Issue | `spec-issue.md` | Document intentions before writing specs |
13
+ | Create Feature | `spec-feature.md` | Define features and write formal specifications |
14
+ | Implement Specs | `spec-implement.md` | Write code that matches specifications |
15
+ | Verify Specs | `spec-verify.md` | Run verification and fix issues |
16
+ | Review Specs | `spec-review.md` | Review specifications for completeness |
17
+
18
+ ## Installation
19
+
20
+ Skills are automatically installed when you run:
21
+
22
+ ```bash
23
+ spec-test init
24
+ ```
25
+
26
+ This copies skills to `.claude/skills/` in your project directory.
27
+
28
+ ### Manual Installation
29
+
30
+ To manually install skills, copy the contents of this directory to your project:
31
+
32
+ ```bash
33
+ mkdir -p .claude/skills
34
+ cp -r /path/to/spec-test/skills/*.md .claude/skills/
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ 1. **Starting a new feature**: Use `spec-feature` to define requirements first
40
+ 2. **Writing code**: Use `spec-implement` to write tests and implementation
41
+ 3. **Checking your work**: Use `spec-verify` to ensure all specs pass
42
+ 4. **Code review**: Use `spec-review` to validate spec completeness
43
+
44
+ ## Workflow Summary
45
+
46
+ ```
47
+ Write Issue --> Define Specs --> Implement Code --> Verify --> Review
48
+ | | | | |
49
+ spec-issue spec-feature spec-implement spec-verify spec-review
50
+ (why) (what) (how) (check) (approve)
51
+ ```
52
+
53
+ See `spec-workflow.md` for the complete workflow guide.
54
+
55
+ ## Key Concepts
56
+
57
+ ### Specification IDs
58
+
59
+ Every requirement has a unique ID following the pattern `PREFIX-NNN`:
60
+
61
+ - `AUTH-001` - Authentication requirement 1
62
+ - `CART-003` - Shopping cart requirement 3
63
+ - `API-012` - API requirement 12
64
+
65
+ ### The `@spec` Decorator
66
+
67
+ Tests are linked to specs using the `@spec` decorator:
68
+
69
+ ```python
70
+ from spec_test import spec
71
+
72
+ @spec("AUTH-001", "User can log in with valid credentials")
73
+ def test_login_success():
74
+ result = login("user@example.com", "password123")
75
+ assert result.success
76
+ ```
77
+
78
+ ### Verification Types
79
+
80
+ Specs can have verification types in brackets:
81
+
82
+ - `**ID**: Description` - Automated test (default)
83
+ - `**ID** [integration]: Description` - Integration test (real I/O)
84
+ - `**ID** [manual]: Description` - Manual verification required
85
+ - `**ID** [contract]: Description` - Contract/property verification
86
+ - `**ID** [provable]: Description` - Z3 formal proof
87
+
88
+ ## Architecture Principles
89
+
90
+ All code should follow **Functional Core, Imperative Shell** with **Dependency Injection**:
91
+
92
+ ```
93
+ ┌─────────────────────────────────────────────────────────────┐
94
+ │ Imperative Shell │
95
+ │ (thin layer, injected dependencies) │
96
+ │ ┌───────────────────────────────────────────────────────┐ │
97
+ │ │ Functional Core │ │
98
+ │ │ (pure functions, all business logic) │ │
99
+ │ │ │ │
100
+ │ │ • Deterministic (same input → same output) │ │
101
+ │ │ • No side effects │ │
102
+ │ │ • Easy to test (unit tests) │ │
103
+ │ │ • Can be formally proven (Z3) │ │
104
+ │ └───────────────────────────────────────────────────────┘ │
105
+ │ │
106
+ │ • Database, Email, API calls via DI │
107
+ │ • Testable with mocks │
108
+ │ • Integration tests verify real I/O │
109
+ └─────────────────────────────────────────────────────────────┘
110
+ ```
111
+
112
+ ### Testing Strategy
113
+
114
+ ```
115
+ ┌─────────────┬────────────────┬─────────────────────┬───────────┐
116
+ │ Test Type │ What │ How │ Speed │
117
+ ├─────────────┼────────────────┼─────────────────────┼───────────┤
118
+ │ Unit │ Pure functions │ Direct call │ Fast (ms) │
119
+ ├─────────────┼────────────────┼─────────────────────┼───────────┤
120
+ │ Mock │ Service wiring │ Inject mocks via DI │ Fast (ms) │
121
+ ├─────────────┼────────────────┼─────────────────────┼───────────┤
122
+ │ Integration │ Real I/O works │ Real DB/API │ Slow (s) │
123
+ └─────────────┴────────────────┴─────────────────────┴───────────┘
124
+ ```
125
+
126
+ **Aim for ~90% unit/mock tests, ~10% integration tests.**
127
+
128
+ ### Example
129
+
130
+ ```python
131
+ # FUNCTIONAL CORE: Pure function, no dependencies
132
+ def calculate_total(items: list[Item]) -> Decimal:
133
+ return sum(item.price * item.quantity for item in items)
134
+
135
+ # IMPERATIVE SHELL: Thin layer with injected dependencies
136
+ class OrderService:
137
+ def __init__(self, db: Database, email: EmailSender): # DI
138
+ self.db = db
139
+ self.email = email
140
+
141
+ def place_order(self, items: list[Item]) -> Order:
142
+ total = calculate_total(items) # Call pure function
143
+ order = Order(items=items, total=total)
144
+ self.db.save(order) # Injected dependency
145
+ self.email.send_confirmation() # Injected dependency
146
+ return order
147
+
148
+ # TESTS
149
+ @spec("ORDER-001", "Total is sum of item prices")
150
+ def test_calculate_total(): # Unit test - pure function
151
+ items = [Item(price=Decimal("10"), quantity=2)]
152
+ assert calculate_total(items) == Decimal("20")
153
+
154
+ @spec("ORDER-002", "Order saved to database")
155
+ def test_order_saved(): # Mock test - inject mock
156
+ mock_db = MockDatabase()
157
+ service = OrderService(db=mock_db, email=MockEmail())
158
+ service.place_order([Item(...)])
159
+ assert len(mock_db.saved) == 1
160
+
161
+ @spec("ORDER-003", "Order persists to real database")
162
+ @pytest.mark.integration
163
+ def test_order_persists(): # Integration test - real I/O
164
+ service = OrderService(db=real_db, email=mock_email)
165
+ order = service.place_order([Item(...)])
166
+ assert real_db.get(order.id) is not None
167
+ ```
168
+
169
+ ## Commands Reference
170
+
171
+ ```bash
172
+ spec-test verify # Verify all specs have passing tests
173
+ spec-test list-specs # List all specifications
174
+ spec-test check ID # Check a single spec
175
+ spec-test init # Initialize spec-test in a project
176
+ spec-test context # Output CLAUDE.md for LLM context
177
+ ```