Track running Granthi review queue jobs

This commit is contained in:
Claude
2026-08-21 18:04:35 -04:00
parent 10bbd598f3
commit c648a5a6da
3 changed files with 35 additions and 3 deletions
+14 -1
View File
@@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { openDb, enqueueJob, finishJob, recoverPendingJobs } from '../src/lib/db.js';
import { openDb, enqueueJob, startJob, finishJob, recoverPendingJobs } from '../src/lib/db.js';
const JOB = (over = {}) => ({
event: 'push', owner: 'nirpa', repo: 'demo', sha: 'a'.repeat(40),
@@ -32,6 +32,19 @@ test('finished jobs are not recovered again', () => {
assert.equal(recoverPendingJobs(db).length, 0);
});
test('running jobs are visible and recovered on startup', () => {
const db = openDb(':memory:');
const id = enqueueJob(db, JOB({ sha: '4'.repeat(40) }));
startJob(db, id);
const row = db.prepare(`SELECT state, started_ts FROM queue_jobs WHERE id = ?`).get(id);
assert.equal(row.state, 'running');
assert.match(row.started_ts, /^\d{4}-\d{2}-\d{2}T/);
const pending = recoverPendingJobs(db);
assert.deepEqual(pending.map(p => p.id), [id]);
});
test('unparseable persisted job is marked done, not re-run forever', () => {
const db = openDb(':memory:');
db.prepare(`INSERT INTO queue_jobs (repo, sha, job) VALUES ('a/b', 'c', '{broken')`).run();