@@ -4,36 +4,80 @@ import type {
44 Transformer ,
55 WalkerOS ,
66} from '@walkeros/core' ;
7- import { createIngest , createMockLogger } from '@walkeros/core' ;
7+ import { createIngest , createMockLogger , getNextSteps } from '@walkeros/core' ;
88import {
99 destinationInit ,
1010 destinationPush ,
1111 transformerInit ,
1212 transformerPush ,
1313 runTransformerChain ,
14- walkChain ,
15- extractTransformerNextMap ,
1614} from '@walkeros/collector' ;
17- import { compileNext , resolveNext } from '@walkeros/core' ;
1815
1916/**
20- * Resolve a `RouteSpec` to the static form expected by `walkChain` in these
21- * fixture tests. Conditional shapes (`case` / `gate`) resolve through
22- * `resolveNext` with an empty context, surfacing the result the engine would
23- * compute for a request with no ingest or event .
17+ * Local mirror of the collector's internal chain walker. The collector no
18+ * longer exports `walkChain` from its public surface (Task 5.1 hard cut), so
19+ * these fixture tests carry their own minimal walker for resolving before
20+ * chains to ordered transformer-id arrays .
2421 */
25- function staticChain (
26- spec : Transformer . RouteSpec | undefined ,
27- ) : string | string [ ] | undefined {
28- if ( spec === undefined ) return undefined ;
29- return resolveNext ( compileNext ( spec ) ) ?? undefined ;
22+ function localWalkChain (
23+ startId : string | string [ ] | undefined ,
24+ transformers : Transformer . Transformers ,
25+ ) : string [ ] {
26+ if ( ! startId ) return [ ] ;
27+ if ( Array . isArray ( startId ) ) return startId ;
28+
29+ const chain : string [ ] = [ ] ;
30+ const visited = new Set < string > ( ) ;
31+ let current : string | undefined = startId ;
32+
33+ while ( current && transformers [ current ] ) {
34+ if ( visited . has ( current ) ) break ;
35+ visited . add ( current ) ;
36+ chain . push ( current ) ;
37+
38+ const next : Transformer . Route | undefined =
39+ transformers [ current ] . config ?. next ;
40+ if ( typeof next === 'string' ) {
41+ current = next ;
42+ continue ;
43+ }
44+ if (
45+ Array . isArray ( next ) &&
46+ next . every ( ( entry ) => typeof entry === 'string' )
47+ ) {
48+ for ( const id of next ) chain . push ( id ) ;
49+ break ;
50+ }
51+ break ;
52+ }
53+
54+ return chain ;
55+ }
56+
57+ /**
58+ * Resolve a Route to an ordered chain of transformer ids. Uses the public
59+ * `getNextSteps` to compute entry points, then walks `.next` links.
60+ */
61+ function resolveChain (
62+ spec : Transformer . Route | undefined ,
63+ transformers : Transformer . Transformers ,
64+ ) : string [ ] {
65+ if ( spec === undefined ) return [ ] ;
66+ if ( typeof spec === 'string' ) return localWalkChain ( spec , transformers ) ;
67+ if ( Array . isArray ( spec ) && spec . every ( ( entry ) => typeof entry === 'string' ) ) {
68+ return localWalkChain ( spec , transformers ) ;
69+ }
70+ const ids = getNextSteps ( spec ) ;
71+ if ( ids . length === 0 ) return [ ] ;
72+ if ( ids . length === 1 ) return localWalkChain ( ids [ 0 ] , transformers ) ;
73+ return ids ;
3074}
3175
3276/**
3377 * Tests for before-chain execution in transformer simulation.
3478 *
35- * Validates the pattern: resolve before chain -> run via runTransformerChain
36- * -> then call transformerPush on the main transformer.
79+ * Validates the pattern: resolve before chain (via `resolveChain`) -> run via
80+ * runTransformerChain -> then call transformerPush on the main transformer.
3781 *
3882 * This mirrors the logic in simulateTransformer without requiring
3983 * a real ESM bundle.
@@ -112,10 +156,7 @@ describe('transformer simulation isolation — before chain', () => {
112156
113157 // Step 1: Resolve before chain
114158 const before = transformer . config . before ;
115- const beforeChainIds = walkChain (
116- staticChain ( before ) ,
117- extractTransformerNextMap ( transformers ) ,
118- ) ;
159+ const beforeChainIds = resolveChain ( before , transformers ) ;
119160 expect ( beforeChainIds ) . toEqual ( [ 'enrich' ] ) ;
120161
121162 // Step 2: Run before chain
@@ -242,10 +283,7 @@ describe('transformer simulation isolation — before chain', () => {
242283
243284 // Resolve before chain
244285 const before = transformer . config . before ;
245- const beforeChainIds = walkChain (
246- staticChain ( before ) ,
247- extractTransformerNextMap ( transformers ) ,
248- ) ;
286+ const beforeChainIds = resolveChain ( before , transformers ) ;
249287 expect ( beforeChainIds ) . toEqual ( [ 'gate' ] ) ;
250288
251289 // Run before chain — gate drops the event
@@ -313,10 +351,7 @@ describe('transformer simulation isolation — before chain', () => {
313351
314352 // Resolve before chain — should follow validate -> enrich via next link
315353 const before = transformer . config . before ;
316- const beforeChainIds = walkChain (
317- staticChain ( before ) ,
318- extractTransformerNextMap ( transformers ) ,
319- ) ;
354+ const beforeChainIds = resolveChain ( before , transformers ) ;
320355 expect ( beforeChainIds ) . toEqual ( [ 'validate' , 'enrich' ] ) ;
321356
322357 // Run before chain
@@ -488,10 +523,7 @@ describe('destination simulation with before chain', () => {
488523 const before = destination . config . before ;
489524 let processedEvent : WalkerOS . Event = inputEvent ;
490525 if ( before && collector . transformers ) {
491- const beforeChainIds = walkChain (
492- staticChain ( before ) ,
493- extractTransformerNextMap ( collector . transformers ) ,
494- ) ;
526+ const beforeChainIds = resolveChain ( before , collector . transformers ) ;
495527 expect ( beforeChainIds ) . toEqual ( [ 'enrich' ] ) ;
496528
497529 const beforeResult = await runTransformerChain (
@@ -564,10 +596,7 @@ describe('destination simulation with before chain', () => {
564596
565597 // Resolve and run before chain
566598 const before = destination . config . before ;
567- const beforeChainIds = walkChain (
568- staticChain ( before ) ,
569- extractTransformerNextMap ( collector . transformers ! ) ,
570- ) ;
599+ const beforeChainIds = resolveChain ( before , collector . transformers ! ) ;
571600 expect ( beforeChainIds ) . toEqual ( [ 'gate' ] ) ;
572601
573602 const beforeResult = await runTransformerChain (
0 commit comments