| 1 | package codex |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 5 | "context" |
| 6 | "crypto/rand" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // Test-only constructor keeps fake executable digests out of production APIs. |
| 11 | func CoordinatorContinuityFixture(t *testing.T, wrap func(provider.ProcessHost) provider.ProcessHost, captures provider.CaptureFactory, source provider.Binding) (provider.Launcher, provider.Launch, func() error, func()) { |
| 12 | f := fixtureFor(t) |
| 13 | if source.ID != "" { |
| 14 | if err := f.lease.Close(); err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | var err error |
| 18 | f.lease, err = provider.OpenAccount(context.Background(), source) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | } |
| 23 | f.launch.Binding = f.lease.Binding() |
| 24 | profile, _ := provider.Profile("coordinate") |
| 25 | in := f.inputs |
| 26 | in.Action = "coordinate" |
| 27 | in.Tools = profile.MCPTools() |
| 28 | var err error |
| 29 | in, err = PolicyInputs(f.lease.Binding(), in, f.launch.Selection.Model) |
| 30 | if err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | f.launch.Policy, err = provider.BuildPolicy(f.lease.Binding(), in) |
| 34 | if err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | f.launch.AttemptKey = rand.Text() |
| 38 | f.l.host = wrap(f.host) |
| 39 | f.l.captures = captures |
| 40 | f.host.sessionID = rand.Text() |
| 41 | return f.l, f.launch, f.lease.Close, func() { |
| 42 | if f.host.count("thread/start") != 1 { |
| 43 | t.Fatal("fresh coordinator omitted thread/start") |
| 44 | } |
| 45 | f.host.mu.Lock() |
| 46 | defer f.host.mu.Unlock() |
| 47 | for _, l := range f.host.launches { |
| 48 | if l.ResumeSessionID != "" { |
| 49 | t.Fatal("coordinator resumed prior thread") |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |