@@ -11,8 +11,10 @@ import {
1111// Deep import: the mount path is not part of core's published export map (it is
1212// bundled into the runtime IIFE, not imported by consumers). Same shape as
1313// engine/src/services/videoFrameExtractor.test.ts reaching into core's runtime.
14+ import { nestedCompositionPathFixture } from "../../../core/src/compiler/nestedCompositionPath.testFixture.js" ;
1415import { loadCompositions } from "../../../core/src/runtime/compositionLoader.js" ;
1516import { compileForRender } from "./htmlCompiler.js" ;
17+ import { createFileServer } from "@hyperframes/engine" ;
1618import { getVerifiedHyperframeRuntimeSource } from "./hyperframeRuntimeLoader.js" ;
1719
1820vi . mock ( "../utils/urlDownloader.js" , async ( importOriginal ) => ( {
@@ -76,7 +78,7 @@ type ParityContract = ReturnType<typeof extractCompiledHtmlParityContract>;
7678
7779/**
7880 * Mount the project the way the player does — parse `index.html` into the live
79- * document, serve its sub-compositions over a stubbed `fetch` , and let the
81+ * document, serve its sub-compositions through the capture file server , and let the
8082 * runtime assemble them — then read the same contract off the resulting DOM.
8183 *
8284 * This is the third assembly path. Both compiler arms below run the same code
@@ -88,20 +90,26 @@ async function mountContract(dir: string, indexHtml: string): Promise<ParityCont
8890 const parsed = new DOMParser ( ) . parseFromString ( indexHtml , "text/html" ) ;
8991 document . head . innerHTML = parsed . head . innerHTML ;
9092 document . body . innerHTML = parsed . body . innerHTML ;
91- vi . spyOn ( globalThis , "fetch" ) . mockImplementation ( async ( input ) =>
92- Promise . resolve ( new Response ( readFileSync ( join ( dir , String ( input ) ) , "utf8" ) , { status : 200 } ) ) ,
93- ) ;
94- await loadCompositions ( {
95- injectedStyles : [ ] ,
96- injectedScripts : [ ] ,
97- injectedLinks : [ ] ,
98- parseDimensionPx : ( value : string | null ) => ( value ? `${ value } px` : null ) ,
99- // A mount that fails is not a parity result. Surface it instead of
100- // comparing the contract of an empty host against a compiled one.
101- onDiagnostic : ( { code, details } ) => {
102- throw new Error ( `mount diagnostic ${ code } : ${ JSON . stringify ( details ) } ` ) ;
103- } ,
104- } ) ;
93+ const server = await createFileServer ( { projectDir : dir } ) ;
94+ const base = document . createElement ( "base" ) ;
95+ base . href = `${ server . url } /` ;
96+ document . head . prepend ( base ) ;
97+ try {
98+ await loadCompositions ( {
99+ injectedStyles : [ ] ,
100+ injectedScripts : [ ] ,
101+ injectedLinks : [ ] ,
102+ parseDimensionPx : ( value : string | null ) => ( value ? `${ value } px` : null ) ,
103+ // A mount that fails is not a parity result. Surface it instead of
104+ // comparing the contract of an empty host against a compiled one.
105+ onDiagnostic : ( { code, details } ) => {
106+ throw new Error ( `mount diagnostic ${ code } : ${ JSON . stringify ( details ) } ` ) ;
107+ } ,
108+ } ) ;
109+ } finally {
110+ base . remove ( ) ;
111+ server . close ( ) ;
112+ }
105113 return extractCompiledHtmlParityContract ( `<!doctype html>${ document . documentElement . outerHTML } ` ) ;
106114}
107115
@@ -453,6 +461,42 @@ function assembledContract(contract: ParityContract) {
453461}
454462
455463describe ( "mount/compile assembly parity" , ( ) => {
464+ it . each ( [
465+ { name : "a free authored id" , extraHosts : "" , ids : [ "card" ] } ,
466+ {
467+ name : "an authored id collision" ,
468+ extraHosts :
469+ '<div data-composition-id="card" data-composition-src="compositions/cards/card.html"></div>' ,
470+ ids : [ "card" , "card__hf1" ] ,
471+ } ,
472+ {
473+ name : "a reserved suffix collision" ,
474+ extraHosts :
475+ '<div data-composition-id="card" data-composition-src="compositions/cards/card.html"></div><div data-composition-id="card__hf1" data-composition-src="compositions/cards/card.html"></div>' ,
476+ ids : [ "card" , "card__hf1" , "card__hf2" ] ,
477+ } ,
478+ ] ) (
479+ "mounts nested project-root paths with $name identically on all three paths" ,
480+ async ( { extraHosts, ids } ) => {
481+ const result = await contracts ( {
482+ ...nestedCompositionPathFixture ,
483+ "index.html" : nestedCompositionPathFixture [ "index.html" ] ! . replace (
484+ '<div data-composition-id="scene"' ,
485+ `${ extraHosts } <div data-composition-id="scene"` ,
486+ ) ,
487+ } ) ;
488+ expect ( result . render ) . toEqual ( result . preview ) ;
489+ expect ( assembledContract ( result . mount ) ) . toEqual ( assembledContract ( result . preview ) ) ;
490+ expect ( result . preview . compositions . map ( ( c ) => c . id ) ) . toEqual ( expect . arrayContaining ( ids ) ) ;
491+ const cards = [ ...document . querySelectorAll ( "[data-proof]" ) ] ;
492+ expect ( cards . map ( ( card ) => card . textContent ) ) . toEqual ( ids . map ( ( ) => "Project-root card" ) ) ;
493+ const hostIds = cards . map ( ( card ) =>
494+ card . closest ( "[data-composition-src]" ) ?. getAttribute ( "data-composition-id" ) ,
495+ ) ;
496+ expect ( hostIds ) . toEqual ( ids ) ;
497+ } ,
498+ ) ;
499+
456500 it ( "keeps a fixture set that still covers the shape the mount path used to drop" , ( ) => {
457501 expect ( MOUNT_PARITY_FIXTURES . length ) . toBeGreaterThan ( 0 ) ;
458502 const siblingShaped = MOUNT_PARITY_FIXTURES . filter ( ( fixture ) =>
0 commit comments