launch: keep Claude Code channels available
This commit is contained in:
@@ -70,11 +70,9 @@ func (c *Claude) envVars(model string) []string {
|
||||
"ANTHROPIC_API_KEY=",
|
||||
"ANTHROPIC_AUTH_TOKEN=ollama",
|
||||
"CLAUDE_CODE_ATTRIBUTION_HEADER=0",
|
||||
"DISABLE_TELEMETRY=1",
|
||||
"DISABLE_ERROR_REPORTING=1",
|
||||
"DISABLE_FEEDBACK_COMMAND=1",
|
||||
"CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY=1",
|
||||
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1",
|
||||
}
|
||||
|
||||
env = append(env, c.modelEnvVars(model)...)
|
||||
|
||||
+107
-13
@@ -322,6 +322,7 @@ func TestClaudeArgs(t *testing.T) {
|
||||
{"with model and verbose", "llama3.2", []string{"--verbose"}, []string{"--model", "llama3.2", "--verbose"}},
|
||||
{"empty model with help", "", []string{"--help"}, []string{"--help"}},
|
||||
{"with allowed tools", "llama3.2", []string{"--allowedTools", "Read,Write,Bash"}, []string{"--model", "llama3.2", "--allowedTools", "Read,Write,Bash"}},
|
||||
{"with channels", "llama3.2", []string{"--channels", "plugin:telegram@claude-plugins-official"}, []string{"--model", "llama3.2", "--channels", "plugin:telegram@claude-plugins-official"}},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -348,24 +349,117 @@ func TestClaudeEnvVars(t *testing.T) {
|
||||
|
||||
got := envMap(c.envVars("llama3.2"))
|
||||
for key, want := range map[string]string{
|
||||
"ANTHROPIC_BASE_URL": envconfig.Host().String(),
|
||||
"ANTHROPIC_API_KEY": "",
|
||||
"ANTHROPIC_AUTH_TOKEN": "ollama",
|
||||
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
||||
"DISABLE_TELEMETRY": "1",
|
||||
"DISABLE_ERROR_REPORTING": "1",
|
||||
"DISABLE_FEEDBACK_COMMAND": "1",
|
||||
"CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY": "1",
|
||||
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
||||
"ANTHROPIC_DEFAULT_OPUS_MODEL": "llama3.2",
|
||||
"ANTHROPIC_DEFAULT_SONNET_MODEL": "llama3.2",
|
||||
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "llama3.2",
|
||||
"CLAUDE_CODE_SUBAGENT_MODEL": "llama3.2",
|
||||
"ANTHROPIC_BASE_URL": envconfig.Host().String(),
|
||||
"ANTHROPIC_API_KEY": "",
|
||||
"ANTHROPIC_AUTH_TOKEN": "ollama",
|
||||
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
||||
"DISABLE_ERROR_REPORTING": "1",
|
||||
"DISABLE_FEEDBACK_COMMAND": "1",
|
||||
"CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY": "1",
|
||||
"ANTHROPIC_DEFAULT_OPUS_MODEL": "llama3.2",
|
||||
"ANTHROPIC_DEFAULT_SONNET_MODEL": "llama3.2",
|
||||
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "llama3.2",
|
||||
"CLAUDE_CODE_SUBAGENT_MODEL": "llama3.2",
|
||||
} {
|
||||
if got[key] != want {
|
||||
t.Errorf("%s = %q, want %q", key, got[key], want)
|
||||
}
|
||||
}
|
||||
|
||||
for _, key := range []string{"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC", "DISABLE_TELEMETRY"} {
|
||||
if _, ok := got[key]; ok {
|
||||
t.Errorf("%s must not be set by Ollama", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClaudeRunEnvironmentAndChannels(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("uses a POSIX shell capture binary")
|
||||
}
|
||||
channelsBlockingEnvVars := []string{
|
||||
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC",
|
||||
"DISABLE_TELEMETRY",
|
||||
}
|
||||
|
||||
writeCaptureBinary := func(t *testing.T) string {
|
||||
t.Helper()
|
||||
binDir := t.TempDir()
|
||||
path := filepath.Join(binDir, "claude")
|
||||
script := `#!/bin/sh
|
||||
printf 'ARG=%s\n' "$@" > "$OLLAMA_LAUNCH_CLAUDE_TEST_LOG"
|
||||
env >> "$OLLAMA_LAUNCH_CLAUDE_TEST_LOG"
|
||||
`
|
||||
if err := os.WriteFile(path, []byte(script), 0o755); err != nil {
|
||||
t.Fatalf("write capture binary: %v", err)
|
||||
}
|
||||
t.Setenv("PATH", binDir+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
return filepath.Join(t.TempDir(), "claude.log")
|
||||
}
|
||||
|
||||
clearChannelsBlockingEnv := func(t *testing.T) {
|
||||
t.Helper()
|
||||
for _, key := range channelsBlockingEnvVars {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
t.Setenv(key, value)
|
||||
} else {
|
||||
t.Setenv(key, "")
|
||||
}
|
||||
if err := os.Unsetenv(key); err != nil {
|
||||
t.Fatalf("unset %s: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("does not add blocking flags and passes channels", func(t *testing.T) {
|
||||
clearChannelsBlockingEnv(t)
|
||||
logPath := writeCaptureBinary(t)
|
||||
t.Setenv("OLLAMA_LAUNCH_CLAUDE_TEST_LOG", logPath)
|
||||
|
||||
err := (&Claude{}).Run("llama3.2", nil, []string{"--channels", "plugin:telegram@claude-plugins-official"})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(logPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := string(data)
|
||||
wantArgs := "ARG=--model\nARG=llama3.2\nARG=--channels\nARG=plugin:telegram@claude-plugins-official\n"
|
||||
if !strings.Contains(got, wantArgs) {
|
||||
t.Fatalf("child args did not contain channels invocation:\n%s", got)
|
||||
}
|
||||
for _, key := range channelsBlockingEnvVars {
|
||||
if strings.Contains(got, "\n"+key+"=") {
|
||||
t.Fatalf("child environment contained %s:\n%s", key, got)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(got, "\nDISABLE_ERROR_REPORTING=1\n") {
|
||||
t.Fatalf("child environment did not retain error-reporting opt-out:\n%s", got)
|
||||
}
|
||||
})
|
||||
|
||||
for _, key := range channelsBlockingEnvVars {
|
||||
t.Run("preserves explicit "+key+" without channels", func(t *testing.T) {
|
||||
clearChannelsBlockingEnv(t)
|
||||
logPath := writeCaptureBinary(t)
|
||||
t.Setenv("OLLAMA_LAUNCH_CLAUDE_TEST_LOG", logPath)
|
||||
t.Setenv(key, "1")
|
||||
|
||||
if err := (&Claude{}).Run("llama3.2", nil, []string{"--print"}); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(logPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(data), "\n"+key+"=1\n") {
|
||||
t.Fatalf("child environment did not preserve explicit %s:\n%s", key, data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClaudeModelEnvVars(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user