fix(walkthrough): thread directory into GitLab diff client and fix tests

- Add directory parameter to getGitLabMergeRequestDiff for per-project
  API base URL override resolution
- Mock getGitLabAuth/getEffectiveProviderApiBaseUrl in walkthrough tests
- Update auth-check test to mock null auth instead of null client
This commit is contained in:
2026-08-18 20:47:36 +00:00
parent 4ce02ee569
commit 1f03b83db1
2 changed files with 18 additions and 4 deletions
@@ -62,7 +62,7 @@ async function getGitHubPullRequestDiff(directory, number) {
* dispatcher's `resolveGitLabRepoFromDirectory` call and is never re-resolved
* here.
*/
async function getGitLabMergeRequestDiff(repo, number) {
async function getGitLabMergeRequestDiff(directory, repo, number) {
// Resolve per-project API base override, mirroring getClient() in routes.js.
const auth = getGitLabAuth();
if (!auth?.accessToken) {
@@ -132,7 +132,7 @@ async function getGitLabMergeRequestDiff(repo, number) {
export async function getPullRequestDiff(directory, number) {
const { repo } = await resolveGitLabRepoFromDirectory(directory);
if (repo) {
return getGitLabMergeRequestDiff(repo, number);
return getGitLabMergeRequestDiff(directory, repo, number);
}
return getGitHubPullRequestDiff(directory, number);
}
@@ -2,13 +2,25 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('../github/octokit.js', () => ({ getOctokitOrNull: vi.fn() }));
vi.mock('../github/repo/index.js', () => ({ resolveGitHubRepoFromDirectory: vi.fn() }));
vi.mock('../gitlab/client.js', () => ({ getGitLabClientOrNull: vi.fn() }));
vi.mock('../gitlab/client.js', () => ({
getGitLabClientOrNull: vi.fn(),
createGitLabClient: vi.fn(),
}));
vi.mock('../gitlab/auth.js', () => ({
getGitLabAuth: vi.fn(),
getGitLabDefaultBaseUrl: vi.fn(() => 'https://gitlab.com'),
}));
vi.mock('../git-providers/project-config.js', () => ({
getEffectiveProviderApiBaseUrl: vi.fn(() => null),
}));
vi.mock('../gitlab/repo.js', () => ({ resolveGitLabRepoFromDirectory: vi.fn() }));
const { getPullRequestDiff } = await import('./pull-request.js');
const { getOctokitOrNull } = await import('../github/octokit.js');
const { resolveGitHubRepoFromDirectory } = await import('../github/repo/index.js');
const { getGitLabClientOrNull } = await import('../gitlab/client.js');
const { getGitLabClientOrNull, createGitLabClient } = await import('../gitlab/client.js');
const { getGitLabAuth } = await import('../gitlab/auth.js');
const { getEffectiveProviderApiBaseUrl } = await import('../git-providers/project-config.js');
const { resolveGitLabRepoFromDirectory } = await import('../gitlab/repo.js');
const PATCH = `diff --git a/src/a.ts b/src/a.ts
@@ -57,6 +69,7 @@ describe('getPullRequestDiff', () => {
// the GitHub path.
resolveGitLabRepoFromDirectory.mockResolvedValue({ repo: null, remoteUrl: null });
getGitLabClientOrNull.mockReturnValue(null);
getGitLabAuth.mockReturnValue({ accessToken: 'test-token' });
});
afterEach(() => {
@@ -146,6 +159,7 @@ describe('getPullRequestDiff', () => {
});
it('asks the user to connect GitLab before fetching diffs', async () => {
getGitLabAuth.mockReturnValue(null);
getGitLabClientOrNull.mockReturnValue(null);
await expect(getPullRequestDiff('/repo', 7)).rejects.toMatchObject({