Summary
Replace all three destructive db.import(partialItems) calls in src/commands/github.ts (delegate line 529, push line 150, import-then-push line 362) with the new db.upsertItems(), and explicitly preserve dependency edges.
User Story
As an operator using wl gh delegate, wl gh push, or wl gh import, I want these commands to only update the items they process without deleting my other work items, so that my worklog remains intact.
Acceptance Criteria
- Running
wl gh delegate <id> does not delete or modify any work items other than the delegated one.
- Running
wl gh push (with or without --all) does not delete items excluded from the push batch.
- Running
wl gh import --create-new followed by re-push does not delete items not in the re-push batch.
- Dependency edges for non-affected items are preserved after each operation.
- Comments for non-affected items remain intact and correctly linked.
- The JSONL export after each operation contains all pre-existing work items (same count and IDs as before the operation), comments, and dependency edges.
- The dead
const items = db.getAll() at line 520 is cleaned up (removed or repurposed).
- Existing delegate, push, and import tests continue to pass.
- CLI flags and output format are unchanged (backward compatible).
- Reverting the fix (replacing
upsertItems back with import) causes the new integration tests to fail.
Minimal Implementation
- Replace
db.import(updatedItems) at line 529 with db.upsertItems(updatedItems), passing dependency edges for the delegated item.
- Replace
db.import(updatedItems) at line 150 with db.upsertItems(updatedItems).
- Replace
db.import(markedItems) at line 362 with db.upsertItems(markedItems).
- Clean up the unused
const items = db.getAll() at line 520 if no longer needed.
- Add integration tests using a real SQLite database for delegate, push, and import-then-push scenarios:
- Each test creates multiple work items with comments and dependency edges.
- Performs the operation on a subset.
- Asserts all non-affected items, comments, and edges are intact.
- Does NOT mock
db.import — exercises the real code path.
Key Files
src/commands/github.ts:529 — delegate flow (primary bug)
src/commands/github.ts:150 — push flow (same pattern)
src/commands/github.ts:362 — import-then-push flow (same pattern)
src/commands/github.ts:520 — dead code to clean up
tests/cli/delegate-guard-rails.test.ts — existing tests (must continue passing)
Dependencies
- Feature 1: Add non-destructive db.upsertItems() API (WL-0MM8V4UPC02YMFXK)
Deliverables
- Source changes in
src/commands/github.ts
- Integration tests for delegate, push, and import-then-push scenarios
Summary
Replace all three destructive
db.import(partialItems)calls insrc/commands/github.ts(delegate line 529, push line 150, import-then-push line 362) with the newdb.upsertItems(), and explicitly preserve dependency edges.User Story
As an operator using
wl gh delegate,wl gh push, orwl gh import, I want these commands to only update the items they process without deleting my other work items, so that my worklog remains intact.Acceptance Criteria
wl gh delegate <id>does not delete or modify any work items other than the delegated one.wl gh push(with or without--all) does not delete items excluded from the push batch.wl gh import --create-newfollowed by re-push does not delete items not in the re-push batch.const items = db.getAll()at line 520 is cleaned up (removed or repurposed).upsertItemsback withimport) causes the new integration tests to fail.Minimal Implementation
db.import(updatedItems)at line 529 withdb.upsertItems(updatedItems), passing dependency edges for the delegated item.db.import(updatedItems)at line 150 withdb.upsertItems(updatedItems).db.import(markedItems)at line 362 withdb.upsertItems(markedItems).const items = db.getAll()at line 520 if no longer needed.db.import— exercises the real code path.Key Files
src/commands/github.ts:529— delegate flow (primary bug)src/commands/github.ts:150— push flow (same pattern)src/commands/github.ts:362— import-then-push flow (same pattern)src/commands/github.ts:520— dead code to clean uptests/cli/delegate-guard-rails.test.ts— existing tests (must continue passing)Dependencies
Deliverables
src/commands/github.ts