feat(web): workbench Outliner matches the desktop Layout geometry
The desktop golden comes from Blender's own laid-out screen data (tools/web/measure-outliner-desktop.py, blender 5.2.0 LTS, factory Layout at 1920x1080): right column 339 px, Outliner area 339x189 under a 26 px header, 20 px rows, 14 px per-level indent (0.7 * UI_UNIT_X). The workbench derives the right width and the Outliner/timeline split from those ratios so it reproduces the area at the reference size and scales elsewhere. The headed suite grows outliner-metrics-web with +-1 px assertions, and the runner now materializes inline base64 attachments so the checker can compare the measured boxes against the golden. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,9 @@ import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const EXPECTED_CASES = ["outliner-tree-baseline-web", "outliner-tools-baseline-web", "outliner-mirror-baseline-web"];
|
||||
const EXPECTED_CASES = ["outliner-tree-baseline-web", "outliner-tools-baseline-web", "outliner-mirror-baseline-web", "outliner-metrics-web"];
|
||||
/* Desktop Layout geometry the metrics case must reproduce (batch 2: UI sizes). */
|
||||
const GEOMETRY_GOLDEN = path.join(REPO_ROOT, "tests/golden/OUTLINER-DESKTOP-METRICS/outliner-metrics.json");
|
||||
const errors = [];
|
||||
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
||||
|
||||
@@ -120,6 +122,36 @@ for (const item of cases) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The metrics case attaches its measured boxes; compare them with the desktop
|
||||
* golden the workbench layout is built from (±1 px at 1920x1080). */
|
||||
const geometryCase = cases.find((item) => item.caseId === "outliner-metrics-web");
|
||||
if (geometryCase) {
|
||||
const artifact = (geometryCase.artifacts ?? []).find((entry) => entry.name === "outliner-metrics-web");
|
||||
if (!artifact) errors.push("outliner-metrics-web attached no geometry artifact");
|
||||
else if (!fs.existsSync(GEOMETRY_GOLDEN)) errors.push(`desktop metrics golden is missing: ${GEOMETRY_GOLDEN}`);
|
||||
else {
|
||||
try {
|
||||
const body = JSON.parse(fs.readFileSync(path.resolve(reportDir, artifact.path ?? ""), "utf8"));
|
||||
const golden = JSON.parse(fs.readFileSync(GEOMETRY_GOLDEN, "utf8")).outliner;
|
||||
const near = (value, expected) => Number.isFinite(value) && Math.abs(value - expected) <= 1;
|
||||
const measured = body.measured ?? {};
|
||||
if (measured.viewport?.width !== 1920 || measured.viewport?.height !== 1080) errors.push(`outliner-metrics-web ran at ${JSON.stringify(measured.viewport)}, expected 1920x1080`);
|
||||
for (const [name, actual, expected] of [
|
||||
["outliner width", measured.outliner?.width, golden.width],
|
||||
["outliner height", measured.outliner?.height, golden.height],
|
||||
["outliner header height", measured.header?.height, golden.headerHeight],
|
||||
["indent per level", measured.indentPerLevel, golden.indentPerLevel],
|
||||
]) {
|
||||
if (!near(actual, expected)) errors.push(`outliner-metrics-web ${name} ${actual} is outside ±1 of desktop ${expected}`);
|
||||
}
|
||||
const heights = Array.isArray(measured.rowHeights) ? measured.rowHeights : [];
|
||||
if (heights.length === 0) errors.push("outliner-metrics-web measured no rows");
|
||||
for (const height of heights) if (!near(height, golden.rowHeight)) errors.push(`outliner-metrics-web row height ${height} is outside ±1 of desktop ${golden.rowHeight}`);
|
||||
}
|
||||
catch (error) { errors.push(`outliner-metrics-web artifact is unreadable: ${error.message}`); }
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
console.error(JSON.stringify({ status: "FAIL", errors }, null, 2));
|
||||
process.exit(1);
|
||||
|
||||
102
tools/web/measure-outliner-desktop.py
Normal file
102
tools/web/measure-outliner-desktop.py
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read the desktop Outliner geometry from Blender's own laid-out screen data.
|
||||
|
||||
blender --factory-startup --background \
|
||||
--python tools/web/measure-outliner-desktop.py -- --out <abs json>
|
||||
|
||||
The factory Layout screen is the reference the web workbench mirrors. The rects
|
||||
below come from the screen/region layout Blender itself produced (background mode
|
||||
lays the startup screen out at the factory window size), never from hand-typed
|
||||
numbers. Every value the web side must match is emitted verbatim:
|
||||
|
||||
* the OUTLINER area rect (the user asked for the same area size as desktop),
|
||||
* its HEADER region height,
|
||||
* the widget unit (`U.widget_unit`), which is the tree row height
|
||||
(`UI_UNIT_Y` in interface code) at the factory dpi/scale,
|
||||
* the per-level tree indent (0.7 * UI_UNIT_X, `UI_TREEVIEW_INDENT`).
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
def _take(flag: str):
|
||||
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||
if flag in argv:
|
||||
index = argv.index(flag)
|
||||
if index + 1 < len(argv):
|
||||
return argv[index + 1]
|
||||
return None
|
||||
|
||||
|
||||
OUT = _take("--out")
|
||||
if not OUT:
|
||||
raise SystemExit("measure-outliner-desktop: pass -- --out <absolute path>")
|
||||
|
||||
screen = bpy.data.screens.get("Layout")
|
||||
if screen is None:
|
||||
raise SystemExit("measure-outliner-desktop: the factory Layout screen is missing")
|
||||
|
||||
areas = []
|
||||
for area in screen.areas:
|
||||
areas.append({
|
||||
"type": area.type,
|
||||
"x": area.x,
|
||||
"y": area.y,
|
||||
"width": area.width,
|
||||
"height": area.height,
|
||||
"regions": [
|
||||
{"type": region.type, "x": region.x, "y": region.y,
|
||||
"width": region.width, "height": region.height}
|
||||
for region in area.regions
|
||||
],
|
||||
})
|
||||
|
||||
outliner = next((area for area in areas if area["type"] == "OUTLINER"), None)
|
||||
if outliner is None:
|
||||
raise SystemExit("measure-outliner-desktop: the Layout screen has no OUTLINER area")
|
||||
if outliner["width"] <= 0 or outliner["height"] <= 0:
|
||||
raise SystemExit(f"measure-outliner-desktop: the OUTLINER rect is empty: {outliner}")
|
||||
|
||||
header = next((region for region in outliner["regions"] if region["type"] == "HEADER"), None)
|
||||
if header is None or header["height"] <= 0:
|
||||
raise SystemExit(f"measure-outliner-desktop: the OUTLINER area has no laid-out HEADER: {outliner}")
|
||||
|
||||
# `U.widget_unit` = round(UI_UNIT_X * ui_scale * dpi / 72); UI_UNIT_X is 20 at
|
||||
# the factory scale. This is the value tree rows use as their height.
|
||||
prefs = bpy.context.preferences
|
||||
dpi = float(prefs.system.dpi)
|
||||
ui_scale = float(prefs.view.ui_scale)
|
||||
widget_unit = round(20.0 * ui_scale * dpi / 72.0)
|
||||
|
||||
metrics = {
|
||||
"schemaVersion": 1,
|
||||
"source": {
|
||||
"binary": bpy.app.binary_path,
|
||||
"version": bpy.app.version_string,
|
||||
"factoryStartup": True,
|
||||
"screen": "Layout",
|
||||
},
|
||||
"preferences": {"dpi": dpi, "uiScale": ui_scale, "widgetUnit": widget_unit},
|
||||
"contentExtent": {
|
||||
"width": max(area["x"] + area["width"] for area in areas),
|
||||
"height": max(area["y"] + area["height"] for area in areas),
|
||||
},
|
||||
"areas": areas,
|
||||
"outliner": {
|
||||
"x": outliner["x"],
|
||||
"y": outliner["y"],
|
||||
"width": outliner["width"],
|
||||
"height": outliner["height"],
|
||||
"headerHeight": header["height"],
|
||||
"rowHeight": widget_unit,
|
||||
"indentPerLevel": round(0.7 * widget_unit),
|
||||
},
|
||||
}
|
||||
|
||||
with open(OUT, "w", encoding="utf-8") as handle:
|
||||
json.dump(metrics, handle, indent=2, sort_keys=False)
|
||||
handle.write("\n")
|
||||
print(f"outliner-metrics -> {OUT} ({outliner['width']}x{outliner['height']}, "
|
||||
f"header {header['height']}, row {widget_unit})")
|
||||
@@ -34,6 +34,7 @@ const KNOWN_CASES = [
|
||||
{ id: "outliner-tree-baseline-web", title: /\[outliner-tree-baseline-web\]/ },
|
||||
{ id: "outliner-tools-baseline-web", title: /\[outliner-tools-baseline-web\]/ },
|
||||
{ id: "outliner-mirror-baseline-web", title: /\[outliner-mirror-baseline-web\]/ },
|
||||
{ id: "outliner-metrics-web", title: /\[outliner-metrics-web\]/ },
|
||||
];
|
||||
|
||||
function usage() {
|
||||
@@ -159,7 +160,7 @@ function flattenSuites(suites, file, output) {
|
||||
const title = spec.title;
|
||||
const tagged = /\[([a-z0-9][a-z0-9-]*)\]/.exec(title);
|
||||
const caseId = tagged ? tagged[1] : title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60);
|
||||
const attachments = (result?.attachments ?? []).map((attachment) => ({ name: attachment.name, path: attachment.path ?? null, contentType: attachment.contentType ?? null }));
|
||||
const attachments = (result?.attachments ?? []).map((attachment) => ({ name: attachment.name, path: attachment.path ?? null, body: attachment.body ?? null, contentType: attachment.contentType ?? null }));
|
||||
output.push({
|
||||
caseId,
|
||||
title,
|
||||
@@ -180,10 +181,18 @@ function copyArtifacts(cases) {
|
||||
fs.mkdirSync(target, { recursive: true });
|
||||
item.artifacts = [];
|
||||
for (const attachment of item.attachments) {
|
||||
if (!attachment.path || !fs.existsSync(attachment.path)) continue;
|
||||
const extension = path.extname(attachment.path) || (attachment.contentType === "image/png" ? ".png" : ".json");
|
||||
let source = attachment.path && fs.existsSync(attachment.path) ? attachment.path : null;
|
||||
/* Playwright only spills attachments to disk when they are large; a small
|
||||
* `testInfo.attach({ body })` payload stays inline as base64 in the JSON
|
||||
* report, so materialize it here or the receipt loses the evidence. */
|
||||
if (!source && attachment.body) {
|
||||
source = path.join(target, `${attachment.name}${attachment.contentType === "image/png" ? ".png" : attachment.contentType === "application/json" ? ".json" : ".txt"}`);
|
||||
fs.writeFileSync(source, Buffer.from(attachment.body, "base64"));
|
||||
}
|
||||
if (!source) continue;
|
||||
const extension = path.extname(source) || (attachment.contentType === "image/png" ? ".png" : ".json");
|
||||
const file = path.join(target, `${attachment.name}${extension}`);
|
||||
fs.copyFileSync(attachment.path, file);
|
||||
if (source !== file) fs.copyFileSync(source, file);
|
||||
item.artifacts.push({ name: attachment.name, kind: extension.replace(".", ""), path: path.relative(reportDir, file), sha256: sha256File(file), bytes: fs.statSync(file).size });
|
||||
}
|
||||
delete item.attachments;
|
||||
|
||||
Reference in New Issue
Block a user