Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

2.2 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { chatLinkAction, chatUrlTransform, nativePathFromMarkdownUrl } from "./chatLinks";

describe("chat file links", () => {
  it.each([
    ["C:/Users/me/Clip.mp4", "C:/Users/me/Clip.mp4"],
    ["C:\\Users\\me\\Clip.mp4", "C:\\Users\\me\\Clip.mp4"],
    ["file:///C:/Users/me/My%20Clip.mp4", "C:/Users/me/My Clip.mp4"],
    ["file://C:/Users/me/Clip.mp4", "C:/Users/me/Clip.mp4"],
    ["file://localhost/home/me/clip.mp4", "/home/me/clip.mp4"],
    ["~/Downloads/clip.mp4", "~/Downloads/clip.mp4"],
    ["/home/me/Videos/clip.mp4", "/home/me/Videos/clip.mp4"],
  ])("keeps %s as a local path", (raw, expected) => {
    expect(nativePathFromMarkdownUrl(raw)).toBe(expected);
    expect(chatUrlTransform(raw)).toBe("#jarvis-local=" + encodeURIComponent(expected));
  });

  it.each([
    "https://example.test/clip.mp4",
    "javascript:alert(1)",
    "  JavaScript:alert(1)",
    "VBScript:msgbox(1)",
    "data:text/html,<script>alert(1)</script>",
    "file://server/share/clip.mp4",
    "/api/outputs/run/files/clip.mp4/download",
  ])("does not treat %s as a local file", raw => {
    expect(nativePathFromMarkdownUrl(raw)).toBeNull();
  });

  it.each(["notes.md", "shot.png", "folder/clip.mp4"])("opens a linked filename %s", name => {
    expect(chatUrlTransform(name)).toBe("#jarvis-local=" + encodeURIComponent(name));
    expect(chatLinkAction(chatUrlTransform(name))).toEqual({ type: "local", path: name });
  });

  it("opens a preserved local path and still sends web links out", () => {
    const href = chatUrlTransform("C:/Users/me/Clip.mp4");
    expect(chatLinkAction(href)).toEqual({ type: "local", path: "C:/Users/me/Clip.mp4" });
    expect(chatLinkAction("https://example.test/clip.mp4")).toEqual({
      type: "external",
      url: "https://example.test/clip.mp4",
    });
  });

  it("uses the visible filename when the address itself was emptied", () => {
    expect(chatLinkAction("", "photo.png")).toEqual({ type: "local", path: "photo.png" });
    expect(chatLinkAction("")).toEqual({ type: "stay" });
    expect(chatLinkAction("javascript:alert(1)")).toEqual({ type: "stay" });
    expect(chatLinkAction("/api/outputs/run/download")).toEqual({ type: "allow" });
  });
});