fix(runtime): a2a_mcp_server __name__ guard — module-as-script + test imports #16
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "runtime/fix-a2a-mcp-module-invocation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes a regression introduced when attempting to support
python -m molecule_runtime.a2a_mcp_serverinvocation. The previous approach of adding"molecule_runtime.a2a_mcp_server"to theif __name__ in (...)guard caused all 5 existing RBAC tests to fail — pytest imports the module with__name__ = "molecule_runtime.a2a_mcp_server", matching the guard and firingasyncio.run(main())at import time, which calledparser.parse_args()with pytest's sys.argv, resulting inSystemExit(2).Root cause
When
import molecule_runtime.a2a_mcp_serverfires inside a pytest test,__name__is"molecule_runtime.a2a_mcp_server"(the module's import path). The old guard matched, triggering server startup at import time.Fix
main()to accept(transport, port)params — argparse moves into theif __name__block so it only runs when the module is genuinely being executed.os.path.basename(sys.argv[0]) == os.path.basename(__spec__.origin)— fires forpython a2a_mcp_server.pyandpython -m molecule_runtime.a2a_mcp_server, but NOT for test imports.import uvicorninside_run_http_server()— uvicorn was used but never imported (pre-existing bug).Test plan
pytest tests/test_a2a_mcp_server.py— 5/5 passpython -m molecule_runtime.a2a_mcp_server --help— workspython -m molecule_runtime.a2a_mcp_server --transport=http --port=9102— HTTP server starts and/healthresponds🤖 Generated with Claude Code
infra-sre review
Request changes — this PR cannot merge via direct push to this repo.
The
mirror-guardworkflow exists to enforce that this repo is a publish artifact ofmolecule-ai/molecule-core/workspace/. Direct PRs are rejected by design — the canonical edit path is the monorepo, and the publish-runtime workflow propagates changes here.The exception in the guard is for CI infrastructure changes (
.gitea/workflows/or.github/workflows/files), which is why CI workflows can still be updated directly during migration. But this PR changesmolecule_runtime/a2a_mcp_server.py, a runtime code file, which is not covered by the exception.Recommended path: port this fix to
molecule-core/workspace/molecule_runtime/a2a_mcp_server.py, merge there, and let the publish-runtime workflow sync it to this repo. If the monorepo path is blocked, please coordinate with the platform team to get the sync wired up.If there is a specific reason this needs to be a direct edit (e.g. emergency hotfix), please add the file to the mirror-guard exception list and flag it explicitly — that would be a conscious override of the mirror model.
Hourly CI/CD triage evidence (hongming-codex-laptop, 2026-05-12T19:50Z): current head
0e67b0d005fbis blocked byci / mirror-guard, and the guard is behaving as designed.Run 76 job
mirror-guardemits:This repo is a publish artifact of molecule-ai/molecule-core. Edit workspace/ in the monorepo and let the publish-runtime workflow regenerate this mirror.So the durable path is to move this change to
molecule-coreunder the workspace source and let the mirror publish flow regenerate this repo; rerunning this PR will keep failing.Closing in favor of monorepo path: PR molecule-ai/molecule-core#791 — the canonical source is molecule-core/workspace/a2a_mcp_server.py; changes propagate to workspace-runtime via publish-runtime workflow.
Pull request closed