- Properties gates the rest-edit forms (add bone, per-bone rest form, bone operations) to Edit mode and the pose readback form to Pose mode; Object mode shows a read-only summary with 进入编辑模式 / 进入姿态模式 buttons. The workbench root carries data-armature-mode for assertions. - Ctrl+Tab on an armature object toggles Pose/Object; Tab still enters Edit. - armature-ui-readback-web waits for the native object.mode_set to report 模式:Pose/模式:Object before pressing shortcuts, matching the app's pending guard that ignores keys during a mode change. - armature-editor-coverage-ui-production enters Edit mode before the rest-edit operations. The coverage spec still cannot run as written: the app worker already holds the web-blender:native-files lock, so the spec's own WebEngineClient fails with WASM_INIT_FAILED. Pre-existing on this branch (also fails with the previous App.tsx); tracked separately from this change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
464 lines
26 KiB
TypeScript
464 lines
26 KiB
TypeScript
import crypto from 'node:crypto';
|
||
import path from 'node:path';
|
||
import { expect, test, type Page, type TestInfo } from '@playwright/test';
|
||
import { applyEngineCommand, installEngineBridge, matrixDistance, openBlendReplyCount, snapshotFacts, writeEvidence, type SnapshotFacts } from '../fixtures/armature-robot-workflow';
|
||
import { productErrors as sharedProductErrors } from '../fixtures/runtime-console';
|
||
|
||
/* Engine-level armature cases: the fixture is opened through the product file
|
||
* input, every edit is a web-engine command the app itself would send, and
|
||
* every assertion reads the result back from the engine snapshot. */
|
||
const REPO_ROOT = path.resolve(import.meta.dirname, '../../..');
|
||
const CANDIDATE = path.resolve(process.env.WBV2_PRODUCTION_CANDIDATE ?? path.join(REPO_ROOT, 'web/dist'));
|
||
const FIXTURE = path.join(REPO_ROOT, 'tests/files/web/pose_constraint_scene.blend');
|
||
const ARMATURE = 'PoseConstraintArmatureObject';
|
||
const TARGET = 'PoseConstraintTarget';
|
||
const CHAIN = [
|
||
{ name: 'Root', parentName: null, head: [0, 0, 0], tail: [0, 1, 0], roll: 0, connected: false },
|
||
{ name: 'Child', parentName: 'Root', head: [0, 1, 0], tail: [0, 2, 0], roll: 0, connected: true },
|
||
];
|
||
const POSE = [0.4, 0, 0.3];
|
||
|
||
const productConsole = (errors: string[]) => sharedProductErrors(errors);
|
||
const sha = (values: number[] | null | undefined) => (values ?? []).join(',');
|
||
|
||
function consoleCollector(page: Page) {
|
||
const errors: string[] = [];
|
||
page.on('console', (message) => { if (message.type() === 'error') errors.push(message.text()); });
|
||
page.on('pageerror', (error) => errors.push(error.message));
|
||
return errors;
|
||
}
|
||
|
||
async function attachEvidence(testInfo: TestInfo, caseId: string, payload: Record<string, unknown>) {
|
||
const file = writeEvidence(caseId, payload);
|
||
await testInfo.attach('armature-engine-evidence', { path: file, contentType: 'application/json' });
|
||
return file;
|
||
}
|
||
|
||
async function openFixture(page: Page): Promise<SnapshotFacts> {
|
||
await page.goto('/?ui=web');
|
||
await page.getByTestId('blend-file-input').setInputFiles(FIXTURE);
|
||
/* A restored OPFS project gates the open behind the unsaved-changes prompt. */
|
||
const discard = page.getByRole('dialog', { name: '保存当前工程的修改?' }).getByRole('button', { name: '不保存,继续', exact: true });
|
||
for (let attempt = 0; attempt < 25; attempt++) {
|
||
if (await discard.isVisible().catch(() => false)) { await discard.click(); break; }
|
||
await page.waitForTimeout(200);
|
||
}
|
||
await expect(page.getByTestId('engine-status')).toContainText(/SceneIR/, { timeout: 240_000 });
|
||
await expect.poll(async () => (await snapshotFacts(page, [ARMATURE, TARGET])).nodes?.[ARMATURE]?.id ?? '', { timeout: 240_000, intervals: [500, 1000, 2000] }).not.toBe('');
|
||
return snapshotFacts(page, [ARMATURE, TARGET]);
|
||
}
|
||
|
||
async function readAfterRevision(page: Page, before: number, names: string[]): Promise<SnapshotFacts> {
|
||
await expect.poll(async () => (await snapshotFacts(page)).revision ?? 0, { timeout: 120_000, intervals: [500, 1000, 2000] }).toBeGreaterThan(before);
|
||
return snapshotFacts(page, names);
|
||
}
|
||
|
||
const boneOf = (facts: SnapshotFacts, name: string) =>
|
||
(facts.armatures ?? []).flatMap((armature) => armature.bones).find((bone) => bone.name === name) ?? null;
|
||
|
||
async function buildChain(page: Page, armatureId: string): Promise<SnapshotFacts> {
|
||
const before = (await snapshotFacts(page)).revision ?? 0;
|
||
const applied = await applyEngineCommand(page, { type: 'setArmatureBones', objectId: armatureId, bones: CHAIN });
|
||
expect(applied.ok, JSON.stringify(applied)).toBe(true);
|
||
const facts = await readAfterRevision(page, before, [ARMATURE]);
|
||
expect(facts.boneNames ?? []).toEqual(expect.arrayContaining(['Root', 'Child']));
|
||
return facts;
|
||
}
|
||
|
||
async function bindTarget(page: Page, armatureId: string): Promise<{ before: SnapshotFacts; after: SnapshotFacts }> {
|
||
const beforeFacts = await snapshotFacts(page, [TARGET]);
|
||
const before = beforeFacts.revision ?? 0;
|
||
const applied = await applyEngineCommand(page, { type: 'setParent', objectId: beforeFacts.nodes?.[TARGET]?.id ?? '', parentId: armatureId, parentType: 'BONE', parentBone: 'Root', keepTransform: true });
|
||
expect(applied.ok, JSON.stringify(applied)).toBe(true);
|
||
const after = await readAfterRevision(page, before, [TARGET, ARMATURE]);
|
||
return { before: beforeFacts, after };
|
||
}
|
||
|
||
test('setArmatureBones builds a chain whose rest and pose channels read back [armature-bones-web]', async ({ page }, testInfo) => {
|
||
const errors = consoleCollector(page);
|
||
await installEngineBridge(page);
|
||
const opened = await openFixture(page);
|
||
const armatureId = opened.nodes?.[ARMATURE]?.id ?? '';
|
||
expect(armatureId).toBeTruthy();
|
||
|
||
const facts = await buildChain(page, armatureId);
|
||
const root = boneOf(facts, 'Root');
|
||
const child = boneOf(facts, 'Child');
|
||
const evidence = {
|
||
schemaVersion: 1,
|
||
case: 'armature-bones-web',
|
||
candidate: CANDIDATE,
|
||
revision: facts.revision ?? null,
|
||
bones: (facts.armatures ?? []).flatMap((armature) => armature.bones).map((bone) => ({
|
||
name: bone.name, parentId: bone.parentId, head: bone.head, tail: bone.tail, restMatrix: bone.restMatrix,
|
||
poseMatrix: bone.poseMatrix, poseLocation: bone.poseLocation, poseRotationEuler: bone.poseRotationEuler,
|
||
poseScale: bone.poseScale, poseRotMode: bone.poseRotMode,
|
||
})),
|
||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||
acceptance: 'NOT_CLAIMED',
|
||
};
|
||
await attachEvidence(testInfo, 'armature-bones-web', evidence);
|
||
|
||
expect(root).toBeTruthy();
|
||
expect(child).toBeTruthy();
|
||
expect(root!.parentId).toBeNull();
|
||
expect(child!.parentId).toBe(root!.id);
|
||
expect(root!.restMatrix).toHaveLength(16);
|
||
expect(root!.poseMatrix).toHaveLength(16);
|
||
/* A freshly built bone starts at rest: identity pose channel transforms. */
|
||
expect(root!.poseLocation).toEqual([0, 0, 0]);
|
||
expect(root!.poseRotationEuler).toEqual([0, 0, 0]);
|
||
expect(root!.poseScale).toEqual([1, 1, 1]);
|
||
expect(productConsole(errors)).toEqual([]);
|
||
});
|
||
|
||
test('setParent BONE keeps the world matrix, records the bone and rejects a missing bone [armature-bind-web]', async ({ page }, testInfo) => {
|
||
const errors = consoleCollector(page);
|
||
await installEngineBridge(page);
|
||
const opened = await openFixture(page);
|
||
const armatureId = opened.nodes?.[ARMATURE]?.id ?? '';
|
||
await buildChain(page, armatureId);
|
||
|
||
const bound = await bindTarget(page, armatureId);
|
||
const target = bound.after.nodes?.[TARGET];
|
||
const evidence = {
|
||
schemaVersion: 1,
|
||
case: 'armature-bind-web',
|
||
candidate: CANDIDATE,
|
||
target: { id: target?.id ?? null, worldBefore: bound.before.nodes?.[TARGET]?.worldMatrix ?? null, worldAfter: target?.worldMatrix ?? null },
|
||
parent: { parentId: target?.parentId ?? null, parentType: target?.parentType ?? null, parentBoneName: target?.parentBoneName ?? null, parentBoneMatrix: target?.parentBoneMatrix ?? null },
|
||
delta: matrixDistance(bound.before.nodes?.[TARGET]?.worldMatrix, target?.worldMatrix),
|
||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||
acceptance: 'NOT_CLAIMED',
|
||
};
|
||
await attachEvidence(testInfo, 'armature-bind-web', evidence);
|
||
|
||
expect(target?.parentId).toBe(armatureId);
|
||
expect(target?.parentType).toBe('BONE');
|
||
expect(target?.parentBoneName).toBe('Root');
|
||
expect(target?.parentBoneMatrix).toHaveLength(16);
|
||
expect(evidence.delta).toBeLessThan(1e-4);
|
||
|
||
const negative = await applyEngineCommand(page, { type: 'setParent', objectId: target?.id ?? '', parentId: armatureId, parentType: 'BONE', parentBone: 'Missing', keepTransform: true });
|
||
expect(negative.ok).toBe(false);
|
||
expect(`${negative.errorCode ?? ''} ${negative.message ?? ''}`).toContain('PARENT_BONE_INVALID');
|
||
|
||
/* The rejected bind must leave the accepted one untouched. */
|
||
const after = await snapshotFacts(page, [TARGET]);
|
||
expect(after.nodes?.[TARGET]?.parentBoneName).toBe('Root');
|
||
expect(matrixDistance(after.nodes?.[TARGET]?.worldMatrix, target?.worldMatrix ?? null)).toBeLessThan(1e-9);
|
||
expect(productConsole(errors)).toEqual([]);
|
||
});
|
||
|
||
test('pose writes evaluate into pose matrices and drive the bone-parented object [armature-pose-web]', async ({ page }, testInfo) => {
|
||
const errors = consoleCollector(page);
|
||
await installEngineBridge(page);
|
||
const opened = await openFixture(page);
|
||
const armatureId = opened.nodes?.[ARMATURE]?.id ?? '';
|
||
await buildChain(page, armatureId);
|
||
const bound = await bindTarget(page, armatureId);
|
||
|
||
const baseline = bound.after;
|
||
const basePose = boneOf(baseline, 'Root')?.poseMatrix ?? null;
|
||
const baseWorld = baseline.nodes?.[TARGET]?.worldMatrix ?? null;
|
||
const poseCommand = { type: 'setPoseBoneTransform', objectId: armatureId, boneName: 'Root', translation: [0, 0, 0], rotationEuler: POSE, scale: [1, 1, 1] };
|
||
|
||
const posedResult = await applyEngineCommand(page, poseCommand);
|
||
expect(posedResult.ok, JSON.stringify(posedResult)).toBe(true);
|
||
const posed = await readAfterRevision(page, baseline.revision ?? 0, [TARGET]);
|
||
const posedPose = boneOf(posed, 'Root')?.poseMatrix ?? null;
|
||
const posedWorld = posed.nodes?.[TARGET]?.worldMatrix ?? null;
|
||
|
||
const repeatedResult = await applyEngineCommand(page, poseCommand);
|
||
expect(repeatedResult.ok, JSON.stringify(repeatedResult)).toBe(true);
|
||
const repeated = await readAfterRevision(page, posed.revision ?? 0, [TARGET]);
|
||
const repeatedPose = boneOf(repeated, 'Root')?.poseMatrix ?? null;
|
||
const repeatedWorld = repeated.nodes?.[TARGET]?.worldMatrix ?? null;
|
||
|
||
const zeroResult = await applyEngineCommand(page, { ...poseCommand, rotationEuler: [0, 0, 0] });
|
||
expect(zeroResult.ok, JSON.stringify(zeroResult)).toBe(true);
|
||
const restored = await readAfterRevision(page, repeated.revision ?? 0, [TARGET]);
|
||
|
||
const deltas = {
|
||
pose: matrixDistance(basePose, posedPose),
|
||
world: matrixDistance(baseWorld, posedWorld),
|
||
repeatPose: matrixDistance(posedPose, repeatedPose),
|
||
repeatWorld: matrixDistance(posedWorld, repeatedWorld),
|
||
restorePose: matrixDistance(basePose, boneOf(restored, 'Root')?.poseMatrix ?? null),
|
||
restoreWorld: matrixDistance(baseWorld, restored.nodes?.[TARGET]?.worldMatrix ?? null),
|
||
};
|
||
const evidence = {
|
||
schemaVersion: 1,
|
||
case: 'armature-pose-web',
|
||
candidate: CANDIDATE,
|
||
joint: { bone: 'Root', rotationEuler: POSE },
|
||
revisions: { baseline: baseline.revision ?? null, posed: posed.revision ?? null, repeated: repeated.revision ?? null, restored: restored.revision ?? null },
|
||
pose: { baseline: basePose, posed: posedPose, repeatSame: sha(posedPose) === sha(repeatedPose) },
|
||
world: { baseline: baseWorld, posed: posedWorld },
|
||
deltas,
|
||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||
acceptance: 'NOT_CLAIMED',
|
||
};
|
||
await attachEvidence(testInfo, 'armature-pose-web', evidence);
|
||
|
||
expect(deltas.pose).toBeGreaterThan(0.01);
|
||
expect(deltas.world).toBeGreaterThan(0.01);
|
||
expect(deltas.repeatPose).toBeLessThan(1e-9);
|
||
expect(deltas.repeatWorld).toBeLessThan(1e-9);
|
||
expect(deltas.restorePose).toBeLessThan(1e-6);
|
||
expect(deltas.restoreWorld).toBeLessThan(1e-6);
|
||
expect(productConsole(errors)).toEqual([]);
|
||
});
|
||
|
||
test('viewport draws the armature and repaints after a pose [armature-viewport-web]', async ({ page }, testInfo) => {
|
||
const errors = consoleCollector(page);
|
||
await installEngineBridge(page);
|
||
const opened = await openFixture(page);
|
||
const boneCount = (opened.armatures ?? []).flatMap((armature) => armature.bones).length;
|
||
expect(boneCount).toBeGreaterThan(0);
|
||
|
||
const canvas = page.locator('canvas.viewport-canvas').first();
|
||
await expect(canvas).toHaveAttribute('data-armature-bone-count', String(boneCount), { timeout: 120_000 });
|
||
const revisionBefore = await canvas.getAttribute('data-snapshot-revision');
|
||
const before = await canvas.screenshot();
|
||
|
||
/* The pose form is the product's own setPoseBoneTransform entry, so the app
|
||
* receives the result and repaints the viewport; direct worker commands never
|
||
* reach the viewport by design. */
|
||
/* The fixture opens with the armature already active, so the workbench is up
|
||
* without an outliner click (the armature object row is not in the fallback
|
||
* outliner tree for this fixture). Workbench sections stay display:none until
|
||
* the property tabs' diagnostics toggle is on. */
|
||
await page.getByRole('button', { name: '诊断', exact: true }).click();
|
||
const panel = page.getByTestId('armature-authoring-workbench');
|
||
await expect(panel).toBeVisible({ timeout: 60_000 });
|
||
const bone = panel.locator('.property-subsection').filter({ has: page.getByRole('heading', { name: 'Root', exact: true }) }).first();
|
||
await expect(bone).toBeVisible({ timeout: 30_000 });
|
||
/* Desktop keeps rest editing in Edit mode and pose channels in Pose mode; the
|
||
* object-mode armature panel is read-only, so enter Pose before the form. */
|
||
await expect(panel.getByTestId('armature-pose-readback')).toHaveCount(0);
|
||
await panel.getByRole('button', { name: '进入姿态模式', exact: true }).click();
|
||
await expect(bone.getByTestId('armature-pose-readback')).toBeVisible({ timeout: 120_000 });
|
||
/* The pose panel shows degrees; the engine keeps radians. */
|
||
await bone.getByLabel('Rotation X', { exact: true }).fill(String(Number((POSE[0] * 180 / Math.PI).toFixed(4))));
|
||
await bone.getByLabel('Rotation Z', { exact: true }).fill(String(Number((POSE[2] * 180 / Math.PI).toFixed(4))));
|
||
await bone.getByRole('button', { name: 'Apply Pose', exact: true }).click();
|
||
/* Pose edits keep the scene revision, so the engine readback is the signal
|
||
* that the product form applied the same values the engine-level case uses. */
|
||
await page.waitForTimeout(2000);
|
||
const sentTrail = await page.evaluate(() => ((window as unknown as { __armatureSent?: Array<Record<string, unknown>> }).__armatureSent ?? []).slice(-6));
|
||
const workerTrail = await page.evaluate(() => ((window as unknown as { __armatureEvents: Array<Record<string, unknown>> }).__armatureEvents ?? []).slice(-3).map((event) => ({ ok: event.ok, errorCode: event.errorCode, message: event.message, revision: (event.snapshot as { revision?: number } | null)?.revision ?? null })));
|
||
workerTrail.push({ sent: sentTrail });
|
||
let poseX = Number.NaN;
|
||
for (const deadline = Date.now() + 60_000; Date.now() < deadline;) {
|
||
poseX = boneOf(await snapshotFacts(page, [ARMATURE]), 'Root')?.poseRotationEuler?.[0] ?? Number.NaN;
|
||
if (Math.abs(poseX - POSE[0]) < 1e-4) break;
|
||
await page.waitForTimeout(1000);
|
||
}
|
||
expect(poseX, JSON.stringify(workerTrail)).toBeCloseTo(POSE[0], 4);
|
||
const digest = (buffer: Buffer) => crypto.createHash('sha256').update(buffer).digest('hex');
|
||
let after = before;
|
||
for (let attempt = 0; attempt < 40 && digest(after) === digest(before); attempt++) { await page.waitForTimeout(500); after = await canvas.screenshot(); }
|
||
const evidence = {
|
||
schemaVersion: 1,
|
||
case: 'armature-viewport-web',
|
||
candidate: CANDIDATE,
|
||
boneCount,
|
||
revisions: { before: revisionBefore, after: await canvas.getAttribute('data-snapshot-revision') },
|
||
screenshots: { before: digest(before), after: digest(after) },
|
||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||
acceptance: 'NOT_CLAIMED',
|
||
};
|
||
await attachEvidence(testInfo, 'armature-viewport-web', evidence);
|
||
|
||
expect(evidence.screenshots.after).not.toBe(evidence.screenshots.before);
|
||
expect(await canvas.getAttribute('data-armature-bone-count')).toBe(String(boneCount));
|
||
expect(productConsole(errors)).toEqual([]);
|
||
});
|
||
|
||
test('decimal input reaches object and pose transforms [armature-decimal-input-web]', async ({ page }, testInfo) => {
|
||
const errors = consoleCollector(page);
|
||
await installEngineBridge(page);
|
||
const opened = await openFixture(page);
|
||
expect(opened.nodes?.[ARMATURE]?.id ?? '').toBeTruthy();
|
||
await page.getByRole('button', { name: '诊断', exact: true }).click();
|
||
const panel = page.getByTestId('armature-authoring-workbench');
|
||
await expect(panel).toBeVisible({ timeout: 120_000 });
|
||
const bone = panel.locator('.property-subsection').filter({ has: page.getByRole('heading', { name: 'Root', exact: true }) }).first();
|
||
await expect(bone).toBeVisible({ timeout: 30_000 });
|
||
await panel.getByRole('button', { name: '进入姿态模式', exact: true }).click();
|
||
await expect(bone.getByTestId('armature-pose-readback')).toBeVisible({ timeout: 120_000 });
|
||
|
||
/* Type key by key like a user: a number input briefly reports "" for "0.",
|
||
* so only the final value proves the decimal survived the round trip. */
|
||
const typeDecimal = async (input: ReturnType<Page['locator']>, digits: string) => {
|
||
await input.click();
|
||
await input.press('Control+A');
|
||
for (const key of digits.split('')) await input.press(key);
|
||
return input.inputValue();
|
||
};
|
||
const poseValue = await typeDecimal(bone.getByLabel('Scale X', { exact: true }), '0.5');
|
||
const objectValue = await typeDecimal(page.locator('input[aria-label="缩放 X"]').first(), '0.5');
|
||
|
||
await bone.getByRole('button', { name: 'Apply Pose', exact: true }).click();
|
||
await expect.poll(async () => boneOf(await snapshotFacts(page, [ARMATURE]), 'Root')?.poseScale?.[0] ?? Number.NaN, { timeout: 120_000, intervals: [500, 1000, 2000] }).toBeCloseTo(0.5, 4);
|
||
const facts = await snapshotFacts(page, [ARMATURE]);
|
||
const evidence = {
|
||
schemaVersion: 1,
|
||
case: 'armature-decimal-input-web',
|
||
candidate: CANDIDATE,
|
||
inputs: { poseScaleX: poseValue, objectScaleX: objectValue },
|
||
poseScale: boneOf(facts, 'Root')?.poseScale ?? null,
|
||
revision: facts.revision ?? null,
|
||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||
acceptance: 'NOT_CLAIMED',
|
||
};
|
||
await attachEvidence(testInfo, 'armature-decimal-input-web', evidence);
|
||
|
||
expect(poseValue).toBe('0.5');
|
||
expect(objectValue).toBe('0.5');
|
||
expect(evidence.poseScale?.[0] ?? Number.NaN).toBeCloseTo(0.5, 4);
|
||
expect(productConsole(errors)).toEqual([]);
|
||
});
|
||
|
||
test('pose form reads back the applied channels [armature-ui-readback-web]', async ({ page }, testInfo) => {
|
||
const errors = consoleCollector(page);
|
||
await installEngineBridge(page);
|
||
const opened = await openFixture(page);
|
||
expect(opened.nodes?.[ARMATURE]?.id ?? '').toBeTruthy();
|
||
await page.getByRole('button', { name: '诊断', exact: true }).click();
|
||
const panel = page.getByTestId('armature-authoring-workbench');
|
||
await expect(panel).toBeVisible({ timeout: 120_000 });
|
||
const bone = panel.locator('.property-subsection').filter({ has: page.getByRole('heading', { name: 'Root', exact: true }) }).first();
|
||
/* Object mode is read-only: neither the rest forms nor the pose form exist
|
||
* until the armature enters the matching mode, like desktop Blender. */
|
||
await expect(panel).toHaveAttribute('data-armature-mode', 'Object');
|
||
await expect(panel.getByTestId('armature-pose-readback')).toHaveCount(0);
|
||
await expect(panel.getByTestId('armature-edit-operations')).toHaveCount(0);
|
||
await panel.getByRole('button', { name: '进入姿态模式', exact: true }).click();
|
||
const form = bone.getByTestId('armature-pose-readback');
|
||
await expect(form).toBeVisible({ timeout: 120_000 });
|
||
await expect(panel.getByTestId('armature-edit-operations')).toHaveCount(0);
|
||
/* The button's native object.mode_set runs after the local mode flips, and
|
||
* shortcuts are ignored while a mode change is pending; wait for the status
|
||
* line to report the completed switch before exercising Ctrl+Tab. */
|
||
const status = page.getByTestId('engine-status');
|
||
await expect(status).toContainText('模式:Pose', { timeout: 120_000 });
|
||
|
||
/* Ctrl+Tab toggles Pose on an armature object (Tab keeps entering Edit). */
|
||
const canvas = page.locator('canvas.viewport-canvas').first();
|
||
await canvas.focus();
|
||
await page.keyboard.press('Control+Tab');
|
||
await expect(panel).toHaveAttribute('data-armature-mode', 'Object', { timeout: 30_000 });
|
||
await expect(panel.getByTestId('armature-pose-readback')).toHaveCount(0);
|
||
await expect(status).toContainText('模式:Object', { timeout: 120_000 });
|
||
await page.keyboard.press('Control+Tab');
|
||
await expect(form).toBeVisible({ timeout: 30_000 });
|
||
|
||
const degrees = Number((POSE[0] * 180 / Math.PI).toFixed(4));
|
||
await form.getByLabel('Rotation X', { exact: true }).fill(String(degrees));
|
||
await form.getByLabel('Scale X', { exact: true }).fill('0.5');
|
||
await form.getByRole('button', { name: 'Apply Pose', exact: true }).click();
|
||
|
||
await expect.poll(async () => boneOf(await snapshotFacts(page, [ARMATURE]), 'Root')?.poseRotationEuler?.[0] ?? Number.NaN, { timeout: 120_000, intervals: [500, 1000, 2000] }).toBeCloseTo(POSE[0], 4);
|
||
const root = boneOf(await snapshotFacts(page, [ARMATURE]), 'Root');
|
||
const readback = {
|
||
rotationX: Number(await form.getByLabel('Rotation X', { exact: true }).inputValue()),
|
||
scaleX: Number(await form.getByLabel('Scale X', { exact: true }).inputValue()),
|
||
};
|
||
const evidence = {
|
||
schemaVersion: 1,
|
||
case: 'armature-ui-readback-web',
|
||
candidate: CANDIDATE,
|
||
typed: { rotationX: degrees, scaleX: 0.5 },
|
||
readback,
|
||
engine: { poseRotationEuler: root?.poseRotationEuler ?? null, poseScale: root?.poseScale ?? null },
|
||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||
acceptance: 'NOT_CLAIMED',
|
||
};
|
||
await attachEvidence(testInfo, 'armature-ui-readback-web', evidence);
|
||
|
||
expect(readback.rotationX).toBeCloseTo(degrees, 3);
|
||
expect(readback.scaleX).toBeCloseTo(0.5, 4);
|
||
expect(root?.poseRotationEuler?.[0] ?? Number.NaN).toBeCloseTo(POSE[0], 4);
|
||
expect(root?.poseScale?.[0] ?? Number.NaN).toBeCloseTo(0.5, 4);
|
||
expect(productConsole(errors)).toEqual([]);
|
||
});
|
||
|
||
test('saving to OPFS and reopening keeps the bones, the binding and the pose [armature-reopen-web]', async ({ page }, testInfo) => {
|
||
const errors = consoleCollector(page);
|
||
await installEngineBridge(page);
|
||
const opened = await openFixture(page);
|
||
const armatureId = opened.nodes?.[ARMATURE]?.id ?? '';
|
||
await buildChain(page, armatureId);
|
||
const bound = await bindTarget(page, armatureId);
|
||
|
||
const posed = await applyEngineCommand(page, { type: 'setPoseBoneTransform', objectId: armatureId, boneName: 'Root', translation: [0, 0, 0], rotationEuler: POSE, scale: [1, 1, 1] });
|
||
expect(posed.ok, JSON.stringify(posed)).toBe(true);
|
||
const before = await readAfterRevision(page, bound.after.revision ?? 0, [TARGET, ARMATURE]);
|
||
const beforeWorld = before.nodes?.[TARGET]?.worldMatrix ?? null;
|
||
/* The pose must be visible before the save, otherwise a preserved world
|
||
* would prove nothing about the round trip. */
|
||
expect(matrixDistance(bound.after.nodes?.[TARGET]?.worldMatrix, beforeWorld)).toBeGreaterThan(0.01);
|
||
|
||
/* Product save path: 文件 → 保存到浏览器 OPFS persists through the storage
|
||
* worker; the app records the transaction outcome on main.blender-app. */
|
||
await page.getByRole('button', { name: '文件', exact: true }).click();
|
||
await page.getByRole('menuitem', { name: '保存到浏览器 OPFS', exact: true }).click();
|
||
const app = page.locator('main.blender-app');
|
||
await expect.poll(async () => app.getAttribute('data-user-action-save-status'), { timeout: 240_000, intervals: [500, 1000, 2000] }).toBe('SUCCEEDED');
|
||
const projectId = await app.getAttribute('data-project-id');
|
||
|
||
/* Product reopen path: 文件 → 最近打开 → the project just saved. The open
|
||
* replaces Main in the same worker, so the bridge keeps recording. */
|
||
const opensBefore = await openBlendReplyCount(page);
|
||
await page.getByRole('button', { name: '文件', exact: true }).click();
|
||
await page.getByRole('menuitem', { name: '最近打开', exact: true }).click();
|
||
await page.getByRole('menuitem', { name: 'pose_constraint_scene.blend', exact: true }).click();
|
||
/* Prove the worker actually reopened the saved bytes: the live Main already
|
||
* answers snapshots, so without this the comparison could pass unaided. */
|
||
await expect.poll(() => openBlendReplyCount(page), { timeout: 300_000, intervals: [500, 1000, 2000] }).toBeGreaterThan(opensBefore);
|
||
await expect.poll(async () => (await snapshotFacts(page, [TARGET, ARMATURE])).nodes?.[TARGET]?.parentBoneName ?? '', { timeout: 300_000, intervals: [500, 1000, 2000] }).toBe('Root');
|
||
const after = await snapshotFacts(page, [TARGET, ARMATURE]);
|
||
|
||
const rootBefore = boneOf(before, 'Root');
|
||
const rootAfter = boneOf(after, 'Root');
|
||
const targetBefore = before.nodes?.[TARGET];
|
||
const targetAfter = after.nodes?.[TARGET];
|
||
const deltas = {
|
||
rest: matrixDistance(rootBefore?.restMatrix, rootAfter?.restMatrix),
|
||
poseMatrix: matrixDistance(rootBefore?.poseMatrix, rootAfter?.poseMatrix),
|
||
poseEuler: matrixDistance(rootBefore?.poseRotationEuler, rootAfter?.poseRotationEuler),
|
||
parentBoneMatrix: matrixDistance(targetBefore?.parentBoneMatrix, targetAfter?.parentBoneMatrix),
|
||
world: matrixDistance(beforeWorld, targetAfter?.worldMatrix),
|
||
};
|
||
const evidence = {
|
||
schemaVersion: 1,
|
||
case: 'armature-reopen-web',
|
||
candidate: CANDIDATE,
|
||
save: { route: '文件 → 保存到浏览器 OPFS', projectId },
|
||
reopen: { route: '文件 → 最近打开 → pose_constraint_scene.blend', openBlendReplies: { before: opensBefore, after: await openBlendReplyCount(page) } },
|
||
revisions: { before: before.revision ?? null, after: after.revision ?? null },
|
||
bones: { before: before.boneNames ?? [], after: after.boneNames ?? [] },
|
||
pose: { rotationEuler: rootAfter?.poseRotationEuler ?? null, matrix: rootAfter?.poseMatrix ?? null },
|
||
parent: { parentType: targetAfter?.parentType ?? null, parentBoneName: targetAfter?.parentBoneName ?? null },
|
||
deltas,
|
||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||
acceptance: 'NOT_CLAIMED',
|
||
};
|
||
await attachEvidence(testInfo, 'armature-reopen-web', evidence);
|
||
|
||
expect(before.boneNames ?? []).toEqual(expect.arrayContaining(['Root', 'Child']));
|
||
expect(after.boneNames ?? []).toEqual(expect.arrayContaining(['Root', 'Child']));
|
||
expect(targetAfter?.parentType).toBe('BONE');
|
||
expect(targetAfter?.parentBoneName).toBe('Root');
|
||
expect(rootAfter?.poseRotationEuler?.[0] ?? Number.NaN).toBeCloseTo(POSE[0], 4);
|
||
expect(rootAfter?.poseRotationEuler?.[2] ?? Number.NaN).toBeCloseTo(POSE[2], 4);
|
||
expect(deltas.rest).toBeLessThan(1e-6);
|
||
expect(deltas.poseMatrix).toBeLessThan(1e-4);
|
||
expect(deltas.poseEuler).toBeLessThan(1e-5);
|
||
expect(deltas.parentBoneMatrix).toBeLessThan(1e-4);
|
||
expect(deltas.world).toBeLessThan(1e-4);
|
||
expect(productConsole(errors)).toEqual([]);
|
||
});
|