Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

test: edge-case coverage for #3845 / #3854 / #3794 merges

Louis Beaumont2458baa2eb7d
diff --git a/apps/screenpipe-app-tauri/lib/__tests__/context-pruning.test.ts b/apps/screenpipe-app-tauri/lib/__tests__/context-pruning.test.ts
index ab3b0baec..ebf53c9d5 100644
--- a/apps/screenpipe-app-tauri/lib/__tests__/context-pruning.test.ts
+++ b/apps/screenpipe-app-tauri/lib/__tests__/context-pruning.test.ts
@@ -267,3 +267,64 @@ describe("tool_result handler", () => {
expect(res.content[0].text).toContain("narrower filters");
});
});
+
+describe("clampMessageText — malformed history blocks fall back to head+tail", () => {
+ it("uses the generic trim when the history block is unterminated (open, no close)", () => {
+ const text = "<conversation_history>\n" + "a".repeat(500);
+ const out = clampMessageText(text, 100);
+ expect(out.length).toBeLessThanOrEqual(100);
+ expect(out).toContain("…[trimmed]");
+ expect(out).not.toContain("older history trimmed");
+ });
+
+ it("uses the generic trim when the close tag appears before the open tag", () => {
+ const text =
+ "</conversation_history> noise <conversation_history>" + "b".repeat(500);
+ const out = clampMessageText(text, 80);
+ expect(out.length).toBeLessThanOrEqual(80);
+ expect(out).toContain("…[trimmed]");
+ expect(out).not.toContain("older history trimmed");
+ });
+});
+
+describe("boundOversizedMessages — additional content shapes", () => {
+ it("clamps every oversized text block but never touches non-text blocks", () => {
+ const limit = maxMessageChars(WINDOW);
+ const image = { type: "image", data: "x".repeat(limit + 10) };
+ const messages = [
+ {
+ role: "assistant",
+ content: [
+ { type: "text", text: "a".repeat(limit + 100) },
+ image,
+ { type: "text", text: "b".repeat(limit + 100) },
+ ],
+ },
+ ];
+ expect(boundOversizedMessages(messages, WINDOW)).toBe(true);
+ expect(messages[0].content[0].text.length).toBeLessThanOrEqual(limit);
+ expect(messages[0].content[2].text.length).toBeLessThanOrEqual(limit);
+ // image block left byte-for-byte alone
+ expect(messages[0].content[1]).toBe(image);
+ expect(messages[0].content[1].data.length).toBe(limit + 10);
+ });
+
+ it("ignores messages whose content is neither a string nor an array (no throw)", () => {
+ const messages = [
+ { role: "user", content: { foo: "bar" } },
+ null,
+ { role: "user" },
+ ];
+ expect(boundOversizedMessages(messages as any, WINDOW)).toBe(false);
+ });
+});
+
+describe("resolveContextWindowTokens — getContextUsage edge", () => {
+ it("ignores a zero contextWindow from getContextUsage and uses the default", () => {
+ expect(
+ resolveContextWindowTokens({
+ getContextUsage: () => ({ contextWindow: 0 }),
+ }),
+ ).toBe(128_000);
+ });
+});
diff --git a/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts b/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts
index fbfb1959a..6a2b1501d 100644
--- a/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts
@@ -109,3 +109,82 @@ describe("normalizeLocalMediaMarkdown", () => {
);
});
});
+
+describe("normalizeMediaFilePath — edge cases", () => {
+ it("keeps the original string when percent-escapes are malformed", () => {
+ // decodeURIComponent throws on the dangling %A; the catch keeps the input.
+ expect(normalizeMediaFilePath("/Users/me/bad%A.mp4")).toBe(
+ "/Users/me/bad%A.mp4",
+ );
+ });
+
+ it("returns the cleaned path unchanged when there is no media extension", () => {
+ expect(normalizeMediaFilePath("/Users/me/notes.txt")).toBe(
+ "/Users/me/notes.txt",
+ );
+ });
+
+ it("returns an empty string for empty input", () => {
+ expect(normalizeMediaFilePath("")).toBe("");
+ });
+
+ it("strips surrounding backticks", () => {
+ expect(normalizeMediaFilePath("`/Users/ansh/clip.mp4`")).toBe(
+ "/Users/ansh/clip.mp4",
+ );
+ });
+
+ it("matches the media extension case-insensitively", () => {
+ expect(normalizeMediaFilePath("/Users/ansh/Clip.MP4")).toBe(
+ "/Users/ansh/Clip.MP4",
+ );
+ });
+
+ it("extracts a Windows path written with forward slashes from surrounding text", () => {
+ expect(normalizeMediaFilePath("see C:/Users/me/clip.webm now")).toBe(
+ "C:/Users/me/clip.webm",
+ );
+ });
+
+ it("extracts a Unix audio-chunk path with spaces and parens from chat text", () => {
+ expect(
+ normalizeMediaFilePath(
+ "recording at /Users/ansh/.screenpipe/data/Mic (input)_2026-05-25_21-42-22.mp4 done",
+ ),
+ ).toBe("/Users/ansh/.screenpipe/data/Mic (input)_2026-05-25_21-42-22.mp4");
+ });
+});
+
+describe("isAudioMediaPath / isMediaFilePath — edge cases", () => {
+ it("treats ogg/m4a/wav (any case) as audio but not webm or video mp4", () => {
+ expect(isAudioMediaPath("/x/a.ogg")).toBe(true);
+ expect(isAudioMediaPath("/x/a.M4A")).toBe(true);
+ expect(isAudioMediaPath("/x/a.WAV")).toBe(true);
+ expect(isAudioMediaPath("/x/clip.webm")).toBe(false);
+ });
+
+ it("isMediaFilePath is case-insensitive and rejects non-media extensions", () => {
+ expect(isMediaFilePath("/x/a.MP4")).toBe(true);
+ expect(isMediaFilePath("/x/a.OGG")).toBe(true);
+ expect(isMediaFilePath("/x/a.png")).toBe(false);
+ });
+});
+
+describe("normalizeLocalMediaMarkdown — edge cases", () => {
+ it("leaves an already-angle-bracket-wrapped media link unchanged", () => {
+ const md = "![](</Users/a/System Audio (output).mp4>)";
+ expect(normalizeLocalMediaMarkdown(md)).toBe(md);
+ });
+
+ it("escapes a literal > inside the wrapped path", () => {
+ expect(normalizeLocalMediaMarkdown("[a](/Users/a/we>ird.mp4)")).toBe(
+ "[a](</Users/a/we%3Eird.mp4>)",
+ );
+ });
+
+ it("wraps a Windows media path inside a link", () => {
+ expect(
+ normalizeLocalMediaMarkdown(String.raw`[v](C:\Users\me\clip.mp4)`),
+ ).toBe(String.raw`[v](<C:\Users\me\clip.mp4>)`);
+ });
+});
diff --git a/apps/screenpipe-app-tauri/lib/utils/notification-toggle.test.ts b/apps/screenpipe-app-tauri/lib/utils/notification-toggle.test.ts
index 802b4435b..7e677fb2e 100644
--- a/apps/screenpipe-app-tauri/lib/utils/notification-toggle.test.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/notification-toggle.test.ts
@@ -379,3 +379,64 @@ Sync screenpipe activity to an Obsidian vault`;
expect(reenabled).toContain("Sync screenpipe activity");
});
});
+
+describe("edge cases — blank lines and sibling allow blocks", () => {
+ it("detects the notify deny rule across a blank line inside the deny block", () => {
+ const content = [
+ "---",
+ "permissions:",
+ " deny:",
+ "",
+ " - Api(POST /notify)",
+ "---",
+ "body",
+ ].join("\n");
+ expect(isNotificationsDenied(content)).toBe(true);
+ });
+
+ it("enable: removes only the notify deny rule and keeps permissions + allow children", () => {
+ const content = [
+ "---",
+ "permissions:",
+ " allow:",
+ " - Api(GET /search)",
+ " deny:",
+ " - Api(POST /notify)",
+ "---",
+ "body",
+ ].join("\n");
+
+ const result = toggleNotificationInContent(content, true);
+
+ expect(result).toBe(
+ [
+ "---",
+ "permissions:",
+ " allow:",
+ " - Api(GET /search)",
+ "---",
+ "body",
+ ].join("\n"),
+ );
+ expect(isNotificationsDenied(result)).toBe(false);
+ expect(result).toContain("Api(GET /search)");
+ });
+
+ it("enable: keeps a deny block that still has a non-notify rule after removing notify", () => {
+ const content = [
+ "---",
+ "permissions:",
+ " deny:",
+ " - Api(POST /notify)",
+ " - Api(POST /shell)",
+ "---",
+ "body",
+ ].join("\n");
+
+ const result = toggleNotificationInContent(content, true);
+
+ expect(result).toContain("deny:");
+ expect(result).toContain("Api(POST /shell)");
+ expect(isNotificationsDenied(result)).toBe(false);
+ });
+});