Skip to content

Commit a9167a1

Browse files
djm81cursoragentDominikus Nold
authored
feat: Phase 4 complete - Contract generation and density scoring (v0.8.0) (#30)
* Build: Include resources in sdist and wheel builds Co-authored-by: dominikus.nold <dominikus.nold@web.de> * feat: Code2Spec Strategic Plan Phase 0 implementation (v0.6.9) (#26) * feat: Add JSON/YAML support for plan bundles (#27) * feat: add batch update support for plan review and updates (v0.7.0) - Add --batch-updates option to plan update-feature command - Add --batch-updates option to plan update-story command - Add --list-findings option to plan review command with structured output - Refactor review function to reduce complexity - Add comprehensive e2e tests for batch updates - Update documentation and prompts to prefer batch updates - Update version to 0.7.0 * fix: remove whitespace from blank lines and apply formatting * docs: align all documentation with CLI-first, integration-focused positioning - Updated all examples and guides with CLI-first messaging - Added Integration Showcases references throughout documentation - Emphasized integration diversity (VS Code, Cursor, GitHub Actions, pre-commit) - Updated brownfield showcase examples with integration workflow sections - Updated platform-frontend CMS to link to Integration Showcases README - Reviewed and aligned all brownfield documentation for CLI-first approach - Updated version to 0.7.1 Files updated: - All docs/examples/ files (6 files) - All docs/guides/ files (6 files) - docs/reference/directory-structure.md - platform-frontend/iac/scripts/payload-content-helper.js - Version files: pyproject.toml, setup.py, src/__init__.py, src/specfact_cli/__init__.py - CHANGELOG.md with comprehensive 0.7.1 entry * fix: resolve type checking errors in constitution_evidence_extractor - Fixed basedpyright warnings for repo_path.exists() in contract decorators - Added isinstance() type guard to properly narrow Path | None types - Updated Example 3 validation status to FULLY VALIDATED (CI/CD workflow verified in production) - Updated documentation to reflect Example 3 is validated in specfact-cli repository CI/CD Fixes type checking errors reported in GitHub Actions workflow: - constitution_evidence_extractor.py:65:53 - Type of "exists" is unknown - Fixed in all three methods: extract_article_vii_evidence, extract_article_viii_evidence, extract_article_ix_evidence Example 3 Status Update: - Changed from "COMMANDS VERIFIED" to "FULLY VALIDATED" - Validated in production CI/CD (specfact-cli PR #28) - Workflow successfully runs specfact repro and blocks PRs when validation fails * Fix typecheck error * Fix all type check errors * Fix type annotations * feat: Phase 4 complete - Contract generation and density scoring - Add contract density validator (contract_validator.py) with metrics calculation - Integrate contract density into enforce sdd and plan review commands - Add contract density metrics display in plan review output - Fix plan bundle hash persistence in plan harden command - Add integration test for plan bundle hash persistence - Update version to 0.8.0 - Update CHANGELOG.md with Phase 4 completion details - Update end-user documentation with new commands (plan harden, enforce sdd, generate contracts) Phase 4 Status: ✅ COMPLETE (2025-11-24) - 4.1 Contract Stub Generator: ✅ Complete - 4.2 Contract Density Scoring: ✅ Complete (10 unit tests passing) Test Coverage: - 10 unit tests for contract density validation - 1 integration test for hash persistence - All tests passing --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Dominikus Nold <dominikus@nold-ai.com>
1 parent 5d9c90f commit a9167a1

36 files changed

+5006
-91
lines changed

CHANGELOG.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,66 @@ All notable changes to this project will be documented in this file.
99

1010
---
1111

12+
## [0.8.0] - 2025-11-24
13+
14+
### Added (0.8.0)
15+
16+
- **Phase 4: Contract Generation from SDD - Complete**
17+
- **Contract Density Scoring** (`src/specfact_cli/validators/contract_validator.py`)
18+
- New `ContractDensityMetrics` class for tracking contract density metrics
19+
- `calculate_contract_density()` function calculates contracts per story, invariants per feature, and architecture facets
20+
- `validate_contract_density()` function validates metrics against SDD coverage thresholds
21+
- Integrated into `specfact enforce sdd` command for automatic validation
22+
- Integrated into `specfact plan review` command with metrics display
23+
- Comprehensive unit test suite (10 tests) covering all validation scenarios
24+
25+
- **Contract Density Metrics Display**
26+
- `specfact plan review` now displays contract density metrics when SDD manifest is present
27+
- Shows contracts/story, invariants/feature, and architecture facets with threshold comparisons
28+
- Provides actionable feedback when thresholds are not met
29+
- Integrated with SDD validation workflow
30+
31+
### Changed (0.8.0)
32+
33+
- **SDD Enforcement Integration**
34+
- `specfact enforce sdd` now uses centralized contract density validator
35+
- Refactored duplicate contract density calculation logic into reusable validator module
36+
- Improved consistency across `enforce sdd` and `plan review` commands
37+
- Contract density validation now part of standard SDD enforcement workflow
38+
39+
- **Plan Harden Command Enhancement**
40+
- `specfact plan harden` now saves plan bundle with updated hash after calculation
41+
- Ensures plan bundle hash persists to disk for subsequent commands
42+
- Prevents hash mismatch errors when running `specfact generate contracts` after `plan harden`
43+
- Improved reliability of SDD-plan bundle linkage
44+
45+
### Fixed (0.8.0)
46+
47+
- **Plan Bundle Hash Persistence**
48+
- Fixed bug where `plan harden` calculated hash but didn't save plan bundle to disk
49+
- Plan bundle now correctly saved with updated summary metadata containing hash
50+
- Subsequent commands (e.g., `generate contracts`) can now load plan and get matching hash
51+
- Added integration test `test_plan_harden_persists_hash_to_disk` to prevent regression
52+
53+
- **Contract-First Testing Coverage**
54+
- Added test to verify plan bundle hash persistence after `plan harden`
55+
- Test would have caught the hash persistence bug if run earlier
56+
- Demonstrates value of contract-first testing approach
57+
58+
### Testing (0.8.0)
59+
60+
- **Contract Validator Test Suite**
61+
- 10 comprehensive unit tests for contract density calculation and validation
62+
- Tests cover empty plans, threshold violations, multiple violations, and edge cases
63+
- All tests passing with full coverage of validation scenarios
64+
65+
- **Integration Test Coverage**
66+
- Enhanced `test_plan_harden` suite with hash persistence verification
67+
- New test `test_plan_harden_persists_hash_to_disk` ensures plan bundle is saved correctly
68+
- All integration tests passing (8 tests)
69+
70+
---
71+
1272
## [0.7.1] - 2025-01-22
1373

1474
### Changed (0.7.1)

docs/examples/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,35 @@ Real-world examples of using SpecFact CLI.
88
- **CLI-First**: Works offline, no account required, integrates with any IDE
99
- Start with the [Integration Showcases README](integration-showcases/README.md) for an overview
1010
- Read the [main showcase document](integration-showcases/integration-showcases.md) for real examples
11+
- **[Brownfield Examples](#brownfield-examples)****NEW** - Complete hard-SDD workflow demonstrations
12+
- **[Django Modernization](brownfield-django-modernization.md)** - Legacy Django app → contract-enforced modern codebase
13+
- **[Flask API](brownfield-flask-api.md)** - Legacy Flask API → contract-enforced modern service
14+
- **[Data Pipeline](brownfield-data-pipeline.md)** - Legacy ETL pipeline → contract-enforced data processing
15+
- All examples now include: `plan harden`, `enforce sdd`, `plan review`, and `plan promote` with SDD validation
16+
- **[Quick Examples](quick-examples.md)** - Quick code snippets for common tasks, including SDD workflow
1117
- **[Dogfooding SpecFact CLI](dogfooding-specfact-cli.md)** - We ran SpecFact CLI on itself (< 10 seconds!)
1218

1319
## Quick Start
1420

1521
### See It In Action
1622

17-
Read the complete dogfooding example to see SpecFact CLI in action:
23+
**For Brownfield Modernization** (Recommended):
24+
25+
Read the complete brownfield examples to see the hard-SDD workflow:
26+
27+
**[Django Modernization Example](brownfield-django-modernization.md)**
28+
29+
This example shows the complete workflow:
30+
31+
1.**Extract specs** from legacy code → 23 features, 112 stories in **8 seconds**
32+
2. 📋 **Create SDD manifest** → Hard spec with WHY/WHAT/HOW, coverage thresholds
33+
3.**Validate SDD** → Hash match, coverage threshold validation
34+
4. 📊 **Review plan** → SDD validation integrated, ambiguity resolution
35+
5. 🚀 **Promote plan** → SDD required for "review" or higher stages
36+
6. 🔒 **Add contracts** → Runtime enforcement prevents regressions
37+
7. 🔍 **Re-validate SDD** → Ensure coverage thresholds maintained
38+
39+
**For Quick Testing**:
1840

1941
**[Dogfooding SpecFact CLI](dogfooding-specfact-cli.md)**
2042

docs/examples/brownfield-data-pipeline.md

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ You inherited a 5-year-old Python data pipeline with:
2121

2222
## Step 1: Reverse Engineer Data Pipeline
2323

24+
> **Note**: This example demonstrates the complete hard-SDD workflow, including SDD manifest creation, validation, and plan promotion gates. The SDD manifest serves as your "hard spec" - a canonical reference that prevents drift during modernization.
25+
2426
**CLI-First Approach**: SpecFact works offline, requires no account, and integrates with your existing workflow. Works with VS Code, Cursor, GitHub Actions, pre-commit hooks, or any IDE.
2527

2628
### Extract Specs from Legacy Pipeline
@@ -74,7 +76,70 @@ features:
7476
7577
---
7678
77-
## Step 2: Add Contracts to Data Transformations
79+
## Step 2: Create Hard SDD Manifest
80+
81+
After extracting the plan, create a hard SDD manifest:
82+
83+
```bash
84+
# Create SDD manifest from the extracted plan
85+
specfact plan harden
86+
```
87+
88+
### Output
89+
90+
```text
91+
✅ SDD manifest created: .specfact/sdd.yaml
92+
93+
📋 SDD Summary:
94+
WHY: Modernize legacy ETL pipeline with zero data corruption
95+
WHAT: 18 ETL jobs, 67 stories extracted from legacy code
96+
HOW: Runtime contracts, data validation, incremental enforcement
97+
98+
🔗 Linked to plan: customer-etl (hash: ghi789jkl012...)
99+
📊 Coverage thresholds:
100+
- Contracts per story: 1.0 (minimum)
101+
- Invariants per feature: 2.0 (minimum)
102+
- Architecture facets: 3 (minimum)
103+
```
104+
105+
---
106+
107+
## Step 3: Validate SDD Before Modernization
108+
109+
Validate that your SDD manifest matches your plan:
110+
111+
```bash
112+
# Validate SDD manifest against plan
113+
specfact enforce sdd
114+
```
115+
116+
### Output
117+
118+
```text
119+
✅ Hash match verified
120+
✅ Contracts/story: 1.1 (threshold: 1.0) ✓
121+
✅ Invariants/feature: 2.3 (threshold: 2.0) ✓
122+
✅ Architecture facets: 4 (threshold: 3) ✓
123+
124+
✅ SDD validation passed
125+
```
126+
127+
---
128+
129+
## Step 4: Promote Plan with SDD Validation
130+
131+
Promote your plan to "review" stage (requires valid SDD):
132+
133+
```bash
134+
# Promote plan to review stage
135+
specfact plan promote --stage review
136+
```
137+
138+
**Why this matters**: Plan promotion enforces SDD presence, ensuring you have a hard spec before starting modernization work.
139+
140+
---
141+
142+
## Step 5: Add Contracts to Data Transformations
78143

79144
### Before: Undocumented Legacy Transformation
80145

@@ -142,9 +207,17 @@ def transform_order(raw_order: Dict[str, Any]) -> Dict[str, Any]:
142207
}
143208
```
144209

210+
### Re-validate SDD After Adding Contracts
211+
212+
After adding contracts, re-validate your SDD:
213+
214+
```bash
215+
specfact enforce sdd
216+
```
217+
145218
---
146219

147-
## Step 3: Discover Data Edge Cases
220+
## Step 6: Discover Data Edge Cases
148221

149222
### Run CrossHair on Data Transformations
150223

@@ -198,7 +271,7 @@ def transform_order(raw_order: Dict[str, Any]) -> Dict[str, Any]:
198271

199272
---
200273

201-
## Step 4: Modernize Pipeline Safely
274+
## Step 7: Modernize Pipeline Safely
202275

203276
### Refactor with Contract Safety Net
204277

@@ -299,10 +372,13 @@ SpecFact CLI integrates seamlessly with your existing tools:
299372
### What Worked Well
300373

301374
1.**code2spec** extracted pipeline structure automatically
302-
2.**Contracts** enforced data validation at runtime
303-
3.**CrossHair** discovered edge cases in data transformations
304-
4.**Incremental modernization** reduced risk
305-
5.**CLI-first integration** - Works offline, no account required, no vendor lock-in
375+
2.**SDD manifest** created hard spec reference, preventing drift
376+
3.**SDD validation** ensured coverage thresholds before modernization
377+
4.**Plan promotion gates** required SDD presence, enforcing discipline
378+
5.**Contracts** enforced data validation at runtime
379+
6.**CrossHair** discovered edge cases in data transformations
380+
7.**Incremental modernization** reduced risk
381+
8.**CLI-first integration** - Works offline, no account required, no vendor lock-in
306382

307383
### Lessons Learned
308384

0 commit comments

Comments
 (0)