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

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")