Skip to content

test(mcp): add RFC 8785 canonicalization regression fixtures for #7935 - #8481

Open
zsobpeter-code wants to merge 2 commits into
apache:masterfrom
zsobpeter-code:mcp-7935-canonicalization-fixtures
Open

zsobpeter-code wants to merge 2 commits into
apache:masterfrom
zsobpeter-code:mcp-7935-canonicalization-fixtures

Conversation

@zsobpeter-code

Copy link
Copy Markdown

Related to #7935

What this adds

Test-only regression fixtures and a test-scoped RFC 8785 (JCS) reference canonicalizer for MCP tools/list descriptors in shenyu-plugin-mcp-server. No production code changes.

  • src/test/resources/mcp-7935/rfc8785/: synthetic tools/list documents with one tool (name, description, inputSchema), as before/after pairs whose raw bytes differ only by
    • number spelling (RFC 8785 §3.2.2.3: 4.50/4.5, 1E30/1e+30, 2e-3/0.002, 1.0/1, -0/0, 1e-7, the 24 Appendix B rows with a canonical form, and 2^53+1 pinned to 9007199254740992),
    • string escaping (§3.2.2.2: the 32 control characters, quote, backslash, DEL, U+20AC, U+1F600, solidus),
    • member order (§3.2.3: the seven-key Unicode sorting data, ""/"a"/"aa"/"ab", and an ASCII descriptor reordered at three levels: different raw bytes, same canonical bytes, i.e. no canonical descriptor drift),
    • plus a negative control: a real schema change (a field becomes required) changes the canonical bytes, so the canonicalizer does not hide drift.
  • Each fixture has a .sha256 sidecar for its canonical bytes and an expected canonical file, following shenyu-admin/src/test/resources/app-auth.
  • expected/canonical-equivalence.json records raw_equal, canonical_equal and semantic_equivalence_proof: false per pair. Canonical equality is not schema-semantic equivalence and not a compatibility verdict.
  • provenance.json records the synthetic origin, the RFC 8785 sections the expected literals are taken from, and what is not included. The fixtures were independently cross-checked against a separate JavaScript JCS implementation.
  • Rfc8785TestCanonicalizer (test utility, not production) parses with Jackson and writes the canonical form itself; McpContractCanonicalizationFixtureTest checks every pair against the expected bytes and sidecars.

What this does not cover

Runtime pinning, generation consistency under concurrent refresh/pin/unpin, tenant/namespace permissions, and compatibility direction (required/enum/annotation/unsupported composition) remain separate acceptance criteria. Lone surrogates, duplicate member names and NaN/Infinity are rejection cases, not before/after pairs, and are not included (reasons in provenance.json).

Relation to the ChangeProof pilot

