oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package runner
2
3import (
4 "encoding/json"
5 "os"
6 "path/filepath"
7 "slices"
8 "testing"
9
10 "amadan.net/oficina/equipo/internal/runner/provider"
11)
12
13// A token connection's home, where its token rests, is denied to every
14// launch's policy (the model's own and every other connection's), like
15// any dedicated home; the bindings file accepts kind token for Claude
16// only; and its launches stage it as a token home.
17func TestTokenBinding(t *testing.T) {
18 c := configFixture(t)
19 root := filepath.Dir(c.StateDir)
20 identity := provider.Identity{AccountID: "t@example.com", HomeID: "h1", ProviderVersion: provider.ClaudeVersion}
21 token := AccountBinding{ID: "claude-2", LocalID: "claude-2", PersonID: "p@example.com", Provider: "claude", Family: "claude", Model: "claude-opus-5-5", AccountID: "t@example.com", ProviderHome: filepath.Join(root, "accounts", "claude-2"), Kind: "token", ExpectedIdentity: identity}
22 other := token
23 other.ID, other.LocalID, other.AccountID, other.ProviderHome, other.Kind = "claude-1", "claude-1", "o@example.com", filepath.Join(root, "accounts", "claude-1"), "subscription"
24 other.ExpectedIdentity = provider.Identity{AccountID: "o@example.com", HomeID: "h2", ProviderVersion: provider.ClaudeVersion}
25 bs := []AccountBinding{other, token}
26 for _, b := range bs {
27 policy, err := bindingPolicy(c, bs, b)
28 if err != nil || !slices.Contains(policy.DeniedPaths, token.ProviderHome) {
29 t.Fatalf("the token home is not denied to %s: %v", b.ID, err)
30 }
31 }
32 write := func(bs []AccountBinding) {
33 raw, _ := json.Marshal(bs)
34 if err := os.WriteFile(c.AccountBindingsPath, raw, 0600); err != nil {
35 t.Fatal(err)
36 }
37 }
38 write(bs)
39 if got, err := loadDirectBindings(c.AccountBindingsPath); err != nil || len(got) != 2 {
40 t.Fatalf("token binding refused: %v", err)
41 }
42 codex := token
43 codex.Provider, codex.Family = "codex", "gpt"
44 write([]AccountBinding{codex})
45 if _, err := loadDirectBindings(c.AccountBindingsPath); err == nil {
46 t.Fatal("a Codex token binding was accepted")
47 }
48 direct, err := c.DirectBinding(token)
49 if err != nil || !direct.Token {
50 t.Fatalf("a token binding stages as a login home: %v", err)
51 }
52 if direct, _ = c.DirectBinding(other); direct.Token {
53 t.Fatal("a login binding stages as a token home")
54 }
55}
56