Skip to content

fix(tests): restore real plugin discovery coverage, drop CI adapter exclusion - #121

Closed
iap wants to merge 5 commits into
mainfrom
fix/restore-discovery-tests
Closed

iap wants to merge 5 commits into
mainfrom
fix/restore-discovery-tests

Conversation

@iap

@iap iap commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

What kind of change is this?

  • bug fix + test

Summary

tests/test_chat_dispatch.py had been rewritten from real dispatch tests into mocked unit tests, which removed the only coverage of the chain CI exists to protect:

hermes_cli.plugins (discovery) -> tools.registry (registration)
  -> registry.get_entry(name).handler(args)   (what run_agent.py invokes)

A rename in _TOOLS, a slug mismatch, or plugin.yaml drift would all have shipped green.

Restored (TestDiscoveryAndRegistry, 5 tests): drive _ensure_plugins_discovered() and assert all 7 tools resolve in the global registry under toolset builder; the models catalog is the plugin.yaml override (Claude variants present, claude-opus-* never advertised); models and tags agree on the tag set; no secret fields leak into handler output.

Fixed the port assertions. The old tests hardcoded 8077 on both sides, so they passed without the adapter binding anything and could not observe the port register() forwards. The fake adapter now mirrors the real (server, actual_port) contract, so the test asserts register() forwards the configured port (AWS_BUILD_ADAPTER_PORT or default) and reports the port start() returned.

ci.yml: dropped -k "not adapter". register() already swallows adapter start failures (verified: OSError: address already in use -> warning, all 7 tools still register) and no test binds the default port, so the exclusion bought nothing and deselected 18 tests. PR template command updated to match.

Branch

This PR was opened from a branch using one of:

  • fix/…

Checklist

  • Tests pass: python -m pytest -q
  • verify.py is green
  • No raw tokens/secrets in code, logs, or tool output
  • Adapter stays loopback-only unless an explicit guard is added
  • Updated docs/README if user-facing behavior changed

Verification

  • python -m pytest -q: 93 passed, 1 skipped (was 88 passed)
  • python verify.py: all checks passed
  • No :8077 listener left bound after the run
  • Mutation-tested the new assertions — each of these fails the suite:
    • renaming a tool in _TOOLS -> 5 failures
    • adding claude-opus-4 to plugin.yaml -> catalog test fails
    • offsetting the forwarded port (port + 1) -> port test fails
    • hardcoding the printed port -> port test fails (the old test could not catch this)
  • The local .venv is the pinned hermes-agent SHA (a88512b, confirmed via direct_url.json), so this run is representative of CI.

Notes for review

  • The discovery fixture stops the adapter via sys.modules["hermes_plugins.builder.adapter"], not the top-level adapter module — discovery imports it as a submodule, so adapter.stop() alone would leave the listener up.
  • Three stale references found but deliberately left out of this change (no behavior impact): conftest.py:33 comment names model_tools (nothing imports it now), conftest.py:22's HERMES_AGENT_DIR resolves to a path that does not exist under the CI mount layout (guarded by exists()), and __init__.py:37's from registry import ... fallback is unreachable here. Happy to fold them in if you want them tracked.

RetriggerView in GreptileConfidence Score: 1/5

Fix the real auth calls in tests, setup failures, and fork PR labeling before merging.

Fix All in CursorFindings

  1. P1 Tests delete saved login files ▶
  2. P1 Setup fails without providers ▶
  3. P1 Setup picks Python without PyYAML ▶
  4. P1 Fork PR labeling fails ▶
  5. P2 Setup erases config comments ▶
  6. P2 Custom port coverage is missing ▶

Summary

The PR expands real discovery coverage to all seven tools, adds adapter lifecycle tests, and removes CI's adapter exclusion. It also changes setup, dependency requirements, and PR labeling.

  • Hermes chat tests now check all seven builder tools through discovery.
  • CI runs adapter tests that check the port registration reports.
  • The setup scripts add and remove the builder provider and enabled plugin together.
  • Pull requests from named branch prefixes get matching labels.
  • The Hermes test dependency is pinned while cryptography accepts newer versions.
  • Unknown model names now leave a quieter log message.

Acknowledged scope: iap explicitly deferred the model_tools comment, HERMES_AGENT_DIR layout, and fallback registry import as outside this change, stating they have no behavior impact.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Discovery tests"] --> B["Hermes plugin discovery"]
  B --> C["Global tool registry"]
  C --> D["Call every handler"]
  D --> E["Real AWS login"]
  D --> F["Logout deletes auth files"]
  G["Temporary profile plugin symlink"] --> H["Plugin checkout"]
  F --> H
Loading

Reviews (1) · Last reviewed commit: "fix(tests): restore real plugin discover..." · Reviewed by Greptile

iap and others added 5 commits July 21, 2026 11:39
…xclusion

test_chat_dispatch.py had been rewritten from real dispatch tests into mocked
unit tests, which removed the only coverage of the chain CI exists to protect:
hermes_cli.plugins discovery -> tools.registry registration ->
registry.get_entry(name).handler(args). A rename in _TOOLS, a slug mismatch,
or plugin.yaml drift would all have shipped green.

- Restore TestDiscoveryAndRegistry: drive _ensure_plugins_discovered() and
  assert all 7 tools resolve in the global registry under toolset "builder",
  that the models catalog is the plugin.yaml override (Claude variants
  present, claude-opus-* never advertised), that models/tags agree on the tag
  set, and that no secret fields leak into handler output.
