TestSessionRecord_JSONShape pins the consumer contract of `pad session list --format json`: the keys scripts read, present in the shape they expect, with agent always present (never omitted when anonymous).
(t *testing.T)
| 397 | // list --format json`: the keys scripts read, present in the shape they |
| 398 | // expect, with agent always present (never omitted when anonymous). |
| 399 | func TestSessionRecord_JSONShape(t *testing.T) { |
| 400 | registryEnv(t) |
| 401 | rec, err := RegisterSession("/proj", "") |
| 402 | if err != nil { |
| 403 | t.Fatal(err) |
| 404 | } |
| 405 | data, err := json.Marshal(rec) |
| 406 | if err != nil { |
| 407 | t.Fatal(err) |
| 408 | } |
| 409 | var raw map[string]any |
| 410 | if err := json.Unmarshal(data, &raw); err != nil { |
| 411 | t.Fatal(err) |
| 412 | } |
| 413 | for _, key := range []string{"session_pid", "session_pid_source", "session_pid_verified", "agent", "cwd", "liveness", "registered_at", "path"} { |
| 414 | if _, ok := raw[key]; !ok { |
| 415 | t.Fatalf("record JSON missing %q: %s", key, data) |
| 416 | } |
| 417 | } |
| 418 | if raw["agent"] != "" || raw["liveness"] != "alive" || raw["session_pid"] != float64(os.Getpid()) || raw["session_pid_verified"] != true { |
| 419 | t.Fatalf("record JSON values wrong: %s", data) |
| 420 | } |
| 421 | for _, absent := range []string{"legacy", "malformed", "session_id"} { |
| 422 | if _, ok := raw[absent]; ok { |
| 423 | t.Fatalf("%q must be omitted when false/empty: %s", absent, data) |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // TestListSessions_SemanticallyMalformedIsUnknown: JSON that parses but |
| 429 | // is not a registration this code wrote must be MALFORMED (unknown, kept |
nothing calls this directly
no test coverage detected