Advance Blender 5.2 web parity through M12-03D
This commit is contained in:
70
web/tests/unit/asset-catalog-v2.test.mjs
Normal file
70
web/tests/unit/asset-catalog-v2.test.mjs
Normal file
@@ -0,0 +1,70 @@
|
||||
import assert from "node:assert/strict";
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import test from "node:test";
|
||||
import ts from "typescript";
|
||||
|
||||
const repoRoot = path.resolve(import.meta.dirname, "../../..");
|
||||
const sourcePath = path.join(repoRoot, "web/protocol/asset-catalog-v2.ts");
|
||||
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "asset-catalog-v2-unit-"));
|
||||
const result = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), {
|
||||
compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 },
|
||||
fileName: sourcePath,
|
||||
reportDiagnostics: true,
|
||||
});
|
||||
assert.deepEqual(result.diagnostics, []);
|
||||
fs.writeFileSync(path.join(temporary, "asset-catalog-v2.mjs"), result.outputText);
|
||||
const catalog = await import(pathToFileURL(path.join(temporary, "asset-catalog-v2.mjs")));
|
||||
const desktop = JSON.parse(fs.readFileSync(path.join(repoRoot, "tests/golden/M12-01B/canonical.json"), "utf8"));
|
||||
const golden = JSON.parse(fs.readFileSync(path.join(repoRoot, "tests/golden/M12-01C/asset-catalog-v2.json"), "utf8"));
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(repoRoot, "tests/golden/M12-01C/manifest.json"), "utf8"));
|
||||
|
||||
test("M12-01C binds the desktop and Blender weak-reference sources", () => {
|
||||
assert.equal(manifest.nextTask, "M12-01D");
|
||||
for (const artifact of Object.values(manifest.artifacts)) {
|
||||
const actual = crypto.createHash("sha256").update(fs.readFileSync(path.join(repoRoot, artifact.path))).digest("hex");
|
||||
assert.equal(actual, artifact.sha256, `${artifact.path} hash drifted`);
|
||||
}
|
||||
const weakReferenceSource = fs.readFileSync(path.join(repoRoot, manifest.artifacts.blenderWeakReferenceSource.path), "utf8");
|
||||
assert.match(weakReferenceSource, /AssetWeakReference AssetRepresentation::make_weak_reference\(\) const/);
|
||||
assert.match(weakReferenceSource, /library_relative_identifier\(\) const/);
|
||||
});
|
||||
|
||||
test("M12-01C converts the desktop catalog baseline into schema v2", async () => {
|
||||
const generated = await catalog.createAssetCatalogManifestV2FromDesktop(desktop, 1);
|
||||
assert.deepEqual(generated, golden);
|
||||
assert.deepEqual(generated.catalogs.map((item) => item.path), ["Characters", "Characters/Heroes", "Materials/Metal"]);
|
||||
assert.deepEqual(generated.assets.map((item) => item.relativeAssetIdentifier), [
|
||||
"Material/M12 Brushed Metal", "Object/M12 Hero", "World/M12 Uncataloged World",
|
||||
]);
|
||||
assert.equal(generated.assets[2].catalogId, null);
|
||||
assert.equal(generated.assets[0].author, "");
|
||||
assert.equal(generated.assets[0].sourceSha256, null);
|
||||
assert.deepEqual(generated.libraries, []);
|
||||
assert.equal(generated.assets[1].customProperties.find((item) => item.name === "dimensions").type, "FLOAT_ARRAY");
|
||||
});
|
||||
|
||||
test("M12-01C stable IDs bind Blender weak-reference identity", async () => {
|
||||
const local = await catalog.createAssetCatalogV2StableId({ assetLibraryIdentifier: null, relativeAssetIdentifier: "Object/M12 Hero" });
|
||||
const external = await catalog.createAssetCatalogV2StableId({ assetLibraryIdentifier: "Studio", relativeAssetIdentifier: "hero.blend/Object/M12 Hero" });
|
||||
assert.match(local, /^asset:[a-f0-9]{64}$/);
|
||||
assert.match(external, /^asset:[a-f0-9]{64}$/);
|
||||
assert.notEqual(local, external);
|
||||
assert.equal(local, golden.assets[1].assetId);
|
||||
assert.equal(local, await catalog.createAssetCatalogV2StableId({ assetLibraryIdentifier: null, relativeAssetIdentifier: "Object/M12 Hero" }));
|
||||
});
|
||||
|
||||
test("M12-01C exposes UTF-8 byte and collection budgets", async () => {
|
||||
assert.equal(catalog.ASSET_CATALOG_SCHEMA, 2);
|
||||
assert.equal(catalog.ASSET_CATALOG_V2_BUDGET.maxCatalogSimpleNameBytes, 63);
|
||||
assert.equal(catalog.ASSET_CATALOG_V2_BUDGET.maxTagBytes, 63);
|
||||
assert.equal(catalog.ASSET_CATALOG_V2_BUDGET.maxCatalogs, 10_000);
|
||||
assert.equal(catalog.ASSET_CATALOG_V2_BUDGET.maxAssets, 100_000);
|
||||
assert.deepEqual(catalog.ASSET_CATALOG_V2_ID_TYPES, ["ACTION", "COLLECTION", "IMAGE", "MATERIAL", "NODE_GROUP", "OBJECT", "WORLD"]);
|
||||
assert.deepEqual(await catalog.parseAssetCatalogManifestV2(golden), golden);
|
||||
});
|
||||
|
||||
test.after(() => fs.rmSync(temporary, { recursive: true, force: true }));
|
||||
Reference in New Issue
Block a user