Reduce server console polling load

This commit is contained in:
npc0-hue
2026-09-07 19:49:20 +08:00
parent 1b583f3ca6
commit 4ab7bb820d
10 changed files with 110 additions and 25 deletions
+13 -1
View File
@@ -311,12 +311,21 @@ describe("PlatformApiClient AI providers", () => {
if (url.endsWith("/api/v1/run/endpoints")) {
return jsonResponse({ items: [endpoint], count: 1 });
}
if (url.endsWith("/api/v1/run/endpoints?status=online")) {
return jsonResponse({ items: [endpoint], count: 1 });
}
if (url.endsWith("/api/v1/jobs")) {
return jsonResponse({ items: [job], count: 1 });
}
if (url.endsWith("/api/v1/jobs?serverInstanceId=server-1")) {
return jsonResponse({ items: [job], count: 1 });
}
if (url.endsWith("/api/v1/jobs?states=queued%2Crunning%2Cfailed")) {
return jsonResponse({ items: [job], count: 1 });
}
if (url.endsWith("/api/v1/jobs?serverInstanceId=server-1&states=queued%2Crunning%2Cfailed")) {
return jsonResponse({ items: [job], count: 1 });
}
if (url.endsWith("/api/v1/artifacts?ownerKind=job&ownerId=job-1&state=available")) {
return jsonResponse({ items: [artifact], count: 1 });
}
@@ -571,8 +580,11 @@ describe("PlatformApiClient AI providers", () => {
await expect(client.uploadServerFile(server.id, { directoryKey: "configs", file: new File(["server.name=Example\n"], "server.properties", { type: "text/plain" }), idempotencyKey: "idem-file-upload" })).resolves.toMatchObject({ inputRef: "artifact://artifact-upload-1", job: { capability: "files.write" } });
await expect(client.prepareServerFileDownload(server.id, { key: "config/server.properties", idempotencyKey: "idem-file-download" })).resolves.toMatchObject({ status: "ready", filename: "server.properties", content: "server.name=Example\n" });
await expect(client.listRunEndpoints()).resolves.toMatchObject({ count: 1 });
await expect(client.listRunEndpoints({ status: "online" })).resolves.toMatchObject({ count: 1 });
await expect(client.listJobs()).resolves.toMatchObject({ count: 1 });
await expect(client.listJobs(server.id)).resolves.toMatchObject({ count: 1 });
await expect(client.listJobs(undefined, { states: ["queued", "running", "failed"] })).resolves.toMatchObject({ count: 1 });
await expect(client.listJobs(server.id, { states: ["queued", "running", "failed"] })).resolves.toMatchObject({ count: 1 });
await expect(client.listArtifacts({ ownerKind: "job", ownerId: job.id, state: "available" })).resolves.toMatchObject({ count: 1, items: [{ id: artifact.id }] });
await expect(client.openArtifactDownload(artifact.id)).resolves.toMatchObject({ downloadUrl: "/api/v1/artifacts/artifact-1/content", rangeSupported: true });
await expect(client.readArtifactContent(artifact.id, 0, 8)).resolves.toMatchObject({ contentLength: 8, contentRange: "bytes 0-7/18", checksum: artifact.checksum });
@@ -613,7 +625,7 @@ describe("PlatformApiClient AI providers", () => {
client.invokeAI({ requestId: "ai-1", serverInstanceId: server.id, purpose: "config.suggest", prompt: "Tune PVP safely", currentConfig: "server.name=Example Survival #1\n" })
).resolves.toMatchObject({ status: "ok", usage: { mocked: true }, configRecommendation: { diffSummary: "review required" } });
expect(fetchMock).toHaveBeenCalledTimes(43);
expect(fetchMock).toHaveBeenCalledTimes(46);
});
it("normalizes server file workspace null arrays from older platform responses", async () => {