spec-test 0.1.3__tar.gz → 0.3.0__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 (53) hide show
  1. {spec_test-0.1.3 → spec_test-0.3.0}/.gitignore +1 -0
  2. spec_test-0.3.0/CLAUDE.md +71 -0
  3. spec_test-0.3.0/PKG-INFO +426 -0
  4. spec_test-0.3.0/README.md +404 -0
  5. spec_test-0.3.0/design/issues/001-core-spec-test.md +71 -0
  6. spec_test-0.3.0/design/issues/002-runtime-contracts.md +88 -0
  7. spec_test-0.3.0/design/issues/003-hypothesis-integration.md +94 -0
  8. spec_test-0.3.0/design/issues/004-z3-formal-proofs.md +104 -0
  9. spec_test-0.3.0/design/issues/005-spec-issue-verification.md +82 -0
  10. spec_test-0.3.0/design/prompts/migrate-v1-to-v2.md +148 -0
  11. spec_test-0.3.0/design/specs/contracts.md +100 -0
  12. spec_test-0.3.0/design/specs/hypothesis-integration.md +358 -0
  13. {spec_test-0.1.3/docs → spec_test-0.3.0/design}/specs/spec-spec-test.md +16 -3
  14. spec_test-0.3.0/design/specs/z3-proofs.md +571 -0
  15. {spec_test-0.1.3 → spec_test-0.3.0}/pyproject.toml +10 -7
  16. spec_test-0.3.0/skills/README.md +177 -0
  17. spec_test-0.3.0/skills/spec-feature.md +209 -0
  18. spec_test-0.3.0/skills/spec-implement.md +546 -0
  19. spec_test-0.3.0/skills/spec-issue.md +216 -0
  20. spec_test-0.3.0/skills/spec-review.md +274 -0
  21. spec_test-0.3.0/skills/spec-verify.md +256 -0
  22. spec_test-0.3.0/skills/spec-workflow.md +297 -0
  23. spec_test-0.3.0/src/spec_test/__init__.py +68 -0
  24. spec_test-0.3.0/src/spec_test/cli.py +596 -0
  25. spec_test-0.3.0/src/spec_test/collector.py +134 -0
  26. spec_test-0.3.0/src/spec_test/contracts.py +334 -0
  27. {spec_test-0.1.3 → spec_test-0.3.0/src}/spec_test/decorators.py +3 -3
  28. spec_test-0.3.0/src/spec_test/prover.py +507 -0
  29. {spec_test-0.1.3 → spec_test-0.3.0/src}/spec_test/reporter.py +1 -0
  30. {spec_test-0.1.3 → spec_test-0.3.0/src}/spec_test/runner.py +32 -17
  31. {spec_test-0.1.3 → spec_test-0.3.0/src}/spec_test/types.py +21 -0
  32. {spec_test-0.1.3 → spec_test-0.3.0/src}/spec_test/verifier.py +9 -1
  33. {spec_test-0.1.3 → spec_test-0.3.0}/tests/test_cli.py +64 -10
  34. spec_test-0.3.0/tests/test_collector.py +141 -0
  35. spec_test-0.3.0/tests/test_contracts.py +416 -0
  36. {spec_test-0.1.3 → spec_test-0.3.0}/tests/test_decorators.py +5 -3
  37. spec_test-0.3.0/tests/test_prover.py +267 -0
  38. spec_test-0.3.0/tests/test_runner.py +72 -0
  39. {spec_test-0.1.3 → spec_test-0.3.0}/uv.lock +3 -1
  40. spec_test-0.1.3/CLAUDE.md +0 -45
  41. spec_test-0.1.3/PKG-INFO +0 -95
  42. spec_test-0.1.3/README.md +0 -78
  43. spec_test-0.1.3/spec_test/__init__.py +0 -32
  44. spec_test-0.1.3/spec_test/cli.py +0 -238
  45. spec_test-0.1.3/spec_test/collector.py +0 -76
  46. spec_test-0.1.3/tests/test_collector.py +0 -89
  47. {spec_test-0.1.3 → spec_test-0.3.0}/.github/workflows/publish.yml +0 -0
  48. {spec_test-0.1.3 → spec_test-0.3.0}/prompt.md +0 -0
  49. {spec_test-0.1.3 → spec_test-0.3.0/src}/spec_test/pytest_plugin.py +0 -0
  50. {spec_test-0.1.3 → spec_test-0.3.0}/tests/__init__.py +0 -0
  51. {spec_test-0.1.3 → spec_test-0.3.0}/tests/conftest.py +0 -0
  52. {spec_test-0.1.3 → spec_test-0.3.0}/tests/test_reporter.py +0 -0
  53. {spec_test-0.1.3 → spec_test-0.3.0}/tests/test_verifier.py +0 -0
