Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions .github/scripts/web-shell-visuals-publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* `buildComment`) are exported and tested. The file also runs as a CLI for the
* workflow:
* node web-shell-visuals-publish.mjs stage <screenshotsDir> <gifsDir> <stageDir>
* node web-shell-visuals-publish.mjs comment <stageDir> <rawBase> <shortSha> <runUrl> <bodyFile> [changedPathsFile] [renderStatusFile]
* node web-shell-visuals-publish.mjs comment <stageDir> <rawBase> <shortSha> <runUrl> <bodyFile> [changedPathsFile] [renderStatusFile] [hostingStatusFile]
*/

import {
Expand Down Expand Up @@ -190,18 +190,22 @@ const codePath = (p) => `\`${esc(String(p).replace(/[`\r\n]/g, ''))}\``;

/**
* Pure comment builder. `files` is the list of staged filenames (png + gif).
* `ctx` is `{ rawBase, shortSha, runUrl, changedPaths, renderIncomplete }`:
* `ctx` is
* `{ rawBase, shortSha, runUrl, changedPaths, renderIncomplete, hostingFailed }`:
* `changedPaths` is the PR's full changed-file list (used only to triage an
* empty preview), and `renderIncomplete` is true when >=1 scenario failed to
* render on the PR head — in which case a missing view may be a render failure,
* not "no change", and the comment must say so instead of a clean bill of
* health. Returns the markdown body.
* health. `hostingFailed` is true when assets rendered but could not be pushed
* to the PR assets branch; in that state the comment must refresh without
* broken inline image URLs. Returns the markdown body.
*/
export function buildComment(files, ctx = {}) {
const rawBase = ctx.rawBase ?? '';
const shortSha = ctx.shortSha ?? '';
const runUrl = ctx.runUrl ?? '';
const renderIncomplete = ctx.renderIncomplete === true;
const hostingFailed = ctx.hostingFailed === true;
const url = (name) => `${rawBase}/${encodeURIComponent(name)}`;
// A "see the run" pointer for the render-failure notes (omitted if unknown).
const runLink = runUrl ? ` — see the [workflow run](${esc(runUrl)})` : '';
Expand All @@ -223,7 +227,25 @@ export function buildComment(files, ctx = {}) {

out.push('#### Screenshots · before / after');
out.push('');
if (shots.length > 0) {
if (hostingFailed) {
if (renderIncomplete) {
out.push(
`⚠️ _One or more scenarios failed to render_ on this head, so this preview may be missing views${runLink}.`,
);
out.push('');
}
out.push(
`⚠️ _Preview images rendered, but the publish workflow failed to host them on the PR assets branch${runLink}._ This comment was still refreshed so stale images from an older push do not remain attached to this SHA.`,
);
out.push('');
const rendered = [...shots, ...gifs].sort();
if (rendered.length > 0) {
out.push('Rendered asset filenames:');
out.push('');
for (const f of rendered) out.push(`- ${codePath(f)}`);
out.push('');
}
} else if (shots.length > 0) {
// Some views rendered. If others FAILED, say so first: the set below is
// partial, and a view a reviewer expects but doesn't see may have crashed
// rather than stayed unchanged.
Expand Down Expand Up @@ -276,7 +298,7 @@ export function buildComment(files, ctx = {}) {
}
}

if (gifs.length > 0) {
if (!hostingFailed && gifs.length > 0) {
out.push('#### Flows');
out.push('');
for (const g of gifs) {
Expand Down Expand Up @@ -365,6 +387,7 @@ function commentCli(
bodyFile,
pathsFile,
renderStatusFile,
hostingStatusFile,
) {
let files = [];
try {
Expand Down Expand Up @@ -397,12 +420,22 @@ function commentCli(
// Unreadable → leave complete (fail open toward the normal preview).
}
}
let hostingFailed = false;
if (hostingStatusFile) {
try {
hostingFailed =
readFileSync(hostingStatusFile, 'utf8').trim() === 'failure';
} catch {
// Missing/older workflow input → normal hosted/no-image behavior.
}
}
const body = buildComment(files, {
rawBase,
shortSha,
runUrl,
changedPaths,
renderIncomplete,
hostingFailed,
});
writeFileSync(bodyFile, body);
process.stderr.write(`Comment body: ${body.split('\n').length} lines.\n`);
Expand All @@ -413,7 +446,16 @@ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
if (cmd === 'stage') {
stageCli(rest[0], rest[1], rest[2]);
} else if (cmd === 'comment') {
commentCli(rest[0], rest[1], rest[2], rest[3], rest[4], rest[5], rest[6]);
commentCli(
rest[0],
rest[1],
rest[2],
rest[3],
rest[4],
rest[5],
rest[6],
rest[7],
);
} else {
process.stderr.write(`unknown command: ${cmd ?? '(none)'}\n`);
process.exit(2);
Expand Down
109 changes: 109 additions & 0 deletions .github/scripts/web-shell-visuals-publish.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
*/

import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import {
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';

import {
buildComment,
Expand All @@ -23,6 +34,15 @@ const PNG = '89504e470d0a1a0a';
const GIF89 = '474946383961';
const GIF87 = '474946383761';

const publishWorkflow = () =>
readFileSync(
new URL('../workflows/web-shell-visuals-publish.yml', import.meta.url),
'utf8',
);
const publishScriptPath = fileURLToPath(
new URL('./web-shell-visuals-publish.mjs', import.meta.url),
);

test('sanitizeName preserves the extension (regression: a trailing char broke the .png filter)', () => {
assert.equal(
sanitizeName('session-transcript-light.png'),
Expand Down Expand Up @@ -162,6 +182,66 @@ test('buildComment lists a lone composite as one wide image (no light/dark table
assert.doesNotMatch(body, /<td>/);
});

test('buildComment: hosting failure reports rendered assets without broken image links', () => {
const body = buildComment(['home-light.png', 'model-switch.gif'], {
hostingFailed: true,
runUrl: 'https://run.example/7',
});
assert.match(body, /failed to host/i);
assert.match(body, /home-light\.png/);
assert.match(body, /model-switch\.gif/);
assert.match(body, /\[workflow run\]\(https:\/\/run\.example\/7\)/);
assert.doesNotMatch(body, /failed to render/i);
assert.doesNotMatch(body, /<img /);
});

test('buildComment: hosting failure preserves render-failure caveat', () => {
const body = buildComment(['home-light.png', 'model-switch.gif'], {
hostingFailed: true,
renderIncomplete: true,
runUrl: 'https://run.example/7',
});
assert.match(body, /failed to render/i);
assert.match(body, /failed to host/i);
assert.match(body, /\[workflow run\]\(https:\/\/run\.example\/7\)/);
assert.doesNotMatch(body, /<img /);
});

test('comment CLI reads hosting failure status from the eighth argument', () => {
const root = mkdtempSync(join(tmpdir(), 'web-shell-visuals-'));
try {
const stageDir = join(root, 'stage');
const bodyFile = join(root, 'body.md');
const changedPathsFile = join(root, 'paths.txt');
const renderStatusFile = join(root, 'render-status.txt');
const hostingStatusFile = join(root, 'hosting-status.txt');
mkdirSync(stageDir);
writeFileSync(join(stageDir, 'home-light.png'), '');
writeFileSync(changedPathsFile, '');
writeFileSync(renderStatusFile, 'success\n');
writeFileSync(hostingStatusFile, 'failure\n');

execFileSync(process.execPath, [
publishScriptPath,
'comment',
stageDir,
'https://assets.example/pr',
'abc1234',
'https://run.example/7',
bodyFile,
changedPathsFile,
renderStatusFile,
hostingStatusFile,
]);

const body = readFileSync(bodyFile, 'utf8');
assert.match(body, /failed to host/i);
assert.doesNotMatch(body, /<img /);
} finally {
rmSync(root, { recursive: true, force: true });
}
});

// --- Empty-preview triage (coverage gap vs. genuinely no visual effect) ---

test('selectRenderShapingFiles keeps rendered .tsx/.css/.svg and drops logic/test/other-package edits', () => {
Expand Down Expand Up @@ -339,3 +419,32 @@ test('buildComment: render-failure note omits the run link when runUrl is absent
assert.match(body, /failed to render/i);
assert.doesNotMatch(body, /\[workflow run\]/); // no dangling empty link
});

test('publish workflow passes hosting failures through to the comment builder', () => {
const workflow = publishWorkflow();
assert.match(
workflow,
/HOSTING_STATUS_FILE="\$\{RUNNER_TEMP\}\/visuals-hosting-status\.txt"/,
);

const failureWrite = `echo 'failure' > "\${HOSTING_STATUS_FILE}"`;
const commentInvocation =
'node .github/scripts/web-shell-visuals-publish.mjs comment';
const failureWriteIndex = workflow.indexOf(failureWrite);
assert.notEqual(failureWriteIndex, -1);
const fromFailureWrite = workflow.slice(failureWriteIndex);
const commentIndex = fromFailureWrite.indexOf(commentInvocation);
assert.ok(commentIndex > 0);
const beforeComment = fromFailureWrite.slice(0, commentIndex);
assert.doesNotMatch(beforeComment, /\bexit 1\b/);

assert.match(
workflow,
/"\$\{BODY_FILE\}" \\\n\s+"\$\{CHANGED_PATHS_FILE\}" \\\n\s+"\$\{RENDER_STATUS_FILE\}" \\\n\s+"\$\{HOSTING_STATUS_FILE\}"/,
);
assert.match(workflow, /echo 'success' > "\$\{HOSTING_STATUS_FILE\}"/);
assert.match(
workflow,
/if \[ "\$\{pushed\}" -ne 1 \]; then\n\s+echo "::warning::[^\n]*"\n\s+echo 'failure' > "\$\{HOSTING_STATUS_FILE\}"/,
);
});
19 changes: 12 additions & 7 deletions .github/workflows/web-shell-visuals-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ jobs:
# skips the asset commit entirely; RAW_BASE stays empty and the
# comment below is image-less ("no screenshot changes").
RAW_BASE=''
HOSTING_STATUS_FILE="${RUNNER_TEMP}/visuals-hosting-status.txt"
echo 'success' > "${HOSTING_STATUS_FILE}"
if [ "${HAS_IMAGES}" = "1" ]; then
BRANCH="pr-assets/web-shell-visuals-${PR}"
AUTH_URL="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
Expand Down Expand Up @@ -219,13 +221,15 @@ jobs:
sleep 2
done
if [ "${pushed}" -ne 1 ]; then
echo "::error::Failed to push web-shell visuals to ${BRANCH} after retries."
exit 1
echo "::warning::Failed to push web-shell visuals to ${BRANCH} after retries; updating the PR comment with a hosting-failure note."
echo 'failure' > "${HOSTING_STATUS_FILE}"
cd "${GITHUB_WORKSPACE}"
else
ASSET_SHA="$(git rev-parse HEAD)"
cd "${GITHUB_WORKSPACE}"
echo "web-shell visuals hosted on ${BRANCH} at ${ASSET_SHA}."
RAW_BASE="https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${ASSET_SHA}/imgs"
fi
ASSET_SHA="$(git rev-parse HEAD)"
cd "${GITHUB_WORKSPACE}"
echo "web-shell visuals hosted on ${BRANCH} at ${ASSET_SHA}."
RAW_BASE="https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${ASSET_SHA}/imgs"
fi

# --- Changed paths, for triaging an EMPTY preview ------------------
Expand Down Expand Up @@ -259,7 +263,8 @@ jobs:
"${RAW_BASE}" \
"${SHORT_SHA}" "${RUN_URL}" "${BODY_FILE}" \
"${CHANGED_PATHS_FILE}" \
"${RENDER_STATUS_FILE}"
"${RENDER_STATUS_FILE}" \
"${HOSTING_STATUS_FILE}"

# --- Post or update the PR comment --------------------------------
# Dedup only against OUR OWN prior comment (bot author + marker), and
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/core/client.telemetrySwap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ function makeEnv() {
const config: any = {
getSessionId: () => sessionId,
getResumedSessionData: () => resumedData,
// initialize() on a resumed session asks the skill tool to restore its
// loaded skills via config.getToolRegistry().getTool(...).
getToolRegistry: () => ({ getTool: () => undefined }),
swap(id: string, data?: ResumedSessionData) {
sessionId = id;
resumedData = data;
Expand Down
Loading