mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-30 17:14:40 +08:00
fix(agent-manager): read project ownership once per PR error
This commit is contained in:
@@ -69,11 +69,7 @@ export class PRStatusBridge {
|
||||
replay(): void {
|
||||
this.cache.forEach((msg) => this.host.postToWebview(msg))
|
||||
if (this.lastErrorNotified === "gh_auth" || this.lastErrorNotified === "gh_missing")
|
||||
this.host.postToWebview({
|
||||
type: "agentManager.prError",
|
||||
error: this.lastErrorNotified,
|
||||
...(this.host.projectId?.() ? { projectId: this.host.projectId() } : {}),
|
||||
})
|
||||
this.error(this.lastErrorNotified)
|
||||
}
|
||||
|
||||
snapshot(): Map<string, PRStatus> {
|
||||
@@ -160,10 +156,15 @@ export class PRStatusBridge {
|
||||
notifyError(err: "gh_missing" | "gh_auth" | "fetch_failed"): void {
|
||||
if (this.lastErrorNotified === err) return
|
||||
this.lastErrorNotified = err
|
||||
this.error(err)
|
||||
}
|
||||
|
||||
private error(err: "gh_missing" | "gh_auth" | "fetch_failed"): void {
|
||||
const project = this.host.projectId?.()
|
||||
this.host.postToWebview({
|
||||
type: "agentManager.prError",
|
||||
error: err,
|
||||
...(this.host.projectId?.() ? { projectId: this.host.projectId() } : {}),
|
||||
...(project ? { projectId: project } : undefined),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ const pr: PRStatus = {
|
||||
function harness(opts: { hasPersisted?: boolean; projectId?: string } = {}) {
|
||||
const sent: AgentManagerOutMessage[] = []
|
||||
const opened: string[] = []
|
||||
const reads: (string | undefined)[] = []
|
||||
const worktrees: { id: string; path: string; branch: string; prUrl?: string }[] = [
|
||||
{ id: "wt1", path: "/repo/wt1", branch: "feature" },
|
||||
]
|
||||
@@ -35,10 +36,13 @@ function harness(opts: { hasPersisted?: boolean; projectId?: string } = {}) {
|
||||
hasPersistedPR: () => opts.hasPersisted ?? false,
|
||||
openExternal: (url) => opened.push(url),
|
||||
log: () => {},
|
||||
projectId: () => opts.projectId,
|
||||
projectId: () => {
|
||||
reads.push(opts.projectId)
|
||||
return opts.projectId
|
||||
},
|
||||
})
|
||||
const onStatus = (bridge.poller as unknown as { options: { onStatus: (...a: unknown[]) => void } }).options.onStatus
|
||||
return { bridge, sent, opened, onStatus, worktrees }
|
||||
return { bridge, sent, opened, onStatus, worktrees, reads }
|
||||
}
|
||||
|
||||
describe("PRStatusBridge.handleMessage openPR", () => {
|
||||
@@ -76,9 +80,10 @@ describe("PRStatusBridge.notifyError", () => {
|
||||
})
|
||||
|
||||
it("tags errors with their owning project", () => {
|
||||
const { bridge, sent } = harness({ projectId: "project-a" })
|
||||
const { bridge, sent, reads } = harness({ projectId: "project-a" })
|
||||
bridge.notifyError("gh_missing")
|
||||
expect(sent).toEqual([{ type: "agentManager.prError", projectId: "project-a", error: "gh_missing" }])
|
||||
expect(reads).toEqual(["project-a"])
|
||||
})
|
||||
|
||||
it("deduplicates the same error type", () => {
|
||||
@@ -207,11 +212,13 @@ describe("PRStatusBridge.replay", () => {
|
||||
})
|
||||
|
||||
it("preserves project ownership when replaying an error", () => {
|
||||
const { bridge, sent, onStatus } = harness({ projectId: "project-a" })
|
||||
const { bridge, sent, onStatus, reads } = harness({ projectId: "project-a" })
|
||||
onStatus("wt1", null, "gh_missing")
|
||||
sent.length = 0
|
||||
reads.length = 0
|
||||
bridge.replay()
|
||||
expect(sent).toEqual([{ type: "agentManager.prError", projectId: "project-a", error: "gh_missing" }])
|
||||
expect(reads).toEqual(["project-a"])
|
||||
})
|
||||
|
||||
it("does not replay fetch_failed errors", () => {
|
||||
|
||||
Reference in New Issue
Block a user