Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/kilo-vscode/tests/unit/comments-github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,19 @@ describe("postAllGithub", () => {
expect(result.posted.map((item) => item.id)).toEqual(["first"])
expect(result.failure).toBe("boom")
})

it("treats a rejected send as the first failure and keeps the unposted comments", async () => {
const sent: string[] = []
const result = await postAllGithub(
[comment("first", 2), comment("second", 1), comment("third", 1)],
fake((item) => {
sent.push(item.id)
if (item.id === "second") throw new Error("network down")
return { success: true }
}),
)
expect(sent).toEqual(["first", "second"])
expect(result.posted.map((item) => item.id)).toEqual(["first"])
expect(result.failure).toBe("network down")
})
})
9 changes: 9 additions & 0 deletions packages/kilo-vscode/tests/unit/use-file-mention.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2412,4 +2412,13 @@ describe("useFileMention reference drops", () => {
expect(area.value).toBe("")
})
})

it("reports a drop as unhandled when the editor does not apply the insert", () => {
withMention("", undefined, (mention, area) => {
// execCommand can silently no-op; the textarea stays unchanged.
globalThis.document.execCommand = () => false
expect(mention.insertDrop({ kind: "terminal" }, area, () => {}, "")).toBe(false)
expect(area.value).toBe("")
})
})
})
11 changes: 9 additions & 2 deletions packages/kilo-vscode/webview-ui/diff-viewer/comments-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export function createCommentsGithub(opts: Options): CommentsGithub {
})
}

const send = (comment: ReviewComment) => {
// async so a synchronous throw while building the request becomes a rejection
// that postAllGithub can report instead of escaping the per-comment loop.
const send = async (comment: ReviewComment) => {
const { promise, resolve: settle } = Promise.withResolvers<{ success: boolean; error?: string }>()
const target = opts.target()
const context = resolve(comment)
Expand Down Expand Up @@ -122,7 +124,12 @@ export async function postAllGithub(
): Promise<{ posted: ReviewComment[]; failure?: string }> {
const posted: ReviewComment[] = []
for (const comment of comments) {
const result = await github.send(comment)
// A rejected send is a failed request too. Convert it into a result so the
// batch stops at the first failure and the caller can clear its pending state.
const result = await github.send(comment).then(
Comment thread
marius-kilocode marked this conversation as resolved.
(value) => value,
(error: unknown) => ({ success: false, error: error instanceof Error ? error.message : String(error) }),
)
if (!result.success) return { posted, failure: result.error }
posted.push(comment)
}
Expand Down
5 changes: 4 additions & 1 deletion packages/kilo-vscode/webview-ui/src/hooks/useFileMention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,10 @@ export function useFileMention(
setText(textarea.value)
closeMention()
onSelect?.()
return true
// execCommand can silently no-op when the editor is not editable. Report the
// drop as unhandled when the text did not change so callers do not treat a
// failed insert as a consumed drag.
return textarea.value !== val
}

const insertDrop = (
Expand Down
Loading