| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/equipo/chat" |
| 5 | "amadan.net/oficina/equipo/internal/wire" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestCopyRevokedDelegationDoesNotLockRunner(t *testing.T) { |
| 11 | r := newRig(t) |
| 12 | p, err := r.inst.Store.AuthenticateRunner(r.ctx, r.runner) |
| 13 | if err != nil { |
| 14 | t.Fatal(err) |
| 15 | } |
| 16 | for _, q := range []struct { |
| 17 | sql string |
| 18 | args []any |
| 19 | }{ |
| 20 | {"INSERT INTO chat_projects(id,repo,state,revision,copy_revision) VALUES ('copy-project','amadan.net/oficina/sample','active',1,2)", nil}, |
| 21 | {"INSERT INTO chat_tasks(id,project_id,title,creator,stage,branch,base_sha,revision) VALUES ('tkcopy','copy-project','Copy',?,'in_review','equipo/tkcopy',?,1)", []any{p.Person, strings.Repeat("b", 40)}}, |
| 22 | {"INSERT INTO chat_steps(id,task_id,idx,specialist,person,state,pushed,candidate_sha) VALUES ('copy-eng','tkcopy',1,'engineering',?,'done',1,?)", []any{p.Person, strings.Repeat("a", 40)}}, |
| 23 | {"INSERT INTO chat_steps(id,task_id,idx,specialist,person,state,placement,copy_owner,copy_revision,candidate_sha,attempt) VALUES ('copy-step','tkcopy',2,'copy',?,'queued','waiting_runner',?,1,?,1)", []any{p.Person, p.Person, strings.Repeat("a", 40)}}, |
| 24 | } { |
| 25 | if err := r.inst.DB.G.Exec(q.sql, q.args...).Error; err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | } |
| 29 | _, err = r.inst.Store.Chat().Connect(r.ctx, chat.RunnerPrincipal{RunnerID: p.RunnerID, Person: p.Person, CredentialID: p.CredentialID}, "copy-reconnect", wire.Hello{Protocol: wire.ProtocolCopy}, "") |
| 30 | if err != nil { |
| 31 | t.Fatal("revoked Copy locked runner out:", err) |
| 32 | } |
| 33 | var state string |
| 34 | if err := r.inst.DB.G.Raw("SELECT state FROM chat_steps WHERE id='copy-step'").Scan(&state).Error; err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | if state == wire.StepQueued { |
| 38 | t.Fatal("revoked Copy not withdrawn") |
| 39 | } |
| 40 | } |
| 41 | |