| 1 | package fprobe |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/wire" |
| 8 | ) |
| 9 | |
| 10 | // Whole-branch fix 1, #6: what the store says of a probe that has no |
| 11 | // current result is a code, each reason its own. |
| 12 | func TestStoreDetailsAreCoded(t *testing.T) { |
| 13 | now := time.Date(2026, 11, 29, 12, 0, 0, 0, time.UTC) |
| 14 | in := NewInputs("v1.0.0", true, wire.Xcode{Version: "27.2", Build: "27B52"}, []wire.Simulator{{Runtime: "iOS 27.2"}}) |
| 15 | var s Store |
| 16 | seen := map[string]bool{} |
| 17 | note := func(ps []wire.Probe, id, code string) { |
| 18 | t.Helper() |
| 19 | coded(t, ps) |
| 20 | p := byID(ps, id) |
| 21 | if parts, _ := wire.ParseProbeDetail(p.Detail); len(parts) != 1 || parts[0].Code != code { |
| 22 | t.Fatalf("%s: %q, want %s", id, p.Detail, code) |
| 23 | } |
| 24 | seen[code] = true |
| 25 | } |
| 26 | note(s.Probes(in, now, true), "F1", "not_run") |
| 27 | note(s.Probes(in, now, false), "F5", "f5_skipped") |
| 28 | s.Put(allPassed(in, now.Add(-25*time.Hour))[0]) |
| 29 | note(s.Probes(in, now, true), "F1", "expired") |
| 30 | s.Put(allPassed(in, now.Add(time.Hour))[0]) |
| 31 | note(s.Probes(in, now, true), "F1", "future") |
| 32 | for code, other := range map[string]Inputs{ |
| 33 | "stale_runner": NewInputs("v1.0.1", true, wire.Xcode{Version: "27.2", Build: "27B52"}, []wire.Simulator{{Runtime: "iOS 27.2"}}), |
| 34 | "stale_xcode": NewInputs("v1.0.0", true, wire.Xcode{Version: "27.3", Build: "27C1"}, []wire.Simulator{{Runtime: "iOS 27.2"}}), |
| 35 | "stale_runtimes": NewInputs("v1.0.0", true, wire.Xcode{Version: "27.2", Build: "27B52"}, []wire.Simulator{{Runtime: "iOS 27.3"}}), |
| 36 | } { |
| 37 | var u Store |
| 38 | u.Put(allPassed(in, now)[0]) |
| 39 | note(u.Probes(other, now, true), "F1", code) |
| 40 | } |
| 41 | for _, ps := range [][]wire.Probe{ |
| 42 | launched(LaunchA, Outcome{Reason: "account_unavailable"}), |
| 43 | launched(LaunchA, Outcome{Reason: "a sentence, with words"}), |
| 44 | launched(LaunchC, Outcome{Started: true}), |
| 45 | undecided(LaunchA, Host{}, "inputs_changed").Probes, |
| 46 | notRun(all(LaunchA, wire.ProbeDenied, wire.ProbeDetail("f1_denied")), "script_not_run"), |
| 47 | notRun(all(LaunchA, wire.ProbeFailed, wire.ProbeDetail("allowed", "tcp")), "other_command"), |
| 48 | } { |
| 49 | coded(t, ps) |
| 50 | } |
| 51 | } |
| 52 | |