Files
workinf_Blender_Wasm/web/tests/fixtures/upstream-autosave-case.ts
mes123456 f3e21c6b98
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
chore: checkpoint web Blender migration source, tools and docs
Accumulated uncommitted work: GHOST Web backend, WebGL/GPU web layer,
web workflow engine and protocol, tooling, docs and task records.
Large generated evidence, user-testing archives, build snapshots and
imported test assets remain untracked.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-10 11:18:01 +08:00

33 lines
3.0 KiB
TypeScript

import fs from 'node:fs';
import path from 'node:path';
import { createHash } from 'node:crypto';
import type { Page, TestInfo } from '@playwright/test';
import { queryNativeJSON } from './native-modeling-workflow';
const root = path.resolve(import.meta.dirname, '../../..');
export async function stageOriginalAutosaveCase(page: Page, info: TestInfo) {
const catalog = JSON.parse(fs.readFileSync(path.join(root, 'tests/golden/WBV2-P1424-001/source-cases-20261028/file-workflow-cases.json'), 'utf8'));
const entry = catalog.cases.find((item: { sourceCaseId: string }) => item.sourceCaseId === 'upstream.blendfile_autosave'); if (!entry) throw new Error('Original autosave case binding missing');
const index = JSON.parse(fs.readFileSync(path.resolve(root, catalog.assetIdentityIndex), 'utf8'));
const caseDir = `/tmp/wbv2-source/${createHash('sha256').update(`${process.env.WBV2_CASE_ATTEMPT ?? ''}:${info.outputPath('autosave-case')}`).digest('hex').slice(0, 24)}`;
const sourceHashes: Record<string, string> = {};
const assetHashes: Record<string, string> = {};
const writeBytes = async (relative: string, bytes: Buffer) => {
const destination = path.posix.join(caseDir, relative);
for (let offset = 0; offset < bytes.length; offset += 65536) {
const chunk = bytes.subarray(offset, offset + 65536);
const receipt = await queryNativeJSON(page, `import base64,json,os\np=${JSON.stringify(destination)}\nos.makedirs(os.path.dirname(p),exist_ok=True)\nwith open(p,${JSON.stringify(offset === 0 ? 'wb' : 'ab')}) as output:\n count=output.write(base64.b64decode(${JSON.stringify(chunk.toString('base64'))}))\nprint(json.dumps({'bytes':count}))`);
if ((receipt.value as { bytes: number }).bytes !== chunk.length) throw new Error(`Incomplete original case write: ${relative}`);
}
};
for (const name of ['bl_blendfile_utils.py', 'bl_blendfile_autosave.py']) {
const bytes = fs.readFileSync(path.join(root, path.dirname(entry.script), name));
sourceHashes[name] = createHash('sha256').update(bytes).digest('hex'); if (sourceHashes[name] !== entry.sourceHashes?.[name]) throw new Error(`Original autosave source identity mismatch: ${name}`); await writeBytes(name, bytes);
}
for (const relative of entry.assets as string[]) {
const expected = index.files.find((item: { path: string }) => item.path === relative);
const bytes = fs.readFileSync(path.resolve(root, catalog.assetRoot, relative)), digest = createHash('sha256').update(bytes).digest('hex');
if (!expected || bytes.length !== expected.bytes || digest !== expected.sha256) throw new Error(`Original autosave asset identity mismatch: ${relative}`);
assetHashes[relative] = digest; await writeBytes(`assets/${relative}`, bytes);
}
return { sourceCaseId: entry.sourceCaseId, caseDir, sourceHashes, assetHashes, writeCaseBytes: writeBytes, script: path.basename(entry.script), argv: entry.arguments.map((arg: string) => arg.replaceAll('{assets}', `${caseDir}/assets`).replaceAll('{output}', `${caseDir}/output`)) }; }