oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package provider
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9func TestCodexLiveThreadState(t *testing.T) {
10 for _, tc := range []struct {
11 path string
12 size int
13 dir, want bool
14 }{
15 {"thread-writer-locks/01a1aaad-0467-7f31-8540-a9004a8aaae2.lock", 0, false, true},
16 {"thread-writer-locks/01a1aaad-0467-7f31-8540-a9004a8aaae2.lock", 1, false, false},
17 {"thread-writer-locks/NOT-A-UUID.lock", 0, false, false},
18 {"thread_history_1.sqlite", 4096, false, true},
19 {"thread_history_1.sqlite-shm", 32768, false, true},
20 {"thread_history_1.sqlite-wal", 383192, false, true},
21 {"thread_history_1.sqlite", 0, true, false},
22 {"thread_history_1.sqlite-extra", 0, false, false},
23 {".sqlite-maintenance.lock", 0, false, true},
24 {".sqlite-maintenance.lock", 1, false, false},
25 {".sqlite-maintenance.lock", 0, true, false},
26 {".sqlite-maintenance.lock-extra", 0, false, false},
27 {".sandbox_migration", 3, false, true}, {"thread-writer-locks", 0, true, true}, {"thread-writer-locks/.coordination.lock", 0, false, true},
28 {".sandbox_migration", 4, false, false}, {".sandbox_migration", 0, true, false}, {"thread-writer-locks", 0, false, false},
29 {"thread-writer-locks/unknown", 0, false, false}, {"thread-writer-locks/.coordination.lock", 1, false, false},
30 } {
31 t.Run(tc.path, func(t *testing.T) {
32 l := &AccountLease{source: Binding{Provider: "codex", Expected: Identity{ProviderVersion: CodexVersion}}, runtime: t.TempDir()}
33 path := filepath.Join(l.runtime, tc.path)
34 if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
35 t.Fatal(err)
36 }
37 var err error
38 if tc.dir {
39 err = os.Mkdir(path, 0700)
40 } else {
41 err = os.WriteFile(path, make([]byte, tc.size), 0600)
42 }
43 if err != nil {
44 t.Fatal(err)
45 }
46 if err = l.validateRuntimeEntries(); (err == nil) != tc.want {
47 t.Fatalf("want allowed=%v got %v", tc.want, err)
48 }
49 l.source.Expected.ProviderVersion = "other"
50 if l.validateRuntimeEntries() == nil {
51 t.Fatal("other version accepted")
52 }
53 })
54 }
55}
56
57func TestCodexMaintenanceLockMetadata(t *testing.T) {
58 for _, kind := range []string{"recorded", "executable", "world-writable", "hardlink", "symlink", "other-provider"} {
59 t.Run(kind, func(t *testing.T) {
60 l := &AccountLease{source: Binding{Provider: "codex", Expected: Identity{ProviderVersion: CodexVersion}}, runtime: t.TempDir()}
61 path := filepath.Join(l.runtime, ".sqlite-maintenance.lock")
62 if err := os.WriteFile(path, nil, 0600); err != nil {
63 t.Fatal(err)
64 }
65 mode := os.FileMode(0664)
66 if kind == "executable" {
67 mode = 0764
68 }
69 if kind == "world-writable" {
70 mode = 0666
71 }
72 if err := os.Chmod(path, mode); err != nil {
73 t.Fatal(err)
74 }
75 if kind == "hardlink" {
76 if err := os.Link(path, filepath.Join(t.TempDir(), "alias")); err != nil {
77 t.Fatal(err)
78 }
79 }
80 if kind == "symlink" {
81 if err := os.Remove(path); err != nil {
82 t.Fatal(err)
83 }
84 if err := os.Symlink("/absent", path); err != nil {
85 t.Fatal(err)
86 }
87 }
88 if kind == "other-provider" {
89 l.source.Provider = "claude"
90 }
91 err := l.validateRuntimeEntries()
92 if (err == nil) != (kind == "recorded") {
93 t.Fatalf("%s: %v", kind, err)
94 }
95 })
96 }
97}
98