Skip to content

Fix destructive db.import() in GitHub flows #911

@SorraTheOrc

Description

@SorraTheOrc

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions