feat(editor): the canvas tells an engine failure (retry) from a view it cannot draw (no retry)
This commit is contained in:
1 parent
6882c6da4a
commit
c0a5c8c7ce
8 files changed
+182
-36
No files matched your search
@@ -52,12 +52,52 @@ export const R3_GOLDEN_DIR = resolve(FIXTURES_DIR, 'goldens/r3')
|
||||
/** `MAKE_R3_GOLDEN=1` writes the R3 freeze; never set it without the owner's decision once frozen. */
|
||||
export const MAKE_R3_GOLDEN = process.env.MAKE_R3_GOLDEN === '1'
|
||||
|
||||
export function checkR3Golden(name: string, actual: unknown): void {
|
||||
/**
|
||||
* Compares `actual` with the frozen R3 golden `name`. `declared` applies an owner-validated
|
||||
* change to the frozen value before comparing (the file itself never changes); with one,
|
||||
* rewriting the golden is refused.
|
||||
*/
|
||||
export function checkR3Golden(
|
||||
name: string,
|
||||
actual: unknown,
|
||||
declared?: (frozen: unknown) => unknown,
|
||||
): void {
|
||||
const file = resolve(R3_GOLDEN_DIR, name)
|
||||
if (MAKE_R3_GOLDEN && declared) throw new Error(`${name}: frozen, a declared change applies`)
|
||||
if (MAKE_R3_GOLDEN) {
|
||||
mkdirSync(R3_GOLDEN_DIR, { recursive: true })
|
||||
writeFileSync(file, `${JSON.stringify(actual, null, 1)}\n`)
|
||||
return
|
||||
}
|
||||
expect(actual, name).toEqual(JSON.parse(readFileSync(file, 'utf8')))
|
||||
const frozen: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
||||
expect(actual, name).toEqual(declared ? declared(frozen) : frozen)
|
||||
}
|
||||
|
||||
export interface ViewName {
|
||||
id: string
|
||||
fr: string
|
||||
en: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner decision 2026-10-15 (R3): a trigger without a name of its own carries the opened
|
||||
* view's name in each language; the TypeScript freeze carries the French name twice. Applied
|
||||
* to a frozen tree (a deep copy): `data-anno-name-en` takes the English name and the title
|
||||
* text reads "FR / EN". Mirrors `crates/core/tests/common/svg_tree.rs`.
|
||||
*/
|
||||
export function withTriggerNamesPerLanguage(tree: unknown, views: readonly ViewName[]): unknown {
|
||||
const copy = structuredClone(tree)
|
||||
const visit = (node: unknown): void => {
|
||||
if (typeof node !== 'object' || node === null) return
|
||||
const n = node as { attrs?: Record<string, string>; text?: string; children?: unknown[] }
|
||||
const view = views.find((v) => v.id === n.attrs?.['data-anno-opens-view'])
|
||||
if (view && n.attrs?.['data-anno-name-en'] === view.fr) n.attrs['data-anno-name-en'] = view.en
|
||||
for (const v of views) {
|
||||
if (n.text === `${v.fr} / ${v.fr}`) n.text = `${v.fr} / ${v.en}`
|
||||
}
|
||||
n.children?.forEach(visit)
|
||||
if (!('attrs' in n) && !('children' in n)) Object.values(n).forEach(visit)
|
||||
}
|
||||
visit(copy)
|
||||
return copy
|
||||
}
|
||||
Reference in new issue
Block a user