test: cover reachable fallback branches in svg-active-content.mjs - #818
Merged
Merged
Conversation
scripts/lib/svg-active-content.mjs was the lowest-region source file in the
repository at 94.07% regions. Five of its nine uncovered sub-line regions are
reachable, and all five sit on a security gate: the code that decides whether
imported third-party SVG executes script or fetches a remote resource.
Add six tests covering them:
- a single-quoted href reaches findRemoteReferences (ATTRIBUTE_PATTERN
alternative 2)
- an unquoted href reaches findRemoteReferences (alternative 3), so
<image href=https://evil.example/b.png> cannot evade the gate unnoticed
- an empty <style></style> block does not break the scan that follows it
- a remote target over 120 characters is truncated with a ... suffix, so one
data-bearing URL cannot flood the import and validation gate output
- an unrecognized named entity survives decodeEntities intact, since dropping
it would splice neighbouring characters and could manufacture a scheme the
source never contained
- an unrecognized named entity does not hide a scheme that follows it
scripts/lib/svg-active-content.mjs goes from 94.07% to 97.06% regions and the
source aggregate from 98.46% to 98.69%, with the existing coverage gate green.
The four remaining regions are unreachable rather than untested: the attribute
and CSS url() patterns always capture exactly one alternative, and an empty
quoted value yields '' rather than undefined, so the trailing ?? '' fallback
short-circuits. No test is added for them.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: hivecommons-hive[bot] <hivecommons-hive@hive.kubestellar.io>
Contributor
Author
|
Important Held for human review by the hive's ACMM level gate. This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Non-outreach agents are held at ACMM L3–L5; the Hive will automatically remove the |
This was referenced Sep 28, 2026
Contributor
Author
CI note (ci-maintainer): the red
|
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.
Test Improvement
scripts/lib/svg-active-content.mjswas the lowest-region source file in the repository — 100.00% lines / 94.07% regions, while every other source file sits at 97.56% or above. Five of its nine uncovered sub-line regions are reachable, and all five sit on a security gate: the code that decides whether third-party SVG imported into the site executes script or fetches a resource from a host the upstream author chose.This PR adds six tests to
tests/svg-active-content.test.mjs. No production file is touched.?? match[3]hrefreachesfindRemoteReferences?? match[4]hrefreachesfindRemoteReferences— so<image href=https://evil.example/b.png>cannot evade the remote-reference gate unnoticedblock[1] || ''<style></style>block does not break the scan that follows it...suffix, so one data-bearing URL cannot flood the import/validate gate output?? matchdecodeEntitiesintact (no false positive) — dropping it would splice neighbouring characters and could manufacture a scheme the source never contained?? matchResult
TZ=UTC node --test tests/svg-active-content.test.mjs→ 53/53 pass. The full suite is 1422 tests, 1420 pass / 0 fail / 2 todo.npm run test:unit:coverage:check(97 / 99 / 93 / 97) exits 0.npx prettier --checkclean.Deliberately not covered
The four remaining regions — trailing
?? ''at lines 153, 194, 302 and 397 — are unreachable, not untested.ATTRIBUTE_PATTERNandCSS_URL_PATTERNalways capture exactly one alternative, and an empty quoted value yields''rather thanundefined, which short-circuits??. That is dead code of the same class already tracked in #699 and #700; no test can reach it, so none is added.Scope
Touches only
tests/svg-active-content.test.mjs, exercisingfindRemoteReferences,describeTargetanddecodeEntities. Disjoint from #810 (tests/import-architecture-issue.test.mjs,tests/helpers-import-issue-sandbox.mjs) and from #812 (scripts/import-architecture-issue.mjs,scripts/lib/mdx-escape.mjs,tests/mdx-escape.test.mjs).Related Issue
Closes #817
Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-opus-5 copilot=1.0.88