A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(api): tested means named in code, and one enum stops being three
esengine0819570638c6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d6c0ff117..a9558969a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -110,6 +110,26 @@ published separately; it ships inside the editor.multi-tileset layer, whose singular field is still carried for older scenes,and the particle curves that only one game has authored.+- **"Tested" now means named in a test's CODE, and three mirrors of one enum are+ gone.** The evidence behind every stability promise counted any identifier+ appearing anywhere in a test file — a comment, a `describe()` title. Measured,+ nothing was passing on a comment alone, but `TextOverflow` was **@public** and+ its only appearance was `describe('TextOverflow', …)`: a title is prose, and+ nothing was pinning the enum's shape.++ What it was hiding is why: the tests exercised `TEXT_OVERFLOW_VISIBLE/CLIP/+ ELLIPSIS`, three constants in `layout.ts` whose own comment called them a+ mirror of `TextOverflow`. Three numbers written twice are two answers the day+ somebody reorders them. They are gone; `layout.ts` reads the component's+ spelling, and so do `DrawTextParams.align`, `.verticalAlign` and `.overflow`,+ which had the mapping written out a third time in prose over a bare `number`.++ Tightening those types found nothing wrong — the values were already right,+ the types were just too loose to say so. `Dimension` and `SceneContext` came+ out of the same sweep: one test shadowed the SDK's own `px`/`percent`/`auto`+ with hand-written `{value, unit}` pairs, and one annotated nothing with the+ shape its subject returns.+- **`check-tier-bar` — a tier above `experimental` has to be earned, and nowsomething asks.** `check-subsystem-tiers` holds the table against the tags: averdict and the code carrying it are one answer. Nothing could say whether thediff --git a/sdk/src/ui/text/layout.ts b/sdk/src/ui/text/layout.tsindex a3bbf624c..98ae68b58 100644--- a/sdk/src/ui/text/layout.ts+++ b/sdk/src/ui/text/layout.ts@@ -17,6 +17,7 @@ import type { GlyphAtlas } from './glyph-atlas';import { TEXT_VERTEX_FLOATS } from './submit';import { parseRichText, type TextSegment, type ImageSegment, type RichTextRun } from './rich-text-parser';import { UI_TEXT_BOLD, UI_TEXT_ITALIC } from './text-transform';+import { TextAlign, TextOverflow } from '../core/text';export interface TextLayoutOptions {/** Display font size in px. */@@ -162,8 +163,8 @@ export const TEXT_ALIGN_RIGHT = 2;export interface MultilineTextOptions extends TextLayoutOptions {/** Baseline-to-baseline distance in px. Default fontSizePx * 1.2. */lineHeight?: number;- /** 0 left | 1 center | 2 right. Default left. */- align?: number;+ /** Horizontal alignment, defaulting to left. */+ align?: TextAlign;/** Parse rich markup (`<b>` etc.) per line. */rich?: boolean;/** Base color (used by rich runs without their own color). */@@ -180,17 +181,13 @@ export interface MultilineTextOptions extends TextLayoutOptions {* no box, so nothing can overflow one. */boxHeight?: number;/**- * What a run too big for the box does: 0 visible (default), 1 clip, 2- * ellipsis. Needs `boxHeight` to drop lines and a width to trim one.+ * What a run too big for the box does. Needs `boxHeight` to drop lines and a+ * width to trim one. The component's own spelling, not a mirror of it: three+ * numbers written twice are two answers the day somebody reorders them.*/- overflow?: number;+ overflow?: TextOverflow;}-/** {@link MultilineTextOptions.overflow} — mirrors the TextOverflow const. */-export const TEXT_OVERFLOW_VISIBLE = 0;-export const TEXT_OVERFLOW_CLIP = 1;-export const TEXT_OVERFLOW_ELLIPSIS = 2;-/** The character appended to a line the ellipsis mode cut. */const ELLIPSIS = '\u2026';@@ -305,16 +302,16 @@ export function layoutText(// How many lines the box has room for. Below Visible only, and never zero: a// box too short for one line shows one clipped line rather than nothing, which// is what every layout engine does and what a reader can act on.- const overflow = opts.overflow ?? TEXT_OVERFLOW_VISIBLE;+ const overflow = opts.overflow ?? TextOverflow.Visible;const boxHeight = opts.boxHeight ?? 0;- const maxLines = overflow !== TEXT_OVERFLOW_VISIBLE && boxHeight > 0+ const maxLines = overflow !== TextOverflow.Visible && boxHeight > 0? Math.max(1, Math.floor(boxHeight / lineHeight)): Infinity;- const ellipsis = overflow === TEXT_OVERFLOW_ELLIPSIS;+ const ellipsis = overflow === TextOverflow.Ellipsis;// The width a line may not exceed. maxWidth already wrapped to it, so this is// for the unwrapped case — a single line in a fixed box, which is the one// ellipsis is usually asked for.- const widthLimit = overflow === TEXT_OVERFLOW_VISIBLE ? 0+ const widthLimit = overflow === TextOverflow.Visible ? 0: (opts.maxWidth && opts.maxWidth > 0) ? opts.maxWidth: (opts.boxWidth ?? 0);diff --git a/sdk/src/ui/text/text-renderer.ts b/sdk/src/ui/text/text-renderer.tsindex b0f7222c9..1c35cc1a5 100644--- a/sdk/src/ui/text/text-renderer.ts+++ b/sdk/src/ui/text/text-renderer.ts@@ -16,6 +16,7 @@ import { GlyphAtlas } from './glyph-atlas';import { CanvasGlyphRasterizer, type CanvasGlyphRasterizerOptions } from './glyph-rasterizer';import { NativeGlyphRasterizer } from './native-glyph-rasterizer';import { EngineAtlasPageStore } from './atlas-page-store';+import { TextAlign, TextVerticalAlign, TextOverflow } from '../core/text';import { layoutText, buildGlyphVertices, type LaidGlyph, type RGBA } from './layout';import { submitTextBatch } from './submit';@@ -32,8 +33,9 @@ export interface DrawTextParams {style?: number;/** Parse `<b>/<i>/<color>/<font size>` markup. */richText?: boolean;- /** Horizontal alignment: 0 left | 1 center | 2 right. */- align?: number;+ /** Horizontal alignment. The component's own spelling, so the mapping from+ * number to meaning is written once. */+ align?: TextAlign;/** Baseline-to-baseline distance (px) for multi-line text. */lineHeight?: number;/** Extra advance between glyphs (px). */@@ -42,12 +44,12 @@ export interface DrawTextParams {maxWidth?: number;/** Box width (px) horizontal align positions the block within; 0/undefined = boxless (anchor to origin). */boxWidth?: number;- /** Vertical alignment within boxHeight: 0 top | 1 middle | 2 bottom. */- verticalAlign?: number;+ /** Vertical alignment within boxHeight. */+ verticalAlign?: TextVerticalAlign;/** Box height (px) for vertical alignment; 0/undefined = boxless (anchor to origin). */boxHeight?: number;- /** What a run too big for the box does: 0 visible | 1 clip | 2 ellipsis. */- overflow?: number;+ /** What a run too big for the box does. */+ overflow?: TextOverflow;/*** Drop shadow: an offset, recolored copy of the glyphs drawn behind the fill.* `blur` (px, 0 = hard) spreads that copy into a ring so the shadow reads asdiff --git a/sdk/tests/sceneManager.test.ts b/sdk/tests/sceneManager.test.tsindex 7fdb221dc..efe1dfcfc 100644--- a/sdk/tests/sceneManager.test.ts+++ b/sdk/tests/sceneManager.test.ts@@ -75,7 +75,7 @@ vi.mock('../src/defaults', () => ({},}));-import { SceneManagerState, SceneLoadCancelled, wrapSceneSystem } from '../src/scene/sceneManager';+import { SceneManagerState, SceneLoadCancelled, wrapSceneSystem, type SceneContext } from '../src/scene/sceneManager';import { SceneOwner, Sprite, SpineAnimation, BitmapText, TilemapLayer } from '../src/ecs/component';import { loadSceneWithAssets } from '../src/scene/scene';import { registerDrawCallback, unregisterDrawCallback } from '../src/render/customDraw';@@ -969,7 +969,9 @@ describe('SceneManager', () => {describe('SceneContext', () => {it('spawn() creates entity with SceneOwner', async () => {manager.register({ name: 'level1', data: makeSceneData() });- const ctx = await manager.load('level1');+ // Annotated: this is the shape `load` promises, so a member that+ // moves fails here and not at whatever calls it next.+ const ctx: SceneContext = await manager.load('level1');const entity = ctx.spawn();expect(app.world.spawn).toHaveBeenCalled();diff --git a/sdk/tests/ui-layout-integration.test.ts b/sdk/tests/ui-layout-integration.test.tsindex f38dbe649..2b3d4a266 100644--- a/sdk/tests/ui-layout-integration.test.ts+++ b/sdk/tests/ui-layout-integration.test.ts@@ -20,10 +20,10 @@ import { Transform, Sprite } from '../src/ecs/component';import type { ESEngineModule, CppRegistry } from '../src/wasm';import { loadWasmModule, HAS_WASM } from './helpers/loadWasm';-// ── Dimension literals (unit 0 = Px, 1 = Percent, 2 = Auto) ─────────────────-const px = (v: number) => ({ value: v, unit: 0 });-const pct = (v: number) => ({ value: v, unit: 1 });-const auto = () => ({ value: 0, unit: 2 });+// The SDK's own dimension factories, not hand-written {value, unit} pairs: the+// unit numbers written a second time here are a second answer, and the engine+// this drives reads the first one.+import { px, percent as pct, auto, type Dimension } from '../src/ui/core/dimension';/** A complete UINode value-object (embind requires every member present). */function node(over: Partial<UINodeData> = {}): UINodeData {@@ -45,9 +45,12 @@ function fillNode(): UINodeData {return node({ position: 1, insetLeft: px(0), insetTop: px(0), insetRight: px(0), insetBottom: px(0) });}-/** Fixed-size in-flow box. */+/** Fixed-size in-flow box. Annotated, so a `Dimension` that grew a field or+ * renamed one fails here rather than at whatever reads it next. */function sizedNode(w: number, h: number): UINodeData {- return node({ width: px(w), height: px(h) });+ const width: Dimension = px(w);+ const height: Dimension = px(h);+ return node({ width, height });}/** Fill the parent inset by `n` px on every edge (Absolute). */diff --git a/sdk/tests/ui-text-overflow.test.ts b/sdk/tests/ui-text-overflow.test.tsindex 168b5d851..164243763 100644--- a/sdk/tests/ui-text-overflow.test.ts+++ b/sdk/tests/ui-text-overflow.test.ts@@ -11,10 +11,8 @@ import { describe, it, expect } from 'vitest';import {GlyphAtlas, type GlyphRasterizer, type AtlasPageStore, type RasterGlyph,} from '../src/ui/text/glyph-atlas';-import {- layoutText, measureWidth,- TEXT_OVERFLOW_VISIBLE, TEXT_OVERFLOW_CLIP, TEXT_OVERFLOW_ELLIPSIS,-} from '../src/ui/text/layout';+import { layoutText, measureWidth } from '../src/ui/text/layout';+import { TextOverflow } from '../src/ui/core/text';function makeAtlas(): GlyphAtlas {const rasterizer: GlyphRasterizer = {@@ -50,7 +48,7 @@ const lay = (text: string, opts: Record<string, unknown>) =>describe('TextOverflow', () => {it('Visible keeps every line, however short the box', () => {- const l = lay('one\ntwo\nthree', { boxHeight: LINE, overflow: TEXT_OVERFLOW_VISIBLE });+ const l = lay('one\ntwo\nthree', { boxHeight: LINE, overflow: TextOverflow.Visible });expect(linesOf(l)).toBe(3);});@@ -60,36 +58,36 @@ describe('TextOverflow', () => {});it('Clip keeps only the lines the box has room for', () => {- expect(linesOf(lay('one\ntwo\nthree', { boxHeight: LINE * 2, overflow: TEXT_OVERFLOW_CLIP }))).toBe(2);- expect(linesOf(lay('one\ntwo\nthree', { boxHeight: LINE * 3, overflow: TEXT_OVERFLOW_CLIP }))).toBe(3);+ expect(linesOf(lay('one\ntwo\nthree', { boxHeight: LINE * 2, overflow: TextOverflow.Clip }))).toBe(2);+ expect(linesOf(lay('one\ntwo\nthree', { boxHeight: LINE * 3, overflow: TextOverflow.Clip }))).toBe(3);});it('a box too short for one line still shows one', () => {// Nothing is not an answer a reader can act on, and it is what a rounding// error in the box height would otherwise produce.- expect(linesOf(lay('one\ntwo', { boxHeight: 1, overflow: TEXT_OVERFLOW_CLIP }))).toBe(1);+ expect(linesOf(lay('one\ntwo', { boxHeight: 1, overflow: TextOverflow.Clip }))).toBe(1);});it('no box height means nothing can overflow one', () => {- expect(linesOf(lay('one\ntwo\nthree', { overflow: TEXT_OVERFLOW_CLIP }))).toBe(3);+ expect(linesOf(lay('one\ntwo\nthree', { overflow: TextOverflow.Clip }))).toBe(3);});it('Ellipsis says there is more below, even when the last line fits', () => {// The mark is about the DROPPED lines, not about this line being long —// which is the distinction a reader needs and a width check cannot make.- const l = lay('one\ntwo\nthree', { boxHeight: LINE, overflow: TEXT_OVERFLOW_ELLIPSIS, boxWidth: 400 });+ const l = lay('one\ntwo\nthree', { boxHeight: LINE, overflow: TextOverflow.Ellipsis, boxWidth: 400 });expect(linesOf(l)).toBe(1);expect(l.width).toBeCloseTo(width('one…'), 5);});it('Clip drops the lines and adds no mark', () => {- const l = lay('one\ntwo\nthree', { boxHeight: LINE, overflow: TEXT_OVERFLOW_CLIP, boxWidth: 400 });+ const l = lay('one\ntwo\nthree', { boxHeight: LINE, overflow: TextOverflow.Clip, boxWidth: 400 });expect(l.width).toBeCloseTo(width('one'), 5);});it('a single line too wide for the box is trimmed to fit, ellipsis included', () => {const limit = width('abcde');- const l = lay('abcdefghij', { boxWidth: limit, overflow: TEXT_OVERFLOW_ELLIPSIS });+ const l = lay('abcdefghij', { boxWidth: limit, overflow: TextOverflow.Ellipsis });expect(l.width).toBeLessThanOrEqual(limit + 1e-6);// Trimmed one glyph at a time, so the result is the widest that FITS —// a proportional guess would leave visible slack or overshoot.@@ -98,28 +96,28 @@ describe('TextOverflow', () => {it('Clip trims the same line without a mark, and keeps more of it', () => {const limit = width('abcde');- const clipped = lay('abcdefghij', { boxWidth: limit, overflow: TEXT_OVERFLOW_CLIP });- const ellipsed = lay('abcdefghij', { boxWidth: limit, overflow: TEXT_OVERFLOW_ELLIPSIS });+ const clipped = lay('abcdefghij', { boxWidth: limit, overflow: TextOverflow.Clip });+ const ellipsed = lay('abcdefghij', { boxWidth: limit, overflow: TextOverflow.Ellipsis });expect(clipped.width).toBeLessThanOrEqual(limit + 1e-6);expect(clipped.width).toBeGreaterThan(ellipsed.width);});it('a line that fits is left exactly alone', () => {- const l = lay('abc', { boxWidth: width('abcdefgh'), overflow: TEXT_OVERFLOW_ELLIPSIS });+ const l = lay('abc', { boxWidth: width('abcdefgh'), overflow: TextOverflow.Ellipsis });expect(l.width).toBeCloseTo(width('abc'), 5);});it('wrapping still happens first, and the box then decides how many survive', () => {// maxWidth wraps 'aa aa aa' into three lines; a two-line box keeps two.const l = lay('aa aa aa', {- maxWidth: width('aa') + 1, boxHeight: LINE * 2, overflow: TEXT_OVERFLOW_CLIP,+ maxWidth: width('aa') + 1, boxHeight: LINE * 2, overflow: TextOverflow.Clip,});expect(linesOf(l)).toBe(2);});it('rich text truncates by line, since a run carries its own size', () => {const l = lay('one\n<b>two</b>\nthree', {- rich: true, boxHeight: LINE * 2, overflow: TEXT_OVERFLOW_CLIP,+ rich: true, boxHeight: LINE * 2, overflow: TextOverflow.Clip,});expect(linesOf(l)).toBe(2);});diff --git a/tools/lib/apiEvidence.mjs b/tools/lib/apiEvidence.mjsindex 4813b20d2..c42e46621 100644--- a/tools/lib/apiEvidence.mjs+++ b/tools/lib/apiEvidence.mjs@@ -36,7 +36,17 @@ export function hasDocProse(decl) {return docProseLines(leadingDoc(decl)).length > 0;}-/** Every identifier named anywhere in the SDK's tests. */+/** A `describe('X', …)` title is prose that happens to sit inside a string. */+const TITLE = /\b(?:describe|it|test|bench)(?:\.\w+)*\s*\(\s*(['"`])(?:[^\\]|\\.)*?\1/g;++/**+ * Every identifier a test names IN CODE. Comments and test titles are stripped+ * first: a symbol whose only appearance is `describe('TextOverflow', …)` has+ * nothing pinning its shape, and that one was @public.+ *+ * A string that is not a title still counts — naming a component by its string+ * is how several APIs are called, and a rename breaks that as loudly.+ */export function testedIdentifiers() {const seen = new Set();const skip = (p, name) => name === 'node_modules' || name === 'dist';@@ -44,7 +54,11 @@ export function testedIdentifiers() {walk(join(SDK, 'tests'), collect, skip);function collect(p) {if (!/\.test\.ts$/.test(p)) return;- for (const id of readFileSync(p, 'utf8').match(/[A-Za-z_$][\w$]*/g) ?? []) seen.add(id);+ const code = readFileSync(p, 'utf8')+ .replace(/\/\*[\s\S]*?\*\//g, ' ')+ .split('\n').map((l) => l.replace(/(^|[^:'"`\\\w])\/\/.*$/, '$1')).join('\n')+ .replace(TITLE, (m, q) => m.slice(0, m.indexOf(q)) + q + q);+ for (const id of code.match(/[A-Za-z_$][\w$]*/g) ?? []) seen.add(id);}return seen;}