From 69a46925ee27f8515f0031b1da997576547aaa3e Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Thu, 29 Oct 2026 12:22:28 +0800 Subject: [PATCH] test(work-items): cover automatic ready-only pickup --- tests/scripts/work-items.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/scripts/work-items.test.js b/tests/scripts/work-items.test.js index 34ea947de..dd1a29c76 100644 --- a/tests/scripts/work-items.test.js +++ b/tests/scripts/work-items.test.js @@ -149,6 +149,34 @@ async function run() { } }); + await test('automatic claim skips higher-priority unready work and picks READY', async () => { + const setup = await createStateStore({ dbPath }); + try { + setup.upsertWorkItem({ id: 'wi-unassigned-high', source: 'manual', title: 'Needs review', status: 'needs-review', priority: 'critical', owner: null, metadata: {} }); + setup.upsertWorkItem({ id: 'wi-unassigned-low', source: 'manual', title: 'Blocked', status: 'blocked', priority: 'high', owner: null, metadata: {} }); + setup.upsertWorkItem({ id: 'wi-auto-blocked-high', source: 'manual', title: 'High priority blocked', status: 'blocked', priority: 'critical', owner: null, metadata: {} }); + setup.upsertWorkItem({ id: 'wi-auto-ready-low', source: 'manual', title: 'Low priority READY', status: 'ready', priority: 'low', owner: null, metadata: {} }); + } finally { setup.close(); } + const result = runClaim(dbPath, ['--owner', 'auto-worker', '--as', 'agent']); + assert.strictEqual(result.status, 0, result.stderr); + const payload = JSON.parse(result.stdout); + assert.strictEqual(payload.claimed, true); + assert.strictEqual(payload.item.id, 'wi-auto-ready-low'); + assert.strictEqual(payload.item.status, 'running'); + }); + + await test('automatic claim returns empty when all unowned items are unready', async () => { + const setup = await createStateStore({ dbPath }); + try { + setup.upsertWorkItem({ id: 'wi-unassigned-high', source: 'manual', title: 'Needs review', status: 'needs-review', priority: 'critical', owner: null, metadata: {} }); + setup.upsertWorkItem({ id: 'wi-unassigned-low', source: 'manual', title: 'Hold', status: 'hold', priority: 'high', owner: null, metadata: {} }); + } finally { setup.close(); } + const result = runClaim(dbPath, ['--owner', 'auto-worker', '--as', 'agent']); + assert.strictEqual(result.status, 0, result.stderr); + const payload = JSON.parse(result.stdout); + assert.deepStrictEqual(payload, { claimed: false, reason: 'no-unassigned-open-items' }); + }); + await test('claim accepts an explicitly ready item', async () => { const setup = await createStateStore({ dbPath }); try { setup.upsertWorkItem({ id: 'wi-explicit-ready', source: 'manual', title: 'Approved', status: 'ready', owner: null, metadata: {} }); }