eiyuuzaki2333 on X: the Gateway page showed Pi's calls, the Masking page records from dsh alone, and nothing said whether Pi's requests were masked. They were: a Pi turn goes through the same masking as every agent's, on each API Pi uses (chat completions, responses, messages), with no agent or protocol scoping. But a record is made only for a request masking changed (noteMasked: hits or held values), and the page's agents came from records alone, so an agent whose requests carried nothing to mask didn't appear at all, the same as one never masked. Now, while masking is on for a request (redactionWantedFor, a key's own switch included), the gateway counts it under its agent (maskrec.Checked): looked over, and whether masking changed something, or sent as written to a model the user set to go unmasked. The counts hold no text: a small checked-<day>.json beside the day's records, written over through temp and rename at most every 5 s, read back after a restart, pruned at 30 days with the records and removed by Clear records. /api/masking/summary returns them as checked. Counted where a turn's masking is decided: serve (every routed chat turn, plugins and groups included), Codex's own sign-in's /responses turn, and the native API passthroughs (nativeArk, nativeAny). Not counted: searches, images, video, embeddings, System One's decisions and Codex's compactions, which are not an agent's turn; they keep their records as before. The Masking page's card lists each agent under the flow: "Pi · 128 checked · none to mask · 3 sent as written". A click narrows the list to it; the agent picker lists checked agents too; and a list with no records says "128 requests from Pi checked, and none carried anything to mask" instead of "Nothing masked matches these filters". Strings in zh, zh-TW, ja and de. Run (code at this head; first at basec41fa8e47on mica, then rebased on origin/maind987cc7d5on mote): -c41fa8e47, mica: go test ./internal/maskrec ./internal/gateway (-timeout 45m, 986s) ./internal/gui: ok. -d987cc7d5, mote: go test ./internal/maskrec ./internal/gui: ok; go test -run "Checked|Masked|Mask|Codex|Native" ./internal/gateway: ok. - GUI on mote, Chromium + WebKit: masking-records 124/124 (every language at 640px, en at 1100px), i18n-keys 4/4, i18n-en-no-cjk 4/4, mask-actions, mask-alert, mask-emails, mask-value-menu, masking-demo, masking-demo-unblurred, routing-masking, gateway-key-redact, group-redact, redact-route, window-mask: all pass. Screenshots checked in WebKit, en 1100 and zh 640. - GOOS=linux and GOOS=windows go vet ./internal/maskrec ./internal/gateway: ok (internal/gui's cross vet stops in wails' cgo, as on main); gofmt -l clean. Broken by hand: without the noteChecked line in serve, TestPiTurnsCountedAsChecked fails ("three turns with nothing to mask: {Looked:0}"); without the one in codex_backend.go, TestCodexOwnSignInKeepsItsMaskingTime fails (Looked 0). Not tried: a real Pi binary against a built magpie (the test sends Pi's own headers: magpie's token, User-Agent pi/…, X-Session-Affinity, on each of its three protocols); the counts across a real restart of the app (the unit test reads the day's file back after a reset).
113 lines
3.2 KiB
Go
113 lines
3.2 KiB
Go
package maskrec
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func resetChecked() {
|
|
checked.mu.Lock()
|
|
defer checked.mu.Unlock()
|
|
if checked.timer != nil {
|
|
checked.timer.Stop()
|
|
}
|
|
checked.days, checked.dirty, checked.timer, checked.pruned = nil, nil, nil, time.Time{}
|
|
}
|
|
|
|
// An agent's turns are counted while masking is on, nothing masked or
|
|
// not: the summary says each agent's turns looked over, those masking
|
|
// changed and those sent as written, over the days asked for, after a
|
|
// restart too (the day's file), and Clear takes them with the records.
|
|
// The file holds counts alone.
|
|
func TestCheckedCountsEachAgent(t *testing.T) {
|
|
now := time.Date(2026, 11, 14, 15, 0, 0, 0, time.Local)
|
|
dir := sandbox(t, now)
|
|
resetChecked()
|
|
t.Cleanup(resetChecked)
|
|
for range 3 {
|
|
Checked("pi", true, false)
|
|
}
|
|
Checked("pi", false, false)
|
|
Checked("dsh", true, true)
|
|
Checked("", true, false)
|
|
want := map[string]Looked{"pi": {Name: "pi", Looked: 3, Whole: 1}, "dsh": {Name: "dsh", Looked: 1, Masked: 1}, "other": {Name: "other", Looked: 1}}
|
|
check := func(when string, sum Summary) {
|
|
t.Helper()
|
|
if len(sum.Checked) != 3 || sum.Checked[0].Name != "pi" {
|
|
t.Fatalf("%s: %+v", when, sum.Checked)
|
|
}
|
|
for _, c := range sum.Checked {
|
|
if c != want[c.Name] {
|
|
t.Fatalf("%s: %+v, want %+v", when, c, want[c.Name])
|
|
}
|
|
}
|
|
}
|
|
check("in memory", Sum(7))
|
|
|
|
flushChecked()
|
|
path := filepath.Join(dir, "checked-2026-11-14.json")
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.ContainsAny(string(b), "\n") || !strings.Contains(string(b), `"pi"`) {
|
|
t.Fatalf("file: %s", b)
|
|
}
|
|
// a restart reads the day again, and counts on from it
|
|
resetChecked()
|
|
check("read back", Sum(7))
|
|
Checked("pi", true, false)
|
|
if c := Sum(7).Checked[0]; c.Name != "pi" || c.Looked != 4 {
|
|
t.Fatalf("counted on: %+v", c)
|
|
}
|
|
// a day out of the days asked for isn't counted
|
|
clock = func() time.Time { return now.AddDate(0, 0, 3) }
|
|
if got := Sum(1).Checked; len(got) != 0 {
|
|
t.Fatalf("today's, with nothing counted: %+v", got)
|
|
}
|
|
if got := Sum(7).Checked; len(got) != 3 {
|
|
t.Fatalf("over seven days: %+v", got)
|
|
}
|
|
// a file that doesn't parse counts from nothing
|
|
resetChecked()
|
|
os.WriteFile(path, []byte("{half"), 0o600)
|
|
if got := Sum(7).Checked; len(got) != 0 {
|
|
t.Fatalf("unparsed file: %+v", got)
|
|
}
|
|
|
|
Checked("pi", true, false)
|
|
flushChecked()
|
|
if err := Clear(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
t.Fatalf("Clear left %s: %v", path, err)
|
|
}
|
|
if got := Sum(7).Checked; len(got) != 0 {
|
|
t.Fatalf("after Clear: %+v", got)
|
|
}
|
|
}
|
|
|
|
// A day's counts older than the records are kept goes with them.
|
|
func TestCheckedPruned(t *testing.T) {
|
|
now := time.Date(2026, 11, 14, 15, 0, 0, 0, time.Local)
|
|
dir := sandbox(t, now)
|
|
resetChecked()
|
|
t.Cleanup(resetChecked)
|
|
old := filepath.Join(dir, "checked-2026-10-01.json")
|
|
os.WriteFile(old, []byte(`{"pi":{"looked":2}}`), 0o600)
|
|
kept := filepath.Join(dir, "checked-2026-11-01.json")
|
|
os.WriteFile(kept, []byte(`{"pi":{"looked":2}}`), 0o600)
|
|
Checked("pi", true, false)
|
|
flushChecked()
|
|
if _, err := os.Stat(old); !os.IsNotExist(err) {
|
|
t.Fatalf("%s kept: %v", old, err)
|
|
}
|
|
if _, err := os.Stat(kept); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|