@useavalon/caelence-agent 0.2.2-canary.5 → 0.2.2-canary.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/desktop/src/App.tsx +226 -74
- package/desktop/src/BubbleClip.tsx +58 -0
- package/desktop/src/PipelineTrack.tsx +19 -0
- package/desktop/src/PlatformPane.tsx +98 -0
- package/desktop/src/ReplySources.tsx +267 -0
- package/desktop/src/ShimmerPhrase.tsx +71 -0
- package/desktop/src/SkillsPanel.tsx +0 -7
- package/desktop/src/api.ts +24 -1
- package/desktop/src/app.css +906 -47
- package/desktop/src/clip.test.ts +16 -0
- package/desktop/src/clip.ts +26 -0
- package/desktop/src/pipeline.test.ts +86 -0
- package/desktop/src/pipeline.ts +131 -0
- package/desktop/src/platform.test.ts +30 -0
- package/desktop/src/platform.ts +76 -0
- package/desktop/src/preview-render.test.ts +79 -0
- package/desktop/src/preview-render.ts +254 -0
- package/desktop/src/queue.test.ts +18 -1
- package/desktop/src/queue.ts +8 -0
- package/desktop/src/reply-sources.test.ts +73 -0
- package/desktop/src/reply-sources.ts +116 -0
- package/desktop/src/rich-text.test.ts +26 -0
- package/desktop/src/rich-text.ts +51 -2
- package/desktop/src/stream.test.ts +41 -2
- package/desktop/src/stream.ts +22 -3
- package/desktop/src/styles/primitives.css +6 -3
- package/desktop/src/thought.test.ts +65 -18
- package/desktop/src/thought.ts +41 -11
- package/desktop/src/tool-label.test.ts +12 -0
- package/desktop/src/tool-label.ts +28 -0
- package/package.json +2 -2
- package/src/cli/models.ts +3 -1
- package/src/cli/openrouter-live.test.ts +29 -0
- package/src/cli/openrouter-live.ts +9 -1
- package/src/core/events.ts +1 -0
- package/src/core/run-turn.ts +7 -0
- package/src/core/session.ts +3 -0
- package/src/desktop/bridge.test.ts +51 -0
- package/src/desktop/bridge.ts +84 -6
- package/src/desktop/preview-kind.test.ts +20 -0
- package/src/desktop/preview-kind.ts +29 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { clipNeedsExpand } from "./clip.ts";
|
|
3
|
+
|
|
4
|
+
describe("clipNeedsExpand", () => {
|
|
5
|
+
test("ignores a sliver of the last line", () => {
|
|
6
|
+
expect(clipNeedsExpand(108, 99, 22)).toBe(false);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("expands when more than a line is hidden", () => {
|
|
10
|
+
expect(clipNeedsExpand(180, 99, 22)).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("does not expand when content fits", () => {
|
|
14
|
+
expect(clipNeedsExpand(80, 99, 22)).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function clipNeedsExpand(
|
|
2
|
+
contentHeight: number,
|
|
3
|
+
collapsedHeight: number,
|
|
4
|
+
lineHeight: number,
|
|
5
|
+
): boolean {
|
|
6
|
+
if (contentHeight <= 0 || collapsedHeight <= 0) return false;
|
|
7
|
+
const hidden = contentHeight - collapsedHeight;
|
|
8
|
+
const slop = Math.max(8, lineHeight * 1.15);
|
|
9
|
+
return hidden > slop;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function collapsedClipLimit(node: HTMLElement): number {
|
|
13
|
+
const style = getComputedStyle(node);
|
|
14
|
+
const raw = style.getPropertyValue("--desk-clip-max").trim() || style.maxHeight;
|
|
15
|
+
const fontSize = parseFloat(style.fontSize);
|
|
16
|
+
if (raw.endsWith("em") && Number.isFinite(fontSize)) return parseFloat(raw) * fontSize;
|
|
17
|
+
if (raw.endsWith("px")) return parseFloat(raw);
|
|
18
|
+
return node.clientHeight;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function clipLineHeight(node: HTMLElement): number {
|
|
22
|
+
const line = parseFloat(getComputedStyle(node).lineHeight);
|
|
23
|
+
if (Number.isFinite(line) && line > 0) return line;
|
|
24
|
+
const fontSize = parseFloat(getComputedStyle(node).fontSize);
|
|
25
|
+
return Number.isFinite(fontSize) ? fontSize * 1.45 : 20;
|
|
26
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
pipelineProgress,
|
|
4
|
+
prettySkillName,
|
|
5
|
+
type SkillToolRef,
|
|
6
|
+
skillIdFromTool,
|
|
7
|
+
} from "./pipeline.ts";
|
|
8
|
+
|
|
9
|
+
function tool(
|
|
10
|
+
partial: Partial<SkillToolRef> & Pick<SkillToolRef, "name" | "label" | "status">,
|
|
11
|
+
): SkillToolRef {
|
|
12
|
+
return {
|
|
13
|
+
preview: "",
|
|
14
|
+
...partial,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("pipeline progress", () => {
|
|
19
|
+
test("pretty-prints bundled skill ids", () => {
|
|
20
|
+
expect(prettySkillName("copy-harry-dry")).toBe("Harry Dry");
|
|
21
|
+
expect(prettySkillName("owner/repo@copy-rmbc")).toBe("RMBC");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("reads the skill name from preview or label", () => {
|
|
25
|
+
expect(
|
|
26
|
+
skillIdFromTool(
|
|
27
|
+
tool({
|
|
28
|
+
key: "t1",
|
|
29
|
+
name: "read_skill",
|
|
30
|
+
label: "Reading skill",
|
|
31
|
+
status: "running",
|
|
32
|
+
preview: '{"name":"copywriting"}',
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
).toBe("copywriting");
|
|
36
|
+
expect(
|
|
37
|
+
skillIdFromTool(
|
|
38
|
+
tool({
|
|
39
|
+
key: "t2",
|
|
40
|
+
name: "read_skill",
|
|
41
|
+
label: "Reading Copy editor",
|
|
42
|
+
status: "ok",
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
|
+
).toBe("Copy editor");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("builds the copywriting track as skills run", () => {
|
|
49
|
+
const pipe = pipelineProgress([
|
|
50
|
+
tool({
|
|
51
|
+
key: "t1",
|
|
52
|
+
name: "read_skill",
|
|
53
|
+
label: "Reading Copywriting",
|
|
54
|
+
status: "ok",
|
|
55
|
+
preview: '{"name":"copywriting"}',
|
|
56
|
+
}),
|
|
57
|
+
tool({
|
|
58
|
+
key: "t2",
|
|
59
|
+
name: "read_skill",
|
|
60
|
+
label: "Reading RMBC",
|
|
61
|
+
status: "running",
|
|
62
|
+
preview: '{"name":"copy-rmbc"}',
|
|
63
|
+
}),
|
|
64
|
+
]);
|
|
65
|
+
expect(pipe?.family).toBe("Copywriting");
|
|
66
|
+
expect(pipe?.title).toBe("Running RMBC");
|
|
67
|
+
expect(pipe?.steps.map((step) => step.status)).toEqual(["done", "run", "wait", "wait"]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("treats a lone skill as a one-step run", () => {
|
|
71
|
+
const pipe = pipelineProgress([
|
|
72
|
+
tool({
|
|
73
|
+
key: "t1",
|
|
74
|
+
name: "read_skill",
|
|
75
|
+
label: "Reading skill",
|
|
76
|
+
status: "running",
|
|
77
|
+
preview: '{"name":"impeccable"}',
|
|
78
|
+
}),
|
|
79
|
+
]);
|
|
80
|
+
expect(pipe).toEqual({
|
|
81
|
+
family: "Impeccable",
|
|
82
|
+
title: "Running Impeccable",
|
|
83
|
+
steps: [{ id: "impeccable", label: "Impeccable", status: "run" }],
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { inputFromPreview } from "./tool-label";
|
|
2
|
+
|
|
3
|
+
export interface SkillToolRef {
|
|
4
|
+
name: string;
|
|
5
|
+
label: string;
|
|
6
|
+
status: "running" | "ok" | "fail";
|
|
7
|
+
preview: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type PipeStepStatus = "done" | "run" | "wait";
|
|
11
|
+
|
|
12
|
+
export interface PipeStep {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
status: PipeStepStatus;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PipelineProgress {
|
|
19
|
+
family: string;
|
|
20
|
+
title: string;
|
|
21
|
+
steps: PipeStep[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const COPY_STEPS = [
|
|
25
|
+
{ id: "copywriting", label: "Copywriting" },
|
|
26
|
+
{ id: "copy-rmbc", label: "RMBC" },
|
|
27
|
+
{ id: "copy-harry-dry", label: "Harry Dry" },
|
|
28
|
+
{ id: "copy-editor", label: "Copy editor" },
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
const SKILL_LABELS: Record<string, string> = {
|
|
32
|
+
copywriting: "Copywriting",
|
|
33
|
+
"copy-rmbc": "RMBC",
|
|
34
|
+
"copy-harry-dry": "Harry Dry",
|
|
35
|
+
"copy-editor": "Copy editor",
|
|
36
|
+
impeccable: "Impeccable",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function prettySkillName(raw: string): string {
|
|
40
|
+
const id = skillKey(raw);
|
|
41
|
+
if (SKILL_LABELS[id]) return SKILL_LABELS[id];
|
|
42
|
+
const spaced = id.replace(/[-_]+/g, " ").trim();
|
|
43
|
+
return spaced ? spaced.charAt(0).toUpperCase() + spaced.slice(1) : raw.trim();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function skillKey(raw: string): string {
|
|
47
|
+
const trimmed = raw.trim();
|
|
48
|
+
const at = trimmed.lastIndexOf("@");
|
|
49
|
+
const afterAt = at >= 0 ? trimmed.slice(at + 1) : trimmed;
|
|
50
|
+
const slash = afterAt.lastIndexOf("/");
|
|
51
|
+
return (slash >= 0 ? afterAt.slice(slash + 1) : afterAt).toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isReadSkill(name: string): boolean {
|
|
55
|
+
return name === "read_skill" || name.endsWith("__read_skill");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function skillIdFromTool(tool: SkillToolRef): string | undefined {
|
|
59
|
+
if (isReadSkill(tool.name)) {
|
|
60
|
+
const parsed = inputFromPreview(tool.preview);
|
|
61
|
+
if (typeof parsed.name === "string" && parsed.name.trim()) return parsed.name.trim();
|
|
62
|
+
const fromLabel = /^Reading(?: skill)?\s+(.+)$/i.exec(tool.label)?.[1];
|
|
63
|
+
return fromLabel?.trim();
|
|
64
|
+
}
|
|
65
|
+
if (tool.name === "task") {
|
|
66
|
+
const parsed = inputFromPreview(tool.preview);
|
|
67
|
+
if (Array.isArray(parsed.skills)) {
|
|
68
|
+
const first = parsed.skills.find((item): item is string => typeof item === "string");
|
|
69
|
+
if (first?.trim()) return first.trim();
|
|
70
|
+
}
|
|
71
|
+
if (typeof parsed.label === "string" && parsed.label.trim()) return parsed.label.trim();
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isCopyFamily(id: string): boolean {
|
|
77
|
+
const key = skillKey(id);
|
|
78
|
+
return COPY_STEPS.some((step) => step.id === key);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function seenIds(
|
|
82
|
+
tools: readonly SkillToolRef[],
|
|
83
|
+
): Array<{ id: string; running: boolean; ok: boolean }> {
|
|
84
|
+
const out: Array<{ id: string; running: boolean; ok: boolean }> = [];
|
|
85
|
+
for (const tool of tools) {
|
|
86
|
+
const id = skillIdFromTool(tool);
|
|
87
|
+
if (!id) continue;
|
|
88
|
+
out.push({ id, running: tool.status === "running", ok: tool.status === "ok" });
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function pipelineProgress(tools: readonly SkillToolRef[]): PipelineProgress | undefined {
|
|
94
|
+
const hits = seenIds(tools);
|
|
95
|
+
if (hits.length === 0) return undefined;
|
|
96
|
+
const copy = hits.some((hit) => isCopyFamily(hit.id));
|
|
97
|
+
const defs = copy
|
|
98
|
+
? COPY_STEPS.map((step) => ({ id: step.id, label: step.label }))
|
|
99
|
+
: uniqueSkillDefs(hits.map((hit) => hit.id));
|
|
100
|
+
const running = [...hits].reverse().find((hit) => hit.running);
|
|
101
|
+
const latest = running ?? [...hits].reverse().find((hit) => hit.ok) ?? hits[0];
|
|
102
|
+
if (!latest) return undefined;
|
|
103
|
+
const currentKey = skillKey(latest.id);
|
|
104
|
+
const steps: PipeStep[] = defs.map((def) => {
|
|
105
|
+
const matched = hits.filter((hit) => skillKey(hit.id) === def.id);
|
|
106
|
+
if (matched.some((hit) => hit.running) || def.id === currentKey) {
|
|
107
|
+
return { ...def, status: latest.running || def.id === currentKey ? "run" : "done" };
|
|
108
|
+
}
|
|
109
|
+
if (matched.some((hit) => hit.ok)) return { ...def, status: "done" };
|
|
110
|
+
return { ...def, status: "wait" };
|
|
111
|
+
});
|
|
112
|
+
const current =
|
|
113
|
+
steps.find((step) => step.status === "run") ?? steps.find((step) => step.status === "done");
|
|
114
|
+
const family = copy ? "Copywriting" : prettySkillName(latest.id);
|
|
115
|
+
const title = latest.running
|
|
116
|
+
? `Running ${prettySkillName(latest.id)}`
|
|
117
|
+
: `Running ${current?.label ?? family}`;
|
|
118
|
+
return { family, title, steps };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function uniqueSkillDefs(ids: string[]): Array<{ id: string; label: string }> {
|
|
122
|
+
const seen = new Set<string>();
|
|
123
|
+
const out: Array<{ id: string; label: string }> = [];
|
|
124
|
+
for (const id of ids) {
|
|
125
|
+
const key = skillKey(id);
|
|
126
|
+
if (seen.has(key)) continue;
|
|
127
|
+
seen.add(key);
|
|
128
|
+
out.push({ id: key, label: prettySkillName(id) });
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
formatPlatformOutput,
|
|
4
|
+
isPlatformTool,
|
|
5
|
+
matchPlatform,
|
|
6
|
+
platformTitle,
|
|
7
|
+
toolEventOutput,
|
|
8
|
+
} from "./platform.ts";
|
|
9
|
+
|
|
10
|
+
describe("platform tools", () => {
|
|
11
|
+
test("reads the MCP namespace", () => {
|
|
12
|
+
expect(isPlatformTool("notion__notion_fetch")).toBe(true);
|
|
13
|
+
expect(isPlatformTool("read_file")).toBe(false);
|
|
14
|
+
expect(platformTitle("notion__notion_fetch", [{ id: "notion", label: "Notion" }])).toBe(
|
|
15
|
+
"Notion",
|
|
16
|
+
);
|
|
17
|
+
expect(
|
|
18
|
+
platformTitle("google_sheets__get_range", [{ id: "google-sheets", label: "Google Sheets" }]),
|
|
19
|
+
).toBe("Google Sheets");
|
|
20
|
+
expect(matchPlatform("canva__list_designs", [{ id: "canva", label: "Canva" }])?.id).toBe(
|
|
21
|
+
"canva",
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("pretty-prints JSON tool payloads", () => {
|
|
26
|
+
expect(formatPlatformOutput('{"title":"Notes"}')).toBe('{\n "title": "Notes"\n}');
|
|
27
|
+
expect(toolEventOutput({ text: "hello" })).toBe("hello");
|
|
28
|
+
expect(toolEventOutput({ content: [{ type: "text", text: "page" }] })).toBe("page");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const PLATFORM_OUTPUT_MAX = 8000;
|
|
2
|
+
|
|
3
|
+
export function platformPrefix(toolName: string): string | undefined {
|
|
4
|
+
const cut = toolName.indexOf("__");
|
|
5
|
+
if (cut <= 0) return undefined;
|
|
6
|
+
return toolName.slice(0, cut);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isPlatformTool(toolName: string): boolean {
|
|
10
|
+
return platformPrefix(toolName) !== undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function matchPlatform<T extends { id: string }>(
|
|
14
|
+
toolName: string,
|
|
15
|
+
items: readonly T[],
|
|
16
|
+
): T | undefined {
|
|
17
|
+
const prefix = platformPrefix(toolName);
|
|
18
|
+
if (!prefix) return undefined;
|
|
19
|
+
const key = prefix.replaceAll("_", "-").toLowerCase();
|
|
20
|
+
return items.find((item) => item.id.replaceAll("_", "-").toLowerCase() === key);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function platformTitle(
|
|
24
|
+
toolName: string,
|
|
25
|
+
items: ReadonlyArray<{ id: string; label: string }>,
|
|
26
|
+
): string {
|
|
27
|
+
const match = matchPlatform(toolName, items);
|
|
28
|
+
if (match) return match.label;
|
|
29
|
+
const prefix = platformPrefix(toolName);
|
|
30
|
+
if (!prefix) return "Integration";
|
|
31
|
+
const label = prefix.replaceAll("_", " ").replaceAll("-", " ").trim();
|
|
32
|
+
return label.length > 0 ? label.charAt(0).toUpperCase() + label.slice(1) : "Integration";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function clipPlatformOutput(text: string): string {
|
|
36
|
+
if (text.length <= PLATFORM_OUTPUT_MAX) return text;
|
|
37
|
+
return `${text.slice(0, PLATFORM_OUTPUT_MAX)}\n…`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function formatPlatformOutput(raw: string): string {
|
|
41
|
+
const trimmed = raw.trim();
|
|
42
|
+
if (!trimmed) return "";
|
|
43
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(JSON.parse(trimmed), null, 2);
|
|
46
|
+
} catch {
|
|
47
|
+
return trimmed;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return trimmed;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function toolEventOutput(result: unknown): string {
|
|
54
|
+
if (typeof result === "string") return clipPlatformOutput(result);
|
|
55
|
+
if (!result || typeof result !== "object") return "";
|
|
56
|
+
const rec = result as Record<string, unknown>;
|
|
57
|
+
if (typeof rec.text === "string") return clipPlatformOutput(rec.text);
|
|
58
|
+
if (Array.isArray(rec.content)) {
|
|
59
|
+
const bits: string[] = [];
|
|
60
|
+
for (const block of rec.content) {
|
|
61
|
+
if (
|
|
62
|
+
block &&
|
|
63
|
+
typeof block === "object" &&
|
|
64
|
+
typeof (block as { text?: unknown }).text === "string"
|
|
65
|
+
) {
|
|
66
|
+
bits.push((block as { text: string }).text);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (bits.length > 0) return clipPlatformOutput(bits.join("\n"));
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return clipPlatformOutput(JSON.stringify(result, null, 2));
|
|
73
|
+
} catch {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
renderMarkdown,
|
|
4
|
+
renderPreviewHtml,
|
|
5
|
+
resolvePreviewAsset,
|
|
6
|
+
rewritePreviewAssets,
|
|
7
|
+
sanitizePreviewHtml,
|
|
8
|
+
} from "./preview-render.ts";
|
|
9
|
+
|
|
10
|
+
describe("preview render", () => {
|
|
11
|
+
test("renders markdown headings, lists, code, and tables", () => {
|
|
12
|
+
const html = renderMarkdown(
|
|
13
|
+
[
|
|
14
|
+
"# Title",
|
|
15
|
+
"",
|
|
16
|
+
"A **bold** and `code` line with [docs](https://example.com).",
|
|
17
|
+
"",
|
|
18
|
+
"- one",
|
|
19
|
+
"- two",
|
|
20
|
+
"",
|
|
21
|
+
"```ts",
|
|
22
|
+
"const n = 1;",
|
|
23
|
+
"```",
|
|
24
|
+
"",
|
|
25
|
+
"| Path | What |",
|
|
26
|
+
"| --- | --- |",
|
|
27
|
+
"| src/ | Runtime |",
|
|
28
|
+
].join("\n"),
|
|
29
|
+
);
|
|
30
|
+
expect(html).toContain("<h1>Title</h1>");
|
|
31
|
+
expect(html).toContain("<strong>bold</strong>");
|
|
32
|
+
expect(html).toContain("<code>code</code>");
|
|
33
|
+
expect(html).toContain('<a href="https://example.com">docs</a>');
|
|
34
|
+
expect(html).toContain("<ul><li>one</li><li>two</li></ul>");
|
|
35
|
+
expect(html).toContain("<pre><code>const n = 1;</code></pre>");
|
|
36
|
+
expect(html).toContain("<th>Path</th>");
|
|
37
|
+
expect(html).toContain("<td>Runtime</td>");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("keeps raw HTML blocks and images", () => {
|
|
41
|
+
const html = renderMarkdown(
|
|
42
|
+
[
|
|
43
|
+
'<p align="center">',
|
|
44
|
+
'\t<img src="brand/logo/mark.svg" alt="Mark" />',
|
|
45
|
+
"</p>",
|
|
46
|
+
"",
|
|
47
|
+
"See  next.",
|
|
48
|
+
].join("\n"),
|
|
49
|
+
);
|
|
50
|
+
expect(html).toContain('<p align="center">');
|
|
51
|
+
expect(html).toContain('src="brand/logo/mark.svg"');
|
|
52
|
+
expect(html).toContain('<img src="docs/shot.png" alt="shot" />');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("resolves and rewrites local assets", () => {
|
|
56
|
+
expect(resolvePreviewAsset("README.md", "brand/logo/mark.svg")).toBe("brand/logo/mark.svg");
|
|
57
|
+
expect(resolvePreviewAsset("docs/guide.md", "./shot.png")).toBe("docs/shot.png");
|
|
58
|
+
expect(resolvePreviewAsset("docs/guide.md", "../shot.png")).toBe("shot.png");
|
|
59
|
+
expect(resolvePreviewAsset("docs/guide.md", "../../secret.png")).toBeUndefined();
|
|
60
|
+
expect(resolvePreviewAsset("README.md", "https://m8ven.ai/badge.png")).toBeUndefined();
|
|
61
|
+
const html = rewritePreviewAssets(
|
|
62
|
+
'<img src="brand/logo/mark.svg" /><source srcset="brand/logo/dark.png" />',
|
|
63
|
+
"README.md",
|
|
64
|
+
(rel) => `/bytes/${rel}`,
|
|
65
|
+
);
|
|
66
|
+
expect(html).toContain("/bytes/brand/logo/mark.svg");
|
|
67
|
+
expect(html).toContain("/bytes/brand/logo/dark.png");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("strips scripts and handlers from html", () => {
|
|
71
|
+
const clean = sanitizePreviewHtml(
|
|
72
|
+
'<p onclick="alert(1)">Hi</p><script>alert(1)</script><img src="javascript:alert(1)" />',
|
|
73
|
+
);
|
|
74
|
+
expect(clean).not.toContain("script");
|
|
75
|
+
expect(clean).not.toContain("onclick");
|
|
76
|
+
expect(clean).not.toContain("javascript:");
|
|
77
|
+
expect(renderPreviewHtml("<h1>Hi</h1>", "html")).toContain("<h1>Hi</h1>");
|
|
78
|
+
});
|
|
79
|
+
});
|