import { test } from 'node:test'; import assert from 'node:assert/strict'; import { openDb } from '../src/lib/db.js'; import { runReview } from '../src/lib/review.js'; const HEAD = 'a'.repeat(40); test('an unavailable review posts success without hiding the failure', async () => { const statuses = []; const db = openDb(':memory:'); const gitea = { postStatus: async (_owner, _repo, _sha, body) => statuses.push(body), getCommitDiff: async () => { throw new Error('review service unavailable'); } }; const job = { owner: 'o', repo: 'r', sha: HEAD, before: null, prIndex: null, event: 'push', pusher: 'tester', authors: [], commitMessages: [] }; const result = await runReview({ cfg: { publicBaseUrl: 'https://reviews.example.test', maxDiffBytes: 1024, model: 'claude-cli/claude-sonnet-4-6', botUsername: 'reviewer' }, gitea, adminGitea: null, db, job, withGlobal: async (fn) => fn(), log: () => {} }); assert.equal(result.ok, false); assert.deepEqual(statuses.map(({ state }) => state), ['pending', 'success']); assert.equal(statuses[1].context, 'granthi-review'); assert.equal(statuses[1].description, 'review unavailable — diff fetch failed (not blocking)'); const persisted = db.prepare( 'SELECT status_state, error FROM reviews WHERE repo = ? AND sha = ?' ).get('o/r', HEAD); assert.equal(persisted.status_state, 'success'); assert.match(persisted.error, /review service unavailable/); });