import assert from 'node:assert/strict' import { test } from 'node:test' import { compareWorkItems, parsePriorityLabel, rankOf } from './priority-queue.ts' import type { WorkItem } from './work-item.ts' test('rankOf orders P0 needs-kent first', () => { assert.equal(rankOf(0, true), 0) assert.equal(rankOf(0, false), 1) assert.ok(rankOf(0, false) < rankOf(1, true)) assert.ok(rankOf(null, false) > rankOf(3, false)) }) test('parsePriorityLabel', () => { const a = parsePriorityLabel(['bug', 'P1', 'needs-kent']) assert.equal(a.priority, 1) assert.equal(a.needsKent, true) }) test('compareWorkItems uses rank then createdAt', () => { const base = { projectId: 'kody', title: 't', body: '', state: 'intake' as const, needsKent: false, source: 'manual', externalId: null, fingerprint: 'f', signalIds: [], labels: [], repoRef: null, planCardId: null, runId: null, updatedAt: '2026-01-01T00:00:00.000Z', events: [], shadow: true, } const a: WorkItem = { ...base, id: 'a', priority: 0, rank: rankOf(0, false), createdAt: '2026-01-02T00:00:00.000Z', } const b: WorkItem = { ...base, id: 'b', priority: 0, rank: rankOf(0, false), createdAt: '2026-01-01T00:00:00.000Z', } assert.ok(compareWorkItems(b, a) < 0) })