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
10 changes: 8 additions & 2 deletions .bca-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,13 @@ value = 6.0
path = "big-code-analysis-cli/src/commands/report.rs"
qualified = "run_command_report"
metric = "abc"
value = 39.06404996924922
value = 39.93745109543172

[[entry]]
path = "big-code-analysis-cli/src/commands/report.rs"
qualified = "run_command_report"
metric = "halstead.effort"
value = 63991.55666020266
value = 64495.18935578189

[[entry]]
path = "big-code-analysis-cli/src/diff.rs"
Expand Down Expand Up @@ -1393,6 +1393,12 @@ qualified = "metric_values"
metric = "halstead.effort"
value = 89579.4980762016

[[entry]]
path = "src/output/sarif.rs"
qualified = "write_sarif_with_provenance"
metric = "nargs"
value = 5.0

[[entry]]
path = "src/spaces.rs"
qualified = "FuncSpace::new"
Expand Down
7 changes: 6 additions & 1 deletion .checkmake.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
; `recovery-oracle-test`, `perturb-test`, `coverage-diff-test`,
; `drift-common-test`) took the `help` body from 143 to 149 against a
; cap with 2 lines of headroom. 165 restores the 15.
;
; Raised from 165 to 170 in #1773: the two baseline-check targets
; (`self-scan-baseline-fresh`, `self-scan-profile-parity`) took the
; `help` body from 149 to 152 (with `self-scan-bca-test`), leaving 13
; of the promised 15.

[maxbodylength]
maxBodyLength = 165
maxBodyLength = 170
15 changes: 13 additions & 2 deletions .github/workflows/baseline-freshness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ jobs:
with:
shared-key: pages-scan-release

# Same install as pages.yml, for the same reason (#1773): the
# `make` recipe below would otherwise `cargo run` under the dev
# profile — a cold build on this release-only cache — and the
# `diff-baseline` call would build release separately. One
# release install, handed to the recipe through
# `BCA_SELF_SCAN_BINARY` and used directly for the diff.
- name: Install bca from current checkout
run: cargo install --path big-code-analysis-cli --locked --bin bca

- name: Point the self-scan recipes at the installed binary
run: echo "BCA_SELF_SCAN_BINARY=$(command -v bca)" >> "$GITHUB_ENV"

# `bca diff-baseline` rather than `git diff --exit-code`: a v6
# baseline records `start_line` for the identity triples two
# spaces share, and for those a `git diff` reports code moving
Expand All @@ -82,8 +94,7 @@ jobs:
# than let `set -e` end the step: the two mean different things
# and only one of them is a finding.
status=0
cargo run --quiet --release -p big-code-analysis-cli -- \
diff-baseline "${RUNNER_TEMP}/old.toml" "${RUNNER_TEMP}/new.toml" \
bca diff-baseline "${RUNNER_TEMP}/old.toml" "${RUNNER_TEMP}/new.toml" \
--format markdown --exit-code > "${RUNNER_TEMP}/diff.md" || status=$?
cat "${RUNNER_TEMP}/diff.md"
if [ "$status" = "0" ]; then
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,8 @@ jobs:
run: python3 -B -m unittest -q utils/perturb-test.py
- name: coverage-diff self-tests (explicit)
run: python3 -B -m unittest -q utils/coverage-diff-test.py
- name: self-scan-bca self-tests (explicit)
run: python3 -B -m unittest -q utils/self-scan-bca-test.py
# Defensive twin to the snapshot-anchors gate above: `make lint`
# already invokes check-versions, but pinning it here guarantees
# the lockstep version invariant is enforced even if a future
Expand Down
57 changes: 55 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ on:
- 'tree-sitter-tcl/**'
- 'bca.toml'
- '.bca-baseline.toml'
# The walk deny-set. An edit here changes which files the gate
# measures, so it must re-run the gate (#1773).
- '.bcaignore'
# The gate's own runner. `make self-scan` is the Makefile recipe
# plus the wrapper it execs, and CI's route through the wrapper
# (an explicit `BCA_SELF_SCAN_BINARY`) is one the self-test only
# dry-runs.
- 'Makefile'
- 'utils/self-scan-bca.py'
- 'utils/self_scan_digest.py'
- '.github/workflows/pages.yml'
pull_request:
paths:
Expand All @@ -53,6 +63,14 @@ on:
- 'tree-sitter-tcl/**'
- 'bca.toml'
- '.bca-baseline.toml'
- '.bcaignore'
# The gate's own runner. `make self-scan` is the Makefile recipe
# plus the wrapper it execs, and CI's route through the wrapper
# (an explicit `BCA_SELF_SCAN_BINARY`) is one the self-test only
# dry-runs.
- 'Makefile'
- 'utils/self-scan-bca.py'
- 'utils/self_scan_digest.py'
- '.github/workflows/pages.yml'
workflow_dispatch:

