// #199: the production bundle must fail closed before the Optimize WS write,
// keep one exact-candidate preflight result, and preserve the existing green
// Preview → Apply / no-op contract.
import { launch, checkAll, finish } from './serve.mjs';
const { page, browser } = await launch({ width: 920, height: 840 });
const out = await page.evaluate(async () => {
const result = {};
const card = window.__card;
const clone = (value) => structuredClone(value);
const noisy = [[
[0.10000000000000002, 0.1], [0.9, 0.1], [0.9, 0.9], [0.1, 0.9],
]];
const makeSpace = (id, title) => ({
id, title, view_box: [0, 0, 1, 1], cell_cm: 5,
rooms: noisy.map((poly, index) => ({ id: `room-${id || index}`, poly })),
});
const original = {
model_version: 6,
spaces: [
makeSpace('alpha', 'Alpha'),
makeSpace('beta', ''),
makeSpace('', ''),
makeSpace('unsafe', '
'),
],
markers: [], settings: {},
};
const originalLayout = { marker: { s: 'alpha', x: 0.2, y: 0.2 } };
const baseCall = card.hass.callWS.bind(card.hass);
const sent = [];
card.hass = {
...card.hass,
callWS: async (message) => {
if (message.type === 'houseplan/plan/optimize') {
sent.push(clone(message));
return { ok: true, config_rev: 42, layout_rev: 24, can_undo: true };
}
return baseCall(message);
},
};
const setCandidate = (language = 'en') => {
card._config = { ...card._config, language };
card._serverCfg = clone(original);
card._layout = clone(originalLayout);
card._cfgRev = 10;
card._layoutRev = 11;
card._canOptimizeUndo = false;
card._undoKind = null;
card._modelCache = null;
card._frame = null;
card._space = 'alpha';
};
const originalCheck = card._checkOptimizeGeometry.bind(card);
let checks = 0;
let forceRed = true;
card._checkOptimizeGeometry = (config) => {
checks++;
const checked = originalCheck(config);
if (!forceRed) return checked;
const failures = checked.spaces.map((space) => ({
...space, status: 'failed', reason: 'wall-null',
}));
return { ...checked, spaces: failures, failures, ok: false };
};
setCandidate('en');
const beforeRed = {
config: clone(card._serverCfg), layout: clone(card._layout),
configRev: card._cfgRev, layoutRev: card._layoutRev,
canUndo: card._canOptimizeUndo, undoKind: card._undoKind,
};
card._openAlignDialog(); await card.updateComplete;
const englishText = card.renderRoot.querySelector('hp-dialog .body')?.textContent || '';
result.englishFailureNamesThreeAndCountsRest = englishText.includes(
'Could not safely verify the geometry of the following spaces: Alpha, beta, Space 3, and 1 more.',
);
result.englishFailureHasExactHint = englishText.includes(
'Plans were not changed. Update House Plan and try again. If the error persists, attach a space export to the bug report.',
);
result.failureTitleIsEscapedAndFourthNameHidden =
!card.renderRoot.querySelector('#preflight-injection')
&& !englishText.includes('![]()