Skip to content

fix(cli): R11(A) — default git_range prefers origin/main..HEAD over HEAD~1..HEAD#104

Merged
montfort merged 1 commit intomainfrom
fix/audit-default-range-origin-main
May 5, 2026
Merged

fix(cli): R11(A) — default git_range prefers origin/main..HEAD over HEAD~1..HEAD#104
montfort merged 1 commit intomainfrom
fix/audit-default-range-origin-main

Conversation

@montfort
Copy link
Copy Markdown
Contributor

@montfort montfort commented May 5, 2026

Summary

Second of 8 PRs implementing the integrated v1 audit-skills iteration described in `Propuesta/devtrail-audit-cli-flow.md` v0.2. Closes R11(A) of issue #102 — default `git_range` was `HEAD~1..HEAD` which fails on multi-commit feature branches.

What was wrong

Sentinel CHARTER-07 was implemented as 8 commits on a feature branch. With the previous default, both auditors processed only the last (metadata-only) commit and converged on "0 substantive findings" vacuously — they never saw the migrations, SQLC, scaffolding, or PII guard test that constituted the actual ~4150 lines of implementation.

What changed

In `cli/src/commands/charter/audit.rs`:

  • New `resolve_default_range(project_root)` helper that probes upstream branches in priority order — `origin/main` first, then `origin/master` (legacy convention) — via `git rev-parse --verify --quiet`. Returns `..HEAD` when one is found.
  • Falls back to `HEAD~1..HEAD` when no upstream is reachable, with a stderr warning suggesting `--range` explicitly.
  • `--range` flag is unchanged: explicit override wins, no upstream probe attempted, no warning.

Tests

  • New helper `init_repo_with_remote_main(dir) -> TempDir` creates a bare remote in its own tempdir (avoiding parallel-test collision on shared `/tmp` parents), pushes main, and spawns a feature branch with multiple commits.
  • 3 new integration tests:
    • `audit_default_range_uses_origin_main_when_available` — happy path with reachable remote.
    • `audit_default_range_falls_back_to_head_minus_one_without_remote` — stderr warning + fallback range.
    • `audit_explicit_range_overrides_default_resolution` — backwards-compat sanity for the `--range` flag.

Test plan

  • `cargo test` → 14 charter_audit (11 + 3 new) + 276 unit + all suites green
  • `cargo build` → 3.65s
  • No version bump (lands together with PRs 3-8 in the integrated v1 release)
  • No CHANGELOG entry (consolidated section at PR 8)

Phase v1 progress

PR Title Status
1 R10 resolver fix merged (#103)
2 `git_range` default → `origin/main..HEAD` with fallback this PR
3 Unified `audit-prompt.md` template (Sentinel skill lift) pending
4 CLI subcommand simplified (`--prepare` / `--merge-reports`) + canonical paths `.devtrail/audits/` pending
5 New skill `devtrail-audit-execute` (3 platforms) pending
6 Updated `audit-prompt` and `audit-review` skills (review.md consolidated) pending
7 Adopter docs (3 langs) pending
8 Bump `fw-4.9.0` / `cli-3.10.0` + CHANGELOG + tag release pending

🤖 Generated with Claude Code

…EAD~1..HEAD

Sentinel CHARTER-07 was implemented as 8 commits on a feature branch.
With the previous default `HEAD~1..HEAD`, both auditors processed only
the last (metadata-only) commit and converged on "0 substantive
findings" vacuously — they never saw the migrations, SQLC, scaffolding,
or PII guard test that constituted the actual ~4150 lines of
implementation. This is R11(A) of issue #102.

Fix in `cli/src/commands/charter/audit.rs`:

- New `resolve_default_range(project_root)` helper that probes upstream
  branches in priority order — `origin/main` first, then `origin/master`
  (legacy convention) — via `git rev-parse --verify --quiet`. Returns
  `<upstream>..HEAD` when one is found, capturing the full implementation
  set since the feature branch diverged from main.
- Falls back to the v0 default `HEAD~1..HEAD` when no upstream is
  reachable (freshly-cloned repo without remote, disconnected branch,
  operator hasn't `git fetch`-ed yet) with a warning to stderr that
  explains the limitation and suggests `--range <REV..REV>` explicitly.
- The `--range` flag is unchanged: explicit operator override still
  wins, and no upstream probe is attempted in that case (no warning).

Tests in `cli/tests/charter_audit_test.rs`:

- New helper `init_repo_with_remote_main(dir) -> TempDir` creates a
  bare remote in its own tempdir (avoiding parallel-test collision on
  shared `/tmp` parents), pushes main, and spawns a feature branch
  with multiple commits. Returns the remote's TempDir so the caller
  keeps it alive for the duration of the test.
- `audit_default_range_uses_origin_main_when_available` — verifies the
  resolved prompt contains `origin/main..HEAD`, NOT the literal
  `HEAD~1..HEAD` fallback.
- `audit_default_range_falls_back_to_head_minus_one_without_remote` —
  verifies stderr warning text and that prompt contains `HEAD~1..HEAD`.
- `audit_explicit_range_overrides_default_resolution` — backwards-compat
  sanity: `--range HEAD~1..HEAD` still wins over the new resolution
  logic and produces NO fallback warning.

Test plan:
- cargo test → 14 charter_audit (11 + 3 new) + 276 unit + all suites
  green.
- cargo build → 3.65s.
- No version bump (lands together with PRs 3-8 in the integrated v1
  release per Propuesta/devtrail-audit-cli-flow.md v0.2 §5).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant