From 1f03b83db19c8e4e97a9e5be42c0b98e03fd6fc2 Mon Sep 17 00:00:00 2001 From: bot-hermes Date: Tue, 18 Aug 2026 20:47:36 +0000 Subject: [PATCH] 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 --- .../web/server/lib/walkthrough/pull-request.js | 4 ++-- .../lib/walkthrough/pull-request.test.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/web/server/lib/walkthrough/pull-request.js b/packages/web/server/lib/walkthrough/pull-request.js index d64b990b..8731b88a 100644 --- a/packages/web/server/lib/walkthrough/pull-request.js +++ b/packages/web/server/lib/walkthrough/pull-request.js @@ -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); } diff --git a/packages/web/server/lib/walkthrough/pull-request.test.js b/packages/web/server/lib/walkthrough/pull-request.test.js index b2cdabcd..ab80f07e 100644 --- a/packages/web/server/lib/walkthrough/pull-request.test.js +++ b/packages/web/server/lib/walkthrough/pull-request.test.js @@ -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({