feat: add client-side JSON Schema 2020-12 preservation scenario (#335)

* feat: add client-side JSON Schema 2020-12 preservation scenario

The mock server, using the version-aware `MockServer` abstraction from #321,
first advertises a focal tool with a detailed inputSchema and also offers a
permissive `json_schema_echo` tool. The client under test retrieves the
inputSchema via `tools/list`, then sends the same inputSchema back to the server
using the echo tool, completing the round-trip.

The scenario diffs from the echoed schema against the canonical fixture. It
emits eight per-keyword conformance checks. SEP-2106 vocabulary checks are
soft-gated using the existing sep2106KeywordCheckStatus helper. They only flip
to FAILURE during DRAFT-2026-v1 runs.

Signed-off-by: Satoshi Ito <satoshi.ito.tf@hitachi.com>

* Drive draft-target preservation tests through the stateless lifecycle

The stateful test helper passed createServerStateful bare, which no longer
compiles now that it takes a second specVersion argument, and forcing the
stateful mock at the draft version trips wire-schema validation (draft
results require the SEP-2549 resultType/ttlMs/cacheScope members). Use
testScenarioContext(DRAFT_PROTOCOL_VERSION), which selects the stateless
mock server, and drive it with sendStatelessRequest, matching the pattern
in json-schema-ref-deref.test.ts.

* Reword client keyword-preservation rows as issue-derived expectations

SEP-2106 §1 contains no normative preservation sentence, so the six new
sep-2106.yaml rows should not attribute a spec MUST to it. Reword the
remaining rows as expectations derived from issue #101. Also drop the
three rows whose check IDs are not sep-prefixed: the traceability
manifest only collects IDs matching /^sep-\d+-/, so those rows could
never be marked tested.

* Replace stale DRAFT-2026-v1 references with the 2026-07-28 draft name

The draft protocol identifier was renamed in #331. Interpolate
DRAFT_PROTOCOL_VERSION into the SKIPPED errorMessage suffix (matching
the server-side scenario) and update the header comment.

---------

Signed-off-by: Satoshi Ito <satoshi.ito.tf@hitachi.com>
Co-authored-by: Paul Carleton <paulc@anthropic.com>
This commit is contained in:
Satoshi Ito 2026-08-01 02:24:05 +09:00 • committed by GitHub
commit 81eb1c3eda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,8 +20,48 @@ import {
import type { RunContext } from '../../connection';
import type { ListToolsResult } from '../../spec-types/2025-11-25';
const EXPECTED_TOOL_NAME = 'json_schema_2020_12_tool';
const EXPECTED_SCHEMA_DIALECT = 'https://json-schema.org/draft/2020-12/schema';
export const EXPECTED_TOOL_NAME = 'json_schema_2020_12_tool';
export const EXPECTED_SCHEMA_DIALECT =
'https://json-schema.org/draft/2020-12/schema';
/**
* Canonical focal `inputSchema` used by both the server-side
* `json-schema-2020-12` scenario (as the schema servers under test are
* expected to emit) and the client-side `json-schema-2020-12-preservation`
* scenario (as the schema the mock server actually emits on the wire).
*
* Keeping a single source of truth ensures the documented requirements and
* the runtime test fixture stay in sync.
*/
export const JSON_SCHEMA_2020_12_FIXTURE = {
$schema: EXPECTED_SCHEMA_DIALECT,
type: 'object',
$defs: {
address: {
$anchor: 'addressDef',
type: 'object',
properties: {
street: { type: 'string' },
city: { type: 'string' }
}
}
},
properties: {
name: { type: 'string' },
address: { $ref: '#/$defs/address' },
contactMethod: { type: 'string', enum: ['phone', 'email'] },
phone: { type: 'string' },
email: { type: 'string' }
},
allOf: [{ anyOf: [{ required: ['phone'] }, { required: ['email'] }] }],
if: {
properties: { contactMethod: { const: 'phone' } },
required: ['contactMethod']
},
then: { required: ['phone'] },
else: { required: ['email'] },
additionalProperties: false
} as const;
/**
* Soft version gate for the SEP-2106 keyword-preservation checks.
@ -55,41 +95,15 @@ export class JsonSchema2020_12Scenario implements ClientScenario {
Implement tool \`${EXPECTED_TOOL_NAME}\` with inputSchema containing JSON Schema 2020-12 features, including the broader vocabulary permitted by SEP-2106 (an \`$anchor\` inside \`$defs\`, composition keywords \`allOf\`/\`anyOf\`, and conditional keywords \`if\`/\`then\`/\`else\`):
\`\`\`json
{
"name": "${EXPECTED_TOOL_NAME}",
"description": "Tool with JSON Schema 2020-12 features",
"inputSchema": {
"$schema": "${EXPECTED_SCHEMA_DIALECT}",
"type": "object",
"$defs": {
"address": {
"$anchor": "addressDef",
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" }
}
}
},
"properties": {
"name": { "type": "string" },
"address": { "$ref": "#/$defs/address" },
"contactMethod": { "type": "string", "enum": ["phone", "email"] },
"phone": { "type": "string" },
"email": { "type": "string" }
},
"allOf": [
{ "anyOf": [{ "required": ["phone"] }, { "required": ["email"] }] }
],
"if": {
"properties": { "contactMethod": { "const": "phone" } },
"required": ["contactMethod"]
},
"then": { "required": ["phone"] },
"else": { "required": ["email"] },
"additionalProperties": false
}
}
${JSON.stringify(
{
name: EXPECTED_TOOL_NAME,
description: 'Tool with JSON Schema 2020-12 features',
inputSchema: JSON_SCHEMA_2020_12_FIXTURE
},
null,
2
)}
\`\`\`
**Verification**: The test verifies that \`$schema\`, \`$defs\`, and \`additionalProperties\` are preserved (SEP-1613), and that the composition (\`allOf\`/\`anyOf\`), conditional (\`if\`/\`then\`/\`else\`), and \`$anchor\` keywords are preserved (SEP-2106), in the tool listing response.`;