@@ -17,6 +17,7 @@ import { PROVIDER_REGISTRY, type ProviderModelDiscoverySpec } from "../src/provi
1717import { routeModel } from "../src/router" ;
1818import type { OcxConfig , OcxProviderConfig } from "../src/types" ;
1919import { withStubbedProviderFetch } from "./helpers/catalog-provider-fetch" ;
20+ import { withRegistryDiscovery } from "./helpers/provider-registry-discovery" ;
2021
2122const FIXTURE = readFileSync ( join ( import . meta. dir , "fixtures/provider-model-discovery.json" ) , "utf8" ) ;
2223const originalFetch = globalThis . fetch ;
@@ -36,37 +37,7 @@ async function withTogetherDiscovery<T>(
3637 spec : ProviderModelDiscoverySpec ,
3738 run : ( ) => Promise < T > | T ,
3839) : Promise < T > {
39- const entry = togetherEntry ( ) ;
40- const original = entry . modelDiscovery ;
41- const originalPreserveCustomDestination = entry . preserveCustomDestination ;
42- entry . modelDiscovery = spec ;
43- entry . preserveCustomDestination = true ;
44- try {
45- return await run ( ) ;
46- } finally {
47- if ( original === undefined ) delete entry . modelDiscovery ;
48- else entry . modelDiscovery = original ;
49- if ( originalPreserveCustomDestination === undefined ) delete entry . preserveCustomDestination ;
50- else entry . preserveCustomDestination = originalPreserveCustomDestination ;
51- clearModelCache ( "together" ) ;
52- }
53- }
54-
55- async function withRegistryDiscovery < T > (
56- providerId : string ,
57- spec : ProviderModelDiscoverySpec ,
58- run : ( ) => Promise < T > | T ,
59- ) : Promise < T > {
60- const entry = PROVIDER_REGISTRY . find ( row => row . id === providerId ) ;
61- if ( ! entry ) throw new Error ( `missing ${ providerId } registry entry` ) ;
62- const original = entry . modelDiscovery ;
63- entry . modelDiscovery = spec ;
64- try {
65- return await run ( ) ;
66- } finally {
67- if ( original === undefined ) delete entry . modelDiscovery ;
68- else entry . modelDiscovery = original ;
69- }
40+ return withRegistryDiscovery ( "together" , spec , run , { preserveCustomDestination : true } ) ;
7041}
7142
7243function togetherConfig ( overrides : Partial < OcxProviderConfig > = { } ) : OcxConfig {
@@ -96,6 +67,11 @@ describe("registry-owned provider model discovery", () => {
9667 . toContain ( "https" ) ;
9768 expect ( providerModelDiscoverySpecError ( { path : "models?unbounded=true" } ) )
9869 . toContain ( "query-free" ) ;
70+ expect ( providerModelDiscoverySpecError ( { path : "../../internal/models" } ) )
71+ . toContain ( "parent-directory" ) ;
72+ expect ( providerModelDiscoverySpecError ( { path : "models/../internal" } ) )
73+ . toContain ( "parent-directory" ) ;
74+ expect ( providerModelDiscoverySpecError ( { path : "models/model..variant" } ) ) . toBeNull ( ) ;
9975 expect ( providerModelDiscoverySpecError ( {
10076 url : "https://api.example.test/models" ,
10177 path : "models" ,
0 commit comments