@peaske7/readit 0.1.7 → 0.2.0
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/README.md +0 -3
- package/biome.json +1 -1
- package/bun.lock +43 -185
- package/docs/perf-baseline.md +75 -0
- package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
- package/e2e/perf/add-comment.spec.ts +118 -0
- package/e2e/perf/fixtures/generate.ts +331 -0
- package/e2e/perf/initial-load.spec.ts +49 -0
- package/e2e/perf/perf.setup.ts +23 -0
- package/e2e/perf/perf.teardown.ts +9 -0
- package/e2e/perf/scroll.spec.ts +39 -0
- package/e2e/perf/tab-switch.spec.ts +69 -0
- package/e2e/perf/text-selection.spec.ts +119 -0
- package/e2e/perf/utils/metrics.ts +286 -0
- package/e2e/perf/utils/perf-cli.ts +86 -0
- package/package.json +9 -18
- package/playwright.config.ts +12 -0
- package/src/App.tsx +133 -178
- package/src/{cli/index.ts → cli.ts} +211 -107
- package/src/components/ActionsMenu.tsx +6 -27
- package/src/components/DocumentViewer/DocumentViewer.tsx +78 -105
- package/src/components/DocumentViewer/MermaidDiagram.tsx +6 -7
- package/src/components/Header.tsx +9 -20
- package/src/components/InlineEditor.tsx +5 -5
- package/src/components/MarginNote.tsx +71 -93
- package/src/components/MarginNotes.tsx +7 -34
- package/src/components/RawModal.tsx +9 -8
- package/src/components/ReanchorConfirm.tsx +2 -2
- package/src/components/SettingsModal.tsx +11 -89
- package/src/components/TabBar.tsx +4 -4
- package/src/components/TableOfContents.tsx +5 -5
- package/src/components/comments/CommentInput.tsx +7 -35
- package/src/components/comments/CommentListItem.tsx +9 -11
- package/src/components/comments/CommentManager.tsx +53 -37
- package/src/components/comments/CommentNav.tsx +14 -14
- package/src/components/ui/ActionLink.tsx +14 -18
- package/src/components/ui/Button.tsx +42 -43
- package/src/components/ui/Dialog.tsx +73 -113
- package/src/components/ui/DropdownMenu.tsx +113 -69
- package/src/components/ui/Text.tsx +30 -37
- package/src/contexts/CommentContext.tsx +75 -106
- package/src/contexts/LocaleContext.tsx +45 -4
- package/src/contexts/PositionsContext.tsx +16 -0
- package/src/contexts/SettingsContext.tsx +133 -0
- package/src/hooks/useClickOutside.ts +0 -4
- package/src/hooks/useCommentNavigation.ts +6 -29
- package/src/hooks/useComments.ts +6 -18
- package/src/hooks/useDocument.ts +35 -34
- package/src/hooks/useHeadings.test.ts +8 -50
- package/src/hooks/useHeadings.ts +5 -88
- package/src/hooks/useScrollSpy.ts +10 -14
- package/src/hooks/useTextSelection.ts +1 -38
- package/src/lib/__fixtures__/bench-data.ts +1 -41
- package/src/lib/anchor.bench.ts +57 -67
- package/src/lib/anchor.test.ts +5 -1
- package/src/lib/anchor.ts +13 -93
- package/src/lib/comment-storage.test.ts +4 -4
- package/src/lib/comment-storage.ts +2 -46
- package/src/lib/export.ts +7 -13
- package/src/lib/highlight/core.test.ts +1 -1
- package/src/lib/highlight/dom.ts +5 -68
- package/src/lib/highlight/highlighter.ts +102 -262
- package/src/lib/highlight/resolver.ts +112 -0
- package/src/lib/highlight/types.ts +0 -35
- package/src/lib/highlight/worker.ts +45 -0
- package/src/lib/i18n/en.ts +1 -50
- package/src/lib/i18n/ja.ts +1 -50
- package/src/lib/i18n/types.ts +1 -49
- package/src/lib/margin-layout.ts +5 -27
- package/src/lib/positions.ts +150 -0
- package/src/lib/utils.ts +2 -19
- package/src/schema.ts +81 -0
- package/src/{server/index.ts → server.ts} +111 -81
- package/src/{store/index.ts → store.ts} +14 -46
- package/vite.config.ts +8 -0
- package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
- package/src/components/DocumentViewer/InlineCode.tsx +0 -60
- package/src/components/DocumentViewer/index.ts +0 -1
- package/src/components/FloatingTOC.tsx +0 -61
- package/src/components/ShortcutCapture.tsx +0 -48
- package/src/components/ShortcutList.tsx +0 -198
- package/src/components/comments/CommentMinimap.tsx +0 -62
- package/src/components/ui/ActionBar.tsx +0 -16
- package/src/components/ui/SeparatorDot.tsx +0 -9
- package/src/contexts/LayoutContext.tsx +0 -88
- package/src/hooks/useClipboard.ts +0 -82
- package/src/hooks/useEditorScheme.ts +0 -51
- package/src/hooks/useFontPreference.ts +0 -59
- package/src/hooks/useKeybindings.ts +0 -108
- package/src/hooks/useKeyboardShortcuts.ts +0 -63
- package/src/hooks/useLayoutMode.ts +0 -44
- package/src/hooks/useLocalePreference.ts +0 -42
- package/src/hooks/useReanchorMode.ts +0 -33
- package/src/hooks/useScrollMetrics.ts +0 -56
- package/src/hooks/useThemePreference.ts +0 -66
- package/src/lib/comment-storage.bench.ts +0 -63
- package/src/lib/context.bench.ts +0 -41
- package/src/lib/context.test.ts +0 -224
- package/src/lib/context.ts +0 -193
- package/src/lib/editor-links.ts +0 -59
- package/src/lib/export.bench.ts +0 -35
- package/src/lib/highlight/colors.ts +0 -37
- package/src/lib/highlight/core.ts +0 -54
- package/src/lib/highlight/index.ts +0 -23
- package/src/lib/highlight/script-builder.ts +0 -485
- package/src/lib/html-processor.test.tsx +0 -170
- package/src/lib/html-processor.tsx +0 -95
- package/src/lib/i18n/completeness.test.ts +0 -51
- package/src/lib/i18n/translations.test.ts +0 -39
- package/src/lib/layout-constants.ts +0 -12
- package/src/lib/margin-layout.bench.ts +0 -28
- package/src/lib/scroll.test.ts +0 -118
- package/src/lib/scroll.ts +0 -47
- package/src/lib/shortcut-registry.test.ts +0 -173
- package/src/lib/shortcut-registry.ts +0 -209
- package/src/lib/utils.test.ts +0 -110
- package/src/store/index.test.ts +0 -242
- package/src/types/index.ts +0 -127
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { expect, test } from "@playwright/test";
|
|
2
|
+
import { getFixturePath, TIERS } from "./fixtures/generate";
|
|
3
|
+
import {
|
|
4
|
+
measureInteraction,
|
|
5
|
+
reportInteraction,
|
|
6
|
+
waitForHighlightCount,
|
|
7
|
+
} from "./utils/metrics";
|
|
8
|
+
import { spawnPerfCli } from "./utils/perf-cli";
|
|
9
|
+
|
|
10
|
+
// Use the medium tier — most representative of real usage
|
|
11
|
+
const tier = TIERS[0];
|
|
12
|
+
|
|
13
|
+
test(`add-comment: ${tier.name} (${tier.lines} lines, ${tier.comments} comments)`, async ({
|
|
14
|
+
page,
|
|
15
|
+
}, testInfo) => {
|
|
16
|
+
const fixturePath = getFixturePath(tier);
|
|
17
|
+
const { url, cleanup } = await spawnPerfCli(fixturePath, { port: 4620 });
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await page.goto(url);
|
|
21
|
+
await waitForHighlightCount(page, tier.comments);
|
|
22
|
+
await page.waitForTimeout(300);
|
|
23
|
+
|
|
24
|
+
// Capture actual highlight count as baseline (may differ from tier.comments)
|
|
25
|
+
const baselineCount = await page.evaluate(() => {
|
|
26
|
+
const marks = document.querySelectorAll("mark[data-comment-id]");
|
|
27
|
+
return new Set([...marks].map((m) => m.getAttribute("data-comment-id")))
|
|
28
|
+
.size;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Find a text that isn't already highlighted — use a line near the end
|
|
32
|
+
const selectionText = await page.evaluate(() => {
|
|
33
|
+
const article = document.querySelector("article");
|
|
34
|
+
if (!article) throw new Error("Article not found");
|
|
35
|
+
|
|
36
|
+
// Find paragraph text near the bottom of the document
|
|
37
|
+
const paragraphs = article.querySelectorAll("p");
|
|
38
|
+
const target = paragraphs[paragraphs.length - 2];
|
|
39
|
+
if (!target?.textContent) throw new Error("No paragraph found");
|
|
40
|
+
|
|
41
|
+
// Use first 30 chars
|
|
42
|
+
return target.textContent.slice(0, 30).trim();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Select text via custom event
|
|
46
|
+
await page.evaluate((text) => {
|
|
47
|
+
const article = document.querySelector("article");
|
|
48
|
+
if (!article) throw new Error("Article not found");
|
|
49
|
+
|
|
50
|
+
const walker = document.createTreeWalker(article, NodeFilter.SHOW_TEXT);
|
|
51
|
+
let currentOffset = 0;
|
|
52
|
+
|
|
53
|
+
while (walker.nextNode()) {
|
|
54
|
+
const textNode = walker.currentNode as Text;
|
|
55
|
+
const content = textNode.textContent || "";
|
|
56
|
+
const index = content.indexOf(text);
|
|
57
|
+
|
|
58
|
+
if (index !== -1) {
|
|
59
|
+
const startOffset = currentOffset + index;
|
|
60
|
+
const endOffset = startOffset + text.length;
|
|
61
|
+
window.dispatchEvent(
|
|
62
|
+
new CustomEvent("test:select-text", {
|
|
63
|
+
detail: { text, startOffset, endOffset },
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
currentOffset += content.length;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
throw new Error(`Text "${text}" not found`);
|
|
73
|
+
}, selectionText);
|
|
74
|
+
|
|
75
|
+
// Wait for comment input to appear
|
|
76
|
+
const textarea = page.locator(
|
|
77
|
+
'textarea[placeholder="Add your comment..."]',
|
|
78
|
+
);
|
|
79
|
+
await textarea.waitFor({ state: "visible", timeout: 10_000 });
|
|
80
|
+
|
|
81
|
+
// Fill in the comment
|
|
82
|
+
await textarea.fill("Performance benchmark comment");
|
|
83
|
+
|
|
84
|
+
// Mark start and click Add
|
|
85
|
+
const duration = await measureInteraction(
|
|
86
|
+
page,
|
|
87
|
+
"add-comment",
|
|
88
|
+
async () => {
|
|
89
|
+
await page.getByRole("button", { name: "Add" }).click();
|
|
90
|
+
},
|
|
91
|
+
async () => {
|
|
92
|
+
await page.waitForFunction((expected) => {
|
|
93
|
+
const marks = document.querySelectorAll("mark[data-comment-id]");
|
|
94
|
+
const ids = new Set(
|
|
95
|
+
[...marks].map((m) => m.getAttribute("data-comment-id")),
|
|
96
|
+
);
|
|
97
|
+
return ids.size > expected;
|
|
98
|
+
}, baselineCount);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
reportInteraction(
|
|
103
|
+
testInfo,
|
|
104
|
+
`add-comment: time to new highlight (${tier.name})`,
|
|
105
|
+
duration,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// Verify the highlight actually appeared
|
|
109
|
+
const finalCount = await page.evaluate(() => {
|
|
110
|
+
const marks = document.querySelectorAll("mark[data-comment-id]");
|
|
111
|
+
return new Set([...marks].map((m) => m.getAttribute("data-comment-id")))
|
|
112
|
+
.size;
|
|
113
|
+
});
|
|
114
|
+
expect(finalCount).toBeGreaterThan(tier.comments);
|
|
115
|
+
} finally {
|
|
116
|
+
await cleanup();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
// ─── Types ───────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
interface Comment {
|
|
9
|
+
id: string;
|
|
10
|
+
selectedText: string;
|
|
11
|
+
comment: string;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
startOffset: number;
|
|
14
|
+
endOffset: number;
|
|
15
|
+
lineHint: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface CommentFile {
|
|
19
|
+
source: string;
|
|
20
|
+
hash: string;
|
|
21
|
+
version: number;
|
|
22
|
+
comments: Comment[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Tier {
|
|
26
|
+
name: string;
|
|
27
|
+
lines: number;
|
|
28
|
+
comments: number;
|
|
29
|
+
fileName: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const TIERS: Tier[] = [
|
|
33
|
+
{ name: "medium", lines: 1000, comments: 100, fileName: "medium.md" },
|
|
34
|
+
{ name: "large", lines: 3000, comments: 200, fileName: "large.md" },
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
// Second medium doc for tab-switch tests
|
|
38
|
+
export const TAB_SWITCH_TIER: Tier = {
|
|
39
|
+
name: "medium-b",
|
|
40
|
+
lines: 1000,
|
|
41
|
+
comments: 100,
|
|
42
|
+
fileName: "medium-b.md",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const FIXTURES_DIR = path.join(os.tmpdir(), "readit-perf-fixtures");
|
|
46
|
+
|
|
47
|
+
// ─── Markdown generation ─────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
function generateMarkdownDoc(lineCount: number, seed: number): string {
|
|
50
|
+
const lines: string[] = [];
|
|
51
|
+
lines.push(`# Performance Benchmark Document (seed=${seed})`);
|
|
52
|
+
lines.push("");
|
|
53
|
+
lines.push(
|
|
54
|
+
"This document is auto-generated for performance benchmarking. It contains realistic markdown patterns.",
|
|
55
|
+
);
|
|
56
|
+
lines.push("");
|
|
57
|
+
|
|
58
|
+
let sectionNum = 1;
|
|
59
|
+
while (lines.length < lineCount) {
|
|
60
|
+
lines.push(`## Section ${sectionNum}: Topic Area ${sectionNum}`);
|
|
61
|
+
lines.push("");
|
|
62
|
+
lines.push(
|
|
63
|
+
`This section covers topic ${sectionNum} in detail. It includes various formatting such as **bold text**, *italic text*, and \`inline code\`. The content is designed to exercise the rendering pipeline.`,
|
|
64
|
+
);
|
|
65
|
+
lines.push("");
|
|
66
|
+
|
|
67
|
+
// Paragraph
|
|
68
|
+
lines.push(
|
|
69
|
+
`When reviewing documents of this complexity, it is important to consider the performance implications of rendering each element. Section ${sectionNum} demonstrates how the margin notes system handles comments distributed across a long document.`,
|
|
70
|
+
);
|
|
71
|
+
lines.push("");
|
|
72
|
+
|
|
73
|
+
// List
|
|
74
|
+
for (let j = 1; j <= 4; j++) {
|
|
75
|
+
lines.push(
|
|
76
|
+
`- Item ${j} in section ${sectionNum}: a list entry with enough text to be selectable`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
lines.push("");
|
|
80
|
+
|
|
81
|
+
// Code block
|
|
82
|
+
lines.push("```typescript");
|
|
83
|
+
lines.push(`function processSection${sectionNum}(data: unknown) {`);
|
|
84
|
+
lines.push(` const result = validate(data);`);
|
|
85
|
+
lines.push(
|
|
86
|
+
` if (!result.ok) throw new Error("Section ${sectionNum} failed");`,
|
|
87
|
+
);
|
|
88
|
+
lines.push(` return transform(result.value);`);
|
|
89
|
+
lines.push("}");
|
|
90
|
+
lines.push("```");
|
|
91
|
+
lines.push("");
|
|
92
|
+
|
|
93
|
+
// Another paragraph
|
|
94
|
+
lines.push(
|
|
95
|
+
`The conclusion of section ${sectionNum} summarizes the key findings and provides actionable recommendations for the reader. This paragraph exists to ensure sufficient text density for highlight testing.`,
|
|
96
|
+
);
|
|
97
|
+
lines.push("");
|
|
98
|
+
|
|
99
|
+
// Table every 4th section
|
|
100
|
+
if (sectionNum % 4 === 0) {
|
|
101
|
+
lines.push("| Metric | Before | After | Change |");
|
|
102
|
+
lines.push("|--------|--------|-------|--------|");
|
|
103
|
+
lines.push(
|
|
104
|
+
`| Latency | ${sectionNum * 10}ms | ${sectionNum * 5}ms | -50% |`,
|
|
105
|
+
);
|
|
106
|
+
lines.push(
|
|
107
|
+
`| Throughput | ${sectionNum * 100} | ${sectionNum * 200} | +100% |`,
|
|
108
|
+
);
|
|
109
|
+
lines.push("");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Blockquote every 5th section
|
|
113
|
+
if (sectionNum % 5 === 0) {
|
|
114
|
+
lines.push(
|
|
115
|
+
`> Note: Section ${sectionNum} contains important observations about system behavior under load.`,
|
|
116
|
+
);
|
|
117
|
+
lines.push("");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
sectionNum++;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return lines.slice(0, lineCount).join("\n");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ─── Comment generation ──────────────────────────────────────────────
|
|
127
|
+
|
|
128
|
+
function makeComment(
|
|
129
|
+
index: number,
|
|
130
|
+
doc: string,
|
|
131
|
+
totalComments: number,
|
|
132
|
+
): Comment {
|
|
133
|
+
const lines = doc.split("\n");
|
|
134
|
+
|
|
135
|
+
// Distribute comments evenly across the document, skipping empty lines and headers
|
|
136
|
+
const contentLines: { lineIndex: number; text: string }[] = [];
|
|
137
|
+
for (let i = 0; i < lines.length; i++) {
|
|
138
|
+
const line = lines[i];
|
|
139
|
+
if (
|
|
140
|
+
line.length > 20 &&
|
|
141
|
+
!line.startsWith("#") &&
|
|
142
|
+
!line.startsWith("```") &&
|
|
143
|
+
!line.startsWith("|") &&
|
|
144
|
+
!line.startsWith(">") &&
|
|
145
|
+
!line.startsWith("- ")
|
|
146
|
+
) {
|
|
147
|
+
contentLines.push({ lineIndex: i, text: line });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Pick a content line for this comment
|
|
152
|
+
const targetIdx = Math.floor(
|
|
153
|
+
(index / totalComments) * (contentLines.length - 1),
|
|
154
|
+
);
|
|
155
|
+
const target = contentLines[Math.min(targetIdx, contentLines.length - 1)];
|
|
156
|
+
|
|
157
|
+
// Select a substring from the target line
|
|
158
|
+
const selectStart = 0;
|
|
159
|
+
const selectEnd = Math.min(40, target.text.length);
|
|
160
|
+
const selectedText = target.text.slice(selectStart, selectEnd);
|
|
161
|
+
|
|
162
|
+
// Compute character offset in the full document
|
|
163
|
+
let startOffset = 0;
|
|
164
|
+
for (let i = 0; i < target.lineIndex; i++) {
|
|
165
|
+
startOffset += lines[i].length + 1; // +1 for \n
|
|
166
|
+
}
|
|
167
|
+
startOffset += selectStart;
|
|
168
|
+
const endOffset = startOffset + selectedText.length;
|
|
169
|
+
|
|
170
|
+
// Line hint (1-indexed)
|
|
171
|
+
const lineHint = `L${target.lineIndex + 1}`;
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
id: `perf${String(index).padStart(4, "0")}`,
|
|
175
|
+
selectedText,
|
|
176
|
+
comment: `Review comment #${index + 1}: This section needs attention regarding clarity and accuracy.`,
|
|
177
|
+
createdAt: "2025-01-01T00:00:00.000Z",
|
|
178
|
+
startOffset,
|
|
179
|
+
endOffset,
|
|
180
|
+
lineHint,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ─── Comment serialization (standalone, no imports from src/) ────────
|
|
185
|
+
|
|
186
|
+
function computeHash(content: string): string {
|
|
187
|
+
return crypto.createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function serializeComments(file: CommentFile): string {
|
|
191
|
+
const lines: string[] = [];
|
|
192
|
+
|
|
193
|
+
lines.push("---");
|
|
194
|
+
lines.push(`source: ${file.source}`);
|
|
195
|
+
lines.push(`hash: ${file.hash}`);
|
|
196
|
+
lines.push(`version: ${file.version}`);
|
|
197
|
+
lines.push("---");
|
|
198
|
+
lines.push("");
|
|
199
|
+
|
|
200
|
+
for (const comment of file.comments) {
|
|
201
|
+
// Metadata
|
|
202
|
+
lines.push(
|
|
203
|
+
`<!-- c:${comment.id}|${comment.lineHint}|${comment.createdAt} -->`,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
// Selected text as blockquote
|
|
207
|
+
const quotedLines = comment.selectedText
|
|
208
|
+
.split("\n")
|
|
209
|
+
.map((line) => `> ${line}`);
|
|
210
|
+
lines.push(...quotedLines);
|
|
211
|
+
|
|
212
|
+
// Comment body
|
|
213
|
+
if (comment.comment) {
|
|
214
|
+
lines.push("");
|
|
215
|
+
lines.push(comment.comment);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
lines.push("");
|
|
219
|
+
lines.push("---");
|
|
220
|
+
lines.push("");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return lines.join("\n");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Compute comment path using realpath to match the server's path resolution.
|
|
228
|
+
* The server uses fs.realpath() which resolves symlinks (e.g., /var → /private/var on macOS).
|
|
229
|
+
* The sourcePath must exist on disk before calling this.
|
|
230
|
+
*/
|
|
231
|
+
async function getCommentPathReal(sourcePath: string): Promise<string> {
|
|
232
|
+
const real = await fs.realpath(path.resolve(sourcePath));
|
|
233
|
+
const normalized = real.replace(/^\//, "").replace(/^[A-Z]:[\\/]/, "");
|
|
234
|
+
const ext = path.extname(normalized);
|
|
235
|
+
const withoutExt = normalized.slice(0, -ext.length || undefined);
|
|
236
|
+
return path.join(
|
|
237
|
+
os.homedir(),
|
|
238
|
+
".readit",
|
|
239
|
+
"comments",
|
|
240
|
+
`${withoutExt}.comments.md`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Sync version for cleanup (file may not exist) */
|
|
245
|
+
function getCommentPathSync(sourcePath: string): string {
|
|
246
|
+
let absolute: string;
|
|
247
|
+
try {
|
|
248
|
+
absolute = require("node:fs").realpathSync(path.resolve(sourcePath));
|
|
249
|
+
} catch {
|
|
250
|
+
absolute = path.resolve(sourcePath);
|
|
251
|
+
}
|
|
252
|
+
const normalized = absolute.replace(/^\//, "").replace(/^[A-Z]:[\\/]/, "");
|
|
253
|
+
const ext = path.extname(normalized);
|
|
254
|
+
const withoutExt = normalized.slice(0, -ext.length || undefined);
|
|
255
|
+
return path.join(
|
|
256
|
+
os.homedir(),
|
|
257
|
+
".readit",
|
|
258
|
+
"comments",
|
|
259
|
+
`${withoutExt}.comments.md`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ─── Public API ──────────────────────────────────────────────────────
|
|
264
|
+
|
|
265
|
+
export function getFixturePath(tier: Tier): string {
|
|
266
|
+
return path.join(FIXTURES_DIR, tier.fileName);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export async function generateFixtures(): Promise<void> {
|
|
270
|
+
await fs.mkdir(FIXTURES_DIR, { recursive: true });
|
|
271
|
+
|
|
272
|
+
const allTiers = [...TIERS, TAB_SWITCH_TIER];
|
|
273
|
+
|
|
274
|
+
for (const tier of allTiers) {
|
|
275
|
+
const doc = generateMarkdownDoc(tier.lines, tier.lines);
|
|
276
|
+
const fixturePath = getFixturePath(tier);
|
|
277
|
+
await fs.writeFile(fixturePath, doc, "utf-8");
|
|
278
|
+
|
|
279
|
+
// Generate and write comment file
|
|
280
|
+
const comments: Comment[] = [];
|
|
281
|
+
for (let i = 0; i < tier.comments; i++) {
|
|
282
|
+
comments.push(makeComment(i, doc, tier.comments));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Use realpath for the comment path (file must exist first)
|
|
286
|
+
const realFixturePath = await fs.realpath(fixturePath);
|
|
287
|
+
|
|
288
|
+
const commentFile: CommentFile = {
|
|
289
|
+
source: realFixturePath,
|
|
290
|
+
hash: computeHash(doc),
|
|
291
|
+
version: 1,
|
|
292
|
+
comments,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const commentPath = await getCommentPathReal(fixturePath);
|
|
296
|
+
await fs.mkdir(path.dirname(commentPath), { recursive: true });
|
|
297
|
+
await fs.writeFile(commentPath, serializeComments(commentFile), "utf-8");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export async function cleanupFixtures(): Promise<void> {
|
|
302
|
+
// Collect comment paths before removing fixtures (need realpath while files exist)
|
|
303
|
+
const commentPaths: string[] = [];
|
|
304
|
+
const allTiers = [...TIERS, TAB_SWITCH_TIER];
|
|
305
|
+
for (const tier of allTiers) {
|
|
306
|
+
commentPaths.push(getCommentPathSync(getFixturePath(tier)));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Remove fixture files
|
|
310
|
+
try {
|
|
311
|
+
await fs.rm(FIXTURES_DIR, { recursive: true, force: true });
|
|
312
|
+
} catch {
|
|
313
|
+
// Ignore if already removed
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Remove comment files
|
|
317
|
+
for (const commentPath of commentPaths) {
|
|
318
|
+
try {
|
|
319
|
+
await fs.unlink(commentPath);
|
|
320
|
+
} catch {
|
|
321
|
+
// Ignore if already removed
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Allow running directly: bun e2e/perf/fixtures/generate.ts
|
|
327
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
328
|
+
generateFixtures().then(() => {
|
|
329
|
+
console.log(`Fixtures generated in ${FIXTURES_DIR}`);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { test } from "@playwright/test";
|
|
2
|
+
import { getFixturePath, TIERS } from "./fixtures/generate";
|
|
3
|
+
import { collectLoadMetrics, reportLoadMetrics } from "./utils/metrics";
|
|
4
|
+
import { spawnPerfCli } from "./utils/perf-cli";
|
|
5
|
+
|
|
6
|
+
const ITERATIONS = 3;
|
|
7
|
+
|
|
8
|
+
for (const tier of TIERS) {
|
|
9
|
+
test(`initial-load: ${tier.name} (${tier.lines} lines, ${tier.comments} comments)`, async ({
|
|
10
|
+
page,
|
|
11
|
+
}, testInfo) => {
|
|
12
|
+
const fixturePath = getFixturePath(tier);
|
|
13
|
+
const { url, cleanup } = await spawnPerfCli(fixturePath, {
|
|
14
|
+
port: 4600 + TIERS.indexOf(tier),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const results: (typeof collected)[] = [];
|
|
19
|
+
let collected!: Awaited<ReturnType<typeof collectLoadMetrics>>;
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < ITERATIONS; i++) {
|
|
22
|
+
// Clear performance entries between iterations
|
|
23
|
+
if (i > 0) {
|
|
24
|
+
await page.evaluate(() => performance.clearResourceTimings());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
collected = await collectLoadMetrics(page, url, tier.comments);
|
|
28
|
+
results.push(collected);
|
|
29
|
+
|
|
30
|
+
// Navigate away between iterations to force full reload
|
|
31
|
+
if (i < ITERATIONS - 1) {
|
|
32
|
+
await page.goto("about:blank");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Report median
|
|
37
|
+
results.sort((a, b) => a.allHighlightsPainted - b.allHighlightsPainted);
|
|
38
|
+
const median = results[Math.floor(results.length / 2)];
|
|
39
|
+
|
|
40
|
+
reportLoadMetrics(
|
|
41
|
+
testInfo,
|
|
42
|
+
`initial-load (${tier.name}: ${tier.lines} lines, ${tier.comments} comments)`,
|
|
43
|
+
median,
|
|
44
|
+
);
|
|
45
|
+
} finally {
|
|
46
|
+
await cleanup();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { generateFixtures } from "./fixtures/generate";
|
|
5
|
+
|
|
6
|
+
async function globalSetup() {
|
|
7
|
+
// Build the app if dist doesn't exist
|
|
8
|
+
const distIndex = resolve(import.meta.dirname, "../../dist/cli.js");
|
|
9
|
+
if (!existsSync(distIndex)) {
|
|
10
|
+
console.log("[perf] Building app...");
|
|
11
|
+
execFileSync("bun", ["run", "build"], {
|
|
12
|
+
cwd: resolve(import.meta.dirname, "../.."),
|
|
13
|
+
stdio: "inherit",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Generate fixture files and comment files
|
|
18
|
+
console.log("[perf] Generating fixtures...");
|
|
19
|
+
await generateFixtures();
|
|
20
|
+
console.log("[perf] Setup complete.");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default globalSetup;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { test } from "@playwright/test";
|
|
2
|
+
import { getFixturePath, TIERS } from "./fixtures/generate";
|
|
3
|
+
import {
|
|
4
|
+
collectScrollMetrics,
|
|
5
|
+
reportScrollMetrics,
|
|
6
|
+
waitForHighlightCount,
|
|
7
|
+
} from "./utils/metrics";
|
|
8
|
+
import { spawnPerfCli } from "./utils/perf-cli";
|
|
9
|
+
|
|
10
|
+
for (const tier of TIERS) {
|
|
11
|
+
test(`scroll: ${tier.name} (${tier.lines} lines, ${tier.comments} comments)`, async ({
|
|
12
|
+
page,
|
|
13
|
+
}, testInfo) => {
|
|
14
|
+
const fixturePath = getFixturePath(tier);
|
|
15
|
+
const { url, cleanup } = await spawnPerfCli(fixturePath, {
|
|
16
|
+
port: 4610 + TIERS.indexOf(tier),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await page.goto(url);
|
|
21
|
+
|
|
22
|
+
// Wait for all highlights to be painted before starting scroll
|
|
23
|
+
await waitForHighlightCount(page, tier.comments);
|
|
24
|
+
|
|
25
|
+
// Small pause for layout to settle
|
|
26
|
+
await page.waitForTimeout(500);
|
|
27
|
+
|
|
28
|
+
const metrics = await collectScrollMetrics(page);
|
|
29
|
+
|
|
30
|
+
reportScrollMetrics(
|
|
31
|
+
testInfo,
|
|
32
|
+
`scroll (${tier.name}: ${tier.lines} lines, ${tier.comments} comments)`,
|
|
33
|
+
metrics,
|
|
34
|
+
);
|
|
35
|
+
} finally {
|
|
36
|
+
await cleanup();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { test } from "@playwright/test";
|
|
2
|
+
import { getFixturePath, TAB_SWITCH_TIER, TIERS } from "./fixtures/generate";
|
|
3
|
+
import {
|
|
4
|
+
measureInteraction,
|
|
5
|
+
reportInteraction,
|
|
6
|
+
waitForHighlightCount,
|
|
7
|
+
} from "./utils/metrics";
|
|
8
|
+
import { spawnPerfCli } from "./utils/perf-cli";
|
|
9
|
+
|
|
10
|
+
const tierA = TIERS[0]; // medium
|
|
11
|
+
const tierB = TAB_SWITCH_TIER; // medium-b
|
|
12
|
+
|
|
13
|
+
test(`tab-switch: between two ${tierA.name} documents`, async ({
|
|
14
|
+
page,
|
|
15
|
+
}, testInfo) => {
|
|
16
|
+
const pathA = getFixturePath(tierA);
|
|
17
|
+
const pathB = getFixturePath(tierB);
|
|
18
|
+
|
|
19
|
+
const { url, cleanup } = await spawnPerfCli([pathA, pathB], { port: 4640 });
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await page.goto(url);
|
|
23
|
+
|
|
24
|
+
// Wait for first document to be fully loaded with highlights
|
|
25
|
+
await waitForHighlightCount(page, tierA.comments);
|
|
26
|
+
await page.waitForTimeout(500);
|
|
27
|
+
|
|
28
|
+
// Find the second tab and measure the switch
|
|
29
|
+
const duration = await measureInteraction(
|
|
30
|
+
page,
|
|
31
|
+
"tab-switch",
|
|
32
|
+
async () => {
|
|
33
|
+
// Click the second tab — tabs display file names
|
|
34
|
+
const tabs = page.locator('[role="tab"], button').filter({
|
|
35
|
+
hasText: tierB.fileName.replace(".md", ""),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// If tabs aren't labeled with role="tab", find by filename text
|
|
39
|
+
const tabCount = await tabs.count();
|
|
40
|
+
if (tabCount > 0) {
|
|
41
|
+
await tabs.first().click();
|
|
42
|
+
} else {
|
|
43
|
+
// Fallback: find any clickable element containing the filename
|
|
44
|
+
const allButtons = page.locator("button, a");
|
|
45
|
+
const count = await allButtons.count();
|
|
46
|
+
for (let i = 0; i < count; i++) {
|
|
47
|
+
const text = await allButtons.nth(i).textContent();
|
|
48
|
+
if (text?.includes("medium-b")) {
|
|
49
|
+
await allButtons.nth(i).click();
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
async () => {
|
|
56
|
+
// Wait for the second document's highlights to paint
|
|
57
|
+
await waitForHighlightCount(page, tierB.comments, 60_000);
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
reportInteraction(
|
|
62
|
+
testInfo,
|
|
63
|
+
`tab-switch: ${tierA.name} → ${tierB.name} (${tierA.comments} → ${tierB.comments} comments)`,
|
|
64
|
+
duration,
|
|
65
|
+
);
|
|
66
|
+
} finally {
|
|
67
|
+
await cleanup();
|
|
68
|
+
}
|
|
69
|
+
});
|