Skip to content

Commit 644c6af

Browse files
fix: resolve 8 issues from code review
1. ci.ts: fix --pr arg parsing reading args[0] when flag absent 2. ci.ts: add isDirectRun guard so main() doesn't run on import 3. capture.ts: fix stories.json parsing — handle Storybook v7+ wrapper 4. supabase.ts: fix storage path mismatch in insertDiffs (include runId) 5. prefilter.ts: replace queue.shift() with index pointer (O(1) dequeue) 6. vr-init.md: remove nonexistent --config flag from capture command 7. vr-watch.md: replace nonexistent --routes flag with --scope=staged 8. comment.ts: escape pipe/newline in Gemini output for markdown tables All 44 tests passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c1d817e commit 644c6af

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

commands/vr-init.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Initialize DojoWatch in the current project. This sets up the configuration, dis
3838

3939
7. **Initial capture.** If the user confirms, remind them to start their dev server, then run:
4040
```bash
41-
npx tsx ${CLAUDE_PLUGIN_ROOT}/scripts/capture.ts --config .dojowatch/config.json --scope all
41+
npx tsx ${CLAUDE_PLUGIN_ROOT}/scripts/capture.ts --scope=all
4242
```
4343

4444
8. **Promote to baselines.** Run:

commands/vr-watch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Start a file watcher that re-captures affected routes when source files change,
1818
- Look up the saved file in `.dojowatch/routeMap.json` to find affected routes
1919
- If the file maps to routes, run a scoped capture:
2020
```bash
21-
npx tsx ${CLAUDE_PLUGIN_ROOT}/scripts/capture.ts --routes <affected-routes>
21+
npx tsx ${CLAUDE_PLUGIN_ROOT}/scripts/capture.ts --scope=staged
2222
```
2323
- Run quick prefilter comparison against baselines
2424
- Report any visual changes inline (pixel diff count, affected areas)

scripts/capture.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,15 @@ export async function captureStorybook(
124124
);
125125
}
126126

127-
const storiesData = (await response.json()) as Record<string, { id: string; title: string; name: string }>;
128-
const storyIds = Object.keys(storiesData);
127+
const rawData = (await response.json()) as
128+
| { v: number; stories: Record<string, { id: string; title: string; name: string }> }
129+
| Record<string, { id: string; title: string; name: string }>;
130+
131+
// Storybook v7+ wraps stories under a "stories" key
132+
const storiesData = "stories" in rawData && typeof rawData.stories === "object"
133+
? rawData.stories
134+
: rawData;
135+
const storyIds = Object.keys(storiesData).filter((k) => k !== "v");
129136

130137
console.log(pc.dim(` Found ${storyIds.length} Storybook stories`));
131138

scripts/ci.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import type { CheckRun } from "./types.js";
2121

2222
async function main(): Promise<void> {
2323
const args = process.argv.slice(2);
24-
const prArg = args.find((a) => a.startsWith("--pr="))?.split("=")[1]
25-
?? args[args.indexOf("--pr") + 1];
24+
const prEqArg = args.find((a) => a.startsWith("--pr="))?.split("=")[1];
25+
const prFlagIdx = args.indexOf("--pr");
26+
const prSpaceArg = prFlagIdx !== -1 ? args[prFlagIdx + 1] : undefined;
27+
const prArg = prEqArg ?? prSpaceArg;
2628
const prNumber = prArg ? parseInt(prArg, 10) : undefined;
2729
const uploadFlag = args.includes("--upload");
2830

@@ -210,7 +212,12 @@ function getGitCommitSha(): string {
210212
}
211213
}
212214

213-
main().catch((err) => {
214-
console.error(pc.red(`CI failed: ${err}`));
215-
process.exit(1);
216-
});
215+
const isDirectRun =
216+
process.argv[1]?.endsWith("ci.ts") ||
217+
process.argv[1]?.endsWith("ci.js");
218+
if (isDirectRun) {
219+
main().catch((err) => {
220+
console.error(pc.red(`CI failed: ${err}`));
221+
process.exit(1);
222+
});
223+
}

scripts/comment.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { execFileSync } from "node:child_process";
22
import pc from "picocolors";
33
import type { AnalysisResult, CheckRun, DiffResult } from "./types.js";
44

5+
/** Escape pipe and newline characters for use inside markdown table cells. */
6+
function escMd(text: string): string {
7+
return text.replace(/\|/g, "\\|").replace(/\n/g, " ");
8+
}
9+
510
/**
611
* Generate a markdown comment body from analysis results.
712
*/
@@ -53,7 +58,7 @@ export function generateCommentMarkdown(
5358
const diffUrl = diffUrls?.get(name);
5459
const thumbnailCol = diffUrl ? ` [![diff](${diffUrl})](${diffUrl})` : "";
5560
lines.push(
56-
`| ${sev} | ${screenshot}: ${diff.element}${thumbnailCol} | ${diff.description} | ${diff.suggested_fix ?? "—"} |`
61+
`| ${sev} | ${escMd(screenshot)}: ${escMd(diff.element)}${thumbnailCol} | ${escMd(diff.description)} | ${escMd(diff.suggested_fix ?? "—")} |`
5762
);
5863
}
5964
lines.push("");

scripts/prefilter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ function floodFill(
129129
): Array<[number, number]> {
130130
const pixels: Array<[number, number]> = [];
131131
const queue: Array<[number, number]> = [[startX, startY]];
132+
let queueHead = 0;
132133

133134
visited[startY * width + startX] = 1;
134135

135-
while (queue.length > 0) {
136-
const [cx, cy] = queue.shift()!;
136+
while (queueHead < queue.length) {
137+
const [cx, cy] = queue[queueHead++];;
137138
pixels.push([cx, cy]);
138139

139140
// Check 8 neighbors (including diagonals)

scripts/supabase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ export async function insertDiffs(
186186
run_id: runId,
187187
name: pf.name,
188188
viewport: pf.viewport,
189-
baseline_storage_path: `${project}/${pf.name}.png`,
190-
current_storage_path: `${project}/captures/${pf.name}.png`,
189+
baseline_storage_path: `${project}/${pf.name}-${pf.viewport}.png`,
190+
current_storage_path: `${project}/captures/${runId}/${pf.name}.png`,
191191
diff_storage_path: pf.diffImagePath
192-
? `${project}/diffs/${basename(pf.diffImagePath)}`
192+
? `${project}/diffs/${runId}/${basename(pf.diffImagePath)}`
193193
: null,
194194
pixel_diff_percent: pf.pixelDiffPercent,
195195
tier: pf.tier,

0 commit comments

Comments
 (0)