Skip to content

fix(build): fail the build when an @include marker is missing - #304

Merged
netravnen merged 1 commit into
dev-nextfrom
fix/build-include-marker-guard
Aug 20, 2026
Merged

netravnen merged 1 commit into
dev-nextfrom
fix/build-include-marker-guard

Conversation

@netravnen

Copy link
Copy Markdown
Contributor

INCLUDE_RE.sub never asserted that it matched anything, so a .src.js that
lost its /* @include admincom-common.js */ marker built clean. The
generated file passed node --check -- the syntax is valid, the references
are not -- the script reported "up to date", and the userscript threw
ReferenceError in the browser on first use, because dbg, fetchWithRetry
and the rest of the shared fragment were silently never inlined. Merging
to master is the deploy for this repo, so that reaches every admin before
anyone notices.

Every script here depends on the shared fragment, so zero markers means
the marker was lost, not that a script genuinely needs no lib. The guard
says so and names where to record the exception if one ever does.

Changes:

  • render() uses INCLUDE_RE.subn and raises ValueError on zero
    substitutions, naming the source file and what would have gone wrong.
    The error propagates out of main() before anything is written, so a
    failed build leaves no partially generated file behind.
  • New tests/build-include-marker.test.js covers the failure case and,
    just as importantly, the success case actually inlining the lib -- a
    guard test that only checks the error path cannot tell a working build
    from a broken one.
  • One case asserts the two build guards stay distinguishable: both run
    over the same sources, and a missing marker must not be diagnosed as a
    version problem.

Security:

  • N/A -- build-time only, no product-facing behavior change.

Testing:

  • node --test: 544 tests, 543 pass, 1 skipped (live tests are opt-in).
  • Fixtures and the spawn harness come from tests/helpers/build-script-
    runner.js, shared with the @Version parity tests. Its defaults produce
    a well-formed single-script repo, so a fixture built to exercise one
    guard does not trip the other.
  • Guard reverted to the old sub() call and confirmed red.
  • build_userscripts.py --check still reports all three up to date, so the
    guard does not fire on the real sources.

Backwards Compatibility:

  • A source with a marker builds byte-identically; all three generated
    files are unchanged. Only the previously silent zero-marker case
    changes, from success to a named failure.

Assisted-by: Claude:claude-opus-5


Stack created with GitHub Stacks CLI • Give Feedback 💬

@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from 7c003e9 to 0e486f4 Compare August 19, 2026 22:27
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from 0e486f4 to aac7d02 Compare August 19, 2026 22:28
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from aac7d02 to 6055efd Compare August 19, 2026 22:29
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from 6055efd to b1698a6 Compare August 19, 2026 22:31
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from b1698a6 to 0d7de55 Compare August 19, 2026 23:05
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from 0d7de55 to 533e506 Compare August 19, 2026 23:06
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from 533e506 to d55e86f Compare August 19, 2026 23:07
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from d55e86f to f344c0d Compare August 19, 2026 23:09
Base automatically changed from fix/cp-ixf-merge-gates to dev-next August 20, 2026 09:25
INCLUDE_RE.sub never asserted that it matched anything, so a .src.js that
lost its `/* @include admincom-common.js */` marker built clean. The
generated file passed node --check -- the syntax is valid, the references
are not -- the script reported "up to date", and the userscript threw
ReferenceError in the browser on first use, because dbg, fetchWithRetry
and the rest of the shared fragment were silently never inlined. Merging
to master is the deploy for this repo, so that reaches every admin before
anyone notices.

Every script here depends on the shared fragment, so zero markers means
the marker was lost, not that a script genuinely needs no lib. The guard
says so and names where to record the exception if one ever does.

Changes:
- render() uses INCLUDE_RE.subn and raises ValueError on zero
  substitutions, naming the source file and what would have gone wrong.
  The error propagates out of main() before anything is written, so a
  failed build leaves no partially generated file behind.
- New tests/build-include-marker.test.js covers the failure case and,
  just as importantly, the success case actually inlining the lib -- a
  guard test that only checks the error path cannot tell a working build
  from a broken one.
- One case asserts the two build guards stay distinguishable: both run
  over the same sources, and a missing marker must not be diagnosed as a
  version problem.

Security:
- N/A -- build-time only, no product-facing behavior change.

Testing:
- node --test: 544 tests, 543 pass, 1 skipped (live tests are opt-in).
- Fixtures and the spawn harness come from tests/helpers/build-script-
  runner.js, shared with the @Version parity tests. Its defaults produce
  a well-formed single-script repo, so a fixture built to exercise one
  guard does not trip the other.
- Guard reverted to the old sub() call and confirmed red.
- build_userscripts.py --check still reports all three up to date, so the
  guard does not fire on the real sources.

Backwards Compatibility:
- A source with a marker builds byte-identically; all three generated
  files are unchanged. Only the previously silent zero-marker case
  changes, from success to a named failure.

Assisted-by: Claude:claude-opus-5
@netravnen
netravnen force-pushed the fix/build-include-marker-guard branch from f344c0d to f0ba5b1 Compare August 20, 2026 09:25
@netravnen
netravnen marked this pull request as ready for review August 20, 2026 09:27
@netravnen
netravnen merged commit 9938bc7 into dev-next Aug 20, 2026
2 checks passed
@netravnen
netravnen deleted the fix/build-include-marker-guard branch August 20, 2026 09:39
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.

1 participant