- Fix the port assertions. The old tests hardcoded 8077 on both sides, so they
  passed without the adapter binding anything and could not see the port
  register() forwards. The fake adapter now mirrors the real (server,
  actual_port) contract, so the test asserts register() forwards the
  configured port (AWS_BUILD_ADAPTER_PORT or default) and reports the port
  start() returned.
- Collapse the duplicated fake-adapter setup into _install_fake_adapter().

ci.yml: drop `-k "not adapter"`. register() already swallows adapter start
failures (verified: OSError "address already in use" -> warning, all 7 tools
still register) and no test binds the default port, so the exclusion bought
nothing and deselected 18 tests. The PR template command is updated to match.

Verified locally: 93 passed, 1 skipped (was 88 passed); verify.py green; no
:8077 listener left bound. Mutation-tested the new assertions -- renaming a
tool, adding claude-opus-4 to plugin.yaml, offsetting the forwarded port, and
hardcoding the printed port each fail the suite. The local .venv is the pinned
hermes-agent SHA (a88512b), so this run is representative of CI.
@iap

iap commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Closing as obsolete: this branch is based on fa3e6f8, which is not in origin/main's history. The remote has since been rewritten (143 commits; PRs #108–#120) and now already contains everything this PR proposed:

  • tests/integration/test_chat_dispatch.py — the real discovery/registry chain (_ensure_plugins_discovered() -> registry.get_entry() -> real handler), including a skip-if-hermes-agent-absent guard.
  • tests/test_coverage.py — already pins the actual-port contract (fake start returns 18092 for a requested 8088; asserts register() forwards the returned port).
  • ci.yml — restructured to uv run pytest -x -q tests; the -k "not adapter" exclusion is gone.
  • PR template — already python3 -m pytest tests/ -q.

Nothing to merge here. Branch kept for reference; will delete on request.

@iap iap closed this Oct 23, 2026
Comment on lines +168 to +169
for name in sorted(EXPECTED_TOOLS):
blob = json.dumps(json.loads(registry.get_entry(name).handler({}, task_id="t")))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Tests delete saved login files

Calling every registered handler now runs bid_login and bid_logout, not just read-only catalog tools. bid_login makes live AWS requests and starts a polling thread. conftest.py symlinks the temporary profile's plugin directory to the checkout, so bid_logout can delete existing auth/bid_*.json files there. Keep real discovery and dispatch, but stub the auth operations and give them a separate temporary store.

Fix in Cursor

Comment thread scripts/setup.sh
Comment on lines +95 to +97
# If no providers: block exists, insert one first.
if not any(l.strip() == "providers:" for l in lines):
lines.append("providers:")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Setup fails without providers

The new missing-providers fallback appends providers: as the last line, but the loop checks in_prov before setting it for that line. The builder block is never written, so the final check restores the backup and exits with an error. Insert the block together with the new section, and test a config without providers.

Fix in Cursor

Comment thread scripts/setup.sh
Comment on lines +33 to +34
PYTHON="$(command -v python3 || true)"
if [[ -z "$PYTHON" ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Setup picks Python without PyYAML

If system Python is on PATH but PyYAML is installed only in the Hermes virtual environment, the new unconditional import yaml fails before setup edits the config. Interpreter selection only checks whether python3 exists, so it never tries the Hermes environment. Check that each candidate can import yaml before selecting it.

Fix in Cursor

Comment on lines +3 to +5
on:
pull_request:
types: [opened, synchronize, reopened]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Fork PR labeling fails

For normal fork PRs, pull_request supplies a read-only token. Requesting pull-requests: write does not override that restriction. A fork branch named fix/... or feature/... therefore reaches addLabels and fails with a permission error. Use pull_request_target for this metadata-only job, without checking out or running PR code.

Suggested change
on:
pull_request:
types: [opened, synchronize, reopened]
on:
pull_request_target:
types: [opened, synchronize, reopened]

Fix in Cursor

Comment thread scripts/setup.sh
en = (c.get("plugins") or {}).get("enabled") or []
if "builder" not in [str(x) for x in en]:
c.setdefault("plugins", {})["enabled"] = [str(x) for x in en] + ["builder"]
yaml.safe_dump(c, open(cfg, "w"), sort_keys=False, default_flow_style=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Setup erases config comments

Adding builder to plugins.enabled now rewrites all of config.yaml with yaml.safe_dump. On a normal first setup, this removes every existing YAML comment, including notes beside unrelated providers. Update only the enabled list, or use a YAML editor that preserves comments.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Cursor

Comment on lines +188 to +195
def test_register_starts_adapter_on_configured_port(self, mod, monkeypatch, capsys):
_install_fake_adapter(monkeypatch)
FakeAdapter.started = False
FakeAdapter.requested_port = None
FakeAdapter.actual_port = None
captured = {}

mod.register(_ctx(captured))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Custom port coverage is missing

The port test reads AWS_BUILD_ADAPTER_PORT but never sets a non-default value. In ordinary CI, a regression that hardcodes the requested port to 8077 still passes. Parameterize the test with the variable absent and with a different value, setting it before register() runs.

Fix in Cursor

@iap
iap deleted the fix/restore-discovery-tests branch October 23, 2026 22:49
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.

1 participant