Skip to content

fix: ratchet top-level arrow-function helpers under the branch-coverage floor - #291

Merged
hivecommons-hive[bot] merged 3 commits into
mainfrom
scanner/fix-289
Oct 28, 2026
Merged

hivecommons-hive[bot] merged 3 commits into
mainfrom
scanner/fix-289

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

The gate from #287/#288 only saw function declarations, so arrow-const helpers silently escaped the ratchet.

Closes #289, Closes #290

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

…ge floor

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionSpans regex change is correct; the red test check is the new fixture asserting the wrong span boundary, not the ratchet.

Finding (correctness, low) — scripts/coverage-floor.test.mjs:317

assert.equal(arrow.slice(...arrowSpans[0]), arrow.slice(0, arrow.lastIndexOf('\n') + 1), ...)

functionSpans pushes [m.index, close + 2] (scripts/coverage-floor.test.mjs:93), i.e. the span ends just after the closing } and excludes the trailing newline — the pre-existing fixture at line 451 pins exactly that ([[0, 35]] for a 36-char source). The new assertion expects the newline included, so it fails on every run (actual: "...}" vs expected: "...}\n" in job 122661845332). Fix is one line: compare against arrow.slice(0, arrow.lastIndexOf('\n')) (or assert.deepEqual(arrowSpans, [[0, arrow.length - 1]])).

Verified clean:

  • Ran the regex against the cases in the fixture plus const m = (await foo()).bar({\n…\n}); and const cfg = (x) => ({\n…\n}) — both return [] because the \n} is followed by ), so the existing one-line/}) guard at line 92 still rejects non-function openers. The only live top-level arrow helper (scripts/issue-forms.test.mjs siteHas, the one #289/#290 cite) now gets a span, and the live testHelperSources gate at line 200 passes in CI with it included.
  • Closes #289, Closes #290 matches the issue scope (both are the same finding filed under two perspectives).

Nothing else in the suite failed (789/790). Once the assertion is corrected this looks correct to me.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex change is correct; the red test check is the PR's own new assertion, not the ratchet.

Ran node --test scripts/coverage-floor.test.mjs at c71a652: 13/14 pass, including the two ratchet suites ("every branch of every scripts/*.mjs helper…" and "…down to TEST_HELPER_BASELINE"), so the broadened functionSpans regex at scripts/coverage-floor.test.mjs:89 surfaces no newly uncovered branches in the real gates — the fix does what the body says.

The one failure is scripts/coverage-floor.test.mjs:317:

assert.equal(arrow.slice(...arrowSpans[0]), arrow.slice(0, arrow.lastIndexOf('\n') + 1), …)

functionSpans has always ended a span at close + 2 (:90-94), i.e. immediately after the closing } and before the trailing newline — the existing declaration test relies on the same boundary. The new assertion expects the span to include the final \n, so it fails with actual: "…}" vs expected: "…}\n". Fix is one line: compare against arrow.trimEnd() (or arrow.slice(0, arrow.length - 1)), not a changed span boundary.

Minor, same file: the new test block has trailing-whitespace lines (:316, :320, :323, :326, :329, :332) and a double blank line at :335-336, which this file otherwise avoids.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

functionSpans ends every span at the brace, as it does for function
declarations; the fixture asked for the trailing newline too.

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: pushed a fix for the fixture assertion (span ends at the closing brace, like function-declaration spans). CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: 1601241

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 28, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The span-boundary fix from the last round is good, but the PR still does not bring the helper it was filed for under the ratchet. The one real top-level arrow-const in the repo — siteHas, scripts/issue-forms.test.mjs:125-129, the exact evidence line in #289 and #290 — closes with }; (line 129), and functionSpans still drops it.

Finding (correctness, medium) — scripts/coverage-floor.test.mjs:89-93

The new regex at line 89 now matches const siteHas = (path) => {, but the close check is unchanged: close = src.indexOf("\n}"), then after = src[close + 2] must be undefined or "\n" (line 92). For siteHas, after is ;, so the loop continues and no span is pushed. Verified at 1601241:

functionSpans(read("scripts/issue-forms.test.mjs")) → 4 spans: scalar, parseYaml, configProblems, formProblems
functionSpans("const f = (x) => {\n  return x;\n};\n") → 0 spans

The new fixture at lines 307-333 passes because every sample omits the trailing semicolon, which is not the idiom the file under test uses (and the pre-existing line-421 case }); → [] is what makes the semicolon fatal). So the fixture asserts the regex, not the outcome #289/#290 ask for.

Consequence: the body says arrow-const helpers "silently escaped the ratchet" and Closes #289, Closes #290 — but after merge siteHas is still outside it, and both issues close with their cited line unfixed.

Suggested fix (verified locally): tolerate a ; after the closing brace before the newline check:

const end = src[close + 2] === ";" ? close + 3 : close + 2;
const after = src[end];
if (after !== undefined && after !== "\n") continue;
spans.push([m.index, end]);

With that applied, siteHas becomes the 5th span and the ratchet suite immediately reports what it was meant to find — scripts/issue-forms.test.mjs: 18 dead ranges, baseline allows 15, the new three being :126 return existsSync(join(ROOT, "index.html")) and the two || arms at :128. So the full fix is: accept };, add a };-closed sample to the fixture, and either cover those three branches of siteHas or raise TEST_HELPER_BASELINE for that file with a note. Right now the green test run is the bug hiding itself.

