diff --git a/src/main/gitlab/gl-utils.test.ts b/src/main/gitlab/gl-utils.test.ts index 8697567f442..d48c28d2540 100644 --- a/src/main/gitlab/gl-utils.test.ts +++ b/src/main/gitlab/gl-utils.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-lines -- Why: GitLab remote parsing coverage needs many URL/host fixtures against the same mocked git/glab helpers. */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const { gitExecFileAsyncMock, glabExecFileAsyncMock, sshExecMock } = vi.hoisted(() => ({ @@ -22,96 +21,12 @@ import { getGlabKnownHosts, getProjectRef, getProjectRefForRemote, - parseGitLabProjectRef, parseGlabApiResponse, parseGlabAuthStatusHosts, resolveIssueSource } from './gl-utils' import { registerSshGitProvider, unregisterSshGitProvider } from '../providers/ssh-git-dispatch' -describe('gitlab project ref parsing', () => { - it('parses HTTPS and SSH GitLab.com remotes', () => { - expect(parseGitLabProjectRef('https://gitlab.com/acme/widgets.git')).toEqual({ - host: 'gitlab.com', - path: 'acme/widgets' - }) - expect(parseGitLabProjectRef('git@gitlab.com:stablyai/orca.git')).toEqual({ - host: 'gitlab.com', - path: 'stablyai/orca' - }) - }) - - it('preserves nested group paths', () => { - expect(parseGitLabProjectRef('git@gitlab.com:group/subgroup/project.git')).toEqual({ - host: 'gitlab.com', - path: 'group/subgroup/project' - }) - expect(parseGitLabProjectRef('https://gitlab.com/g1/g2/g3/proj.git')).toEqual({ - host: 'gitlab.com', - path: 'g1/g2/g3/proj' - }) - }) - - it('returns null for non-GitLab hosts when host not in knownHosts', () => { - expect(parseGitLabProjectRef('git@github.com:stablyai/orca.git')).toBeNull() - expect(parseGitLabProjectRef('git@example.com:foo/bar.git')).toBeNull() - }) - - it('matches self-hosted hosts when included in knownHosts', () => { - expect( - parseGitLabProjectRef('git@gitlab.example.com:team/api.git', [ - 'gitlab.com', - 'gitlab.example.com' - ]) - ).toEqual({ host: 'gitlab.example.com', path: 'team/api' }) - }) - - it('parses GitLab remotes with non-standard ports without treating the port as a path segment', () => { - expect( - parseGitLabProjectRef('ssh://git@gitlab.example.com:2222/team/api.git', [ - 'gitlab.com', - 'gitlab.example.com' - ]) - ).toEqual({ host: 'gitlab.example.com', path: 'team/api' }) - expect( - parseGitLabProjectRef('https://gitlab.example.com:8443/team/api.git', [ - 'gitlab.com', - 'gitlab.example.com' - ]) - ).toEqual({ host: 'gitlab.example.com', path: 'team/api' }) - }) - - it('rejects single-segment paths (host root or user-only)', () => { - expect(parseGitLabProjectRef('git@gitlab.com:foo.git')).toBeNull() - expect(parseGitLabProjectRef('https://gitlab.com/foo.git')).toBeNull() - }) - - it('handles missing .git suffix', () => { - expect(parseGitLabProjectRef('https://gitlab.com/acme/widgets')).toEqual({ - host: 'gitlab.com', - path: 'acme/widgets' - }) - }) - - it('strips trailing slashes after .git suffixes', () => { - expect(parseGitLabProjectRef('https://gitlab.com/acme/widgets.git/')).toEqual({ - host: 'gitlab.com', - path: 'acme/widgets' - }) - expect(parseGitLabProjectRef('ssh://git@gitlab.com/acme/widgets.git/')).toEqual({ - host: 'gitlab.com', - path: 'acme/widgets' - }) - }) - - it('preserves git protocol remote support', () => { - expect(parseGitLabProjectRef('git://gitlab.com/acme/widgets.git')).toEqual({ - host: 'gitlab.com', - path: 'acme/widgets' - }) - }) -}) - describe('gitlab project ref resolution', () => { beforeEach(() => { gitExecFileAsyncMock.mockReset() diff --git a/src/main/gitlab/project-ref-parser.test.ts b/src/main/gitlab/project-ref-parser.test.ts new file mode 100644 index 00000000000..53adc0c5aa5 --- /dev/null +++ b/src/main/gitlab/project-ref-parser.test.ts @@ -0,0 +1,99 @@ +import { describe, expect, it } from 'vitest' +import { parseGitLabProjectRef, parseRemoteProjectRefCandidate } from './project-ref-parser' + +describe('gitlab project ref parsing', () => { + it('parses HTTPS and SSH GitLab.com remotes', () => { + expect(parseGitLabProjectRef('https://gitlab.com/acme/widgets.git')).toEqual({ + host: 'gitlab.com', + path: 'acme/widgets' + }) + expect(parseGitLabProjectRef('git@gitlab.com:stablyai/orca.git')).toEqual({ + host: 'gitlab.com', + path: 'stablyai/orca' + }) + }) + + it('preserves nested group paths', () => { + expect(parseGitLabProjectRef('git@gitlab.com:group/subgroup/project.git')).toEqual({ + host: 'gitlab.com', + path: 'group/subgroup/project' + }) + expect(parseGitLabProjectRef('https://gitlab.com/g1/g2/g3/proj.git')).toEqual({ + host: 'gitlab.com', + path: 'g1/g2/g3/proj' + }) + }) + + it('returns null for non-GitLab hosts when host not in knownHosts', () => { + expect(parseGitLabProjectRef('git@github.com:stablyai/orca.git')).toBeNull() + expect(parseGitLabProjectRef('git@example.com:foo/bar.git')).toBeNull() + }) + + it('matches self-hosted hosts when included in knownHosts', () => { + expect( + parseGitLabProjectRef('git@gitlab.example.com:team/api.git', [ + 'gitlab.com', + 'gitlab.example.com' + ]) + ).toEqual({ host: 'gitlab.example.com', path: 'team/api' }) + }) + + it('parses GitLab remotes with non-standard ports without treating the port as a path segment', () => { + expect( + parseGitLabProjectRef('ssh://git@gitlab.example.com:2222/team/api.git', [ + 'gitlab.com', + 'gitlab.example.com' + ]) + ).toEqual({ host: 'gitlab.example.com', path: 'team/api' }) + expect( + parseGitLabProjectRef('https://gitlab.example.com:8443/team/api.git', [ + 'gitlab.com', + 'gitlab.example.com' + ]) + ).toEqual({ host: 'gitlab.example.com', path: 'team/api' }) + }) + + it('rejects single-segment paths (host root or user-only)', () => { + expect(parseGitLabProjectRef('git@gitlab.com:foo.git')).toBeNull() + expect(parseGitLabProjectRef('https://gitlab.com/foo.git')).toBeNull() + }) + + it('handles missing .git suffix', () => { + expect(parseGitLabProjectRef('https://gitlab.com/acme/widgets')).toEqual({ + host: 'gitlab.com', + path: 'acme/widgets' + }) + }) + + it('strips trailing slashes after .git suffixes', () => { + expect(parseGitLabProjectRef('https://gitlab.com/acme/widgets.git/')).toEqual({ + host: 'gitlab.com', + path: 'acme/widgets' + }) + expect(parseGitLabProjectRef('ssh://git@gitlab.com/acme/widgets.git/')).toEqual({ + host: 'gitlab.com', + path: 'acme/widgets' + }) + }) + + it('preserves git protocol remote support', () => { + expect(parseGitLabProjectRef('git://gitlab.com/acme/widgets.git')).toEqual({ + host: 'gitlab.com', + path: 'acme/widgets' + }) + }) +}) + +describe('gitlab remote project ref candidates', () => { + it('extracts self-hosted candidates before the host is trusted', () => { + expect(parseRemoteProjectRefCandidate('git@gitlab.internal:team/orca.git')).toEqual({ + host: 'gitlab.internal', + path: 'team/orca' + }) + }) + + it('rejects non-git URLs and single-segment project paths', () => { + expect(parseRemoteProjectRefCandidate('file:///tmp/repo')).toBeNull() + expect(parseRemoteProjectRefCandidate('git@gitlab.internal:team.git')).toBeNull() + }) +}) diff --git a/src/renderer/src/components/stats/UsageSessionsTable.tsx b/src/renderer/src/components/stats/UsageSessionsTable.tsx index f84e49f46dc..242350c67b9 100644 --- a/src/renderer/src/components/stats/UsageSessionsTable.tsx +++ b/src/renderer/src/components/stats/UsageSessionsTable.tsx @@ -69,7 +69,7 @@ export function UsageSessionsTable({ {translate('auto.components.stats.UsageSessionsTable.c17bed0416', 'Project')}