From 66cdf59d7dfd04772b2a2304e42d70bba641b325 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 09:34:51 +0000 Subject: [PATCH 1/2] Lay the summary comment out like Appwrite's Sites and Functions comments The summary opens with a head row (commit, status, tier, verdict, details) in the shape of a deployment row, and the status cell uses the same state images Appwrite serves from the Console: the animated one while a review runs, then ready, queued or failed. Findings, walkthrough, still-open, fixed and filtered findings are counted collapsible sections, and the comment ends with a tip on how to re-run or ask. Origin gets the labels without images, as it does for Appwrite's own comments, and so does any repository without a Console root. The latest-changes paragraph now ends at a hidden marker, so a settlement rebuild reads it back without the old verdict table; old summaries still parse. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F3M7tukAPsZ8K2YWuskhgg Co-authored-by: Torsten Dittmann <1759475+TorstenDittmann@users.noreply.github.com> --- packages/engine/src/chat-job.ts | 3 +- packages/engine/src/core.test.ts | 8 +- packages/engine/src/format.test.ts | 74 ++++++++++-- packages/engine/src/format.ts | 155 ++++++++++++++++++------- packages/engine/src/merge-only.test.ts | 5 +- packages/engine/src/merge-only.ts | 2 + packages/engine/src/progress.test.ts | 52 ++++++--- packages/engine/src/progress.ts | 72 ++++++++---- packages/engine/src/review-job.test.ts | 8 +- packages/engine/src/review-job.ts | 9 +- packages/engine/src/shared.test.ts | 23 ++++ packages/engine/src/shared.ts | 17 +++ packages/engine/src/summary.test.ts | 7 +- packages/engine/src/summary.ts | 12 +- 14 files changed, 339 insertions(+), 108 deletions(-) create mode 100644 packages/engine/src/shared.test.ts diff --git a/packages/engine/src/chat-job.ts b/packages/engine/src/chat-job.ts index 4ef66b2..517d777 100644 --- a/packages/engine/src/chat-job.ts +++ b/packages/engine/src/chat-job.ts @@ -17,7 +17,7 @@ import { chatFailureReply } from './public-failure'; import type { ChatRef, ModelUsage, PullRef } from './results'; import { lazySandbox, openSandbox } from './review-sandbox'; import { scopeToRepository } from './scope'; -import { modelUsage, withWorkdir } from './shared'; +import { modelUsage, statusImagesOrigin, withWorkdir } from './shared'; import { refreshSummaryAfterSettlement } from './summary'; // One answer to a comment on a pull request. It follows hansi.codes' worker step for step; @@ -236,6 +236,7 @@ export async function runChatJob( pull, repository, consoleUrl: job.repository.consoleUrl, + images: statusImagesOrigin(job.repository), blockingSeverity: changeRequestSeverity(config), log }).catch((error: unknown) => diff --git a/packages/engine/src/core.test.ts b/packages/engine/src/core.test.ts index ada9226..87512c8 100644 --- a/packages/engine/src/core.test.ts +++ b/packages/engine/src/core.test.ts @@ -1702,11 +1702,11 @@ ${upstream}`; mention: '@hansi-codes' }); const title = 'Require mutation permission before changing video children'; - const attachAt = body.indexOf("### Couldn't attach to a line"); + const attachAt = body.indexOf("Couldn't attach to a line"); expect(attachAt).toBeGreaterThan(0); // The unattached list sits above the collapsed sections. It is not the headline. const headline = body.slice(0, attachAt); - expect(headline).toContain('Tier B'); + expect(headline).toContain('🟡 **B**'); expect(headline).toContain('Division by zero'); expect(headline.toLowerCase()).not.toContain('bypass'); expect(headline).not.toContain('Require mutation permission'); @@ -1757,10 +1757,10 @@ ${upstream}`; walkthrough: [], mention: '@hansi-codes' }); - const attachAt = body.indexOf("### Couldn't attach to a line"); + const attachAt = body.indexOf("Couldn't attach to a line"); expect(attachAt).toBeGreaterThan(0); const headline = body.slice(0, attachAt); - expect(headline).toContain('Tier S'); + expect(headline).toContain('🟢 **S**'); expect(headline.toLowerCase()).not.toContain('bypass'); expect(headline).not.toContain(title); expect(body.slice(attachAt)).toContain(title); diff --git a/packages/engine/src/format.test.ts b/packages/engine/src/format.test.ts index 4a4df32..e755722 100644 --- a/packages/engine/src/format.test.ts +++ b/packages/engine/src/format.test.ts @@ -9,6 +9,8 @@ import { formatFindingComment, formatReviewBody, formatSummaryComment, + latestChangesFromBody, + statusCell, SUMMARY_MARKER, type SummaryInput } from './format'; @@ -53,20 +55,45 @@ const base: SummaryInput = { describe('formatSummaryComment', () => { const body = formatSummaryComment(base); - test('starts with the marker and the tier', () => { - expect(body).toStartWith(`${SUMMARY_MARKER}\n\n## 🟡 Tier B · Needs changes before merging`); - expect(body).toContain('> Limited by an open major finding: Off by one'); + test('starts with the head row of the Sites and Functions comments', () => { + expect(body).toStartWith( + [ + SUMMARY_MARKER, + '', + '## Code review', + '', + '| Commit | Status | Tier | Verdict | Details |', + '| :- | :- | :- | :- | :- |', + '| `abcdef1` | _Reviewed_ | 🟡 **B** · Needs changes before merging | 🛑 Changes requested | [View review](https://hans.example/app/acme/reviews/1) |', + '', + '> Limited by an open major finding: Off by one' + ].join('\n') + ); }); - test('shows the verdict and counts, and links findings to their lines', () => { - expect(body).toContain('| 🛑 Changes requested | 1 | 1 | 0 |'); + test('shows the status image from the Console when there is one', () => { + const body = formatSummaryComment({ ...base, images: 'https://cloud.appwrite.io' }); + expect(body).toContain( + '| `abcdef1` | Reviewed _Reviewed_ |' + ); + }); + + test('leaves out the details column without a link', () => { + const body = formatSummaryComment({ ...base, detailsUrl: undefined }); + expect(body).toContain('| Commit | Status | Tier | Verdict |\n| :- | :- | :- | :- |\n'); + }); + + test('counts the findings on their sections and links them to their lines', () => { + expect(body).toContain('
\nFindings (1)'); + expect(body).toContain('Fixed since the last review (1)'); expect(body).toContain( '| 🟠 | Off by one \\| skips the first page | [`src/paginate.ts:3`](https://github.com/acme/api/blob/abcdef1234567890/src/paginate.ts#L3-L4) |' ); }); test('collapses the walkthrough, fixed and filtered findings', () => { - expect(body).toContain('📂 Walkthrough · 1'); + expect(body).toContain('
\nWalkthrough (1)'); + expect(body).toContain('
\nFiltered out (1)'); expect(body).toContain('| `src/paginate.ts` | Switches to 1-based pages. Adds pageCount. |'); expect(body).toContain('- ~~Missing await~~ · `src/a.ts:9`'); expect(body).toContain('| Naming | Below minSeverity (minor) |'); @@ -104,7 +131,7 @@ describe('formatSummaryComment', () => { } ] }); - const section = body.slice(body.indexOf("### Couldn't attach to a line")); + const section = body.slice(body.indexOf("Couldn't attach to a line")); expect(section).toContain( 'These findings could not be placed on a changed line, so they were not posted as inline comments.' ); @@ -168,9 +195,36 @@ describe('formatSummaryComment', () => { expect(body).toContain('Reviewed 410aa75'); }); - test('ends with how to interact', () => { - expect(body).toContain('Reviewed abcdef1'); - expect(body).toContain('@hans-review review to re-run'); + test('ends with how to interact, in a tip', () => { + expect(body).toContain('Reviewed abcdef1'); + expect(body).toEndWith( + '> [!TIP]\n> Comment @hans-review review to re-run, or mention @hans-review with a question.' + ); + }); + + test('the latest changes read back out, however many lines they span', () => { + const latestChanges = 'Adds a cursor.\n\nDrops the offset.'; + expect(latestChangesFromBody(formatSummaryComment({ ...base, latestChanges }))).toBe( + latestChanges + ); + // Summaries written before the restyle ended the paragraph at the verdict table. + expect( + latestChangesFromBody('**Latest changes:** Adds a cursor.\n\n| Verdict | New comments |') + ).toBe('Adds a cursor.'); + expect(latestChangesFromBody(body)).toBeNull(); + }); +}); + +describe('statusCell', () => { + test('is the label alone without images, as for providers that cannot show them', () => { + expect(statusCell('building', 'Reviewing 2 files')).toBe('_Reviewing 2 files_'); + expect(statusCell(null, 'Skipped', 'https://cloud.appwrite.io')).toBe('_Skipped_'); + }); + + test('animates the running state and keeps the label', () => { + expect(statusCell('building', 'Reviewing', 'https://cloud.appwrite.io')).toBe( + 'Reviewing _Reviewing_' + ); }); }); diff --git a/packages/engine/src/format.ts b/packages/engine/src/format.ts index d4100f5..4b4f257 100644 --- a/packages/engine/src/format.ts +++ b/packages/engine/src/format.ts @@ -474,6 +474,56 @@ export interface SummaryInput { detailsUrl?: string; /** The bot's handle, e.g. `@hansi-codes`. */ mention: string; + /** The Console's origin, where the status images are served. Absent: the status is text. */ + images?: string; +} + +/** + * The state images Appwrite's Sites and Functions comments show, served by the Appwrite Console + * under `/images/vcs/`: queued, running (animated), finished and failed. + */ +export type StatusImage = 'waiting' | 'building' | 'ready' | 'failed'; + +/** + * A status cell in the style of Appwrite's deployment comments: the state image (light and dark) + * and the label in italics. `images` is the Console's origin; without it, or with no image for + * this state, the cell is the label alone, as Appwrite writes it for providers that cannot show + * images from another host. + */ +export function statusCell(image: StatusImage | null, label: string, images?: string): string { + const text = `_${label}_`; + if (!image || !images) return text; + const extension = image === 'building' ? 'gif' : 'png'; + const src = (theme: 'light' | 'dark') => + `${images}/images/vcs/status-${image}-${theme}.${extension}`; + const alt = label.replace(/"/g, '"'); + return `${alt} ${text}`; +} + +/** A collapsible section, as Appwrite's deployment comments group Sites and Functions. */ +export function detailsSection(title: string, count: number, body: string, open = false): string { + return `\n${title} (${count})\n\n
\n\n${body}\n\n
`; +} + +/** The closing tip: how to ask for another review or a question. */ +export function interactionTip(mention: string): string { + return `> [!TIP]\n> Comment ${mention} review to re-run, or mention ${mention} with a question.`; +} + +/** + * Ends the latest-changes paragraph, which can span lines, so a settlement rebuild can read it back + * whatever follows it. + */ +const LATEST_CHANGES_END = ``; + +/** Reads the latest-changes paragraph back out of a summary comment. */ +export function latestChangesFromBody(body: string): string | null { + const current = body.match( + new RegExp(`\\*\\*Latest changes:\\*\\* ([\\s\\S]*?)\\n${LATEST_CHANGES_END}`) + )?.[1]; + if (current !== undefined) return current; + // Summaries written before the restyle ended the paragraph at the verdict table. + return body.match(/\*\*Latest changes:\*\* ([\s\S]*?)\n\n\| Verdict \|/)?.[1] ?? null; } /** The summary comment Hansi keeps up to date on every pull request. */ @@ -496,9 +546,28 @@ export function formatSummaryComment(input: SummaryInput): string { const lineLink = (path: string, start: number, end = start) => `[\`${path}:${start}\`](${input.repository}/${input.headSha}/${path}#L${start}${end > start ? `-L${end}` : ''})`; + // The head row, laid out like a deployment row in Appwrite's Sites and Functions comments. + // The sections below carry the finding counts. + const columns = ['Commit', 'Status', 'Tier', 'Verdict']; + const row = [ + `\`${input.headSha.slice(0, 7)}\``, + statusCell('ready', 'Reviewed', input.images), + `${tierIcon[input.tier]} **${input.tier}** · ${tierMeaning[input.tier]}`, + verdictText[input.verdict] + ]; + if (input.detailsUrl) { + columns.push('Details'); + row.push(`[View review](${input.detailsUrl})`); + } + const parts = [ SUMMARY_MARKER, - `## ${tierIcon[input.tier]} Tier ${input.tier} · ${tierMeaning[input.tier]}` + '## Code review', + [ + `| ${columns.join(' | ')} |`, + `| ${columns.map(() => ':-').join(' | ')} |`, + `| ${row.join(' | ')} |` + ].join('\n') ]; if (input.tierReason) parts.push(`> ${cell(input.tierReason)}`); parts.push(input.summary); @@ -506,15 +575,9 @@ export function formatSummaryComment(input: SummaryInput): string { if (omitted && omitted.omitted > 0) { parts.push(filesTooLargeSentence(omitted.omitted, omitted.total)); } - if (input.latestChanges) parts.push(`**Latest changes:** ${input.latestChanges}`); - - parts.push( - [ - '| Verdict | New comments | Fixed | Still open |', - '| :-- | :-: | :-: | :-: |', - `| ${verdictText[input.verdict]} | ${input.posted.length} | ${input.resolved.length} | ${input.stillOpen.length} |` - ].join('\n') - ); + if (input.latestChanges) { + parts.push(`**Latest changes:** ${input.latestChanges}\n${LATEST_CHANGES_END}`); + } if (input.staleHead) { parts.push(`> [!NOTE]\n> ${STALE_HEAD_NOTE_MARK} ${cell(input.staleHead)}`); @@ -523,30 +586,38 @@ export function formatSummaryComment(input: SummaryInput): string { if (input.posted.length) { parts.push( - [ - '| | Finding | Where |', - '| :-: | :-- | :-- |', - ...input.posted.map( - (f) => - `| ${severityIcon[f.severity]} | ${cell(f.title)} | ${lineLink(f.path, f.startLine, f.endLine)} |` - ) - ].join('\n') + detailsSection( + 'Findings', + input.posted.length, + [ + '| | Finding | Where |', + '| :-: | :- | :- |', + ...input.posted.map( + (f) => + `| ${severityIcon[f.severity]} | ${cell(f.title)} | ${lineLink(f.path, f.startLine, f.endLine)} |` + ) + ].join('\n'), + true + ) ); } const unattached = input.dropped.filter((f) => isUnattachedDrop(f.dropReason)); if (unattached.length) { parts.push( - [ - "### Couldn't attach to a line", - '', - 'These findings could not be placed on a changed line, so they were not posted as inline comments.', - '', - ...unattached.map( - (f) => - `- ${cell(f.title)} · ${lineLink(f.path, f.startLine, f.endLine)} · ${cell(f.dropReason)}` - ) - ].join('\n') + detailsSection( + "Couldn't attach to a line", + unattached.length, + [ + 'These findings could not be placed on a changed line, so they were not posted as inline comments.', + '', + ...unattached.map( + (f) => + `- ${cell(f.title)} · ${lineLink(f.path, f.startLine, f.endLine)} · ${cell(f.dropReason)}` + ) + ].join('\n'), + true + ) ); } @@ -565,17 +636,14 @@ export function formatSummaryComment(input: SummaryInput): string { parts.push(agentPromptBlock('Fix with agent prompt', summaryAgentPrompt(openIssues))); } - const section = (title: string, count: number, body: string) => - `
\n${title} · ${count}\n\n${body}\n\n
`; - if (input.walkthrough.length) { parts.push( - section( - '📂 Walkthrough', + detailsSection( + 'Walkthrough', input.walkthrough.length, [ '| File | Change |', - '| :-- | :-- |', + '| :- | :- |', ...input.walkthrough.map((w) => `| \`${cell(w.path)}\` | ${cell(w.change)} |`) ].join('\n') ) @@ -583,8 +651,8 @@ export function formatSummaryComment(input: SummaryInput): string { } if (input.stillOpen.length) { parts.push( - section( - '⏳ Still open from earlier reviews', + detailsSection( + 'Still open from earlier reviews', input.stillOpen.length, input.stillOpen .map((f) => `- ${severityIcon[f.severity]} ${f.title} · ${lineLink(f.path, f.startLine)}`) @@ -594,8 +662,8 @@ export function formatSummaryComment(input: SummaryInput): string { } if (input.resolved.length) { parts.push( - section( - '✅ Fixed since the last review', + detailsSection( + 'Fixed since the last review', input.resolved.length, input.resolved.map((f) => `- ~~${f.title}~~ · \`${f.path}:${f.startLine}\``).join('\n') ) @@ -604,14 +672,14 @@ export function formatSummaryComment(input: SummaryInput): string { const filtered = input.dropped.filter((f) => !isUnattachedDrop(f.dropReason)); if (filtered.length) { parts.push( - section( - '🔇 Filtered out', + detailsSection( + 'Filtered out', filtered.length, [ 'Findings Hansi considered but did not post.', '', '| Finding | Why |', - '| :-- | :-- |', + '| :- | :- |', ...filtered.map((f) => `| ${cell(f.title)} | ${cell(f.dropReason)} |`) ].join('\n') ) @@ -623,10 +691,7 @@ export function formatSummaryComment(input: SummaryInput): string { : input.incrementalFrom ? `Reviewed the commits since ${input.incrementalFrom.slice(0, 7)}` : `Reviewed ${input.headSha.slice(0, 7)}`; - const details = input.detailsUrl ? ` · Details` : ''; - parts.push( - `---\n${reviewed}${details} · Comment ${input.mention} review to re-run, or mention ${input.mention} with a question.` - ); + parts.push(`
\n\n${reviewed}`, interactionTip(input.mention)); return parts.join('\n\n'); } diff --git a/packages/engine/src/merge-only.test.ts b/packages/engine/src/merge-only.test.ts index 12fd53b..d633b09 100644 --- a/packages/engine/src/merge-only.test.ts +++ b/packages/engine/src/merge-only.test.ts @@ -131,9 +131,10 @@ describe('carried summary', () => { const body = formatSummaryComment(input); // The carried grade stays, including when posted findings would grade the PR lower. - expect(body).toContain('## 🟢 Tier S'); + expect(body).toContain('🟢 **S** · Ready to merge'); expect(body).not.toContain('Tier B'); - expect(body).toContain('| ✅ Approved | 1 | 0 | 0 |'); + expect(body).toContain('| ✅ Approved |'); + expect(body).toContain('Findings (1)'); expect(body).toContain('Stops redelivering function events.'); expect(body).toContain('**Latest changes:** Skips duplicate deliveries.'); expect(body).toContain('| `src/functions.ts` | Skips duplicate deliveries. |'); diff --git a/packages/engine/src/merge-only.ts b/packages/engine/src/merge-only.ts index 9c2a7a1..ec7b21f 100644 --- a/packages/engine/src/merge-only.ts +++ b/packages/engine/src/merge-only.ts @@ -143,6 +143,7 @@ export function carriedSummaryInput(input: { repository: string; mention: string; detailsUrl?: string; + images?: string; scope: string; review: CarriedReview; findings: Parameters[0]['findings']; @@ -158,6 +159,7 @@ export function carriedSummaryInput(input: { findings: input.findings, detailsUrl: input.detailsUrl, mention: input.mention, + images: input.images, ...input.extras, scope: input.scope }); diff --git a/packages/engine/src/progress.test.ts b/packages/engine/src/progress.test.ts index a95e2b4..310b398 100644 --- a/packages/engine/src/progress.test.ts +++ b/packages/engine/src/progress.test.ts @@ -13,7 +13,7 @@ import { } from './progress'; const sha = 'abcdef1234567890'; -const summary = `${SUMMARY_MARKER}\n\n## 🟢 Tier A · Merge after a quick look\n\n| Verdict | New comments | Fixed | Still open |`; +const summary = `${SUMMARY_MARKER}\n\n## Code review\n\n| Commit | Status | Tier | Verdict |`; const block = (previous = false) => statusBlock( { kind: 'running', phase: { kind: 'reviewing', files: 3 } }, @@ -33,13 +33,17 @@ test('trace events move the review into its phases', () => { expect(phaseFromEvent({ type: 'tool.read_file', data: {} })).toBeNull(); }); -test('the status block says what is running and links to the live trace', () => { +test('the status block is the progress row of the Sites and Functions comments', () => { expect(block(true)).toBe( [ '', - '> ⏳ **Reviewing `abcdef1`** · Reviewing 3 files…', - '>', - '> The summary below is from the previous review. · [Follow along](https://hansi.test/r/1)', + '', + '| Commit | Status | Details |', + '| :- | :- | :- |', + '| `abcdef1` | _Reviewing 3 files_ | [Follow along](https://hansi.test/r/1) |', + '', + 'The summary below is from the previous review.', + '', '' ].join('\n') ); @@ -47,11 +51,30 @@ test('the status block says what is running and links to the live trace', () => { kind: 'failed' }, { headSha: sha, mention: '@hansi', previous: false } ); - expect(failed).toContain('could not finish reviewing `abcdef1`'); - expect(failed).toContain('@hansi review'); + expect(failed).toContain('| `abcdef1` | _Failed_ |'); + expect(failed).toContain('@hansi review to try again'); expect(failed).not.toContain('Follow along'); }); +test('the status row shows the animated image while running, and the state images after', () => { + const images = 'https://cloud.appwrite.io'; + const running = statusBlock( + { kind: 'running', phase: { kind: 'verifying', findings: 2 } }, + { headSha: sha, mention: '@hansi', previous: false, images } + ); + expect(running).toContain( + 'Verifying 2 possible findings _Verifying 2 possible findings_' + ); + const image = (status: Parameters[0]) => + statusBlock(status, { headSha: sha, mention: '@hansi', previous: true, images }).match( + /status-(\w+)-light\.(\w+)/ + )?.[0]; + expect(image({ kind: 'retrying' })).toBe('status-waiting-light.png'); + expect(image({ kind: 'failed' })).toBe('status-failed-light.png'); + // A skip has no state image of its own. + expect(image({ kind: 'skipped', reason: 'Nothing to review' })).toBeUndefined(); +}); + test('a first review starts the summary with the status block alone', () => { const body = withStatusBlock(null, block()); expect(body).toBe(`${SUMMARY_MARKER}\n\n${block()}`); @@ -61,7 +84,7 @@ test('a first review starts the summary with the status block alone', () => { test('a later review puts the status above the previous summary and removes it cleanly', () => { const body = withStatusBlock(summary, block(true)); - expect(body.startsWith(`${SUMMARY_MARKER}\n\n${block(true)}\n\n## 🟢 Tier A`)).toBe(true); + expect(body.startsWith(`${SUMMARY_MARKER}\n\n${block(true)}\n\n## Code review`)).toBe(true); expect(hasReviewSummary(body)).toBe(true); expect(withoutStatusBlock(body)).toBe(summary); // Replacing the block keeps one, not two. @@ -110,7 +133,7 @@ test('progress follows the phases on the check run and the summary', async () => 'Posting the review' ]); expect(state.writes).toBe(3); - expect(state.comment?.body).toContain('Verifying 1 possible finding…'); + expect(state.comment?.body).toContain('_Verifying 1 possible finding_'); expect(state.comment?.body).toContain('The summary below is from the previous review.'); // Nothing lands after close, so the final summary cannot be overwritten. progress.phase({ kind: 'reviewing', files: 9 }); @@ -123,8 +146,9 @@ test('a failed review never leaves the summary saying it is running', async () = const progress = createReviewProgress(target); progress.phase({ kind: 'reviewing', files: 2 }); await progress.settle({ kind: 'failed' }); - expect(state.comment?.body).not.toContain('⏳'); - expect(state.comment?.body).toContain('could not finish reviewing'); + expect(state.comment?.body).not.toContain('_Reviewing 2 files_'); + expect(state.comment?.body).toContain('_Failed_'); + expect(state.comment?.body).toContain('could not finish this review'); expect(withoutStatusBlock(state.comment!.body)).toBe(summary); }); @@ -141,7 +165,8 @@ test('a retry clears the status an earlier attempt left behind', async () => { const progress = createReviewProgress(target); await progress.settle({ kind: 'retrying' }); expect(state.comment?.body).toContain('was interrupted'); - expect(state.comment?.body).not.toContain('⏳'); + expect(state.comment?.body).toContain('_Interrupted, retrying_'); + expect(state.comment?.body).not.toContain('_Reviewing 3 files_'); }); test('a skip removes the status, or explains itself when there is no earlier summary', async () => { @@ -155,7 +180,8 @@ test('a skip removes the status, or explains itself when there is no earlier sum const two = createReviewProgress(first.target); two.phase({ kind: 'reviewing', files: 1 }); await two.settle({ kind: 'skipped', reason: 'No reviewable changes' }); - expect(first.state.comment?.body).toContain('Skipped `abcdef1`: No reviewable changes'); + expect(first.state.comment?.body).toContain('| `abcdef1` | _Skipped_ |'); + expect(first.state.comment?.body).toContain('No reviewable changes'); }); test('a GitHub error while reporting progress does not fail the review', async () => { diff --git a/packages/engine/src/progress.ts b/packages/engine/src/progress.ts index f9354ca..ad6bf3d 100644 --- a/packages/engine/src/progress.ts +++ b/packages/engine/src/progress.ts @@ -1,5 +1,5 @@ import type { Log } from './context'; -import { MARKER_NAMESPACE, SUMMARY_MARKER } from './format'; +import { MARKER_NAMESPACE, statusCell, SUMMARY_MARKER, type StatusImage } from './format'; import type { ReviewEvent as TraceEvent } from './tools'; /** @@ -66,37 +66,60 @@ export function checkRunProgress(phase: ReviewPhase): { title: string; summary: }; } -/** The block at the top of the summary comment, between hidden markers so it can be replaced. */ -export function statusBlock( - status: ReviewStatus, - input: { headSha: string; mention: string; previous: boolean; detailsUrl?: string } -): string { - const sha = `\`${input.headSha.slice(0, 7)}\``; - const lines: string[] = []; +/** The state image and label the status row shows. */ +function statusState(status: ReviewStatus): { image: StatusImage | null; label: string } { switch (status.kind) { case 'running': - lines.push(`> ⏳ **Reviewing ${sha}** · ${phaseText(status.phase)}…`); - break; + return { image: 'building', label: phaseText(status.phase) }; case 'retrying': - lines.push(`> ⚠️ **The review of ${sha} was interrupted.** Hansi will try again.`); - break; + return { image: 'waiting', label: 'Interrupted, retrying' }; case 'failed': - lines.push( - `> ⚠️ **Hansi could not finish reviewing ${sha}.** Comment ${input.mention} review to try again.` - ); - break; + return { image: 'failed', label: 'Failed' }; case 'skipped': - lines.push(`> Skipped ${sha}: ${status.reason}`); - break; + return { image: null, label: 'Skipped' }; + } +} + +/** + * The block at the top of the summary comment, between hidden markers so it can be replaced. It + * is the progress row of Appwrite's Sites and Functions comments: the commit, the animated state + * image while the review runs, and a link to follow it. + */ +export function statusBlock( + status: ReviewStatus, + input: { + headSha: string; + mention: string; + previous: boolean; + detailsUrl?: string; + images?: string; + } +): string { + const { image, label } = statusState(status); + const columns = ['Commit', 'Status']; + const row = [`\`${input.headSha.slice(0, 7)}\``, statusCell(image, label, input.images)]; + if (status.kind === 'running' && input.detailsUrl) { + columns.push('Details'); + row.push(`[Follow along](${input.detailsUrl})`); } const notes = [ + status.kind === 'retrying' ? 'The review was interrupted. Hansi will try again.' : '', + status.kind === 'failed' + ? `Hansi could not finish this review. Comment ${input.mention} review to try again.` + : '', + status.kind === 'skipped' ? status.reason : '', input.previous && status.kind !== 'skipped' ? 'The summary below is from the previous review.' - : '', - status.kind === 'running' && input.detailsUrl ? `[Follow along](${input.detailsUrl})` : '' + : '' ].filter(Boolean); - if (notes.length) lines.push('>', `> ${notes.join(' · ')}`); - return [STATUS_START, ...lines, STATUS_END].join('\n'); + const lines = [ + `| ${columns.join(' | ')} |`, + `| ${columns.map(() => ':-').join(' | ')} |`, + `| ${row.join(' | ')} |` + ]; + if (notes.length) lines.push('', `${notes.join(' ')}`); + // Blank lines keep the hidden markers apart from the table, so every provider renders it. + return [STATUS_START, '', ...lines, '', STATUS_END].join('\n'); } /** The status block in a summary body, if it has one. */ @@ -134,6 +157,8 @@ export interface ProgressTarget { headSha: string; mention: string; detailsUrl?: string; + /** The Console's origin, where the status images are served. Absent: the status is text. */ + images?: string; log: Log; updateCheckRun: (output: { title: string; summary: string }) => Promise; readSummary: () => Promise<{ id: string; body: string } | null>; @@ -184,7 +209,8 @@ export function createReviewProgress(target: ProgressTarget): ReviewProgress { headSha: target.headSha, mention: target.mention, previous: hasReviewSummary(existing?.body ?? null), - detailsUrl: target.detailsUrl + detailsUrl: target.detailsUrl, + images: target.images }) : null; const body = withStatusBlock(existing?.body ?? null, block); diff --git a/packages/engine/src/review-job.test.ts b/packages/engine/src/review-job.test.ts index 5f5cf94..c95bb5c 100644 --- a/packages/engine/src/review-job.test.ts +++ b/packages/engine/src/review-job.test.ts @@ -149,7 +149,11 @@ describe('runReviewJob', () => { const summary = github.summary(); expect(summary).toStartWith(summaryMarkerFor('repo1')); expect(summary).toContain('Divides for real.'); - expect(summary).toContain('| Verdict |'); + // The status images come from the Console, as in Appwrite's Sites and Functions comments. + expect(summary).toContain( + 'srcset="https://cloud.appwrite.io/images/vcs/status-ready-dark.png"' + ); + expect(summary).toContain('_Reviewed_'); expect(summary).toContain('@hansi review'); expect(summary).not.toContain('appwrite-hansi:status'); @@ -235,7 +239,7 @@ describe('runReviewJob', () => { const check = github.checkRuns.at(-1); expect(check?.conclusion).toBe('neutral'); expect(check?.title).toStartWith('Tier S: '); - expect(github.summary()).toContain('Tier S'); + expect(github.summary()).toContain('🟢 **S** · Ready to merge'); expect(github.reviews[0]?.state).toBe('DISMISSED'); expect(results.review('review2')).toMatchObject({ tier: 'S', verdict: 'comment' }); }); diff --git a/packages/engine/src/review-job.ts b/packages/engine/src/review-job.ts index ae0a472..d82a0e1 100644 --- a/packages/engine/src/review-job.ts +++ b/packages/engine/src/review-job.ts @@ -64,6 +64,7 @@ import { lastCompleted, modelUsage, reviewDetailsUrl, + statusImagesOrigin, withdrawChangeRequests, withWorkdir } from './shared'; @@ -244,6 +245,7 @@ async function executeReview( } const detailsUrl = reviewDetailsUrl(job.repository.consoleUrl, ref.projectId, ref.reviewId); + const images = statusImagesOrigin(job.repository); const checkRunId = await github.startCheckRun({ headSha: pr.headSha, name: CHECK_NAME, @@ -256,6 +258,7 @@ async function executeReview( headSha: pr.headSha, mention, detailsUrl, + images, log, updateCheckRun: (output) => github.updateCheckRun(checkRunId, output), readSummary: () => github.getMarkedComment(pr.number, SUMMARY_MARKER), @@ -355,6 +358,7 @@ async function executeReview( consoleUrl: job.repository.consoleUrl, checkRunId, detailsUrl, + images, decision, blocking: changeRequestSeverity(config), lastDecisiveVerdict: history.lastDecisiveVerdict, @@ -509,7 +513,8 @@ async function executeReview( staleHead: decision.note, incrementalFrom, detailsUrl, - mention + mention, + images }); let submission = decide((await github.getPullRequest(pr.number)).headSha); @@ -878,6 +883,7 @@ async function finishMergeOnly(input: { consoleUrl?: string; checkRunId: string; detailsUrl?: string; + images?: string; decision: Extract; /** Findings at or above this keep a change request standing; null when it never requests changes. */ blocking: Severity | null; @@ -918,6 +924,7 @@ async function finishMergeOnly(input: { repository: input.repository, mention: `@${app.slug}`, detailsUrl: input.detailsUrl, + images: input.images, scope: decision.scope, review: carried, findings, diff --git a/packages/engine/src/shared.test.ts b/packages/engine/src/shared.test.ts new file mode 100644 index 0000000..1cc7c86 --- /dev/null +++ b/packages/engine/src/shared.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, test } from 'bun:test'; +import { statusImagesOrigin } from './shared'; + +describe('statusImagesOrigin', () => { + test("is the Console's origin, where Appwrite serves the status images", () => { + expect( + statusImagesOrigin({ provider: 'github', consoleUrl: 'https://cloud.appwrite.io/console' }) + ).toBe('https://cloud.appwrite.io'); + for (const provider of ['gitlab', 'bitbucket', 'gitea'] as const) { + expect(statusImagesOrigin({ provider, consoleUrl: 'http://localhost/console/' })).toBe( + 'http://localhost' + ); + } + }); + + test('is absent on Origin, without a Console, or for a root that is not a URL', () => { + expect( + statusImagesOrigin({ provider: 'origin', consoleUrl: 'https://cloud.appwrite.io/console' }) + ).toBeUndefined(); + expect(statusImagesOrigin({ provider: 'github' })).toBeUndefined(); + expect(statusImagesOrigin({ provider: 'github', consoleUrl: 'console' })).toBeUndefined(); + }); +}); diff --git a/packages/engine/src/shared.ts b/packages/engine/src/shared.ts index fd678d1..82439b8 100644 --- a/packages/engine/src/shared.ts +++ b/packages/engine/src/shared.ts @@ -3,6 +3,7 @@ import { hostname, tmpdir } from 'node:os'; import { join } from 'node:path'; import type { Log } from './context'; import type { GitHubConnection } from './github'; +import type { Repository } from './jobs'; import type { ModelCall } from './model-call'; import type { ModelUsage, ReviewRecord } from './results'; @@ -27,6 +28,22 @@ export function reviewDetailsUrl( return `${base}/projects/${encodeURIComponent(projectId)}/reviews/${encodeURIComponent(reviewId)}`; } +/** + * The Console's origin, which serves the status images of Appwrite's Sites and Functions + * comments. Origin gets text instead, as it does in Appwrite's own comments: it cannot show images + * from another host. Without a Console root, there are no images either. + */ +export function statusImagesOrigin( + repository: Pick +): string | undefined { + if (repository.provider === 'origin' || !repository.consoleUrl) return undefined; + try { + return new URL(repository.consoleUrl).origin; + } catch { + return undefined; + } +} + /** One model call as Appwrite meters it. */ export function modelUsage(call: ModelCall): ModelUsage { return { diff --git a/packages/engine/src/summary.test.ts b/packages/engine/src/summary.test.ts index 826f018..79254d3 100644 --- a/packages/engine/src/summary.test.ts +++ b/packages/engine/src/summary.test.ts @@ -38,8 +38,9 @@ describe('summaryAfterSettlement', () => { expect(input.stillOpen).toEqual([]); const body = formatSummaryComment(input); - expect(body).toContain('## 🟢 Tier S'); - expect(body).toContain('| ✅ Approved | 0 | 0 | 0 |'); + expect(body).toContain('🟢 **S** · Ready to merge'); + expect(body).toContain('| ✅ Approved |'); + expect(body).not.toContain('Findings'); expect(body).not.toContain('Still open from earlier reviews'); expect(body).not.toContain('/api responses bypass'); }); @@ -180,7 +181,7 @@ describe('summaryExtrasFromBody', () => { }); const body = formatSummaryComment(input); expect(body).toContain('3 of 12 changed files were too large to include in full.'); - expect(body).toContain("### Couldn't attach to a line"); + expect(body).toContain("Couldn't attach to a line"); expect(body).toContain('Caption manifest mixes formats'); expect(body).toContain('Lines outside the changed hunks'); expect(body).not.toContain( diff --git a/packages/engine/src/summary.ts b/packages/engine/src/summary.ts index c340588..2ecd7f6 100644 --- a/packages/engine/src/summary.ts +++ b/packages/engine/src/summary.ts @@ -4,6 +4,7 @@ import type { Finding } from './findings'; import { filesTooLargeFromBody, formatSummaryComment, + latestChangesFromBody, STALE_HEAD_NOTE_MARK, SUMMARY_MARKER, type SummaryInput @@ -46,9 +47,7 @@ export type SummaryExtras = { * drop them. These are not stored on the review row. */ export function summaryExtrasFromBody(body: string): SummaryExtras { - // latestChanges can span lines; it always sits before the verdict table. - const latestChanges = - body.match(/\*\*Latest changes:\*\* ([\s\S]*?)\n\n\| Verdict \|/)?.[1] ?? null; + const latestChanges = latestChangesFromBody(body); const noteLines = [...body.matchAll(/> \[!NOTE\]\n> (.+)/g)].map((match) => match[1] ?? ''); const stalePrefix = `${STALE_HEAD_NOTE_MARK} `; const staleLine = noteLines.find((line) => line.startsWith(stalePrefix)); @@ -80,6 +79,8 @@ export async function refreshSummaryAfterSettlement(input: { /** Where file links hang off: `//`. */ repository: string; consoleUrl?: string; + /** The Console's origin, where the status images are served. Absent: the status is text. */ + images?: string; /** * Findings at or above this severity keep a change request standing * (`reviews.requestChanges`); null when the repository never requests changes. @@ -114,6 +115,7 @@ export async function refreshSummaryAfterSettlement(input: { findings: rows, detailsUrl: reviewDetailsUrl(input.consoleUrl, pull.projectId, last.id), mention, + images: input.images, ...extras }); @@ -160,6 +162,7 @@ export function summaryAfterSettlement( findings: FindingRow[]; detailsUrl?: string; mention: string; + images?: string; } & SummaryExtras ): SummaryInput { const toFinding = (row: FindingRow): Finding => ({ @@ -216,6 +219,7 @@ export function summaryAfterSettlement( incrementalFrom: input.incrementalFrom, scope: input.scope, detailsUrl: input.detailsUrl, - mention: input.mention + mention: input.mention, + images: input.images }; } From f4246aa74a7131d08bf0aa793a019c231953e8ad Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 09:38:30 +0000 Subject: [PATCH 2/2] Take the status images' host from the job, not the Console URL On Cloud the Console (appwrite.io) does not serve /images/vcs/; the Appwrite host (cloud.appwrite.io) does, as consoleHostname in Appwrite's own comments. Appwrite names it as repository.imagesUrl; without it the status stays text. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F3M7tukAPsZ8K2YWuskhgg Co-authored-by: Torsten Dittmann <1759475+TorstenDittmann@users.noreply.github.com> --- packages/appwrite/src/payload.test.ts | 12 ++++++++++++ packages/appwrite/src/payload.ts | 3 ++- packages/engine/src/jobs.ts | 5 +++++ packages/engine/src/review-job.test.ts | 3 ++- packages/engine/src/shared.test.ts | 12 ++++++------ packages/engine/src/shared.ts | 12 ++++++------ 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/appwrite/src/payload.test.ts b/packages/appwrite/src/payload.test.ts index dc5bca4..46e7b1a 100644 --- a/packages/appwrite/src/payload.test.ts +++ b/packages/appwrite/src/payload.test.ts @@ -77,6 +77,18 @@ describe('parseJob', () => { expect(job.type).toBe('chat'); }); + test('reads the host of the status images, which an older Appwrite does not send', () => { + expect(parseJob(review).repository.imagesUrl).toBeUndefined(); + const withImages = { + ...review, + repository: { ...repository, imagesUrl: 'https://cloud.appwrite.io' } + }; + expect(parseJob(withImages).repository.imagesUrl).toBe('https://cloud.appwrite.io'); + expect(() => + parseJob({ ...review, repository: { ...repository, imagesUrl: 'cloud' } }) + ).toThrow(); + }); + test('reviews on GitHub when Appwrite names no provider', () => { expect(parseJob(review).repository.provider).toBe('github'); expect(() => parseJob({ ...review, repository: { ...repository, provider: 'azure' } })).toThrow( diff --git a/packages/appwrite/src/payload.ts b/packages/appwrite/src/payload.ts index 5f48876..ad43f5f 100644 --- a/packages/appwrite/src/payload.ts +++ b/packages/appwrite/src/payload.ts @@ -23,7 +23,8 @@ const repository = z.object({ providerRepositoryId: providerId, owner: id, name: id, - consoleUrl: z.url().optional() + consoleUrl: z.url().optional(), + imagesUrl: z.url().optional() }); const comment = z.object({ diff --git a/packages/engine/src/jobs.ts b/packages/engine/src/jobs.ts index 8f58025..38adcc8 100644 --- a/packages/engine/src/jobs.ts +++ b/packages/engine/src/jobs.ts @@ -24,6 +24,11 @@ export interface Repository { name: string; /** The Console's root, for links to a review. Absent when Appwrite has none to give. */ consoleUrl?: string; + /** + * The Appwrite host that serves the status images of its Sites and Functions comments + * (`https://cloud.appwrite.io`). On Cloud it is not the Console's host. Absent: the status is text. + */ + imagesUrl?: string; } /** Git hosts the service reviews on. Each has its own client behind the same contract. */ diff --git a/packages/engine/src/review-job.test.ts b/packages/engine/src/review-job.test.ts index c95bb5c..1980dbc 100644 --- a/packages/engine/src/review-job.test.ts +++ b/packages/engine/src/review-job.test.ts @@ -105,7 +105,8 @@ const repository = { providerRepositoryId: '3', owner: 'acme', name: 'math', - consoleUrl: 'https://cloud.appwrite.io/console' + consoleUrl: 'https://cloud.appwrite.io/console', + imagesUrl: 'https://cloud.appwrite.io' }; const job = (overrides: Partial = {}): ReviewJob => ({ type: 'review', diff --git a/packages/engine/src/shared.test.ts b/packages/engine/src/shared.test.ts index 1cc7c86..6baeff0 100644 --- a/packages/engine/src/shared.test.ts +++ b/packages/engine/src/shared.test.ts @@ -2,22 +2,22 @@ import { describe, expect, test } from 'bun:test'; import { statusImagesOrigin } from './shared'; describe('statusImagesOrigin', () => { - test("is the Console's origin, where Appwrite serves the status images", () => { + test('is the origin of the Appwrite host that serves the status images', () => { expect( - statusImagesOrigin({ provider: 'github', consoleUrl: 'https://cloud.appwrite.io/console' }) + statusImagesOrigin({ provider: 'github', imagesUrl: 'https://cloud.appwrite.io/' }) ).toBe('https://cloud.appwrite.io'); for (const provider of ['gitlab', 'bitbucket', 'gitea'] as const) { - expect(statusImagesOrigin({ provider, consoleUrl: 'http://localhost/console/' })).toBe( + expect(statusImagesOrigin({ provider, imagesUrl: 'http://localhost' })).toBe( 'http://localhost' ); } }); - test('is absent on Origin, without a Console, or for a root that is not a URL', () => { + test('is absent on Origin, when Appwrite names no host, or for one that is not a URL', () => { expect( - statusImagesOrigin({ provider: 'origin', consoleUrl: 'https://cloud.appwrite.io/console' }) + statusImagesOrigin({ provider: 'origin', imagesUrl: 'https://cloud.appwrite.io/' }) ).toBeUndefined(); expect(statusImagesOrigin({ provider: 'github' })).toBeUndefined(); - expect(statusImagesOrigin({ provider: 'github', consoleUrl: 'console' })).toBeUndefined(); + expect(statusImagesOrigin({ provider: 'github', imagesUrl: 'cloud' })).toBeUndefined(); }); }); diff --git a/packages/engine/src/shared.ts b/packages/engine/src/shared.ts index 82439b8..4654778 100644 --- a/packages/engine/src/shared.ts +++ b/packages/engine/src/shared.ts @@ -29,16 +29,16 @@ export function reviewDetailsUrl( } /** - * The Console's origin, which serves the status images of Appwrite's Sites and Functions - * comments. Origin gets text instead, as it does in Appwrite's own comments: it cannot show images - * from another host. Without a Console root, there are no images either. + * Where the status images of Appwrite's Sites and Functions comments are served: the Appwrite + * host Appwrite names in the job, not the Console's, which differs on Cloud. Origin gets text + * instead, as it does in Appwrite's own comments: it cannot show images from another host. */ export function statusImagesOrigin( - repository: Pick + repository: Pick ): string | undefined { - if (repository.provider === 'origin' || !repository.consoleUrl) return undefined; + if (repository.provider === 'origin' || !repository.imagesUrl) return undefined; try { - return new URL(repository.consoleUrl).origin; + return new URL(repository.imagesUrl).origin; } catch { return undefined; }