26f897c1ec
release / release-please (push) Failing after 1m49s
docs / build (push) Failing after 6m34s
release / build-and-upload (arm64, linux) (push) Has been cancelled
release / build-and-upload (arm64, windows) (push) Has been cancelled
release / build-darwin (amd64, darwin) (push) Has been cancelled
release / checksums (push) Has been cancelled
release / finalize (push) Has been cancelled
release / build-darwin (arm64, darwin) (push) Has been cancelled
release / build-and-upload (amd64, linux) (push) Has been cancelled
release / build-and-upload (amd64, windows) (push) Has been cancelled
docs / deploy (push) Has been cancelled
35 lines
1.3 KiB
Go
35 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestScrubClaudeHookEvents_RemovesInitEvent(t *testing.T) {
|
|
input := []byte("{\"type\":\"assistant\",\"message\":\"keep\"}\n{\"subtype\":\"init\",\"session_id\":\"abc\",\"tools\":[\"terminal-axi\"]}\n{\"type\":\"result\",\"status\":\"ok\"}\n")
|
|
|
|
scrubbed := scrubClaudeHookEvents(input)
|
|
|
|
if bytes.Contains(scrubbed, []byte(`"subtype":"init"`)) {
|
|
t.Fatalf("expected init event removed, got %q", scrubbed)
|
|
}
|
|
want := []byte("{\"type\":\"assistant\",\"message\":\"keep\"}\n{\"type\":\"result\",\"status\":\"ok\"}\n")
|
|
if !bytes.Equal(scrubbed, want) {
|
|
t.Fatalf("scrubbed = %q, want %q", scrubbed, want)
|
|
}
|
|
}
|
|
|
|
func TestReplacePathForms_ReplacesEscapedWindowsPaths(t *testing.T) {
|
|
input := []byte(`{"cwd":"C:\\Users\\kun\\project","tmp":"C:\\Users\\kun\\AppData\\Local\\Temp\\recordfixture-123"}`)
|
|
|
|
scrubbed := replacePathForms(input, `C:\Users\kun\AppData\Local\Temp`, "/tmp")
|
|
scrubbed = replacePathForms(scrubbed, `C:\Users\kun`, "/private/tmp/fixture-cwd")
|
|
|
|
if bytes.Contains(scrubbed, []byte(`C:\\Users\\kun`)) {
|
|
t.Fatalf("expected escaped home path removed, got %q", scrubbed)
|
|
}
|
|
if !bytes.Contains(scrubbed, []byte(`/tmp\\recordfixture-123`)) {
|
|
t.Fatalf("expected escaped temp path preserved under placeholder, got %q", scrubbed)
|
|
}
|
|
}
|