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 "encoding/json"
5 "reflect"
6 "strings"
7 "testing"
8
9 "amadan.net/oficina/equipo/internal/wire"
10)
11
12func TestContractEngineeringChangeFiles(t *testing.T) {
13 for _, protocol := range []int{wire.ProtocolChangeFiles, wire.ProtocolChangeFiles - 1} {
14 t.Run(string(rune('A'+protocol)), func(t *testing.T) {
15 r := newToolRigAt(t, protocol)
16 base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40)
17 id := taskID(t, r.call("files-record", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": "Changed file facts", "brief": "Adjust the README", "separate": true}))
18 if res := r.call("files-start", wire.ToolStartTask, map[string]string{"task": id, "brief": "Adjust it"}); res.IsError {
19 t.Fatal(res)
20 }
21 _, body := r.expect(wire.FrameDispatch)
22 eng := body.(*wire.DispatchCommand)
23 facts := &wire.ChangeFiles{Base: base, SHA: cand, Files: 2, Additions: 3, Deletions: 1, Entries: []wire.ChangedFile{
24 {Path: "docs/read me 日本語.md", OldPath: "README.md", Status: "renamed", Additions: 3, Deletions: 1},
25 {Path: "empty.txt", Status: "added"},
26 }}
27 r.step("files-done", wire.StepReport{TaskID: id, StepID: eng.StepID, Attempt: eng.Attempt, State: wire.StepDone, BaseSHA: base, CandidateSHA: cand, Pushed: true, Termination: true, ChangeFiles: facts})
28 task, err := r.client.Task(r.ctx, id)
29 if err != nil {
30 t.Fatal(err)
31 }
32 // Only this detail route carries file facts, even for new runners.
33 list, err := r.client.Tasks(r.ctx)
34 if err != nil {
35 t.Fatal(err)
36 }
37 snapshot, err := r.client.Snapshot(r.ctx)
38 if err != nil {
39 t.Fatal(err)
40 }
41 for name, value := range map[string]any{"list": list, "snapshot": snapshot} {
42 raw, err := json.Marshal(value)
43 if err != nil {
44 t.Fatal(err)
45 }
46 if strings.Contains(string(raw), "\"change_files\"") {
47 t.Fatalf("%s leaked file facts", name)
48 }
49 }
50 got := task.Steps[0].ChangeFiles
51 if protocol < 31 {
52 if got != nil {
53 t.Fatalf("old runner facts: %+v", got)
54 }
55 return
56 }
57 if !reflect.DeepEqual(got, facts) {
58 t.Fatalf("device facts: %+v", got)
59 }
60 raw, _ := json.Marshal(got)
61 for _, secret := range []string{"review_step", "old_mode", "new_mode", "complete", "repo", "content", "token"} {
62 if strings.Contains(string(raw), "\""+secret+"\"") {
63 t.Fatalf("non-display field: %s", raw)
64 }
65 }
66 // Engineering presentation is never Review's accepted merge evidence.
67 if task.MergeDecision != nil {
68 t.Fatalf("Engineering facts made a merge decision: %+v", task.MergeDecision)
69 }
70 })
71 }
72}
73