Ephemeral task containers re-resolve and re-download npx-launched MCP server packages from the npm registry on every task, since each task gets a fresh container with no persistent cache -- a worse amplifier of a registry outage than the daemon-restart case d4bb914b already fixed. Extract the daemon's npm-cache env logic into mcp.NpmCacheEnv, shared by both the daemon's own long-lived npx MCP servers and archie-agent's per-task ones. Mount a new archie-cache-mcp-npm Docker volume at /data/cache/mcp-npm on every task container regardless of ecosystem (MCP servers are daemon-wide config, not tied to the task repo's language), and point npx-launched per-task stdio transports at it. Closes archie-core-qk8m.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package mcp
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestNpmCacheEnv(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
command string
|
|
cacheDir string
|
|
want []string
|
|
}{
|
|
{
|
|
name: "npx gets a persistent cache",
|
|
command: "npx",
|
|
cacheDir: "/data/cache/mcp-npm",
|
|
want: []string{
|
|
"NPM_CONFIG_CACHE=/data/cache/mcp-npm",
|
|
"NPM_CONFIG_PREFER_OFFLINE=true",
|
|
},
|
|
},
|
|
{
|
|
name: "an absolute path to npx still gets the persistent cache",
|
|
command: "/usr/local/bin/npx",
|
|
cacheDir: "/data/cache/mcp-npm",
|
|
want: []string{
|
|
"NPM_CONFIG_CACHE=/data/cache/mcp-npm",
|
|
"NPM_CONFIG_PREFER_OFFLINE=true",
|
|
},
|
|
},
|
|
{
|
|
name: "a non-npx command has no npm registry dependency to fix",
|
|
command: "/usr/local/bin/my-mcp-server",
|
|
cacheDir: "/data/cache/mcp-npm",
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "empty command is left alone",
|
|
command: "",
|
|
cacheDir: "/data/cache/mcp-npm",
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "empty cacheDir is refused rather than caching into the process CWD",
|
|
command: "npx",
|
|
cacheDir: "",
|
|
want: nil,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
got := NpmCacheEnv(c.command, c.cacheDir)
|
|
if !slices.Equal(got, c.want) {
|
|
t.Errorf("NpmCacheEnv(%q, %q) = %v, want %v", c.command, c.cacheDir, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|