Expand Down Expand Up @@ -232,8 +250,11 @@ jobs:
# bca workspace (many tree-sitter grammar C crates plus the Rust
# workspace itself). Warm-cache runs finish in 3-5 min; the
# ceiling absorbs the worst-case "Cargo.lock churned + Swatinem
# cache evicted" combo without killing useful runs.
timeout-minutes: 30
# cache evicted" combo without killing useful runs. Raised from 30
# for the profile-parity step (#1773), which on that same cold
# cache adds a full dev build and a release relink after the
# install.
timeout-minutes: 45
# security-events:write lets the upload-sarif step publish bca's own
# self-scan offenders to GitHub code scanning (Security tab + PR
# annotations) — dogfooding the SARIF path we document for adopters
Expand Down Expand Up @@ -302,6 +323,17 @@ jobs:
- name: bca version
run: bca --version

# Hand the installed binary to the `make self-scan` recipes below
# (#1773). Without this they would `cargo run` under the dev
# profile — the local default, chosen because the release relink
# costs ~100 s per edit — which here means a cold dev build on a
# release-only cache and a gate measured by a different binary
# from the one the report steps above use. The absolute path is
# what `cargo install` printed; `~/.cargo/bin` is on PATH, but a
# path is unambiguous in the gate log.
- name: Point the self-scan recipes at the installed binary
run: echo "BCA_SELF_SCAN_BINARY=$(command -v bca)" >> "$GITHUB_ENV"

# The deny-set (`exclude_from = ".bcaignore"`) is auto-discovered
# from the repo-root `bca.toml` manifest, so the report
# invocations no longer pass `--exclude-from` — workflow, recipe,
Expand Down Expand Up @@ -399,6 +431,27 @@ jobs:
env:
BCA_SINCE: origin/${{ github.base_ref || 'main' }}

# The dev-profile default behind `make self-scan` locally (#1773)
# rests on both profiles writing the same baseline. This builds
# the dev binary — several minutes cold, since the cache above is
# release-only — and the release one again, since `cargo install`
# builds in its own temporary target directory and leaves nothing
# for `cargo run --release` to reuse, then `cmp`s the two
# regenerations. Per PR rather than quarterly so a divergence is
# attributed to the change that caused it. Not
# `BCA_SELF_SCAN_BINARY`-driven: the recipe builds both sides from
# source on purpose. The release leg is the ~100 s LTO link, warm
# only through the restored cache; the dev artifacts left behind
# grow the `pages-scan-release` entry; split the key if it starts
# evicting, and raise the job timeout if a cold run nears it.
# `success()` rather than the gate's `!cancelled()`: a red gate or
# a failed report step already has the job's answer, and this step
# is the costliest in the job on a cold cache, so it is not spent
# on a run that has already failed.
- name: Profile parity (dev vs release baseline)
if: ${{ success() }}
run: make self-scan-profile-parity

