Skip to content

Commit 1cf2469

Browse files
Merge pull request #790 from rgardler-msft/wl-0MM8V5GTH06V9Z0P-realistic-mock
WL-0MM8V5GTH06V9Z0P: Make delegate mock destructive and add preservation test
2 parents 0442187 + 59edf3b commit 1cf2469

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/cli/delegate-guard-rails.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ function createDelegateTestContext() {
122122
getAllComments: () => comments,
123123
getChildren: (parentId: string) => Array.from(items.values()).filter(i => i.parentId === parentId),
124124
getDescendants: (parentId: string) => Array.from(items.values()).filter(i => i.parentId === parentId),
125+
// Mirrors real db.import() destructive semantics: DELETE all items then
126+
// re-insert only the provided set. This ensures mock-based tests would
127+
// catch data-loss bugs if code mistakenly calls import() with a partial
128+
// item set instead of upsertItems().
125129
import: (updatedItems: any[]) => {
130+
items.clear();
126131
for (const item of updatedItems) {
127132
items.set(item.id, item);
128133
}
@@ -411,4 +416,30 @@ describe('delegate subcommand guard rails', () => {
411416
expect(assignError!.data.assigned).toBe(false);
412417
expect(assignError!.data.error).toBe('forbidden');
413418
});
419+
420+
it('preserves non-delegated items after successful delegation', async () => {
421+
// Create multiple items — only one will be delegated
422+
t.makeItem({ id: 'WL-KEEP-1', title: 'Unrelated epic', githubIssueNumber: 200 });
423+
t.makeItem({ id: 'WL-KEEP-2', title: 'Unrelated bug', githubIssueNumber: 201 });
424+
t.makeItem({ id: 'WL-TARGET', title: 'Delegate target', githubIssueNumber: 202 });
425+
426+
await t.runDelegate('WL-TARGET');
427+
428+
// The delegated item should be updated
429+
const target = t.db.get('WL-TARGET');
430+
expect(target).toBeDefined();
431+
expect(target.status).toBe('in-progress');
432+
expect(target.assignee).toBe('@github-copilot');
433+
434+
// Non-delegated items MUST still exist.
435+
// With the realistic destructive db.import mock, this test would fail
436+
// if the code called db.import() instead of db.upsertItems().
437+
const keep1 = t.db.get('WL-KEEP-1');
438+
expect(keep1, 'WL-KEEP-1 should survive delegation of another item').toBeDefined();
439+
expect(keep1.title).toBe('Unrelated epic');
440+
441+
const keep2 = t.db.get('WL-KEEP-2');
442+
expect(keep2, 'WL-KEEP-2 should survive delegation of another item').toBeDefined();
443+
expect(keep2.title).toBe('Unrelated bug');
444+
});
414445
});

0 commit comments

Comments
 (0)