[skip ci] wip: preserve Hermes crank development checkpoint
Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
This commit is contained in:
1 parent
1b6db09bd1
commit
75fe5a123c
357 files changed
+118831
-5113
No files matched your search
@@ -8,6 +8,7 @@ import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
@@ -23,6 +24,7 @@ JUSTFILE = ROOT / "justfile"
|
||||
CI_WORKFLOW = ROOT / ".gitea" / "workflows" / "ci.yml"
|
||||
RELEASE_WORKFLOW = ROOT / ".gitea" / "workflows" / "release.yml"
|
||||
REQUIRED_SURFACES = ROOT / "docs" / "capability-baseline" / "required-surfaces.json"
|
||||
MCP_REVISION_FIXTURES = ROOT / "tests" / "fixtures" / "mcp-revisions"
|
||||
|
||||
|
||||
def load_validator_module():
|
||||
@@ -106,6 +108,7 @@ class CapabilityInventoryValidatorTests(unittest.TestCase):
|
||||
self,
|
||||
required_frs: list[str],
|
||||
install_schema: bool = True,
|
||||
mode: str | None = None,
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
if install_schema:
|
||||
self.install_canonical_schema()
|
||||
@@ -121,6 +124,8 @@ class CapabilityInventoryValidatorTests(unittest.TestCase):
|
||||
]
|
||||
for requirement in required_frs:
|
||||
command.extend(["--required-fr", requirement])
|
||||
if mode is not None:
|
||||
command.extend(["--mode", mode])
|
||||
return subprocess.run(
|
||||
command,
|
||||
check=False,
|
||||
@@ -838,5 +843,744 @@ class CapabilityInventoryValidatorTests(unittest.TestCase):
|
||||
self.assertLess(release.index("Check Community scope"), release.index("Build release binaries"))
|
||||
|
||||
|
||||
# --- Story 3.1 ATDD (red): the approved two-revision MCP window -------------------------------
|
||||
# Oracle: tests/fixtures/mcp-revisions/* (owner-approved 2026-10-11 contract, source-backed, not a
|
||||
# snapshot of current output). Behaviour is observed on the real validator
|
||||
# (scripts/validate-capability-inventory.py) and the real schema copy.
|
||||
# The protocol vocabulary here (supported/not_applicable/experimental/deferred) is deliberately
|
||||
# separate from the unchanged flow vocabulary (implemented/planned/gap/blocked).
|
||||
|
||||
PROTOCOL_STATUSES = {"supported", "not_applicable", "experimental", "deferred"}
|
||||
|
||||
def load_revision_fixture(self, name: str) -> dict[str, object]:
|
||||
return json.loads((MCP_REVISION_FIXTURES / name).read_text(encoding="utf-8"))
|
||||
|
||||
def write_revision_inventory(self, name: str) -> tuple[dict[str, object], dict[str, object]]:
|
||||
payload = self.load_revision_fixture(name)
|
||||
expected = payload.pop("expected", {})
|
||||
for flow in payload.get("flows", []): # type: ignore[union-attr]
|
||||
for kind in ("automated", "manual"):
|
||||
for relative in flow.get("evidence", {}).get(kind, []):
|
||||
self.write_evidence(relative)
|
||||
self.inventory_path.write_text(
|
||||
json.dumps(payload, indent=2, sort_keys=True) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return payload, expected # type: ignore[return-value]
|
||||
|
||||
def required_surfaces(self) -> set[str]:
|
||||
oracle = self.load_revision_fixture("source-backed-capabilities.json")
|
||||
return {
|
||||
item["surface"]
|
||||
for item in oracle["items"] # type: ignore[index]
|
||||
if item["role"] == "server"
|
||||
}
|
||||
|
||||
def test_at_3_1_01_full_reviewed_candidate_passes_the_validity_gate(self) -> None:
|
||||
"""Target oracle: the FULL reviewed candidate is an accepted v2 inventory (Gate A, exit 0).
|
||||
|
||||
This is a genuine behavioural RED on the current revision: the validator has no v2 `protocol`
|
||||
block, so it answers `schema_version 1 is required` / `UNKNOWN_FIELD`. The assertions below
|
||||
describe the agreed target behaviour and are deliberately NOT relaxed to the current one.
|
||||
"""
|
||||
self.write_candidate_inventory()
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertEqual(
|
||||
result.returncode,
|
||||
0,
|
||||
"the complete reviewed v2 candidate must pass the validity gate, observed: " + combined,
|
||||
)
|
||||
# The agreed validity output is the existing one-line summary plus the protocol counts.
|
||||
self.assertIn("Capability inventory validation passed", combined)
|
||||
self.assertRegex(combined, r"\bprotocol_items=50\b")
|
||||
self.assertRegex(combined, r"\brevisions=2\b")
|
||||
|
||||
def test_at_3_1_01_scoped_pre_atdd_candidate_stays_a_scoped_input(self) -> None:
|
||||
"""Preserved pre-ATDD input: the scoped window candidate is NOT promoted to full validity.
|
||||
|
||||
Pure oracle-input provenance - no validator run, so this is not labelled validator GREEN. The
|
||||
file keeps its own recorded verdict (`counts_as_exhaustive: false`, completeness BLOCKED) and
|
||||
stays byte-identical (checked by the ATDD snapshot verifier); the reviewed candidate above is
|
||||
the completeness basis.
|
||||
"""
|
||||
payload, expected = self.write_revision_inventory("inventory-two-revision-window.json")
|
||||
protocol: Any = payload["protocol"]
|
||||
cells = protocol["capabilities"]
|
||||
|
||||
self.assertEqual(payload["schema_version"], 2)
|
||||
self.assertEqual(
|
||||
[entry["revision"] for entry in protocol["revisions"]],
|
||||
["2026-07-28", "2025-11-25"],
|
||||
)
|
||||
self.assertEqual(
|
||||
set(entry["revision"] for entry in protocol["revisions"])
|
||||
& set(protocol["withdrawn"]),
|
||||
set(),
|
||||
)
|
||||
self.assertIn("scope_note", payload)
|
||||
self.assertEqual(expected["gate"], "validity-shape")
|
||||
self.assertEqual(expected["verdict"], "scoped-candidate-not-full-validity")
|
||||
self.assertEqual(expected["completeness"], "blocked-scoped-subset")
|
||||
self.assertEqual({cell["surface"] for cell in cells}, self.required_surfaces())
|
||||
|
||||
def test_at_3_1_01_third_revision_outside_the_approved_window_is_rejected_by_name(self) -> None:
|
||||
"""Bounded one-factor mutation OF THE REVIEWED CANDIDATE: one extra ledger revision entry."""
|
||||
payload = self.write_candidate_inventory("inventory-mutation-third-revision.json")
|
||||
revisions = [entry["revision"] for entry in payload["protocol"]["revisions"]] # type: ignore[index]
|
||||
self.assertEqual(revisions[:2], ["2026-07-28", "2025-11-25"])
|
||||
self.assertEqual(revisions[2:], ["2025-03-26"], "only one revision entry may be added")
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
self.assertIn("2025-03-26", combined)
|
||||
|
||||
def test_at_3_1_03_reviewed_candidate_omission_is_rejected_by_the_triple(self) -> None:
|
||||
"""Bounded one-factor mutation OF THE REVIEWED CANDIDATE: exactly one reviewed row dropped."""
|
||||
payload = self.write_candidate_inventory("inventory-mutation-omission.json")
|
||||
observed = {
|
||||
(cell["role"], cell["kind"], cell["surface"])
|
||||
for cell in payload["protocol"]["capabilities"] # type: ignore[index]
|
||||
}
|
||||
self.assertEqual(len(observed), 49, "only one reviewed identity may be dropped")
|
||||
self.assertNotIn(("client", "method", "prompts/get"), observed)
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
lines = [line for line in combined.splitlines() if "OMISSION" in line]
|
||||
self.assertTrue(
|
||||
any("prompts/get" in line for line in lines),
|
||||
f"the omitted triple must be printed by name: {combined}",
|
||||
)
|
||||
self.assertTrue(
|
||||
any("client" in line and "method" in line for line in lines),
|
||||
f"the full (role, kind, surface) triple must be printed: {combined}",
|
||||
)
|
||||
|
||||
def test_at_3_1_03_undocumented_surface_is_rejected_by_the_triple(self) -> None:
|
||||
"""Bounded one-factor mutation OF THE REVIEWED CANDIDATE: one extra undocumented triple."""
|
||||
payload = self.write_candidate_inventory("inventory-mutation-undocumented-surface.json")
|
||||
observed = {
|
||||
(cell["role"], cell["kind"], cell["surface"])
|
||||
for cell in payload["protocol"]["capabilities"] # type: ignore[index]
|
||||
}
|
||||
self.assertEqual(len(observed), 51, "only one extra identity may be added")
|
||||
self.assertIn(("server", "method", "resources/read"), observed)
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
lines = [line for line in combined.splitlines() if "UNDOCUMENTED_SURFACE" in line]
|
||||
self.assertTrue(
|
||||
any("resources/read" in line for line in lines),
|
||||
f"the undocumented triple must be printed by name: {combined}",
|
||||
)
|
||||
self.assertTrue(
|
||||
any("server" in line and "method" in line for line in lines),
|
||||
f"the full (role, kind, surface) triple must be printed: {combined}",
|
||||
)
|
||||
|
||||
def test_at_3_1_01_revision_missing_only_the_digest_is_rejected_by_that_field(self) -> None:
|
||||
"""One-factor provenance negative: only `provenance.sha256` of the modern revision is gone."""
|
||||
payload = self.write_candidate_inventory("inventory-mutation-missing-digest.json")
|
||||
modern = next(
|
||||
entry
|
||||
for entry in payload["protocol"]["revisions"] # type: ignore[index]
|
||||
if entry["revision"] == "2026-07-28"
|
||||
)
|
||||
self.assertEqual(sorted(modern["provenance"]), ["captured_on", "locator"])
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
diagnostics = [line for line in combined.splitlines() if line.startswith("error[")]
|
||||
digest_lines = [line for line in diagnostics if "sha256" in line]
|
||||
self.assertTrue(
|
||||
any("2026-07-28" in line for line in digest_lines),
|
||||
f"the missing digest must be reported for the revision that lost it: {combined}",
|
||||
)
|
||||
self.assertFalse(
|
||||
any("captured_on" in line for line in diagnostics),
|
||||
f"the date is still present and must not be reported missing: {combined}",
|
||||
)
|
||||
|
||||
def test_at_3_1_01_revision_missing_only_the_date_is_rejected_by_that_field(self) -> None:
|
||||
"""One-factor provenance negative: only `provenance.captured_on` of the modern revision is gone."""
|
||||
payload = self.write_candidate_inventory("inventory-mutation-missing-date.json")
|
||||
modern = next(
|
||||
entry
|
||||
for entry in payload["protocol"]["revisions"] # type: ignore[index]
|
||||
if entry["revision"] == "2026-07-28"
|
||||
)
|
||||
self.assertEqual(sorted(modern["provenance"]), ["locator", "sha256"])
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
diagnostics = [line for line in combined.splitlines() if line.startswith("error[")]
|
||||
date_lines = [line for line in diagnostics if "captured_on" in line]
|
||||
self.assertTrue(
|
||||
any("2026-07-28" in line for line in date_lines),
|
||||
f"the missing capture date must be reported for the revision that lost it: {combined}",
|
||||
)
|
||||
self.assertFalse(
|
||||
any("sha256" in line for line in diagnostics),
|
||||
f"the digest is still present and must not be reported missing: {combined}",
|
||||
)
|
||||
|
||||
def test_at_3_1_03_ordered_validity_first_gate_table_is_exercised_when_mode_exists(self) -> None:
|
||||
"""The agreed validity-first gate table (A0 / B3 / B0 / invalid1) on the real CLI.
|
||||
|
||||
While the CLI exposes no `--mode`, this stays an honest interface gap (skip, never a
|
||||
synthetic red). As soon as `--mode` exists the same test body exercises every agreed row, so
|
||||
a wrong Gate A/B implementation fails here instead of being skipped.
|
||||
"""
|
||||
probe = subprocess.run(
|
||||
[sys.executable, str(VALIDATOR), "--help"],
|
||||
check=False,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
help_text = probe.stdout + probe.stderr
|
||||
self.assertEqual(probe.returncode, 0, help_text)
|
||||
if "--mode" not in help_text:
|
||||
self.skipTest(
|
||||
"interface gap, not a behavioural red: the validator CLI exposes no --mode yet, so "
|
||||
"the ordered validity/feature-complete gate table cannot be exercised on this "
|
||||
"revision"
|
||||
)
|
||||
|
||||
self.install_canonical_schema()
|
||||
|
||||
# invalid1 - structurally invalid input: `invalid` in BOTH modes, step-0 diagnostics, and no
|
||||
# feature-complete evaluation at all (accepted spec `remaining-ac-spec.md:392`).
|
||||
self.inventory_path.write_text("{not-json", encoding="utf-8")
|
||||
for mode in ("validity", "feature-complete"):
|
||||
with self.subTest(row="structural-invalid", mode=mode):
|
||||
result = self.run_validator(["FR-13"], install_schema=False, mode=mode)
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertEqual(result.returncode, 1, combined)
|
||||
self.assertIn("status=invalid", combined)
|
||||
self.assertIn("error[", combined)
|
||||
self.assertNotIn("status=blocked", combined)
|
||||
self.assertNotIn("status=complete", combined)
|
||||
self.assertNotRegex(combined, r"blockers=[1-9]")
|
||||
|
||||
# invalid1 - semantic validity diagnostics (only the modern `provenance.sha256` is gone):
|
||||
# `invalid` in BOTH modes, the targeted missing-digest diagnostic, no feature-complete output
|
||||
# (accepted spec `remaining-ac-spec.md:393`).
|
||||
self.write_candidate_inventory("inventory-mutation-missing-digest.json")
|
||||
for mode in ("validity", "feature-complete"):
|
||||
with self.subTest(row="semantic-invalid", mode=mode):
|
||||
result = self.run_validator(["FR-13"], mode=mode)
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertEqual(result.returncode, 1, combined)
|
||||
self.assertIn("status=invalid", combined)
|
||||
diagnostics = [line for line in combined.splitlines() if line.startswith("error[")]
|
||||
self.assertTrue(
|
||||
any("2026-07-28" in line and "sha256" in line for line in diagnostics),
|
||||
f"the missing digest must be named for the revision that lost it: {combined}",
|
||||
)
|
||||
self.assertNotIn("status=blocked", combined)
|
||||
self.assertNotIn("status=complete", combined)
|
||||
self.assertNotRegex(combined, r"blockers=[1-9]")
|
||||
|
||||
# invalid1 - the rejected false-not-applicable variant: applicable scheduled work renamed to
|
||||
# `not_applicable` must stay `invalid` in BOTH modes, never `complete` with 0 blockers.
|
||||
self.write_candidate_inventory("inventory-mutation-false-not-applicable.json")
|
||||
for mode in ("validity", "feature-complete"):
|
||||
with self.subTest(row="false-not-applicable", mode=mode):
|
||||
result = self.run_validator(["FR-13"], mode=mode)
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertEqual(result.returncode, 1, combined)
|
||||
self.assertIn("status=invalid", combined)
|
||||
self.assertNotIn("status=blocked", combined)
|
||||
self.assertNotIn("status=complete", combined)
|
||||
self.assertNotRegex(combined, r"blockers=[1-9]")
|
||||
|
||||
# A0 / B3 - a truthful candidate passes validity and is blocked by the feature gate.
|
||||
self.write_candidate_inventory()
|
||||
validity = self.run_validator(["FR-13"], mode="validity")
|
||||
self.assertEqual(validity.returncode, 0, validity.stdout + validity.stderr)
|
||||
self.assertIn("Capability inventory validation passed", validity.stdout + validity.stderr)
|
||||
feature_complete = self.run_validator(["FR-13"], mode="feature-complete")
|
||||
self.assertEqual(
|
||||
feature_complete.returncode,
|
||||
3,
|
||||
feature_complete.stdout + feature_complete.stderr,
|
||||
)
|
||||
self.assertIn("status=blocked", feature_complete.stdout + feature_complete.stderr)
|
||||
self.assertRegex(
|
||||
feature_complete.stdout + feature_complete.stderr,
|
||||
r"blockers=[1-9][0-9]*",
|
||||
)
|
||||
|
||||
# B0 - the explicitly SYNTHETIC no-blocker input (hypothetical completed state, marked with
|
||||
# its own owner) is complete in the feature gate.
|
||||
self.write_candidate_inventory("inventory-synthetic-no-blocker.json")
|
||||
validity = self.run_validator(["FR-13"], mode="validity")
|
||||
self.assertEqual(validity.returncode, 0, validity.stdout + validity.stderr)
|
||||
self.assertIn("Capability inventory validation passed", validity.stdout + validity.stderr)
|
||||
feature_complete = self.run_validator(["FR-13"], mode="feature-complete")
|
||||
self.assertEqual(
|
||||
feature_complete.returncode,
|
||||
0,
|
||||
feature_complete.stdout + feature_complete.stderr,
|
||||
)
|
||||
self.assertIn("status=complete", feature_complete.stdout + feature_complete.stderr)
|
||||
self.assertRegex(
|
||||
feature_complete.stdout + feature_complete.stderr,
|
||||
r"blockers=0\b",
|
||||
)
|
||||
|
||||
# --- Story 3.1 remaining-foundation ATDD additions ------------------------------------------
|
||||
# Oracle inputs: the reviewed v2 candidate (`inventory-reviewed-v2-candidate.json`), its bounded
|
||||
# one-factor mutations, and the independent per-era frozen projections. The reviewed identity is
|
||||
# the triple `(role, kind, surface)`; `role` is one enum {server, client, both} with a
|
||||
# kind-specific meaning (declarer for capability/extension, sender for method/notification).
|
||||
# The target validator behaviour (v2 protocol block, Gate A/B split, named diagnostics) does not
|
||||
# exist on this revision, so the assertions below are the contract the implementation stage must
|
||||
# satisfy. Anything that can only fail because a CLI flag or a module is absent is recorded as an
|
||||
# honest API gap, never as a behavioural red and never as a pass.
|
||||
|
||||
REVIEWED_IDENTITY_TRIPLES = {
|
||||
# server capabilities (surface-inventory.md section 3)
|
||||
("server", "capability", "experimental"),
|
||||
("server", "capability", "logging"),
|
||||
("server", "capability", "completions"),
|
||||
("server", "capability", "prompts"),
|
||||
("server", "capability", "resources"),
|
||||
("server", "capability", "tools"),
|
||||
("server", "capability", "extensions"),
|
||||
("server", "capability", "tasks"),
|
||||
# client capabilities (section 4)
|
||||
("client", "capability", "experimental"),
|
||||
("client", "capability", "roots"),
|
||||
("client", "capability", "sampling"),
|
||||
("client", "capability", "elicitation"),
|
||||
("client", "capability", "extensions"),
|
||||
("client", "capability", "tasks"),
|
||||
# methods (section 5); role = the sending party
|
||||
("client", "method", "tools/list"),
|
||||
("client", "method", "tools/call"),
|
||||
("client", "method", "resources/list"),
|
||||
("client", "method", "resources/read"),
|
||||
("client", "method", "resources/templates/list"),
|
||||
("client", "method", "resources/subscribe"),
|
||||
("client", "method", "resources/unsubscribe"),
|
||||
("client", "method", "prompts/list"),
|
||||
("client", "method", "prompts/get"),
|
||||
("client", "method", "completion/complete"),
|
||||
("client", "method", "logging/setLevel"),
|
||||
("client", "method", "initialize"),
|
||||
("both", "method", "ping"),
|
||||
("client", "method", "server/discover"),
|
||||
("client", "method", "subscriptions/listen"),
|
||||
("server", "method", "roots/list"),
|
||||
("server", "method", "sampling/createMessage"),
|
||||
("server", "method", "elicitation/create"),
|
||||
("both", "method", "tasks/get"),
|
||||
("both", "method", "tasks/list"),
|
||||
("both", "method", "tasks/result"),
|
||||
("both", "method", "tasks/cancel"),
|
||||
# notifications (section 6)
|
||||
("server", "notification", "notifications/tools/list_changed"),
|
||||
("server", "notification", "notifications/resources/list_changed"),
|
||||
("server", "notification", "notifications/prompts/list_changed"),
|
||||
("server", "notification", "notifications/resources/updated"),
|
||||
("server", "notification", "notifications/progress"),
|
||||
("server", "notification", "notifications/message"),
|
||||
("server", "notification", "notifications/subscriptions/acknowledged"),
|
||||
("both", "notification", "notifications/cancelled"),
|
||||
("client", "notification", "notifications/initialized"),
|
||||
("client", "notification", "notifications/roots/list_changed"),
|
||||
("both", "notification", "notifications/tasks/status"),
|
||||
("server", "notification", "notifications/elicitation/complete"),
|
||||
# extensions (section 7)
|
||||
("server", "extension", "io.modelcontextprotocol/tasks"),
|
||||
("client", "extension", "io.modelcontextprotocol/oauth-client-credentials"),
|
||||
}
|
||||
|
||||
REVIEWED_ROLES = {"server", "client", "both"}
|
||||
REVIEWED_KINDS = {"capability", "method", "notification", "extension"}
|
||||
REVIEWED_STATUSES = {"supported", "not_applicable", "experimental", "deferred"}
|
||||
|
||||
# Independent per-era ABSENCE oracle, read off the "absent" cells of the reviewed tables in
|
||||
# `build/remaining-ac-spec/surface-inventory.md` sections 3-7 (deliberately NOT taken from the
|
||||
# fixture). Rule O2 resolves an era in two steps (`remaining-ac-spec.md:296-300`): a surface whose
|
||||
# `revisions[]` does not contain the era is ABSENT for that era - never `not_applicable` - and only
|
||||
# then is the shallow `per_revision[era]` merge applied. Applicable per-era completeness is
|
||||
# therefore `REVIEWED_IDENTITY_TRIPLES - REVIEWED_ABSENT_<era>`, not the 50-identity default union.
|
||||
REVIEWED_ABSENT_MODERN = {
|
||||
# sections 3/4: modern expresses Tasks as an extension, so the server `tasks` capability is
|
||||
# absent, and the client `tasks` declaration does not exist in modern either
|
||||
("server", "capability", "tasks"),
|
||||
("client", "capability", "tasks"),
|
||||
# section 5: method literals absent from the pinned modern schema
|
||||
("client", "method", "resources/subscribe"),
|
||||
("client", "method", "resources/unsubscribe"),
|
||||
("client", "method", "logging/setLevel"),
|
||||
("client", "method", "initialize"),
|
||||
("both", "method", "ping"),
|
||||
("both", "method", "tasks/get"),
|
||||
("both", "method", "tasks/list"),
|
||||
("both", "method", "tasks/result"),
|
||||
("both", "method", "tasks/cancel"),
|
||||
# section 6: notifications absent from the pinned modern schema
|
||||
("client", "notification", "notifications/initialized"),
|
||||
("client", "notification", "notifications/roots/list_changed"),
|
||||
("both", "notification", "notifications/tasks/status"),
|
||||
("server", "notification", "notifications/elicitation/complete"),
|
||||
}
|
||||
REVIEWED_ABSENT_LEGACY = {
|
||||
# sections 3/4: neither legacy `ServerCapabilities` nor legacy `ClientCapabilities` has an
|
||||
# `extensions` key
|
||||
("server", "capability", "extensions"),
|
||||
("client", "capability", "extensions"),
|
||||
# sections 5/6: modern-only method literals and the subscription acknowledgement
|
||||
("client", "method", "server/discover"),
|
||||
("client", "method", "subscriptions/listen"),
|
||||
("server", "notification", "notifications/subscriptions/acknowledged"),
|
||||
# section 7: both extension identifiers are declared in the modern schema only
|
||||
("server", "extension", "io.modelcontextprotocol/tasks"),
|
||||
("client", "extension", "io.modelcontextprotocol/oauth-client-credentials"),
|
||||
}
|
||||
|
||||
def load_candidate_fixture(self, name: str = "inventory-reviewed-v2-candidate.json") -> dict[str, object]:
|
||||
return self.load_revision_fixture(name)
|
||||
|
||||
def write_candidate_inventory(self, name: str = "inventory-reviewed-v2-candidate.json") -> dict[str, object]:
|
||||
"""Install a reviewed candidate/mutation fixture as the validator input."""
|
||||
payload = self.load_candidate_fixture(name)
|
||||
for flow in payload.get("flows", []): # type: ignore[union-attr]
|
||||
for kind in ("automated", "manual"):
|
||||
for relative in flow.get("evidence", {}).get(kind, []):
|
||||
self.write_evidence(relative)
|
||||
self.inventory_path.write_text(
|
||||
json.dumps(payload, indent=2, sort_keys=True) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return payload
|
||||
|
||||
def effective_entry(self, entry: dict[str, object], revision: str) -> dict[str, object]:
|
||||
merged = {key: value for key, value in entry.items() if key != "per_revision"}
|
||||
overrides = entry.get("per_revision", {}).get(revision, {}) # type: ignore[union-attr]
|
||||
merged.update(overrides)
|
||||
return merged
|
||||
|
||||
def test_at_3_1_03_reviewed_candidate_is_identity_complete_and_metadata_stays_separate(self) -> None:
|
||||
"""The reviewed completeness basis itself: one judged entry per reviewed row, no more, no less."""
|
||||
payload = self.load_candidate_fixture()
|
||||
protocol: Any = payload["protocol"]
|
||||
|
||||
self.assertEqual(payload["schema_version"], 2)
|
||||
self.assertEqual(
|
||||
[entry["revision"] for entry in protocol["revisions"]],
|
||||
["2026-07-28", "2025-11-25"],
|
||||
)
|
||||
for entry in protocol["revisions"]:
|
||||
provenance = entry["provenance"]
|
||||
self.assertTrue(provenance["locator"] and provenance["sha256"] and provenance["captured_on"])
|
||||
self.assertEqual(protocol["withdrawn"], ["2025-06-18", "2025-03-26"])
|
||||
|
||||
capabilities = protocol["capabilities"]
|
||||
triples = [(cell["role"], cell["kind"], cell["surface"]) for cell in capabilities]
|
||||
self.assertEqual(len(triples), len(set(triples)), "identity is the (role, kind, surface) triple")
|
||||
self.assertEqual(set(triples), self.REVIEWED_IDENTITY_TRIPLES)
|
||||
for cell in capabilities:
|
||||
self.assertIn(cell["role"], self.REVIEWED_ROLES)
|
||||
self.assertIn(cell["kind"], self.REVIEWED_KINDS)
|
||||
self.assertIn(cell["status"], self.REVIEWED_STATUSES)
|
||||
self.assertTrue(cell["owner"] and cell["fallback"] and cell["evidence_target"])
|
||||
if cell["status"] == "supported":
|
||||
self.assertNotIn("reason", cell)
|
||||
else:
|
||||
self.assertTrue(cell["reason"], cell)
|
||||
|
||||
# `io.modelcontextprotocol/related-task` is a non-advertisable `_meta` metadata note, not a
|
||||
# capability extension: it must stay out of the four-kind ledger and out of the advertisement.
|
||||
self.assertFalse(
|
||||
any(
|
||||
cell["surface"] == "io.modelcontextprotocol/related-task"
|
||||
for cell in capabilities
|
||||
),
|
||||
"related-task must not be recorded as a capability/extension entry",
|
||||
)
|
||||
|
||||
# Per-revision overrides are resolved with a shallow per-field merge (rule O2).
|
||||
progress = next(
|
||||
cell
|
||||
for cell in capabilities
|
||||
if cell["surface"] == "notifications/progress" and cell["kind"] == "notification"
|
||||
)
|
||||
self.assertEqual(self.effective_entry(progress, "2025-11-25")["role"], "both")
|
||||
self.assertEqual(self.effective_entry(progress, "2026-07-28")["role"], "server")
|
||||
roots = next(
|
||||
cell
|
||||
for cell in capabilities
|
||||
if cell["surface"] == "roots" and cell["kind"] == "capability"
|
||||
)
|
||||
self.assertEqual(self.effective_entry(roots, "2026-07-28")["subfeatures"], [])
|
||||
self.assertEqual(self.effective_entry(roots, "2025-11-25")["subfeatures"], ["listChanged"])
|
||||
|
||||
# A `both` row satisfies both sender sides but is never advertisable.
|
||||
tools = next(cell for cell in capabilities if cell["surface"] == "tools" and cell["role"] == "server")
|
||||
self.assertEqual(tools["status"], "supported")
|
||||
self.assertEqual(tools["advertised"], {"tools": {"listChanged": False}})
|
||||
for cell in capabilities:
|
||||
resolved = [self.effective_entry(cell, revision) for revision in ("2026-07-28", "2025-11-25")]
|
||||
for effective in resolved:
|
||||
if effective["role"] != "server" or effective["kind"] not in {"capability", "extension"}:
|
||||
self.assertIsNone(effective["advertised"], cell["surface"])
|
||||
if effective["kind"] in {"method", "notification"}:
|
||||
self.assertIsNone(effective["advertised"], cell["surface"])
|
||||
|
||||
def test_at_3_1_03_duplicate_surface_identity_is_rejected_by_the_triple(self) -> None:
|
||||
self.write_candidate_inventory("inventory-mutation-duplicate-identity.json")
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
self.assertIn("DUPLICATE_SURFACE_IDENTITY", combined)
|
||||
self.assertIn("experimental", combined)
|
||||
|
||||
def test_at_3_1_03_advertised_fragment_on_a_non_advertisable_role_is_rejected(self) -> None:
|
||||
self.write_candidate_inventory("inventory-mutation-advertised-on-client-role.json")
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
self.assertIn("ADVERTISED_ON_NON_ADVERTISABLE", combined)
|
||||
self.assertIn("elicitation", combined)
|
||||
|
||||
def test_at_3_1_03_supported_server_capability_must_carry_an_advertised_fragment(self) -> None:
|
||||
self.write_candidate_inventory("inventory-mutation-supported-server-without-advertised.json")
|
||||
|
||||
result = self.run_validator(["FR-13"])
|
||||
|
||||
combined = result.stdout + result.stderr
|
||||
self.assertNotEqual(result.returncode, 0, result.stdout)
|
||||
self.assertIn("tools", combined)
|
||||
self.assertIn("advertised", combined.lower())
|
||||
|
||||
def test_at_3_1_03_effective_per_era_identities_follow_eligibility_then_o2(self) -> None:
|
||||
"""O2 coverage beyond the default 50 identities: effective per-era identity sets.
|
||||
|
||||
Rule O2 resolves an era in two steps (accepted spec `remaining-ac-spec.md:296-300`): a surface
|
||||
whose `revisions[]` does not contain the era is ABSENT for that era - never `not_applicable` -
|
||||
and only then is the shallow `per_revision[era]` merge applied. The expectations below are the
|
||||
reviewed absence sets read off `surface-inventory.md` sections 3-7, not a copy of the fixture:
|
||||
the applicable set of an era is `REVIEWED_IDENTITY_TRIPLES - REVIEWED_ABSENT_<era>` (35 modern,
|
||||
43 legacy on this candidate). The 50-identity default union stays a separate ORACLE-INPUT and is
|
||||
never reported as per-era completeness.
|
||||
"""
|
||||
payload = self.load_candidate_fixture()
|
||||
protocol: Any = payload["protocol"]
|
||||
capabilities: Any = protocol["capabilities"]
|
||||
|
||||
per_era: dict[str, list[tuple[Any, Any, Any]]] = {}
|
||||
progress_reviewed_default = ("server", "notification", "notifications/progress")
|
||||
# The one reviewed per-era identity substitution (surface-inventory.md section 2.1/6): the
|
||||
# progress sender is `server` in the modern revision and `both` in the legacy revision.
|
||||
reviewed_progress_per_era = {
|
||||
"2026-07-28": ("server", "notification", "notifications/progress"),
|
||||
"2025-11-25": ("both", "notification", "notifications/progress"),
|
||||
}
|
||||
for era, absent in (
|
||||
("2026-07-28", self.REVIEWED_ABSENT_MODERN),
|
||||
("2025-11-25", self.REVIEWED_ABSENT_LEGACY),
|
||||
):
|
||||
with self.subTest(era=era):
|
||||
eligible = [cell for cell in capabilities if era in cell["revisions"]]
|
||||
triples = [
|
||||
(self.effective_entry(cell, era)["role"], cell["kind"], cell["surface"])
|
||||
for cell in eligible
|
||||
]
|
||||
per_era[era] = triples
|
||||
expected = (
|
||||
self.REVIEWED_IDENTITY_TRIPLES
|
||||
- absent
|
||||
- {progress_reviewed_default}
|
||||
) | {reviewed_progress_per_era[era]}
|
||||
|
||||
self.assertEqual(
|
||||
len(triples),
|
||||
len(set(triples)),
|
||||
"an override must not create a duplicate EFFECTIVE identity",
|
||||
)
|
||||
self.assertEqual(
|
||||
set(triples),
|
||||
expected,
|
||||
f"the applicable identities of {era} must match the reviewed tables",
|
||||
)
|
||||
self.assertEqual(
|
||||
sorted(absent),
|
||||
sorted(
|
||||
(cell["role"], cell["kind"], cell["surface"])
|
||||
for cell in capabilities
|
||||
if era not in cell["revisions"]
|
||||
),
|
||||
"every explicitly absent reviewed identity must be ineligible in that era",
|
||||
)
|
||||
self.assertEqual(
|
||||
set(triples) & absent,
|
||||
set(),
|
||||
"an absent identity can never be part of the applicable set",
|
||||
)
|
||||
|
||||
self.assertEqual(len(per_era["2026-07-28"]), 35)
|
||||
self.assertEqual(len(per_era["2025-11-25"]), 43)
|
||||
for era, triples in per_era.items():
|
||||
self.assertNotEqual(
|
||||
set(triples),
|
||||
self.REVIEWED_IDENTITY_TRIPLES,
|
||||
f"the default 50-identity union is not the applicable set of {era}",
|
||||
)
|
||||
|
||||
# The only identity that resolves to a different ROLE per era is the agreed progress override.
|
||||
overridden = set()
|
||||
for cell in capabilities:
|
||||
if "2026-07-28" in cell["revisions"] and "2025-11-25" in cell["revisions"]:
|
||||
roles = {
|
||||
era: self.effective_entry(cell, era)["role"]
|
||||
for era in ("2026-07-28", "2025-11-25")
|
||||
}
|
||||
if roles["2026-07-28"] != roles["2025-11-25"]:
|
||||
overridden.add((cell["role"], cell["kind"], cell["surface"]))
|
||||
self.assertEqual(
|
||||
overridden,
|
||||
{("server", "notification", "notifications/progress")},
|
||||
"the agreed per-era role difference is exactly the progress sender override",
|
||||
)
|
||||
|
||||
progress = next(
|
||||
cell
|
||||
for cell in capabilities
|
||||
if cell["surface"] == "notifications/progress" and cell["kind"] == "notification"
|
||||
)
|
||||
self.assertEqual(progress["role"], "server")
|
||||
self.assertEqual(progress["per_revision"]["2025-11-25"]["role"], "both")
|
||||
self.assertEqual(self.effective_entry(progress, "2026-07-28")["role"], "server")
|
||||
self.assertEqual(self.effective_entry(progress, "2025-11-25")["role"], "both")
|
||||
|
||||
# --- B0 / invalid1 inputs of the agreed Gate table (round-2 corrections) ----------------------
|
||||
# Both are fixture oracles only: they inspect the input documents and never run the validator, so
|
||||
# nothing here is called validator GREEN. The executable Gate rows live in the `--mode` table above
|
||||
# and stay an honest interface gap until the CLI exposes `--mode`.
|
||||
|
||||
def test_at_3_1_03_synthetic_no_blocker_variant_is_a_hypothetical_completed_state(self) -> None:
|
||||
"""`inventory-synthetic-no-blocker.json` (B0 row) is synthetic, never a status relabel.
|
||||
|
||||
Every `deferred` reviewed surface is resolved to the hypothetical completed state
|
||||
(`supported`), never to `not_applicable`; advertisable server capability/extension rows carry
|
||||
the exact `advertised` fragment their reviewed `subfeatures` declare; and every flipped row is
|
||||
marked with the owner `atdd-synthetic-no-blocker-input`. The document therefore contains no
|
||||
deferral at all - a no-blocker input under the agreed gate reading and under any stricter one.
|
||||
"""
|
||||
payload = self.load_candidate_fixture("inventory-synthetic-no-blocker.json")
|
||||
protocol: Any = payload["protocol"]
|
||||
capabilities: Any = protocol["capabilities"]
|
||||
reviewed_payload: dict[str, Any] = self.load_candidate_fixture()
|
||||
reviewed: Any = reviewed_payload["protocol"]["capabilities"]
|
||||
reviewed_by_identity = {
|
||||
(cell["role"], cell["kind"], cell["surface"]): cell for cell in reviewed
|
||||
}
|
||||
|
||||
self.assertEqual(
|
||||
[cell["surface"] for cell in capabilities if cell["status"] == "deferred"],
|
||||
[],
|
||||
"the no-blocker input must not defer any reviewed surface",
|
||||
)
|
||||
self.assertEqual(
|
||||
sorted(cell["surface"] for cell in capabilities if cell["status"] == "not_applicable"),
|
||||
sorted(cell["surface"] for cell in reviewed if cell["status"] == "not_applicable"),
|
||||
"the reviewed `not_applicable` rows must stay exactly as reviewed",
|
||||
)
|
||||
|
||||
flipped = 0
|
||||
for cell in capabilities:
|
||||
original = reviewed_by_identity[(cell["role"], cell["kind"], cell["surface"])]
|
||||
if original["status"] != "deferred":
|
||||
self.assertEqual(
|
||||
cell,
|
||||
original,
|
||||
f"only deferred rows may differ from the reviewed candidate: {cell['surface']}",
|
||||
)
|
||||
continue
|
||||
flipped += 1
|
||||
self.assertEqual(cell["status"], "supported", cell["surface"])
|
||||
self.assertNotIn("reason", cell, "a hypothetical `supported` row carries no reason")
|
||||
self.assertEqual(cell["owner"], "atdd-synthetic-no-blocker-input", cell["surface"])
|
||||
self.assertEqual(
|
||||
sorted(cell),
|
||||
sorted(set(original) - {"reason"}),
|
||||
"a flipped row may only change status/reason/advertised/open_subfeatures",
|
||||
)
|
||||
self.assertEqual(flipped, 26, "every deferred reviewed row must be flipped")
|
||||
|
||||
for cell in capabilities:
|
||||
if cell["owner"].startswith("atdd-synthetic") and cell["role"] == "server" and cell[
|
||||
"kind"
|
||||
] in {"capability", "extension"}:
|
||||
self.assertIsNotNone(
|
||||
cell["advertised"],
|
||||
f"a supported server declaration must advertise: {cell['surface']}",
|
||||
)
|
||||
|
||||
def test_at_3_1_03_false_not_applicable_input_keeps_the_planned_reasons(self) -> None:
|
||||
"""`inventory-mutation-false-not-applicable.json` (invalid1 row) is the REJECTED predecessor.
|
||||
|
||||
It is the variant that renames every `deferred` status to `not_applicable` while keeping the
|
||||
planned/deferred reasons, i.e. it claims that applicable, scheduled work is inapplicable. A
|
||||
truthful validity gate must answer `invalid` in BOTH modes and never `complete` / 0 blockers;
|
||||
the executable assertion lives in the `--mode` table, which is an honest interface gap until
|
||||
`--mode` exists.
|
||||
"""
|
||||
payload = self.load_candidate_fixture("inventory-mutation-false-not-applicable.json")
|
||||
protocol: Any = payload["protocol"]
|
||||
capabilities: Any = protocol["capabilities"]
|
||||
reviewed_payload: dict[str, Any] = self.load_candidate_fixture()
|
||||
reviewed: Any = reviewed_payload["protocol"]["capabilities"]
|
||||
reviewed_by_identity = {
|
||||
(cell["role"], cell["kind"], cell["surface"]): cell for cell in reviewed
|
||||
}
|
||||
|
||||
relabelled = 0
|
||||
falsely_inapplicable_server_capabilities = []
|
||||
for cell in capabilities:
|
||||
original = reviewed_by_identity[(cell["role"], cell["kind"], cell["surface"])]
|
||||
if original["status"] != "deferred":
|
||||
self.assertEqual(cell, original, f"only deferred rows may be relabelled: {cell['surface']}")
|
||||
continue
|
||||
relabelled += 1
|
||||
self.assertEqual(cell["status"], "not_applicable", cell["surface"])
|
||||
self.assertEqual(
|
||||
cell["reason"],
|
||||
original["reason"],
|
||||
"the relabel keeps the planned/deferred reason - that is the false claim",
|
||||
)
|
||||
if cell["role"] == "server" and cell["kind"] == "capability":
|
||||
falsely_inapplicable_server_capabilities.append(cell["surface"])
|
||||
|
||||
self.assertEqual(relabelled, 26, "every deferred reviewed row must be relabelled")
|
||||
self.assertEqual(
|
||||
sorted(falsely_inapplicable_server_capabilities),
|
||||
["completions", "logging", "prompts", "tasks"],
|
||||
"applicable server capabilities must never be declared inapplicable",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user