fix: close project before deleting project row#2256
Conversation
Greptile SummaryFixes a race condition where
Confidence Score: 4/5The reordering is safe to merge; The core logic change is small and clearly correct. The new test validates the ordering for the mounted-project path, but leaves the unmounted path and error-return paths untested, so a future refactor could break those branches silently. src/main/core/projects/operations/deleteProject.test.ts — the unmounted-project and
|
| Filename | Overview |
|---|---|
| src/main/core/projects/operations/deleteProject.ts | Moves closeProject call from after the DB delete to before it, inside the mounted-project guard; the Result return value is still ignored (intentional). |
| src/main/core/projects/operations/deleteProject.test.ts | New test file that verifies closeProject is called before the DB delete using invocation-order comparison; only covers the mounted-project happy path. |
Sequence Diagram
sequenceDiagram
participant C as Caller
participant D as deleteProject()
participant PM as projectManager
participant TM as taskManager
participant VS as viewStateService
participant PR as prSyncEngine
participant DB as Database
C->>D: deleteProject(id)
D->>PM: getProject(id)
alt project is mounted
PM-->>D: provider (truthy)
D->>TM: teardownTask(t.id) [per task]
D->>VS: "del(task:{id}) [per task]"
Note over D: await Promise.allSettled(...)
D->>PM: closeProject(id) ← moved here
PM-->>D: "Result<void>"
else project not mounted
PM-->>D: undefined
end
D->>PR: deleteProjectData(id)
D->>DB: "DELETE projects WHERE id = ?"
D->>VS: "del(project:{id}) [fire-and-forget]"
D->>C: emit project:deleted
D->>C: capture telemetry
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
src/main/core/projects/operations/deleteProject.test.ts:74-79
**Missing test for unmounted project path**
The suite only exercises the branch where `getProject` returns a truthy provider. There is no test verifying that when `getProject` returns `undefined` the function still deletes the DB row and that `closeProject` is never called. A regression in the `if (provider)` guard (e.g. the call being hoisted out of the block by accident) would go undetected.
### Issue 2 of 2
src/main/core/projects/operations/deleteProject.test.ts:76-79
**Inconsistent non-null assertion on `invocationCallOrder`**
`mocks.closeProject.mock.invocationCallOrder[0]` is used without `!` while `mocks.deleteWhere.mock.invocationCallOrder[0]!` has one. TypeScript types both as `number | undefined`, so only one side is guarded. The `toBeLessThan` call would produce a confusing `undefined < number` failure message rather than a clear assertion error if `closeProject` were never called. Adding `!` (or a preceding `toBeDefined()` assertion) on the left side makes the intent explicit and symmetric.
Reviews (1): Last reviewed commit: "fix: close project before deleting proje..." | Re-trigger Greptile
No description provided.