package opencode import ( "os" "slices" "testing" "git.a-wan.net/alan/pipelines/internal/agentenv" ) // The OpenCode serve processes (chat service and owned stage services) and the // tools they run never see Pipelines' own secret pointers. func TestServiceEnvironmentScrubsPipelinesSecrets(t *testing.T) { t.Setenv("PIPELINES_SERVER_TOKEN_FILE", "/secret/server-token") t.Setenv("PIPELINES_WEB_AUTH_FILE", "/secret/web-auth.json") t.Setenv("PIPELINES_OPENCODE_ENDPOINT_PASSWORD_FILE", "/secret/opencode-password") t.Setenv("KEEP_ME", "1") for name, env := range map[string][]string{ "chat service": serviceEnvironment(`{"a":1}`), "stage service (server env)": serviceEnvironmentFrom(nil, ""), "stage service (run env)": serviceEnvironmentFrom(append(os.Environ(), "PIPELINES_X_TOKEN=envrc"), ""), "stage service (owned config)": serviceEnvironmentFrom(os.Environ(), `{"b":2}`), } { if leaks := agentenv.Leaks(env); len(leaks) > 0 { t.Errorf("%s leaks %v", name, leaks) } if !slices.Contains(env, "KEEP_ME=1") { t.Errorf("%s dropped an ordinary variable", name) } } }