These fixtures complement the ChangeProof pilot package (https://github.com/jajazpua/ChangeProof/tree/11bb0c33d70e0211e5649c27566da7069c0f0824/pilots/shenyu-7935) by adding the RFC 8785 number, escaping and Unicode key-order rules next to its ASCII key-order control; none of its files are copied.

No external CLI is required or invoked; the suite runs with the project's Maven/JUnit workflow.

Verification

  • full ./mvnw clean install -Dmaven.javadoc.skip=true (en_US locale): all 216 modules green; one run was interrupted by a transient local port conflict in an unrelated module and resumed with -rf

  • ./mvnw -pl shenyu-plugin/shenyu-plugin-mcp-server -am test -Dtest=McpContractCanonicalizationFixtureTest -Dsurefire.failIfNoSpecifiedTests=false: 7 tests, 0 failures

  • module tests: 231 tests, 0 failures; checkstyle:check and apache-rat:check on the module: passed

  • You have read the contribution guidelines.

  • You submit test cases (unit or integration tests) that back your changes.

  • New production code follows the code quality rules Q1-Q9 in AGENTS.md (no magic numbers, focused methods, reuse of existing utilities).

  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

Aias00
Aias00 previously approved these changes Nov 14, 2026

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stream Agent analysis

Test-only RFC 8785 (JCS) canonicalization regression fixtures and a test-scoped reference canonicalizer for shenyu-plugin-mcp-server (issue #7935). No production code changed.

Evidence

  • Full diff read (has_more=false, 90175 chars): every addition is under shenyu-plugin/shenyu-plugin-mcp-server/src/test/; no src/main/production changes (repository-wide 'src/main' search only matched pre-existing .github/shenyu-admin files).
  • New McpContractCanonicalizationFixtureTest + Rfc8785TestCanonicalizer (ASF-licensed, JUnit5) drive per-pair canonical-byte equality, SHA-256 sidecar verification, raw/canonical-equal flags and a negative-control assertion; two-pow-53-plus-one is listed with a canonical file and a dedicated test.
  • CI complete: discover=success, policy (8481)=success, issue-spec-policy=neutral/completed; passed=true. Fixtures are self-validating via the included tests.

Recommended next steps

Scope: captured diff and GitHub check metadata only; no local tests were executed.

Task: 21ddbe27-c97a-4ebc-8925-ecd18e7c7447 · Commit: a091f0e8dd8c6e504a7e812804ce29c16b646a0f

Review verdict: PASS

Complete test-only change with self-consistent fixtures and a reference canonicalizer validated by the included tests; CI passed; no production impact or concrete defect identified.

Publication: APPROVE (EXPLICIT_PASS)

@wy471x wy471x left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: RFC 8785 canonicalization fixtures for #7935

Verdict: Request changes — small, mechanical fixes; the fixture content itself looks correct.

The RFC 8785 coverage is genuinely good: I spot-checked Appendix B number spellings, 1e+30/0.002/4.5, -0, the lowercase \u001b escaping, raw DEL/€/emoji, unescaped solidus and the UTF-16 code-unit key ordering, and they match the RFC. Hand-writing a test-scoped canonicalizer is defensible here — there is no JCS implementation anywhere in the repo's dependency set to reuse — and the 2^53+1 case is documented honestly in provenance.json ("a parser that keeps arbitrary precision would write 9007199254740993 and fail this case on purpose"), which I initially read as a wrong expectation.

Required changes

  1. Pin the fixture files to LF. McpContractCanonicalizationFixtureTest compares raw committed bytes (Files.readAllBytes(...)) against canonicalizer output, and read(before)/read(after) feed those bytes to the parser. .gitattributes currently only pins shenyu-dist/**/docker/* and script/*.sh, so a Windows checkout with core.autocrlf=true gains CRLF in the 13 .canonical.json files (and in the pairs) and every assertion in testEveryFixtureCanonicalizesToItsExpectedBytes fails for a test that is about JSON bytes, not line endings. One line fixes it: shenyu-plugin/shenyu-plugin-mcp-server/src/test/resources/mcp-7935/** -text (the shenyu-admin/src/test/resources/app-auth precedent you cite has the same latent exposure; that is not a reason to replicate it 74 files wide).
  2. Fix or remove the orphan sidecar. testEverySidecarHoldsTheSha256OfTheCanonicalBytes checks the before/after sidecars plus <pair>.canonical.json.sha256, but a pair with after_canonical (the negative control) also ships rfc8785/negative-control/required-added.after.canonical.json.sha256, which no test ever reads — a wrong hash there passes silently. Either check it when after_canonical is present, or add a test that walks FIXTURE_ROOT and fails on any .sha256 file not referenced by expected/canonical-equivalence.json, which would also catch future orphans.
  3. Name the directory for the behaviour, not the issue. mcp-7935/ is named after a closed issue and will mean nothing once #7935 scrolls away; the subdirectories (numbers, strings, key-order) are already the meaningful axes, so mcp/canonicalization/ (or similar) would age better. Related: provenance.json says the sidecars follow the app-auth convention, but that directory uses stem-based canonical-request.sha256 while these are foo.json.sha256 — pick one.

Droppable, per the review standards

  • For every canonical_equal: true pair, sha256(canonical(before)) == sha256(<pair>.canonical.json), so the before/after sidecars repeat the canonical file's hash. Dropping them would leave one sidecar per fixture instead of three to keep in sync (not required, just noting the bookkeeping cost).
  • testPairEqualityMatchesTheExpectedFile, testAsciiDescriptorKeyOrderIsNoCanonicalDescriptorDrift and testNewRequiredFieldChangesTheCanonicalBytes re-assert what testEveryFixtureCanonicalizesToItsExpectedBytes and the raw_equal/canonical_equal loop already cover. testExpectedFileStatesThatCanonicalEqualityIsNotSemanticEquivalence asserts a prose sentence, so it will fail on rewording while verifying no behaviour. These can go without losing coverage.
  • testTwoPowFiftyThreePlusOneIsWrittenAsTheDoubleItRoundsTo asserts contains("\"minimum\":9007199254740992"), which would be satisfied by any document containing that member; comparing the full canonical bytes (already done in the first test) is stronger.

Spec (#7935)

The PR is upfront that runtime pinning, generation consistency under refresh/pin/unpin, tenant permissions, compatibility direction and legacy-tool shapes are out of scope — that is fine for a fixtures-only PR, and semantic_equivalence_proof: false keeps canonical equality from being read as compatibility. Two things would make the gap easier for reviewers to judge: a short mapping from the six acceptance criteria in #7935 to "covered here / deferred to ", so nobody assumes AC-1 is done; and a note that no production code consumes these fixtures yet, since shenyu-plugin-mcp-server/src/main has no canonicalizer — as things stand this suite guards a helper that only the test tree owns. Also consider dropping the pointer that outsources AC-1 to the external ChangeProof tree: it asks reviewers to trust a package that is not reviewable here.

…ixture with orphan check, rename to mcp/canonicalization, map apache#7935 acceptance criteria

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stream Agent analysis

Test-only PR adding RFC 8785 (JCS) canonicalization regression fixtures and a test-scoped canonicalizer for MCP tools/list descriptors in shenyu-plugin-mcp-server. No production code changes.

Evidence

  • Complete diff read: 82,408 characters across all pages (has_more=false).
  • CI passing: 3 checks completed, all passed, failed_checks=[], passed=true.
  • All 15 fixture pairs verified: number spelling (8), string escaping (1), key order (3), negative control (1) with sidecar SHA-256 integrity and cross-referencing tests.

Recommended next steps

Scope: captured diff and GitHub check metadata only; no local tests were executed.

Task: 276bc87d-860f-4c04-a1dd-73580ba63c0a · Commit: ae0df0d1372d4d136cec07ee177e5d7856f0d42d

Review verdict: PASS

Full diff coverage achieved, CI passing, no concrete blocking defects. Test-only addition with comprehensive RFC 8785 canonicalization fixtures covering number serialization, string escaping, member ordering, and a negative control for real schema changes.

Publication: APPROVE (EXPLICIT_PASS)

This branch has not been deployed

No deployments
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.

3 participants