2026-06-10 14:10:25 +00:00
|
|
|
import { describe, expect, test } from 'bun:test'
|
|
|
|
|
|
|
|
|
|
import { SceneGraph } from '@open-pencil/core'
|
|
|
|
|
import { FigmaAPI } from '@open-pencil/core/figma-api'
|
|
|
|
|
import { nodeProxyToJSON } from '@open-pencil/core/figma-api/serialization'
|
2026-09-01 08:57:36 +00:00
|
|
|
import { setInstanceOverride } from '@open-pencil/scene-graph'
|
2026-06-10 14:10:25 +00:00
|
|
|
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
import { getNodeOrThrow } from '#tests/helpers/assert'
|
|
|
|
|
|
2026-06-10 14:10:25 +00:00
|
|
|
function pageId(graph: SceneGraph): string {
|
|
|
|
|
return graph.getPages()[0].id
|
|
|
|
|
}
|
|
|
|
|
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
/** Narrows a serialized `nodeProxyToJSON` member, which the serializer types as `unknown`. */
|
|
|
|
|
function asRecord(value: unknown, label: string): Record<string, unknown> {
|
|
|
|
|
if (typeof value !== 'object' || value === null) {
|
|
|
|
|
throw new Error(`${label} was expected to be an object`)
|
|
|
|
|
}
|
|
|
|
|
return Object.fromEntries(Object.entries(value))
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-10 14:10:25 +00:00
|
|
|
function setupColorVars(graph: SceneGraph, ...ids: string[]): void {
|
|
|
|
|
graph.addCollection({
|
|
|
|
|
id: 'col1',
|
|
|
|
|
name: 'Colors',
|
|
|
|
|
modes: [{ modeId: 'm1', name: 'Light' }],
|
|
|
|
|
defaultModeId: 'm1',
|
|
|
|
|
variableIds: []
|
|
|
|
|
})
|
|
|
|
|
for (const id of ids) {
|
|
|
|
|
graph.addVariable({
|
|
|
|
|
id,
|
|
|
|
|
name: `Var ${id}`,
|
|
|
|
|
type: 'COLOR',
|
|
|
|
|
collectionId: 'col1',
|
|
|
|
|
valuesByMode: { m1: { r: 0.5, g: 0.5, b: 0.5, a: 1 } },
|
|
|
|
|
description: '',
|
|
|
|
|
hiddenFromPublishing: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── boundVariables sync from component to instance ──────────────────────
|
|
|
|
|
|
|
|
|
|
describe('INSTANCE_SYNC_PROPS includes boundVariables', () => {
|
|
|
|
|
function setupGraph(): SceneGraph {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
graph.addCollection({
|
|
|
|
|
id: 'col1',
|
|
|
|
|
name: 'Colors',
|
|
|
|
|
modes: [{ modeId: 'm1', name: 'Light' }],
|
|
|
|
|
defaultModeId: 'm1',
|
|
|
|
|
variableIds: []
|
|
|
|
|
})
|
|
|
|
|
graph.addVariable({
|
|
|
|
|
id: 'v1',
|
|
|
|
|
name: 'Primary',
|
|
|
|
|
type: 'COLOR',
|
|
|
|
|
collectionId: 'col1',
|
|
|
|
|
valuesByMode: { m1: { r: 1, g: 0, b: 0, a: 1 } },
|
|
|
|
|
description: '',
|
|
|
|
|
hiddenFromPublishing: false
|
|
|
|
|
})
|
|
|
|
|
graph.addVariable({
|
|
|
|
|
id: 'v2',
|
|
|
|
|
name: 'Secondary',
|
|
|
|
|
type: 'COLOR',
|
|
|
|
|
collectionId: 'col1',
|
|
|
|
|
valuesByMode: { m1: { r: 0, g: 0, b: 1, a: 1 } },
|
|
|
|
|
description: '',
|
|
|
|
|
hiddenFromPublishing: false
|
|
|
|
|
})
|
|
|
|
|
return graph
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('syncInstances propagates boundVariables from component to instance', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const page = pageId(graph)
|
|
|
|
|
|
|
|
|
|
const component = graph.createNode('COMPONENT', page, {
|
|
|
|
|
name: 'Button',
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 40
|
|
|
|
|
})
|
|
|
|
|
const child = graph.createNode('RECTANGLE', component.id, {
|
|
|
|
|
name: 'Bg',
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 40,
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Bind variable on component child
|
|
|
|
|
graph.bindVariable(child.id, 'fills/0/color', 'v1')
|
|
|
|
|
|
|
|
|
|
// Create instance
|
|
|
|
|
const instance =
|
|
|
|
|
graph.createInstance(component.id, page) ??
|
|
|
|
|
(() => {
|
|
|
|
|
throw new Error('instance failed')
|
|
|
|
|
})()
|
|
|
|
|
const instanceChild = graph.getChildren(instance.id)[0]
|
|
|
|
|
|
|
|
|
|
// Change component child's binding
|
|
|
|
|
graph.bindVariable(child.id, 'fills/0/color', 'v2')
|
|
|
|
|
// Sync
|
|
|
|
|
graph.syncInstances(component.id)
|
|
|
|
|
|
|
|
|
|
// Instance child should now have the updated binding
|
|
|
|
|
expect(instanceChild.boundVariables['fills/0/color']).toBe('v2')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('synced boundVariables is an independent copy', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const page = pageId(graph)
|
|
|
|
|
|
|
|
|
|
const component = graph.createNode('COMPONENT', page, {
|
|
|
|
|
name: 'Button',
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 40
|
|
|
|
|
})
|
|
|
|
|
const child = graph.createNode('RECTANGLE', component.id, {
|
|
|
|
|
name: 'Bg',
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 40,
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
graph.bindVariable(child.id, 'fills/0/color', 'v1')
|
|
|
|
|
|
|
|
|
|
const instance =
|
|
|
|
|
graph.createInstance(component.id, page) ??
|
|
|
|
|
(() => {
|
|
|
|
|
throw new Error('instance failed')
|
|
|
|
|
})()
|
|
|
|
|
const instanceChild = graph.getChildren(instance.id)[0]
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
const compChild = getNodeOrThrow(graph, child.id)
|
2026-06-10 14:10:25 +00:00
|
|
|
|
|
|
|
|
graph.syncInstances(component.id)
|
|
|
|
|
|
|
|
|
|
// After sync, boundVariables must still be independent objects
|
|
|
|
|
expect(instanceChild.boundVariables).not.toBe(compChild.boundVariables)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('instance override blocks boundVariables sync', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const page = pageId(graph)
|
|
|
|
|
|
|
|
|
|
const component = graph.createNode('COMPONENT', page, {
|
|
|
|
|
name: 'Button',
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 40
|
|
|
|
|
})
|
|
|
|
|
const child = graph.createNode('RECTANGLE', component.id, {
|
|
|
|
|
name: 'Bg',
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 40,
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
graph.bindVariable(child.id, 'fills/0/color', 'v1')
|
|
|
|
|
|
|
|
|
|
const instance =
|
|
|
|
|
graph.createInstance(component.id, page) ??
|
|
|
|
|
(() => {
|
|
|
|
|
throw new Error('instance failed')
|
|
|
|
|
})()
|
|
|
|
|
const instanceChild = graph.getChildren(instance.id)[0]
|
|
|
|
|
|
|
|
|
|
// Set an override to block boundVariables sync
|
2026-09-01 08:57:36 +00:00
|
|
|
setInstanceOverride(instance.instanceOverrides, instance.id, instanceChild.id, 'boundVariables')
|
2026-06-10 14:10:25 +00:00
|
|
|
|
|
|
|
|
// Change component child's binding
|
|
|
|
|
graph.bindVariable(child.id, 'fills/0/color', 'v2')
|
|
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
|
graph.syncInstances(component.id)
|
|
|
|
|
|
|
|
|
|
// Instance child binding should NOT be overwritten (override takes precedence)
|
|
|
|
|
expect(instanceChild.boundVariables['fills/0/color']).toBe('v1')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// ─── bindVariable validation continued ────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
describe('bindVariable validation continued', () => {
|
|
|
|
|
function setupGraph(): SceneGraph {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
graph.addCollection({
|
|
|
|
|
id: 'col1',
|
|
|
|
|
name: 'Colors',
|
|
|
|
|
modes: [{ modeId: 'm1', name: 'Light' }],
|
|
|
|
|
defaultModeId: 'm1',
|
|
|
|
|
variableIds: []
|
|
|
|
|
})
|
|
|
|
|
graph.addVariable({
|
|
|
|
|
id: 'v-float',
|
|
|
|
|
name: 'Spacing',
|
|
|
|
|
type: 'FLOAT',
|
|
|
|
|
collectionId: 'col1',
|
|
|
|
|
valuesByMode: { m1: 16 },
|
|
|
|
|
description: '',
|
|
|
|
|
hiddenFromPublishing: false
|
|
|
|
|
})
|
|
|
|
|
return graph
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('bindVariable rejects unknown field names', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'Rect' })
|
|
|
|
|
expect(() => {
|
|
|
|
|
graph.bindVariable(node.id, 'customPluginField', 'v-float')
|
|
|
|
|
}).toThrow(/Unknown binding field/)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// ─── unbindVariable removes binding correctly ────────────────────────────
|
|
|
|
|
|
|
|
|
|
describe('unbindVariable', () => {
|
|
|
|
|
function setupGraph(): SceneGraph {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
graph.addCollection({
|
|
|
|
|
id: 'col1',
|
|
|
|
|
name: 'Colors',
|
|
|
|
|
modes: [{ modeId: 'm1', name: 'Light' }],
|
|
|
|
|
defaultModeId: 'm1',
|
|
|
|
|
variableIds: []
|
|
|
|
|
})
|
|
|
|
|
graph.addVariable({
|
|
|
|
|
id: 'v1',
|
|
|
|
|
name: 'Primary',
|
|
|
|
|
type: 'COLOR',
|
|
|
|
|
collectionId: 'col1',
|
|
|
|
|
valuesByMode: { m1: { r: 0.5, g: 0.5, b: 0.5, a: 1 } },
|
|
|
|
|
description: '',
|
|
|
|
|
hiddenFromPublishing: false
|
|
|
|
|
})
|
|
|
|
|
return graph
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('unbindVariable removes the binding from node', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.5, g: 0.5, b: 0.5, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
graph.bindVariable(node.id, 'fills/0/color', 'v1')
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
expect(getNodeOrThrow(graph, node.id).boundVariables['fills/0/color']).toBe('v1')
|
2026-06-10 14:10:25 +00:00
|
|
|
graph.unbindVariable(node.id, 'fills/0/color')
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
expect(getNodeOrThrow(graph, node.id).boundVariables['fills/0/color']).toBeUndefined()
|
2026-06-10 14:10:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('unbindVariable emits node:updated event', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.5, g: 0.5, b: 0.5, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
graph.bindVariable(node.id, 'fills/0/color', 'v1')
|
|
|
|
|
const events: Array<{ nodeId: string; changes: Record<string, unknown> }> = []
|
|
|
|
|
graph.onNodeEvents({
|
|
|
|
|
updated: (nodeId, changes) => events.push({ nodeId, changes })
|
|
|
|
|
})
|
|
|
|
|
graph.unbindVariable(node.id, 'fills/0/color')
|
|
|
|
|
expect(events.length).toBe(1)
|
|
|
|
|
expect(events[0].nodeId).toBe(node.id)
|
|
|
|
|
expect('boundVariables' in events[0].changes).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('unbindVariable on non-existent binding is a no-op', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'Rect' })
|
|
|
|
|
// Should not throw when unbinding a field that was never bound
|
|
|
|
|
expect(() => graph.unbindVariable(node.id, 'opacity')).not.toThrow()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('unbindVariable does not emit event for non-existent binding', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'Rect' })
|
|
|
|
|
const events: Array<{ nodeId: string; changes: Record<string, unknown> }> = []
|
|
|
|
|
graph.onNodeEvents({
|
|
|
|
|
updated: (nodeId, changes) => events.push({ nodeId, changes })
|
|
|
|
|
})
|
|
|
|
|
graph.unbindVariable(node.id, 'opacity')
|
|
|
|
|
expect(events).toHaveLength(0)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// ─── nodeProxyToJSON includes boundVariables ─────────────────────────────
|
|
|
|
|
|
|
|
|
|
describe('nodeProxyToJSON boundVariables', () => {
|
|
|
|
|
test('nodeProxyToJSON includes boundVariables with resolved info', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
setupColorVars(graph, 'v1')
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.5, g: 0.5, b: 0.5, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
graph.bindVariable(node.id, 'fills/0/color', 'v1')
|
|
|
|
|
const api = new FigmaAPI(graph)
|
|
|
|
|
const json = nodeProxyToJSON(graph, api, node.id)
|
|
|
|
|
expect(json.boundVariables).toBeDefined()
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
const bindings = asRecord(json.boundVariables, 'boundVariables')
|
|
|
|
|
expect(bindings['fills/0/color']).toBeDefined()
|
|
|
|
|
const binding = asRecord(bindings['fills/0/color'], 'fills/0/color binding')
|
|
|
|
|
expect(binding.variableId).toBe('v1')
|
|
|
|
|
expect(binding.variableName).toBe('Var v1')
|
2026-06-10 14:10:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('nodeProxyToJSON omits boundVariables when none exist', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'Rect' })
|
|
|
|
|
const api = new FigmaAPI(graph)
|
|
|
|
|
const json = nodeProxyToJSON(graph, api, node.id)
|
|
|
|
|
expect(json.boundVariables).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// ─── Scope expansion: bindVariable range validation tests ────────────────
|
|
|
|
|
|
|
|
|
|
describe('bindVariable out-of-range index validation', () => {
|
|
|
|
|
function setupGraph(): SceneGraph {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
graph.addCollection({
|
|
|
|
|
id: 'col1',
|
|
|
|
|
name: 'Colors',
|
|
|
|
|
modes: [{ modeId: 'm1', name: 'Light' }],
|
|
|
|
|
defaultModeId: 'm1',
|
|
|
|
|
variableIds: []
|
|
|
|
|
})
|
|
|
|
|
graph.addVariable({
|
|
|
|
|
id: 'v1',
|
|
|
|
|
name: 'Primary',
|
|
|
|
|
type: 'COLOR',
|
|
|
|
|
collectionId: 'col1',
|
|
|
|
|
valuesByMode: { m1: { r: 0.5, g: 0.5, b: 0.5, a: 1 } },
|
|
|
|
|
description: '',
|
|
|
|
|
hiddenFromPublishing: false
|
|
|
|
|
})
|
|
|
|
|
return graph
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('bindVariable rejects index beyond current fills length', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.1, g: 0.1, b: 0.1, a: 1 }, visible: true, opacity: 1 },
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.2, g: 0.2, b: 0.2, a: 1 }, visible: true, opacity: 1 }
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
// Node has 2 fills (indices 0, 1). Index 5 is out of range.
|
|
|
|
|
expect(() => {
|
|
|
|
|
graph.bindVariable(node.id, 'fills/5/color', 'v1')
|
|
|
|
|
}).toThrow(/out of range/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('bindVariable rejects next-index binding (index == currentLength)', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.1, g: 0.1, b: 0.1, a: 1 }, visible: true, opacity: 1 },
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.2, g: 0.2, b: 0.2, a: 1 }, visible: true, opacity: 1 }
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
// Node has 2 fills (indices 0, 1). Index 2 is out of range (index >= length).
|
|
|
|
|
expect(() => {
|
|
|
|
|
graph.bindVariable(node.id, 'fills/2/color', 'v1')
|
|
|
|
|
}).toThrow(/out of range/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('bindVariable rejects binding to empty fills array (index 0, length 0)', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: []
|
|
|
|
|
})
|
|
|
|
|
// No fills exist. Index 0 is out of range (0 >= 0).
|
|
|
|
|
expect(() => {
|
|
|
|
|
graph.bindVariable(node.id, 'fills/0/color', 'v1')
|
|
|
|
|
}).toThrow(/out of range/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('bindVariable rejects out-of-range stroke index', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
strokes: [
|
|
|
|
|
{
|
|
|
|
|
type: 'SOLID',
|
|
|
|
|
color: { r: 0, g: 0, b: 0, a: 1 },
|
|
|
|
|
visible: true,
|
|
|
|
|
opacity: 1,
|
|
|
|
|
weight: 1,
|
|
|
|
|
align: 'INSIDE'
|
|
|
|
|
}
|
|
|
|
|
]
|
2026-06-10 14:10:25 +00:00
|
|
|
})
|
|
|
|
|
// Node has 1 stroke. Index 3 is out of range.
|
|
|
|
|
expect(() => {
|
|
|
|
|
graph.bindVariable(node.id, 'strokes/3/color', 'v1')
|
|
|
|
|
}).toThrow(/out of range/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('bindVariable rejects unknown field names', () => {
|
|
|
|
|
const graph = setupGraph()
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'Rect' })
|
|
|
|
|
expect(() => {
|
|
|
|
|
graph.bindVariable(node.id, 'someRandomField', 'v1')
|
|
|
|
|
}).toThrow(/Unknown binding field/)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// ─── cleanupStaleBindings handles any indexed sub-path ──────────────────────
|
|
|
|
|
|
|
|
|
|
describe('cleanupStaleBindings handles any indexed sub-path', () => {
|
|
|
|
|
test('cleans up fills/N/something bindings when fills shrink past the index', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
setupColorVars(graph, 'v1')
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.1, g: 0.1, b: 0.1, a: 1 }, visible: true, opacity: 1 },
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.2, g: 0.2, b: 0.2, a: 1 }, visible: true, opacity: 1 }
|
|
|
|
|
]
|
|
|
|
|
})
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
const n = getNodeOrThrow(graph, node.id)
|
2026-06-10 14:10:25 +00:00
|
|
|
// Bind a hypothetical non-color sub-path at index 1
|
|
|
|
|
n.boundVariables['fills/1/somethingElse'] = 'v1'
|
|
|
|
|
|
|
|
|
|
// Remove all fills — index 1 is now beyond the array (1 > 0)
|
|
|
|
|
graph.updateNode(node.id, { fills: [] })
|
|
|
|
|
|
|
|
|
|
// fills/1/somethingElse binding must be removed (index 1 > length 0)
|
|
|
|
|
expect(n.boundVariables['fills/1/somethingElse']).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('fills/0/color binding is cleaned up when fills shrink to empty', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
setupColorVars(graph, 'v1')
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.1, g: 0.1, b: 0.1, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
graph.bindVariable(node.id, 'fills/0/color', 'v1')
|
|
|
|
|
|
|
|
|
|
// Shrink fills to empty — fills/0/color must be removed (0 >= 0 is true)
|
|
|
|
|
graph.updateNode(node.id, { fills: [] })
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
expect(getNodeOrThrow(graph, node.id).boundVariables['fills/0/color']).toBeUndefined()
|
2026-06-10 14:10:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('malformed non-numeric indexed keys are cleaned up on fills change', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
setupColorVars(graph, 'v1')
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.1, g: 0.1, b: 0.1, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
const n = getNodeOrThrow(graph, node.id)
|
2026-06-10 14:10:25 +00:00
|
|
|
// Simulate a malformed binding key from legacy data — non-numeric index portion
|
|
|
|
|
n.boundVariables['fills/blendMode'] = 'v1'
|
|
|
|
|
|
|
|
|
|
// Any fills change triggers cleanup — malformed key must be removed
|
|
|
|
|
graph.updateNode(node.id, {
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.2, g: 0.2, b: 0.2, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
expect(n.boundVariables['fills/blendMode']).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('negative indexed keys are cleaned up on fills change', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
setupColorVars(graph, 'v1')
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.1, g: 0.1, b: 0.1, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
const n = getNodeOrThrow(graph, node.id)
|
2026-06-10 14:10:25 +00:00
|
|
|
// Simulate a malformed binding key from legacy data — negative index
|
|
|
|
|
n.boundVariables['fills/-1/color'] = 'v1'
|
|
|
|
|
|
|
|
|
|
// Any fills change triggers cleanup — negative index must be removed
|
|
|
|
|
graph.updateNode(node.id, {
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.2, g: 0.2, b: 0.2, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
|
|
|
|
expect(n.boundVariables['fills/-1/color']).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// ─── cleanupStaleBindings includes boundVariables in changes payload ──────
|
|
|
|
|
|
|
|
|
|
describe('cleanupStaleBindings includes boundVariables in changes payload', () => {
|
|
|
|
|
test('updateNode emits boundVariables in changes when stale bindings are cleaned', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
setupColorVars(graph, 'v1', 'v2')
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.1, g: 0.1, b: 0.1, a: 1 }, visible: true, opacity: 1 },
|
|
|
|
|
{ type: 'SOLID', color: { r: 0.2, g: 0.2, b: 0.2, a: 1 }, visible: true, opacity: 1 }
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
graph.bindVariable(node.id, 'fills/1/color', 'v2')
|
|
|
|
|
|
|
|
|
|
const events: Array<{ nodeId: string; changes: Record<string, unknown> }> = []
|
|
|
|
|
graph.onNodeEvents({
|
|
|
|
|
updated: (nodeId, changes) => events.push({ nodeId, changes })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
graph.updateNode(node.id, { fills: [] })
|
|
|
|
|
|
|
|
|
|
const updateEvent = events.find((e) => e.nodeId === node.id)
|
|
|
|
|
expect(updateEvent).toBeDefined()
|
|
|
|
|
if (updateEvent) {
|
|
|
|
|
expect('boundVariables' in updateEvent.changes).toBe(true)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// ─── bindVariable creates new reference (immutability) ──────────────────
|
|
|
|
|
|
|
|
|
|
describe('bindVariable creates new boundVariables reference', () => {
|
|
|
|
|
test('binding a variable replaces the boundVariables object reference', () => {
|
|
|
|
|
const graph = new SceneGraph()
|
|
|
|
|
setupColorVars(graph, 'v1')
|
|
|
|
|
const node = graph.createNode('RECTANGLE', pageId(graph), {
|
|
|
|
|
name: 'Rect',
|
|
|
|
|
fills: [{ type: 'SOLID', color: { r: 0.5, g: 0.5, b: 0.5, a: 1 }, visible: true, opacity: 1 }]
|
|
|
|
|
})
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
const originalBV = getNodeOrThrow(graph, node.id).boundVariables
|
2026-06-10 14:10:25 +00:00
|
|
|
graph.bindVariable(node.id, 'fills/0/color', 'v1')
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
const newBV = getNodeOrThrow(graph, node.id).boundVariables
|
2026-06-10 14:10:25 +00:00
|
|
|
expect(newBV).not.toBe(originalBV)
|
|
|
|
|
})
|
|
|
|
|
})
|