mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-10 16:49:36 +01:00
e1941e0ed7
* WIP - initial refactoring * More refactoring * Extract changeset subscriptions into a separate service * Pull request feedback
62 lines
3.0 KiB
TypeScript
62 lines
3.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import assert from 'assert';
|
|
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
|
|
import { InstantiationService } from '../../../instantiation/common/instantiationService.js';
|
|
import { NullLogService } from '../../../log/common/log.js';
|
|
import { AgentHostStateManager } from '../../node/agentHostStateManager.js';
|
|
import { AgentHostPullRequestOperationContribution } from '../../node/agentHostPullRequestOperationProvider.js';
|
|
import type { ISessionGitState } from '../../common/state/sessionState.js';
|
|
import { ChangesetKind } from '../../common/changesetUri.js';
|
|
|
|
const githubBranchWithUncommittedChanges: ISessionGitState = {
|
|
hasGitHubRemote: true,
|
|
branchName: 'feature/test',
|
|
uncommittedChanges: 1,
|
|
outgoingChanges: 0,
|
|
};
|
|
|
|
suite('AgentHostPullRequestOperationContribution', () => {
|
|
const disposables = ensureNoDisposablesAreLeakedInTestSuite();
|
|
|
|
function createContribution(): AgentHostPullRequestOperationContribution {
|
|
return disposables.add(new AgentHostPullRequestOperationContribution(
|
|
disposables.add(new AgentHostStateManager(new NullLogService())),
|
|
disposables.add(new InstantiationService()),
|
|
));
|
|
}
|
|
|
|
test('advertises PR operations for GitHub branches with uncommitted changes', () => {
|
|
const provider = createContribution();
|
|
|
|
const operations = provider.getOperations({ sessionKey: 'agent:/session', gitState: githubBranchWithUncommittedChanges, changesetKind: ChangesetKind.Session, changesetUri: '' });
|
|
|
|
assert.deepStrictEqual(operations?.map(op => op.id), ['create-pr', 'create-draft-pr']);
|
|
});
|
|
|
|
test('does not advertise PR operations without GitHub branch changes', () => {
|
|
const provider = createContribution();
|
|
|
|
const actual = [
|
|
provider.getOperations({ sessionKey: 'agent:/session', gitState: { ...githubBranchWithUncommittedChanges, hasGitHubRemote: false }, changesetKind: ChangesetKind.Session, changesetUri: '' }),
|
|
provider.getOperations({ sessionKey: 'agent:/session', gitState: { ...githubBranchWithUncommittedChanges, uncommittedChanges: 0, outgoingChanges: 0 }, changesetKind: ChangesetKind.Session, changesetUri: '' }),
|
|
];
|
|
|
|
assert.deepStrictEqual(actual, [undefined, undefined]);
|
|
});
|
|
|
|
test('hides PR operations immediately after handler reports PR creation', () => {
|
|
const provider = createContribution();
|
|
|
|
provider.onPullRequestCreated({ sessionKey: 'agent:/session', branchName: 'feature/test' });
|
|
const operations = provider.getOperations({ sessionKey: 'agent:/session', gitState: githubBranchWithUncommittedChanges, changesetKind: ChangesetKind.Session, changesetUri: '' });
|
|
|
|
assert.deepStrictEqual({ operations }, {
|
|
operations: undefined,
|
|
});
|
|
});
|
|
});
|