mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-29 18:46:59 +00:00
test(cli): regression for deferred platform CLI registration path
Some checks are pending
CI / Detect affected areas (push) Waiting to run
CI / Python tests (push) Blocked by required conditions
CI / Python lints (push) Blocked by required conditions
CI / JS & TS checks (push) Blocked by required conditions
CI / Desktop E2E (push) Blocked by required conditions
CI / Docs Site (push) Blocked by required conditions
CI / Deny unrelated histories (push) Blocked by required conditions
CI / Check contributors (push) Blocked by required conditions
CI / Check uv.lock (push) Blocked by required conditions
CI / Check no committed infographics (push) Blocked by required conditions
CI / package-lock.json diff (push) Blocked by required conditions
CI / Lint Docker scripts (push) Blocked by required conditions
CI / Build&Test Docker image (push) Blocked by required conditions
CI / Supply-chain scan (push) Blocked by required conditions
CI / Review label gate (push) Blocked by required conditions
CI / OSV scan (push) Waiting to run
CI / CI review comment (live) (push) Blocked by required conditions
CI / All required checks pass (push) Blocked by required conditions
CI / CI timing report (push) Blocked by required conditions
Deploy Site / deploy-vercel (push) Waiting to run
Deploy Site / deploy-docs (push) Waiting to run
Docker Build, Test, and Publish / build (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest) (push) Waiting to run
Docker Build, Test, and Publish / build (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Docker Build, Test, and Publish / publish (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest) (push) Blocked by required conditions
Docker Build, Test, and Publish / publish (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
Docker Build, Test, and Publish / merge (push) Blocked by required conditions
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Waiting to run
auto-fix lint issues & formatting / Apply patch (push) Blocked by required conditions
Some checks are pending
CI / Detect affected areas (push) Waiting to run
CI / Python tests (push) Blocked by required conditions
CI / Python lints (push) Blocked by required conditions
CI / JS & TS checks (push) Blocked by required conditions
CI / Desktop E2E (push) Blocked by required conditions
CI / Docs Site (push) Blocked by required conditions
CI / Deny unrelated histories (push) Blocked by required conditions
CI / Check contributors (push) Blocked by required conditions
CI / Check uv.lock (push) Blocked by required conditions
CI / Check no committed infographics (push) Blocked by required conditions
CI / package-lock.json diff (push) Blocked by required conditions
CI / Lint Docker scripts (push) Blocked by required conditions
CI / Build&Test Docker image (push) Blocked by required conditions
CI / Supply-chain scan (push) Blocked by required conditions
CI / Review label gate (push) Blocked by required conditions
CI / OSV scan (push) Waiting to run
CI / CI review comment (live) (push) Blocked by required conditions
CI / All required checks pass (push) Blocked by required conditions
CI / CI timing report (push) Blocked by required conditions
Deploy Site / deploy-vercel (push) Waiting to run
Deploy Site / deploy-docs (push) Waiting to run
Docker Build, Test, and Publish / build (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest) (push) Waiting to run
Docker Build, Test, and Publish / build (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Docker Build, Test, and Publish / publish (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest) (push) Blocked by required conditions
Docker Build, Test, and Publish / publish (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
Docker Build, Test, and Publish / merge (push) Blocked by required conditions
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Waiting to run
auto-fix lint issues & formatting / Apply patch (push) Blocked by required conditions
Responds to hermes-sweeper review on #54717: existing tests only mocked platform_registry.get(). Add a hermetic fake deferred-loader test that runs real PlatformRegistry resolution → PluginContext.register_cli_command → argparse subparser/choices visibility, without Photon SDK imports.
This commit is contained in:
parent
bff3aa3c1e
commit
585726ac2e
1 changed files with 76 additions and 0 deletions
|
|
@ -249,3 +249,79 @@ def test_deferred_platform_cli_resolution_swallows_registry_errors():
|
|||
with patch.dict(sys.modules, {"gateway.platform_registry": fake_module}):
|
||||
# Must not raise.
|
||||
_resolve_deferred_platform_cli_command("photon")
|
||||
|
||||
|
||||
def test_deferred_platform_loader_registers_cli_command_before_parser_table():
|
||||
"""Fake deferred loader must resolve through real registry + register CLI
|
||||
before argparse builds plugin command subparsers (issue #54678 review).
|
||||
|
||||
Existing unit tests mock ``platform_registry.get`` and only assert the
|
||||
helper calls it. This regression exercises the full chain hermes-sweeper
|
||||
asked for:
|
||||
|
||||
1. a deferred platform loader is pending on a real ``PlatformRegistry``
|
||||
2. that loader materializes a ``register_cli_command`` side effect on the
|
||||
plugin manager (no Photon SDK import)
|
||||
3. ``_resolve_deferred_platform_cli_command`` runs the pending loader
|
||||
4. the registered command is present on the manager *and* visible as an
|
||||
argparse subparser/choice after the same construction path ``main()``
|
||||
uses for plugin CLI commands
|
||||
"""
|
||||
import argparse
|
||||
|
||||
from gateway.platform_registry import PlatformRegistry
|
||||
from hermes_cli.plugins import PluginContext, PluginManager, PluginManifest
|
||||
|
||||
mgr = PluginManager()
|
||||
manifest = PluginManifest(name="fake-photon-platform")
|
||||
command_name = "fakephoton"
|
||||
|
||||
def _fake_loader():
|
||||
# Mirrors what a real platform adapter does on import: register its
|
||||
# top-level hermes <name> CLI command via PluginContext.
|
||||
ctx = PluginContext(manifest, mgr)
|
||||
ctx.register_cli_command(
|
||||
name=command_name,
|
||||
help="Fake deferred platform CLI (test-only)",
|
||||
setup_fn=lambda p: None,
|
||||
description="Hermetic stand-in for deferred platform CLI registration",
|
||||
)
|
||||
|
||||
registry = PlatformRegistry()
|
||||
registry.register_deferred(command_name, _fake_loader)
|
||||
|
||||
# Precondition: deferred is known, but CLI command is not yet registered.
|
||||
assert registry.is_registered(command_name)
|
||||
assert command_name not in mgr._cli_commands
|
||||
assert command_name in registry._deferred
|
||||
|
||||
fake_module = type(sys)("gateway.platform_registry")
|
||||
fake_module.platform_registry = registry
|
||||
with patch.dict(sys.modules, {"gateway.platform_registry": fake_module}):
|
||||
_resolve_deferred_platform_cli_command(command_name)
|
||||
|
||||
# Loader resolution must promote deferred -> concrete and fire CLI register.
|
||||
assert command_name not in registry._deferred
|
||||
assert command_name in mgr._cli_commands
|
||||
cmd_info = mgr._cli_commands[command_name]
|
||||
assert cmd_info["name"] == command_name
|
||||
assert cmd_info["plugin"] == "fake-photon-platform"
|
||||
|
||||
# Same parser-table assembly main() uses after reading _cli_commands.
|
||||
parser = argparse.ArgumentParser(prog="hermes")
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
for info in mgr._cli_commands.values():
|
||||
plugin_parser = subparsers.add_parser(
|
||||
info["name"],
|
||||
help=info["help"],
|
||||
description=info.get("description", ""),
|
||||
)
|
||||
info["setup_fn"](plugin_parser)
|
||||
if info.get("handler_fn") is not None:
|
||||
plugin_parser.set_defaults(func=info["handler_fn"])
|
||||
|
||||
# argparse surface: choices + parse success.
|
||||
choices = getattr(subparsers, "choices", None) or {}
|
||||
assert command_name in choices
|
||||
parsed = parser.parse_args([command_name])
|
||||
assert parsed.command == command_name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue