Files
kilocode/packages/kilo-vscode/tests/unit/agent-project-run-status-webview.test.ts
T
marius-kilocode 52447ed2af fix(agent-manager): scope run-script state to the owning project
The RunScriptManager keys entries by worktreeId and the webview sends
"local" for whichever project's local context is selected, so in
multi-project mode two projects' local runs collided in one entry: a
second project's Run button stopped the first project's script, and the
state payload spread every project's run statuses into the active
project's push, rendering foreign local rows as running.

The provider now namespaces the local key as <projectId>:local at the
message boundary (ambient project scope, no webview protocol change),
RunController treats the qualified suffix as a local run (repo root cwd,
"local" branch label), each project's state payload is filtered to its
own worktrees plus its un-namespaced local key, and runStatus emissions
are routed with a projectId stamp so background-project statuses land in
their own webview store. ScriptTerminalManager keys inherit the same
qualification, and its view mapping already namespaces run terminals to
the matching project bucket.
2026-07-30 17:50:04 +02:00

58 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "bun:test"
import { createRoot } from "solid-js"
import { applyRunStatus } from "../../webview-ui/agent-manager/project/run-status"
import { createProjectRegistry } from "../../webview-ui/agent-manager/project/registry"
const pending = (id: string) => id.startsWith("pending")
function setup(active: string) {
let id = active
const registry = createProjectRegistry({ persisted: {}, activeId: () => id })
return {
registry,
set: (next: string) => (id = next),
deps: { ensure: (pid: string) => registry.ensure(pid), active: () => registry.active() },
}
}
describe("applyRunStatus", () => {
it("routes project-stamped statuses to their own store", () =>
createRoot((dispose) => {
const { registry, set, deps } = setup("prj-a")
registry.ensure("prj-b")
expect(
applyRunStatus(
{ type: "agentManager.runStatus", worktreeId: "local", state: "running", projectId: "prj-b" },
deps,
),
).toBe(true)
expect(registry.ensure("prj-b").runStatuses()["local"]?.state).toBe("running")
expect(registry.active().runStatuses()["local"]).toBeUndefined()
set("prj-b")
expect(registry.active().runStatuses()["local"]?.state).toBe("running")
dispose()
}))
it("routes unstamped statuses to the active store (legacy behavior)", () =>
createRoot((dispose) => {
const { registry, deps } = setup("prj-a")
registry.ensure("prj-b")
expect(applyRunStatus({ type: "agentManager.runStatus", worktreeId: "local", state: "running" }, deps)).toBe(true)
expect(registry.active().runStatuses()["local"]?.state).toBe("running")
expect(registry.ensure("prj-b").runStatuses()["local"]).toBeUndefined()
dispose()
}))
it("ignores other message types", () =>
createRoot((dispose) => {
const { deps } = setup("prj-a")
expect(applyRunStatus({ type: "agentManager.localStats" }, deps)).toBe(false)
dispose()
}))
})