Files
orca/src/shared/imported-folder-project-identity.test.ts
T
Neil a201eacd06 fix(projects): link a cloned or imported folder into a GitLab or generic-remote project (#30785)
Setting a project up on another host (a cloned or imported folder)
only knew how to link the folder through a GitHub identity. A project
keyed by its Git remote (GitLab, Bitbucket, a self-hosted host) was
always refused with "Imported folder does not match the selected
project identity". A fresh clone's remote is not probed when it is
registered, so it never projected into that project by itself.

The link now probes an unprobed folder's remote. If the canonical key
of that remote is the project's, the remote is recorded on the repo, so
the folder projects into the project. SSH and HTTPS forms share a key.
A GitHub project is still linked by stamping upstream, and a remote
that names another repository is still refused.
2026-10-19 14:43:33 -07:00

85 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { deriveGitRemoteIdentity } from './git-remote-identity'
import { resolveImportedFolderProjectLink } from './imported-folder-project-identity'
import { getProjectIdentityKey } from './project-host-setup-projection'
function folder(remoteUrl: string | null) {
return {
gitRemoteIdentity: remoteUrl
? deriveGitRemoteIdentity(`origin\t${remoteUrl} (fetch)\norigin\t${remoteUrl} (push)\n`)
: null
}
}
/** The project a source host derives for a repo with this remote. */
function projectIdFor(remoteUrl: string): string {
return getProjectIdentityKey({ id: 'source-repo', ...folder(remoteUrl) })
}
describe('resolveImportedFolderProjectLink', () => {
it('stamps a GitHub project as upstream', () => {
expect(
resolveImportedFolderProjectLink(folder(null), 'github:acme/orca', {
provider: 'github',
owner: 'acme',
repo: 'orca'
})
).toEqual({ upstream: { owner: 'acme', repo: 'orca' } })
})
it.each([
['GitLab over HTTPS', 'https://gitlab.com/group/sub/app.git'],
['GitLab over SSH', 'git@gitlab.com:group/sub/app.git'],
['a self-hosted host over ssh://', 'ssh://git@git.example.test:2222/team/app.git'],
['a generic HTTPS host', 'https://git.example.test/team/app']
])('links %s through the folder remote', (_label, remoteUrl) => {
const link = resolveImportedFolderProjectLink(
folder(remoteUrl),
projectIdFor(remoteUrl),
undefined
)
expect(link).toEqual({ gitRemoteIdentity: folder(remoteUrl).gitRemoteIdentity })
})
it('treats the SSH and HTTPS forms of one repository as the same project', () => {
const projectId = projectIdFor('https://gitlab.com/group/app.git')
expect(
resolveImportedFolderProjectLink(folder('git@gitlab.com:group/app.git'), projectId, undefined)
).toHaveProperty('gitRemoteIdentity')
})
it('refuses a folder whose remote names another repository', () => {
expect(() =>
resolveImportedFolderProjectLink(
folder('https://gitlab.com/group/other.git'),
projectIdFor('https://gitlab.com/group/app.git'),
undefined
)
).toThrow('Imported folder does not match the selected project identity.')
})
it('refuses a folder with no remote for a Git-remote project', () => {
expect(() =>
resolveImportedFolderProjectLink(
folder(null),
projectIdFor('https://gitlab.com/group/app.git'),
undefined
)
).toThrow('Imported folder does not match the selected project identity.')
})
it('still refuses a GitHub remote that names another repository', () => {
expect(() =>
resolveImportedFolderProjectLink(
folder('https://github.com/acme/other.git'),
'github:acme/orca',
{
provider: 'github',
owner: 'acme',
repo: 'orca'
}
)
).toThrow('its Git remote "origin" points at acme/other')
})
})