chore: normalize formatting (2-space → tabs) in stream-error-patterns files
Re-tab only — no logic changes. Follows the repo's tab-based formatting for these files, matching the CommandCode executor/translator style. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
This commit is contained in:
@@ -1,50 +1,70 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { parsePatterns, matchStreamErrorPatterns, streamStatusForContent } from "../../open-sse/utils/streamErrorPatterns.js";
|
||||
import {
|
||||
parsePatterns,
|
||||
matchStreamErrorPatterns,
|
||||
streamStatusForContent,
|
||||
} from "../../open-sse/utils/streamErrorPatterns.js";
|
||||
|
||||
describe("streamErrorPatterns util", () => {
|
||||
it("matches plain text as case-insensitive substring", () => {
|
||||
expect(matchStreamErrorPatterns(["Network connection lost"], "network CONNECTION LOST.")).toBe("Network connection lost");
|
||||
expect(matchStreamErrorPatterns(["server_error"], "some normal content")).toBeNull();
|
||||
});
|
||||
it("matches plain text as case-insensitive substring", () => {
|
||||
expect(
|
||||
matchStreamErrorPatterns(
|
||||
["Network connection lost"],
|
||||
"network CONNECTION LOST.",
|
||||
),
|
||||
).toBe("Network connection lost");
|
||||
expect(
|
||||
matchStreamErrorPatterns(["server_error"], "some normal content"),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("matches /regex/flags", () => {
|
||||
expect(matchStreamErrorPatterns(["/generation failed.*retry/i"], "GENERATION FAILED. please RETRY")).toBe("/generation failed.*retry/i");
|
||||
expect(matchStreamErrorPatterns(["/\\d+ tokens/"], "used 123 tokens")).toBe("/\\d+ tokens/");
|
||||
});
|
||||
it("matches /regex/flags", () => {
|
||||
expect(
|
||||
matchStreamErrorPatterns(
|
||||
["/generation failed.*retry/i"],
|
||||
"GENERATION FAILED. please RETRY",
|
||||
),
|
||||
).toBe("/generation failed.*retry/i");
|
||||
expect(matchStreamErrorPatterns(["/\\d+ tokens/"], "used 123 tokens")).toBe(
|
||||
"/\\d+ tokens/",
|
||||
);
|
||||
});
|
||||
|
||||
it("skips invalid regex and empty entries", () => {
|
||||
expect(matchStreamErrorPatterns(["/[unclosed/", "", " "], "anything")).toBeNull();
|
||||
});
|
||||
it("skips invalid regex and empty entries", () => {
|
||||
expect(
|
||||
matchStreamErrorPatterns(["/[unclosed/", "", " "], "anything"),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for empty patterns or text", () => {
|
||||
expect(matchStreamErrorPatterns([], "x")).toBeNull();
|
||||
expect(matchStreamErrorPatterns(["x"], "")).toBeNull();
|
||||
expect(matchStreamErrorPatterns(null, "x")).toBeNull();
|
||||
expect(matchStreamErrorPatterns(undefined, "x")).toBeNull();
|
||||
});
|
||||
it("returns null for empty patterns or text", () => {
|
||||
expect(matchStreamErrorPatterns([], "x")).toBeNull();
|
||||
expect(matchStreamErrorPatterns(["x"], "")).toBeNull();
|
||||
expect(matchStreamErrorPatterns(null, "x")).toBeNull();
|
||||
expect(matchStreamErrorPatterns(undefined, "x")).toBeNull();
|
||||
});
|
||||
|
||||
it("regex matching is stateless across calls", () => {
|
||||
const pats = ["/error/i"];
|
||||
expect(matchStreamErrorPatterns(pats, "ERROR")).toBe("/error/i");
|
||||
expect(matchStreamErrorPatterns(pats, "ERROR")).toBe("/error/i");
|
||||
});
|
||||
it("regex matching is stateless across calls", () => {
|
||||
const pats = ["/error/i"];
|
||||
expect(matchStreamErrorPatterns(pats, "ERROR")).toBe("/error/i");
|
||||
expect(matchStreamErrorPatterns(pats, "ERROR")).toBe("/error/i");
|
||||
});
|
||||
|
||||
it("parsePatterns normalizes entries", () => {
|
||||
const parsed = parsePatterns(["Plain", "/re/g", "", "/bad["]);
|
||||
expect(parsed.length).toBe(3);
|
||||
expect(parsed[0]).toEqual({ text: "plain", raw: "Plain" });
|
||||
expect(parsed[1].regex).toBeInstanceOf(RegExp);
|
||||
expect(parsed[2]).toEqual({ text: "/bad[", raw: "/bad[" });
|
||||
});
|
||||
it("parsePatterns normalizes entries", () => {
|
||||
const parsed = parsePatterns(["Plain", "/re/g", "", "/bad["]);
|
||||
expect(parsed.length).toBe(3);
|
||||
expect(parsed[0]).toEqual({ text: "plain", raw: "Plain" });
|
||||
expect(parsed[1].regex).toBeInstanceOf(RegExp);
|
||||
expect(parsed[2]).toEqual({ text: "/bad[", raw: "/bad[" });
|
||||
});
|
||||
|
||||
it("skips entries that look like regex but fail to compile", () => {
|
||||
const parsed = parsePatterns(["/[unclosed/", "/ok/g"]);
|
||||
expect(parsed.length).toBe(1);
|
||||
expect(parsed[0].raw).toBe("/ok/g");
|
||||
});
|
||||
it("skips entries that look like regex but fail to compile", () => {
|
||||
const parsed = parsePatterns(["/[unclosed/", "/ok/g"]);
|
||||
expect(parsed.length).toBe(1);
|
||||
expect(parsed[0].raw).toBe("/ok/g");
|
||||
});
|
||||
|
||||
it("streamStatusForContent maps match to error status", () => {
|
||||
expect(streamStatusForContent(["boom"], "a boom happened")).toBe("error");
|
||||
expect(streamStatusForContent(["boom"], "all good")).toBe("success");
|
||||
});
|
||||
it("streamStatusForContent maps match to error status", () => {
|
||||
expect(streamStatusForContent(["boom"], "a boom happened")).toBe("error");
|
||||
expect(streamStatusForContent(["boom"], "all good")).toBe("success");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user