Repository navigation
fix(rules): stop counting unconditional transfers & non-decision tokens as branch — closes #2832, #2833 - #2923
Merged
Conversation
…ns as branch (#2832, #2833) Per the branch contract's corollary 3 (an unconditional transfer is not a decision) and the #2833 measured residue, the `branch` rule was still counting tokens that aren't runtime choices. This relocates / excludes them, matching how `return`/`goto` were already handled. #2832 — unconditional transfers relocated `branch` -> `structural_boundaries` (beside `return`) in the 12 languages whose rule listed them: c, go, java, javascript, kotlin, lua, objectivec, ruby, shell, solidity, typescript, zig (`break`, `continue`, ruby `next`/`redo`, go `fallthrough`). Python/embedded_python already carried break/continue in boundaries. Still deferred: the two-keyword loop headers (C-family `do…while`, ada `while … loop`) the regex slicer can't collapse with the condition between the keywords. #2833 — non-decision token bleed fixed: - ruby bare `?` now excludes predicate-method names via `(?<!\w)\?`, and drops `=>`. - java bare `:` excludes `::` method references via `(?<!:):(?!:)`. - python/embedded_python `with` (a resource scope) moved to structural_boundaries. Verified with tests/tools/rule_probe.py before/after: the false positives are gone (ruby 266->132, java 428->351, python 8177->7757, c 9720->9310) while legitimate branch keywords still match. Golden masters re-blessed (`crucible_check.py --update --yes`, both modes) because branch counts and the downstream ratios that derive from them (Control Flow Ratio, Cognitive Density, …) shift across the affected languages — this is an intentional precision improvement, not a parser regression. docs/branch_rule_contract.md updated (deferred-residue section + per-language count table). Strict tests for the moved tokens updated to assert structural_boundaries. Closes #2832 Closes #2833 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01QBL6TAMVXRUY7iQyy9Ysvi
Contributor
squid-protocol
deleted the
fix/2832-2833-branch-unconditional-transfers
branch
September 9, 2026 17:47
squid-protocol
added a commit
that referenced
this pull request
Sep 11, 2026
…#2853) (#2966) * fix(rules): apply test-contract C1/C3 to ruby/js/java/groovy/assembly #2853 deferred the #2852 test-contract corollaries for five languages the crucible could not then measure. At the pinned v1.2.0 corpus all five now have files, so apply the fixes (same shape as PR #2923 for #2832/#2833): - ruby (C3): anchor every everyday word to its rspec/minitest form (describe/context -> description string or `do`, it/specify -> string, before/after -> hook call/`do`/:each/:all, let/subject -> `(`/`{`, expect -> `(`, minitest assert/refute -> `assert_<name>`/`assert(`, setup/teardown -> `def`). Ruby has no runtime assert, so assert* stays test's. Prose (`# context`, the noun `assertions`) no longer fires. - javascript (C3/C1): anchor bare describe/expect to `\s*\(`; reduce bare runtime `assert` to the chai chain `assert.<x>` (Node/console.assert is safety's); keep jest/mocha/vitest/cy./beforeEach/afterEach and the already contract-shaped `(?<!\.)\b(?:it|test)\s*\(`; `\bcy\.` anchored so it can't match `transparency.`. - java + groovy (C1): `assert\w*\(` -> `assert\w{1,40}\(` -- keeps the JUnit `assertEquals(` framework form, drops the JLS/power-assert runtime `assert(cond)` (safety's), and bounds the run so a long word-char stream with no `(` can't catastrophically backtrack (a latent ReDoS the new contract-test coverage surfaced). - assembly (C3/C1): drop the `(?i)` bare prose menu describe/expect/assert (and the linker `ASSERT(` guard, safety's); keep the nasm `testcase` macro and call-anchored `it(`. Pipeline reprice (comment-stripped, golden-relevant): javascript 5->0, ruby 2->0, assembly 284->275, groovy 954->954 (no bare power-assert in corpus), java 0->0. Tests: add ruby/js/java/groovy/assembly CASES + COUNTS to test_test_contract_2852.py (java/groovy also added to the C1 runtime-guard-is-safety's test); refresh the assembly strict row + its collision test. docs/test_rule_contract.md: five audit rows moved to "validated"; the deferred-residue bullet rewritten as landed-in-#2853. Golden-master rebless owed (scoring-layer change: `verification`). Closes #2853 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_014rUcYDAzYYCgrLdHyKBT9G * test(golden): rebless test-rule C1/C3 reprice (#2853) The #2853 test-rule fixes drop the comment/prose and runtime-assert residue for ruby/javascript/assembly (groovy/java unchanged in corpus), repricing the `verification` signal. Both golden masters regenerated per-leg in isolated venvs against language-crucible @ v1.2.0. bless_scope.py (both legs): 24 diffs, 0 topological, all substantive and confined to the `test`/`safety` signal family exactly as the contract's Bless scope note predicts -- Unit Test Assertions (7) + Testing Exposure (1) direct; Error & Exception Exposure (11) + safety_score (4) + avg_safety_score (1) are the normalized-relative shifts (a file's exposures are relative to its total magnitude, and the C1 fix moves the dropped runtime `assert` from test to safety). Movement lands on ruby/rails, brew's .rb, vscode's .js and react .js (.rb/.js files nested in mixed-language project dirs); NO files newly parsed or excluded. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_014rUcYDAzYYCgrLdHyKBT9G --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
branchrule was still counting tokens that aren't runtime decisions. This resolves the two deferred residue issues from the #2822 branch-contract audit:break,continue, rubynext/redo, gofallthrough)?, java bare:, pythonwith)How
Per corollary 3 (an unconditional transfer is not a decision), the transfers are relocated
branch→structural_boundaries(besidereturn), matching howreturn/gotowere already handled — not deleted. Applied to the 12 languages whose rule listed them: c, go, java, javascript, kotlin, lua, objectivec, ruby, shell, solidity, typescript, zig. (python/embedded_python already carried break/continue in boundaries.)#2833 token fixes:
\?|=>matchedvalid?, hash rockets(?<!\w)\?(excludes predicate methods),=>dropped:matchedCollection::stream(?<!:):(?!:)(excludes::method refs)withcounted as branchstructural_boundaries(resource scope)Still deferred: the two-keyword loop headers (C-family
do…while, adawhile … loop) — the regex slicer can't collapse them with the condition between the keywords. Documented in the contract.Verification
rule_probe.pybefore/after confirms the false positives are gone while real branch keywords still match: ruby 266→132, java 428→351, python 8177→7757, c 9720→9310 (full per-language table indocs/branch_rule_contract.md).crucible_check.py --update --yes, both full + zero-dep modes). The diff is large because branch counts and the ratios derived from them (Control Flow Ratio, Cognitive Density, Structural Magnitude) shift across the affected languages — an intentional precision improvement, not a parser regression.structural_boundaries. Full extraction + detector suite: 7672 passed, 0 failed.ruff_audit --ciclean.Note
Found and scoped via a per-issue agent analysis pass over the actual rule code + crucible incidence; every claim was verified against
rule_probebefore implementing.Closes #2832, closes #2833
🤖 Generated with Claude Code
https://claude.ai/code/session_01QBL6TAMVXRUY7iQyy9Ysvi