Skip to content

WL-0MM8V55PV1Q32K7D: Fix destructive db.import() in GitHub flows#789

Merged
rgardler-msft merged 1 commit intomainfrom
wl-0MM8V55PV1Q32K7D-fix-destructive-import
Mar 2, 2026
Merged

WL-0MM8V55PV1Q32K7D: Fix destructive db.import() in GitHub flows#789
rgardler-msft merged 1 commit intomainfrom
wl-0MM8V55PV1Q32K7D-fix-destructive-import

Conversation

@rgardler-msft
Copy link
Copy Markdown
Owner

Summary

  • Replace all 4 destructive db.import() calls in src/commands/github.ts with the non-destructive db.upsertItems() API (added in PR WL-0MM8V4UPC02YMFXK: Add non-destructive db.upsertItems() API #788)
  • Fixes critical data-loss bug where wl gh delegate, wl gh push, and wl gh import could wipe all local work items when called with partial item sets
  • Removes dead const items = db.getAll() in the delegate flow (line 520)

Changes

Source (src/commands/github.ts)

  • Push flow (line 150): db.import(updatedItems) -> db.upsertItems(updatedItems)
  • Import flow (line 338): db.import(mergedItems) -> db.upsertItems(mergedItems)
  • Import-then-push flow (line 362): db.import(markedItems) -> db.upsertItems(markedItems)
  • Delegate flow (line 528): db.import(updatedItems) -> db.upsertItems(updatedItems), removed unused db.getAll() call

Tests

  • tests/cli/delegate-guard-rails.test.ts: Added upsertItems method to mock db object
  • tests/integration/github-upsert-preservation.test.ts (new): 9 integration tests using real SQLite:
    • Delegate: upserting a single item preserves all other items, comments, and edges
    • Push: upserting a batch preserves non-pushed items
    • Import-then-push: upserting merged items preserves unrelated items
    • Edge preservation when upserted item is an endpoint
    • New edge addition via upsert
    • Comment preservation on non-upserted items
    • JSONL roundtrip integrity after upsert
    • Multiple sequential upserts preserve all data
    • Regression guard: proves db.import() with partial set destroys non-included items

Related Work Items

…ems() in all GitHub flows

Replace all 4 db.import() calls in src/commands/github.ts with
db.upsertItems() to prevent data loss when GitHub flows (push,
import, import-then-push, delegate) are called with partial item
sets. Remove dead db.getAll() call in delegate flow.

Add upsertItems to mock db in delegate-guard-rails tests.

Add 9 integration tests using real SQLite to verify that upserting
a subset preserves all non-affected items, comments, and dependency
edges. Includes a regression guard proving db.import() is destructive.
@rgardler-msft rgardler-msft merged commit 0442187 into main Mar 2, 2026
4 checks passed
@SorraTheOrc SorraTheOrc deleted the wl-0MM8V55PV1Q32K7D-fix-destructive-import branch March 10, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant