Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions packages/appwrite/src/payload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion packages/appwrite/src/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/src/chat-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) =>
Expand Down
8 changes: 4 additions & 4 deletions packages/engine/src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("<summary>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');
Expand Down Expand Up @@ -1757,10 +1757,10 @@ ${upstream}`;
walkthrough: [],
mention: '@hansi-codes'
});
const attachAt = body.indexOf("### Couldn't attach to a line");
const attachAt = body.indexOf("<summary>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);
Expand Down
74 changes: 64 additions & 10 deletions packages/engine/src/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
formatFindingComment,
formatReviewBody,
formatSummaryComment,
latestChangesFromBody,
statusCell,
SUMMARY_MARKER,
type SummaryInput
} from './format';
Expand Down Expand Up @@ -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` | <picture><source media="(prefers-color-scheme: dark)" srcset="https://cloud.appwrite.io/images/vcs/status-ready-dark.png"><img alt="Reviewed" width="85" align="center" src="https://cloud.appwrite.io/images/vcs/status-ready-light.png"></picture> _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('<details open>\n<summary>Findings (1)</summary>');
expect(body).toContain('<summary>Fixed since the last review (1)</summary>');
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('<summary><b>📂 Walkthrough</b> · 1</summary>');
expect(body).toContain('<details>\n<summary>Walkthrough (1)</summary>');
expect(body).toContain('<details>\n<summary>Filtered out (1)</summary>');
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) |');
Expand Down Expand Up @@ -104,7 +131,7 @@ describe('formatSummaryComment', () => {
}
]
});
const section = body.slice(body.indexOf("### Couldn't attach to a line"));
const section = body.slice(body.indexOf("<summary>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.'
);
Expand Down Expand Up @@ -168,9 +195,36 @@ describe('formatSummaryComment', () => {
expect(body).toContain('Reviewed <code>410aa75</code>');
});

test('ends with how to interact', () => {
expect(body).toContain('Reviewed <code>abcdef1</code>');
expect(body).toContain('<code>@hans-review review</code> to re-run');
test('ends with how to interact, in a tip', () => {
expect(body).toContain('<sub>Reviewed <code>abcdef1</code></sub>');
expect(body).toEndWith(
'> [!TIP]\n> Comment <code>@hans-review review</code> to re-run, or mention <code>@hans-review</code> 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(
'<picture><source media="(prefers-color-scheme: dark)" srcset="https://cloud.appwrite.io/images/vcs/status-building-dark.gif"><img alt="Reviewing" width="85" align="center" src="https://cloud.appwrite.io/images/vcs/status-building-light.gif"></picture> _Reviewing_'
);
});
});

Expand Down
Loading