Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/providers/wellknown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
24 changes: 12 additions & 12 deletions tests/wellknown-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down