| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "fmt" |
| 6 | "os" |
| 7 | "path/filepath" |
| 8 | "runtime" |
| 9 | "testing" |
| 10 | "time" |
| 11 | |
| 12 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 13 | ) |
| 14 | |
| 15 | func runtimeFixture(t *testing.T) Config { |
| 16 | t.Helper() |
| 17 | c := configFixture(t) |
| 18 | c.GoRoot = filepath.Join(t.TempDir(), "go") |
| 19 | c.GoBinary = filepath.Join(c.GoRoot, "bin/go") |
| 20 | c.CodexPath = filepath.Join(t.TempDir(), "codex") |
| 21 | c.Copy = ToolCopy{Accepted: "accepted", Rejected: "rejected"} |
| 22 | for _, p := range []string{c.StateDir, filepath.Dir(c.GoBinary)} { |
| 23 | if err := os.MkdirAll(p, 0700); err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | } |
| 27 | if err := os.WriteFile(c.GoBinary, []byte(fmt.Sprintf("#!/bin/sh\necho 'go version go1.26.11 %s/%s'\n", runtime.GOOS, runtime.GOARCH)), 0700); err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | if err := os.WriteFile(c.CodexPath, []byte("#!/bin/sh\necho 'codex-cli 0.165.0'\n"), 0700); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | home := filepath.Join(t.TempDir(), "home") |
| 34 | os.Mkdir(home, 0700) |
| 35 | raw, _ := json.Marshal([]AccountBinding{{ID: "b", LocalID: "local", Provider: "codex", Family: "gpt", Model: "model", AccountID: "account", CredentialHome: home, Kind: "subscription"}}) |
| 36 | if err := os.WriteFile(c.AccountBindingsPath, raw, 0600); err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | if err := runnerproto.JournalCredentials(filepath.Join(c.StateDir, "credentials.json"), runnerproto.CredentialRotation{Bearer: runnerproto.RunnerCredential{Version: 1, RunnerID: "runner", Token: "test", ExpiresAt: time.Now().Add(time.Hour)}}); err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | return c |
| 43 | } |
| 44 | |