Skip to content

Commit 315e53d

Browse files
Clarify pending sync completion names
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4dc1f23 commit 315e53d

3 files changed

Lines changed: 36 additions & 36 deletions

File tree

packages/code-link-cli/src/controller.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { tryGitInit } from "./helpers/git.ts"
2727
import { Installer } from "./helpers/installer.ts"
2828
import { initWatcher } from "./helpers/watcher.ts"
29-
import { type ConflictPromptChange, type PendingSyncCompleteResult, SyncRuntime } from "./runtime.ts"
29+
import { type ConflictPromptChange, SyncRuntime } from "./runtime.ts"
3030
import type { Effect, SyncEvent, SyncState, WriteEchoPolicy } from "./sync-events.ts"
3131
import type { Config, Conflict, FileInfo } from "./types.ts"
3232
import {
@@ -805,7 +805,7 @@ async function applyConflictChange(change: ConflictPromptChange, ctx: ApplyCtx):
805805
async function applySyncComplete(effect: Extract<Effect, { type: "SYNC_COMPLETE" }>, ctx: ApplyCtx): Promise<void> {
806806
const { config, runtime, syncState, shutdown } = ctx
807807
if (runtime.hasAnyActivePrompt()) {
808-
runtime.addPendingSyncComplete({
808+
runtime.deferSyncComplete({
809809
totalCount: effect.totalCount,
810810
updatedCount: effect.updatedCount,
811811
unchangedCount: effect.unchangedCount,
@@ -841,12 +841,12 @@ async function applySyncComplete(effect: Extract<Effect, { type: "SYNC_COMPLETE"
841841
if (shouldShutdown) await shutdown()
842842
}
843843

844-
async function flushPendingSyncComplete(ctx: ApplyCtx): Promise<PendingSyncCompleteResult["is"]> {
845-
const result = ctx.runtime.checkPendingSyncComplete()
846-
if (result.is === "ready") {
844+
async function flushPendingSyncComplete(ctx: ApplyCtx): Promise<"ready" | "blocked" | "empty"> {
845+
const result = ctx.runtime.claimPendingSyncComplete()
846+
if (result.status === "ready") {
847847
await applySyncComplete({ type: "SYNC_COMPLETE", ...result.payload }, ctx)
848848
}
849-
return result.is
849+
return result.status
850850
}
851851

852852
export async function applyEffect(effect: Effect, ctx: ApplyCtx): Promise<SyncEvent[]> {

packages/code-link-cli/src/runtime.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ describe("SyncRuntime pending sync-complete", () => {
123123
it("returns empty when no sync-complete is pending", () => {
124124
const runtime = new SyncRuntime()
125125

126-
expect(runtime.checkPendingSyncComplete()).toEqual({ is: "empty" })
126+
expect(runtime.claimPendingSyncComplete()).toEqual({ status: "empty" })
127127
})
128128

129129
it("merges pending sync-complete payloads and clears them when ready", () => {
130130
const runtime = new SyncRuntime()
131-
runtime.addPendingSyncComplete({ totalCount: 1, updatedCount: 1, unchangedCount: 0 })
132-
runtime.addPendingSyncComplete({ totalCount: 2, updatedCount: 1, unchangedCount: 1 })
131+
runtime.deferSyncComplete({ totalCount: 1, updatedCount: 1, unchangedCount: 0 })
132+
runtime.deferSyncComplete({ totalCount: 2, updatedCount: 1, unchangedCount: 1 })
133133

134-
expect(runtime.checkPendingSyncComplete()).toEqual({
135-
is: "ready",
134+
expect(runtime.claimPendingSyncComplete()).toEqual({
135+
status: "ready",
136136
payload: { totalCount: 3, updatedCount: 2, unchangedCount: 1 },
137137
})
138-
expect(runtime.checkPendingSyncComplete()).toEqual({ is: "empty" })
138+
expect(runtime.claimPendingSyncComplete()).toEqual({ status: "empty" })
139139
})
140140

141141
it("keeps pending sync-complete blocked while prompts are active", () => {
@@ -144,12 +144,12 @@ describe("SyncRuntime pending sync-complete", () => {
144144
const prompt = runtime.startDeletePrompt(["A.tsx"])
145145
if (!prompt) throw new Error("Expected delete prompt")
146146

147-
runtime.addPendingSyncComplete({ totalCount: 1, updatedCount: 1, unchangedCount: 0 })
147+
runtime.deferSyncComplete({ totalCount: 1, updatedCount: 1, unchangedCount: 0 })
148148

149-
expect(runtime.checkPendingSyncComplete()).toEqual({ is: "blocked" })
149+
expect(runtime.claimPendingSyncComplete()).toEqual({ status: "blocked" })
150150
runtime.clearDeletePromptFiles(prompt.session, ["A.tsx"])
151-
expect(runtime.checkPendingSyncComplete()).toEqual({
152-
is: "ready",
151+
expect(runtime.claimPendingSyncComplete()).toEqual({
152+
status: "ready",
153153
payload: { totalCount: 1, updatedCount: 1, unchangedCount: 0 },
154154
})
155155
})

packages/code-link-cli/src/runtime.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ interface DeletePromptState {
2323
fileNames: Set<string>
2424
}
2525

26-
interface DeferredSyncComplete {
26+
export interface PendingSyncCompletionEvent {
2727
totalCount: number
2828
updatedCount: number
2929
unchangedCount: number
3030
}
3131

32-
export type PendingSyncCompleteResult =
33-
| { is: "ready"; payload: DeferredSyncComplete }
34-
| { is: "blocked" }
35-
| { is: "empty" }
32+
type ClaimPendingSyncCompleteResult =
33+
| { status: "ready"; payload: PendingSyncCompletionEvent }
34+
| { status: "blocked" }
35+
| { status: "empty" }
3636

3737
interface ConflictPromptState {
3838
session: PromptSession
@@ -99,7 +99,7 @@ export class SyncRuntime {
9999

100100
private activeDeletePrompt: DeletePromptState | null = null
101101
private activeConflictPrompt: ConflictPromptState | null = null
102-
private pendingSyncComplete: DeferredSyncComplete | null = null
102+
private pendingSyncCompletionEvent: PendingSyncCompletionEvent | null = null
103103

104104
installer: Installer | null = null
105105

@@ -248,29 +248,29 @@ export class SyncRuntime {
248248
return this.activeDeletePrompt !== null || this.activeConflictPrompt !== null
249249
}
250250

251-
addPendingSyncComplete(syncComplete: DeferredSyncComplete): void {
252-
this.pendingSyncComplete =
253-
this.pendingSyncComplete === null
251+
deferSyncComplete(syncComplete: PendingSyncCompletionEvent): void {
252+
this.pendingSyncCompletionEvent =
253+
this.pendingSyncCompletionEvent === null
254254
? syncComplete
255255
: {
256-
totalCount: this.pendingSyncComplete.totalCount + syncComplete.totalCount,
257-
updatedCount: this.pendingSyncComplete.updatedCount + syncComplete.updatedCount,
258-
unchangedCount: this.pendingSyncComplete.unchangedCount + syncComplete.unchangedCount,
256+
totalCount: this.pendingSyncCompletionEvent.totalCount + syncComplete.totalCount,
257+
updatedCount: this.pendingSyncCompletionEvent.updatedCount + syncComplete.updatedCount,
258+
unchangedCount: this.pendingSyncCompletionEvent.unchangedCount + syncComplete.unchangedCount,
259259
}
260260
}
261261

262262
/**
263-
* Reads the pending sync-complete and clears it when ready to fire.
263+
* Claims the pending sync-complete event and clears it when ready to fire.
264264
* - `ready`: payload is returned and the slot is cleared.
265265
* - `blocked`: payload remains pending until prompts clear.
266266
* - `empty`: nothing was pending.
267267
*/
268-
checkPendingSyncComplete(): PendingSyncCompleteResult {
269-
if (this.pendingSyncComplete === null) return { is: "empty" }
270-
if (this.hasAnyActivePrompt()) return { is: "blocked" }
271-
const syncComplete = this.pendingSyncComplete
272-
this.pendingSyncComplete = null
273-
return { is: "ready", payload: syncComplete }
268+
claimPendingSyncComplete(): ClaimPendingSyncCompleteResult {
269+
if (this.pendingSyncCompletionEvent === null) return { status: "empty" }
270+
if (this.hasAnyActivePrompt()) return { status: "blocked" }
271+
const syncComplete = this.pendingSyncCompletionEvent
272+
this.pendingSyncCompletionEvent = null
273+
return { status: "ready", payload: syncComplete }
274274
}
275275

276276
invalidateDeletePromptPath(filePath: string): DeletePromptChange {
@@ -391,7 +391,7 @@ export class SyncRuntime {
391391
resetPrompts(): void {
392392
this.activeDeletePrompt = null
393393
this.activeConflictPrompt = null
394-
this.pendingSyncComplete = null
394+
this.pendingSyncCompletionEvent = null
395395
}
396396

397397
cleanupUserActions(): void {

0 commit comments

Comments
 (0)