@@ -52,44 +52,65 @@ export const BENCHMARK_CASES: Array<{
5252
5353/**
5454 * Create case definitions for benchmark graphs.
55+ * Pre-loads benchmark data to determine seed nodes.
5556 */
56- const createBenchmarkCaseDefinitions = ( ) : CaseDefinition < BenchmarkGraphExpander > [ ] => BENCHMARK_CASES . map ( ( benchmark ) => {
57- const inputs : CaseInputs = {
58- summary : {
59- datasetId : benchmark . id ,
60- expectedNodes : benchmark . expectedNodes ,
61- } ,
62- artefacts : [
63- {
64- type : "graph" ,
65- uri : `benchmark://${ benchmark . id } ` ,
57+ const createBenchmarkCaseDefinitions = async ( ) : Promise < CaseDefinition < BenchmarkGraphExpander > [ ] > => {
58+ const cases : CaseDefinition < BenchmarkGraphExpander > [ ] = [ ] ;
59+
60+ for ( const benchmark of BENCHMARK_CASES ) {
61+ // Load benchmark data to get node IDs
62+ const benchmarkData = await loadBenchmarkByIdFromUrl ( benchmark . id ) ;
63+ const nodes = benchmarkData . graph . getAllNodes ( ) ;
64+
65+ // Determine seed nodes (first and last)
66+ let seeds : string [ ] ;
67+ if ( nodes . length >= 2 ) {
68+ const lastNode = nodes . at ( - 1 ) ;
69+ seeds = lastNode ? [ nodes [ 0 ] . id , lastNode . id ] : [ nodes [ 0 ] . id ] ;
70+ } else if ( nodes . length === 1 ) {
71+ seeds = [ nodes [ 0 ] . id ] ;
72+ } else {
73+ seeds = [ ] ;
74+ }
75+
76+ const inputs : CaseInputs = {
77+ summary : {
78+ datasetId : benchmark . id ,
79+ expectedNodes : benchmark . expectedNodes ,
80+ seeds, // Store seeds in inputs
6681 } ,
67- ] ,
68- } ;
82+ artefacts : [
83+ {
84+ type : "graph" ,
85+ uri : `benchmark://${ benchmark . id } ` ,
86+ } ,
87+ ] ,
88+ } ;
6989
70- const caseSpec : EvaluationCase = {
71- caseId : generateCaseId ( benchmark . name , inputs ) ,
72- name : benchmark . name ,
73- caseClass : benchmark . caseClass ,
74- inputs,
75- version : "1.0.0" ,
76- tags : benchmark . tags ,
77- } ;
90+ const caseSpec : EvaluationCase = {
91+ caseId : generateCaseId ( benchmark . name , inputs ) ,
92+ name : benchmark . name ,
93+ caseClass : benchmark . caseClass ,
94+ inputs,
95+ version : "1.0.0" ,
96+ tags : benchmark . tags ,
97+ } ;
7898
79- return {
80- case : caseSpec ,
81- createExpander : async ( inputsForExpander : CaseInputs ) => {
82- const datasetId = inputsForExpander . summary ?. datasetId as string ;
83- const benchmarkData = await loadBenchmarkByIdFromUrl ( datasetId ) ;
84- return new BenchmarkGraphExpander ( benchmarkData . graph , benchmarkData . meta . directed ) ;
85- } ,
86- getSeeds : ( _inputsForSeeds : CaseInputs ) => {
87- // Default: return first and last nodes (will be populated after loading)
88- // In practice, seeds are determined after the expander is created
89- return [ ] ;
90- } ,
91- } ;
92- } ) ;
99+ cases . push ( {
100+ case : caseSpec ,
101+ createExpander : async ( _inputsForExpander : CaseInputs ) => {
102+ // Use the pre-loaded data
103+ return new BenchmarkGraphExpander ( benchmarkData . graph , benchmarkData . meta . directed ) ;
104+ } ,
105+ getSeeds : ( _inputsForSeeds : CaseInputs ) => {
106+ // Return the pre-computed seeds
107+ return seeds ;
108+ } ,
109+ } ) ;
110+ }
111+
112+ return cases ;
113+ } ;
93114
94115/**
95116 * Synthetic graph case class types.
@@ -132,23 +153,76 @@ export const createSyntheticCaseDefinition = (type: SyntheticGraphType, nodes: n
132153} ;
133154
134155/**
135- * Register all cases with a registry.
156+ * Register all cases with a registry (sync version, doesn't pre-load seeds).
157+ * Use this for backward compatibility when seeds aren't needed upfront.
158+ *
159+ * @param registry - Registry to populate (defaults to new instance)
160+ * @returns The populated registry
161+ */
162+ export const registerCasesSync = ( registry : GraphCaseRegistry = new CaseRegistry ( ) ) : GraphCaseRegistry => {
163+ // Register benchmark cases (without seed pre-loading)
164+ const cases : CaseDefinition < BenchmarkGraphExpander > [ ] = BENCHMARK_CASES . map ( ( benchmark ) => {
165+ const inputs : CaseInputs = {
166+ summary : {
167+ datasetId : benchmark . id ,
168+ expectedNodes : benchmark . expectedNodes ,
169+ } ,
170+ artefacts : [
171+ {
172+ type : "graph" ,
173+ uri : `benchmark://${ benchmark . id } ` ,
174+ } ,
175+ ] ,
176+ } ;
177+
178+ const caseSpec : EvaluationCase = {
179+ caseId : generateCaseId ( benchmark . name , inputs ) ,
180+ name : benchmark . name ,
181+ caseClass : benchmark . caseClass ,
182+ inputs,
183+ version : "1.0.0" ,
184+ tags : benchmark . tags ,
185+ } ;
186+
187+ return {
188+ case : caseSpec ,
189+ createExpander : async ( inputsForExpander : CaseInputs ) => {
190+ const datasetId = inputsForExpander . summary ?. datasetId as string ;
191+ const benchmarkData = await loadBenchmarkByIdFromUrl ( datasetId ) ;
192+ return new BenchmarkGraphExpander ( benchmarkData . graph , benchmarkData . meta . directed ) ;
193+ } ,
194+ getSeeds : ( _inputsForSeeds : CaseInputs ) => {
195+ // Seeds will be determined from the expander after creation
196+ // The SUT factory should handle empty seeds
197+ return [ ] ;
198+ } ,
199+ } ;
200+ } ) ;
201+
202+ registry . registerAll ( cases ) ;
203+ return registry ;
204+ } ;
205+
206+ /**
207+ * Register all cases with a registry (async version, pre-loads seeds).
208+ * This version loads benchmark data during registration to determine seed nodes.
136209 *
137210 * @param registry - Registry to populate (defaults to new instance)
138211 * @returns The populated registry
139212 */
140- export const registerCases = ( registry : GraphCaseRegistry = new CaseRegistry ( ) ) : GraphCaseRegistry => {
141- // Register benchmark cases
142- const benchmarkCases = createBenchmarkCaseDefinitions ( ) ;
213+ export const registerCases = async ( registry : GraphCaseRegistry = new CaseRegistry ( ) ) : Promise < GraphCaseRegistry > => {
214+ // Register benchmark cases (async now, pre-loads seeds)
215+ const benchmarkCases = await createBenchmarkCaseDefinitions ( ) ;
143216 registry . registerAll ( benchmarkCases ) ;
144217
145218 return registry ;
146219} ;
147220
148221/**
149- * Global case registry with all cases registered.
222+ * Global case registry with all cases registered (sync version).
223+ * For async version with pre-loaded seeds, use `await registerCases()` instead.
150224 */
151- export const graphCaseRegistry = registerCases ( new CaseRegistry ( ) ) ;
225+ export const graphCaseRegistry = registerCasesSync ( new CaseRegistry ( ) ) ;
152226
153227/**
154228 * Get seeds for a benchmark graph.
0 commit comments