# Dogfood bca's own SARIF writer: re-run the gate as a pure
# emitter (`--no-fail` keeps exit 0 regardless of offenders) so
# this step runs even when the gate above is red, and upload the
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ big-code-analysis-cli/dist/
big-code-analysis-cli/LICENSE
big-code-analysis-cli/THIRD-PARTY-LICENSES-bca.md
big-code-analysis-cli/man/
# Temporary siblings `make self-scan-baseline-fresh` / `-profile-parity`
# write beside the committed baseline (#1773); removed on exit, but a
# Ctrl-C that kills make first can leave one.
.bca-baseline.*.toml
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ repos:
files: '^utils/coverage-diff(-test)?\.py$'
entry: python3 -B -m unittest -q utils/coverage-diff-test.py
pass_filenames: false
- id: self-scan-bca-test
name: self-scan-bca-test
language: system
files: '^utils/(self-scan-bca(-test)?|self_scan_digest)\.py$'
entry: python3 -B -m unittest -q utils/self-scan-bca-test.py
pass_filenames: false
- id: role-coverage
name: role-coverage
language: system
Expand Down
50 changes: 49 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ and `cargo run -p big-code-analysis-web --`.
the enum owns. Each has a `*-test.py` in `make pre-commit` that
stubs the binaries it drives (`coverage-diff-test.py` runs real
`git` on a scratch repository), which is the only thing that lints
them (#1477).
them (#1477). `self-scan-bca.py` is what every `make self-scan*`
recipe runs instead of `cargo run`: it picks the `bca` to execute —
an explicit `BCA_SELF_SCAN_BINARY`, a PATH `bca` whose `--version`
reports a `build inputs:` digest equal to the one
`self_scan_digest.py` recomputes over the checkout, or a dev-profile
`cargo run` — and `exec`s it (#1773). The digest module mirrors
`big-code-analysis-cli/src/build_info/digest.rs`; one fixture and one
pinned hex in `self-scan-bca-test.py` and the Rust tests hold the two
together.
- Other helper scripts: `recreate-grammars.sh`, `generate-grammars/`.
(The grammar-bump diff step now uses the native `bca diff`; the former
`split-minimal-tests.py` + external `json-minimal-tests` chain was
Expand Down Expand Up @@ -518,6 +526,46 @@ that edits the baseline itself then stops the rebase with a conflict,
because the file is `-merge`: regenerate, stage, and `git rebase
--continue`, as for a merge.

**What a refresh costs, and why.** The scan itself is ~0.2 s for the
whole tree; what you wait for is the build. The self-scan recipes
build `bca` under the **dev** profile (#1773): ~5 s for a step that
touched something compiled into it — Rust under `src/`,
`big-code-analysis-ast/src/`, `big-code-analysis-cli/src/`, a grammar
crate's sources, a manifest or `Cargo.lock` — and ~0.1 s for one that
did not, because cargo finds every artifact fresh. A commit that
touches nothing compiled is in the second class even though it moves
`HEAD`: the `git:` field of `bca --version` is deliberately *not*
refreshed on a bare commit, because refreshing it would cost the
rebuild on every step of the rebase loop this paragraph is about (it
is exact as of the last build whose inputs changed; the `build
inputs:` digest, the field the resolver decides on, is exact always).
Integration tests under a crate's `tests/`, `.snap` files and grammar
`node-types.json` are not inputs either. They used to build
release, whose `lto = true` / `codegen-units = 1` relink is ~100 s
after *any* such edit — which made the nine-conflict rebase that
motivated #1773 a ten-minute job. `BCA_SELF_SCAN_PROFILE=release`
restores that build when you need CI's exact profile; `make
self-scan-profile-parity` is the per-PR check that the two profiles
write a byte-identical baseline, and the reason the default is safe.
`BCA_SELF_SCAN_BINARY=<path>` skips the build and runs a prebuilt
binary, trusted as given: sound for a batch no commit of which touches
those compiled-in roots or `Cargo.toml` (the manifest, `.bcaignore`
and the baseline are read at run time, so any binary sees the live
copies), and wrong without a warning otherwise. CI sets it to the
release binary it has just installed from HEAD. A `bca` on PATH needs
no such care: `utils/self-scan-bca.py` uses it only when the `build
inputs:` digest its `--version` reports equals the digest of the
checkout's compiled-in sources, recomputed each run — which is to say
only when it was built from these exact bytes — and otherwise builds.
That proof is what an mtime cannot give (a binary installed from a
newer `main` reads as fresh in an older worktree), and it costs ~0.2 s.
It also bounds what the route can save: a tree whose inputs match an
installed binary is one cargo already finds fresh in ~0.1 s, so the
PATH route matters for the forensic trail and for CI's one-build
guarantee more than for the clock. `make self-scan-baseline-fresh`
answers the question the quarterly job asks — does the committed file
still describe the tree — in a few seconds locally.

**Price a candidate limit at both tiers before calling it free.**
Converging a limit onto a cluster of existing values is never free while
a proportional soft tier is active — the soft tier measures *distance to
Expand Down
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ for historical reference.

### Added

- **`bca --version` records build provenance** (#1773). `-V` is the
unchanged one-line `bca <version>`; `--version` follows it with
`build inputs:` (a SHA-256 content digest of every source compiled
into the binary — the workspace's Rust, manifests and the five
vendored grammars — or `unavailable` for a crates.io build),
`git:` (`<sha>`, `-dirty` when those inputs had uncommitted edits;
exact as of the last build whose inputs changed, since refreshing it
on a bare commit would cost the rebuild #1773 removes),
`built:` (RFC 3339 UTC, honouring `SOURCE_DATE_EPOCH`, with the
profile, `rustc`, target and debug-assertions state) and
`build id:` (the linker's GNU build-id on Linux). Two builds of one
tree share a digest whatever their mtimes or branch, and two
binaries that both print `2.4.0` from different commits do not —
which is the question "is this installed `bca` the one this checkout
would build" needs answered. The digest is stamped into `bca check`'s
SARIF under `tool.driver.properties` (`bca.buildInputs`,
`bca.buildGit`) and abbreviated in the `bca report` footer. Library:
`SarifProvenance` and `write_sarif_with_provenance` are additive; the
two existing SARIF writers emit byte-identical documents.
`utils/self_scan_digest.py` reproduces the digest in Python, pinned to
the Rust implementation by one shared fixture; the vendored grammar
build scripts now watch their `src/tree_sitter/` headers, so a
header-only edit recompiles the parser instead of leaving a stale
object behind a fresh digest.
- `[[thresholds.path]]` in `bca.toml` and `--config`: path-scoped
threshold overrides, layered `[thresholds]` → `[thresholds.lang.<slug>]`
→ `[[thresholds.path]]` → tier → `--threshold`. Each entry's glob is
Expand Down Expand Up @@ -157,6 +181,34 @@ for historical reference.

### Changed

- **The self-scan recipes build `bca` under the dev profile** (#1773).
`make self-scan`, `self-scan-headroom`, both `write-baseline`
recipes and `vcs` used to `cargo run --release`, whose `lto = true`
/ `codegen-units = 1` relink is ~100 s after any `src/` edit — once
per conflicting commit in a rebase, per AGENTS.md's refresh
discipline. The scan itself is ~0.2 s, so the release build was the
whole cost; the dev build is ~5 s for an edit and 0.1 s when nothing
changed, and writes a byte-identical baseline. Two knobs:
`BCA_SELF_SCAN_PROFILE=release` restores the release build, and
`BCA_SELF_SCAN_BINARY=<path>` runs a prebuilt binary without
building — which `pages.yml` and `baseline-freshness.yml` now set to
the release binary they install from the checkout, so CI's gate is
measured by the same binary as its reports. Two new targets check
the baseline file: `self-scan-baseline-fresh` (regenerate to a
temporary sibling and `diff-baseline` against the committed file;
the quarterly job's question, locally) and `self-scan-profile-parity`
(dev and release regenerations `cmp` equal; `pages.yml` runs it per
PR, which is what makes the dev default safe). `.bcaignore` joins
`pages.yml`'s path filters, so an edit to the walk deny-set re-runs
the gate. The recipes run `utils/self-scan-bca.py`, which also
picks up a `bca` on PATH on its own — but only after comparing the
`build inputs:` digest that binary's `--version` reports with a
fresh digest of the checkout, so a binary installed from another
commit can never measure this tree by mistake; a `bca` from before
the field existed, or from crates.io, simply falls through to the
build. `BCA_SELF_SCAN_FROM_SOURCE=1` forces the build whatever else
is set, which is how the parity target keeps its two legs honest.
Repository tooling only; no published API moves.
- **The `loc` declaration gates, the JS-family binding gate and the
Python cognitive boolean-operator questions no longer climb to the
root from every node** (#1767). Each asks a node's ancestors a
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ serde-saphyr = { version = "^2.0", default-features = false, features = [
"serialize",
"deserialize",
] }
# Exact-pinned: the Code Climate writer's per-violation fingerprints and
# the CLI's build-inputs digest (#1773) are both frozen contracts over
# this hash, so the implementation only ever moves deliberately. Here
# rather than in the root `[dependencies]` because the CLI needs the
# same pin twice over (its build script and its tests).
sha2 = "=0.11.1"
tree-sitter = "=0.26.13"
tree-sitter-bash = "=0.25.1"
tree-sitter-c-sharp = "=0.23.5"
Expand Down Expand Up @@ -233,9 +239,9 @@ serde.workspace = true
# which is deterministic and gives the uniform field set #674 requires.
serde_json = { workspace = true, features = ["float_roundtrip"] }
# Used by the GitLab Code Climate writer to compute stable
# per-violation fingerprints. Exact-pinned so the hash implementation
# behind a frozen output contract only ever moves deliberately.
sha2 = "=0.11.1"
# per-violation fingerprints; the pin and its rationale are the
# workspace's.
sha2.workspace = true
# HMAC-SHA256 for the opt-in keyed author-identity hashing
# (`--author-hash-key`, #956). Kept in lockstep with `sha2`: both sit on
# the RustCrypto `digest` 0.11 trait family, which `actix-http` already
Expand Down
Loading
Loading