* 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
161 lines
4.7 KiB
TypeScript
161 lines
4.7 KiB
TypeScript
import { describe, test, expect } from 'bun:test'
|
|
|
|
import { fitCircleArc, isClosedThinCrescent } from '@open-pencil/core/vector'
|
|
import type { Vector, VectorNetwork } from '@open-pencil/scene-graph'
|
|
|
|
import { expectDefined } from '#tests/helpers/assert'
|
|
|
|
function makeAnnularWedge(
|
|
cx: number,
|
|
cy: number,
|
|
rInner: number,
|
|
rOuter: number,
|
|
startDeg: number,
|
|
sweepDeg: number,
|
|
segmentsPerArc: number
|
|
): VectorNetwork {
|
|
const vertices: Vector[] = []
|
|
const segments: VectorNetwork['segments'] = []
|
|
|
|
for (let i = 0; i <= segmentsPerArc; i++) {
|
|
const angle = ((startDeg + (sweepDeg * i) / segmentsPerArc) * Math.PI) / 180
|
|
vertices.push({ x: cx + rOuter * Math.cos(angle), y: cy + rOuter * Math.sin(angle) })
|
|
}
|
|
for (let i = segmentsPerArc; i >= 0; i--) {
|
|
const angle = ((startDeg + (sweepDeg * i) / segmentsPerArc) * Math.PI) / 180
|
|
vertices.push({ x: cx + rInner * Math.cos(angle), y: cy + rInner * Math.sin(angle) })
|
|
}
|
|
|
|
const n = vertices.length
|
|
for (let i = 0; i < n; i++) {
|
|
segments.push({
|
|
start: i,
|
|
end: (i + 1) % n,
|
|
tangentStart: { x: 0, y: 0 },
|
|
tangentEnd: { x: 0, y: 0 }
|
|
})
|
|
}
|
|
|
|
return { vertices, segments, regions: [] }
|
|
}
|
|
|
|
describe('fitCircleArc', () => {
|
|
test('returns null for fewer than 3 points', () => {
|
|
expect(fitCircleArc([])).toBeNull()
|
|
expect(fitCircleArc([{ x: 0, y: 0 }])).toBeNull()
|
|
expect(
|
|
fitCircleArc([
|
|
{ x: 0, y: 0 },
|
|
{ x: 1, y: 0 }
|
|
])
|
|
).toBeNull()
|
|
})
|
|
|
|
test('fits points on a known circle', () => {
|
|
const r = 100
|
|
const pts = []
|
|
for (let i = 0; i <= 10; i++) {
|
|
const angle = (i / 10) * Math.PI
|
|
pts.push({ x: r * Math.cos(angle), y: r * Math.sin(angle) })
|
|
}
|
|
const result = fitCircleArc(pts)
|
|
const arc = expectDefined(result, 'fitted arc')
|
|
expect(arc.r).toBeCloseTo(r, 1)
|
|
expect(arc.cx).toBeCloseTo(0, 1)
|
|
expect(arc.cy).toBeCloseTo(0, 1)
|
|
})
|
|
|
|
test('returns null for collinear points', () => {
|
|
const pts = [
|
|
{ x: 0, y: 0 },
|
|
{ x: 5, y: 0 },
|
|
{ x: 10, y: 0 }
|
|
]
|
|
expect(fitCircleArc(pts)).toBeNull()
|
|
})
|
|
|
|
test('returns null when points do not lie on a single circle', () => {
|
|
const pts = [
|
|
{ x: 0, y: 0 },
|
|
{ x: 50, y: 100 },
|
|
{ x: 100, y: 0 },
|
|
{ x: 50, y: -200 }
|
|
]
|
|
expect(fitCircleArc(pts)).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('isClosedThinCrescent', () => {
|
|
test('detects annular wedge as crescent', () => {
|
|
const network = makeAnnularWedge(0, 0, 80, 100, 0, 180, 5)
|
|
const result = isClosedThinCrescent(network)
|
|
const crescent = expectDefined(result, 'crescent result')
|
|
expect(crescent.ordered.length).toBe(network.vertices.length)
|
|
})
|
|
|
|
test('rejects a simple rectangle (4 vertices)', () => {
|
|
const network: VectorNetwork = {
|
|
vertices: [
|
|
{ x: 0, y: 0 },
|
|
{ x: 100, y: 0 },
|
|
{ x: 100, y: 100 },
|
|
{ x: 0, y: 100 }
|
|
],
|
|
segments: [
|
|
{ start: 0, end: 1, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } },
|
|
{ start: 1, end: 2, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } },
|
|
{ start: 2, end: 3, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } },
|
|
{ start: 3, end: 0, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } }
|
|
],
|
|
regions: []
|
|
}
|
|
expect(isClosedThinCrescent(network)).toBeNull()
|
|
})
|
|
|
|
test('rejects a regular hexagon (thick shape)', () => {
|
|
const vertices = []
|
|
for (let i = 0; i < 6; i++) {
|
|
const angle = (i / 6) * 2 * Math.PI
|
|
vertices.push({ x: 100 * Math.cos(angle), y: 100 * Math.sin(angle) })
|
|
}
|
|
const segments = vertices.map((_, i) => ({
|
|
start: i,
|
|
end: (i + 1) % 6,
|
|
tangentStart: { x: 0, y: 0 },
|
|
tangentEnd: { x: 0, y: 0 }
|
|
}))
|
|
expect(isClosedThinCrescent({ vertices, segments, regions: [] })).toBeNull()
|
|
})
|
|
|
|
test('rejects open path (segments != vertices)', () => {
|
|
const network: VectorNetwork = {
|
|
vertices: [
|
|
{ x: 0, y: 0 },
|
|
{ x: 10, y: 0 },
|
|
{ x: 20, y: 0 }
|
|
],
|
|
segments: [
|
|
{ start: 0, end: 1, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } },
|
|
{ start: 1, end: 2, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } }
|
|
],
|
|
regions: []
|
|
}
|
|
expect(isClosedThinCrescent(network)).toBeNull()
|
|
})
|
|
|
|
test('rejects odd vertex count', () => {
|
|
const network = makeAnnularWedge(0, 0, 80, 100, 0, 180, 4)
|
|
const n = network.vertices.length
|
|
if (n % 2 === 0) {
|
|
network.vertices.push({ x: 999, y: 999 })
|
|
network.segments.push({
|
|
start: n - 1,
|
|
end: n,
|
|
tangentStart: { x: 0, y: 0 },
|
|
tangentEnd: { x: 0, y: 0 }
|
|
})
|
|
}
|
|
expect(isClosedThinCrescent(network)).toBeNull()
|
|
})
|
|
})
|