refactor(webui): remove obsolete workspace picker code

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-08 20:33:15 +08:00
1 parent d5dc59ea76
commit 024d181013
17 files changed
+31 -109

No files matched your search

+1 -1
View File
@@ -2232,7 +2232,7 @@ describe("App layout", () => {
});
it("uses native chrome when the host bridge overrides browser gateway metadata", async () => {
Reflect.set(window, "nanobotHost", { pickFolder: vi.fn() });
Reflect.set(window, "nanobotHost", { getRuntimeInfo: vi.fn() });
vi.mocked(fetchBootstrap).mockResolvedValue({
token: "tok",
api_token: "api-tok",
-1
View File
@@ -205,7 +205,6 @@ const LOCALIZED_WORKSPACE_COPY_KEYS = [
"errors.workspaceScopeRejected.title",
"errors.workspaceScopeRejected.body",
"workspace.dialog.defaultProject",
"workspace.dialog.usePath",
"workspace.dialog.absolutePathRequired",
];
const LOCALIZED_CHANNEL_SHELL_KEYS = [
+15 -24
View File
@@ -11,7 +11,6 @@ afterEach(() => {
window.sessionStorage.clear();
window.history.replaceState(null, "", "/");
initializeLoopbackRuntimeHost();
vi.unstubAllGlobals();
});
describe("runtime host facade", () => {
@@ -19,21 +18,21 @@ describe("runtime host facade", () => {
const host = getRuntimeHost();
expect(host.surface).toBe("browser");
expect(host.pickFolder).toBeUndefined();
expect(host.restartEngine).toBeUndefined();
expect(isNativeRuntime()).toBe(false);
});
it("wraps native host actions behind the runtime facade", async () => {
const pickFolder = vi.fn(async () => "/tmp/project");
const restartEngine = vi.fn(async () => undefined);
const openLogs = vi.fn(async () => undefined);
const exportDiagnostics = vi.fn(async () => "/tmp/diagnostics.txt");
Object.defineProperty(window, "nanobotHost", {
configurable: true,
value: {
getRuntimeInfo: vi.fn(),
restartEngine,
pickFolder,
openLogs: vi.fn(async () => undefined),
exportDiagnostics: vi.fn(async () => "/tmp/diagnostics.txt"),
openLogs,
exportDiagnostics,
},
});
@@ -41,23 +40,20 @@ describe("runtime host facade", () => {
expect(host.surface).toBe("native");
expect(isNativeRuntime()).toBe(true);
await expect(host.pickFolder?.()).resolves.toBe("/tmp/project");
await host.restartEngine?.();
expect(pickFolder).toHaveBeenCalledTimes(1);
await host.openLogs?.();
await expect(host.exportDiagnostics?.()).resolves.toBe("/tmp/diagnostics.txt");
expect(restartEngine).toHaveBeenCalledTimes(1);
expect(openLogs).toHaveBeenCalledTimes(1);
expect(exportDiagnostics).toHaveBeenCalledTimes(1);
});
it("treats server-reported native surface as native for UI labels", () => {
expect(isNativeRuntime("native")).toBe(true);
});
it("installs an authenticated loopback folder picker from the URL fragment", async () => {
it("recognizes an external native host across refresh and consumes its URL bootstrap", () => {
const token = "a".repeat(43);
const fetchMock = vi.fn(async () => new Response(
JSON.stringify({ path: "/Users/test/project" }),
{ status: 200, headers: { "Content-Type": "application/json" } },
));
vi.stubGlobal("fetch", fetchMock);
window.history.replaceState(
null,
"",
@@ -67,18 +63,12 @@ describe("runtime host facade", () => {
expect(initializeLoopbackRuntimeHost()).toBe(true);
expect(window.location.hash).toBe("#/new?bootstrapSecret=secret");
expect(isNativeRuntime()).toBe(true);
await expect(getRuntimeHost().pickFolder?.()).resolves.toBe("/Users/test/project");
expect(fetchMock).toHaveBeenCalledWith(
"http://127.0.0.1:43123/v1/pick-folder",
expect.objectContaining({
method: "POST",
headers: { Authorization: `Bearer ${token}` },
}),
);
expect(getRuntimeHost().surface).toBe("native");
window.history.replaceState(null, "", "/#/new");
expect(initializeLoopbackRuntimeHost()).toBe(true);
await expect(getRuntimeHost().pickFolder?.()).resolves.toBe("/Users/test/project");
expect(getRuntimeHost().surface).toBe("native");
expect(isNativeRuntime()).toBe(true);
});
it("rejects invalid loopback bridge bootstrap values", () => {
@@ -90,6 +80,7 @@ describe("runtime host facade", () => {
expect(initializeLoopbackRuntimeHost()).toBe(false);
expect(window.location.hash).toBe("#/new");
expect(getRuntimeHost().pickFolder).toBeUndefined();
expect(getRuntimeHost().surface).toBe("browser");
expect(isNativeRuntime()).toBe(false);
});
});
-3
View File
@@ -1596,7 +1596,6 @@ describe("ThreadComposer", () => {
it("browses and selects the connected host's project in one dialog on a native client", async () => {
const user = userEvent.setup();
const onWorkspaceScopeChange = vi.fn();
const pickFolder = vi.fn().mockResolvedValue("/Users/test/native-project");
const defaultScope = {
project_path: "/Users/test/.nanobot/workspace",
project_name: "workspace",
@@ -1618,7 +1617,6 @@ describe("ThreadComposer", () => {
value: {
getRuntimeInfo: vi.fn(),
restartEngine: vi.fn(),
pickFolder,
openLogs: vi.fn(),
exportDiagnostics: vi.fn(),
},
@@ -1652,7 +1650,6 @@ describe("ThreadComposer", () => {
await user.click(screen.getByRole("button", { name: "Select" }));
await waitFor(() => expect(screen.queryByRole("dialog", { name: "Choose project" })).not.toBeInTheDocument());
expect(onResolveWorkspaceProject).toHaveBeenCalledWith(project.path);
expect(pickFolder).not.toHaveBeenCalled();
expect(onWorkspaceScopeChange).toHaveBeenCalledWith(expect.objectContaining({
project_path: project.path,
project_name: project.name,