| 1 | //go:build testbuild |
| 2 | |
| 3 | package thin |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "slices" |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
| 11 | "amadan.net/oficina/equipo/internal/runner/mac" |
| 12 | "amadan.net/oficina/equipo/internal/runner/mac/fprobe" |
| 13 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 14 | "amadan.net/oficina/equipo/internal/wire" |
| 15 | ) |
| 16 | |
| 17 | // Whole-branch fix 2, #5: every candidate's object scan runs gitleaks |
| 18 | // under the checks profile P2 proves, so a Mac is ready for Engineering |
| 19 | // only with P2 denied: with F1 to F7 passed and P2 not run or not |
| 20 | // denied it says so (P2 named) and carries no claude tag, so the |
| 21 | // instance places no Engineering there. |
| 22 | func TestMacEngineeringNeedsP2(t *testing.T) { |
| 23 | x := newEngRig(t) |
| 24 | h := &macHost{version: "v-test", probes: newMacProbes("v-test", "", nil, func() bool { return true }), creds: x.m, taint: x.m.taint, turns: x.m.turns} |
| 25 | h.eng = newMacEngineering(h) |
| 26 | sims := []wire.Simulator{{Name: "iPhone 17 Pro", Runtime: "iOS 27.2", UDID: "ABCDEF01-2345-6789-ABCD-EF0123456789", State: "Shutdown"}} |
| 27 | xcode := wire.Xcode{Version: "27.2", Build: "27B52"} |
| 28 | now := time.Now() |
| 29 | h.eng.now = func() time.Time { return now } |
| 30 | in := fprobe.NewInputs("v-test", true, xcode, sims) |
| 31 | for _, l := range fprobe.Launches { |
| 32 | r := fprobe.Result{Launch: l, Inputs: in, At: now} |
| 33 | for _, id := range wire.EngineeringProbeIDs { |
| 34 | if fprobe.LaunchOf(id) == l { |
| 35 | r.Probes = append(r.Probes, wire.Probe{ID: id, Verdict: wire.EngineeringProbeSuccess(id), Detail: wire.ProbeDetail("f1_denied")}) |
| 36 | } |
| 37 | } |
| 38 | h.eng.store.Put(r) |
| 39 | } |
| 40 | h.eng.bind(x.w, x.conns, nil) |
| 41 | live := wire.Capabilities{Tags: []string{wire.TagMacOS, wire.TagXcode}, Simulators: sims, Xcode: xcode, Harness: wire.Harness{Claude: provider.ClaudeVersion}} |
| 42 | h.eng.live = func(context.Context) wire.Capabilities { return live } |
| 43 | compose := func() wire.Capabilities { |
| 44 | c := live |
| 45 | c.Tags = slices.Clone(live.Tags) |
| 46 | h.eng.compose(&c) |
| 47 | if err := wire.ValidCapabilities(c); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | return c |
| 51 | } |
| 52 | if c := compose(); *c.Engineering != (wire.EngineeringStatus{State: wire.EngineeringProbesPending, Reason: "P2"}) || slices.Contains(c.Tags, wire.TagClaude) { |
| 53 | t.Fatalf("P2 not run: %+v %v", c.Engineering, c.Tags) |
| 54 | } |
| 55 | h.probes.last = mac.Report{Version: "v-test", Profile: mac.ProfileDigest(), At: now, SRT: srtPinned, Probes: []wire.Probe{{ID: "P2", Verdict: wire.ProbeFailed}}} |
| 56 | if c := compose(); *c.Engineering != (wire.EngineeringStatus{State: wire.EngineeringProbesFailed, Reason: "P2"}) || slices.Contains(c.Tags, wire.TagClaude) { |
| 57 | t.Fatalf("P2 not denied: %+v %v", c.Engineering, c.Tags) |
| 58 | } |
| 59 | if st := h.eng.statusNow(context.Background()); st.State == wire.EngineeringReady { |
| 60 | t.Fatalf("ready at use with P2 not denied: %+v", st) |
| 61 | } |
| 62 | h.probes.last.Probes[0].Verdict = wire.ProbeDenied |
| 63 | if c := compose(); *c.Engineering != (wire.EngineeringStatus{State: wire.EngineeringReady}) || !slices.Contains(c.Tags, wire.TagClaude) { |
| 64 | t.Fatalf("P2 denied: %+v %v", c.Engineering, c.Tags) |
| 65 | } |
| 66 | } |
| 67 | |