fix(core,testing): improve type safety and update tests for latest tstest and storage APIs

This commit is contained in:
2026-04-30 09:25:26 +00:00
parent 2e2726a4de
commit 45e24ecff3
19 changed files with 1394 additions and 1414 deletions
+21 -11
View File
@@ -9,9 +9,19 @@ import type {
IUpstreamProvider,
IUpstreamResolutionContext,
IProtocolUpstreamConfig,
IUpstreamRegistryConfig,
} from '../ts/upstream/interfaces.upstream.js';
import type { TRegistryProtocol } from '../ts/core/interfaces.core.js';
const createUpstream = (id: string, url: string): IUpstreamRegistryConfig => ({
id,
name: id,
url,
priority: 1,
enabled: true,
auth: { type: 'none' },
});
// =============================================================================
// StaticUpstreamProvider Tests
// =============================================================================
@@ -19,7 +29,7 @@ import type { TRegistryProtocol } from '../ts/core/interfaces.core.js';
tap.test('StaticUpstreamProvider: should return config for configured protocol', async () => {
const npmConfig: IProtocolUpstreamConfig = {
enabled: true,
upstreams: [{ id: 'npmjs', url: 'https://registry.npmjs.org', priority: 1, enabled: true }],
upstreams: [createUpstream('npmjs', 'https://registry.npmjs.org')],
};
const provider = new StaticUpstreamProvider({
@@ -43,7 +53,7 @@ tap.test('StaticUpstreamProvider: should return null for unconfigured protocol',
const provider = new StaticUpstreamProvider({
npm: {
enabled: true,
upstreams: [{ id: 'npmjs', url: 'https://registry.npmjs.org', priority: 1, enabled: true }],
upstreams: [createUpstream('npmjs', 'https://registry.npmjs.org')],
},
});
@@ -62,15 +72,15 @@ tap.test('StaticUpstreamProvider: should support multiple protocols', async () =
const provider = new StaticUpstreamProvider({
npm: {
enabled: true,
upstreams: [{ id: 'npmjs', url: 'https://registry.npmjs.org', priority: 1, enabled: true }],
upstreams: [createUpstream('npmjs', 'https://registry.npmjs.org')],
},
oci: {
enabled: true,
upstreams: [{ id: 'dockerhub', url: 'https://registry-1.docker.io', priority: 1, enabled: true }],
upstreams: [createUpstream('dockerhub', 'https://registry-1.docker.io')],
},
maven: {
enabled: true,
upstreams: [{ id: 'central', url: 'https://repo1.maven.org/maven2', priority: 1, enabled: true }],
upstreams: [createUpstream('central', 'https://repo1.maven.org/maven2')],
},
});
@@ -113,7 +123,7 @@ tap.test('Provider Integration: should create registry with upstream provider',
trackingProvider = createTrackingUpstreamProvider({
npm: {
enabled: true,
upstreams: [{ id: 'test-npm', url: 'https://registry.npmjs.org', priority: 1, enabled: true }],
upstreams: [createUpstream('test-npm', 'https://registry.npmjs.org')],
},
});
@@ -200,13 +210,13 @@ tap.test('Custom Provider: should support dynamic resolution based on context',
// Internal packages go to private registry
return {
enabled: true,
upstreams: [{ id: 'private', url: 'https://private.registry.com', priority: 1, enabled: true }],
upstreams: [createUpstream('private', 'https://private.registry.com')],
};
}
// Everything else goes to public registry
return {
enabled: true,
upstreams: [{ id: 'public', url: 'https://registry.npmjs.org', priority: 1, enabled: true }],
upstreams: [createUpstream('public', 'https://registry.npmjs.org')],
};
},
};
@@ -237,12 +247,12 @@ tap.test('Custom Provider: should support actor-based resolution', async () => {
if (context.actor?.orgId === 'enterprise-org') {
return {
enabled: true,
upstreams: [{ id: 'enterprise', url: 'https://enterprise.registry.com', priority: 1, enabled: true }],
upstreams: [createUpstream('enterprise', 'https://enterprise.registry.com')],
};
}
return {
enabled: true,
upstreams: [{ id: 'default', url: 'https://registry.npmjs.org', priority: 1, enabled: true }],
upstreams: [createUpstream('default', 'https://registry.npmjs.org')],
};
},
};
@@ -277,7 +287,7 @@ tap.test('Custom Provider: should support disabling upstream for specific resour
}
return {
enabled: true,
upstreams: [{ id: 'public', url: 'https://registry.npmjs.org', priority: 1, enabled: true }],
upstreams: [createUpstream('public', 'https://registry.npmjs.org')],
};
},
};