TestContainingCommGate is the regression guard for the false-FLAGGED class: a background harness read (comm=claude) in a benign tool's window must NOT be attributed to that tool, while the tool's own subprocess read (comm matching the tool program) must be -- even when the syscall lands seconds afte
(t *testing.T)
| 18 | // the tool program) must be -- even when the syscall lands seconds after the |
| 19 | // hook window (PostToolUse fires early). |
| 20 | func TestContainingCommGate(t *testing.T) { |
| 21 | windows := toolCallWindows{ |
| 22 | win("main", "tc-echo", "echo", "2026-07-06T08:45:00.000Z", "2026-07-06T08:45:00.100Z"), |
| 23 | win("main", "tc-cat", "cat", "2026-07-06T08:45:12.180Z", "2026-07-06T08:45:12.331Z"), |
| 24 | } |
| 25 | |
| 26 | // The cat subprocess reads the secret 3s after PostToolUse: still attributed |
| 27 | // (wide window) and to the cat tool (comm match), not the echo tool. |
| 28 | w, ok := windows.containing("2026-07-06T08:45:15.341Z", "cat") |
| 29 | if !ok || w.toolCall != "tc-cat" { |
| 30 | t.Fatalf("cat read should attribute to tc-cat, got ok=%v tc=%q", ok, w.toolCall) |
| 31 | } |
| 32 | |
| 33 | // A background harness read (comm=claude) in the same window matches NO tool |
| 34 | // program -> not attributed (becomes a coverage gap, never a mismatch). |
| 35 | if _, ok := windows.containing("2026-07-06T08:45:13.000Z", "claude"); ok { |
| 36 | t.Fatal("a comm=claude background read must not attribute to any tool call") |
| 37 | } |
| 38 | if _, ok := windows.containing("2026-07-06T08:45:13.000Z", "Bun Pool 1"); ok { |
| 39 | t.Fatal("a comm=Bun read must not attribute to any tool call") |
| 40 | } |
| 41 | |
| 42 | // No comm at all -> no time-window attribution. |
| 43 | if _, ok := windows.containing("2026-07-06T08:45:15.341Z", ""); ok { |
| 44 | t.Fatal("an effect with no comm must not be time-window attributed") |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestProgramName(t *testing.T) { |
| 49 | cases := map[string]string{ |
nothing calls this directly
no test coverage detected