import { describe, expect, it } from 'vitest'; import { DEMO_TEMPLATE_300x250 } from '@banner-studio/layout-engine'; import type { Layer, GroupLayer, SmartAssetLayer } from '@banner-studio/types'; import { routeNode } from '../src/ai-orchestration/route-node.js'; function findSmartAsset(layers: Layer[]): SmartAssetLayer | null { for (const l of layers) { if (l.type === 'smart_asset') return l as SmartAssetLayer; if (l.type === 'group') { const found = findSmartAsset((l as GroupLayer).children); if (found) return found; } } return null; } describe('routeNode', () => { it('writes hero_image_url onto the smart_asset layer', () => { const bundle = routeNode({ template: DEMO_TEMPLATE_300x250, hero_image_url: 'https://cdn.example/hero1.jpg' }); const hero = findSmartAsset(bundle.template.artboards[0]!.layers); expect(hero).not.toBeNull(); expect(hero!.direct_url).toBe('https://cdn.example/hero1.jpg'); expect(hero!.selected_variant_id).toBe('feed-row'); expect(bundle.asset_layer_ids).toContain(hero!.id); }); it('does not mutate the input template', () => { const before = JSON.stringify(DEMO_TEMPLATE_300x250); routeNode({ template: DEMO_TEMPLATE_300x250, hero_image_url: 'https://cdn.example/whatever.jpg' }); expect(JSON.stringify(DEMO_TEMPLATE_300x250)).toBe(before); }); });