Skip to content

fix(setup): resolve comdev MCP dirs from the registered index.js - #2199

Merged
potiuk merged 6 commits into
apache:mainfrom
potiuk:fix/comdev-mcp-server-dir
Nov 19, 2026
Merged

potiuk merged 6 commits into
apache:mainfrom
potiuk:fix/comdev-mcp-server-dir

Conversation

@potiuk

@potiuk potiuk commented Nov 19, 2026

Copy link
Copy Markdown
Member

Summary

  • The printed comdev MCP refresh commands failed in every shell. comdev-mcp.md and setup update Step 6e built the npm install directory as mcp/<server>. That uses the registered server names (ponymail, apache-projects), but the apache/comdev directories are mcp/ponymail-mcp and mcp/apache-projects-mcp.
  • The fix takes the directory from the registration itself. <server-dir> is now the directory holding the index.js in the registered args, and <root> comes from git rev-parse --show-toplevel. Printed commands must carry resolved absolute paths, never a placeholder.
  • A self-resolving script for when the agent can't read the registration. Under the secure setup the sandbox denies ~/.claude.json, so the agent handed the operator an unresolved <comdev> placeholder. comdev-mcp.md gains When the registration cannot be read: one script the operator pastes into bash or zsh.
    • It reads only absolute index.js paths from ~/.claude.json, never a .mcp.json that a cloned repo or an agent could write.
    • It skips any checkout whose origin is not exactly apache/comdev on GitHub, as git remote get-url --all reports it after insteadOf rewrites, or that is not on main, or whose fetch failed.
    • It runs fetch and merge with core.hooksPath=/dev/null, so no hook in the checkout runs.
    • By default it only reports each server against the commit it fetched, with a compare link.
    • refresh=<commit> takes only the full 40-character commit the report printed and fast-forwards to exactly that commit.
    • Before changing anything it checks every checkout, and leaves alone any where that commit is not on the main just fetched, where the checkout is already past it, or where the working tree has local changes.
    • It then runs npm install in each server's own directory, so a shared checkout ends on one commit and a later run retries a failed install.
    • setup update Step 6e and the paste-in prompt in docs/setup/secure-agent-setup.md point at it, and the prompt drops mcp/<server>/.

Type of change

  • Skill change (.claude/skills/<name>/): eval fixtures updated below
  • Documentation (docs/, README.md, CONTRIBUTING.md)

Test plan

  • prek run --files <changed files> passes. Its only change was refreshing the surface_hash in setup-isolated-setup-update/SKILL.md.
  • New plugins/magpie-setup/skills/isolated-setup-update/tests/test_comdev_mcp.py, picked up by tools/dev/run-skill-script-tests.sh. It has 25 tests: 2 check the docs, 23 run the documented script under bash and zsh. One of them pipes it into an interactive zsh -f -i, as a real paste runs, with history expansion and no interactive comments.
    • The script runs against a fake ~/.claude.json and a real temporary checkout whose upstream is one commit ahead; the temp path contains a space.
    • A git wrapper on PATH sends only fetch to the local upstream, so the origin check still sees the real GitHub URL.
    • Covered:
      • the report shows the commit and compare link, and neither merges nor installs;
      • a refresh fast-forwards a shared checkout once and installs both servers, even with an npm that reads stdin;
      • a refresh stops at the reviewed commit when main has moved on since, and refuses a commit that is not on the fetched main, a checkout already past it, a checkout with modified or untracked files, and anything but a full commit hash (main, origin/main, a short or upper-case hash, -x);
      • a lockfile rewritten by the first server's install does not block the second server of a shared checkout;
      • a failed npm install is retried on the next run;
      • hooks in the checkout (reference-transaction, post-merge, post-checkout) never run;
      • .mcp.json, relative paths and --require=… args are ignored;
      • odd but valid JSON shapes and a non-object document are tolerated, while malformed JSON is reported as such;
      • lookalike origins are skipped: other hosts, path-embedded github.com, http://, local paths, an insteadOf rewrite, a second origin URL;
      • a feature branch, a failed fetch and a deleted checkout are each skipped.
    • Removing each of the 14 guards from the doc in turn makes a test fail.
  • Eval suite for setup-isolated-setup-update: not run, because it needs model access. No existing fixture covers the comdev check.

