Prevent stale approval buttons

This commit is contained in:
Codex
2026-05-24 03:23:58 +00:00
parent fd80780581
commit e85d0eb928
4 changed files with 91 additions and 9 deletions
+2 -4
View File
@@ -460,10 +460,8 @@ INSERT INTO pending_approvals (
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending')
ON CONFLICT(telegram_user_id, codex_request_id) DO UPDATE SET
payload_json = excluded.payload_json,
message_chat_id = excluded.message_chat_id,
message_id = excluded.message_id,
status = 'pending',
resolved_at = ''`,
message_chat_id = CASE WHEN pending_approvals.status = 'pending' THEN excluded.message_chat_id ELSE pending_approvals.message_chat_id END,
message_id = CASE WHEN pending_approvals.status = 'pending' THEN excluded.message_id ELSE pending_approvals.message_id END`,
approval.TelegramUserID, approval.CodexRequestID, approval.CodexThreadID, approval.TurnID,
approval.ItemID, approval.Kind, approval.PayloadJSON, approval.MessageChatID, approval.MessageID)
if err != nil {
+51
View File
@@ -192,6 +192,57 @@ func TestRenameThread(t *testing.T) {
}
}
func TestUpsertPendingApprovalDoesNotReopenResolved(t *testing.T) {
ctx := context.Background()
st, err := Open(ctx, filepath.Join(t.TempDir(), "bot.db"))
if err != nil {
t.Fatal(err)
}
defer st.Close()
first, err := st.UpsertPendingApproval(ctx, PendingApproval{
TelegramUserID: 42,
CodexRequestID: "request-1",
CodexThreadID: "thread-1",
Kind: "item/commandExecution/requestApproval",
PayloadJSON: `{"command":"go test ./..."}`,
})
if err != nil {
t.Fatal(err)
}
if err := st.UpdatePendingApprovalMessage(ctx, first.ID, 1001, 2002); err != nil {
t.Fatal(err)
}
if err := st.ResolvePendingApproval(ctx, 42, first.ID, "accept"); err != nil {
t.Fatal(err)
}
second, err := st.UpsertPendingApproval(ctx, PendingApproval{
TelegramUserID: 42,
CodexRequestID: "request-1",
CodexThreadID: "thread-1",
Kind: "item/commandExecution/requestApproval",
PayloadJSON: `{"command":"go test ./...","duplicate":true}`,
MessageChatID: 3003,
MessageID: 4004,
})
if err != nil {
t.Fatal(err)
}
if second.ID != first.ID {
t.Fatalf("duplicate approval id = %d, want %d", second.ID, first.ID)
}
if second.Status != "accept" {
t.Fatalf("duplicate approval status = %q, want accept", second.Status)
}
if second.MessageChatID != 1001 || second.MessageID != 2002 {
t.Fatalf("resolved approval message changed: chat=%d message=%d", second.MessageChatID, second.MessageID)
}
if second.ResolvedAt == "" {
t.Fatal("resolved approval lost resolved_at")
}
}
func TestValidateWorkspacePath(t *testing.T) {
if _, err := ValidateWorkspacePath("relative/path"); err == nil {
t.Fatal("relative path should be rejected")