Skip to content

Commit aaeed30

Browse files
howwohmmclaude
andcommitted
test(useRepositoryUrl): add regression tests for monorepo .git URL handling
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 50491e6 commit aaeed30

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
/**
4+
* Tests for useRepositoryUrl composable.
5+
*
6+
* Regression tests for GitHub issue #2233: monorepo packages with .git suffix
7+
* in repository.url generated broken source links like:
8+
* https://github.com/org/repo.git/tree/HEAD/packages/foo (404)
9+
* instead of:
10+
* https://github.com/org/repo/tree/HEAD/packages/foo
11+
*/
12+
describe('useRepositoryUrl', () => {
13+
it('should strip .git from repository URL', () => {
14+
const { repositoryUrl } = useRepositoryUrl(ref({
15+
repository: {
16+
type: 'git',
17+
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
18+
},
19+
}))
20+
21+
expect(repositoryUrl.value).toBe('https://github.com/agentmarkup/agentmarkup')
22+
})
23+
24+
it('should append /tree/HEAD/{directory} for monorepo packages without .git', () => {
25+
const { repositoryUrl } = useRepositoryUrl(ref({
26+
repository: {
27+
type: 'git',
28+
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
29+
directory: 'packages/vite',
30+
},
31+
}))
32+
33+
expect(repositoryUrl.value).toBe(
34+
'https://github.com/agentmarkup/agentmarkup/tree/HEAD/packages/vite',
35+
)
36+
})
37+
38+
it('should return null when repository has no url', () => {
39+
const { repositoryUrl } = useRepositoryUrl(ref({
40+
repository: {},
41+
}))
42+
43+
expect(repositoryUrl.value).toBeNull()
44+
})
45+
46+
it('should return null when no repository field', () => {
47+
const { repositoryUrl } = useRepositoryUrl(ref({}))
48+
49+
expect(repositoryUrl.value).toBeNull()
50+
})
51+
52+
it('should handle plain HTTPS URLs without .git suffix', () => {
53+
const { repositoryUrl } = useRepositoryUrl(ref({
54+
repository: {
55+
url: 'https://github.com/nuxt/ui',
56+
},
57+
}))
58+
59+
expect(repositoryUrl.value).toBe('https://github.com/nuxt/ui')
60+
})
61+
62+
it('should handle directory with trailing slash', () => {
63+
const { repositoryUrl } = useRepositoryUrl(ref({
64+
repository: {
65+
url: 'git+https://github.com/org/repo.git',
66+
directory: 'packages/core/',
67+
},
68+
}))
69+
70+
expect(repositoryUrl.value).toBe(
71+
'https://github.com/org/repo/tree/HEAD/packages/core/',
72+
)
73+
})
74+
})

0 commit comments

Comments
 (0)