Harden conversation replies and prioritize newest candidates
This commit is contained in:
1 parent
f98c5c732d
commit
b8e4a1bb88
23 files changed
+598
-113
No files matched your search
+41
-1
@@ -160,7 +160,7 @@ describe('Database Client', () => {
|
||||
DROP TABLE conversation_automation_claims;
|
||||
DROP TABLE ai_usage;
|
||||
`);
|
||||
db.pragma(`user_version = ${latestVersion - 5}`);
|
||||
db.pragma(`user_version = ${latestVersion - 6}`);
|
||||
runMigrations(db);
|
||||
|
||||
expect(db.prepare('SELECT recipient, reason FROM recipient_suppressions ORDER BY recipient COLLATE NOCASE').all())
|
||||
@@ -170,6 +170,46 @@ describe('Database Client', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('preserves pending reply claims when adding auditable superseded status', () => {
|
||||
runMigrations(db);
|
||||
const latestVersion = db.pragma('user_version', { simple: true }) as number;
|
||||
db.exec(`
|
||||
DROP TABLE conversation_automation_claims;
|
||||
CREATE TABLE conversation_automation_claims (
|
||||
account_id TEXT NOT NULL,
|
||||
conversation_id TEXT NOT NULL,
|
||||
incoming_key TEXT NOT NULL,
|
||||
status TEXT NOT NULL CHECK(status IN ('pending', 'sent')),
|
||||
claimed_at INTEGER NOT NULL,
|
||||
sent_at INTEGER,
|
||||
reply_text TEXT,
|
||||
incoming_at INTEGER,
|
||||
last_attempt_at INTEGER,
|
||||
attempt_count INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (account_id, conversation_id, incoming_key),
|
||||
FOREIGN KEY (account_id) REFERENCES reddit_accounts(account_id) ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO conversation_automation_claims (
|
||||
account_id, conversation_id, incoming_key, status, claimed_at,
|
||||
reply_text, incoming_at, last_attempt_at, attempt_count
|
||||
) VALUES (
|
||||
'__legacy_unassigned__', 'room', 'event', 'pending', 10,
|
||||
'durable reply', 5, 11, 1
|
||||
);
|
||||
`);
|
||||
db.pragma(`user_version = ${latestVersion - 1}`);
|
||||
|
||||
runMigrations(db);
|
||||
|
||||
expect(db.prepare(`
|
||||
SELECT status, reply_text, incoming_at, last_attempt_at, attempt_count, superseded_at
|
||||
FROM conversation_automation_claims
|
||||
`).get()).toEqual({
|
||||
status: 'pending', reply_text: 'durable reply', incoming_at: 5,
|
||||
last_attempt_at: 11, attempt_count: 1, superseded_at: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('processed_posts has correct schema', () => {
|
||||
runMigrations(db);
|
||||
const columns = db.prepare('PRAGMA table_info(processed_posts)').all() as { name: string; notnull: number }[];
|
||||
|
||||
Reference in new issue
Block a user