Skip to content

feat(check): add --base flag for cross-file rule parity between local and CI#339

Merged
rhuanbarreto merged 5 commits into
mainfrom
feat/check-base-flag
May 25, 2026
Merged

feat(check): add --base flag for cross-file rule parity between local and CI#339
rhuanbarreto merged 5 commits into
mainfrom
feat/check-base-flag

Conversation

@rhuanbarreto

Copy link
Copy Markdown
Contributor

Summary

  • Auto-detect base branch and populate ctx.changedFiles with the branch diff (git diff <base>...HEAD), giving local developers the same cross-file rule coverage that CI gets — without needing git reset --soft workarounds
  • Add --base [ref] flag to check and review-context commands with resolution priority: --staged--base <ref> → config baseBranch → git auto-detect → empty
  • Add baseBranch field to .archgate/config.json for project-level override

Closes #338

Test plan

  • bun run validate passes (lint, typecheck, format, test, ADR check, knip, build)
  • Unit tests: detectBaseRef() detects local main/master branches, returns null for non-git dirs
  • Unit tests: getFilesChangedSinceRef() returns correct branch diff, empty when on base branch
  • Integration test: --base main with cross-file rule fires violation when only one file changed
  • Integration test: --base main passes when both files changed
  • Integration test: --staged takes precedence over base auto-detection
  • Manual: bun run cli check on main → changedFiles empty (no diff)
  • Manual: create feature branch, commit change, bun run cli check --base main → changedFiles populated

… and CI

`ctx.changedFiles` was empty by default, making cross-file dependency
rules (e.g., "if config.yml changed, manifest.yml must also change")
silently pass locally. These rules only worked in CI via a non-obvious
`git reset --soft` workaround.

Now `archgate check` auto-detects the base branch and populates
`changedFiles` with the branch diff (`git diff <base>...HEAD`). The
resolution priority is: `--staged` flag (skips base) → `--base <ref>`
flag → `.archgate/config.json` `baseBranch` → git auto-detect → empty.

Changes:
- Add `detectBaseRef()` and `getFilesChangedSinceRef()` to git-files.ts
- Add `--base [ref]` flag to `check` and `review-context` commands
- Extend `ProjectConfigSchema` with optional `baseBranch` field
- Extend `runChecks` and `buildReviewContext` options with `base`
- Add `used_base` to check telemetry event
- Add unit tests for new git helpers and integration tests for --base
- Document Bun.env parallel test leakage pattern in agent memory

Closes #338

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 24, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 88cb873
Status: ✅  Deploy successful!
Preview URL: https://a1bbbfb9.archgate-cli.pages.dev
Branch Preview URL: https://feat-check-base-flag.archgate-cli.pages.dev

View logs

@github-actions

github-actions Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Code Coverage

Metric Value
Lines 90.0% (6485 / 7208)
Platforms Linux + Windows

Full HTML report available in workflow artifacts.

Per-directory breakdown
Directory Coverage Lines
src/commands/ 88.1% 2069 / 2348
src/engine/ 92.7% 1185 / 1278
src/formats/ 100.0% 141 / 141
src/helpers/ 89.8% 3090 / 3441

rhuanbarreto and others added 4 commits May 25, 2026 01:38
… tests

Extract duplicated base resolution logic from check.ts and
review-context.ts into a shared resolveBaseRef() function in
git-files.ts. Add integration tests for review-context --base
to close the coverage gap.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Update CLI reference, rule API, concepts, writing-rules guide, and
CI integration guide to document the new --base flag and automatic
base branch detection for changedFiles. Includes both English and
Portuguese (pt-br) translations.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@rhuanbarreto rhuanbarreto merged commit 1058aa5 into main May 25, 2026
12 checks passed
@rhuanbarreto rhuanbarreto deleted the feat/check-base-flag branch May 25, 2026 09:43
@archgatebot archgatebot Bot mentioned this pull request May 25, 2026
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.

feat: add --base flag for cross-file rule parity between local and CI

1 participant