oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "context"
5 "strings"
6 "testing"
7
8 "amadan.net/oficina/equipo/internal/wire"
9)
10
11// Thinking is GET /api/v1/thinking.
12func (c *Client) Thinking(ctx context.Context) (out wire.ThinkingWords, err error) {
13 return out, c.do(ctx, "GET", "/api/v1/thinking", nil, &out)
14}
15
16// SetThinking is PUT /api/v1/thinking.
17func (c *Client) SetThinking(ctx context.Context, set string, revision int64) (out wire.ThinkingWords, err error) {
18 return out, c.do(ctx, "PUT", "/api/v1/thinking", wire.ThinkingChoice{Set: set, Revision: revision}, &out)
19}
20
21// TestContractThinkingWords: each person picks the words the thinking line
22// shows (Paul: "fun 'Thinking' variants... start with a more professional
23// one... and 'Random'... 'Delcambring' should be one"). Professional
24// until they pick; every set but Random has phrases for every situation;
25// a change against an old revision is refused; the person's open pages
26// hear of it; another person's choice is their own.
27func TestContractThinkingWords(t *testing.T) {
28 r := newToolRig(t)
29 ctx := r.ctx
30 got, err := r.client.Thinking(ctx)
31 if err != nil {
32 t.Fatal(err)
33 }
34 shape(t, "api/thinking.json", got)
35 if got.Set != wire.DefaultThinking || got.Revision != 0 || len(got.Sets) != len(wire.ThinkingSets) {
36 t.Fatalf("default: %s r%d, %d sets", got.Set, got.Revision, len(got.Sets))
37 }
38 all := ""
39 for _, s := range got.Sets {
40 if s.Name == "" || s.Description == "" {
41 t.Fatalf("set %s has no name or description", s.ID)
42 }
43 if s.ID == wire.ThinkingRandom {
44 continue
45 }
46 // Paul, 2026-11-09: "many more per category so it takes a while
47 // before I see the same ones again": 40 or more for thinking, 15
48 // or more for each other situation, none twice, short.
49 for _, sit := range wire.ThinkingSituations {
50 need := 15
51 if sit == "think" {
52 need = 40
53 }
54 if len(s.Phrases[sit]) < need {
55 t.Fatalf("set %s has %d phrases for %s, want %d or more", s.ID, len(s.Phrases[sit]), sit, need)
56 }
57 seen := map[string]bool{}
58 for _, p := range s.Phrases[sit] {
59 all += p + "\n"
60 if strings.ContainsRune(p, '—') || strings.Contains(p, "!") || strings.ContainsAny(p, `"“”`) || !strings.HasSuffix(p, "…") || len(strings.Fields(p)) > 6 || seen[p] {
61 t.Fatalf("%s %s: %q", s.ID, sit, p)
62 }
63 seen[p] = true
64 }
65 }
66 }
67 if strings.Count(all, "Delcambring…") < 2 {
68 t.Fatal("Delcambring is missing from Playful or Terminal")
69 }
70 set, err := r.client.SetThinking(ctx, "pirate", 0)
71 if err != nil || set.Set != "pirate" || set.Revision == 0 {
72 t.Fatalf("set: %+v %v", set, err)
73 }
74 if _, err := r.client.SetThinking(ctx, "galaxy", 0); Status(err) != 409 {
75 t.Fatalf("stale revision: %v", err)
76 }
77 if _, err := r.client.SetThinking(ctx, "jedi", set.Revision); err == nil {
78 t.Fatal("an unknown set was accepted")
79 }
80 events, err := r.inst.Store.Chat().Events(ctx, Owner, 0, 1000)
81 if err != nil {
82 t.Fatal(err)
83 }
84 heard := false
85 for _, e := range events {
86 heard = heard || e.Type == wire.EventThinking && e.ID == Owner
87 }
88 if !heard {
89 t.Fatal("no thinking event for the person")
90 }
91 if again, _ := r.client.Thinking(ctx); again.Set != "pirate" {
92 t.Fatalf("read back %s", again.Set)
93 }
94}
95