Removes seven end-to-end tool policy tests from `chatd_test.go` (949
lines). The table test from #30867 checks the same policy at
`buildTurnEnvironment`.
- `TestPlanModeSubagentChatExcludesAskUserQuestion`
- `TestPlanModeRootChatAllowsApprovedExternalMCPTools`
- `TestExploreSubagentIsReadOnly`
- `TestExploreChatUsesPersistedMCPSnapshot`
- `TestExploreChatSendMessageCannotMutateMCPSnapshot`
- `TestRootExploreChatStaysBuiltinOnlyAtRuntime`
- `TestRootExploreChatExcludesWebSearchProviderToolAtRuntime`
Each test started chatd with a fake model server, ran a turn, and read
the tool names from the model request. Each had its own fixture.
**Why removal is safe:** a test was removed only if other tests still
catch every mutant it caught. On `main`, 9 mutants were caught only by
these tests, and the table test catches all 9. Review and two audits of
every check in these tests then found nine more regressions that only
these tests caught, and #30867 now covers each one. That includes the
`TestExploreChatSendMessageCannotMutateMCPSnapshot` scenario: the
`ExploreChildAfterMCPReplacement` case calls `SendMessage` on an Explore
child chat, checks the stored MCP servers, and builds the next turn.
`TestEditMessage_MCPServerIDs` still covers the same guard through
`EditMessage`. The first mutation run used an earlier `main` and the
#28757 branch, which removed the same lines.
**Tradeoff:** the table test stops at the result of
`buildTurnEnvironment`. No test now checks plan mode and Explore tool
lists in the model request itself. The audits found one mutant that only
these tests catch: a branch in `generation.go` that clears the active
tools of Explore chats just before the model call. The same change
without the Explore condition fails `TestMCPToolSearchGenerationFlows`,
because the step from `buildTurnEnvironment` to the model request is the
same for every mode. Only an end-to-end test like the ones this PR
removes would catch the Explore-only form, so this PR does not add one.
Validation: build and vet pass, and the pre-commit hook passed.
## Stack
This stack splits #28757, as requested in review. It moves the code that
prepares a chat turn into one file, `turn_environment.go`, and moves the
tool policy tests from full turns to a table test. chatd behaves as on
`main`, except for the debug log in #30865.
1. #30864 Remove the no-op `allowedBehaviorToolNames` filter
2. #30865 Log workspace agent lookup errors in turn preparation
3. #30866 Rename `prepareGeneration` to `buildTurnEnvironment`
4. #30867 Cover the turn tool policy at `buildTurnEnvironment`
5. #30868 Remove seven end-to-end tool policy tests
6. #30869 Name the `*Server` receiver `p` in `turn_environment.go`
7. #30870 Move the turn preparation helpers into `turn_environment.go`
> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.