fix: support multiple keys per action and harden runtime/parsing

This commit is contained in:
2026-08-14 10:59:25 -06:00
parent 7e3377f932
commit 733bc2b4f9
10 changed files with 180 additions and 87 deletions
+27
View File
@@ -64,3 +64,30 @@ test("decodeEvent returns null for unrelated or malformed events", () => {
assert.equal(decodeEvent({ event: "message", data: JSON.stringify({ type: "logData", data: "{}" }) }), null);
assert.equal(decodeEvent({ event: "message", data: "not json" }), null);
});
test("decodeEvent returns null when modelStatus data is not an array", () => {
const msg: SseMessage = {
event: "message",
data: JSON.stringify({
type: "modelStatus",
data: JSON.stringify({ id: "DeepSeek-V4-Flash-0731", state: "ready" }),
}),
};
assert.equal(decodeEvent(msg), null);
});
test("decodeEvent handles inflight with a non-array requests field and no request field", () => {
const msg: SseMessage = {
event: "message",
data: JSON.stringify({
type: "inflight",
data: JSON.stringify({ operation: "snapshot", requests: "oops" }),
}),
};
const ev = decodeEvent(msg);
assert.ok(ev && ev.type === "inflight");
if (ev && ev.type === "inflight") {
assert.equal(ev.operation, "snapshot");
assert.deepEqual(ev.requests, []);
}
});
+1 -1
View File
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
import { test } from "node:test";
import { type LlamaSwapConfig } from "../src/lib/util";
import { MetricsPoller } from "../src/lib/metrics-poller";
import { parseGpuMetrics } from "../src/lib/metrics-parser";
const FIXTURE = readFileSync(new URL("./fixtures/metrics.txt", import.meta.url), "utf8");
const FIXTURE2 = FIXTURE
+7
View File
@@ -22,3 +22,10 @@ test("parseSse joins multi-line data fields with newline", () => {
assert.equal(messages.length, 1);
assert.equal(messages[0].data, "line1\nline2");
});
test("parseSse normalizes CRLF-delimited events", () => {
const { messages, rest } = parseSse("data:hello\r\n\r\n");
assert.equal(rest, "");
assert.equal(messages.length, 1);
assert.equal(messages[0].data, "hello");
});