Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(playable): bind preview records to delivery hashes

yhh85450026adbd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66dab1f89..e49188443 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Playable preview records identify the delivered archive.** Full export reports verify the adjacent ZIP hash before previewing, catching config changes even when HTML stays identical. Downloaded logs retain HTML/delivery hashes and explicitly disclose omitted events; HTML-only previews remain labeled accordingly.
+
- **World transforms preserve mirrored axes.** Quaternion decomposition retains signed scale instead of converting reflected bases into invalid rotations. Planar transforms keep a Z rotation, including collapsed axes; mirrored UI pointer bounds and flat render bounds follow their displayed geometry.
diff --git a/docs/astro/src/content/docs/publishing/overview.mdx b/docs/astro/src/content/docs/publishing/overview.mdx
index 77fbb8be2..d8fdbb77f 100644
--- a/docs/astro/src/content/docs/publishing/overview.mdx
+++ b/docs/astro/src/content/docs/publishing/overview.mdx
@@ -130,6 +130,8 @@ Use `pnpm preview:playable path/to/index.html --report export-result.json` from
The required host SDK check verifies literal script tags and their placement. Google Exit API belongs in head; TikTok/Pangle must load before game scripts in body. Missing scripts, incorrect positions and delayed TikTok/Pangle SDK loading fail this static check. Actual SDK availability and CTA behavior remain runtime checks.
+With a full export result, preview also checks the adjacent ZIP’s delivery hash; changing config while keeping identical HTML still invalidates the old report. Saved logs carry both hashes and the archive filename. Without delivery evidence they identify HTML only. A visible notice and log field disclose when older events were omitted from the 1,000-entry history.
+
### A network we don't ship
Define it yourself — the built-in networks are written against this exact contract,
diff --git a/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx b/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx
index 7139b12e3..aba9d326e 100644
--- a/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx
+++ b/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx
@@ -114,6 +114,8 @@ MRAID 安装按钮须通过 `playableCta(storeUrl)` 传入目标地址,或由
必需宿主 SDK 检查会核对真实的 script 标签及其位置:Google Exit API 位于 head,TikTok/Pangle 位于 body 且在游戏脚本之前。缺少脚本、位置错误或 TikTok/Pangle SDK 延迟加载都会使静态检查失败。真实 SDK 是否可用及 CTA 行为仍需运行验证。
+提供完整导出结果时,预览还会核对同目录 ZIP 的交付哈希;只改配置而 HTML 不变,也会使旧报告失效。保存的日志记录两种哈希和文件名;缺少交付证据时明确标为仅关联 HTML。事件历史最多保留 1,000 条,界面和日志会说明省略了多少早期记录。
+
### 我们没内置的平台
自己定义就行——内置的那几家写的就是这份契约,没有做不到的事。**打包项目 → 新建平台** 可以
diff --git a/examples/playable-ad/README.md b/examples/playable-ad/README.md
index faadbf5a3..18c329323 100644
--- a/examples/playable-ad/README.md
+++ b/examples/playable-ad/README.md
@@ -81,3 +81,10 @@ The `google` and `meta` named profiles export the same scene for the existing
networks. Mandatory SDK checks now verify both presence and placement: Google
Exit API in head, TikTok/Pangle before game scripts in body. SDK addresses merely
appearing in an allowlist or in JavaScript text do not satisfy this check.
+
+When a full export result is supplied, the preview also verifies the actual ZIP
+beside the HTML against its delivery SHA256. Relocated exports use the archive
+filename, not the old absolute output path. A changed archive is rejected even
+when index.html stayed identical. Saved logs include both hashes and the delivery
+filename; HTML-only previews are labeled as such. Event history retains the last
+1,000 entries and displays/saves the count of omitted earlier events.
diff --git a/tools/playable-preview.mjs b/tools/playable-preview.mjs
index b08785d14..b3b6b6102 100644
--- a/tools/playable-preview.mjs
+++ b/tools/playable-preview.mjs
@@ -82,35 +82,49 @@ button,input,select{font:inherit;border:1px solid #61718a;border-radius:6px;padd
<button data-command="ready">Ready / 准备</button><button data-command="show">Show / 显示</button><button data-command="hide">Hide / 隐藏</button>
<label>Viewport / 视口 <select id="viewport"><option value="360,640">360 × 640</option><option value="800,400">800 × 400</option></select></label>
<input id="store-url" aria-label="Store URL" placeholder="MRAID store URL / 商店地址"><button id="reload">Reload / 重载</button><button id="save">Save log / 保存记录</button></div>
-<div class="layout"><iframe id="creative" title="Playable creative" width="360" height="640"></iframe><section class="events"><h2>Host events / 宿主事件</h2><ol id="events"></ol></section></div></main>
+<div class="layout"><iframe id="creative" title="Playable creative" width="360" height="640"></iframe><section class="events"><h2>Host events / 宿主事件</h2><p id="truncated-log" class="note" aria-live="polite" hidden></p><ol id="events"></ol></section></div></main>
<script>
const config=${safeJson(config)},source='estella-playable-preview',frame=document.getElementById('creative'),events=[];
-window.previewEvents=events;document.getElementById('identity').textContent=config.network+' · HTML SHA256 '+config.htmlSha256;
+let truncatedEvents=0;
+window.previewEvents=events;document.getElementById('identity').textContent=config.network+' · HTML SHA256 '+config.htmlSha256+(config.deliverySha256?' · Delivery SHA256 '+config.deliverySha256:' · HTML-only identity');
document.getElementById('store-url').value=config.storeUrl||'';
const load=()=>{frame.src='/creative?store='+encodeURIComponent(document.getElementById('store-url').value);};
document.querySelectorAll('[data-command]').forEach(button=>button.onclick=()=>frame.contentWindow.postMessage({source,type:'command',command:button.dataset.command},location.origin));
document.getElementById('reload').onclick=load;
document.getElementById('viewport').onchange=event=>{const [w,h]=event.target.value.split(',');frame.width=w;frame.height=h;};
window.addEventListener('message',event=>{if(event.source!==frame.contentWindow||event.origin!==location.origin||event.data?.source!==source||event.data.type!=='event')return;
-const record={...event.data,timeMs:Math.round(performance.now())};events.push(record);if(events.length>1000)events.shift();const item=document.createElement('li');item.textContent=record.name+' '+JSON.stringify(record.data)+(record.gesture?' [gesture]':'');document.getElementById('events').append(item);if(document.getElementById('events').children.length>1000)document.getElementById('events').firstChild.remove();});
-document.getElementById('save').onclick=()=>{const blob=new Blob([JSON.stringify({mode:'local-mock',network:config.network,htmlSha256:config.htmlSha256,events},null,2)],{type:'application/json'});const url=URL.createObjectURL(blob);const link=document.createElement('a');link.href=url;link.download='playable-preview-log.json';link.click();setTimeout(()=>URL.revokeObjectURL(url),1000);};load();
+const record={...event.data,timeMs:Math.round(performance.now())};events.push(record);if(events.length>1000){events.shift();truncatedEvents++;const notice=document.getElementById('truncated-log');notice.hidden=false;notice.textContent=truncatedEvents+' earlier events omitted / 已省略 '+truncatedEvents+' 条早期记录';}const item=document.createElement('li');item.textContent=record.name+' '+JSON.stringify(record.data)+(record.gesture?' [gesture]':'');document.getElementById('events').append(item);if(document.getElementById('events').children.length>1000)document.getElementById('events').firstChild.remove();});
+document.getElementById('save').onclick=()=>{const blob=new Blob([JSON.stringify({mode:'local-mock',identityScope:config.deliverySha256?'delivery':'html-only',network:config.network,htmlSha256:config.htmlSha256,deliverySha256:config.deliverySha256,deliveryFile:config.deliveryFile,truncatedEvents,events},null,2)],{type:'application/json'});const url=URL.createObjectURL(blob);const link=document.createElement('a');link.href=url;link.download='playable-preview-log.json';link.click();setTimeout(()=>URL.revokeObjectURL(url),1000);};load();
</script></body></html>`;
}
export async function createPlayablePreview({ htmlFile, network, storeUrl = '', reportFile, port = 0 }) {
const html = await readFile(htmlFile);
const htmlSha256 = createHash('sha256').update(html).digest('hex');
+ let deliverySha256, deliveryFile;
if (reportFile) {
const result = JSON.parse(await readFile(reportFile, 'utf8'));
const report = result.playableCheck ?? result;
if (report.htmlSha256 !== htmlSha256) throw new Error('The report does not describe this HTML file. Export it again.');
if (network && network !== report.network) throw new Error('The selected network differs from the export report.');
network = report.network;
+ if (report.deliverySha256) {
+ let delivery = html;
+ deliveryFile = path.basename(htmlFile);
+ if (result.zipFile) {
+ if (typeof result.zipFile !== 'string') throw new Error('The export result ZIP filename must be a string.');
+ deliveryFile = path.basename(result.zipFile);
+ if (!/^[A-Za-z0-9_]+\.zip$/.test(deliveryFile) || /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])\.zip$/i.test(deliveryFile)) throw new Error('The report needs a portable ZIP filename.');
+ delivery = await readFile(path.join(path.dirname(path.resolve(htmlFile)), deliveryFile));
+ } else if (report.deliverySha256 !== htmlSha256) throw new Error('ZIP identity needs the full export result with zipFile, beside its HTML.');
+ deliverySha256 = createHash('sha256').update(delivery).digest('hex');
+ if (deliverySha256 !== report.deliverySha256) throw new Error('The delivered file differs from its export report. Export it again.');
+ }
}
if (!NETWORKS.includes(network)) throw new Error(`Choose --network ${NETWORKS.join('|')} or supply --report export-result.json.`);
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error('Port must be an integer from 0 to 65535.');
if (!/<head\b[^>]*>/i.test(html.toString('utf8'))) throw new Error('The creative needs an explicit HTML head.');
- const config = { network, storeUrl, htmlSha256 };
+ const config = { network, storeUrl, htmlSha256, deliverySha256, deliveryFile };
const server = createServer((request, response) => {
const url = new URL(request.url, 'http://127.0.0.1');
response.setHeader('Cache-Control', 'no-store');
@@ -130,7 +144,7 @@ export async function createPlayablePreview({ htmlFile, network, storeUrl = '',
else { response.writeHead(404); response.end('Not found'); }
});
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(port, '127.0.0.1', resolve); });
- return { server, url: `http://127.0.0.1:${server.address().port}/`, htmlSha256,
+ return { server, url: `http://127.0.0.1:${server.address().port}/`, htmlSha256, deliverySha256,
close: () => new Promise(resolve => { server.close(resolve); server.closeAllConnections?.(); }) };
}
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index ee53f77be..b7c603c7e 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(playable): bind preview records to delivery hashes':
+ { note: 'Playable preview records identify the delivered archive.' },
'fix(transform): preserve reflected world transforms and UI bounds':
{ note: 'World transforms preserve mirrored axes.' },
diff --git a/tools/tests/playable-preview.test.ts b/tools/tests/playable-preview.test.ts
index 3adc68309..140453847 100644
--- a/tools/tests/playable-preview.test.ts
+++ b/tools/tests/playable-preview.test.ts
@@ -5,6 +5,8 @@ import { mkdtemp, writeFile, readFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { runInNewContext } from 'node:vm';
+import { createHash } from 'node:crypto';
+import { makeZip } from '../../build-tools/utils/zip.js';
import { createPlayablePreview } from '../playable-preview.mjs';
async function fixture(network: string, run: (preview: any, file: string) => Promise<void>) {
@@ -62,6 +64,37 @@ describe('local playable mock', () => {
});
});
+ it('binds records to the actual relocated ZIP and refuses changed config with unchanged HTML', async () => {
+ await fixture('pangle', async (initial, file) => {
+ const html = await readFile(file), root = path.dirname(file), zipFile = path.join(root, 'playable.zip');
+ const zip = (orientation: number) => makeZip([{ name: 'index.html', data: html },
+ { name: 'config.json', data: Buffer.from(JSON.stringify({ playable_orientation: orientation })) }]);
+ const original = zip(0), deliverySha256 = createHash('sha256').update(original).digest('hex');
+ await writeFile(zipFile, original);
+ const reportFile = path.join(root, 'report.json');
+ await writeFile(reportFile, JSON.stringify({ zipFile: '/previous/export/playable.zip',
+ playableCheck: { network: 'pangle', htmlSha256: initial.htmlSha256, deliverySha256 } }));
+ const preview = await createPlayablePreview({ htmlFile: file, reportFile });
+ try {
+ expect(preview.deliverySha256).toBe(deliverySha256);
+ expect(await (await fetch(preview.url)).text()).toContain(deliverySha256);
+ expect(await readFile(zipFile)).toEqual(original);
+ } finally { await preview.close(); }
+ await writeFile(zipFile, zip(1));
+ expect(createHash('sha256').update(await readFile(file)).digest('hex')).toBe(initial.htmlSha256);
+ await expect(createPlayablePreview({ htmlFile: file, reportFile })).rejects.toThrow(/delivered file differs/);
+ });
+ });
+
+ it('refuses ZIP-only hashes without an archive filename and keeps HTML-only records explicit', async () => {
+ await fixture('mraid', async (initial, file) => {
+ const reportFile = path.join(path.dirname(file), 'report.json');
+ await writeFile(reportFile, JSON.stringify({ network: 'mraid', htmlSha256: initial.htmlSha256, deliverySha256: 'other' }));
+ await expect(createPlayablePreview({ htmlFile: file, reportFile })).rejects.toThrow(/full export result/);
+ expect(await (await fetch(initial.url)).text()).toContain('HTML-only identity');
+ });
+ });
+
it('emits genuine mock callbacks and ignores commands from an unrelated frame', async () => {
await fixture('mraid', async preview => {
const creative = await (await fetch(preview.url + 'creative?store=https%3A%2F%2Fexample.com%2Fstore')).text();