Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,66 @@ All notable changes to this project will be documented in this file.

---

## [0.8.0] - 2025-11-24

### Added (0.8.0)

- **Phase 4: Contract Generation from SDD - Complete**
- **Contract Density Scoring** (`src/specfact_cli/validators/contract_validator.py`)
- New `ContractDensityMetrics` class for tracking contract density metrics
- `calculate_contract_density()` function calculates contracts per story, invariants per feature, and architecture facets
- `validate_contract_density()` function validates metrics against SDD coverage thresholds
- Integrated into `specfact enforce sdd` command for automatic validation
- Integrated into `specfact plan review` command with metrics display
- Comprehensive unit test suite (10 tests) covering all validation scenarios

- **Contract Density Metrics Display**
- `specfact plan review` now displays contract density metrics when SDD manifest is present
- Shows contracts/story, invariants/feature, and architecture facets with threshold comparisons
- Provides actionable feedback when thresholds are not met
- Integrated with SDD validation workflow

### Changed (0.8.0)

- **SDD Enforcement Integration**
- `specfact enforce sdd` now uses centralized contract density validator
- Refactored duplicate contract density calculation logic into reusable validator module
- Improved consistency across `enforce sdd` and `plan review` commands
- Contract density validation now part of standard SDD enforcement workflow

- **Plan Harden Command Enhancement**
- `specfact plan harden` now saves plan bundle with updated hash after calculation
- Ensures plan bundle hash persists to disk for subsequent commands
- Prevents hash mismatch errors when running `specfact generate contracts` after `plan harden`
- Improved reliability of SDD-plan bundle linkage

### Fixed (0.8.0)

- **Plan Bundle Hash Persistence**
- Fixed bug where `plan harden` calculated hash but didn't save plan bundle to disk
- Plan bundle now correctly saved with updated summary metadata containing hash
- Subsequent commands (e.g., `generate contracts`) can now load plan and get matching hash
- Added integration test `test_plan_harden_persists_hash_to_disk` to prevent regression

- **Contract-First Testing Coverage**
- Added test to verify plan bundle hash persistence after `plan harden`
- Test would have caught the hash persistence bug if run earlier
- Demonstrates value of contract-first testing approach

### Testing (0.8.0)

- **Contract Validator Test Suite**
- 10 comprehensive unit tests for contract density calculation and validation
- Tests cover empty plans, threshold violations, multiple violations, and edge cases
- All tests passing with full coverage of validation scenarios

- **Integration Test Coverage**
- Enhanced `test_plan_harden` suite with hash persistence verification
- New test `test_plan_harden_persists_hash_to_disk` ensures plan bundle is saved correctly
- All integration tests passing (8 tests)

---

## [0.7.1] - 2025-01-22

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

## Quick Start

### See It In Action

Read the complete dogfooding example to see SpecFact CLI in action:
**For Brownfield Modernization** (Recommended):

Read the complete brownfield examples to see the hard-SDD workflow:

**[Django Modernization Example](brownfield-django-modernization.md)**

This example shows the complete workflow:

1. ⚑ **Extract specs** from legacy code β†’ 23 features, 112 stories in **8 seconds**
2. πŸ“‹ **Create SDD manifest** β†’ Hard spec with WHY/WHAT/HOW, coverage thresholds
3. βœ… **Validate SDD** β†’ Hash match, coverage threshold validation
4. πŸ“Š **Review plan** β†’ SDD validation integrated, ambiguity resolution
5. πŸš€ **Promote plan** β†’ SDD required for "review" or higher stages
6. πŸ”’ **Add contracts** β†’ Runtime enforcement prevents regressions
7. πŸ” **Re-validate SDD** β†’ Ensure coverage thresholds maintained

**For Quick Testing**:

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

Expand Down
90 changes: 83 additions & 7 deletions docs/examples/brownfield-data-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ You inherited a 5-year-old Python data pipeline with:

## Step 1: Reverse Engineer Data Pipeline

> **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.

**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.

### Extract Specs from Legacy Pipeline
Expand Down Expand Up @@ -74,7 +76,70 @@ features:

---

## Step 2: Add Contracts to Data Transformations
## Step 2: Create Hard SDD Manifest

After extracting the plan, create a hard SDD manifest:

```bash
# Create SDD manifest from the extracted plan
specfact plan harden
```

### Output

```text
βœ… SDD manifest created: .specfact/sdd.yaml

πŸ“‹ SDD Summary:
WHY: Modernize legacy ETL pipeline with zero data corruption
WHAT: 18 ETL jobs, 67 stories extracted from legacy code
HOW: Runtime contracts, data validation, incremental enforcement

πŸ”— Linked to plan: customer-etl (hash: ghi789jkl012...)
πŸ“Š Coverage thresholds:
- Contracts per story: 1.0 (minimum)
- Invariants per feature: 2.0 (minimum)
- Architecture facets: 3 (minimum)
```

---

## Step 3: Validate SDD Before Modernization

Validate that your SDD manifest matches your plan:

```bash
# Validate SDD manifest against plan
specfact enforce sdd
```

### Output

```text
βœ… Hash match verified
βœ… Contracts/story: 1.1 (threshold: 1.0) βœ“
βœ… Invariants/feature: 2.3 (threshold: 2.0) βœ“
βœ… Architecture facets: 4 (threshold: 3) βœ“

βœ… SDD validation passed
```

---

## Step 4: Promote Plan with SDD Validation

Promote your plan to "review" stage (requires valid SDD):

```bash
# Promote plan to review stage
specfact plan promote --stage review
```

**Why this matters**: Plan promotion enforces SDD presence, ensuring you have a hard spec before starting modernization work.

---

## Step 5: Add Contracts to Data Transformations

### Before: Undocumented Legacy Transformation

Expand Down Expand Up @@ -142,9 +207,17 @@ def transform_order(raw_order: Dict[str, Any]) -> Dict[str, Any]:
}
```

### Re-validate SDD After Adding Contracts

After adding contracts, re-validate your SDD:

```bash
specfact enforce sdd
```

---

## Step 3: Discover Data Edge Cases
## Step 6: Discover Data Edge Cases

### Run CrossHair on Data Transformations

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

---

## Step 4: Modernize Pipeline Safely
## Step 7: Modernize Pipeline Safely

### Refactor with Contract Safety Net

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

1. βœ… **code2spec** extracted pipeline structure automatically
2. βœ… **Contracts** enforced data validation at runtime
3. βœ… **CrossHair** discovered edge cases in data transformations
4. βœ… **Incremental modernization** reduced risk
5. βœ… **CLI-first integration** - Works offline, no account required, no vendor lock-in
2. βœ… **SDD manifest** created hard spec reference, preventing drift
3. βœ… **SDD validation** ensured coverage thresholds before modernization
4. βœ… **Plan promotion gates** required SDD presence, enforcing discipline
5. βœ… **Contracts** enforced data validation at runtime
6. βœ… **CrossHair** discovered edge cases in data transformations
7. βœ… **Incremental modernization** reduced risk
8. βœ… **CLI-first integration** - Works offline, no account required, no vendor lock-in

### Lessons Learned

Expand Down
Loading
Loading