oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package release
2
3import (
4 "crypto/sha256"
5 "fmt"
6 "os"
7 "path/filepath"
8 "testing"
9)
10
11func TestDirectReleaseDigests(t *testing.T) {
12 m := BuildManifest()
13 paths := map[string]string{}
14 m.Binaries = nil
15 for _, name := range []string{"claude", "codex", "codex-code-mode-host", "bwrap", "equipo-tool-proxy"} {
16 path := filepath.Join(t.TempDir(), name)
17 raw := []byte(name)
18 if err := os.WriteFile(path, raw, 0700); err != nil {
19 t.Fatal(err)
20 }
21 paths[name] = path
22 version := map[string]string{"claude": m.Claude, "codex": m.Codex, "codex-code-mode-host": m.Codex, "bwrap": m.BwrapVersion, "equipo-tool-proxy": m.LauncherVersion}[name]
23 m.Binaries = append(m.Binaries, BinaryDigest{Name: name, Version: version, SHA256: fmt.Sprintf("%x", sha256.Sum256(raw))})
24 }
25 if err := m.VerifyInstalled(paths); err != nil {
26 t.Fatal(err)
27 }
28 if err := os.WriteFile(paths["codex-code-mode-host"], []byte("changed"), 0700); err != nil {
29 t.Fatal(err)
30 }
31 if m.VerifyInstalled(paths) == nil {
32 t.Fatal("changed helper accepted")
33 }
34 if BuildManifest().VerifyInstalled(paths) == nil {
35 t.Fatal("offline manifest admitted production binaries")
36 }
37}
38
39func TestToolProxyDigestPinned(t *testing.T) {
40 m := BuildManifest()
41 paths := map[string]string{}
42 m.Binaries = nil
43 for name, version := range map[string]string{"claude": m.Claude, "codex": m.Codex, "codex-code-mode-host": m.Codex, "bwrap": m.BwrapVersion, "equipo-tool-proxy": m.LauncherVersion} {
44 path := filepath.Join(t.TempDir(), name)
45 raw := []byte(name)
46 if err := os.WriteFile(path, raw, 0700); err != nil {
47 t.Fatal(err)
48 }
49 paths[name] = path
50 m.Binaries = append(m.Binaries, BinaryDigest{Name: name, Version: version, SHA256: fmt.Sprintf("%x", sha256.Sum256(raw))})
51 }
52 if err := m.VerifyInstalled(paths); err != nil {
53 t.Fatal(err)
54 }
55 if err := os.WriteFile(paths["equipo-tool-proxy"], []byte("changed helper"), 0700); err != nil {
56 t.Fatal(err)
57 }
58 if m.VerifyInstalled(paths) == nil {
59 t.Fatal("changed tool proxy accepted")
60 }
61}
62
63// The source manifest pins the programs this repository does not build
64// and never the tool proxy: that digest is recorded by the release build.
65func TestManifestPinsNoToolProxy(t *testing.T) {
66 m := BuildManifest()
67 if m.Schema != 3 || len(m.Binaries) != 4 || m.ToolProxySHA256() != "" || m.Installable() {
68 t.Fatalf("an unlinked build carries a tool proxy digest or installs: %+v", m)
69 }
70 toolProxySHA256 = fmt.Sprintf("%x", sha256.Sum256([]byte("proxy")))
71 defer func() { toolProxySHA256 = "" }()
72 linked := BuildManifest()
73 if linked.ToolProxySHA256() != toolProxySHA256 || !linked.Installable() {
74 t.Fatalf("a linked build does not record its tool proxy: %+v", linked)
75 }
76 for _, bad := range []string{"bad", "ABCDEF", fmt.Sprintf("%X", sha256.Sum256([]byte("proxy")))} {
77 toolProxySHA256 = bad
78 if BuildManifest().Installable() {
79 t.Fatal("a malformed linked digest installs", bad)
80 }
81 }
82}
83
84func TestInstallableGuards(t *testing.T) {
85 valid := fixtureManifest([]byte("proxy"))
86 if !valid.Installable() {
87 t.Fatal("fixture")
88 }
89 for name, change := range map[string]func(*Manifest){
90 "schema": func(m *Manifest) { m.Schema = 2 },
91 "target": func(m *Manifest) { m.RunnerTarget = "linux/arm64" },
92 "bwrap": func(m *Manifest) { m.BwrapVersion = "0.10.0" },
93 "launcher": func(m *Manifest) { m.LauncherVersion = "direct-v2" },
94 "policy": func(m *Manifest) { m.PolicyVersion = "direct-v0" },
95 "missing": func(m *Manifest) { m.Binaries = m.Binaries[1:] },
96 "duplicate": func(m *Manifest) { m.Binaries[0] = m.Binaries[1] },
97 "digest": func(m *Manifest) { m.Binaries[0].SHA256 = "bad" },
98 "two proxies": func(m *Manifest) { m.Binaries[0] = m.Binaries[4] },
99 "proxy digest": func(m *Manifest) { m.Binaries[4].SHA256 = "bad" },
100 } {
101 m := valid
102 m.Binaries = append([]BinaryDigest(nil), valid.Binaries...)
103 change(&m)
104 if m.Installable() {
105 t.Error("installable with a wrong", name)
106 }
107 }
108}
109