@@ -1,3 +1,4 @@
1
1
  dist/
2
2
  __pycache__/
3
3
  *.pyc
4
+ .coverage*
@@ -0,0 +1,71 @@
1
+ # CLAUDE.md - Agent Instructions
2
+
3
+ ## Specification-Driven Development
4
+
5
+ This project uses `spec-test` for specification-driven development. Every behavior must be backed by a passing test.
6
+
7
+ ## Workflow
8
+
9
+ 1. **Issues** document intentions in `design/issues/`
10
+ 2. **Specs** define requirements in `design/specs/`
11
+ 3. **Tests** use `@spec("ID", "description")` decorator
12
+ 4. **Run** `spec-test verify` to check all specs have passing tests
13
+
14
+ ## Directory Structure
15
+
16
+ ```
17
+ design/
18
+ issues/ # Why - intentions, pros/cons, context
19
+ specs/ # What - formal requirements
20
+ prompts/ # How - AI agent instructions
21
+ ```
22
+
23
+ ## Spec Format
24
+
25
+ ```markdown
26
+ - **PREFIX-001**: Description of requirement
27
+ ```
28
+
29
+ ## Test Format
30
+
31
+ ```python
32
+ from spec_test import spec
33
+
34
+ @spec("PREFIX-001", "Description")
35
+ def test_something():
36
+ assert result == expected
37
+ ```
38
+
39
+ ## Commands
40
+
41
+ ```bash
42
+ spec-test verify # Check all specs have passing tests
43
+ spec-test list-specs # List all specs
44
+ spec-test check PREFIX-001 # Check single spec
45
+ ```
46
+
47
+ ## Architecture
48
+
49
+ Follow **Functional Core, Imperative Shell** with **Dependency Injection**:
50
+
51
+ - **Pure functions** for all business logic (testable, provable with Z3)
52
+ - **Dependency Injection** for I/O dependencies (testable with mocks)
53
+ - **Integration tests** only for verifying real I/O works
54
+
55
+ ```
56
+ ┌─────────────────────────────────────────┐
57
+ │ Imperative Shell │ ← I/O via DI
58
+ │ ┌───────────────────────────────────┐ │
59
+ │ │ Functional Core │ │ ← Pure functions
60
+ │ │ (all business logic here) │ │
61
+ │ └───────────────────────────────────┘ │
62
+ └─────────────────────────────────────────┘
63
+ ```
64
+
65
+ ## Rules
66
+
67
+ 1. Write an issue before writing specs
68
+ 2. Every spec must link to an issue
69
+ 3. Every spec ID must have a corresponding `@spec` test
70
+ 4. Run `spec-test verify` before committing
71
+ 5. Prefer pure functions; push side effects to the edges
@@ -0,0 +1,426 @@
1
+ Metadata-Version: 2.4
2
+ Name: spec-test
3
+ Version: 0.3.0
4
+ Summary: Make AI-generated code trustworthy through mathematical verification
5
+ Author: Pulse Team
6
+ License: MIT
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: pydantic>=2.0.0
9
+ Requires-Dist: pytest-cov>=4.0.0
10
+ Requires-Dist: pytest>=8.0.0
11
+ Requires-Dist: rich>=13.0.0
12
+ Requires-Dist: typer>=0.9.0
13
+ Provides-Extra: all
14
+ Requires-Dist: z3-solver>=4.12.0; extra == 'all'
15
+ Provides-Extra: dev
16
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
17
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
18
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
19
+ Provides-Extra: z3
20
+ Requires-Dist: z3-solver>=4.12.0; extra == 'z3'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # spec-test
24
+
25
+ **Make AI-generated code trustworthy through specification-driven development.**
26
+
27
+ Stop reviewing code. Start verifying specs.
28
+
29
+ ---
30
+
31
+ ## The Problem
32
+
33
+ AI writes code 100x faster than humans can review it. Traditional code review is now the bottleneck:
34
+
35
+ ```
36
+ Human writes code --> Human reviews code --> Ship
37
+ (slow) (slow)
38
+
39
+ AI writes code --> Human reviews code --> Ship
40
+ (fast) (slow)
41
+ ^
42
+ BOTTLENECK
43
+ ```
44
+
45
+ You cannot keep up. And the code AI generates is often correct, but *how do you know?*
46
+
47
+ ## The Solution
48
+
49
+ **Shift review from CODE to SPECS.**
50
+
51
+ Specs are 10x smaller than implementations. If your specs are correct and verification passes, the code is correct by definition.
52
+
53
+ ```
54
+ +------------------+
55
+ | YOU REVIEW |
56
+ | SPECS |
57
+ | (10 minutes) |
58
+ +--------+---------+
59
+ |
60
+ v
61
+ +----------------+ +-------------------+ +-----------------+
62
+ | AI Generates | --> | spec-test | --> | Verified Code |
63
+ | Code | | VERIFIES | | Ready to Ship |
64
+ +----------------+ +-------------------+ +-----------------+
65
+ ```
66
+
67
+ ## Quick Start
68
+
69
+ ### Installation
70
+
71
+ ```bash
72
+ pip install spec-test
73
+
74
+ # With Z3 formal proofs (optional)
75
+ pip install spec-test[z3]
76
+ ```
77
+
78
+ ### 1. Initialize Project
79
+
80
+ ```bash
81
+ spec-test init
82
+ ```
83
+
84
+ Creates:
85
+ ```
86
+ design/
87
+ issues/ # Why - intentions, decisions
88
+ specs/ # What - formal requirements
89
+ prompts/ # How - AI instructions
90
+ ```
91
+
92
+ ### 2. Write an Issue First
93
+
94
+ Document *why* before *what*:
95
+
96
+ ```markdown
97
+ # design/issues/001-user-auth.md
98
+
99
+ ## Summary
100
+ Add user authentication to the API.
101
+
102
+ ## Motivation
103
+ Users need secure access to their data.
104
+
105
+ ## Decision
106
+ Use JWT tokens with 24h expiry.
107
+ ```
108
+
109
+ ### 3. Define Specs
110
+
111
+ ```markdown
112
+ # design/specs/auth.md
113
+
114
+ ## User Authentication
115
+
116
+ ### Related Issue
117
+ - [001-user-auth](../issues/001-user-auth.md)
118
+
119
+ ### Requirements
120
+ - **AUTH-001**: User can login with valid email and password
121
+ - **AUTH-002**: Invalid credentials return 401 error
122
+ - **AUTH-003**: JWT token expires after 24 hours
123
+ - **AUTH-010** [integration]: User session persists to database
124
+ ```
125
+
126
+ ### 4. Implement with Tests
127
+
128
+ ```python
129
+ from spec_test import spec
130
+
131
+ @spec("AUTH-001", "User can login with valid email and password")
132
+ def test_login_success():
133
+ result = login("user@example.com", "password123")
134
+ assert result.success
135
+ assert result.token is not None
136
+ ```
137
+
138
+ ### 5. Add Runtime Contracts
139
+
140
+ ```python
141
+ from spec_test import contract
142
+
143
+ @contract(
144
+ spec="AUTH-001",
145
+ requires=[
146
+ lambda email, password: "@" in email,
147
+ lambda email, password: len(password) >= 8,
148
+ ],
149
+ ensures=[
150
+ lambda result: result.token is not None,
151
+ ],
152
+ )
153
+ def login(email: str, password: str) -> LoginResult:
154
+ user = db.get_user(email)
155
+ if verify_password(password, user.password_hash):
156
+ return LoginResult(success=True, token=generate_jwt(user))
157
+ return LoginResult(success=False, token=None)
158
+ ```
159
+
160
+ ### 6. Verify
161
+
162
+ ```bash
163
+ $ spec-test verify
164
+
165
+ ╭─────────────────────────────────────────╮
166
+ │ Specification Verification Report │
167
+ ╰─────────────────────────────────────────╯
168
+
169
+ ✓ AUTH-001: User can login with valid email and password
170
+ ✓ AUTH-002: Invalid credentials return 401 error
171
+ ✓ AUTH-003: JWT token expires after 24 hours
172
+ ! AUTH-010: No test
173
+
174
+ Summary: 3 passing, 0 failing, 1 missing
175
+ ```
176
+
177
+ ## Architecture: Functional Core, Imperative Shell
178
+
179
+ All code should follow this pattern with **Dependency Injection**:
180
+
181
+ ```
182
+ ┌─────────────────────────────────────────────────────────────┐
183
+ │ Imperative Shell │
184
+ │ (thin layer, injected dependencies) │
185
+ │ ┌───────────────────────────────────────────────────────┐ │
186
+ │ │ Functional Core │ │
187
+ │ │ (pure functions, all business logic) │ │
188
+ │ │ │ │
189
+ │ │ • Deterministic (same input → same output) │ │
190
+ │ │ • No side effects │ │
191
+ │ │ • Easy to test (unit tests) │ │
192
+ │ │ • Can be formally proven (Z3) │ │
193
+ │ └───────────────────────────────────────────────────────┘ │
194
+ │ │
195
+ │ • Database, Email, API calls via DI │
196
+ │ • Testable with mocks │
197
+ │ • Integration tests verify real I/O │
198
+ └─────────────────────────────────────────────────────────────┘
199
+ ```
200
+
201
+ ### Example
202
+
203
+ ```python
204
+ # FUNCTIONAL CORE: Pure function, no dependencies
205
+ def calculate_total(items: list[Item]) -> Decimal:
206
+ return sum(item.price * item.quantity for item in items)
207
+
208
+ # IMPERATIVE SHELL: Thin layer with injected dependencies
209
+ class OrderService:
210
+ def __init__(self, db: Database, email: EmailSender): # DI
211
+ self.db = db
212
+ self.email = email
213
+
214
+ def place_order(self, items: list[Item]) -> Order:
215
+ total = calculate_total(items) # Call pure function
216
+ order = Order(items=items, total=total)
217
+ self.db.save(order) # Injected dependency
218
+ self.email.send_confirmation() # Injected dependency
219
+ return order
220
+ ```
221
+
222
+ ### Testing Strategy
223
+
224
+ ```
225
+ ┌─────────────┬────────────────┬─────────────────────┬───────────┐
226
+ │ Test Type │ What │ How │ Speed │
227
+ ├─────────────┼────────────────┼─────────────────────┼───────────┤
228
+ │ Unit │ Pure functions │ Direct call │ Fast (ms) │
229
+ ├─────────────┼────────────────┼─────────────────────┼───────────┤
230
+ │ Mock │ Service wiring │ Inject mocks via DI │ Fast (ms) │
231
+ ├─────────────┼────────────────┼─────────────────────┼───────────┤
232
+ │ Integration │ Real I/O works │ Real DB/API │ Slow (s) │
233
+ └─────────────┴────────────────┴─────────────────────┴───────────┘
234
+ ```
235
+
236
+ **Aim for ~90% unit/mock tests, ~10% integration tests.**
237
+
238
+ ## Verification Types
239
+
240
+ Mark specs with verification type in brackets:
241
+
242
+ | Type | Meaning |
243
+ |------|---------|
244
+ | (none) | Automated unit test |
245
+ | `[integration]` | Integration test (real I/O) |
246
+ | `[manual]` | Manual human verification |
247
+ | `[contract]` | Runtime contract verification |
248
+ | `[provable]` | Z3 formal proof |
249
+
250
+ ```markdown
251
+ - **AUTH-001**: User can login (unit test)
252
+ - **AUTH-010** [integration]: Session persists to database
253
+ - **AUTH-020** [manual]: UI follows brand guidelines
254
+ - **AUTH-030** [provable]: Token expiry is always positive
255
+ ```
256
+
257
+ ## Runtime Contracts
258
+
259
+ ### Basic Contract
260
+
261
+ ```python
262
+ from spec_test import contract
263
+
264
+ @contract(
265
+ spec="CART-001",
266
+ requires=[lambda items: len(items) > 0],
267
+ ensures=[lambda result: result >= 0],
268
+ )
269
+ def calculate_total(items: list[Item]) -> Decimal:
270
+ return sum(item.price * item.quantity for item in items)
271
+ ```
272
+
273
+ ### With Invariants
274
+
275
+ ```python
276
+ @contract(
277
+ spec="CART-002",
278
+ requires=[lambda items, discount: discount >= 0],
279
+ ensures=[lambda result: result >= 0],
280
+ invariants=[lambda items, discount: discount <= 100],
281
+ )
282
+ def apply_discount(items: list[Item], discount: int) -> Decimal:
283
+ total = calculate_total(items)
284
+ return total * (1 - discount / 100)
285
+ ```
286
+
287
+ ### Comparing Pre/Post State with `old()`
288
+
289
+ ```python
290
+ from spec_test import contract, Old
291
+
292
+ @contract(
293
+ spec="LIST-001",
294
+ capture_old=True,
295
+ ensures=[lambda result, old: len(result) == len(old.items) + 1],
296
+ )
297
+ def append_item(items: list, item) -> list:
298
+ return items + [item]
299
+ ```
300
+
301
+ ## Z3 Formal Proofs
302
+
303
+ For mathematical verification of pure functions:
304
+
305
+ ```bash
306
+ pip install spec-test[z3]
307
+ ```
308
+
309
+ ```python
310
+ from spec_test import provable, contract
311
+
312
+ @provable(spec="MATH-001")
313
+ @contract(
314
+ requires=[lambda x, y: x >= 0, lambda x, y: y >= 0],
315
+ ensures=[lambda result: result >= 0],
316
+ )
317
+ def add_positive(x: int, y: int) -> int:
318
+ return x + y
319
+ ```
320
+
321
+ ```bash
322
+ $ spec-test verify --proofs
323
+
324
+ ╭─────────────────────────────────────╮
325
+ │ Proof Verification Summary │
326
+ ╰─────────────────────────────────────╯
327
+ Proven: 1 | Refuted: 0 | Unknown: 0
328
+ ```
329
+
330
+ ## For AI Agents
331
+
332
+ spec-test is designed for AI-assisted development.
333
+
334
+ ### Workflow
335
+
336
+ ```
337
+ Write Issue --> Define Specs --> Implement Code --> Verify --> Review
338
+ | | | | |
339
+ (why) (what) (how) (check) (approve)
340
+ ```
341
+
342
+ ### Add to CLAUDE.md
343
+
344
+ ```markdown
345
+ ## Specification-Driven Development
346
+
347
+ This project uses spec-test. Every behavior must be backed by a passing test.
348
+
349
+ ## Architecture
350
+ - Pure functions for business logic (Functional Core)
351
+ - Dependency Injection for I/O (Imperative Shell)
352
+ - Integration tests only for verifying real I/O
353
+
354
+ ## Rules
355
+ 1. Write an issue before writing specs
356
+ 2. Every spec ID must have a corresponding @spec test
357
+ 3. Run `spec-test verify` before committing
358
+ 4. Prefer pure functions; push side effects to edges
359
+ ```
360
+
361
+ ### AI Agent Skills
362
+
363
+ Initialize with skills for Claude:
364
+
365
+ ```bash
366
+ spec-test init
367
+ ```
368
+
369
+ Installs skills to `.claude/skills/`:
370
+ - `spec-workflow.md` - Complete development workflow
371
+ - `spec-issue.md` - Writing issues
372
+ - `spec-feature.md` - Defining specifications
373
+ - `spec-implement.md` - Implementation with architecture principles
374
+ - `spec-verify.md` - Running verification
375
+
376
+ ## Commands
377
+
378
+ ```bash
379
+ spec-test verify # Verify all specs have passing tests
380
+ spec-test verify --proofs # Include Z3 formal proof verification
381
+ spec-test verify --coverage # Include code coverage analysis
382
+ spec-test list-specs # List all specifications
383
+ spec-test list-specs -i # Show related issues for each spec
384
+ spec-test check AUTH-001 # Verify single spec
385
+ spec-test init # Initialize spec-test in a project
386
+ spec-test context # Output CLAUDE.md for LLM context
387
+ ```
388
+
389
+ ## Roadmap
390
+
391
+ > **Note:** spec-test is in active development.
392
+
393
+ - [x] Spec-to-test linking with `@spec` decorator
394
+ - [x] Runtime contracts with `@contract` (requires/ensures/invariants)
395
+ - [x] `old()` support for comparing pre/post state
396
+ - [x] Z3 formal proof verification with `@provable`
397
+ - [x] Issues-first workflow with `design/` structure
398
+ - [x] AI agent skills
399
+ - [ ] Hypothesis property testing integration
400
+ - [ ] Spec coverage reporting
401
+
402
+ ## Contributing
403
+
404
+ ```bash
405
+ git clone https://github.com/Varuas37/spec-test.git
406
+ cd spec-test
407
+ uv sync
408
+
409
+ # Run tests
410
+ uv run pytest
411
+
412
+ # Run verification
413
+ uv run spec-test verify
414
+ ```
415
+
416
+ ## License
417
+
418
+ MIT
419
+
420
+ ---
421
+
422
+ **Stop reviewing code. Start verifying specs.**
423
+
424
+ ```bash
425
+ pip install spec-test
426
+ ```