Skip to content

Commit 5c905ec

Browse files
authored
fix: Add external repository support for repro command (v0.20.1) (#52)
* fix: add external repository support for repro command (0.20.1) - Add environment manager detection (hatch, poetry, uv, pip) - Make all validation tools optional with clear messaging - Add dynamic source directory detection - Update documentation for external repo support - Add comprehensive test coverage (25 new tests) Fixes critical design issue where repro command only worked on SpecFact CLI's own codebase. Now works on external repositories without requiring SpecFact CLI adoption. Closes: External repository support issue Reference: CRITICAL_DESIGN_ISSUE_EXTERNAL_REPO_SUPPORT.md * fix: add external repository support for generate commands (0.20.1) - Fix generate contracts-apply: use dynamic source/test detection - Fix generate test-prompt: use dynamic source directory detection - Add test directory detection utilities (detect_test_directories, find_test_files_for_source) - Use environment detection for Python/pytest invocations - Add comprehensive tests (6 new tests for test detection utilities) Completes external repository support fixes identified in analysis. All generate commands now work on external repositories. * test: add comprehensive tests for repro setup and init environment warning - Add 15 integration tests for repro setup command covering: - pyproject.toml creation and updates with CrossHair config - Environment manager detection (hatch, poetry, uv, pip) - Source directory detection (src/, lib/, package name) - CrossHair tool availability checking and installation - Error handling and user guidance - Add 5 e2e tests for init command environment manager warning: - Warning display when no environment manager detected - No warning when hatch/poetry/pip/uv detected - Update CHANGELOG.md with new features and test coverage improvements All tests passing (20/20) * feat: align init --install-deps with environment manager detection - Update init --install-deps to use build_tool_command for environment-aware installation - Automatically detect and use hatch, poetry, uv, or pip based on project configuration - Show detected environment manager message and command being used - Provide environment-specific installation guidance on errors - Add 5-minute timeout for package installation - Track environment manager in telemetry - Update help text to reflect environment manager awareness - Update CHANGELOG.md with improvements This ensures consistent behavior with repro setup command and proper integration with different Python project management tools. --------- Co-authored-by: Dominikus Nold <[email protected]>
1 parent 890b1f6 commit 5c905ec

File tree

23 files changed

+2454
-156
lines changed

23 files changed

+2454
-156
lines changed

CHANGELOG.md

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

1010
---
1111

12+
## [0.20.1] - 2025-12-20
13+
14+
### Fixed (0.20.1)
15+
16+
- **External Repository Support**: Fixed critical issue where `repro` command only worked on SpecFact CLI's own codebase
17+
- Added automatic environment manager detection (hatch, poetry, uv, pip)
18+
- Made all validation tools optional with clear messaging when unavailable
19+
- Added dynamic source directory detection (src/, lib/, or package name from pyproject.toml)
20+
- Commands now work on external repositories without requiring SpecFact CLI adoption
21+
- Enables OSS validation plan execution as designed
22+
- **`generate contracts-apply` Command**: Fixed hardcoded paths and environment assumptions
23+
- Uses dynamic source directory detection instead of hardcoded `src/` paths
24+
- Uses environment detection for Python/pytest invocations
25+
- Dynamic test file detection (supports multiple test directory structures)
26+
- Works on external repositories with different project structures
27+
- **`generate test-prompt` Command**: Fixed hardcoded source directory detection
28+
- Uses dynamic source directory detection instead of hardcoded `src/`
29+
- Dynamic test file detection for better external repository support
30+
31+
### Added (0.20.1)
32+
33+
- **Environment Manager Detection**: New `env_manager` utility module for detecting and working with different Python environment managers
34+
- **Test Directory Detection**: New utilities for detecting test directories and finding test files dynamically
35+
- **Comprehensive Tests**: Added 31 new tests for environment detection, test directory detection, and external repository support
36+
- **`repro setup` Command**: New subcommand to automatically configure CrossHair for contract exploration
37+
- Automatically generates `[tool.crosshair]` configuration in `pyproject.toml`
38+
- Detects source directories and environment managers
39+
- Provides installation guidance for crosshair-tool
40+
- Optional `--install-crosshair` flag to attempt automatic installation
41+
- **`init` Command Environment Warning**: Added warning when no compatible environment manager is detected
42+
- Non-blocking warning that provides guidance on supported tools
43+
- Helps users understand best practices for SpecFact CLI integration
44+
- Lists supported environment managers (hatch, poetry, uv, pip) with detection criteria
45+
46+
### Improved (0.20.1)
47+
48+
- **Documentation**: Updated `repro` command documentation to clarify external repository support and environment requirements
49+
- Added `repro setup` command documentation
50+
- Updated all example flows to include CrossHair setup step
51+
- Added "Supported Project Management Tools" section to installation guide
52+
- **Error Messages**: Improved messaging when tools are unavailable, providing clear guidance on installation
53+
- **Code Quality**: All linting/formatting tools in `generate contracts-apply` now use environment detection
54+
- **Test Coverage**: Added comprehensive test suite for `repro setup` command (15 tests) and `init` command environment warning (5 tests)
55+
- **`init --install-deps` Command**: Now uses environment manager detection for package installation
56+
- Automatically detects and uses hatch, poetry, uv, or pip based on project configuration
57+
- Provides environment-specific installation commands and error guidance
58+
- Shows detected environment manager and command being used
59+
- Adds timeout handling and improved error messages
60+
- Tracks environment manager in telemetry
61+
62+
### Notes (0.20.1)
63+
64+
This patch release fixes the critical design issue identified during OSS validation planning. The `repro` command can now be used to validate external repositories (Requests, Flask, FastAPI, etc.) without requiring those projects to adopt SpecFact CLI.
65+
66+
**Reference**: [CRITICAL_DESIGN_ISSUE_EXTERNAL_REPO_SUPPORT.md](docs/internal/analysis/CRITICAL_DESIGN_ISSUE_EXTERNAL_REPO_SUPPORT.md)
67+
68+
---
69+
1270
## [0.20.0] - 2025-12-17
1371

1472
### 🎉 Long-Term Stable (LTS) Release

docs/examples/integration-showcases/integration-showcases-testing-guide.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,11 +1035,17 @@ Report written to: .specfact/projects/<bundle-name>/reports/enforcement/report-<
10351035
- Type checking (basedpyright) - type annotations and type safety
10361036
10371037
- **Conditionally runs** (only if present):
1038-
- Contract exploration (CrossHair) - only if `src/` directory exists (symbolic execution to find counterexamples, not runtime contract validation)
1038+
- Contract exploration (CrossHair) - only if `[tool.crosshair]` config exists in `pyproject.toml` (use `specfact repro setup` to generate) and `src/` directory exists (symbolic execution to find counterexamples, not runtime contract validation)
10391039
- Semgrep async patterns - only if `tools/semgrep/async.yml` exists (requires semgrep installed)
10401040
- Property tests (pytest) - only if `tests/contracts/` directory exists
10411041
- Smoke tests (pytest) - only if `tests/smoke/` directory exists
10421042
1043+
**CrossHair Setup**: Before running `repro` for the first time, set up CrossHair configuration:
1044+
```bash
1045+
specfact repro setup
1046+
```
1047+
This automatically generates `[tool.crosshair]` configuration in `pyproject.toml` to enable contract exploration.
1048+
10431049
**Important**: `repro` does **not** perform runtime contract validation (checking `@icontract` decorators at runtime). It runs static analysis (linting, type checking) and symbolic execution (CrossHair) for contract exploration. Type mismatches will be detected by the type checking tool (basedpyright) if available. The enforcement configuration determines whether failures block the workflow.
10441050
10451051
### Example 3 - Step 6: Verify Results

docs/examples/quick-examples.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ specfact enforce sdd
174174
## Validation
175175

176176
```bash
177+
# First-time setup: Configure CrossHair for contract exploration
178+
specfact repro setup
179+
177180
# Quick validation
178181
specfact repro
179182

docs/getting-started/first-steps.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@ specfact bridge constitution bootstrap --repo .
106106
### Step 3: Find and Fix Gaps
107107

108108
```bash
109+
# First-time setup: Configure CrossHair for contract exploration
110+
specfact repro setup
111+
109112
# Analyze and validate your codebase
110113
specfact repro --verbose
111114
```
112115

113116
**What happens**:
114117

115-
- Runs the full validation suite (linting, type checking, contracts, tests)
118+
- `repro setup` configures CrossHair for contract exploration (one-time setup)
119+
- `repro` runs the full validation suite (linting, type checking, contracts, tests)
116120
- Identifies gaps and issues in your codebase
117121
- Generates enforcement reports that downstream tools (like `generate fix-prompt`) can use
118122

docs/getting-started/installation.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ jobs:
125125
- name: Install SpecFact CLI
126126
run: pip install specfact-cli
127127

128+
- name: Set up CrossHair Configuration
129+
run: specfact repro setup
130+
128131
- name: Run Contract Validation
129132
run: specfact repro --verbose --budget 90
130133

@@ -322,6 +325,104 @@ specfact sync repository --repo . --watch
322325
- **Bidirectional sync**: Use `sync bridge --adapter <adapter>` or `sync repository` for ongoing change management
323326
- **Semgrep (optional)**: Install `pip install semgrep` for async pattern detection in `specfact repro`
324327

328+
---
329+
330+
## Supported Project Management Tools
331+
332+
SpecFact CLI automatically detects and works with the following Python project management tools. **No configuration needed** - it detects your project's environment manager automatically!
333+
334+
### Automatic Detection
335+
336+
When you run SpecFact CLI commands on a repository, it automatically:
337+
338+
1. **Detects the environment manager** by checking for configuration files
339+
2. **Detects source directories** (`src/`, `lib/`, or package name from `pyproject.toml`)
340+
3. **Builds appropriate commands** using the detected environment manager
341+
4. **Checks tool availability** and skips with clear messages if tools are missing
342+
343+
### Supported Tools
344+
345+
#### 1. **hatch** - Modern Python project manager
346+
347+
- **Detection**: `[tool.hatch]` section in `pyproject.toml`
348+
- **Command prefix**: `hatch run`
349+
- **Example**: `hatch run pytest tests/`
350+
- **Use case**: Modern Python projects using hatch for build and dependency management
351+
352+
#### 2. **poetry** - Dependency management and packaging
353+
354+
- **Detection**: `[tool.poetry]` section in `pyproject.toml` or `poetry.lock` file
355+
- **Command prefix**: `poetry run`
356+
- **Example**: `poetry run pytest tests/`
357+
- **Use case**: Projects using Poetry for dependency management
358+
359+
#### 3. **uv** - Fast Python package installer and resolver
360+
361+
- **Detection**: `[tool.uv]` section in `pyproject.toml`, `uv.lock`, or `uv.toml` file
362+
- **Command prefix**: `uv run`
363+
- **Example**: `uv run pytest tests/`
364+
- **Use case**: Projects using uv for fast package management
365+
366+
#### 4. **pip** - Standard Python package installer
367+
368+
- **Detection**: `requirements.txt` or `setup.py` file
369+
- **Command prefix**: Direct tool invocation (no prefix)
370+
- **Example**: `pytest tests/`
371+
- **Use case**: Traditional Python projects using pip and virtual environments
372+
373+
### Detection Priority
374+
375+
SpecFact CLI checks in this order:
376+
377+
1. `pyproject.toml` for tool sections (`[tool.hatch]`, `[tool.poetry]`, `[tool.uv]`)
378+
2. Lock files (`poetry.lock`, `uv.lock`, `uv.toml`)
379+
3. Fallback to `requirements.txt` or `setup.py` for pip-based projects
380+
381+
### Source Directory Detection
382+
383+
SpecFact CLI automatically detects source directories:
384+
385+
- **Standard layouts**: `src/`, `lib/`
386+
- **Package name**: Extracted from `pyproject.toml` (e.g., `my-package` → `my_package/`)
387+
- **Root-level**: Falls back to root directory if no standard layout found
388+
389+
### Example: Working with Different Projects
390+
391+
```bash
392+
# Hatch project
393+
cd /path/to/hatch-project
394+
specfact repro --repo . # Automatically uses "hatch run" for tools
395+
396+
# Poetry project
397+
cd /path/to/poetry-project
398+
specfact repro --repo . # Automatically uses "poetry run" for tools
399+
400+
# UV project
401+
cd /path/to/uv-project
402+
specfact repro --repo . # Automatically uses "uv run" for tools
403+
404+
# Pip project
405+
cd /path/to/pip-project
406+
specfact repro --repo . # Uses direct tool invocation
407+
```
408+
409+
### External Repository Support
410+
411+
SpecFact CLI works seamlessly on **external repositories** without requiring:
412+
413+
- ❌ SpecFact CLI adoption
414+
- ❌ Specific project structures
415+
- ❌ Manual configuration
416+
- ❌ Tool installation in global environment
417+
418+
**All commands automatically adapt to the target repository's environment and structure.**
419+
420+
This makes SpecFact CLI ideal for:
421+
422+
- **OSS validation workflows** - Validate external open-source projects
423+
- **Multi-project environments** - Work with different project structures
424+
- **CI/CD pipelines** - Validate any Python project without setup
425+
325426
## Common Commands
326427

327428
```bash

docs/guides/migration-0.16-to-0.19.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ specfact implement tasks .specfact/projects/my-bundle/tasks.yaml
3434
Use the new bridge commands instead:
3535

3636
```bash
37+
# Set up CrossHair for contract exploration (one-time setup, only available since v0.20.1)
38+
specfact repro setup
39+
3740
# Analyze and validate your codebase
3841
specfact repro --verbose
3942

docs/guides/speckit-journey.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ specfact sync bridge --adapter speckit --bundle <bundle-name> --repo . --bidirec
252252
# Start in shadow mode (observe only)
253253
specfact enforce stage --preset minimal
254254

255+
# Set up CrossHair for contract exploration
256+
specfact repro setup
257+
255258
# Review what would be blocked
256259
specfact repro --verbose
257260

@@ -285,6 +288,7 @@ specfact repro --fix # Apply Semgrep auto-fixes, then validate
285288
specfact enforce stage --preset strict
286289

287290
# Full automation (CI/CD, brownfield analysis, etc.)
291+
# (CrossHair setup already done in Week 3)
288292
specfact repro --budget 120 --verbose
289293
```
290294

@@ -411,6 +415,9 @@ specfact enforce stage --preset strict
411415
### **Step 6: Validate**
412416

413417
```bash
418+
# Set up CrossHair for contract exploration (one-time setup)
419+
specfact repro setup
420+
414421
# Run all checks
415422
specfact repro --verbose
416423

docs/guides/use-cases.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ specfact enforce stage --preset strict
310310
#### 7. Validate
311311

312312
```bash
313+
# First-time setup: Configure CrossHair for contract exploration
314+
specfact repro setup
315+
316+
# Run validation
313317
specfact repro --verbose
314318
```
315319

@@ -440,6 +444,9 @@ specfact enforce stage --preset strict
440444
#### 5. Validate Continuously
441445
442446
```bash
447+
# First-time setup: Configure CrossHair for contract exploration
448+
specfact repro setup
449+
443450
# During development
444451
specfact repro
445452
@@ -505,6 +512,9 @@ jobs:
505512
- name: Install SpecFact CLI
506513
run: pip install specfact-cli
507514
515+
- name: Set up CrossHair Configuration
516+
run: specfact repro setup
517+
508518
- name: Run Contract Validation
509519
run: specfact repro --verbose --budget 90
510520
@@ -625,6 +635,9 @@ specfact plan compare \
625635
#### 4. Enforce Consistency
626636
627637
```bash
638+
# First-time setup: Configure CrossHair for contract exploration
639+
specfact repro setup
640+
628641
# Add to CI
629642
specfact repro
630643
specfact plan compare --manual contracts/shared/plan.bundle.yaml --auto .

docs/guides/workflows.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ specfact enforce stage --preset strict
254254
### Running Validation
255255

256256
```bash
257+
# First-time setup: Configure CrossHair for contract exploration
258+
specfact repro setup
259+
257260
# Quick validation
258261
specfact repro
259262

@@ -266,7 +269,8 @@ specfact repro --fix --budget 120
266269

267270
**What it does**:
268271

269-
- Validates contracts
272+
- `repro setup` configures CrossHair for contract exploration (one-time setup)
273+
- `repro` validates contracts
270274
- Checks types
271275
- Detects async anti-patterns
272276
- Validates state machines

0 commit comments

Comments
 (0)