RFC-AI-0004 compliance

  • HITL: the agent only prints the script, and the operator runs it. It changes nothing until the operator pastes back the commit they reviewed.
  • Sandbox: the agent still does not read ~/.claude.json. The script acts only on checkouts registered there, which a sandboxed agent cannot write, and runs none of their git hooks. Beyond hooks it trusts the checkout's own .git/config, as any git command run there does.

Linked issues

None. Found while running setup-upgrade and setup-isolated-setup-update on an ASF tracker: the printed ( cd <comdev>/mcp/ponymail && npm install ) failed whatever directory it was run from.

Notes for reviewers (optional)

  • The script needs jq, which ships in /usr/bin on macOS 15 and later. It says so when jq is missing.
  • It runs in a ( … ) subshell, so a pasted exit cannot close the terminal. It carries no # comments and no !: interactive zsh does not treat # as a comment by default, and takes ! for history expansion.
  • npm install still runs the packages' install scripts, as the documented manual refresh always has. The script narrows what it installs to a reviewed commit of apache/comdev main.

🤖 Generated with Claude Code

The refresh commands built the npm-install directory as mcp/<server>,
but the registered names (ponymail, apache-projects) are not the
directories (mcp/ponymail-mcp, mcp/apache-projects-mcp), so every
printed cd failed. Under the sandbox the agent also cannot read
~/.claude.json and handed the operator an unresolved <comdev>
placeholder.

Take the server dir from the index.js in the registration, print only
resolved paths, and give a self-resolving jq check for when the
registration cannot be read. A test runs that check against a fake
registration and a real checkout.

Generated-by: Claude Code (Opus 5.5)
Address adversarial-review findings on the self-resolving fallback:
merge the check and refresh loops into one script with refresh=no|yes,
cover every registration (user, per-project, ./.mcp.json), skip a
checkout whose origin is not apache/comdev, that is off main, or whose
fetch failed, print the compare link, and fast-forward to the checked
origin/main only. Tests run it under bash and zsh with upstream ahead.

Generated-by: Claude Code (Opus 5.5)
Address the second adversarial review: read only ~/.claude.json, never
a writable ./.mcp.json; match the origin exactly against apache/comdev
on GitHub via git remote get-url --all, so insteadOf rewrites, extra
URLs and lookalike hosts are skipped; compare and fast-forward to the
fetched commit; keep git and npm off the loop's stdin; report a missing
jq or malformed JSON; retry npm install on the next run. Run it in a
subshell with no # comments so a paste into interactive zsh works.

Generated-by: Claude Code (Opus 5.5)
Address the third adversarial review: refresh=<commit> fast-forwards
to exactly the commit the operator reviewed, only when it is on the
main just fetched, so a later push is never pulled in unseen and two
servers sharing a checkout end on one commit; run fetch and merge with
core.hooksPath=/dev/null; accept only absolute index.js args; skip
unexpected JSON shapes instead of aborting.

Generated-by: Claude Code (Opus 5.5)
Address the fourth adversarial review: take only a full commit hash in
refresh=, check every checkout before changing any, and leave alone
one with local changes or already past the reviewed commit, so npm
install runs only on the reviewed tree; confirm HEAD ends at that
commit. State that the script trusts the checkout's own .git/config.

Generated-by: Claude Code (Opus 5.5)
Address the fifth adversarial review: the hash check's [!0-9a-f] made
interactive zsh fail with "event not found" (history expansion), so
use [^0-9a-f] and test a real paste into zsh -f -i. Say which line to
edit for refresh=, and name local commits as well as an advanced
checkout when HEAD is not an ancestor of the reviewed commit.

Generated-by: Claude Code (Opus 5.5)
@potiuk potiuk added family:setup setup-* skills capability:fix Implement code change to resolve an issue labels Nov 19, 2026
@github-actions github-actions Bot added family:docs Docs, MISSION.md, READMEs capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) labels Nov 19, 2026
@potiuk
potiuk enabled auto-merge (squash) November 19, 2026 07:12
@potiuk
potiuk merged commit f91ddf3 into apache:main Nov 19, 2026
10 checks passed
@KatalKavya96

Copy link
Copy Markdown
Member

