Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/experiments/pixel/pixel-tool.mjs
Original file line number Diff line number Diff line change
@@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion src/experiments/pixel/pixel.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="color-scheme" content="light dark"><link rel="icon" href="data:,">
<link rel="stylesheet" href="./style.css"><link rel="stylesheet" href="./pixel.css?v=first-letter-v1&amp;art=post-clerks-v2"><link rel="stylesheet" href="./pixel-recipient.css?v=recipient-1">
<link rel="stylesheet" href="./pixel-code.css?v=code-1">
<script type="module" src="./pixel.mjs?v=delivery-render-v1&amp;art=post-clerks-v2"></script><title>算法游乐场 · 像素邮局</title>
<script type="module" src="./pixel.mjs?v=pixel-engine-load-v1&amp;art=post-clerks-v2"></script><title>算法游乐场 · 像素邮局</title>
<link rel="stylesheet" href="./navigation.css?v=three-cat-brand-v1"><script type="module" src="./navigation.mjs?v=cats-in-scenes-v1"></script>
<link rel="stylesheet" href="./space-theme.css">
<link rel="stylesheet" href="./experiment-showcase.css?v=home-aligned-v1">
Expand Down
2 changes: 1 addition & 1 deletion src/experiments/pixel/pixel.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
22 changes: 22 additions & 0 deletions tests/delivery/pixel-engine-loading.test.mjs
Original file line number Diff line number Diff line change
@@ -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(', ')}`);
});
21 changes: 21 additions & 0 deletions tests/experiments/pixel/pixel-ui.test.mjs
Original file line number Diff line number Diff line change
@@ -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<count;i++){
for(let bit=0;bit<4&&!u.els.get('recipient-read').disabled;bit++)u.click('recipient-read');
Expand Down
Loading