diff --git a/src/experiments/pixel/pixel-tool.mjs b/src/experiments/pixel/pixel-tool.mjs index 22ff034..3dc2bd0 100644 --- a/src/experiments/pixel/pixel-tool.mjs +++ b/src/experiments/pixel/pixel-tool.mjs @@ -1,4 +1,4 @@ -import {encode,preset,EDITOR_POSTCARD_PRESETS} from './pixel-core.mjs?v=studio-postcards-v2'; +import {encode,preset,EDITOR_POSTCARD_PRESETS} from './pixel-core.mjs?v=recipient-1'; import {createDelivery,deliveryAt} from './pixel-delivery.mjs?v=delivery-1'; const LEGACY_PRESETS=['chouchou','cat']; diff --git a/src/experiments/pixel/pixel.html b/src/experiments/pixel/pixel.html index 598bb15..0cc9ca0 100644 --- a/src/experiments/pixel/pixel.html +++ b/src/experiments/pixel/pixel.html @@ -5,7 +5,7 @@ - 算法游乐场 · 像素邮局 + 算法游乐场 · 像素邮局 diff --git a/src/experiments/pixel/pixel.mjs b/src/experiments/pixel/pixel.mjs index 20de92e..cd59bcf 100644 --- a/src/experiments/pixel/pixel.mjs +++ b/src/experiments/pixel/pixel.mjs @@ -1,4 +1,4 @@ -import { encode, decode, preset, stroke, rearrangement, POSTCARD_COLORS, EDITOR_POSTCARD_PRESETS, STUDIO_POSTCARD_NAMES, POSTAGE_BYTE_STEPS, postageByteTrial } from './pixel-core.mjs?v=cat-postage-byte-v1'; +import { encode, decode, preset, stroke, rearrangement, POSTCARD_COLORS, EDITOR_POSTCARD_PRESETS, STUDIO_POSTCARD_NAMES, POSTAGE_BYTE_STEPS, postageByteTrial } from './pixel-core.mjs?v=recipient-1'; import { setupRecipient } from './pixel-recipient-ui.mjs?v=recipient-resume-v1'; import { setupCodeLesson } from './pixel-code-ui.mjs?v=code-1'; import { createDelivery, deliveryAt } from './pixel-delivery.mjs?v=delivery-1'; diff --git a/tests/delivery/pixel-engine-loading.test.mjs b/tests/delivery/pixel-engine-loading.test.mjs new file mode 100644 index 0000000..227e738 --- /dev/null +++ b/tests/delivery/pixel-engine-loading.test.mjs @@ -0,0 +1,22 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {execFileSync} from 'node:child_process'; + +test('the public learning API shares one codec between pixel replay and delivery',()=>{ + const entry=new URL('../../dist/learning-tool.mjs',import.meta.url).href; + const output=execFileSync(process.execPath,['--input-type=module','-e',` + import {registerHooks} from 'node:module'; + registerHooks({load(url,context,next){ + const result=next(url,context); + if(new URL(url).pathname.endsWith('/pixel-core.mjs'))console.log(JSON.stringify(url)); + return result; + }}); + const {runLearningTool,replayLearningReceipt}=await import(${JSON.stringify(entry)}); + const receipt=runLearningTool({experimentId:'pixel-decode',preset:'bobby',mode:'slow-replay',actions:[{action:'read',value:1}]}); + const saved=JSON.stringify(receipt); + runLearningTool({experimentId:'pixel-decode',preset:'noise',actions:[{action:'read',value:528}]}); + if(JSON.stringify(receipt)!==saved||!replayLearningReceipt(receipt).matches)throw Error('Shared codec changed earlier pixel evidence'); + `],{encoding:'utf8'}); + const loaded=output.trim().split('\n').filter(Boolean).map(line=>JSON.parse(line)); + assert.equal(loaded.length,1,`expected one actual codec load, got ${loaded.join(', ')}`); +}); diff --git a/tests/experiments/pixel/pixel-ui.test.mjs b/tests/experiments/pixel/pixel-ui.test.mjs index cf8701a..e21b4f0 100644 --- a/tests/experiments/pixel/pixel-ui.test.mjs +++ b/tests/experiments/pixel/pixel-ui.test.mjs @@ -1,10 +1,31 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; +import { registerHooks } from 'node:module'; import { memoryStorage } from '../../helpers/storage-helper.mjs'; import { DRAFT_KEYS } from '../../../dist/local-drafts.mjs'; import { preset } from '../../../dist/pixel-core.mjs'; let serial = 0; +// Keep the cold-load check before the UI scenarios: the module cache is shared +// within this test file, while Node runs each test file in its own process. +test('the postcard editor loads one codec across drawing, lessons, delivery and AI replay',async()=>{ + const loaded=[]; + const hook=registerHooks({load(url,context,next){ + const result=next(url,context); + if(new URL(url).pathname.endsWith('/pixel-core.mjs'))loaded.push(url); + return result; + }}); + let u; + try{ + u=await boot({reduced:true}); + assert.equal(loaded.length,1,`expected one actual codec load, got ${loaded.join(', ')}`); + u.click('preset-bobby');u.click('send'); + assert.match(u.els.get('receipt').textContent,/256 \/ 256/); + u.click('delivery-replay');u.click('pixel-ai-generate'); + const receipt=JSON.parse(u.els.get('pixel-ai-text').value); + assert.equal(receipt.fixture.id,'pixel-bobby-v1'); + }finally{u?.restore();hook.deregister();} +}); function restoreRecipientCells(u, count) { for(let i=0;i