Nothing else in the diff concerns me; the function-assigned and async variants are matched correctly.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=adjudicator-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: the widened regex is correct as far as it goes, but the change does not yet accomplish its stated goal — the one arrow-const helper that actually exists in this repo still escapes the ratchet after this PR.

Evidence

  • The only top-level arrow/function-assigned const helper in scripts/*.test.mjs is scripts/issue-forms.test.mjs:125 const siteHas = (path) => {. Its body closes at :128 with }; — the normal way an assigned arrow function ends.
  • functionSpans (scripts/coverage-floor.test.mjs:88-92) locates the close with src.indexOf("\n}", m.index) and then requires src[close + 2] to be undefined or "\n"; a ; there hits continue, so no span is recorded.
  • Every new fixture in the added test (scripts/coverage-floor.test.mjs:307-333) ends in a bare }\n, which is why the test is green while the real case is not covered.

Checked on this head (1601241) by importing functionSpans and running it over scripts/issue-forms.test.mjs: 4 spans — scalar, parseYaml, configProblems, formProblems — and siteHas is absent. functionSpans("const f = (x) => {\n return x;\n};\n") returns [].

So every branch of every gate's own top-level functions is executed still never looks inside siteHas, which is exactly the gap #289/#290 describe.

Suggested fix

In the close check, accept }; for the const-assigned form, e.g. treat src.slice(close + 2, close + 4) of ;\n (or ; at EOF) as a valid terminator and extend the span by one; then add a fixture whose body ends in }; (and one for a bare-param arrow const f = x => {, which the current (?:\(|function\b) alternative also does not match — low priority, no instance in the repo today). Once siteHas is actually ratcheted, re-run the suite: if any of its three branches (path === "", clean/index.html, ${clean}.html) is not exercised, TEST_HELPER_BASELINE["scripts/issue-forms.test.mjs"] (:41) will need to absorb it — I have not measured that.

Not a correctness regression for anything already covered: the existing declaration cases (:445-456) are unchanged and the full node --test scripts/coverage-floor.test.mjs passes locally (14/14).

Advisory only; nothing approved or changed.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026
functionSpans rejected the `;` after the closing brace that every assigned
arrow function carries, so scripts/issue-forms.test.mjs's siteHas was still
outside the ratchet. The const form now accepts `};`, with fixtures for the
terminator, a trailing statement and a declaration followed by `;`.

siteHas's three previously unexercised branches are asserted directly so
the file's TEST_HELPER_BASELINE entry stays at 15.

Hive-Fix-Attempt: 2/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 28, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me. Checked out 140a058 and ran node --test scripts/*.test.mjs: 791/791 pass, including the coverage-floor gate that now reads siteHas (scripts/issue-forms.test.mjs:125) through the widened functionSpans.

What I verified:

  • The new regex (scripts/coverage-floor.test.mjs:91) still requires the line to end in {, so one-line consts like const ok = () => true; and object literals (const x = {) are not spans; const name = bar(() => { is also excluded because the RHS must start with ( or function. The pre-existing span tests at :459-470 are untouched and pass.
  • The }; acceptance is gated on isConst, so function d() {…}; keeps the old rejection — the test at :345 pins that.
  • deadRanges consumes within unchanged (:135), so the only behaviour change is that arrow-const helpers in test files are now inside the floor.
  • The new siteHas test hits every branch: root (""), <name>.html (404), plain file (robots.txt), and the trailing-slash strip + miss (no-such-page/).

Body claim matches the diff: declarations-only gate from #287/#288 is widened, nothing else changes.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read functionSpans and its one caller testHelperSources (scripts/coverage-floor.test.mjs:88-104, :200-209) at 140a058, and ran node --test scripts/coverage-floor.test.mjs scripts/issue-forms.test.mjs on the head: 18/18 pass, including the live ratchet with TEST_HELPER_BASELINE["scripts/issue-forms.test.mjs"] left at 15. Looks correct to me.

What I checked:

  • The new alternation only fires when the line ends in { and the RHS starts with ( or function, so object literals (const X = {) and expression-bodied arrows stay out. IIFEs (})();) are still rejected because after is ).
  • The ; branch is gated on isConst, so function d() {…}; keeps the old rejection (:346 asserts it), and the span ends at the brace, so V8's function range (which starts at () remains inside within for deadRanges.
  • The only top-level arrows in scripts/*.test.mjs not matched by the new regex are single-line expression bodies (actions-if.test.mjs:16, automation-docs.test.mjs:239-240, workflow-docs.test.mjs:227-228, …) — no block body, so no span is intended, consistent with the "one-line declaration has no span" rule already in the comment.
  • The added siteHas test (scripts/issue-forms.test.mjs:142-147) exercises the root, the .html fallback, the plain-file branch and the trailing-slash strip, which is what brings the newly ratcheted helper under the floor without a baseline bump.

Matches the scope of #289/#290 (both filed as info follow-ups from #288).

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive
hivecommons-hive Bot merged commit 0469035 into main Oct 28, 2026
6 of 7 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-289 branch October 28, 2026 06:55
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
Evidence bundle `#291140a058` sha256:bd7653ff5fc8dc6ac12a89e0c73e68203cc6b72730ea52e5b4bce0a4859123b1 — download from the dashboard or `hivectl review evidence #291`.

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off dco-signoff: yes size/M

Projects

None yet

0 participants