feat(tui): start fresh chats in launch workspace

This commit is contained in:
chengyongru
2026-08-20 11:16:09 +08:00
committed by chengyongru
parent 1018bdb7fe
commit c615aee2ca
11 changed files with 85 additions and 105 deletions
+45
View File
@@ -259,6 +259,10 @@ describe("gateway protocol", () => {
const client = new NanobotClient({
url: "ws://nanobot.test/ws",
chatId: "terminal",
initialWorkspaceScope: {
project_path: "/tmp/project",
access_mode: "restricted",
},
onEvent: (event) => events.push(event),
onStatus: () => undefined,
})
@@ -324,6 +328,47 @@ describe("gateway protocol", () => {
}
})
test("starts a fresh chat in the launch workspace", () => {
const original = globalThis.WebSocket
let socket: FakeSocket | undefined
Object.defineProperty(globalThis, "WebSocket", {
configurable: true,
value: class extends FakeSocket {
constructor() {
super()
socket = this
}
},
})
try {
const client = new NanobotClient({
url: "ws://nanobot.test/ws",
initialWorkspaceScope: {
project_path: "/tmp/launch-project",
access_mode: "restricted",
},
onEvent: () => undefined,
onStatus: () => undefined,
})
client.connect()
if (!socket) throw new Error("socket was not created")
socket.emit("message", {
data: JSON.stringify({ event: "ready", chat_id: "", client_id: "client" }),
})
expect(socket.sent.map((value) => JSON.parse(value))).toEqual([{
type: "new_chat",
workspace_scope: {
project_path: "/tmp/launch-project",
access_mode: "restricted",
},
}])
} finally {
Object.defineProperty(globalThis, "WebSocket", { configurable: true, value: original })
}
})
test("loads runtime model and access controls from canonical APIs", async () => {
const original = globalThis.fetch
globalThis.fetch = (async (input: string | URL | Request) => {