Repository navigation
Conversation
Two acceptance tests that record what `aitools mcp add` and `remove` do today when something else writes at the same time, and what is left after a CLI older than v1.28.0 touches the shared state file. agent-cli-concurrent-edit puts a stand-in for the claude CLI in front of the harness's one. It runs a script between the moment databricks starts claude and the moment claude reads its config, which orders a concurrent change without timing. state-across-cli-versions deletes the state file as v1.27.0's `aitools uninstall` does, and edits it as a newer CLI would. Co-authored-by: Isaac <no-reply@databricks.com>
Regression test report ✅Commit: Selected 2 changed tests (limit=20, 0 not selected) 2 tests: regression=0 unreleased=1 coverage=1 failing=0
TestAccept/cmd/aitools/mcp/state-across-cli-versions: branch ✅ | main (905b0f7) ✅ | latest (v1.28.0) ❌latest (v1.28.0): |
✅ Integration test reportCommit: d233b3a
Top 6 slowest tests (at least 2 minutes):
|
There was a problem hiding this comment.
Automated review at 4941086. Each finding was verified against the code.
No blocking issues found. 4 non-blocking comment(s) below.
This PR adds two acceptance tests that pin what aitools mcp add/remove do today when another writer changes the agent config while the agent CLI runs, and what is left after an older CLI drops the MCP section of the state file. The goldens match what addViaCLI/removeViaCLI do today. The main issue is that the concurrent-edit test is switched off on Windows because its claude stand-in is a bash script, when the cross-platform fakeagent could do the same job. There are also some smaller problems with the readability of the goldens and the reuse of helpers.
| Badness = "aitools mcp add replaces, and remove deletes, a same-name entry that another process wrote while the agent's CLI ran, and both report success; two concurrent adds of one server name both report installed while one server is lost and state holds the name twice" | ||
|
|
||
| # bin/claude is a shell script, which a PATH lookup on Windows does not find. | ||
| GOOS.windows = false |
There was a problem hiding this comment.
[nice to have] AGENTS.md says tests also run on Windows, but GOOS.windows = false turns off all four cases there. The only reason is that bin/claude is a bash script that a Windows PATH lookup won't find. The Go stand-in in acceptance/internal/fakeagent/main.go already handles claude mcp add-json/mcp remove and is put on PATH for msys by acceptance/cmd/aitools/script.prepare. Could claude() there refuse a name that already exists and run a pre-read hook named by an env var? Then the test runs on Windows too. It would also stop the bash mcp remove branch (bin/claude line 32) from skipping the $FAKE_AGENT_LOG argv log that every aitools test sets up.
There was a problem hiding this comment.
Not changed in this PR, and the gap is listed under "Gaps and risks". You are right that the Go stand-in could carry this. It needs three changes to the shared stand-in: a hook that runs before the read, mcp add-json refusing a taken name, and mcp remove deleting an entry it did not write (today it goes through RemoveAt, which refuses one). The last two change what every cmd/aitools test runs against, so I kept them out of a PR that only records behavior. Where this lands depends on the fix: #8151 removes the agent-CLI path, and this test with it; #8150 keeps the path for add, and moving the stand-in into fakeagent belongs there. The code under test is the order of the config check and the agent CLI run in agentconfig, which has no Windows-specific branch on this path.
The stand-in logs each add, refusal and removal to concurrent.log, so the golden records that claude refused the name before databricks replaced the entry. The re-pointed profile uses setup_custom_host and update_file.py instead of a sed and a replacement of its own, and the serve command is shown above its output. Co-authored-by: Isaac <no-reply@databricks.com>
Changes
Two acceptance tests that record what
aitools mcp addandaitools mcp removedo today when another process writes at the same time, and what is left after a CLI older than v1.28.0 touches the state file. No production code changes. Each wrong result has aBadnessnote; the undefined case has anUndefinednote.cmd/aitools/mcp/agent-cli-concurrent-edit(agent-CLI path, introduced in #7595; no lock across runs, introduced in #7539)The test puts a stand-in
claudein front of the harness's one. It does what Claude Code 2.1.325 does where the harness's stand-in does not:mcp add-jsonrefuses a name that the user config already holds (MCP server <name> already exists in user config, exit 1), andmcp removedeletes the entry of that name whoever wrote it. Before it reads the config it runs one script, which is the concurrent change. That orders the race without sleeps or background processes.add: the user adds their owngithub-logfoodserver while the claude CLI starts. Claude refuses to replace it.claude-code installed, without--force; the user's entry now holds the Databricks server.remove: the user replaces the Databricks entry with their own while the claude CLI starts.Removed github-logfood ... (Claude Code);.mcpServersis{}, so the user's entry is deleted.add --name githubruns for two profiles. One after the other, the second is refused (--name github is used by another installed server). At the same time, the second finishes while the first waits for the claude CLI.installed. The agent has onegithubserver, for the first profile. State holdsgithubtwice.remove --all.Removed github ... profile logfood, and the record that is dropped is the other profile's: records are matched by name.cmd/aitools/mcp/state-across-cli-versions(MCP records in the shared state file, introduced in #7537, where the description lists it as a decision to review)aitools uninstall, which deletes a state file that holds no skills or plugins. The script deletes the file, since no such binary is in the test.mcp listshows both entries as unmanaged.mcp remove --namesfails withno installed MCP server named ...,remove --allsaysNo Databricks MCP servers to remove, and both agent configs keep the entry.serveexits 2 (was set up for ..., but profile "logfood" now points at ...). Without it,servestarts against the new host and printsNo install record ...; using its current host.schema_versionand a section this CLI does not know.mcp addwrites the file back withschema_version4 and without the section.Why
These paths have unit tests for each step and no test for what happens when two writers meet. The tests pin today's behavior so that a fix shows up as a golden change.
Tests
mcp add-json --scope useron an existing name exits 1 and leaves the entry, andmcp remove --scope userremoves an entry it did not write.aitools uninstalldeletes a state file that holds only themcpsection, andaitools uninstall --skills <name>writes the file back without it.Gaps and risks
agent-cli-concurrent-editdoes not run on Windows: its stand-in is a shell script, which a PATH lookup there does not find.mcp addprocesses that interleave inside one read-modify-write of an agent config or of the state file. That needs real concurrency, so its outcome depends on timing. Eight parallelmcp addruns for eight services into Claude Code, Cursor and Codex, ten rounds: every run reported 24 of 24 installed; Cursor was missing an entry in 4 rounds, Codex in 3, and the state file a record in 2. Claude Code, whose file is locked, lost none.🤖 AI agent (fable5.2, isaac_claude)
This pull request and its description were written by Isaac.