Skip to content

Commit 0f88b1e

Browse files
Merge pull request #31 from DeDuckProject/fix/lazy-playwright-import
fix: lazy-load Playwright to prevent it leaking into check-trigger bu…
2 parents 685c371 + 28dbb2a commit 0f88b1e

6 files changed

Lines changed: 61 additions & 34 deletions

File tree

packages/action/dist/check.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25800,12 +25800,6 @@ function computeChangeMagnitude(files) {
2580025800
return files.reduce((sum, f) => sum + f.additions + f.deletions, 0);
2580125801
}
2580225802

25803-
// ../core/dist/recorder/playwright-runner.js
25804-
var import_test = require("@playwright/test");
25805-
25806-
// ../core/dist/recorder/fallback.js
25807-
var import_test2 = require("@playwright/test");
25808-
2580925803
// ../core/dist/config/loader.js
2581025804
var import_node_url = require("node:url");
2581125805
var import_node_fs = require("node:fs");
@@ -30108,6 +30102,15 @@ async function check() {
3010830102
core.setOutput("should-run", "false");
3010930103
return;
3011030104
}
30105+
try {
30106+
await octokit.rest.reactions.createForIssueComment({
30107+
owner,
30108+
repo,
30109+
comment_id: context2.payload.comment.id,
30110+
content: "eyes"
30111+
});
30112+
} catch {
30113+
}
3011130114
pullNumber = context2.payload.issue.number;
3011230115
eventType = "comment";
3011330116
const pr = await octokit.rest.pulls.get({ owner, repo, pull_number: pullNumber });

