Qualify the role permission version upsert and wait for the second HITL card #246

Merged
weichen merged 1 commits from fix/pg-role-policy-version-and-hitl-wait into main 2026-10-22 06:42:24 +00:00
2 changed files with 19 additions and 1 deletions
+18
View File
@@ -217,6 +217,24 @@ func TestResolveHITLSecondRoundKeepsTerminalStatus(t *testing.T) {
case <-time.After(10 * time.Second):
t.Fatal("runner did not reach the second HITL question")
}
// asked 只保证 runner 已经发出提问,不保证 waiting_hitl 行与卡片都已落库;
// 与第 1 轮同一序列:等 run 处于 waiting_hitl 且存在未解决卡片后再读取。
waitUntilWithin(t, 10*time.Second, func() bool {
got, err := st.GetRunByID(run.ID)
if err != nil || got.Status != core.RunWaitingHITL {
return false
}
cards, err := st.ActiveHITLCards(conv.Owner, conv.ID)
if err != nil {
return false
}
for _, c := range cards {
if !c.Resolved {
return true
}
}
return false
})
second := pendingCard(t, st, conv, 1)
if got, err := st.GetRunByID(run.ID); err != nil || got.Status != core.RunWaitingHITL {
t.Fatalf("round 2 status=%s err=%v (want waiting_hitl)", got.Status, err)
+1 -1
View File
@@ -2252,7 +2252,7 @@ func (s *Store) upsertRolePermissionsTx(tx *sql.Tx, actorID, roleID string, curr
for _, row := range writes {
if _, err := tx.Exec(s.q(`INSERT INTO role_permissions(role_id,action_id,allowed,cap_allowed,permission_version,updated_by,updated_at)
VALUES(?,?,?,?,?,?,?) ON CONFLICT(role_id,action_id) DO UPDATE SET allowed=excluded.allowed,cap_allowed=excluded.cap_allowed,
permission_version=permission_version+1,updated_by=excluded.updated_by,updated_at=excluded.updated_at`),
permission_version=role_permissions.permission_version+1,updated_by=excluded.updated_by,updated_at=excluded.updated_at`),
roleID, row.ActionID, row.Allowed, row.CapAllowed, 1, actorID, now); err != nil {
return err
}