From f24fc94310407d14f3005b4331f84dd55e5c074d Mon Sep 17 00:00:00 2001 From: John Wooten Date: Sun, 11 Oct 2026 16:02:22 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9E=95=20Add=20tests=20for=20pull=20requ?= =?UTF-8?q?est=20overview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Codex --- src/github/pullRequestOverview.ts | 14 ++++++ src/test/github/pullRequestOverview.test.ts | 47 +++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/github/pullRequestOverview.ts b/src/github/pullRequestOverview.ts index a47c0d75b5..54ebd772cf 100644 --- a/src/github/pullRequestOverview.ts +++ b/src/github/pullRequestOverview.ts @@ -521,6 +521,20 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel(); const measure = async (name: string, promise: Promise): Promise => { const start = performance.now(); diff --git a/src/test/github/pullRequestOverview.test.ts b/src/test/github/pullRequestOverview.test.ts index a54b438377..3323566d3a 100644 --- a/src/test/github/pullRequestOverview.test.ts +++ b/src/test/github/pullRequestOverview.test.ts @@ -349,6 +349,7 @@ describe('PullRequestOverview', function () { setStacksEnabled(false); const model = new PullRequestModel(credentialStore, telemetry, repo, remote, convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().number(1000).build(), repo)); + model.bodyHTML = '

Please merge thx

'; const identity = { owner: remote.owner, repo: remote.repositoryName, number: model.number }; pullRequestManager.activePullRequest = initiallyCheckedOut ? model : undefined; sinon.stub(pullRequestManager, 'getCurrentUser').resolves(model.author); @@ -391,6 +392,7 @@ describe('PullRequestOverview', function () { setStacksEnabled(false); const model = new PullRequestModel(credentialStore, telemetry, repo, remote, convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().number(1000).build(), repo)); + model.bodyHTML = '

Please merge thx

'; const getStack = sinon.stub(model, 'getStack'); const postMessage = sinon.spy(PullRequestOverviewPanel.prototype as any, '_postMessage'); sinon.stub(pullRequestManager, 'getCurrentUser').resolves(model.author); @@ -540,6 +542,7 @@ describe('PullRequestOverview', function () { .onFirstCall().returns(blockedInitialization) .onSecondCall().resolves('main'); for (const model of [firstModel, updatedModel]) { + model.bodyHTML = '

Please merge thx

'; sinon.stub(model, 'getReviewRequests').resolves([]); sinon.stub(model, 'getTimelineEvents').resolves([]); sinon.stub(model, 'validateDraftMode').resolves(false); @@ -675,6 +678,7 @@ describe('PullRequestOverview', function () { beforeEach(function () { const prItem = convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().number(1000).build(), repo); + prItem.bodyHTML = '

Please merge thx

'; prModel = new PullRequestModel(credentialStore, telemetry, repo, remote, prItem); getRepository = sinon.stub(pullRequestManager, 'createGitHubRepositoryFromOwnerName').resolves(repo); getPreview = sinon.stub(repo, 'getPullRequestPreview').resolves(preview); @@ -730,6 +734,49 @@ describe('PullRequestOverview', function () { previewLoadingTests(() => ({ model: prModel, preview, getPreview, getRepository, getRepositoryAccess, getAssignableUsers, openPanel, messages, webviewPanel })); + for (const bodyHTML of [undefined, '', ' ']) { + it(`loads missing description HTML before initialization (${JSON.stringify(bodyHTML)})`, async function () { + prModel.bodyHTML = bodyHTML; + let resolveDescription!: (model: PullRequestModel) => void; + const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest') + .returns(new Promise(resolve => resolveDescription = resolve)); + const opening = openPanel(); + await new Promise(resolve => setImmediate(resolve)); + assert.strictEqual(messages.some(message => message.command === 'pr.initialize'), false); + sinon.assert.calledOnce(resolveModel); + sinon.assert.calledWithExactly(resolveModel, remote.owner, remote.repositoryName, prModel.number, false, 'overview'); + prModel.bodyHTML = '

Please merge thx

'; + resolveDescription(prModel); + await opening; + assert.strictEqual(messages.find(message => message.command === 'pr.initialize')?.pullrequest?.bodyHTML, prModel.bodyHTML); + }); + } + + it('does not resolve a description that already has HTML', async function () { + const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest'); + await openPanel(); + sinon.assert.notCalled(resolveModel); + assert.strictEqual(messages.find(message => message.command === 'pr.initialize')?.pullrequest?.bodyHTML, prModel.bodyHTML); + }); + + it('does not resolve an empty description', async function () { + prModel.body = ''; + prModel.bodyHTML = undefined; + const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest'); + await openPanel(); + sinon.assert.notCalled(resolveModel); + assert.ok(messages.some(message => message.command === 'pr.initialize')); + }); + + it('reports a description lookup failure instead of initializing a blank body', async function () { + prModel.bodyHTML = undefined; + sinon.stub(pullRequestManager, 'resolvePullRequest').rejects(new Error('Description lookup failed')); + const showError = sinon.stub(vscode.window, 'showErrorMessage').resolves(undefined); + await openPanel(); + assert.strictEqual(showError.firstCall.args[0], 'Error updating pull request description: Description lookup failed'); + assert.strictEqual(messages.some(message => message.command === 'pr.initialize'), false); + }); + it('keeps the stack queue method when deferred PR data arrives after the stack', async function () { sinon.stub(vscode.env, 'asExternalUri').callsFake(async uri => uri); sinon.stub(prModel, 'getStack').resolves({ From 95e472a50b9e118ac1f4d681a72ddc1856e5bd37 Mon Sep 17 00:00:00 2001 From: John Wooten <60260750+JFWooten4@users.noreply.github.com> Date: Sun, 11 Oct 2026 16:12:48 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20Guard=20PR=20description=20l?= =?UTF-8?q?oading=20against=20stale=20overviews?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Discard description and initialization results after an overview closes or a newer request replaces it, and add GraphQL hydration and race regression coverage. Co-authored-by: Codex Web --- src/github/pullRequestOverview.ts | 17 +++++- src/test/github/pullRequestOverview.test.ts | 59 +++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/github/pullRequestOverview.ts b/src/github/pullRequestOverview.ts index 54ebd772cf..38b5a49ada 100644 --- a/src/github/pullRequestOverview.ts +++ b/src/github/pullRequestOverview.ts @@ -517,6 +517,10 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel this.isDisposed || updateSequence !== this._updateSequence + || overviewIdentity !== this._identity || this._pendingUpdate !== undefined; this._stackLoaded = false; const updateStart = performance.now(); @@ -529,6 +533,9 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel { + builder.pullRequest(response => { + response.repository(repository => { + repository.pullRequest(pullRequest => pullRequest.number(prModel.number) + .body('Actual GitHub Markdown').bodyHTML('

Actual GitHub Markdown

')); + }); + }); + }); + const fetchedModel = await repo.getPullRequest(prModel.number, 'description hydration regression', false, false, 'overview'); + assert(fetchedModel); + assert.strictEqual(fetchedModel.bodyHTML, '

Actual GitHub Markdown

'); + sinon.stub(fetchedModel, 'canEdit').resolves(true); + sinon.stub(fetchedModel, 'getReviewRequests').resolves([]); + sinon.stub(fetchedModel, 'getTimelineEvents').resolves([]); + sinon.stub(fetchedModel, 'validateDraftMode').resolves(false); + sinon.stub(fetchedModel, 'getStatusChecks').resolves([{ state: CheckState.Success, statuses: [] }, null]); + sinon.stub(fetchedModel, 'getMergeability').resolves({ mergeability: PullRequestMergeability.Mergeable }); + const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest').resolves(fetchedModel); + await openPanel(); + sinon.assert.calledOnce(resolveModel); + assert.strictEqual(messages.find(message => message.command === 'pr.initialize')?.pullrequest?.bodyHTML, + '

Actual GitHub Markdown

'); + }); + + it('ignores description lookups that finish after the overview closes', async function () { + prModel.bodyHTML = undefined; + let resolveDescription!: (model: PullRequestModel) => void; + sinon.stub(pullRequestManager, 'resolvePullRequest') + .returns(new Promise(resolve => resolveDescription = resolve)); + const opening = openPanel(); + await new Promise(resolve => setImmediate(resolve)); + webviewPanel.dispose(); + prModel.bodyHTML = '

Late description

'; + resolveDescription(prModel); + await opening; + assert.strictEqual(messages.some(message => message.command === 'pr.initialize'), false); + }); + + it('does not overwrite a newer overview when an older description lookup finishes', async function () { + prModel.bodyHTML = undefined; + let resolveDescription!: (model: PullRequestModel) => void; + const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest') + .returns(new Promise(resolve => resolveDescription = resolve)); + const firstOpening = openPanel(); + await new Promise(resolve => setImmediate(resolve)); + sinon.assert.calledOnce(resolveModel); + const staleModel = new PullRequestModel(credentialStore, telemetry, repo, remote, prModel.item); + staleModel.bodyHTML = '

Old description

'; + prModel.bodyHTML = '

New description

'; + const secondOpening = openPanel(); + resolveDescription(staleModel); + await Promise.all([firstOpening, secondOpening]); + const initializations = messages.filter(message => message.command === 'pr.initialize'); + assert.strictEqual(initializations.length, 1); + assert.strictEqual(initializations[0].pullrequest?.bodyHTML, '

New description

'); + }); + it('does not resolve a description that already has HTML', async function () { const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest'); await openPanel(); From 3657bd58015b3e60db2972d086bc0a7bc740b273 Mon Sep 17 00:00:00 2001 From: Lindsey Pony <346700433+sync@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:12:00 -0500 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Preserve=20descript?= =?UTF-8?q?ion=20hydration=20and=20upstream=20branch-label=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PR adds regression coverage for loading description HTML before initialization and ignoring stale asynchronous overview loads. Upstream adds branch-label coverage for single and multiple repositories and forked pull requests at the same insertion point. Preserve both independent test groups so the description fix and the newer overview labels remain covered. Validation: TypeScript test compilation and all three webpack targets pass; 1,379 extension tests, 130 webview tests and 75 script tests pass. --- src/test/github/pullRequestOverview.test.ts | 129 ++++++++++++++++++-- 1 file changed, 118 insertions(+), 11 deletions(-) diff --git a/src/test/github/pullRequestOverview.test.ts b/src/test/github/pullRequestOverview.test.ts index 51021f8e03..19ae3aa6c4 100644 --- a/src/test/github/pullRequestOverview.test.ts +++ b/src/test/github/pullRequestOverview.test.ts @@ -18,6 +18,7 @@ import { MockCommandRegistry } from '../mocks/mockCommandRegistry'; import { Protocol } from '../../common/protocol'; import { convertRESTPullRequestToRawPullRequest } from '../../github/utils'; import { PullRequestBuilder } from '../builders/rest/pullRequestBuilder'; +import { RepositoryBuilder } from '../builders/rest/repoBuilder'; import { MockExtensionContext } from '../mocks/mockExtensionContext'; import { MockGitHubRepository } from '../mocks/mockGitHubRepository'; import { Repository } from '../../api/api'; @@ -29,7 +30,7 @@ import { EXTENSION_ID } from '../../constants'; import { CredentialStore } from '../../github/credentials'; import { GitHubServerType } from '../../common/authentication'; import { GitHubRemote } from '../../common/remote'; -import { CheckState, GithubItemStateEnum, IAccount, MergeMethod, MergeQueueState, PullRequestMergeability, PullRequestStack, StackablePullRequest } from '../../github/interface'; +import { CheckState, GithubItemStateEnum, IAccount, MergeMethod, MergeQueueState, PullRequestChecks, PullRequestMergeability, PullRequestReviewRequirement, PullRequestStack, StackablePullRequest } from '../../github/interface'; import { GitHubRepository } from '../../github/githubRepository'; import { CreatePullRequestHelper } from '../../view/createPullRequestHelper'; import { RepositoriesManager } from '../../github/repositoriesManager'; @@ -161,7 +162,7 @@ describe('PullRequestOverview', function () { function previewLoadingTests(fixture: () => { model: TItem; preview: TPreview; - getPreview: SinonStub<[number], Promise>; + getPreview: SinonStub<[number, boolean?], Promise>; getRepository: SinonStub, ReturnType>; getRepositoryAccess: SinonStub, ReturnType>; getAssignableUsers: SinonStub, ReturnType>; @@ -923,7 +924,7 @@ describe('PullRequestOverview', function () { let usersPromise: Promise<{ [key: string]: IAccount[] }>; let getAssignableUsers: SinonStub, ReturnType>; let getReviewRequests: SinonStub<[], ReturnType>; - let getPreview: SinonStub<[number], Promise>; + let getPreview: SinonStub, Promise>; let getRepository: SinonStub, ReturnType>; let getRepositoryAccess: SinonStub, ReturnType>; let getMergeQueueMethod: SinonStub; @@ -1095,6 +1096,62 @@ describe('PullRequestOverview', function () { }); + describe('branch labels', function () { + const initialized = () => messages.find(message => message.command === 'pr.initialize')?.pullrequest; + const branchLabels = () => [initialized()?.base, initialized()?.head]; + + beforeEach(function () { + sinon.stub(pullRequestManager, 'gitHubRepositories').get(() => [repo]); + repositoriesManager.insertFolderManager(pullRequestManager); + PullRequestOverviewPanel.registerGlobalCommands(context, telemetry, repositoriesManager); + }); + + function insertOtherFolder(gitHubRepositories: GitHubRepository[]): void { + const otherRepository = new MockRepository(); + otherRepository.rootUri = vscode.Uri.file('/other'); + const otherManager = new FolderRepositoryManager(1, context, otherRepository, telemetry, new GitApiImpl(repositoriesManager), credentialStore, new CreatePullRequestHelper(), mockThemeWatcher); + context.subscriptions.push(otherManager); + sinon.stub(otherManager, 'gitHubRepositories').get(() => gitHubRepositories); + repositoriesManager.insertFolderManager(otherManager); + } + + it('shows only the branch names in a single-repo workspace', async function () { + await openPanel(Promise.resolve(prModel)); + + assert.deepStrictEqual(branchLabels(), ['new-feature', 'new-feature']); + assert.strictEqual(initialized()?.qualifiedHead, 'octocat/bbb:new-feature', 'the merge commit title keeps the owner and repository'); + sinon.assert.calledWithExactly(getPreview, 1000, false); + }); + + it('shows the repository name in a multi-repo workspace', async function () { + insertOtherFolder([repo]); + + await openPanel(Promise.resolve(prModel)); + + assert.deepStrictEqual(branchLabels(), ['bbb:new-feature', 'bbb:new-feature']); + sinon.assert.calledWithExactly(getPreview, 1000, true); + }); + + it('does not count a workspace folder without a GitHub repository', async function () { + insertOtherFolder([]); + + await openPanel(); + + assert.deepStrictEqual(branchLabels(), ['new-feature', 'new-feature']); + }); + + it('shows the owners when the pull request is from a fork', async function () { + prModel.update(convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().number(1000) + .head(h => h.ref('feature').repo((r: RepositoryBuilder) => r.owner(o => o.login('contributor')))) + .build(), repo)); + + await openPanel(); + + assert.deepStrictEqual(branchLabels(), ['octocat:new-feature', 'contributor:feature']); + assert.strictEqual(initialized()?.qualifiedHead, 'contributor/bbb:feature'); + }); + }); + it('loads the stack while the rest of the page loads, and shows it after the page', async function () { const getStack = sinon.stub(prModel, 'getStack').resolves(undefined); let releaseAccess!: () => void; @@ -1549,7 +1606,7 @@ describe('PullRequestOverview', function () { branch: 'new-feature', createdForPullRequest: false, }); - const showWarningMessage = sinon.stub(vscode.window, 'showWarningMessage').resolves(undefined); + const showQuickPick = sinon.stub(vscode.window, 'showQuickPick').resolves(undefined); const replyMessage = sinon.stub(panel as any, '_replyMessage'); await (panel as any).mergePullRequest({ @@ -1557,12 +1614,11 @@ describe('PullRequestOverview', function () { args: { title: '', description: '', method: 'squash' }, }); - assert.strictEqual(showWarningMessage.calledOnce, true); - assert.strictEqual((showWarningMessage.firstCall.args[1] as vscode.MessageOptions).modal, true); - const actions = showWarningMessage.firstCall.args.slice(2) as vscode.MessageItem[]; - assert.deepStrictEqual(actions.map(action => action.title), ['Delete Local Branch']); + assert.strictEqual(showQuickPick.calledOnce, true); + const actions = showQuickPick.firstCall.args[0] as readonly (vscode.QuickPickItem & { type: string })[]; + assert.deepStrictEqual(actions.map(action => action.type), ['local']); assert.strictEqual(replyMessage.firstCall.args[1].state, GithubItemStateEnum.Merged); - sinon.assert.callOrder(replyMessage, showWarningMessage); + sinon.assert.callOrder(replyMessage, showQuickPick); }); }); @@ -1677,12 +1733,12 @@ describe('PullRequestOverview', function () { sinon.stub(model, 'getReviewRequests').resolves([]); const timeline = sinon.stub(model, 'getTimelineEvents').resolves([]); sinon.stub(model, 'validateDraftMode').resolves(false); - sinon.stub(model, 'getStatusChecks').resolves([{ state: CheckState.Success, statuses: [] }, null]); + const statusChecks = sinon.stub(model, 'getStatusChecks').resolves([{ state: CheckState.Success, statuses: [] }, null]); sinon.stub(model, 'getMergeability').resolves({ mergeability: PullRequestMergeability.Mergeable }); sinon.stub(model, 'getCoAuthors').resolves([]); sinon.stub(model, 'getLastUpdateTime').resolves(new Date(0)); const stack = sinon.stub(model, 'getStack').resolves(undefined); - return { stack, timeline }; + return { stack, timeline, statusChecks }; } async function createPanel(number = 1000, branches?: { base: string; head: string }) { @@ -3276,6 +3332,57 @@ describe('PullRequestOverview', function () { }); }); + describe('approveWorkflowRuns', function () { + let panel: TestPullRequestOverviewPanel; + let services: ReturnType; + let statusChecks: SinonStub<[], Promise<[PullRequestChecks | null, PullRequestReviewRequirement | null]>>; + const refreshed: PullRequestChecks = { state: CheckState.Pending, statuses: [] }; + + function approval(runId: number) { + return [{ owner: remote.owner, repo: remote.repositoryName, run_id: runId }]; + } + + beforeEach(function () { + const model = new PullRequestModel(credentialStore, telemetry, repo, remote, + convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().number(1000).build(), repo)); + services = panelServices ??= stubPanelServices(); + services.models.set(model.number, model); + statusChecks = stubModelServices(model).statusChecks; + panel = new TestPullRequestOverviewPanel(telemetry, pullRequestManager); + panel.setItem(model); + context.subscriptions.push(panel); + }); + + it('approves every workflow run and replies with the refreshed checks', async function () { + const approve = sinon.spy(repo, 'approveWorkflowRun'); + repo.queryProvider.expectOctokitRequest(['actions', 'approveWorkflowRun'], approval(11), {}, 201); + repo.queryProvider.expectOctokitRequest(['actions', 'approveWorkflowRun'], approval(12), {}, 201); + statusChecks.resolves([refreshed, null]); + const reply = sinon.stub(panel, '_replyMessage').resolves(); + const message = { req: 'approve', command: 'pr.approve-workflow-runs', args: { workflowRunIds: [11, 12] } }; + + await panel._onDidReceiveMessage(message); + + assert.deepStrictEqual(approve.args, [[11], [12]]); + sinon.assert.notCalled(services.showError); + assert(reply.calledOnceWithExactly(message, { status: refreshed, reviewRequirement: null })); + }); + + it('reports a workflow run that could not be approved and still refreshes the checks', async function () { + repo.queryProvider.expectOctokitRequest(['actions', 'approveWorkflowRun'], approval(11), {}, 201); + repo.queryProvider.expectOctokitError(['actions', 'approveWorkflowRun'], approval(12), new Error('Must have write access')); + statusChecks.resolves([refreshed, null]); + const reply = sinon.stub(panel, '_replyMessage').resolves(); + const message = { req: 'approve', command: 'pr.approve-workflow-runs', args: { workflowRunIds: [11, 12] } }; + + await panel._onDidReceiveMessage(message); + + sinon.assert.calledOnce(services.showError); + assert.match(services.showError.firstCall.args[0], /Must have write access/); + assert(reply.calledOnceWithExactly(message, { status: refreshed, reviewRequirement: null })); + }); + }); + describe('viewChanges', function () { it('opens the changes with the overview tab title', async function () { const { panel, model } = await createPanel(); From 31c9f45196e82fd6344717d5e0aec3e327cf4c32 Mon Sep 17 00:00:00 2001 From: John Wooten Date: Tue, 17 Nov 2026 13:19:53 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=A7=20Update=20pull=20request=20co?= =?UTF-8?q?de=20and=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Codex --- src/github/pullRequestOverview.ts | 14 +--- src/test/github/pullRequestOverview.test.ts | 83 ++++++++++----------- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/src/github/pullRequestOverview.ts b/src/github/pullRequestOverview.ts index 28ab5dc5ef..e424178d72 100644 --- a/src/github/pullRequestOverview.ts +++ b/src/github/pullRequestOverview.ts @@ -569,19 +569,13 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel void; - const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest') - .returns(new Promise(resolve => resolveDescription = resolve)); + let resolveDescription!: (description: PullRequestPreview) => void; + const getDescription = getPreview.returns(new Promise(resolve => resolveDescription = resolve)); const opening = openPanel(); await new Promise(resolve => setImmediate(resolve)); assert.strictEqual(messages.some(message => message.command === 'pr.initialize'), false); - sinon.assert.calledOnce(resolveModel); - sinon.assert.calledWithExactly(resolveModel, remote.owner, remote.repositoryName, prModel.number, false, 'overview'); - prModel.bodyHTML = '

Please merge thx

'; - resolveDescription(prModel); + sinon.assert.calledOnce(getDescription); + sinon.assert.calledWithExactly(getDescription, prModel.number); + resolveDescription({ ...preview, body: prModel.body, bodyHTML: '

Please merge thx

' }); await opening; assert.strictEqual(messages.find(message => message.command === 'pr.initialize')?.pullrequest?.bodyHTML, prModel.bodyHTML); }); @@ -1013,82 +1015,72 @@ describe('PullRequestOverview', function () { it('initializes with description HTML parsed from a GitHub GraphQL response', async function () { prModel.bodyHTML = undefined; - repo.addGraphQLPullRequest(builder => { - builder.pullRequest(response => { - response.repository(repository => { - repository.pullRequest(pullRequest => pullRequest.number(prModel.number) - .body('Actual GitHub Markdown').bodyHTML('

Actual GitHub Markdown

')); - }); - }); + getPreview.restore(); + const query = sinon.stub(repo, 'query').resolves({ + loading: false, stale: false, networkStatus: NetworkStatus.ready, + data: { repository: { pullRequest: { + ...preview, body: 'Actual GitHub Markdown', bodyHTML: '

Actual GitHub Markdown

', + author: null, baseRefName: 'main', headRefName: 'feature', + baseRepository: { owner: { login: remote.owner } }, headRepository: null, + } } }, }); - const fetchedModel = await repo.getPullRequest(prModel.number, 'description hydration regression', false, false, 'overview'); - assert(fetchedModel); - assert.strictEqual(fetchedModel.bodyHTML, '

Actual GitHub Markdown

'); - sinon.stub(fetchedModel, 'canEdit').resolves(true); - sinon.stub(fetchedModel, 'getReviewRequests').resolves([]); - sinon.stub(fetchedModel, 'getTimelineEvents').resolves([]); - sinon.stub(fetchedModel, 'validateDraftMode').resolves(false); - sinon.stub(fetchedModel, 'getStatusChecks').resolves([{ state: CheckState.Success, statuses: [] }, null]); - sinon.stub(fetchedModel, 'getMergeability').resolves({ mergeability: PullRequestMergeability.Mergeable }); - const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest').resolves(fetchedModel); await openPanel(); - sinon.assert.calledOnce(resolveModel); + sinon.assert.calledWithMatch(query, { query: repo.schema.PullRequestPreview }); assert.strictEqual(messages.find(message => message.command === 'pr.initialize')?.pullrequest?.bodyHTML, '

Actual GitHub Markdown

'); }); it('ignores description lookups that finish after the overview closes', async function () { prModel.bodyHTML = undefined; - let resolveDescription!: (model: PullRequestModel) => void; - sinon.stub(pullRequestManager, 'resolvePullRequest') - .returns(new Promise(resolve => resolveDescription = resolve)); + let resolveDescription!: (description: PullRequestPreview) => void; + getPreview.returns(new Promise(resolve => resolveDescription = resolve)); const opening = openPanel(); await new Promise(resolve => setImmediate(resolve)); webviewPanel.dispose(); - prModel.bodyHTML = '

Late description

'; - resolveDescription(prModel); + resolveDescription({ ...preview, bodyHTML: '

Late description

' }); await opening; assert.strictEqual(messages.some(message => message.command === 'pr.initialize'), false); }); it('does not overwrite a newer overview when an older description lookup finishes', async function () { prModel.bodyHTML = undefined; - let resolveDescription!: (model: PullRequestModel) => void; - const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest') - .returns(new Promise(resolve => resolveDescription = resolve)); + let resolveDescription!: (description: PullRequestPreview) => void; + const getDescription = getPreview.returns(new Promise(resolve => resolveDescription = resolve)); const firstOpening = openPanel(); await new Promise(resolve => setImmediate(resolve)); - sinon.assert.calledOnce(resolveModel); - const staleModel = new PullRequestModel(credentialStore, telemetry, repo, remote, prModel.item); - staleModel.bodyHTML = '

Old description

'; - prModel.bodyHTML = '

New description

'; - const secondOpening = openPanel(); - resolveDescription(staleModel); + sinon.assert.calledOnce(getDescription); + const cachedModel = repo.createOrUpdatePullRequestModel(prModel.item); + assert.strictEqual(cachedModel, prModel); + cachedModel.update({ ...cachedModel.item, body: 'New description', bodyHTML: '

New description

' }); + const secondOpening = openPanel(cachedModel); + resolveDescription({ ...preview, body: 'Old description', bodyHTML: '

Old description

' }); await Promise.all([firstOpening, secondOpening]); const initializations = messages.filter(message => message.command === 'pr.initialize'); + assert.strictEqual(cachedModel.body, 'New description'); + assert.strictEqual(cachedModel.bodyHTML, '

New description

'); assert.strictEqual(initializations.length, 1); assert.strictEqual(initializations[0].pullrequest?.bodyHTML, '

New description

'); }); it('does not resolve a description that already has HTML', async function () { - const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest'); + const getDescription = getPreview; await openPanel(); - sinon.assert.notCalled(resolveModel); + sinon.assert.notCalled(getDescription); assert.strictEqual(messages.find(message => message.command === 'pr.initialize')?.pullrequest?.bodyHTML, prModel.bodyHTML); }); it('does not resolve an empty description', async function () { prModel.body = ''; prModel.bodyHTML = undefined; - const resolveModel = sinon.stub(pullRequestManager, 'resolvePullRequest'); + const getDescription = getPreview; await openPanel(); - sinon.assert.notCalled(resolveModel); + sinon.assert.notCalled(getDescription); assert.ok(messages.some(message => message.command === 'pr.initialize')); }); it('reports a description lookup failure instead of initializing a blank body', async function () { prModel.bodyHTML = undefined; - sinon.stub(pullRequestManager, 'resolvePullRequest').rejects(new Error('Description lookup failed')); + getPreview.rejects(new Error('Description lookup failed')); const showError = sinon.stub(vscode.window, 'showErrorMessage').resolves(undefined); await openPanel(); assert.strictEqual(showError.firstCall.args[0], 'Error updating pull request description: Description lookup failed'); @@ -1729,6 +1721,7 @@ describe('PullRequestOverview', function () { } function stubModelServices(model: PullRequestModel) { + model.bodyHTML ??= '

Please merge thx

'; sinon.stub(model, 'canEdit').resolves(true); sinon.stub(model, 'getReviewRequests').resolves([]); const timeline = sinon.stub(model, 'getTimelineEvents').resolves([]);