Fix server file workspace null handling

This commit is contained in:
npc0-hue
2026-08-24 14:06:14 +08:00
parent 33d3a13e74
commit 504387c657
6 changed files with 190 additions and 7 deletions
+19
View File
@@ -657,6 +657,25 @@ describe("PlatformApiClient AI providers", () => {
expect(fetchMock).toHaveBeenCalledTimes(44);
});
it("normalizes server file workspace null arrays from older platform responses", async () => {
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url.endsWith("/api/v1/server-instances/server-1/files/workspace")) {
return jsonResponse({ ...serverFileWorkspace, defaultDirectoryKey: "", directories: null, files: null, configFields: null, transfer: { ...serverFileWorkspace.transfer, notes: null } });
}
if (url.endsWith("/api/v1/server-instances/server-1/files/list?directoryKey=scum-config")) {
return jsonResponse({ serverInstanceId: server.id, pluginId: plugin.id, directoryKey: "scum-config", state: "declared", entries: null });
}
throw new Error(`unexpected request: ${url}`);
});
vi.stubGlobal("fetch", fetchMock);
const client = new PlatformApiClient();
await expect(client.getServerFileWorkspace(server.id)).resolves.toMatchObject({ directories: [], files: [], configFields: [], transfer: { notes: [] } });
await expect(client.listServerFiles(server.id, { directoryKey: "scum-config" })).resolves.toMatchObject({ entries: [] });
});
it("calls plugin marketplace endpoints with filter and state contracts", async () => {
const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);