package thin import ( "os" "runtime" "strings" "testing" "time" "amadan.net/oficina/equipo/internal/toolproxy" ) // The Linux tool proxy still speaks the recorded transcript, so the // oracle the Mac endpoint is held to is what Linux does today. With // EQUIPO_RECORD_TOOL_TRANSCRIPT=1 it records the transcript again, with // today's date and this machine in its header. func TestLinuxToolProxyTranscript(t *testing.T) { got := playTranscript(t, toolproxy.Serve) if os.Getenv("EQUIPO_RECORD_TOOL_TRANSCRIPT") == "1" { host, err := os.Hostname() if err != nil { t.Fatal(err) } header := "# The tool proxy transcript: what a CLI sends through a tool proxy to a\n" + "# step's tool socket (>) and each reply (<), one tool socket per session.\n" + "# Recorded " + time.Now().UTC().Format("2006-01-02") + " on " + strings.ToLower(host) + " (" + runtime.GOOS + "/" + runtime.GOARCH + ") from the Linux tool proxy\n" + "# (internal/toolproxy.Serve) by TestLinuxToolProxyTranscript, and the\n" + "# oracle for TestDarwinToolProxySpeaksTheProtocol. Record it again with\n" + "# EQUIPO_RECORD_TOOL_TRANSCRIPT=1 go test ./internal/runner/thin -run TestLinuxToolProxyTranscript\n" if err := os.WriteFile(transcriptFile, []byte(header+got), 0644); err != nil { t.Fatal(err) } } _, want := readTranscript(t) sameTranscript(t, got, want) // The oracle holds both answers: a permission allowed and one denied. if !strings.Contains(want, `\"behavior\":\"allow\"`) || !strings.Contains(want, `\"behavior\":\"deny\"`) { t.Fatal("the transcript records no allowed and denied permission") } }