Files
coder/cli/exp_chat_internal_test.go
T
Kyle Carberry cd56ab9e33 refactor: remove legacy live-read and injected-history chat context paths (#26585)
This PR makes the agent-pushed pinned snapshot
(`chat_context_resources`) the sole source of workspace context for
chats, completing the "Release 5" cleanup. It removes legacy mechanisms
now superseded by the snapshot that agents push over dRPC
(`PushContextState`) and refresh via `chat-context/refresh`.

Removed:

- **Live-read at turn time.** MCP tool discovery, skill live-body reads,
and the instruction/skill history fallback that dialed the workspace on
every turn.
- **Context injected as message history.** The
`persist_workspace_context` generation action and its decision-loop
guard.
- **The legacy write path.** `POST`/`DELETE
/api/v2/workspaceagents/me/experimental/chat-context`, the agentsdk
`AddChatContext`/`ClearChatContext` methods, and the CLI one-shot
writer.
- **The `chats.last_injected_context` column** and all of its plumbing
(migration `000529`, queries, `db2sdk`, `dbauthz`, audit table, and the
frontend `ContextUsageIndicator` fallback).

Subagent context inheritance no longer copies parent context messages;
children now hydrate the parent's pinned `chat_context_resources` on
create, which yields an identical pin for the same workspace and agent.

What stays (still served by the live agent connection, not the
snapshot): `read_skill_file` supporting-file reads, `read_skill`
supporting-file listing, and MCP tool execution.

> [!NOTE]
> Migration `000529` drops `chats.last_injected_context` and recreates
the `chats_expanded` view without it. The down migration restores both.

<details>
<summary>Decision log (D1-D5)</summary>

- **D1 (subagent inheritance):** Re-point inheritance from the legacy
message copy to a pinned hydrate. Children call
`hydrateChatContextOnCreate` instead of copying parent context messages.
- **D2 (`persist_workspace_context`):** Remove the generation action
entirely along with the decision-loop guard it existed to satisfy, since
context is never injected into history anymore.
- **D3 (legacy HTTP + CLI):** Remove the experimental `chat-context`
POST/DELETE endpoints, the agentsdk methods, and the CLI one-shot. The
dRPC push + `chat-context/refresh` replace them.
- **D4 (frontend fallback):** Remove the `last_injected_context`
fallback in `ContextUsageIndicator`; pinned `resources` are the sole
source.
- **D5 (sequencing):** Ship as a single PR rather than a stacked pair.

</details>

---
Coder Agents generated on behalf of @kylecarbs.
2026-06-22 19:26:34 -06:00

51 lines
1.3 KiB
Go

package cli
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestResolveContextSourcePath(t *testing.T) {
t.Parallel()
t.Run("EmptyErrors", func(t *testing.T) {
t.Parallel()
_, err := resolveContextSourcePath(" ")
require.Error(t, err)
require.Contains(t, err.Error(), "empty")
})
t.Run("PreservesTilde", func(t *testing.T) {
t.Parallel()
// A leading ~ is left for the agent to expand against its own home.
got, err := resolveContextSourcePath("~")
require.NoError(t, err)
require.Equal(t, "~", got)
got, err = resolveContextSourcePath(" ~/skills/deploy ")
require.NoError(t, err)
require.Equal(t, "~/skills/deploy", got)
})
t.Run("KeepsAbsolute", func(t *testing.T) {
t.Parallel()
got, err := resolveContextSourcePath("/home/coder/AGENTS.md")
require.NoError(t, err)
require.Equal(t, "/home/coder/AGENTS.md", got)
})
t.Run("MakesRelativeAbsolute", func(t *testing.T) {
t.Parallel()
// "./" was the reported failure: a relative path must be resolved to an
// absolute one before it reaches the agent.
got, err := resolveContextSourcePath("./")
require.NoError(t, err)
require.True(t, filepath.IsAbs(got), "want absolute, got %q", got)
want, err := filepath.Abs("./")
require.NoError(t, err)
require.Equal(t, want, got)
})
}