feat(web): armature bone parenting, pose evaluation and ABB IRB120 headed suite
- engine: PARBONE parenting, BKE_pose_where_is pose refresh, pose channel readback - viewport: three.js bone wireframes for the main-thread and offscreen paths - properties: draft numeric transform inputs (decimals survive typing), armature pose readback in degrees with step=any fields so validation cannot block Apply Pose - tests: headed armature/robot suite (9 cases), receipts bound to candidate hashes Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
357
web/tests/e2e/armature-engine-headed-production.spec.ts
Normal file
357
web/tests/e2e/armature-engine-headed-production.spec.ts
Normal file
@@ -0,0 +1,357 @@
|
||||
import crypto from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import { expect, test, type Page, type TestInfo } from '@playwright/test';
|
||||
import { applyEngineCommand, installEngineBridge, matrixDistance, 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 });
|
||||
/* 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 });
|
||||
|
||||
/* 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();
|
||||
const form = bone.getByTestId('armature-pose-readback');
|
||||
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([]);
|
||||
});
|
||||
224
web/tests/e2e/armature-robot-headed-production.spec.ts
Normal file
224
web/tests/e2e/armature-robot-headed-production.spec.ts
Normal file
@@ -0,0 +1,224 @@
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { expect, test, type Locator, type Page, type TestInfo } from '@playwright/test';
|
||||
import { installEngineBridge, matrixDistance, snapshotFacts, writeEvidence, type SnapshotFacts } from '../fixtures/armature-robot-workflow';
|
||||
import { productErrors as sharedProductErrors } from '../fixtures/runtime-console';
|
||||
|
||||
/* The robot tool drives the product's own URDF import / assemble / pose entries
|
||||
* (RobotTool.tsx -> robot-workflow.py) against the sample ABB IRB120 shipped in
|
||||
* the candidate. Nothing here re-implements the import path: every assertion is
|
||||
* a read-back from the engine snapshot after a user click. */
|
||||
const REPO_ROOT = path.resolve(import.meta.dirname, '../../..');
|
||||
const CANDIDATE = path.resolve(process.env.WBV2_PRODUCTION_CANDIDATE ?? path.join(REPO_ROOT, 'web/dist'));
|
||||
const ASSET_DIR = path.join(CANDIDATE, 'robot-assets/abb-irb120');
|
||||
const ROOT_OBJECT = 'Robot_abb_irb120_3_58';
|
||||
const LINKS = ['base_link', 'link_1', 'link_2', 'link_3', 'link_4', 'link_5', 'link_6', 'base', 'flange', 'tool0'];
|
||||
const REVOLUTE = ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5', 'joint_6'];
|
||||
const EXPECTED_PARENTS: Record<string, string> = { base_link: ROOT_OBJECT, link_1: 'base_link', link_2: 'link_1', link_3: 'link_2', link_4: 'link_3', link_5: 'link_4', link_6: 'link_5', base: 'base_link', flange: 'link_6', tool0: 'flange' };
|
||||
/* 导入零件 only parks every link frame under the robot empty; the URDF chain
|
||||
* is what 建立 URDF 层级 writes. */
|
||||
const IMPORTED_PARENTS: Record<string, string> = Object.fromEntries(LINKS.map((name) => [name, ROOT_OBJECT]));
|
||||
|
||||
const sha256 = (file: string) => crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
||||
|
||||
function provenanceBindings() {
|
||||
const provenance = JSON.parse(fs.readFileSync(path.join(ASSET_DIR, 'provenance.json'), 'utf8')) as { files: { path: string; sha256: string }[] };
|
||||
return provenance.files.map((file) => ({ path: file.path, expected: file.sha256, actual: sha256(path.join(ASSET_DIR, file.path)), match: sha256(path.join(ASSET_DIR, file.path)) === file.sha256 }));
|
||||
}
|
||||
|
||||
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-robot-evidence', { path: file, contentType: 'application/json' });
|
||||
return file;
|
||||
}
|
||||
|
||||
async function openRobotTool(page: Page): Promise<Locator> {
|
||||
await page.goto('/?ui=web');
|
||||
await page.getByLabel('六轴机器人工具').click();
|
||||
const dialog = page.locator('.robot-tool').first();
|
||||
await expect(dialog).toBeVisible({ timeout: 60_000 });
|
||||
return dialog;
|
||||
}
|
||||
|
||||
async function loadSample(dialog: Locator) {
|
||||
await dialog.getByRole('button', { name: '加载 ABB IRB120 样例', exact: true }).click();
|
||||
await expect(dialog).toContainText(/资源就绪 · 10 links · \d+ STL · 6 轴/, { timeout: 120_000 });
|
||||
}
|
||||
|
||||
async function importParts(page: Page, dialog: Locator) {
|
||||
const button = dialog.getByRole('button', { name: '导入零件', exact: true });
|
||||
await expect(button).toBeEnabled({ timeout: 180_000 });
|
||||
await button.click();
|
||||
await expect(dialog).toContainText('零件已导入', { timeout: 240_000 });
|
||||
await expect(page.getByTestId('engine-status')).toContainText(/SceneIR/, { timeout: 60_000 });
|
||||
}
|
||||
|
||||
async function assembleAndCheck(dialog: Locator) {
|
||||
await dialog.getByRole('button', { name: '建立 URDF 层级', exact: true }).click();
|
||||
await expect(dialog).toContainText('层级已建立', { timeout: 120_000 });
|
||||
await dialog.getByRole('button', { name: '检查六轴', exact: true }).click();
|
||||
await expect(dialog).toContainText('六轴检查通过', { timeout: 180_000 });
|
||||
}
|
||||
|
||||
/* Snapshot read-back is polled on the engine's own revision instead of on a UI
|
||||
* string, so a status that happens to look identical across two poses cannot
|
||||
* make an assertion pass early. */
|
||||
async function readAfterRevision(page: Page, before: number, names: string[]): Promise<SnapshotFacts> {
|
||||
await expect.poll(async () => (await snapshotFacts(page)).revision ?? 0, { timeout: 180_000, intervals: [500, 1000, 2000] }).toBeGreaterThan(before);
|
||||
return snapshotFacts(page, names);
|
||||
}
|
||||
|
||||
const parentChain = (facts: SnapshotFacts) => {
|
||||
const nameById = Object.fromEntries(Object.entries(facts.nodes ?? {}).map(([name, node]) => [node.id, name]));
|
||||
return Object.fromEntries(LINKS.map((name) => [name, facts.nodes?.[name]?.parentId ? nameById[facts.nodes[name].parentId!] ?? facts.nodes[name].parentId : null]));
|
||||
};
|
||||
|
||||
const productConsole = (errors: string[]) => sharedProductErrors(errors);
|
||||
|
||||
test.beforeAll(() => {
|
||||
expect(fs.existsSync(path.join(ASSET_DIR, 'provenance.json')), `missing robot sample in ${ASSET_DIR}`).toBe(true);
|
||||
});
|
||||
|
||||
test('robot sample loads from the candidate and its links import into the scene [robot-sample-web]', async ({ page }, testInfo) => {
|
||||
const errors = consoleCollector(page);
|
||||
await installEngineBridge(page);
|
||||
const dialog = await openRobotTool(page);
|
||||
await loadSample(dialog);
|
||||
const status = (await dialog.locator('.robot-tool-summary, .robot-tool-body').first().innerText()).replace(/\s+/g, ' ');
|
||||
await importParts(page, dialog);
|
||||
|
||||
const facts = await snapshotFacts(page, [ROOT_OBJECT, ...LINKS]);
|
||||
const bindings = provenanceBindings();
|
||||
const summary = await dialog.locator('.robot-tool-summary').innerText();
|
||||
const evidence = {
|
||||
schemaVersion: 1,
|
||||
case: 'robot-sample-web',
|
||||
candidate: CANDIDATE,
|
||||
sample: { assetDir: ASSET_DIR, provenance: bindings, summary: summary.replace(/\s+/g, ' '), status: status.slice(0, 300) },
|
||||
scene: { revision: facts.revision ?? null, armatureCount: facts.armatureCount ?? null, boneNames: facts.boneNames ?? [], rootParent: facts.nodes?.[ROOT_OBJECT]?.parentId ?? 'missing', linkedFrames: LINKS.filter((name) => (facts.nodes?.[name]?.id ?? '') !== ''), parentChain: parentChain(facts) },
|
||||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||||
acceptance: 'NOT_CLAIMED',
|
||||
};
|
||||
const file = await attachEvidence(testInfo, 'robot-sample-web', evidence);
|
||||
|
||||
expect(bindings.every((binding) => binding.match), `provenance mismatch: ${JSON.stringify(bindings.filter((binding) => !binding.match))}`).toBe(true);
|
||||
expect(bindings.map((binding) => binding.path)).toContain('abb_irb120.urdf');
|
||||
expect(summary).toMatch(/abb_irb120_3_58 · 10 links · \d+ files/);
|
||||
expect(facts.ok).toBe(true);
|
||||
expect(facts.revision).toBeGreaterThan(0);
|
||||
expect(facts.nodes?.[ROOT_OBJECT]?.id).toBeTruthy();
|
||||
expect(facts.nodes?.[ROOT_OBJECT]?.parentId).toBeNull();
|
||||
expect(evidence.scene.linkedFrames).toHaveLength(LINKS.length);
|
||||
expect(evidence.scene.parentChain).toEqual(IMPORTED_PARENTS);
|
||||
expect(productConsole(errors)).toEqual([]);
|
||||
expect(file).toContain('armature-robot-sample-web-');
|
||||
});
|
||||
|
||||
test('the assembled ABB IRB120 passes the six-axis check on the real parent chain [robot-assemble-check-web]', async ({ page }, testInfo) => {
|
||||
const errors = consoleCollector(page);
|
||||
await installEngineBridge(page);
|
||||
const dialog = await openRobotTool(page);
|
||||
await loadSample(dialog);
|
||||
await importParts(page, dialog);
|
||||
await assembleAndCheck(dialog);
|
||||
|
||||
const rows = dialog.getByRole('table', { name: '机器人关节表' }).locator('tbody tr');
|
||||
await expect(rows).toHaveCount(9);
|
||||
const table = [] as { joint: string; chain: string; axis: string; check: string }[];
|
||||
for (let index = 0; index < 9; index++) {
|
||||
const cells = rows.nth(index).locator('td');
|
||||
table.push({ joint: (await cells.nth(0).innerText()).split('\n')[0], chain: await cells.nth(1).innerText(), axis: await cells.nth(2).innerText(), check: await cells.nth(3).innerText() });
|
||||
}
|
||||
const facts = await snapshotFacts(page, [ROOT_OBJECT, ...LINKS]);
|
||||
const evidence = {
|
||||
schemaVersion: 1,
|
||||
case: 'robot-assemble-check-web',
|
||||
candidate: CANDIDATE,
|
||||
status: '六轴检查通过',
|
||||
table,
|
||||
scene: { revision: facts.revision ?? null, armatureCount: facts.armatureCount ?? null, parentChain: parentChain(facts) },
|
||||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||||
acceptance: 'NOT_CLAIMED',
|
||||
};
|
||||
await attachEvidence(testInfo, 'robot-assemble-check-web', evidence);
|
||||
|
||||
expect(table.map((row) => row.joint)).toEqual([...REVOLUTE, 'base_link-base', 'joint_6-flange', 'link_6-tool0']);
|
||||
for (const row of table.slice(0, 6)) expect(row.check, `${row.joint} check`).toBe('PASS');
|
||||
expect(table[6]).toMatchObject({ joint: 'base_link-base', axis: '--', check: '--' });
|
||||
expect(table[6].chain).toBe('base_link → base');
|
||||
expect(table.slice(1, 6).map((row) => row.chain)).toEqual(['link_1 → link_2', 'link_2 → link_3', 'link_3 → link_4', 'link_4 → link_5', 'link_5 → link_6']);
|
||||
expect(evidence.scene.parentChain).toEqual(EXPECTED_PARENTS);
|
||||
expect(productConsole(errors)).toEqual([]);
|
||||
});
|
||||
|
||||
test('joint_1 pose moves the link chain and 恢复零位 restores it [robot-pose-web]', async ({ page }, testInfo) => {
|
||||
const errors = consoleCollector(page);
|
||||
await installEngineBridge(page);
|
||||
const dialog = await openRobotTool(page);
|
||||
await loadSample(dialog);
|
||||
await importParts(page, dialog);
|
||||
/* The joint sliders only render once the URDF hierarchy exists, and pose
|
||||
* writes travel through the assembled parent chain. */
|
||||
await assembleAndCheck(dialog);
|
||||
|
||||
const zero = await snapshotFacts(page, [ROOT_OBJECT, ...LINKS]);
|
||||
const zeroRevision = zero.revision ?? 0;
|
||||
const zeroLink1 = zero.nodes?.link_1?.worldMatrix ?? null;
|
||||
const zeroLink6 = zero.nodes?.link_6?.worldMatrix ?? null;
|
||||
const zeroBase = zero.nodes?.base_link?.worldMatrix ?? null;
|
||||
|
||||
await dialog.getByLabel('joint_1 角度', { exact: true }).fill('30');
|
||||
await dialog.getByRole('button', { name: '应用关节角度', exact: true }).click();
|
||||
const posed = await readAfterRevision(page, zeroRevision, [ROOT_OBJECT, ...LINKS]);
|
||||
const posedLink1 = posed.nodes?.link_1?.worldMatrix ?? null;
|
||||
const posedLink6 = posed.nodes?.link_6?.worldMatrix ?? null;
|
||||
const posedBase = posed.nodes?.base_link?.worldMatrix ?? null;
|
||||
|
||||
/* Same input twice must not accumulate: the pose command writes an absolute
|
||||
* basis, so a second apply leaves every matrix bit-identical. */
|
||||
await dialog.getByRole('button', { name: '应用关节角度', exact: true }).click();
|
||||
const repeated = await readAfterRevision(page, posed.revision ?? zeroRevision, [ROOT_OBJECT, ...LINKS]);
|
||||
|
||||
await dialog.getByRole('button', { name: '恢复零位', exact: true }).click();
|
||||
const restored = await readAfterRevision(page, repeated.revision ?? zeroRevision, [ROOT_OBJECT, ...LINKS]);
|
||||
|
||||
const evidence = {
|
||||
schemaVersion: 1,
|
||||
case: 'robot-pose-web',
|
||||
candidate: CANDIDATE,
|
||||
joint: { name: 'joint_1', degrees: 30 },
|
||||
revisions: { zero: zeroRevision, posed: posed.revision ?? null, repeated: repeated.revision ?? null, restored: restored.revision ?? null },
|
||||
link1: { zero: zeroLink1, posed: posedLink1, repeated: repeated.nodes?.link_1?.worldMatrix ?? null, restored: restored.nodes?.link_1?.worldMatrix ?? null },
|
||||
link6: { zero: zeroLink6, posed: posedLink6, restored: restored.nodes?.link_6?.worldMatrix ?? null },
|
||||
base: { zero: zeroBase, posed: posedBase, restored: restored.nodes?.base_link?.worldMatrix ?? null },
|
||||
deltas: {
|
||||
link1Posed: matrixDistance(zeroLink1, posedLink1),
|
||||
link6Posed: matrixDistance(zeroLink6, posedLink6),
|
||||
basePosed: matrixDistance(zeroBase, posedBase),
|
||||
repeat: matrixDistance(posedLink1, repeated.nodes?.link_1?.worldMatrix ?? null),
|
||||
restore: matrixDistance(zeroLink1, restored.nodes?.link_1?.worldMatrix ?? null),
|
||||
},
|
||||
console: { productErrors: productConsole(errors), rawErrorCount: errors.length },
|
||||
acceptance: 'NOT_CLAIMED',
|
||||
};
|
||||
await attachEvidence(testInfo, 'robot-pose-web', evidence);
|
||||
|
||||
expect(posed.revision ?? 0).toBeGreaterThan(zeroRevision);
|
||||
expect(evidence.deltas.link1Posed).toBeGreaterThan(0.01);
|
||||
expect(evidence.deltas.link6Posed).toBeGreaterThan(0.01);
|
||||
expect(evidence.deltas.basePosed).toBeLessThan(1e-9);
|
||||
expect(evidence.deltas.repeat).toBeLessThan(1e-9);
|
||||
expect(evidence.deltas.restore).toBeLessThan(1e-6);
|
||||
/* The tool still advertises the six revolute joints this pose drove through. */
|
||||
const joints = await dialog.locator('.robot-joint input[aria-label$="角度"]').evaluateAll((nodes) => nodes.map((node) => (node as HTMLInputElement).getAttribute('aria-label')));
|
||||
expect(joints).toEqual(REVOLUTE.map((name) => `${name} 角度`));
|
||||
expect(productConsole(errors)).toEqual([]);
|
||||
});
|
||||
Reference in New Issue
Block a user