Skip to content

chore: add pre-commit research validation - #222

Merged
RobinLinus merged 4 commits into
solving-bitcoin:mainfrom
brenorb:chore/precommit-validation
Sep 28, 2026
Merged

RobinLinus merged 4 commits into
solving-bitcoin:mainfrom
brenorb:chore/precommit-validation

Conversation

@brenorb

@brenorb brenorb commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add an opt-in Git pre-commit hook for knowledge validation and Rust formatting. Before checking the checkout, the hook rejects tracked differences from the index and every non-ignored untracked file, preventing an unstaged fix from validating different staged bytes. Ignored files are outside this guard.

The full primitive metric suite runs only when explicitly requested with RUN_PRIMITIVE_METRICS=1 git commit. CONTRIBUTING.md documents installation and this behavior.

Validation

A nine-scenario temporary-Git contract harness covers the original partial-stage defect, fixed rejection, valid staging with spaces/deletions, unstaged dependencies, untracked files, validator failures, preservation of staged state, metric opt-in, and a linked worktree. It is included in normal Python unittest discovery. Checker stubs inspect fixture content; these tests do not claim to execute the real metric suite.

The actual hook passed on the fully staged integrated tree: KB validation and Rust formatting succeeded. Shell syntax and whitespace checks also passed. The broad metric and field-arithmetic suites were not run for this revision.

Copy link
Copy Markdown
Contributor

Review: changes required before merge.

The hook chooses checks from the staged paths but executes them against the working tree. With a partially staged file, it can validate an unstaged fix while the committed version still fails. Validate a snapshot of the index (or explicitly reject relevant staged/unstaged divergence). Also, any staged source/README change currently triggers every active primitive metric test, including unrelated primitives; this conflicts with the current targeted-test guidance. Select affected metric checks and keep broad runs opt-in.

Evidence: inspected. Run the affected focused checks after the correction; no full-repository run is requested.

Reviewed commit: e27160292ccbe177a5c0905f1c23631918926ba6.

Copy link
Copy Markdown
Contributor

Review of 79308bd8f831d19f8585fbaee03c0d47631258c8:

The hook still chooses checks from the index but runs them on the working tree, so a partially staged file can commit a failing version while an unstaged fix passes validation. Validate an index snapshot or reject relevant staged/unstaged divergence. Also replace the unconditional full primitive_metrics run for every source/README change with affected checks or an explicit opt-in; AGENTS.md requires scoped primitive validation. The latest PR workflow also fails its formatting step. Rebase and rerun formatting/KB checks after addressing the hook behavior.

Holding this version for the concrete change above.

Validation scope: source/diff and existing CI review; no new full-repository or field-arithmetic test run was requested.

@brenorb

brenorb commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 67723a6, integrated with main at e9d5a66.

Reproduced the original bug in a temporary Git repository: the hook allowed a commit containing staged-bad bytes while its checker read working-tree-good bytes. The hook now rejects tracked index/checkout differences and every non-ignored untracked file before invoking checkout-wide checks. It leaves the index and tracked contents intact. This is the conservative divergence-rejection option; ignored files are explicitly outside the guard.

Removed automatic full-suite metric selection. The full primitive_metrics suite now requires RUN_PRIMITIVE_METRICS=1; CONTRIBUTING.md and the PR description reflect that opt-in.

Added nine real-Git contract scenarios, including the original defect, fixed partial-stage rejection, valid changes with spaces/deletions, unstaged dependencies, untracked sources, restored deletions, validator failure propagation/state preservation, metric opt-in, and a linked worktree. A unittest wrapper includes this harness in existing CI discovery. Checker stubs inspect fixture content and verify orchestration; they do not substitute for real Rust validation.

The actual hook passed on the fully staged integrated tree with metrics disabled: KB validation (101 records/256 configurations) and Rust formatting passed. The contract harness, shell syntax, and whitespace checks also passed. No broad repository, full metric, or field-arithmetic suite was run for this revision.

@RobinLinus
RobinLinus merged commit 4a45d98 into solving-bitcoin:main Sep 28, 2026
3 checks passed
@brenorb
brenorb deleted the chore/precommit-validation branch October 28, 2026 02:57
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.

2 participants