Skip to content

test: share repeated boundary preambles to restore the jscpd gate - #2691

Merged
morluto merged 2 commits into
morluto:mainfrom
NIU-123370:test/share-repeated-boundary-preambles
Oct 13, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
NIU-123370:test/share-repeated-boundary-preambles

Conversation

@NIU-123370

Copy link
Copy Markdown
Contributor

Main fails its own duplicate-code gate

npm run jscpd is the step that exits 1 inside Static checks, and it does so on
current main, not because of any one branch. .jscpd.json sets "threshold": 3.0.
Measured on this box against three trees:

Tree Scanned files Clones Duplicated lines npm run jscpd
bb540826 — base a recently green PR branch used 2321 1427 2.98% exit 0
bf34d0d2 — current main 2367 1480 3.0097% exit 1
this branch 2367 1460 2.9641% exit 0

The main run for 4276aaf1 already concluded failure at 06:58Z today on the same
step, which is why open PRs such as #2486 show a Static checks red while their own
diff contributes nothing to it.

What this changes

Five test files repeat blocks inside themselves, and one shared fixture gains the
narrowing those repeats each re-state. No production code, no assertion, and no test
case is added or removed: the same set of files reports 79 passed before and after
this change on this box.

  • reconstructionCoverage — one fixture helper returns the complete workspace with
    its first verifier result and boundary narrowed, replacing six copies of the same
    preamble; the two "newest observation fails" cases share one evaluation helper.
  • NativeUiObservation — one PNG payload builder and one screenshot observation call
    replace five literal copies. The builder reads width/height from the buffer, so
    each payload keeps exactly the values the copies hardcoded for these fixtures.
  • installScript — the fixture installer environment is built once and spread by the
    exec, pipe and PTY runs, keeping each one's ...process.env and ...overrides
    position.
  • setupClientConfigCleanupOwnership — the VS Code setup preamble and the
    release-then-close assertion tail are each stated once.
  • captureCleanup — the two "refuse before the service is reached" cases share one
    CLI harness; each still asserts its own stdout substring.

Net effect: 15807 → 15564 duplicated lines, 1480 → 1460 clones, 3.0097% → 2.9641%.

Deliberately not touched: the largest new duplication is
src/captures/TsharkCaptureProvider.ts against src/signals/SigrokRecordingProvider.ts
(15 clones, 304 lines, from #2487 and #2496). That is a cross-domain design decision for
those authors rather than a mechanical collapse, so this PR leaves it alone.

Verification

Command Result
npm run jscpd exit 0, 2.96%
npx tsc --noEmit exit 0
npx oxlint exit 0, 0 errors
npx oxfmt --check . exit 0 (3028 files)
npx knip exit 0
npm run verify:architecture-guards exit 0 (1297 source files)
npm run verify:test-discovery exit 0 (1036 test files, each discovered once)
npm run scan:todos exit 0
the five focused test files 79 passed, identical to the same command on bf34d0d2
tests/boundary/mcp/reconstructionCoverageMcp.test.ts (other consumer of the changed fixture) 1 passed

Node 26.11.1 on macOS. No file here is touched by any of the 203 currently open PRs.

Note on the threshold

This buys back headroom (≈190 duplicated lines before the gate trips again), it does
not make the gate self-maintaining. If the project would rather have a ratchet — a
committed ceiling that only ever goes down, checked in check:ci — say so and I can
look at that separately.

Main fails its own duplicate-code gate: npm run jscpd reports 3.01%
duplicated lines against the 3.0% ceiling in .jscpd.json, so Static
checks exits 1 for every branch that merges on top of it.

Collapse blocks these files already repeat locally. The count lands at
2.96% (15807 -> 15564 duplicated lines, 1480 -> 1460 clones) with no
production code touched and no assertion changed.

- reconstructionCoverage: one fixture helper narrows the workspace, its
  first verifier result and boundary; the two newest-observation cases
  share one evaluation helper.
- NativeUiObservation: one PNG payload builder and one screenshot
  observation call replace five literal copies.
- installScript: the fixture installer environment is built once and
  spread by the exec, pipe and PTY runs.
- setupClientConfigCleanupOwnership: the VS Code setup preamble and the
  close-reclaims-handle tail are each stated once.
- captureCleanup: the two pre-service refusals share one CLI harness.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T12:10:58.364649Z 781d659 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Low impact] This PR appears safe to merge; the shared helpers preserve the existing test behavior.

Summary

This PR replaces repeated test setup and cleanup with shared helpers to reduce duplicate code.

  • Reconstruction-coverage tests share their fixture setup.
  • Native UI screenshot tests share their payload and observation setup.
  • Capture cleanup tests share a harness for rejected CLI requests.
  • Installer tests share fixture environment values across run types.
  • Setup cleanup tests share VS Code host and handle helpers.

Reviews (2) · Last reviewed commit: "chore: merge main into shared boundary t..." · Reviewed by Greptile

@morluto morluto added area: domain Domain logic, errors, and pure functions area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: tests Test suite and verification P3: low Low priority, nice to have labels Oct 13, 2026
@morluto
morluto merged commit 8b1549a into morluto:main Oct 13, 2026
36 checks passed
@morluto

morluto commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Appreciate the careful cleanup, @NIU-123370. Sharing repeated fixture setup across the focused tests brought the duplicate-code measure back under the repository’s gate without changing the test cases or their assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: tests Test suite and verification P3: low Low priority, nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants