@tora-editor/tora 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -58
- package/assets/free-audio/arcade-pop/audio/loss.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/reward.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/win.wav +0 -0
- package/assets/free-audio/arcade-pop/source/INFO.txt +11 -11
- package/assets/kenney-food-starter/License.txt +28 -0
- package/assets/kenney-food-starter/burger.glb +0 -0
- package/assets/kenney-food-starter/frying-pan.glb +0 -0
- package/assets/kenney-food-starter/plan.json +61 -0
- package/assets/kenney-food-starter/plate.glb +0 -0
- package/assets/kenney-food-starter/pot.glb +0 -0
- package/assets/kenney-harvest/audio/victory.wav +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_NES/jingles_NES03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/license.txt +14 -0
- package/bin/tora.mjs +77 -9
- package/crates/packer/trusted/native-3d-meta.json +3 -2
- package/crates/packer/trusted/native-3d.js +181 -181
- package/crates/packer/trusted/native-meta.json +2 -2
- package/crates/packer/trusted/native.js +5 -5
- package/crates/packer/trusted/release-manifest.json +17 -17
- package/crates/packer/trusted/review-runtime-meta.json +3 -2
- package/crates/packer/trusted/review-runtime.js +182 -182
- package/docs/TORA_AGENT_SETUP.md +24 -13
- package/docs/TORA_CREATION_API.md +29 -12
- package/docs/reference/CORE_AUTHORING.md +2 -1
- package/docs/reference/PLAYABLE_STARTERS.md +20 -0
- package/docs/reference/packs/3d.md +9 -3
- package/network-rules/mintegral-appgrowth-single-html.json +10 -10
- package/package.json +6 -6
- package/packages/creative-project/project-v21.schema.json +264 -8
- package/scripts/lean/editor/review-editor.css +10 -0
- package/scripts/lean/editor/review-editor.js +117 -1
- package/scripts/lean/native/agent-tools.mjs +7 -7
- package/scripts/lean/native/api.mjs +16 -5
- package/scripts/lean/native/asset-catalog.mjs +7 -6
- package/scripts/lean/native/asset-lineage.mjs +54 -0
- package/scripts/lean/native/asset-prep.mjs +173 -40
- package/scripts/lean/native/assets.mjs +107 -11
- package/scripts/lean/native/author-expansion-proofs.mjs +2 -99
- package/scripts/lean/native/author-fps.mjs +545 -0
- package/scripts/lean/native/author-primitive-proofs.mjs +5 -4
- package/scripts/lean/native/build-cache.mjs +2 -2
- package/scripts/lean/native/cc0-inputs.mjs +24 -0
- package/scripts/lean/native/cc0-staging.mjs +28 -8
- package/scripts/lean/native/check-harvest-outcome-audio.mjs +7 -8
- package/scripts/lean/native/check-salvage.mjs +8 -5
- package/scripts/lean/native/compiler.mjs +9 -3
- package/scripts/lean/native/contracts.mjs +11 -8
- package/scripts/lean/native/creative-qa.mjs +305 -122
- package/scripts/lean/native/demos.mjs +47 -3
- package/scripts/lean/native/document.mjs +36 -10
- package/scripts/lean/native/export-budget.mjs +75 -0
- package/scripts/lean/native/glb-loader.mjs +468 -0
- package/scripts/lean/native/intake-creator-tools.mjs +83 -30
- package/scripts/lean/native/local-bundle.mjs +5 -3
- package/scripts/lean/native/mcp-server.mjs +33 -46
- package/scripts/lean/native/media-validate.mjs +124 -0
- package/scripts/lean/native/native-bin.mjs +3 -3
- package/scripts/lean/native/outcome-playthrough.mjs +97 -0
- package/scripts/lean/native/prepare-fps-assets.mjs +330 -0
- package/scripts/lean/native/project-bundle.mjs +3 -3
- package/scripts/lean/native/remote-cc0-fetcher.mjs +403 -197
- package/scripts/lean/native/review-agent-tools.mjs +2 -2
- package/scripts/lean/native/review.mjs +3 -0
- package/scripts/lean/native/runtime.mjs +242 -56
- package/scripts/lean/native/schema.mjs +7 -5
- package/scripts/lean/native/service.mjs +159 -32
- package/scripts/lean/native/stage-3d.mjs +343 -40
- package/scripts/lean/native/starters.mjs +436 -0
- package/scripts/lean/native/verify.mjs +1 -1
- package/scripts/lean/native/win-cues.mjs +96 -0
- package/skills/tora-playables/SKILL.md +1 -1
|
@@ -8,7 +8,9 @@ import {setTimeout} from 'node:timers';
|
|
|
8
8
|
import process from 'node:process';
|
|
9
9
|
import {loadCatalog} from './catalog-cache.mjs';
|
|
10
10
|
import {moduleForProject} from './modules/index.mjs';
|
|
11
|
-
import {
|
|
11
|
+
import {builtInPlaythrough} from './outcome-playthrough.mjs';
|
|
12
|
+
import {isAudioMime,validateGlbHeader} from './media-validate.mjs';
|
|
13
|
+
import {glbBudgetInfo} from './export-budget.mjs';
|
|
12
14
|
import {getNetworkTarget} from './network-targets.mjs';
|
|
13
15
|
import {IS_SOURCE_CHECKOUT} from '../runtime-paths.mjs';
|
|
14
16
|
|
|
@@ -46,15 +48,16 @@ const canonical=value=>{
|
|
|
46
48
|
return value;
|
|
47
49
|
};
|
|
48
50
|
const hash=value=>'sha256:'+createHash('sha256').update(value).digest('hex');
|
|
49
|
-
const [qaSourceBytes,mraidHostBytes,vendorHostBytes]=await Promise.all([
|
|
51
|
+
const [qaSourceBytes,playthroughBytes,mraidHostBytes,vendorHostBytes]=await Promise.all([
|
|
50
52
|
readFile(new URL(import.meta.url)),
|
|
53
|
+
readFile(new URL('./outcome-playthrough.mjs',import.meta.url)),
|
|
51
54
|
readFile(new URL(IS_SOURCE_CHECKOUT?'../../../packages/test-harness/src/mraid-host.ts':'../../../crates/packer/trusted/mraid-host.iife.js',import.meta.url)),
|
|
52
55
|
readFile(new URL(IS_SOURCE_CHECKOUT?'../../../packages/test-harness/src/vendor-hosts.ts':'../../../crates/packer/trusted/vendor-hosts.iife.js',import.meta.url)),
|
|
53
56
|
]);
|
|
54
|
-
export const CREATIVE_QA_CHECKER_VERSION='tora-creative-qa-1:'+hash(Buffer.concat([qaSourceBytes,mraidHostBytes,vendorHostBytes]));
|
|
57
|
+
export const CREATIVE_QA_CHECKER_VERSION='tora-creative-qa-1:'+hash(Buffer.concat([qaSourceBytes,playthroughBytes,mraidHostBytes,vendorHostBytes]));
|
|
55
58
|
const DEFAULT_MOTION_OFFSETS_MS=Object.freeze([0,80,180,320,500,750,1050,1350]);
|
|
56
59
|
const DEFAULT_ENDCARD_OFFSETS_MS=Object.freeze([0,150,350,650]);
|
|
57
|
-
const MOTION_BEHAVIOR_KINDS=new Set(['emitter','animation','motion','physics-body','physics-3d','camera-follow','path-agent','oscillate','oscillate-3d']);
|
|
60
|
+
const MOTION_BEHAVIOR_KINDS=new Set(['emitter','animation','animate-3d','motion','physics-body','physics-3d','camera-follow','path-agent','oscillate','oscillate-3d']);
|
|
58
61
|
let cachedBrowserVersionPromise=null;
|
|
59
62
|
export function getPlaywrightBrowserVersion(){
|
|
60
63
|
if(!cachedBrowserVersionPromise){
|
|
@@ -82,7 +85,7 @@ async function readVerifiedHostBundle(filename){
|
|
|
82
85
|
if(typeof expected!=='string'||hash(script)!==expected)throw Error('E_NATIVE_HOST_CORRUPT');
|
|
83
86
|
return script;
|
|
84
87
|
}
|
|
85
|
-
async function getHostInit(networkTarget){
|
|
88
|
+
export async function getHostInit(networkTarget){
|
|
86
89
|
const key=`${networkTarget.hostKind}:${networkTarget.mraidVersion??''}`;
|
|
87
90
|
if(hostInitCache.has(key))return hostInitCache.get(key);
|
|
88
91
|
let script;
|
|
@@ -444,6 +447,57 @@ export async function runStaticPreflight(projectOrOptions,suppliedOptions={}){
|
|
|
444
447
|
blockers.push(issue('blocker','end-card-hero-low-res',component.id,'Replace the upscaled low-resolution end-card image with crisp high-resolution artwork (>= 50% of rendered size).',{detail:`End-card image ${component.id} upscales ${dims.width}x${dims.height}px artwork to ${renderW}x${renderH}px (${Math.max(scaleX,scaleY).toFixed(1)}x).`,metrics:{componentId:component.id,assetId,intrinsicWidth:dims.width,intrinsicHeight:dims.height,renderWidth:renderW,renderHeight:renderH}}));
|
|
445
448
|
}
|
|
446
449
|
}
|
|
450
|
+
// Inspect embedded 3D GLB assets, subNode bindings, and scene 3D budgets
|
|
451
|
+
const glbAssets=assets.filter(asset=>asset.mime==='model/gltf-binary');
|
|
452
|
+
const glbInfoById=new Map();
|
|
453
|
+
let totalGlbDecodedTextureBytes=0;
|
|
454
|
+
for(const asset of [...glbAssets].sort((a,b)=>a.id.localeCompare(b.id))){
|
|
455
|
+
const rawBytes=await bytesFor(asset,project);
|
|
456
|
+
if(!rawBytes)continue;
|
|
457
|
+
try{
|
|
458
|
+
const buf=Buffer.isBuffer(rawBytes)?rawBytes:Buffer.from(rawBytes);
|
|
459
|
+
validateGlbHeader(buf,'E_MODEL_CORRUPT');
|
|
460
|
+
const info=glbBudgetInfo(buf);
|
|
461
|
+
glbInfoById.set(asset.id,info);
|
|
462
|
+
totalGlbDecodedTextureBytes+=info.decodedTextureBytes;
|
|
463
|
+
}catch(error){
|
|
464
|
+
blockers.push(issue('blocker','model-glb-invalid',null,'Re-prepare or re-upload the 3D asset as a valid canonical glTF 2.0 binary (.glb).',{detail:`${asset.id}: ${error.message}`,metrics:{assetId:asset.id}}));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const scene3dStats=new Map();
|
|
468
|
+
for(const component of components){
|
|
469
|
+
if(component.contract!=='native.mesh3d.v1')continue;
|
|
470
|
+
const sourceSlot=component.assetSlots?.find(slot=>slot.slotId==='source');
|
|
471
|
+
const info=sourceSlot?glbInfoById.get(sourceSlot.assetId):undefined;
|
|
472
|
+
if(!info)continue;
|
|
473
|
+
const requestedSubNode=component.parameters?.subNode;
|
|
474
|
+
if(typeof requestedSubNode==='string'&&requestedSubNode.length>0&&!info.subNodes.includes(requestedSubNode)){
|
|
475
|
+
blockers.push(issue('blocker','model-subnode-missing',component.id,'Update subNode to match a preserved named node in the GLB asset or remove subNode to render the whole model.',{detail:`Component ${component.id} requests subNode "${requestedSubNode}", which is not present in ${sourceSlot.assetId} (${info.subNodes.join(', ')||'no named nodes'}).`,metrics:{componentId:component.id,assetId:sourceSlot.assetId,subNode:requestedSubNode,availableSubNodes:info.subNodes}}));
|
|
476
|
+
}
|
|
477
|
+
for(const animBeh of (project.gameplay??[]).filter(b=>b.kind==='animate-3d'&&b.componentId===component.id)){
|
|
478
|
+
const clip=animBeh.parameters?.clipName;
|
|
479
|
+
if(typeof clip==='string'&&clip.length>0&&!(info.animations??[]).includes(clip)){
|
|
480
|
+
blockers.push(issue('blocker','model-animation-missing',component.id,'Update animate-3d clipName to match an animation clip in the GLB asset or leave clipName empty for the default clip.',{detail:`Component ${component.id} requests animation clip "${clip}", which is not present in ${sourceSlot.assetId} (${(info.animations??[]).join(', ')||'no clips'}).`,metrics:{componentId:component.id,assetId:sourceSlot.assetId,clipName:clip,availableClips:info.animations??[]}}));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if(!component.prototype&&component.parameters?.visible!==false){
|
|
484
|
+
const st=scene3dStats.get(component.sceneId)??{triangles:0,drawCalls:0};
|
|
485
|
+
st.triangles+=info.triangles;
|
|
486
|
+
st.drawCalls+=info.drawCalls;
|
|
487
|
+
scene3dStats.set(component.sceneId,st);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
for(const [sceneId,st] of scene3dStats.entries()){
|
|
491
|
+
if(st.triangles>25000){
|
|
492
|
+
warnings.push(issue('warning','scene3d-high-triangles',null,'Reduce 3D scene triangle count below 25,000 for smooth mobile WebView performance.',{detail:`Scene ${sceneId} references ~${st.triangles} triangles across GLB meshes.`,metrics:{sceneId,triangles:st.triangles}}));
|
|
493
|
+
}
|
|
494
|
+
if(st.drawCalls>40){
|
|
495
|
+
warnings.push(issue('warning','scene3d-high-drawcalls',null,'Reduce 3D scene draw calls below 40 by merging materials or reducing separate GLB instances.',{detail:`Scene ${sceneId} issues ~${st.drawCalls} GLB draw calls.`,metrics:{sceneId,drawCalls:st.drawCalls}}));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if(totalGlbDecodedTextureBytes>16*1024*1024){
|
|
499
|
+
warnings.push(issue('warning','scene3d-high-vram',null,'Lower maxTextureSide on 3D models to keep decoded GLB texture VRAM under 16 MiB.',{detail:`Decoded GLB textures require ${(totalGlbDecodedTextureBytes/(1024*1024)).toFixed(1)} MiB across ${glbInfoById.size} model(s).`,metrics:{decodedTextureBytes:totalGlbDecodedTextureBytes}}));
|
|
500
|
+
}
|
|
447
501
|
const wavAssets=assets.filter(asset=>isAudioMime(asset.mime)),assetRoutes=new Map();
|
|
448
502
|
for(const route of routes)if(route.valid){
|
|
449
503
|
if(!assetRoutes.has(route.asset.id))assetRoutes.set(route.asset.id,[]);
|
|
@@ -474,7 +528,7 @@ export async function runStaticPreflight(projectOrOptions,suppliedOptions={}){
|
|
|
474
528
|
blockers.push(issue('blocker','audio-analysis-failed',routeRows[0].componentId,'Replace malformed or unsupported audio bytes with a bounded WAV or MP3 accepted by the asset pipeline.',{detail:`${asset.id}: ${error.message}`,metrics:{assetId:asset.id,code:error.code??null}}));
|
|
475
529
|
}
|
|
476
530
|
}
|
|
477
|
-
return formatCreativeQaReport({scope:'static',blockers,warnings,checks:{audioBindings:audio.length,wavAssets:wavAssets.length,wavAnalysis:analyzerStatus,pixelTextComponents:pixelComponents.length,catalogMetadata:Boolean(catalog)}});
|
|
531
|
+
return formatCreativeQaReport({scope:'static',blockers,warnings,checks:{audioBindings:audio.length,wavAssets:wavAssets.length,wavAnalysis:analyzerStatus,glbAssets:glbAssets.length,pixelTextComponents:pixelComponents.length,catalogMetadata:Boolean(catalog)}});
|
|
478
532
|
}
|
|
479
533
|
export const staticPreflight=runStaticPreflight;
|
|
480
534
|
export const preflight=runStaticPreflight;
|
|
@@ -491,6 +545,45 @@ function meaningfulState(state){
|
|
|
491
545
|
}
|
|
492
546
|
function stateChanged(before,after){return JSON.stringify(canonical(meaningfulState(before)))!==JSON.stringify(canonical(meaningfulState(after)));}
|
|
493
547
|
|
|
548
|
+
function endingScenes(project){
|
|
549
|
+
const cards=(project?.scenes??[]).filter(scene=>scene.role==='end-card');
|
|
550
|
+
const isTimeout=scene=>normalizeRole(scene.id)==='loss'||normalizeRole(scene.label)==='loss';
|
|
551
|
+
return {win:cards.filter(scene=>!isTimeout(scene)).map(scene=>scene.id),timeout:cards.filter(isTimeout).map(scene=>scene.id)};
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function captureBrowserStore(){
|
|
555
|
+
globalThis.__toraQaStoreCalls=[];
|
|
556
|
+
globalThis.open=url=>{globalThis.__toraQaStoreCalls.push(String(url));return null;};
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
async function storeCalls(page,hostKind){
|
|
560
|
+
const entries={
|
|
561
|
+
mraid:['__mraidTest','open'],dapi:['__ironsourceTest','openStoreUrl'],meta:['__metaTest','onCTAClick'],
|
|
562
|
+
'google-exitapi':['__googleTest','exit'],mintegral:['__mintegralTest','install'],tiktok:['__tiktokTest','openAppStore'],
|
|
563
|
+
};
|
|
564
|
+
return page.evaluate(entry=>{
|
|
565
|
+
if(!entry)return globalThis.__toraQaStoreCalls??[];
|
|
566
|
+
const snapshot=globalThis[entry[0]]?.snapshot?.();
|
|
567
|
+
return (Array.isArray(snapshot)?snapshot:snapshot?.calls??[]).filter(call=>call.name===entry[1]);
|
|
568
|
+
},entries[hostKind]??null);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
async function storeTarget(page,current){
|
|
572
|
+
const ids=(current.events??[]).filter(event=>event.kind==='click'&¤t.eventBindings.some(
|
|
573
|
+
binding=>binding.eventId===event.id&&binding.actions.some(action=>action.kind==='store'),
|
|
574
|
+
)).map(event=>event.componentId);
|
|
575
|
+
return page.evaluate(ids=>{
|
|
576
|
+
const canvas=globalThis.document.querySelector('canvas');
|
|
577
|
+
const audit=globalThis.toraRuntime?.auditSceneLayout?.({ids,interactiveIds:ids});
|
|
578
|
+
const target=audit?.interactive?.find(row=>ids.includes(row.id));
|
|
579
|
+
if(!canvas||!target)return null;
|
|
580
|
+
const {bounds}=target,{width,height,scale}=audit.viewport,rect=canvas.getBoundingClientRect();
|
|
581
|
+
const x=rect.left+(rect.width-width*scale)/2+(bounds.left+bounds.right)/2*scale;
|
|
582
|
+
const y=rect.top+(rect.height-height*scale)/2+(bounds.top+bounds.bottom)/2*scale;
|
|
583
|
+
return x>=rect.left&&x<rect.right&&y>=rect.top&&y<rect.bottom?{componentId:target.id,x,y}:null;
|
|
584
|
+
},ids);
|
|
585
|
+
}
|
|
586
|
+
|
|
494
587
|
async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,network,browser:sharedBrowser}){
|
|
495
588
|
const {chromium}=await import('playwright');
|
|
496
589
|
const browser=sharedBrowser??await chromium.launch({headless:true});
|
|
@@ -506,15 +599,71 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
506
599
|
const scriptUrl=networkTarget.hostKind==='google-exitapi'?'https://tpc.googlesyndication.com/pagead/gadgets/html5/api/exitapi.js':'https://sf16-muse-va.ibytedtos.com/obj/union-fe-nc-i18n/Playable/sdk/Playable-sdk.js';
|
|
507
600
|
await context.route(scriptUrl,route=>route.fulfill({status:200,contentType:'application/javascript',body:'/* declared vendor host supplied by the QA mock */'}));
|
|
508
601
|
}
|
|
602
|
+
const mockBrowserStore=!networkTarget||networkTarget.hostKind==='browser';
|
|
603
|
+
if(mockBrowserStore)await page.addInitScript(captureBrowserStore);
|
|
509
604
|
const url=htmlPath?pathToFileURL(resolve(htmlPath)).href:undefined;
|
|
605
|
+
const settleFrame=async targetPage=>{
|
|
606
|
+
await targetPage.waitForFunction(()=>(globalThis.toraRuntime?.state?.()?.model3d?.texturesPending??0)===0,undefined,{timeout:5000}).catch(()=>{});
|
|
607
|
+
await targetPage.evaluate(async()=>{await globalThis.document.fonts?.ready;await new Promise(resolveFrame=>globalThis.requestAnimationFrame(()=>globalThis.requestAnimationFrame(resolveFrame)));});
|
|
608
|
+
};
|
|
609
|
+
const readProject=async targetPage=>project??await targetPage.evaluate(()=>{
|
|
610
|
+
const embedded=globalThis.document.getElementById('project');
|
|
611
|
+
return embedded?JSON.parse(embedded.textContent):null;
|
|
612
|
+
});
|
|
613
|
+
const playEnding=async(targetPage,session)=>{
|
|
614
|
+
const current=await readProject(targetPage);
|
|
615
|
+
if(!current)return {available:false,required:false};
|
|
616
|
+
const {win,timeout}=endingScenes(current),{descriptor}=moduleForProject(current);
|
|
617
|
+
if(descriptor?.qa?.playToEndCard)return {...await descriptor.qa.playToEndCard(targetPage,current),required:true};
|
|
618
|
+
if(!win.length)return {available:false,required:false};
|
|
619
|
+
const play=builtInPlaythrough(current);
|
|
620
|
+
if(play)return {available:await play(targetPage),required:true,mode:'real-play'};
|
|
621
|
+
const readScene=()=>targetPage.evaluate(()=>globalThis.toraRuntime?.state?.()?.scene);
|
|
622
|
+
for(let attempt=0;attempt<24;attempt++){
|
|
623
|
+
const scene=await readScene();
|
|
624
|
+
if(win.includes(scene))return {available:true,required:true,mode:'real-play'};
|
|
625
|
+
if(timeout.includes(scene))break;
|
|
626
|
+
const target=await session.getPrimaryTarget(targetPage,true);
|
|
627
|
+
if(!target)break;
|
|
628
|
+
await session.prepareClick(target,targetPage);
|
|
629
|
+
await session.click(target,targetPage);
|
|
630
|
+
await targetPage.waitForTimeout(180);
|
|
631
|
+
}
|
|
632
|
+
const winBindings=current.eventBindings.filter(binding=>binding.actions.some(
|
|
633
|
+
action=>action.kind==='changeScene'&&win.includes(action.sceneId),
|
|
634
|
+
));
|
|
635
|
+
const actionDelay=Math.max(0,...winBindings.flatMap(binding=>binding.actions.map(action=>action.delaySeconds??0)));
|
|
636
|
+
const arrival=current.events.some(event=>event.kind==='pathArrive'&&winBindings.some(binding=>binding.eventId===event.id));
|
|
637
|
+
await targetPage.waitForFunction(ids=>ids.includes(globalThis.toraRuntime?.state?.()?.scene),win,
|
|
638
|
+
{timeout:Math.max(arrival?6500:1500,actionDelay*1200+300)}).catch(()=>{});
|
|
639
|
+
return win.includes(await readScene())?{available:true,required:true,mode:'real-play'}:{available:false,required:true};
|
|
640
|
+
};
|
|
641
|
+
const verifyStore=async targetPage=>{
|
|
642
|
+
const current=await readProject(targetPage);
|
|
643
|
+
const before=await storeCalls(targetPage,networkTarget?.hostKind);
|
|
644
|
+
if(before.length)return {ok:false,reason:'early-store-open'};
|
|
645
|
+
const until=Date.now()+1400;
|
|
646
|
+
let target;
|
|
647
|
+
do{
|
|
648
|
+
target=await storeTarget(targetPage,current);
|
|
649
|
+
if(target)break;
|
|
650
|
+
await targetPage.waitForTimeout(50);
|
|
651
|
+
}while(Date.now()<until);
|
|
652
|
+
if(!target)return {ok:false,reason:'store-cta-missing'};
|
|
653
|
+
await targetPage.mouse.click(target.x,target.y);
|
|
654
|
+
const after=await storeCalls(targetPage,networkTarget?.hostKind);
|
|
655
|
+
const actualUrl=typeof after[0]==='string'?after[0]:after[0]?.args?.[0];
|
|
656
|
+
const ok=after.length===1&&(actualUrl===undefined||actualUrl===current.base.storeUrl);
|
|
657
|
+
return {ok,componentId:target.componentId,...(!ok?{reason:'store-cta-did-not-open'}:{})};
|
|
658
|
+
};
|
|
510
659
|
let closed=false;
|
|
511
660
|
return {
|
|
512
661
|
async setViewport(viewport){await page.setViewportSize(viewport);},
|
|
513
662
|
async load(){
|
|
514
663
|
await page.evaluate(()=>globalThis.toraRuntime?.destroy?.()).catch(()=>{});
|
|
515
|
-
if(url)await page.goto(url,{waitUntil:'load'});else{if(hostInit)await page.evaluate(hostInit);await page.setContent(html,{waitUntil:'load'});}
|
|
664
|
+
if(url)await page.goto(url,{waitUntil:'load'});else{await page.goto('about:blank');if(hostInit)await page.evaluate(hostInit);await page.setContent(html,{waitUntil:'load'});}
|
|
516
665
|
await page.waitForFunction(()=>globalThis.toraRuntime);
|
|
517
|
-
await page
|
|
666
|
+
await settleFrame(page);
|
|
518
667
|
},
|
|
519
668
|
async screenshot(){return page.screenshot({type:'png'});},
|
|
520
669
|
async auditLayout(args){
|
|
@@ -524,8 +673,31 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
524
673
|
},args);
|
|
525
674
|
},
|
|
526
675
|
async getState(){return page.evaluate(()=>globalThis.toraRuntime?.state?.()??null);},
|
|
527
|
-
async
|
|
528
|
-
|
|
676
|
+
async armResponseMeasurement(){
|
|
677
|
+
await page.evaluate(()=>{
|
|
678
|
+
globalThis.__toraQaInputResponse=undefined;
|
|
679
|
+
globalThis.document.addEventListener('pointerdown',event=>{
|
|
680
|
+
const snapshot=()=>{
|
|
681
|
+
const state=globalThis.toraRuntime?.state?.();
|
|
682
|
+
if(!state)return null;
|
|
683
|
+
const observable={...state};
|
|
684
|
+
delete observable.time;
|
|
685
|
+
delete observable.input;
|
|
686
|
+
return JSON.stringify(observable);
|
|
687
|
+
};
|
|
688
|
+
const before=snapshot(),started=event.timeStamp;
|
|
689
|
+
const poll=()=>{
|
|
690
|
+
const elapsed=globalThis.performance.now()-started;
|
|
691
|
+
if(before!==snapshot())globalThis.__toraQaInputResponse=elapsed;
|
|
692
|
+
else if(elapsed<260)globalThis.requestAnimationFrame(poll);
|
|
693
|
+
};
|
|
694
|
+
globalThis.requestAnimationFrame(poll);
|
|
695
|
+
},{capture:true,once:true});
|
|
696
|
+
});
|
|
697
|
+
},
|
|
698
|
+
async readResponseMeasurement(){return page.evaluate(()=>globalThis.__toraQaInputResponse);},
|
|
699
|
+
async getPrimaryTarget(targetPage=page,activeScene=false){
|
|
700
|
+
return targetPage.evaluate(({authored,preferred,activeScene})=>{
|
|
529
701
|
const embedded=globalThis.document.getElementById('project');
|
|
530
702
|
const current=authored??(embedded?JSON.parse(embedded.textContent):undefined);
|
|
531
703
|
const canvas=globalThis.document.querySelector('canvas');
|
|
@@ -534,12 +706,23 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
534
706
|
const bindings=new Map(current.eventBindings.map(binding=>[binding.eventId,binding]));
|
|
535
707
|
const multiply=(a,b)=>[a[0]*b[0]+a[2]*b[1],a[1]*b[0]+a[3]*b[1],a[0]*b[2]+a[2]*b[3],a[1]*b[2]+a[3]*b[3],a[0]*b[4]+a[2]*b[5]+a[4],a[1]*b[4]+a[3]*b[5]+a[5]];
|
|
536
708
|
const clickEvents=current.events.filter(event=>event.kind==='click'&&byId.has(event.componentId));
|
|
709
|
+
const liveState=activeScene?globalThis.toraRuntime?.state?.():null;
|
|
710
|
+
const scene=liveState?.scene??current.base.startScene;
|
|
711
|
+
const parameters=component=>({...component.parameters,...liveState?.components?.[component.id]?.parameters});
|
|
537
712
|
const eligible=event=>{
|
|
538
713
|
const component=byId.get(event.componentId);
|
|
539
|
-
|
|
714
|
+
if(component.sceneId!==scene||component.prototype||parameters(component).enabled===false)return false;
|
|
715
|
+
for(let node=component;node;node=byId.get(node.parentId)){
|
|
716
|
+
const params=parameters(node);
|
|
717
|
+
if(params.visible===false||params.opacity===0)return false;
|
|
718
|
+
}
|
|
719
|
+
return true;
|
|
540
720
|
};
|
|
541
721
|
let candidates=clickEvents.filter(event=>!preferred||event.componentId===preferred).filter(eligible).filter(event=>{
|
|
542
722
|
const component=byId.get(event.componentId);
|
|
723
|
+
if(activeScene&¤t.eventBindings.filter(binding=>binding.eventId===event.id).every(
|
|
724
|
+
binding=>binding.actions.every(action=>action.kind==='store'||action.kind==='restart'),
|
|
725
|
+
))return false;
|
|
543
726
|
return component.contract!=='native.group.v1'||component.parameters?.width>0&&component.parameters?.height>0;
|
|
544
727
|
});
|
|
545
728
|
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='match-tile'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id+'.primary',componentId:behavior.componentId})).filter(eligible);
|
|
@@ -547,7 +730,7 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
547
730
|
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='aim-launch-3d'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id,kind:'aim-launch-3d',componentId:behavior.componentId})).filter(eligible);
|
|
548
731
|
const liveInstances=globalThis.toraRuntime?.state?.()?.instances??[];
|
|
549
732
|
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='drag'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id,kind:'drag',componentId:behavior.componentId,parameters:behavior.parameters})).filter(eligible);
|
|
550
|
-
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='drag'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id,kind:'drag',componentId:behavior.componentId,parameters:behavior.parameters,fromInstance:true})).filter(entry=>{const c=byId.get(entry.componentId);return c.sceneId===
|
|
733
|
+
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='drag'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id,kind:'drag',componentId:behavior.componentId,parameters:behavior.parameters,fromInstance:true})).filter(entry=>{const c=byId.get(entry.componentId);return c.sceneId===scene&&c.prototype&&c.parameters?.visible!==false&&liveInstances.some(instance=>instance.prototypeId===c.id);});
|
|
551
734
|
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='swipe-input'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id,kind:'swipe',componentId:behavior.componentId})).filter(eligible);
|
|
552
735
|
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='virtual-joystick'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id,kind:'joystick',componentId:behavior.componentId})).filter(eligible);
|
|
553
736
|
if(!candidates.length&&!preferred)candidates=current.gameplay.filter(behavior=>behavior.kind==='hold-charge'&&byId.has(behavior.componentId)).map(behavior=>({id:behavior.id,kind:'hold',componentId:behavior.componentId})).filter(eligible);
|
|
@@ -571,12 +754,12 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
571
754
|
return {componentId:component.id,interaction:'aim-launch',x:rect.left+offsetX+pt.x*scale,y:rect.top+offsetY+pt.y*scale};
|
|
572
755
|
}
|
|
573
756
|
const local=target=>{
|
|
574
|
-
const authoredTransform=target.transform??[1,0,0,1,0,0],layout=responsive.get(target.id);
|
|
757
|
+
const authoredTransform=liveState?.components?.[target.id]?.transform??target.transform??[1,0,0,1,0,0],layout=responsive.get(target.id);
|
|
575
758
|
if(!layout||!landscape)return authoredTransform;
|
|
576
759
|
const result=[...authoredTransform];result[4]+=layout.x-authoredTransform[4];result[5]+=layout.y-authoredTransform[5];result[0]*=layout.scaleX;result[1]*=layout.scaleX;result[2]*=layout.scaleY;result[3]*=layout.scaleY;return result;
|
|
577
760
|
};
|
|
578
761
|
const world=target=>target.parentId?multiply(world(byId.get(target.parentId)),local(target)):local(target);
|
|
579
|
-
const matrix=world(component),width
|
|
762
|
+
const matrix=world(component),{width,height}=parameters(component);
|
|
580
763
|
const screen=pt=>({x:rect.left+offsetX+pt.x*scale,y:rect.top+offsetY+pt.y*scale});
|
|
581
764
|
const liveMatches=candidates[0]?.fromInstance?liveInstances.filter(instance=>instance.prototypeId===component.id):[];
|
|
582
765
|
const center=liveMatches.length?{x:liveMatches[0].x+width/2,y:liveMatches[0].y+height/2}:{x:matrix[0]*width/2+matrix[2]*height/2+matrix[4],y:matrix[1]*width/2+matrix[3]*height/2+matrix[5]};
|
|
@@ -605,108 +788,80 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
605
788
|
return {componentId:component.id,interaction:kind,x:from.x,y:from.y,endX:to.x,endY:to.y};
|
|
606
789
|
}
|
|
607
790
|
return {componentId:component.id,interaction:kind==='aim-launch'?'aim-launch':'click',...start};
|
|
608
|
-
},{authored:project??null,preferred:primaryComponentId??null});
|
|
791
|
+
},{authored:project??null,preferred:activeScene?null:primaryComponentId??null,activeScene});
|
|
609
792
|
},
|
|
610
|
-
async prepareClick(target){if(target.interaction==='aim-launch')await
|
|
611
|
-
async click(target){
|
|
612
|
-
if(target.interaction==='aim-launch'){await
|
|
613
|
-
else if(target.interaction==='drag-drop'){await
|
|
614
|
-
else if(target.interaction==='swipe'){await
|
|
615
|
-
else if(target.interaction==='hold'){await
|
|
616
|
-
else if(target.interaction==='draw'||target.interaction==='erase'){await
|
|
617
|
-
else await
|
|
618
|
-
},
|
|
619
|
-
async enterEndCard(){
|
|
620
|
-
const current=project??await page.evaluate(()=>{const el=globalThis.document.getElementById('project');return el?JSON.parse(el.textContent):null;});
|
|
621
|
-
if(!current)return {available:false};
|
|
622
|
-
const endScenes=(current.scenes??[]).filter(scene=>scene.role==='end-card');
|
|
623
|
-
const {descriptor}=moduleForProject(current);
|
|
624
|
-
if(descriptor?.qa?.playToEndCard)return descriptor.qa.playToEndCard(page,current);
|
|
625
|
-
if(endScenes.length){
|
|
626
|
-
const target=await this.getPrimaryTarget();
|
|
627
|
-
if(target){
|
|
628
|
-
for(let tap=0;tap<12;tap++){
|
|
629
|
-
await page.mouse.click(target.x,target.y);
|
|
630
|
-
const sceneNow=await page.evaluate(()=>globalThis.toraRuntime?.state?.()?.scene);
|
|
631
|
-
if(endScenes.some(scene=>scene.id===sceneNow))return {available:true,mode:'real-play'};
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
const winEndScene=endScenes.find(scene=>!/fail|loss|timeout/i.test(scene.id))??endScenes[0];
|
|
635
|
-
const ok=await page.evaluate(sceneId=>{
|
|
636
|
-
const canvas=globalThis.document.querySelector('canvas'),embedded=globalThis.document.getElementById('project');
|
|
637
|
-
if(!canvas||!embedded||typeof globalThis.ToraNative?.mountNative!=='function')return false;
|
|
638
|
-
globalThis.toraRuntime?.destroy?.();
|
|
639
|
-
globalThis.toraRuntime=globalThis.ToraNative.mountNative(JSON.parse(embedded.textContent),canvas,{edit:true,sceneId});
|
|
640
|
-
return true;
|
|
641
|
-
},winEndScene.id);
|
|
642
|
-
if(ok){
|
|
643
|
-
await page.evaluate(()=>new Promise(resolveFrame=>globalThis.requestAnimationFrame(()=>globalThis.requestAnimationFrame(resolveFrame))));
|
|
644
|
-
return {available:true,mode:'edit-layout'};
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
return {available:false};
|
|
793
|
+
async prepareClick(target,targetPage=page){if(target.interaction==='aim-launch')await targetPage.mouse.move(target.x,target.y);},
|
|
794
|
+
async click(target,targetPage=page){
|
|
795
|
+
if(target.interaction==='aim-launch'){await targetPage.mouse.down();await targetPage.mouse.move(target.x-64,target.y+28);await targetPage.mouse.up();}
|
|
796
|
+
else if(target.interaction==='drag-drop'){await targetPage.mouse.move(target.x,target.y);await targetPage.mouse.down();await targetPage.mouse.move(target.endX,target.endY,{steps:3});await targetPage.mouse.up();}
|
|
797
|
+
else if(target.interaction==='swipe'){await targetPage.mouse.move(target.x,target.y);await targetPage.mouse.down();await targetPage.mouse.move(target.endX,target.endY,{steps:3});await targetPage.mouse.up();}
|
|
798
|
+
else if(target.interaction==='hold'){await targetPage.mouse.move(target.x,target.y);await targetPage.mouse.down();await targetPage.waitForTimeout(55);await targetPage.mouse.up();}
|
|
799
|
+
else if(target.interaction==='draw'||target.interaction==='erase'){await targetPage.mouse.move(target.x,target.y);await targetPage.mouse.down();await targetPage.mouse.move(target.endX,target.endY,{steps:3});await targetPage.mouse.up();}
|
|
800
|
+
else await targetPage.mouse.click(target.x,target.y);
|
|
648
801
|
},
|
|
802
|
+
async enterEndCard(){return playEnding(page,this);},
|
|
803
|
+
async verifyStore(){return verifyStore(page);},
|
|
649
804
|
async enterTimeout(){
|
|
650
|
-
const current=
|
|
651
|
-
if(!current)return {available:false};
|
|
652
|
-
const {descriptor}=moduleForProject(current);
|
|
653
|
-
const phaseVariable=descriptor?.qa?.phaseVariable??
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
if(
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
if(descriptor?.qa?.validateTimeout&&!descriptor.qa.validateTimeout(timeoutState))throw Error('E_CREATIVE_TIMEOUT_OUTCOME');
|
|
684
|
-
if(!reached){await timeoutPage.close();return {available:false};}
|
|
685
|
-
return {
|
|
686
|
-
available:true,mode:'real-timeout',
|
|
687
|
-
async setViewport(vp){await timeoutPage.setViewportSize(vp);await timeoutPage.evaluate(()=>new Promise(r=>globalThis.requestAnimationFrame(()=>globalThis.requestAnimationFrame(r))));},
|
|
688
|
-
async screenshot(){return timeoutPage.screenshot({type:'png'});},
|
|
689
|
-
async getState(){return timeoutPage.evaluate(()=>globalThis.toraRuntime?.state?.()??null);},
|
|
690
|
-
async auditLayout(args){return timeoutPage.evaluate(opts=>globalThis.toraRuntime?.auditSceneLayout?.(opts)??null,args);},
|
|
691
|
-
async close(){await timeoutPage.close();},
|
|
805
|
+
const current=await readProject(page);
|
|
806
|
+
if(!current)return {available:false,required:false};
|
|
807
|
+
const {descriptor}=moduleForProject(current),{timeout}=endingScenes(current);
|
|
808
|
+
const phaseVariable=descriptor?.qa?.phaseVariable??null;
|
|
809
|
+
const lossBindings=current.eventBindings.filter(binding=>binding.actions.some(
|
|
810
|
+
action=>action.kind==='changeScene'&&timeout.includes(action.sceneId),
|
|
811
|
+
));
|
|
812
|
+
const lossTimers=new Set(current.events.filter(event=>event.kind==='timer'&&lossBindings.some(binding=>binding.eventId===event.id))
|
|
813
|
+
.map(event=>event.behaviorId));
|
|
814
|
+
const timers=current.gameplay.filter(behavior=>behavior.kind==='timer');
|
|
815
|
+
const deadlineBehavior=timers.find(behavior=>behavior.id===descriptor?.qa?.deadlineBehaviorId)??
|
|
816
|
+
timers.find(behavior=>lossTimers.has(behavior.id))??timers.find(behavior=>/deadline|timeout/i.test(behavior.id));
|
|
817
|
+
const declaredTimeout=current.scenes.some(scene=>timeout.includes(scene.id)&&
|
|
818
|
+
/\b(timeout|deadline)\b/.test(semanticText(scene.id+' '+scene.label)));
|
|
819
|
+
const required=declaredTimeout||Boolean(deadlineBehavior&&(timeout.length||phaseVariable));
|
|
820
|
+
if(!required||!deadlineBehavior)return {available:false,required};
|
|
821
|
+
const deadlineSec=deadlineBehavior.parameters.seconds;
|
|
822
|
+
const timeoutPage=await context.newPage();
|
|
823
|
+
try{
|
|
824
|
+
await timeoutPage.setViewportSize(DEFAULT_VIEWPORTS[1]);
|
|
825
|
+
if(hostInit)await timeoutPage.addInitScript(hostInit);
|
|
826
|
+
else await timeoutPage.addInitScript(captureBrowserStore);
|
|
827
|
+
await timeoutPage.addInitScript(({phase,scenes})=>{
|
|
828
|
+
const original=globalThis.requestAnimationFrame.bind(globalThis);
|
|
829
|
+
let frame,now=0,manual=true;
|
|
830
|
+
globalThis.requestAnimationFrame=callback=>{if(!manual)return original(callback);frame=callback;return 1;};
|
|
831
|
+
globalThis.__pumpTimeout=steps=>{
|
|
832
|
+
const reached=()=>{const state=globalThis.toraRuntime?.state?.();return scenes.includes(state?.scene)||Boolean(phase&&state?.variables?.[phase]==='cta');};
|
|
833
|
+
for(let i=0;i<steps&&frame&&!reached();i++){
|
|
834
|
+
const callback=frame;frame=undefined;now+=80;callback(now);
|
|
835
|
+
}
|
|
836
|
+
manual=false;if(frame)original(frame);
|
|
837
|
+
return reached();
|
|
692
838
|
};
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
globalThis.toraRuntime=globalThis.ToraNative.mountNative(JSON.parse(embedded.textContent),canvas,{edit:true,sceneId});
|
|
702
|
-
return true;
|
|
703
|
-
},failScene.id);
|
|
704
|
-
if(ok){
|
|
705
|
-
await page.evaluate(()=>new Promise(resolveFrame=>globalThis.requestAnimationFrame(()=>globalThis.requestAnimationFrame(resolveFrame))));
|
|
706
|
-
return {available:true,mode:'edit-layout'};
|
|
839
|
+
},{phase:phaseVariable,scenes:timeout});
|
|
840
|
+
if(url)await timeoutPage.goto(url,{waitUntil:'load'});
|
|
841
|
+
else{await timeoutPage.goto('about:blank');await timeoutPage.setContent(html,{waitUntil:'load'});}
|
|
842
|
+
await timeoutPage.waitForFunction(()=>globalThis.toraRuntime&&typeof globalThis.__pumpTimeout==='function',undefined,{polling:25,timeout:5000});
|
|
843
|
+
if(descriptor?.qa?.prepareTimeout)await descriptor.qa.prepareTimeout(timeoutPage,current);
|
|
844
|
+
else{
|
|
845
|
+
const state=await timeoutPage.evaluate(()=>globalThis.toraRuntime.state());
|
|
846
|
+
if(!state.network?.started)await timeoutPage.mouse.click(1,1);
|
|
707
847
|
}
|
|
708
|
-
|
|
709
|
-
|
|
848
|
+
// Advance the real runtime on a small canvas, then restore the capture size.
|
|
849
|
+
await timeoutPage.setViewportSize({width:32,height:32});
|
|
850
|
+
const reached=await timeoutPage.evaluate(steps=>globalThis.__pumpTimeout(steps),Math.ceil((deadlineSec+11)/.08));
|
|
851
|
+
const state=await timeoutPage.evaluate(()=>globalThis.toraRuntime?.state?.());
|
|
852
|
+
if(descriptor?.qa?.validateTimeout&&!descriptor.qa.validateTimeout(state))throw Error('E_CREATIVE_TIMEOUT_OUTCOME');
|
|
853
|
+
if(!reached){await timeoutPage.close();return {available:false,required};}
|
|
854
|
+
await timeoutPage.setViewportSize(DEFAULT_VIEWPORTS[1]);
|
|
855
|
+
await settleFrame(timeoutPage);
|
|
856
|
+
return {available:true,required,mode:'real-timeout',
|
|
857
|
+
async setViewport(vp){await timeoutPage.setViewportSize(vp);await settleFrame(timeoutPage);},
|
|
858
|
+
async screenshot(){return timeoutPage.screenshot({type:'png'});},
|
|
859
|
+
async getState(){return timeoutPage.evaluate(()=>globalThis.toraRuntime?.state?.()??null);},
|
|
860
|
+
async auditLayout(args){return timeoutPage.evaluate(opts=>globalThis.toraRuntime?.auditSceneLayout?.(opts)??null,args);},
|
|
861
|
+
async verifyStore(){return verifyStore(timeoutPage);},
|
|
862
|
+
async close(){await timeoutPage.close();},
|
|
863
|
+
};
|
|
864
|
+
}catch(error){await timeoutPage.close().catch(()=>{});throw error;}
|
|
710
865
|
},
|
|
711
866
|
async enterState(state,stateHook){
|
|
712
867
|
if(typeof stateHook!=='string')throw Error('The Playwright state hook must be a global function name');
|
|
@@ -925,15 +1080,16 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
925
1080
|
if(url)await vPage.goto(url,{waitUntil:'load'});
|
|
926
1081
|
else{if(hostInit)await vPage.evaluate(hostInit);await vPage.setContent(html,{waitUntil:'load'});}
|
|
927
1082
|
await vPage.waitForFunction(()=>globalThis.toraRuntime);
|
|
928
|
-
await vPage
|
|
1083
|
+
await settleFrame(vPage);
|
|
929
1084
|
await delay(250);
|
|
930
|
-
|
|
1085
|
+
const ending=await playEnding(vPage,this);
|
|
1086
|
+
if(!ending.required&&target){
|
|
931
1087
|
if(target.interaction==='aim-launch'){await vPage.mouse.move(target.x,target.y);await vPage.mouse.down();await vPage.mouse.move(target.x-64,target.y+28);await vPage.mouse.up();}
|
|
932
1088
|
else if(target.interaction==='drag-drop'||target.interaction==='swipe'||target.interaction==='draw'||target.interaction==='erase'){await vPage.mouse.move(target.x,target.y);await vPage.mouse.down();await vPage.mouse.move(target.endX,target.endY,{steps:5});await vPage.mouse.up();}
|
|
933
1089
|
else if(target.interaction==='hold'){await vPage.mouse.move(target.x,target.y);await vPage.mouse.down();await vPage.waitForTimeout(80);await vPage.mouse.up();}
|
|
934
1090
|
else await vPage.mouse.click(target.x,target.y);
|
|
935
1091
|
}
|
|
936
|
-
await delay(
|
|
1092
|
+
await delay(1100);
|
|
937
1093
|
const videoHandle=vPage.video();
|
|
938
1094
|
await videoContext.close();
|
|
939
1095
|
videoContext=null;
|
|
@@ -948,6 +1104,7 @@ async function openPlaywrightSession({html,htmlPath,project,primaryComponentId,n
|
|
|
948
1104
|
bytes:bytes.length,
|
|
949
1105
|
viewport:normalizeViewport(viewport),
|
|
950
1106
|
triageOnly:true,
|
|
1107
|
+
reachedEndCard:ending.available,
|
|
951
1108
|
};
|
|
952
1109
|
}finally{
|
|
953
1110
|
if(videoContext)await videoContext.close().catch(()=>{});
|
|
@@ -999,6 +1156,7 @@ async function interact(session,viewport,target,openingState,blockers){
|
|
|
999
1156
|
const result={viewport:normalizeViewport(viewport),componentId:target.componentId,within150Ms:false,deltaType:null,maxResponseMs:INTERACTION_LIMIT_MS};
|
|
1000
1157
|
const beforeState=openingState??await session.getState(),beforeScreenshot=hash(await session.screenshot());
|
|
1001
1158
|
if(typeof session.prepareClick==='function')await session.prepareClick(target);
|
|
1159
|
+
await session.armResponseMeasurement?.();
|
|
1002
1160
|
const deadline=Date.now()+INTERACTION_LIMIT_MS;
|
|
1003
1161
|
try{await session.click(target);}catch(error){
|
|
1004
1162
|
const timedOut=error?.name==='TimeoutError'||error?.code==='ETIMEDOUT'||error?.timedOut===true;
|
|
@@ -1006,7 +1164,7 @@ async function interact(session,viewport,target,openingState,blockers){
|
|
|
1006
1164
|
blockers.push(issue('blocker',kind,target.componentId,'Restore a trusted pointer path to the primary target and ensure its click binding executes promptly.',{viewport,detail:error.message,metrics:{limitMs:INTERACTION_LIMIT_MS}}));
|
|
1007
1165
|
result.error=kind;return result;
|
|
1008
1166
|
}
|
|
1009
|
-
if(Date.now()>deadline){
|
|
1167
|
+
if(Date.now()>deadline&&typeof session.readResponseMeasurement!=='function'){
|
|
1010
1168
|
blockers.push(issue('blocker','interaction-timeout',target.componentId,'Produce immediate state or visual feedback within 150 ms of pointer input.',{viewport,detail:'The primary pointer action completed after the 150 ms response budget.',metrics:{limitMs:INTERACTION_LIMIT_MS}}));
|
|
1011
1169
|
result.error='interaction-timeout';return result;
|
|
1012
1170
|
}
|
|
@@ -1014,8 +1172,10 @@ async function interact(session,viewport,target,openingState,blockers){
|
|
|
1014
1172
|
while(true){
|
|
1015
1173
|
const afterState=await session.getState(),stateDelta=stateChanged(beforeState,afterState);
|
|
1016
1174
|
if(stateDelta){
|
|
1017
|
-
|
|
1018
|
-
|
|
1175
|
+
const browserMs=await session.readResponseMeasurement?.();
|
|
1176
|
+
const onTime=Number.isFinite(browserMs)?browserMs<=INTERACTION_LIMIT_MS:Date.now()<=deadline;
|
|
1177
|
+
if(onTime){result.within150Ms=true;result.deltaType='state';return result;}
|
|
1178
|
+
blockers.push(issue('blocker','interaction-timeout',target.componentId,'Produce immediate state or visual feedback within 150 ms of pointer input.',{viewport,detail:'The first observable response arrived after the 150 ms response budget.',metrics:{limitMs:INTERACTION_LIMIT_MS,...(Number.isFinite(browserMs)?{browserMs:Math.round(browserMs)}:{})}}));
|
|
1019
1179
|
result.error='interaction-timeout';return result;
|
|
1020
1180
|
}
|
|
1021
1181
|
const screenshotDelta=hash(await session.screenshot())!==beforeScreenshot;
|
|
@@ -1042,7 +1202,7 @@ export async function runBrowserQa(options={}){
|
|
|
1042
1202
|
if(!outputDir)throw Error('A deterministic output directory is required');
|
|
1043
1203
|
if(!htmlPath&&typeof options.html!=='string'&&typeof options.htmlString!=='string')throw Error('Supply an HTML artifact path or HTML string');
|
|
1044
1204
|
const html=typeof options.html==='string'?options.html:typeof options.htmlString==='string'?options.htmlString:await readFile(htmlPath,'utf8');
|
|
1045
|
-
const project=options.project??projectFromHtml(html),blockers=[],warnings=[],interactions=[],states=[],screenshots=[];
|
|
1205
|
+
const project=options.project??projectFromHtml(html),blockers=[],warnings=[],interactions=[],states=[],screenshots=[],storeChecks={};
|
|
1046
1206
|
let contactSheets=[],motionFilmstrips=[],video=null;
|
|
1047
1207
|
const screenshotDir=resolve(outputDir,'screenshots');await mkdir(screenshotDir,{recursive:true});
|
|
1048
1208
|
const staleCleanup=[
|
|
@@ -1078,12 +1238,23 @@ export async function runBrowserQa(options={}){
|
|
|
1078
1238
|
}
|
|
1079
1239
|
addLayoutReport(result,viewport,state,blockers,warnings);
|
|
1080
1240
|
};
|
|
1241
|
+
const checkStore=async(targetSession,state)=>{
|
|
1242
|
+
const result=await targetSession.verifyStore();
|
|
1243
|
+
storeChecks[state]=result;
|
|
1244
|
+
if(result.ok)return;
|
|
1245
|
+
blockers.push(issue('blocker',result.reason,result.componentId??null,
|
|
1246
|
+
'Make the visible Store CTA open the configured destination through one deliberate tap.',
|
|
1247
|
+
{viewport:DEFAULT_VIEWPORTS[1],metrics:{state}}));
|
|
1248
|
+
};
|
|
1081
1249
|
try{
|
|
1082
1250
|
const useAutoEndCard=!stateHook&&options.autoEndCard!==false&&!browserAdapter&&typeof session.enterEndCard==='function';
|
|
1083
1251
|
for(const viewport of DEFAULT_VIEWPORTS){
|
|
1084
1252
|
await session.setViewport(viewport);await session.load();
|
|
1085
1253
|
await capture(viewport,'opening');states.push({viewport:normalizeViewport(viewport),state:'opening',status:'checked'});await audit(viewport,'opening');
|
|
1086
1254
|
const openingState=await session.getState(),target=await session.getPrimaryTarget();
|
|
1255
|
+
if((openingState?.model3d?.textureErrors??0)>0){
|
|
1256
|
+
blockers.push(issue('blocker','model-texture-decode-failed',null,'Re-export or re-optimize the 3D GLB asset with valid PNG/JPEG embedded textures.',{viewport,detail:`${openingState.model3d.textureErrors} embedded GLB texture(s) failed to decode at runtime.`,metrics:{textureErrors:openingState.model3d.textureErrors}}));
|
|
1257
|
+
}
|
|
1087
1258
|
if(!target){
|
|
1088
1259
|
blockers.push(issue('blocker','primary-interaction-missing',primaryComponentId??null,'Declare a click event on an enabled component in the start scene and bind meaningful feedback to it.',{viewport,detail:'No generic primary target could be derived from project click events.'}));
|
|
1089
1260
|
states.push({viewport:normalizeViewport(viewport),state:'after-first-input',status:'unavailable',reason:'primary-interaction-missing'});
|
|
@@ -1105,7 +1276,7 @@ export async function runBrowserQa(options={}){
|
|
|
1105
1276
|
blockers.push(issue('blocker','state-hook-failed',null,'Repair the supplied generic state hook or declare the state unavailable.',{viewport,detail:`${state}: ${error.message}`,metrics:{state}}));continue;
|
|
1106
1277
|
}
|
|
1107
1278
|
if(!available){states.push({viewport:normalizeViewport(viewport),state,status:'unavailable',reason:'state-hook-unsupported'});continue;}
|
|
1108
|
-
states.push({viewport:normalizeViewport(viewport),state,status:'checked'});await capture(viewport,state);await audit(viewport,state);
|
|
1279
|
+
states.push({viewport:normalizeViewport(viewport),state,status:'checked',mode:'state-hook'});await capture(viewport,state);await audit(viewport,state);
|
|
1109
1280
|
}
|
|
1110
1281
|
}
|
|
1111
1282
|
if(useAutoEndCard){
|
|
@@ -1119,7 +1290,11 @@ export async function runBrowserQa(options={}){
|
|
|
1119
1290
|
discovered=null;
|
|
1120
1291
|
}
|
|
1121
1292
|
if(discovered&&!discovered.available){
|
|
1122
|
-
|
|
1293
|
+
const reason=discovered.required?'end-card-unreachable':'end-card-not-declared';
|
|
1294
|
+
for(const viewport of DEFAULT_VIEWPORTS)states.push({viewport:normalizeViewport(viewport),state:'end-card',status:'unavailable',reason});
|
|
1295
|
+
if(discovered.required)blockers.push(issue('blocker',reason,null,
|
|
1296
|
+
'Make the winning action reach the end card in the packaged playable. Start any reveal delay on the winning action.',
|
|
1297
|
+
{viewport:DEFAULT_VIEWPORTS[1],metrics:{state:'end-card'}}));
|
|
1123
1298
|
}else if(discovered?.available){
|
|
1124
1299
|
if(wantFilmstrip&&discovered.mode==='real-play'&&typeof session.captureMotionFilmstrip==='function'){
|
|
1125
1300
|
try{
|
|
@@ -1134,6 +1309,8 @@ export async function runBrowserQa(options={}){
|
|
|
1134
1309
|
states.push({viewport:normalizeViewport(viewport),state:'end-card',status:'checked',mode:discovered.mode});
|
|
1135
1310
|
await capture(viewport,'end-card');await audit(viewport,'end-card');
|
|
1136
1311
|
}
|
|
1312
|
+
await session.setViewport(DEFAULT_VIEWPORTS[1]);
|
|
1313
|
+
await checkStore(session,'end-card');
|
|
1137
1314
|
}
|
|
1138
1315
|
if(typeof session.enterTimeout==='function'){
|
|
1139
1316
|
await session.setViewport(DEFAULT_VIEWPORTS[1]);await session.load();
|
|
@@ -1146,7 +1323,11 @@ export async function runBrowserQa(options={}){
|
|
|
1146
1323
|
timedOut=null;
|
|
1147
1324
|
}
|
|
1148
1325
|
if(timedOut&&!timedOut.available){
|
|
1149
|
-
|
|
1326
|
+
const reason=timedOut.required?'timeout-unreachable':'timeout-not-declared';
|
|
1327
|
+
for(const viewport of DEFAULT_VIEWPORTS)states.push({viewport:normalizeViewport(viewport),state:'timeout',status:'unavailable',reason});
|
|
1328
|
+
if(timedOut.required)blockers.push(issue('blocker',reason,null,
|
|
1329
|
+
'Make the gameplay deadline reach a timeout card in the packaged playable.',
|
|
1330
|
+
{viewport:DEFAULT_VIEWPORTS[1],metrics:{state:'timeout'}}));
|
|
1150
1331
|
}else if(timedOut?.available){
|
|
1151
1332
|
const targetSession=timedOut.auditLayout?timedOut:session;
|
|
1152
1333
|
try{
|
|
@@ -1162,6 +1343,8 @@ export async function runBrowserQa(options={}){
|
|
|
1162
1343
|
const res=await targetSession.auditLayout({ids:[...active],interactiveIds:[...new Set([...(project?.events??[]).filter(e=>e.kind==='click'&&active.has(e.componentId)).map(e=>e.componentId),...(project?.gameplay??[]).filter(behavior=>['aim-launch','drag','swipe-input','hold-charge','virtual-joystick','draw-stroke','erase-mask'].includes(behavior.kind)&&active.has(behavior.componentId)).map(behavior=>behavior.componentId)])],network,minTouchPx:MIN_TOUCH_PX});
|
|
1163
1344
|
addLayoutReport(res,viewport,'timeout',blockers,warnings);
|
|
1164
1345
|
}
|
|
1346
|
+
await targetSession.setViewport(DEFAULT_VIEWPORTS[1]);
|
|
1347
|
+
await checkStore(targetSession,'timeout');
|
|
1165
1348
|
}finally{await timedOut.close?.();}
|
|
1166
1349
|
}
|
|
1167
1350
|
}
|
|
@@ -1197,7 +1380,7 @@ export async function runBrowserQa(options={}){
|
|
|
1197
1380
|
}
|
|
1198
1381
|
}
|
|
1199
1382
|
}finally{await session.close?.();}
|
|
1200
|
-
const report=formatCreativeQaReport({scope:'browser',blockers,warnings,interactions,states,screenshots,contactSheets,motionFilmstrips,video,checks:{viewports:DEFAULT_VIEWPORTS,browserContexts:wantVideo?2:1,primaryInteraction:'project-click-events',interactionLimitMs:INTERACTION_LIMIT_MS,minTouchPx:MIN_TOUCH_PX,stateHook:stateHook?typeof stateHook:'not-supplied'}});
|
|
1383
|
+
const report=formatCreativeQaReport({scope:'browser',blockers,warnings,interactions,states,screenshots,contactSheets,motionFilmstrips,video,checks:{viewports:DEFAULT_VIEWPORTS,browserContexts:wantVideo?2:1,primaryInteraction:'project-click-events',storeCta:storeChecks,interactionLimitMs:INTERACTION_LIMIT_MS,minTouchPx:MIN_TOUCH_PX,stateHook:stateHook?typeof stateHook:'not-supplied'}});
|
|
1201
1384
|
await writeCreativeQaReport(report,outputDir);return report;
|
|
1202
1385
|
}
|
|
1203
1386
|
export const runBrowserAudit=runBrowserQa;
|