packages/action/dist/check.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/action/dist/index.js

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41787,7 +41787,6 @@ function buildScriptGenerationPrompt(options) {
4178741787
## Rules
4178841788
- Navigate to the affected pages
4178941789
- Interact with new/changed UI elements (click buttons, fill forms, hover states)
41790-
- Add \`await page.waitForTimeout(1500)\` pauses on key visual states so the recording captures them clearly
4179141790
- Use resilient selectors in priority order: text content > ARIA roles > test IDs > CSS classes
4179241791
- The script must be self-contained and immediately runnable
4179341792
- Total demo should be under ${options.maxDuration} seconds
@@ -41796,6 +41795,16 @@ function buildScriptGenerationPrompt(options) {
4179641795
- Do NOT inject code into the page via \`page.evaluate\`, \`page.addInitScript\`, or inline \`<script>\` / \`<style>\` tags. The recording infrastructure handles visual overlays \u2014 the script should not.
4179741796
- Always call \`await page.waitForLoadState('networkidle')\` after navigation
4179841797

41798+
## Timing
41799+
- Keep pauses short: use \`await page.waitForTimeout(300)\` between most actions
41800+
- Only use a longer pause (\`await page.waitForTimeout(800)\`) directly after an interaction whose visual result (animation, state change, panel opening) is the point of the demo
41801+
- Avoid stacking multiple pauses in a row \u2014 one pause per meaningful moment is enough
41802+
41803+
## Mouse movement
41804+
- Move the mouse naturally between interactions: before clicking or hovering a target, briefly move to a nearby point first so the cursor doesn't teleport
41805+
- Use \`await page.mouse.move(x, y)\` for a single intermediate waypoint \u2014 keep it simple, one waypoint is enough
41806+
- Coordinates should be plausible screen positions relative to the viewport (${options.viewport.width}x${options.viewport.height})
41807+
4179941808
## Context
4180041809
- Base URL: ${options.baseUrl}
4180141810
- Viewport: ${options.viewport.width}x${options.viewport.height}
@@ -41895,15 +41904,15 @@ async function generateDemoScript(client, analysis, rawDiff, baseUrl, config) {
4189541904
}
4189641905

4189741906
// ../core/dist/recorder/playwright-runner.js
41898-
var import_test = require("@playwright/test");
4189941907
var import_node_fs2 = require("node:fs");
4190041908
var import_node_path = require("node:path");
4190141909
async function runScriptAndRecord(options) {
4190241910
const { script, baseUrl, recording, outputDir } = options;
4190341911
if (!(0, import_node_fs2.existsSync)(outputDir)) {
4190441912
(0, import_node_fs2.mkdirSync)(outputDir, { recursive: true });
4190541913
}
41906-
const browser = await import_test.chromium.launch({ headless: true });
41914+
const { chromium } = await import("@playwright/test");
41915+
const browser = await chromium.launch({ headless: true });
4190741916
const startTime = Date.now();
4190841917
try {
4190941918
const context2 = await createContext(browser, recording, outputDir);
@@ -42155,14 +42164,14 @@ function scanForFfmpeg(cacheDir) {
4215542164
}
4215642165

4215742166
// ../core/dist/recorder/fallback.js
42158-
var import_test2 = require("@playwright/test");
4215942167
var import_node_fs4 = require("node:fs");
4216042168
var import_node_path3 = require("node:path");
4216142169
async function takeScreenshots(baseUrl, routes, recording, outputDir) {
4216242170
if (!(0, import_node_fs4.existsSync)(outputDir)) {
4216342171
(0, import_node_fs4.mkdirSync)(outputDir, { recursive: true });
4216442172
}
42165-
const browser = await import_test2.chromium.launch({ headless: true });
42173+
const { chromium } = await import("@playwright/test");
42174+
const browser = await chromium.launch({ headless: true });
4216642175
const screenshots = [];
4216742176
try {
4216842177
const context2 = await browser.newContext({
@@ -46444,7 +46453,7 @@ async function postSkipComment(token, options) {
4644446453
${options.reason}
4644546454

4644646455
---
46447-
*Generated by [git-glimpse](https://github.com/git-glimpse/git-glimpse)*`;
46456+
*Generated by [git-glimpse](https://github.com/DeDuckProject/git-glimpse)*`;
4644846457
const existing = await findExistingComment(octokit, options);
4644946458
if (existing) {
4645046459
const response2 = await octokit.rest.issues.updateComment({
@@ -46498,13 +46507,16 @@ function buildCommentBody(options) {
4649846507
const { analysis, recordingUrl, screenshots, script, rerunUrl } = options;
4649946508
const changedFilesList = analysis.changedFiles.slice(0, 5).map((f2) => `\`${f2}\``).join(", ");
4650046509
const moreFiles = analysis.changedFiles.length > 5 ? ` (+${analysis.changedFiles.length - 5} more)` : "";
46501-
const mediaSection = recordingUrl ? `![Demo](${recordingUrl})` : screenshots && screenshots.length > 0 ? screenshots.map((s2, i2) => `![Screenshot ${i2 + 1}](${s2})`).join("\n") : "_No recording available._";
46510+
const mediaSection = recordingUrl ? `![Demo](${recordingUrl})
46511+
46512+
[\u{1F4F1} Can't see the preview? Open it directly](${recordingUrl})` : screenshots && screenshots.length > 0 ? screenshots.map((s2, i2) => `![Screenshot ${i2 + 1}](${s2})
46513+
46514+
[\u{1F4F1} Can't see screenshot ${i2 + 1}? Open it directly](${s2})`).join("\n\n") : "_No recording available._";
4650246515
const rerunSection = rerunUrl ? `
4650346516

4650446517
[\u21BA Re-run demo](${rerunUrl})` : "";
46505-
const logoUrl = "https://raw.githubusercontent.com/DeDuckProject/git-glimpse/main/assets/logo_square_small.png";
4650646518
return `${COMMENT_MARKER}
46507-
## <img src="${logoUrl}" width="40" height="40" align="absmiddle" alt="git-glimpse logo" /> UI Demo Preview
46519+
## \u{1F9D0} UI Demo Preview
4650846520

4650946521
**Changes detected in**: ${changedFilesList}${moreFiles}
4651046522

@@ -46521,7 +46533,9 @@ ${script}
4652146533
</details>
4652246534

4652346535
---
46524-
*Generated by [git-glimpse](https://github.com/git-glimpse/git-glimpse)${rerunSection}*`;
46536+
*Generated by [git-glimpse](https://github.com/DeDuckProject/git-glimpse)${rerunSection}*
46537+
46538+
<img src="https://raw.githubusercontent.com/DeDuckProject/git-glimpse/main/assets/logo_square_small.png" width="90" height="90" alt="git-glimpse logo" />`;
4652546539
}
4652646540

4652746541
// ../core/dist/publisher/storage.js
@@ -46688,6 +46702,19 @@ async function run() {
4668846702
let headSha;
4668946703
let eventType;
4669046704
let command = null;
46705+
let commentId = null;
46706+
const addCommentReaction = async (content) => {
46707+
if (commentId === null) return;
46708+
try {
46709+
await octokit.rest.reactions.createForIssueComment({
46710+
owner,
46711+
repo,
46712+
comment_id: commentId,
46713+
content
46714+
});
46715+
} catch {
46716+
}
46717+
};
4669146718
if (eventName === "issue_comment") {
4669246719
if (!context2.payload.issue?.pull_request) {
4669346720
core.info("Comment is on an issue, not a PR. Skipping.");
@@ -46700,16 +46727,8 @@ async function run() {
4670046727
return;
4670146728
}
4670246729
pullNumber = context2.payload.issue.number;
46730+
commentId = context2.payload.comment.id;
4670346731
eventType = "comment";
46704-
try {
46705-
await octokit.rest.reactions.createForIssueComment({
46706-
owner,
46707-
repo,
46708-
comment_id: context2.payload.comment.id,
46709-
content: "eyes"
46710-
});
46711-
} catch {
46712-
}
4671346732
const pr2 = await octokit.rest.pulls.get({ owner, repo, pull_number: pullNumber });
4671446733
baseSha = pr2.data.base.sha;
4671546734
headSha = pr2.data.head.sha;
@@ -46798,6 +46817,10 @@ ${result.errors.join("\n")}`);
4679846817
core.info(`Demo comment posted: ${comment.url}`);
4679946818
core.setOutput("comment-url", comment.url);
4680046819
core.setOutput("success", String(result.success));
46820+
await addCommentReaction("hooray");
46821+
} catch (err) {
46822+
await addCommentReaction("confused");
46823+
throw err;
4680146824
} finally {
4680246825
appProcess?.kill();
4680346826
}

packages/action/dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/recorder/fallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { chromium } from '@playwright/test';
21
import { mkdirSync, existsSync } from 'node:fs';
32
import { join } from 'node:path';
43
import type { RecordingConfig } from '../config/schema.js';
@@ -18,6 +17,7 @@ export async function takeScreenshots(
1817
mkdirSync(outputDir, { recursive: true });
1918
}
2019

20+
const { chromium } = await import('@playwright/test');
2121
const browser = await chromium.launch({ headless: true });
2222
const screenshots: string[] = [];
2323

packages/core/src/recorder/playwright-runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { chromium, type Browser, type BrowserContext, type Page } from '@playwright/test';
1+
import type { Browser, BrowserContext, Page } from '@playwright/test';
22
import { existsSync, mkdirSync } from 'node:fs';
33
import { join } from 'node:path';
44
import type { RecordingConfig } from '../config/schema.js';
@@ -22,6 +22,7 @@ export async function runScriptAndRecord(options: RunScriptOptions): Promise<Rec
2222
mkdirSync(outputDir, { recursive: true });
2323
}
2424

25+
const { chromium } = await import('@playwright/test');
2526
const browser = await chromium.launch({ headless: true });
2627
const startTime = Date.now();
2728

0 commit comments

Comments
 (0)