From 59edf3bccdab3df7b5498c06b649539068b991e4 Mon Sep 17 00:00:00 2001 From: rgardler-msft Date: Mon, 2 Mar 2026 00:06:45 -0800 Subject: [PATCH] WL-0MM8V5GTH06V9Z0P: Make delegate mock destructive and add preservation test - Update db.import mock in createDelegateTestContext() to clear items before re-inserting, matching real db.import() semantics - Add test verifying non-delegated items survive delegation - This test would fail if upsertItems() were reverted to import() --- tests/cli/delegate-guard-rails.test.ts | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/cli/delegate-guard-rails.test.ts b/tests/cli/delegate-guard-rails.test.ts index a78f3a3..8e1757c 100644 --- a/tests/cli/delegate-guard-rails.test.ts +++ b/tests/cli/delegate-guard-rails.test.ts @@ -122,7 +122,12 @@ function createDelegateTestContext() { getAllComments: () => comments, getChildren: (parentId: string) => Array.from(items.values()).filter(i => i.parentId === parentId), getDescendants: (parentId: string) => Array.from(items.values()).filter(i => i.parentId === parentId), + // Mirrors real db.import() destructive semantics: DELETE all items then + // re-insert only the provided set. This ensures mock-based tests would + // catch data-loss bugs if code mistakenly calls import() with a partial + // item set instead of upsertItems(). import: (updatedItems: any[]) => { + items.clear(); for (const item of updatedItems) { items.set(item.id, item); } @@ -411,4 +416,30 @@ describe('delegate subcommand guard rails', () => { expect(assignError!.data.assigned).toBe(false); expect(assignError!.data.error).toBe('forbidden'); }); + + it('preserves non-delegated items after successful delegation', async () => { + // Create multiple items — only one will be delegated + t.makeItem({ id: 'WL-KEEP-1', title: 'Unrelated epic', githubIssueNumber: 200 }); + t.makeItem({ id: 'WL-KEEP-2', title: 'Unrelated bug', githubIssueNumber: 201 }); + t.makeItem({ id: 'WL-TARGET', title: 'Delegate target', githubIssueNumber: 202 }); + + await t.runDelegate('WL-TARGET'); + + // The delegated item should be updated + const target = t.db.get('WL-TARGET'); + expect(target).toBeDefined(); + expect(target.status).toBe('in-progress'); + expect(target.assignee).toBe('@github-copilot'); + + // Non-delegated items MUST still exist. + // With the realistic destructive db.import mock, this test would fail + // if the code called db.import() instead of db.upsertItems(). + const keep1 = t.db.get('WL-KEEP-1'); + expect(keep1, 'WL-KEEP-1 should survive delegation of another item').toBeDefined(); + expect(keep1.title).toBe('Unrelated epic'); + + const keep2 = t.db.get('WL-KEEP-2'); + expect(keep2, 'WL-KEEP-2 should survive delegation of another item').toBeDefined(); + expect(keep2.title).toBe('Unrelated bug'); + }); });