package thintest import ( "amadan.net/oficina/equipo/internal/equipo/chat" "amadan.net/oficina/equipo/internal/wire" "strings" "testing" ) func TestCopyRevokedDelegationDoesNotLockRunner(t *testing.T) { r := newRig(t) p, err := r.inst.Store.AuthenticateRunner(r.ctx, r.runner) if err != nil { t.Fatal(err) } for _, q := range []struct { sql string args []any }{ {"INSERT INTO chat_projects(id,repo,state,revision,copy_revision) VALUES ('copy-project','amadan.net/oficina/sample','active',1,2)", nil}, {"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)}}, {"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)}}, {"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)}}, } { if err := r.inst.DB.G.Exec(q.sql, q.args...).Error; err != nil { t.Fatal(err) } } _, 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}, "") if err != nil { t.Fatal("revoked Copy locked runner out:", err) } var state string if err := r.inst.DB.G.Raw("SELECT state FROM chat_steps WHERE id='copy-step'").Scan(&state).Error; err != nil { t.Fatal(err) } if state == wire.StepQueued { t.Fatal("revoked Copy not withdrawn") } }