Repository navigation
feat(testing): plugin contract testing harness (Change A) - #29
Merged
Merged
Conversation
Remove the non-standard `version` and `category` keys from the hermes-plugins skill frontmatter, and expand the Shipping section so the skill teaches the source-change / snapshot-promotion / runtime-proof split for plugins deployed through an immutable GitOps snapshot. Also ignore .DS_Store so macOS metadata stops showing up as untracked.
Add the implementation plan for exporting a public test harness from the kit, hardening the Hermes contract gates, and routing plugin authors to both. Delivered as three OpenSpec changes. Grounded in verified findings: a permissive or hand-written fake cannot catch host signature drift (only replaying recorded call arguments through the real signature can), unittest exits 0 on Python 3.11 for both all-skipped and zero-collected runs, and the upstream-drift CI job triggers only on push/pull_request so it never fires when Hermes moves.
Initialize OpenSpec with --tools none, so the repo gains only openspec/ and AGENTS.md keeps sole ownership of agent guidance. Create the three changes the plan defines. The two tooling changes carry skip_specs: true, because they alter no capability-level requirement and the shipped template warns against inventing one to satisfy validation. add-plugin-test-harness introduces a real capability and is authored in full: proposal, spec delta, design, tasks. Enforce the 1.13.1 floor in the justfile rather than relying on whichever machine happened to upgrade. Releases before it could exit 0 from archive having applied less than the delta specified. spec-validate also resolves each authored change's deltas, because validate --strict can pass while archive refuses.
Add hermes_plugin_kit.testing: a recording plugin context a consumer can use with no Hermes checkout present, plus a replay that binds the recorded call arguments against the real PluginContext signatures wherever a host is importable. The split matters. A permissive fake accepts every future signature, and a hand-written fake mirroring today's host is a frozen snapshot of one revision -- both pass unchanged when the host gains a required parameter. Comparing a fake's own signature to the real one catches nothing either, because **kwargs fits every signature by construction. Binding the recorded arguments catches added and renamed parameters and removed registrars, and needs the host only at check time. check_against_host(None) reports unchecked rather than clean and names the revision to provision: not having looked is not having found nothing. strict_against binds at call time, so a consumer calling the fake directly is covered too, not just a lane-side replay. Carries plugin name and config as constructor arguments, so load_plugin_config and the receipt identity resolve -- the largest gap between the kit's own fake and what consumers hand-rolled around. Shape knobs reach both branches of the references_dir capability probe and the missing-registrar path. Ships as a flat module: pyproject declares packages as an explicit list, so a subpackage would be dropped from the wheel silently. Exported as the submodule name rather than its classes, keeping test doubles out of the runtime namespace.
product-lens and scope-guardian converged on two gaps the earlier rounds missed. The harness would never actually check anything on a consumer's machine. Recording always happens; the replay needs an importable host, and the only thing that acquires one at the pin is a just-only recipe that KTD7 already says consumers cannot use. Documenting provisioning is not enough, so R17 makes the acquisition step part of what ships. The "deletes more lines than they add" criterion had nothing in scope to measure. R16 excludes consumer repositories; the Problem Frame counts the kit separately as the fifteenth fake, so migrating the kit's own FakePluginCtx is inside the boundary and is the only in-repo proof that the harness works the way a consumer would use it. U3 now owns it. Also from feasibility: the outside-skipUnless guard needs an explicit intent signal or it reddens the blocking job on every push, since that job checks out no Hermes revision and just test discovers both contract modules. The pin and upstream recipes need separate directories, since prepare-hermes-agent swallows the pull error a detached checkout leaves behind. U4's guard takes its input set from the Surface Map's Kit API column rather than scraping README prose full of host-side names. U7 traces to R1, the requirement its wheel-membership assertion enforces.
Three decisions the user settled with the tradeoffs in view. The harness fetches a Hermes checkout at the pin when none resolves, rather than only reporting what to provision. A step that merely instructs leaves every consumer on the record-only path, which is the gap the harness exists to close. The cost is network I/O from a test library, so an explicit HERMES_AGENT_PATH always wins, the fetch is cached and bounded, and a failure surfaces as the unchecked result R3 already defines rather than a hang. The pin stays kit-owned. A constant that ships in the wheel is the only form a consumer can read offline, and it keeps R6 free of a cross-repo dependency. That closes the plan's first open question. U3 migrates the bespoke host-shape classes alongside FakePluginCtx, not the fake alone. Only those classes exercise the references_dir switch and the missing-registrar mode the way a consumer would.
An independent cross-model review found the replay reports clean when a host renames a parameter the kit passes positionally, and a probe confirmed it: Python binds positionals by position, so register_hook(event_name, callback) accepts a call written for register_hook(hook_name, callback) and nothing raises. Keyword calls were already covered -- a rename there surfaces as an unexpected-keyword error -- so the claim held for register_tool and hid the gap. register_hook and register_middleware are exactly the positional registrars, which is where a rename would actually land. Compare parameter names as well as arity for the registrars the kit calls positionally, against a baseline read from the real PluginContext at the pin. Corrects the overclaim in the module docstring, KTD1, and the spec delta, which all said "catches renames" without the positional caveat.
An independent cross-model pass (codex, all three lenses independence-verified) found the plan promised more than it delivers. Four calls settled with the tradeoffs surfaced. The Objective narrows to registration drift. The harness replays outbound registration calls and is blind to how Hermes invokes a registered hook; proving the full runtime contract stays this repo's own contract gate, which runs the real dispatchers. Two lenses flagged the overclaim independently. The first success criterion split. A refusal used to satisfy it, so a fresh consumer could "pass" having never fetched Hermes and never replayed anything. Core outcome now requires a completed replay at a named revision with a non-zero check count; refusal safety stays a separate guarantee so it cannot stand in for the outcome. The pin is not deployment truth, and the plan now says so rather than implying it. The gate proves conformance at the revision the kit names; keeping that equal to production belongs to the promotion process. Making it the kit's job would reintroduce the cross-repo dependency the kit-owned-pin decision rejected. R8 gets a daily schedule and a stated 24-hour lag bound, so "before it reaches production" is checkable rather than aspirational. Structural: the checkout resolver moves from U5 into Change A as U9, because it is a harness capability a consumer imports -- leaving it in the lane is what made R17 unreachable. Also: pin-targeted runs compare resolved HEAD against the pin; the drift baseline matches failure fingerprints rather than test names, since a baselined test whose error changed is a new break wearing a known name; U7 asserts the classification rather than the baseline file's existence; the unit suite gate no longer contradicts U5's intent signal; and validate --archived joins the gates, since archive does not block on unchecked tasks. Dismissed on evidence: the claim that tooling changes need --skip-specs passed to archive. Tested -- archive honors the .openspec.yaml marker alone and reports specsUpdated: false.
The checklist predated the last two review rounds, so it under-counted the work: U9 had no task group at all, and the U3 entries predated both the kit-fake migration and the two host-shape modes the migration needs. This matters beyond bookkeeping. openspec validate --archived checks task completion, so a checklist that does not describe the real work would pass while the work was unfinished. Also records 1.6, the positional-rename fix, which landed after the group was first written.
Two modes the kit's own tests need, and the migration in group 4 depends on. references_dir_probe_lies gives register_skill a permissive signature that satisfies the kit's keyword probe and then rejects the keyword at call time. That is the shape a signature check cannot see through, and the only way to reach the retry branch register_plugin documents. register_skill_error raises from register_skill, proving the retry stays narrow: an error unrelated to references_dir must propagate rather than being swallowed by the fallback. Both replace bespoke host classes currently defined inline in tests/test_kit.py, which group 4 removes.
The kit now uses the harness it ships, so the consumer-facing surface is exercised by a real caller rather than only by its own unit tests. Net -69 lines: 92 removed, 23 added. Replaces FakeCtx and FakePluginCtx with aliases to RecordingPluginContext, and the four bespoke host-shape classes with constructor modes -- strict positional, explicit references_dir, the fooled probe, and the raising host. Subclassing would not have worked: the harness assigns registrars as instance attributes, which is what lets a missing registrar genuinely disappear from getattr, so a subclass overriding register_skill as a class attribute would be shadowed. Modes are the supported shape and the aliases carry a comment saying so. Verified beyond a green suite: disabling register_plugin's references_dir retry makes a migrated test fail, and restoring it passes. The branch is still exercised rather than silently no-op.
Gives a consumer the kit's standing conventions without copying
literals out of its test suite.
RECEIPT_FIELD_ORDER pins the order log_registration_summary emits,
which is deliberately not RegistrationSummary's dataclass order -- the
two genuinely differ, and asserting the dataclass order would pass
while the external contract drifted. A test holds those two apart so
the distinction cannot quietly collapse.
receipt_fields parses one receipt into its fields, rendering <none> as
empty so an absent surface and an empty one read alike.
check_registration covers deterministic ordering, per-surface duplicate
names, and the tool-schema shape. Results are returned rather than
raised: the kit is stdlib unittest but consumers may not be, so
`assert result.ok, result` works under any runner.
The schema check reads the inner function schema the kit actually hands
register_tool -- {name, description, parameters} -- so the defect is a
top-level `properties` flattening arguments beside `parameters`, which
would then never reach function.parameters once Hermes wraps it. An
earlier draft had this inverted and flagged correct schemas.
Adds plugin_reference_tool to __all__. It was documented in README.md and the Surface Map and covered by tests, but never exported -- the exact drift this unit exists to prevent, already present before the guard existed. The guard takes its input from the Surface Map's Kit API column, the one place the kit enumerates its own public names. The README is not usable for this: it has no API section, and its prose names host-side calls like ctx.register_tool that would fail falsely. ContextEngine is excluded with a reason -- Hermes owns it, the kit only takes an instance. just check-install builds, installs into a throwaway venv, and imports every __all__ name with --no-project so the source tree is off sys.path. Wired into the existing package job. Mutation-tested rather than assumed: converting the module to a subpackage, which the explicit packages list in pyproject silently drops, produced a wheel with no testing module at all. twine check PASSED on it; check-install failed with ModuleNotFoundError. That is the difference the gate exists for. Two of the guard's own tests keep it honest: one fails if the Surface Map ever parses as empty, and one proves an unexported name is caught.
Without this the drift replay only ever runs inside this repository. A consumer's machine has no Hermes checkout, so recording always happens and checking never does -- every consumer would get the honest record-only result and none of the protection. resolve_hermes_checkout returns a ResolvedHost: HERMES_AGENT_PATH wins outright, a cache already at the pin is reused so the fetch happens at most once per machine, and otherwise it fetches one revision shallow. A cache sitting at some other revision is never returned as if it were the pin -- that would receipt the wrong host, which is worse than not checking. Same reasoning after a fetch: if HEAD is not the requested revision the result is unavailable rather than optimistic. Nothing raises and nothing hangs. Offline, sandboxed, timed-out, and wrong-revision all land on an unavailable result naming the revision and the reason, which plugin_context_class() turns into the unchecked drift report the caller already handles. That is the accepted cost of fetch-when-missing: bounded, cached, and never a hang. Written offline-first, since a sandboxed CI run is the case a test library must not make worse.
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.
Bottom of a 3-PR stack. Review this first; #30 builds on it.
Implements Change A of
docs/plans/2026-09-21-1406-feat-plugin-contract-testing-harness-plan.md, plus the plan and OpenSpec adoption the other two build on.Why
Fourteen consumer plugin repositories each hand-roll a fake Hermes plugin context, because the kit's own fake and its real-Hermes import seam live in
tests/and never reach an install. None of them catches the failure they exist to catch: a permissive fake accepts every future signature, and a hand-written one is a frozen snapshot of one host revision — both pass unchanged when the host adds a required parameter.The repo already states the principle in
references/plugin-kit.md("a fake context alone can hide signature drift") and cannot deliver it.What ships
hermes_plugin_kit.testing— a recording fake that needs no host, whose captured calls replay against the realPluginContextsignatures wherever one is importable. Catches added, renamed, and removed registrar parameters.HERMES_AGENT_PATHwins; otherwise a cached, bounded, offline-safe fetch at the pin.just check-install, which builds, installs, and imports from the wheel.Verified, not assumed
cleanwhen a host renames a parameter passed positionally — Python binds by position. Confirmed by probe, fixed, andregister_hook/register_middlewareare exactly the positional registrars.twine checkis blind to a missing module. Converting the module to a subpackage produced a wheel with it absent entirely;twine checkpassed,just check-installfailed.register_plugin'sreferences_dirretry makes a migrated test fail; restoring it passes.plugin_reference_toolwas already drifting — documented and tested, never exported. Now caught by the guard.Scope
Net −69 lines in
tests/test_kit.pyfrom migrating the kit's own fake. No consumer repository is modified.deliver_mediais unchanged — the #99220 relay-egress break is the motivating evidence, not this PR's work.Status
Change A complete: 22/22 tasks,
openspec validate --strictclean, full suite green at the pinned Hermes revision.