Repository navigation
test: pin the uri-safety classifier's own contract - #1262
Merged
Merged
Conversation
scripts/lib/uri-safety.mjs is the shared decision point for the SVG and MDX content gates, but no file under tests/ imported it: every assertion about decodeEntities, normalizeUri, activeScheme and describeTarget was made indirectly, through findActiveContent/findRemoteReferences on a whole SVG or Markdown document. Add tests/uri-safety.test.mjs, which imports the module directly and records today's behaviour for each of those four exports -- both numeric-reference forms and the out-of-range guard, the named references, the deliberate second decode pass, control-character stripping, every script-executing scheme, the scheme-boundary rule in both directions, the active data: media types and the +xml suffix rule, the inert ones, and both sides of describeTarget's 120-character cut. remoteTarget is deliberately left out: #1249 is open over that function. No production code changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: quality <quality@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 keep the |
This was referenced Oct 10, 2026
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
Adds
tests/uri-safety.test.mjs— the first test that importsscripts/lib/uri-safety.mjsdirectly.That module is the shared decision point for both content gates
(
scripts/lib/svg-active-content.mjs:24andscripts/lib/mdx-active-content.mjs:29both import from it), and its headerstates that a divergence between the two gates is "a bypass of whichever gate is
more permissive". Until now no file under
tests/imported it: every assertionabout it was made through
findActiveContent/findRemoteReferenceson a wholeSVG or Markdown document, so the predicate's own boundaries were reached only
through whichever values those fixtures happened to carry.
20 tests, pinning today's behaviour of four exports:
decodeEntities— hexadecimal and decimal references with and without theterminating semicolon; the out-of-range guard (
�and�are handed back unchanged rather than thrown out of
String.fromCodePoint);all seven named references; an unrecognised name left as written.
normalizeUri— the deliberate second decode pass (&#58;→:),whitespace and control-character stripping, lowercasing, and non-string
coercion.
activeScheme— each of the four script-executing schemes; reference- andcontrol-character-obscured forms; the scheme-boundary rule in both
directions (
url(javascript:…)matches,xjavascript:,not-javascript:,x.javascript:andx+javascript:do not); the same boundary fordata:;all nine active
data:media types plus the+xmlsuffix rule; the inerttypes (
image/png,font/woff2,data:,) left alone.Also records that
foo javascript:alert(1)is not flagged —normalizeUriremoves the space before the boundary test, so no scheme boundary survives.
That answer was previously unstated anywhere.
describeTarget— both sides of the 120-character cut, including that thetruncated form is itself exactly 120 characters.
No production code changes; this records existing behaviour only.
Scope and open-PR overlap
remoteTargetis deliberately excluded. #1249 is open and changes exactlythat function (slashless
http:authorities) along withtests/svg-active-content.test.mjs. The four exports covered here are untouchedby #1249 and by #1255, and this PR adds one new file and edits nothing else, so
the diffs do not overlap. A follow-up can extend this file to
remoteTargetonce #1249 lands.
Verification
Repository revision
365e11f(main), node v26.10.0, TZ=UTC:node --test tests/uri-safety.test.mjs→ 20 pass, 0 fail.npm run test:unit:coverage:check→ exit 0;src files | 100.00 | 100.00 | 9015/9015 lines | 2715/2715 regions(region denominator rises from 2713 as the direct import attributes
uri-safety.mjs's regions to the file itself),harness filesandall filesunchanged.npx prettier --check tests/uri-safety.test.mjs→ clean.Related Issue
Closes #1261
Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-opus-5 copilot=1.0.88