* feat(forge): let providers declare their hosts, names, sign-in, and review decisions Prepare the forge contract for a second provider: - ForgeProvider lists the hosts it serves and names itself (label, changeRequestNoun); registering a provider that lists a host another registered provider lists throws, so each URL has at most one provider. ctx.forge.describe(forge) returns the family's ForgeDescription. - ForgeReadiness carries the sign-in command, which the panel's sign-in banner shows instead of building `gh auth login` for the github family. - ForgeReviewData lists the review decisions the host lets the reader record; the review dialog offers only those instead of hardcoding the GitHub rule that a pull request's author may only comment. - ForgeReviewThread.original may name a later commit the host carried the thread to while its lines stayed unchanged. - The changes view names the code host and its word for a change request from the entry's ForgeDescription instead of hardcoding GitHub and PR. The GitHub provider declares its configured hosts, GitHub, pull requests, `gh auth login --hostname <host>`, and reads viewerDidAuthor for the review decisions. Upgrade guide: forge-provider-hosts. * feat(forge-gitlab): read GitLab merge requests through the GitLab CLI Add the experimental forge-gitlab provider. It serves the configured GitLab hosts through glab: status batches over GraphQL, head-pinned patches from merge request diff versions, commit listings, merge bases, pipeline jobs, closing issues, and review threads mapped from REST discussions, including outdated threads' hunks. The forge bundle composes the provider, disabled by default. * feat(forge-gitlab): write GitLab reviews, retry pipelines, request reviews, and rebase The GitLab provider now writes through glab as well as reading: comments start discussions at positions derived from the head's diff version, pending replies and comments are draft notes that a review publishes with its summary and review state, and approving checks the head through GitLab's sha parameter. Review reads carry the signed-in user's rights from GraphQL, their draft notes as the pending review, and the decisions GitLab lets them record. Snapshots name the head pipeline as every job's rerun, offer rebase as the branch update, and follow GitLab's permissions for reruns and review requests. updateBranch's contract now states how a provider whose host takes no expected head checks it. * feat(forge): let forge providers register the commands that bind change requests forge-session no longer recognizes gh commands by itself. A provider now registers a declarative ForgeCommandRule through ctx.forgeSession.registerCommands: its executable, creation and reference subcommands, change request page path, JSON URL members, declared options, and a pure select that maps one parsed reference command to a URL or a read-only lookup. forge-github registers gh and forge-gitlab registers glab, which adds glab mr create, view, update, and checkout, including numbers with -R: a full project URL binds directly, and other repository forms resolve through glab mr view in the call's shell. forge-session keeps the shared parts: the literal shell tokenizer, option parsing, output reading, lookups, and the projection. The forgeChangeRequests state version derives from the recognized rules, so a changed rule set refolds every Session, including commands that ran before the provider loaded. Ending a registration keeps its rule recognized until restart, so unloading providers at shutdown does not rewrite every checkpoint. * refactor(forge-gitlab): publish the GitLab provider as @deepseek-ai/dsh-forge-gitlab New experimental packages omit the experimental prefix so that promotion keeps their npm name. Register the directory in EXPERIMENTAL_PACKAGE_NAME_EXCEPTIONS instead of growing the legacy prefixed list, and rename every dependency, configuration row, path mapping, and document that names the package. * fix(forge-gitlab): keep review writes, comment positions, and reads within GitLab's facts and the limits - After GitLab refuses a publication, read the drafts again: delete them only when all remain, since GitLab can publish them before it refuses the summary, and report the outcome as unknown otherwise. A rollback that leaves drafts reports how many may remain. - Place comments on files GitLab collapsed through the diff compared from their texts, and let a file's new path name it over another file's old path after chained renames. - Keep the final newline of raw file reads. - Apply maxOutputBytes to the complete review result, and report a read whose rights stop early or skip a discussion's later notes as truncated. - Serve a version over maxCachedVersionBytes without keeping it. - Resolve uploaded avatars GitLab names by their path on the host. - Schedule bounded reads through p-limit. * fix(forge-session): run lookups only for live command rules and keep the projection registered - Reference lookups use the rules of live registrations, so a disposed provider's rule still folds but starts no gh or glab process. - A failed re-registration registers the projection again with the earlier rules, so clients keep its view; an error is logged only when that fails too. - Document the startup re-registration, test that the checkpointed state version survives a real Loader start, shutdown, and restart, and record that starting without a provider removes the bindings only its commands made. - Describe the changes view's pending review and single comment without naming GitHub, which keeps its own rule in forge-github, and render registerCommands as code in the generated service reference. * fix(forge-bundle): name GitLab merge requests in the bundle description The bundle now follows GitLab merge requests as well as GitHub pull requests, so the description's first sentence in every locale names both kinds of change request. * feat(forge): bind the change requests that gh api and glab api requests name Models often read a merge request through `glab api` or a pull request through `gh api` instead of `glab mr view` or `gh pr view`, which left the change request unbound. A command rule now declares raw API request subcommands beside its reference subcommands, each group with its own options, since `-f` is a value of `gh api` and a flag of `gh pr checkout`. An API request binds, as referenced, only the change request its REST path names, such as `projects/group%2Fapp/merge_requests/7/changes` or `repos/octo/demo/pulls/7/files`; its output is not read, since one request can list many change requests. A path whose host the command names binds directly, and one without a host, or with the current repository's placeholders, resolves through the CLI's view command in the call's shell. The gh and glab rules move to version 2. * docs(forge): add forge-gitlab and the forge-session peers to the module graph Regenerate docs/module-graph for the renamed GitLab provider and the optional forge-session peer of both providers. * test(web): refresh the forge bundle description in the recommended plugin catalog The creation recommendation recording carries every recommended plugin's description; refresh it for the forge bundle description that now names GitLab merge requests and the glab sign-in. * chore(forge-gitlab): carry the 0.2.2-rc.3 release version and move upgrade guides to v0.2.2-rc.3
349 lines
20 KiB
TypeScript
349 lines
20 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { GhOutputLimitError, type GhOutput, type GhRunner } from '../src/gh.ts'
|
|
import { GitHubProvider } from '../src/provider.ts'
|
|
import type { GitHubLimits } from '../src/provider.ts'
|
|
import { REVIEW_QUERY, REVIEW_THREADS_QUERY, THREAD_COMMENTS_QUERY } from '../src/threads.ts'
|
|
import { demo, pull } from './fixtures.ts'
|
|
|
|
const head = 'c'.repeat(40)
|
|
const older = 'a'.repeat(40)
|
|
const pushed = 'd'.repeat(40)
|
|
const signal = new AbortController().signal
|
|
|
|
function output(stdout: unknown, exitCode = 0, stderr = ''): GhOutput {
|
|
return { exitCode, stdout: typeof stdout === 'string' ? stdout : JSON.stringify(stdout), stderr }
|
|
}
|
|
|
|
/** Answer each `gh` call through `handler`, recording the arguments. */
|
|
function fakeGh(handler: (args: readonly string[]) => GhOutput): { run: GhRunner; calls: string[][] } {
|
|
const calls: string[][] = []
|
|
return { calls, run: async (args) => { calls.push([...args]); return handler(args) } }
|
|
}
|
|
|
|
function provider(run: GhRunner, limits: Partial<GitHubLimits> = {}): GitHubProvider {
|
|
return new GitHubProvider(run, ['github.com'], { maxOutputBytes: 8_388_608, maxReviewThreads: 1_000, maxCommits: 250, maxViewedFiles: 3_000, ...limits })
|
|
}
|
|
|
|
function page(nodes: readonly unknown[], next: string | null = null): Record<string, unknown> {
|
|
return { pageInfo: { hasNextPage: next !== null, endCursor: next }, nodes }
|
|
}
|
|
|
|
/** One review comment node as the thread query selects it. */
|
|
function commentNode(id: string, overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
|
return {
|
|
id, state: 'SUBMITTED', createdAt: '2026-11-05T08:00:00Z', url: `https://github.com/octo/demo/pull/7#discussion_${id}`, body: `Body of ${id}`,
|
|
viewerCanUpdate: false, viewerCanDelete: false,
|
|
author: { __typename: 'User', login: 'reviewer', avatarUrl: 'https://avatars.githubusercontent.com/u/1?s=48&v=4' },
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
/** One review thread node on a new-side line at the head, with one comment. */
|
|
function threadNode(id: string, overrides: Record<string, unknown> = {}, root: Record<string, unknown> = {}): Record<string, unknown> {
|
|
return {
|
|
id, isOutdated: false, isResolved: false, path: 'src/a.ts', diffSide: 'RIGHT', startDiffSide: null,
|
|
line: 12, startLine: null, originalLine: 12, originalStartLine: null, subjectType: 'LINE',
|
|
viewerCanReply: true, viewerCanResolve: true, viewerCanUnresolve: false,
|
|
root: { nodes: [{ diffHunk: '@@ -10,2 +10,3 @@\n a\n+b\n c', commit: { oid: head }, originalCommit: { oid: head }, ...root }] },
|
|
comments: page([commentNode(`${id}-1`)]),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
function firstPage(
|
|
threads: Record<string, unknown>, headRefOid = head, viewer: unknown = { login: 'octo' }, pull: Record<string, unknown> = {},
|
|
repository: Record<string, unknown> = {},
|
|
): Record<string, unknown> {
|
|
return { data: { viewer, repository: { isArchived: false, viewerPermission: 'READ', ...repository, pullRequest: {
|
|
id: 'pull-7', headRefOid, locked: false, viewerDidAuthor: false, reviews: { nodes: [] }, reviewThreads: threads, ...pull,
|
|
} } } }
|
|
}
|
|
|
|
function nextPage(threads: Record<string, unknown>, headRefOid = head): Record<string, unknown> {
|
|
return { data: { node: { headRefOid, reviewThreads: threads } } }
|
|
}
|
|
|
|
/** Whether a scripted answer is `gh` output as printed rather than a JSON body. */
|
|
function isRaw(answer: Record<string, unknown> | { readonly raw: GhOutput }): answer is { readonly raw: GhOutput } {
|
|
return 'raw' in answer
|
|
}
|
|
|
|
/** Answer the first thread page with `first`, later thread pages from `later` by cursor, and comment pages from `comments` by cursor. */
|
|
function review(
|
|
first: Record<string, unknown> | { readonly raw: GhOutput },
|
|
later: Readonly<Record<string, Record<string, unknown>>> = {},
|
|
comments: Readonly<Record<string, Record<string, unknown>>> = {},
|
|
): ReturnType<typeof fakeGh> {
|
|
return fakeGh((args) => {
|
|
const cursor = args.find(arg => arg.startsWith('cursor='))?.slice('cursor='.length) ?? ''
|
|
if (args.includes(`query=${REVIEW_QUERY}`)) return isRaw(first) ? first.raw : output(first)
|
|
if (args.includes(`query=${REVIEW_THREADS_QUERY}`)) return output(later[cursor] ?? { data: { node: null } })
|
|
if (args.includes(`query=${THREAD_COMMENTS_QUERY}`)) return output(comments[cursor] ?? { data: { node: null } })
|
|
throw new Error(`unexpected gh ${args.join(' ')}`)
|
|
})
|
|
}
|
|
|
|
describe('GitHub provider review threads', () => {
|
|
it('reads the first page with the head, the viewer, and the pull request as variables, and maps a thread placed at the head', async () => {
|
|
const gh = review(firstPage(page([threadNode('t1', { isResolved: true })])))
|
|
|
|
await expect(provider(gh.run).readReview(pull(7), head, signal)).resolves.toEqual({
|
|
headSha: head,
|
|
viewer: 'octo',
|
|
truncated: false,
|
|
pendingReview: null,
|
|
viewerCanReview: true,
|
|
reviewEvents: ['comment', 'approve', 'request-changes'],
|
|
threads: [{
|
|
id: 't1', path: 'src/a.ts', side: 'R', subject: 'line',
|
|
current: { commit: head, startLine: 12, endLine: 12 },
|
|
original: { commit: head, startLine: 12, endLine: 12 },
|
|
diffHunk: '@@ -10,2 +10,3 @@\n a\n+b\n c',
|
|
resolved: true,
|
|
viewerCanReply: true,
|
|
viewerCanResolve: false,
|
|
comments: [{
|
|
id: 't1-1', body: 'Body of t1-1', createdAt: '2026-11-05T08:00:00Z', pending: false,
|
|
url: 'https://github.com/octo/demo/pull/7#discussion_t1-1',
|
|
author: { login: 'reviewer', avatarUrl: 'https://avatars.githubusercontent.com/u/1?s=48&v=4', bot: false },
|
|
viewerCanEdit: false, viewerCanDelete: false,
|
|
}],
|
|
}],
|
|
})
|
|
expect(gh.calls).toEqual([['api', 'graphql', '--hostname', 'github.com', '-f', `query=${REVIEW_QUERY}`,
|
|
'-f', `owner=${demo.owner}`, '-f', `name=${demo.name}`, '-F', 'number=7', '-F', 'first=100']])
|
|
})
|
|
|
|
it('places a thread GitHub moved to the head at its current lines and keeps the lines it was written on', async () => {
|
|
const gh = review(firstPage(page([threadNode('moved', { line: 136, originalLine: 135 }, { originalCommit: { oid: older } })])))
|
|
|
|
const result = await provider(gh.run).readReview(pull(7), head, signal)
|
|
|
|
expect(result).toMatchObject({ threads: [{
|
|
current: { commit: head, startLine: 136, endLine: 136 }, original: { commit: older, startLine: 135, endLine: 135 },
|
|
}] })
|
|
})
|
|
|
|
it.each([
|
|
['GitHub marks it outdated without a line', { isOutdated: true, line: null }, {}],
|
|
['GitHub marks it outdated but keeps a line', { isOutdated: true, line: 303, startLine: 294 }, {}],
|
|
['GitHub reports no line', { line: null }, {}],
|
|
['its comment is on a commit other than the head', {}, { commit: { oid: older }, originalCommit: { oid: older } }],
|
|
['its comment has no commit', {}, { commit: null }],
|
|
] as const)('gives a thread no current position when %s', async (_label, thread, root) => {
|
|
const gh = review(firstPage(page([threadNode('old', { originalLine: 9, ...thread }, root)])))
|
|
|
|
const result = await provider(gh.run).readReview(pull(7), head, signal)
|
|
|
|
expect(result).toMatchObject({ threads: [{ current: null, original: { startLine: 9, endLine: 9 } }] })
|
|
})
|
|
|
|
it('maps a file thread without positions or hunk, an old-side range, and a range that starts on the other side', async () => {
|
|
const gh = review(firstPage(page([
|
|
threadNode('file', { subjectType: 'FILE', line: null, originalLine: null }, { diffHunk: '' }),
|
|
threadNode('left', { diffSide: 'LEFT', startDiffSide: 'LEFT', startLine: 3, line: 5, originalStartLine: 3, originalLine: 5 }),
|
|
threadNode('cross', { diffSide: 'RIGHT', startDiffSide: 'LEFT', startLine: 4, line: 6, originalStartLine: 4, originalLine: 6 }),
|
|
threadNode('reversed', { startLine: 8, line: 6, originalStartLine: 0, originalLine: 6 }),
|
|
])))
|
|
|
|
const result = await provider(gh.run).readReview(pull(7), head, signal)
|
|
|
|
expect(result).toMatchObject({ threads: [
|
|
{ id: 'file', subject: 'file', side: 'R', current: null, original: null, diffHunk: null },
|
|
{ id: 'left', side: 'L', current: { startLine: 3, endLine: 5 }, original: { startLine: 3, endLine: 5 } },
|
|
{ id: 'cross', side: 'R', current: { startLine: 6, endLine: 6 }, original: { startLine: 6, endLine: 6 } },
|
|
{ id: 'reversed', current: { startLine: 6, endLine: 6 }, original: { startLine: 6, endLine: 6 } },
|
|
] })
|
|
})
|
|
|
|
it('maps pending comments, bots, and deleted authors, and drops a thread without comments', async () => {
|
|
const gh = review(firstPage(page([
|
|
threadNode('t1', { comments: page([
|
|
commentNode('c1', { author: { __typename: 'Bot', login: 'ci', avatarUrl: null } }),
|
|
commentNode('c2', { state: 'PENDING', author: null, url: null }),
|
|
]) }),
|
|
threadNode('empty', { comments: page([]) }, { diffHunk: '' }),
|
|
])))
|
|
|
|
const result = await provider(gh.run).readReview(pull(7), head, signal)
|
|
|
|
expect(result).toMatchObject({ threads: [{ id: 't1', comments: [
|
|
{ id: 'c1', author: { login: 'ci', avatarUrl: null, bot: true }, pending: false },
|
|
{ id: 'c2', author: null, pending: true, url: null },
|
|
] }] })
|
|
expect(result).toMatchObject({ threads: { length: 1 } })
|
|
})
|
|
|
|
it('maps the permissions of the viewer on threads and comments, resolving an unresolved thread and unresolving a resolved one', async () => {
|
|
const gh = review(firstPage(page([
|
|
threadNode('open', { viewerCanReply: false, viewerCanResolve: true, viewerCanUnresolve: false, comments: page([
|
|
commentNode('mine', { viewerCanUpdate: true, viewerCanDelete: true }),
|
|
]) }),
|
|
threadNode('settled', { isResolved: true, viewerCanResolve: false, viewerCanUnresolve: true }),
|
|
])))
|
|
|
|
const result = await provider(gh.run).readReview(pull(7), head, signal)
|
|
|
|
expect(result).toMatchObject({ threads: [
|
|
{ id: 'open', viewerCanReply: false, viewerCanResolve: true, comments: [{ id: 'mine', viewerCanEdit: true, viewerCanDelete: true }] },
|
|
{ id: 'settled', viewerCanReply: true, viewerCanResolve: true },
|
|
] })
|
|
})
|
|
|
|
it('reports no viewer when GitHub names none', async () => {
|
|
const gh = review(firstPage(page([]), head, null))
|
|
|
|
await expect(provider(gh.run).readReview(pull(7), head, signal)).resolves.toMatchObject({ viewer: null })
|
|
})
|
|
|
|
it('reports the pending review the viewer authored with its comment count, after another user\'s', async () => {
|
|
const reviews = { nodes: [
|
|
{ id: 'review-other', viewerDidAuthor: false, comments: { totalCount: 5 } },
|
|
{ id: 'review-1', viewerDidAuthor: true, comments: { totalCount: 2 } },
|
|
] }
|
|
const gh = review(firstPage(page([]), head, { login: 'octo' }, { reviews }))
|
|
|
|
await expect(provider(gh.run).readReview(pull(7), head, signal))
|
|
.resolves.toEqual(expect.objectContaining({ pendingReview: { id: 'review-1', comments: 2 } }))
|
|
})
|
|
|
|
it('reports no pending review for one another user authored', async () => {
|
|
const node = { id: 'review-2', viewerDidAuthor: false, comments: { totalCount: 1 } }
|
|
const gh = review(firstPage(page([]), head, { login: 'octo' }, { reviews: { nodes: [node] } }))
|
|
|
|
await expect(provider(gh.run).readReview(pull(7), head, signal)).resolves.toMatchObject({ pendingReview: null })
|
|
})
|
|
|
|
it.each([
|
|
['an archived repository', {}, { isArchived: true, viewerPermission: 'ADMIN' }, false],
|
|
['a locked conversation without write access', { locked: true }, { viewerPermission: 'TRIAGE' }, false],
|
|
['a locked conversation without a known permission', { locked: true }, { viewerPermission: null }, false],
|
|
['a locked conversation with write access', { locked: true }, { viewerPermission: 'WRITE' }, true],
|
|
['an open conversation with read access', {}, { viewerPermission: 'READ' }, true],
|
|
] as const)('reports whether the viewer can review in %s', async (_label, pullFields, repository, expected) => {
|
|
const gh = review(firstPage(page([]), head, { login: 'octo' }, pullFields, repository))
|
|
|
|
await expect(provider(gh.run).readReview(pull(7), head, signal)).resolves.toMatchObject({
|
|
viewerCanReview: expected, reviewEvents: expected ? ['comment', 'approve', 'request-changes'] : [],
|
|
})
|
|
})
|
|
|
|
it('lets the author of the pull request only comment, as GitHub allows', async () => {
|
|
const gh = review(firstPage(page([]), head, { login: 'octo' }, { viewerDidAuthor: true }))
|
|
|
|
await expect(provider(gh.run).readReview(pull(7), head, signal)).resolves.toMatchObject({ viewerCanReview: true, reviewEvents: ['comment'] })
|
|
})
|
|
|
|
it('reads the following thread and comment pages, asking only for the threads left under maxReviewThreads', async () => {
|
|
const gh = review(
|
|
firstPage(page([threadNode('t1', { comments: page([commentNode('c1')], 'comments-1') })], 'threads-1')),
|
|
{ 'threads-1': nextPage(page([threadNode('t2')], 'threads-2')) },
|
|
{ 'comments-1': { data: { node: { comments: page([commentNode('c2')]) } } } },
|
|
)
|
|
|
|
const result = await provider(gh.run, { maxReviewThreads: 2 }).readReview(pull(7), head, signal)
|
|
|
|
expect(result).toMatchObject({ truncated: true, threads: [
|
|
{ id: 't1', comments: [{ id: 'c1' }, { id: 'c2' }] }, { id: 't2' },
|
|
] })
|
|
expect(gh.calls.slice(1)).toEqual([
|
|
['api', 'graphql', '--hostname', 'github.com', '-f', `query=${THREAD_COMMENTS_QUERY}`, '-f', 'id=t1', '-f', 'cursor=comments-1'],
|
|
['api', 'graphql', '--hostname', 'github.com', '-f', `query=${REVIEW_THREADS_QUERY}`, '-f', 'id=pull-7', '-f', 'cursor=threads-1', '-F', 'first=1'],
|
|
])
|
|
expect(gh.calls[0]).toContain('first=2')
|
|
})
|
|
|
|
it('reports a head other than the requested commit as stale, on the first page or on a later one', async () => {
|
|
const moved = review(firstPage(page([threadNode('t1')]), pushed))
|
|
await expect(provider(moved.run).readReview(pull(7), head, signal))
|
|
.resolves.toEqual({ code: 'stale', message: `the pull request head moved from ${head} to ${pushed}` })
|
|
|
|
const later = review(firstPage(page([threadNode('t1')], 'threads-1')), { 'threads-1': nextPage(page([threadNode('t2')]), pushed) })
|
|
await expect(provider(later.run).readReview(pull(7), head.toUpperCase(), signal))
|
|
.resolves.toEqual({ code: 'stale', message: `the pull request head moved from ${head.toUpperCase()} to ${pushed}` })
|
|
})
|
|
|
|
it('keeps the threads read before a page that passes maxOutputBytes and marks the result truncated', async () => {
|
|
const first = firstPage(page([threadNode('t1', { comments: page([commentNode('c1')], 'comments-1') })], 'threads-1'))
|
|
const size = JSON.stringify(first).length
|
|
const comments = { 'comments-1': { data: { node: { comments: page([commentNode('c2')]) } } } }
|
|
const threads = { 'threads-1': nextPage(page([threadNode('t2')])) }
|
|
|
|
const byComments = review(first, threads, comments)
|
|
await expect(provider(byComments.run, { maxOutputBytes: size + 10 }).readReview(pull(7), head, signal))
|
|
.resolves.toEqual({ headSha: head, viewer: 'octo', threads: [], truncated: true, pendingReview: null, viewerCanReview: true, reviewEvents: ['comment', 'approve', 'request-changes'] })
|
|
|
|
const commentBytes = JSON.stringify(comments['comments-1']).length
|
|
const byThreads = review(first, threads, comments)
|
|
await expect(provider(byThreads.run, { maxOutputBytes: size + commentBytes + 10 }).readReview(pull(7), head, signal))
|
|
.resolves.toMatchObject({ threads: [{ id: 't1' }], truncated: true })
|
|
})
|
|
|
|
it('fails a read whose first page alone passes maxOutputBytes as too-large', async () => {
|
|
const run: GhRunner = async () => { throw new GhOutputLimitError('gh output exceeds maxOutputBytes') }
|
|
|
|
await expect(provider(run).readReview(pull(7), head, signal)).resolves.toEqual({ code: 'too-large', message: 'gh output exceeds maxOutputBytes' })
|
|
})
|
|
|
|
it.each([
|
|
['a thread page without a cursor', firstPage({ pageInfo: { hasNextPage: true, endCursor: null }, nodes: [] }), {}, {},
|
|
'GitHub review thread pagination did not advance'],
|
|
['a thread page that repeats its cursor', firstPage(page([], 'threads-1')), { 'threads-1': nextPage(page([], 'threads-1')) }, {},
|
|
'GitHub review thread pagination did not advance'],
|
|
['a comment page that repeats its cursor', firstPage(page([threadNode('t1', { comments: page([commentNode('c1')], 'comments-1') })])), {},
|
|
{ 'comments-1': { data: { node: { comments: page([], 'comments-1') } } } }, 'GitHub review comment pagination did not advance'],
|
|
['a comment page without a cursor', firstPage(page([threadNode('t1', { comments: { pageInfo: { hasNextPage: true, endCursor: null }, nodes: [] } })])),
|
|
{}, {}, 'GitHub review comment pagination did not advance'],
|
|
['an unexpected first page', { data: { repository: { pullRequest: { id: 'pull-7' } } } }, {}, {}, 'unexpected GitHub response to the review thread read'],
|
|
['an unexpected thread page', firstPage(page([], 'threads-1')), {}, {}, 'unexpected GitHub response to the review thread read'],
|
|
['an unexpected comment page', firstPage(page([threadNode('t1', { comments: page([], 'comments-1') })])), {}, {},
|
|
'unexpected GitHub response to the review thread read'],
|
|
] as const)('reports %s as unavailable', async (_label, first, later, comments, message) => {
|
|
const gh = review(first, later, comments)
|
|
|
|
await expect(provider(gh.run).readReview(pull(7), head, signal)).resolves.toEqual({ code: 'unavailable', message })
|
|
})
|
|
|
|
it.each([
|
|
['a pull request', { data: { viewer: { login: 'octo' }, repository: { isArchived: false, viewerPermission: 'READ', pullRequest: null } } }],
|
|
['a repository', { data: { viewer: { login: 'octo' }, repository: null } }],
|
|
])('reports %s GitHub does not have as not-found, as the commit listing does', async (_label, first) => {
|
|
await expect(provider(review(first).run).readReview(pull(7), head, signal))
|
|
.resolves.toEqual({ code: 'not-found', message: 'pull request 7 was not found' })
|
|
})
|
|
|
|
it('passes on the failure of any page read and of a response that is not JSON', async () => {
|
|
const missing = review({ raw: output('', 1, 'gh: Could not resolve to a PullRequest with the number of 7.') })
|
|
await expect(provider(missing.run).readReview(pull(7), head, signal))
|
|
.resolves.toEqual({ code: 'not-found', message: 'gh: Could not resolve to a PullRequest with the number of 7.' })
|
|
|
|
const garbled = review({ raw: output('not json') })
|
|
await expect(provider(garbled.run).readReview(pull(7), head, signal)).resolves.toEqual({ code: 'unavailable', message: 'unexpected GitHub response' })
|
|
|
|
const refused = review({ raw: output({ data: null, errors: [{ type: 'FORBIDDEN', message: 'Resource not accessible by integration' }] }) })
|
|
await expect(provider(refused.run).readReview(pull(7), head, signal))
|
|
.resolves.toEqual({ code: 'unavailable', message: 'Resource not accessible by integration' })
|
|
|
|
const failing = fakeGh(args => args.includes(`query=${REVIEW_QUERY}`)
|
|
? output(firstPage(page([threadNode('t1', { comments: page([], 'comments-1') })], 'threads-1')))
|
|
: output('', 1, 'gh: Server Error (HTTP 502)'))
|
|
await expect(provider(failing.run).readReview(pull(7), head, signal)).resolves.toEqual({ code: 'unavailable', message: 'gh: Server Error (HTTP 502)' })
|
|
|
|
const failingThreads = fakeGh(args => args.includes(`query=${REVIEW_QUERY}`)
|
|
? output(firstPage(page([threadNode('t1')], 'threads-1')))
|
|
: output('', 1, 'gh: Server Error (HTTP 502)'))
|
|
await expect(provider(failingThreads.run).readReview(pull(7), head, signal))
|
|
.resolves.toEqual({ code: 'unavailable', message: 'gh: Server Error (HTTP 502)' })
|
|
})
|
|
|
|
it('refuses an unconfigured host without starting gh and a head that is not a commit object name', async () => {
|
|
const gh = review(firstPage(page([])))
|
|
const elsewhere = { ...demo, host: 'ghe.other.example' }
|
|
|
|
await expect(provider(gh.run).readReview(pull(7, elsewhere), head, signal))
|
|
.resolves.toEqual({ code: 'unavailable', message: 'forge-github: host "ghe.other.example" is not configured' })
|
|
await expect(provider(gh.run).readReview(pull(7), 'main', signal)).rejects.toThrow('forge-github: invalid head commit "main"')
|
|
expect(gh.calls).toEqual([])
|
|
})
|
|
})
|