@potiuk heads-up: prek on main has failed since this merge (https://github.com/apache/magpie/actions/runs/44494193186). Two hooks fail on plugins/magpie-setup/skills/isolated-setup-update/tests/test_comdev_mcp.py:

  • ruff format wants to wrap three long lines.
  • mypy rejects REAL_GIT (str | None from shutil.which) in the subprocess.run call at line 72.

The PR run stayed green because both workspace hooks' files: filter only matches paths under tools/, so they printed "(no files to check) Skipped".

I have a small fix ready (the ruff format output plus assert REAL_GIT is not None in _git, since the class is already skipped without git). I'll open it in about an hour unless you'd rather handle it yourself. I'll file the hook filter gap as a separate issue.

@KatalKavya96

Copy link
Copy Markdown
Member

Update: this also turns prek red on any PR that touches Python, because the workspace hooks check every member once triggered. Opening the fix now so other PRs are unblocked.

@KatalKavya96

Copy link
Copy Markdown
Member

Fix in #2202.

@KatalKavya96

Copy link
Copy Markdown
Member

@potiuk one more thing I noticed while testing #2202, separate from the lint fix: test_pasted_into_interactive_zsh_it_reports_and_refreshes seems to hang when the test runs inside a terminal.

  • On macOS, run alone (-k interactive_zsh -p no:xdist), both subtests time out after 120s, and the test zsh's prompt shows up in the calling terminal.
  • On Linux (zsh 5.9) it passes without a terminal and hangs the same way under a pseudo-terminal (script -qec "uv run pytest ..."), so it looks like zsh -i reads the controlling terminal rather than the piped input.
  • CI skips it (needs zsh, the runner has no zsh), which would explain why it hasn't shown up there.

Adding start_new_session=True to that subprocess.run made it pass for me: about 1s on macOS from Terminal, and on Linux with and without a pseudo-terminal (the whole file: 25 passed). Happy to open a one-line PR if that's useful, or leave it with you if you'd prefer a different approach.

KatalKavya96 added a commit that referenced this pull request Nov 20, 2026
prek on main has failed since #2199: ruff format wants to wrap three
long lines in the isolated-setup-update comdev MCP test, and mypy
rejects passing `REAL_GIT` (`str | None` from `shutil.which`) into the
`subprocess.run` argument list. The test class is already skipped when
git is missing, so `_git` now asserts that invariant, which narrows the
type. No behaviour change: 24 passed, 1 skipped (needs zsh).

Generated-by: Claude Code (Opus 5.5)
@KatalKavya96

Copy link
Copy Markdown
Member

@potiuk update: #2202 is merged (approved by Kaap10), and prek on main is green again at 51b86b0. The filter gap that let this through on the PR run is tracked in #2201. The zsh terminal hang in my earlier comment is separate and still open; the one-line start_new_session=True change is ready if you want it as a PR.

KatalKavya96 added a commit that referenced this pull request Nov 21, 2026
* fix(ci): run workspace checks on plugins and ai-tutors

The ruff, ruff-format and mypy workspace hooks filtered on `tools/`
paths only, so a pull request that changed Python under `plugins/` or
`ai-tutors/` skipped all three while `main` still checked them. That is
how the formatting and typing break in #2199 reached `main`.

Extend the shared filter to the two members and pin it with a test that
runs every member path through each hook's pattern.

Generated-by: OpenCode v2.3.2 (DeepSeek V4.1 Flash 1017)

* fix(ci): widen workspace hook filters to every member path

The previous filter only recognised `src/`, `tests/` and a top-level
`pyproject.toml` under a `tools/` member, and only a top-level
`pyproject.toml` under `plugins/`. Scripts at a member root, such as
`tools/dev/check-doc-sync.py`, and nested member configs under
`plugins/magpie-*/tools/` still skipped ruff and mypy on a pull request.

Match Python and `pyproject.toml` anywhere under the three trees, the
same scope `workspace-pytest` already uses. Derive the test paths from
`git ls-files` filtered by the workspace members so a new member or a
new layout inside one cannot slip past, and pin the deliberate
Markdown-only skip with a negative case.

---------

Co-authored-by: Kavya Katal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capability:fix Implement code change to resolve an issue capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) family:docs Docs, MISSION.md, READMEs family:setup setup-* skills

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants