diff --git a/src/providers/wellknown.ts b/src/providers/wellknown.ts index 191955a6..efa05db9 100644 --- a/src/providers/wellknown.ts +++ b/src/providers/wellknown.ts @@ -362,8 +362,11 @@ export class WellKnownProvider implements HostProvider { getSourceIdentifier(url: string): string { try { const parsed = new URL(url); - // Use full hostname, only strip www. prefix - return parsed.hostname.replace(/^www\./, ''); + // Preserve the scheme so experimental_install can re-use the source as a valid URL. + // Only strip www. prefix and trailing slash for cleanliness. + const host = parsed.hostname.replace(/^www\./, ''); + const pathname = parsed.pathname.replace(/\/+$/, ''); + return `${parsed.protocol}//${host}${pathname}`; } catch { return 'unknown'; } diff --git a/tests/wellknown-provider.test.ts b/tests/wellknown-provider.test.ts index 6f9efc71..26506b4a 100644 --- a/tests/wellknown-provider.test.ts +++ b/tests/wellknown-provider.test.ts @@ -36,30 +36,30 @@ describe('WellKnownProvider', () => { }); describe('getSourceIdentifier', () => { - it('should return full hostname', () => { - expect(provider.getSourceIdentifier('https://example.com')).toBe('example.com'); - expect(provider.getSourceIdentifier('https://mintlify.com')).toBe('mintlify.com'); - expect(provider.getSourceIdentifier('https://lovable.dev')).toBe('lovable.dev'); + it('should return full URL with scheme', () => { + expect(provider.getSourceIdentifier('https://example.com')).toBe('https://example.com'); + expect(provider.getSourceIdentifier('https://mintlify.com')).toBe('https://mintlify.com'); + expect(provider.getSourceIdentifier('https://lovable.dev')).toBe('https://lovable.dev'); }); - it('should return same identifier regardless of path', () => { - expect(provider.getSourceIdentifier('https://example.com/docs')).toBe('example.com'); - expect(provider.getSourceIdentifier('https://example.com/api/v1')).toBe('example.com'); + it('should preserve path in identifier', () => { + expect(provider.getSourceIdentifier('https://example.com/docs')).toBe('https://example.com/docs'); + expect(provider.getSourceIdentifier('https://example.com/api/v1')).toBe('https://example.com/api/v1'); }); it('should preserve subdomains', () => { - expect(provider.getSourceIdentifier('https://docs.example.com')).toBe('docs.example.com'); + expect(provider.getSourceIdentifier('https://docs.example.com')).toBe('https://docs.example.com'); expect(provider.getSourceIdentifier('https://api.mintlify.com/docs')).toBe( - 'api.mintlify.com' + 'https://api.mintlify.com/docs' ); expect(provider.getSourceIdentifier('https://mppx-discovery-skills.vercel.app')).toBe( - 'mppx-discovery-skills.vercel.app' + 'https://mppx-discovery-skills.vercel.app' ); }); it('should strip www. prefix', () => { - expect(provider.getSourceIdentifier('https://www.example.com')).toBe('example.com'); - expect(provider.getSourceIdentifier('https://www.mintlify.com/docs')).toBe('mintlify.com'); + expect(provider.getSourceIdentifier('https://www.example.com')).toBe('https://example.com'); + expect(provider.getSourceIdentifier('https://www.mintlify.com/docs')).toBe('https://mintlify.com/docs'); }); it('should return unknown for invalid URLs', () => {