From c8c30891d53da359b040876e6b36796d02a970d7 Mon Sep 17 00:00:00 2001 From: Sophie Date: Fri, 20 Nov 2026 12:17:35 +0000 Subject: [PATCH] fix typecheck errors TypeScript 6 rejects baseUrl, which stopped every project before its type pass. All five projects (root, shoji_wm, config, overlays, tests) now pass under 6.0.3 and 5.9.3; the runtime fixes are type-only. The tests get their own project with a node:test/assert shim, since @types/node's process clashes with runtime-globals.d.ts. Co-Authored-By: Claude Opus 5.5 --- packages/shoji_wm/src/index.ts | 8 ++++ tests/node-test.d.ts | 59 +++++++++++++++++++++++++++++ tests/output-direct-scanout.test.ts | 11 ++++-- tests/output-vrr.test.ts | 11 ++++-- tests/tsconfig.json | 5 +++ tools/decoration-runtime.ts | 46 ++++++++++++++++------ tsconfig.json | 9 +++-- 7 files changed, 125 insertions(+), 24 deletions(-) create mode 100644 tests/node-test.d.ts create mode 100644 tests/tsconfig.json diff --git a/packages/shoji_wm/src/index.ts b/packages/shoji_wm/src/index.ts index ee8b26d0e..57bd97174 100644 --- a/packages/shoji_wm/src/index.ts +++ b/packages/shoji_wm/src/index.ts @@ -670,6 +670,14 @@ export type { AutomaticEffectInvalidationPolicyHandle, LabelProps, ManagedWindowProps, + ManagedWindowAnimationEasing, + ManagedWindowAnimationMode, + ManagedWindowPoint, + ManagedWindowPointAnimationOptions, + ManagedWindowRect, + ManagedWindowRectAnimationOptions, + ManagedWindowScalarAnimationOptions, + ManagedWindowScheduleAnimationOptions, ManagedWindowState, ManagedWindowTransform, MaybeSignal, diff --git a/tests/node-test.d.ts b/tests/node-test.d.ts new file mode 100644 index 000000000..97936b7bd --- /dev/null +++ b/tests/node-test.d.ts @@ -0,0 +1,59 @@ +// Types for the Node APIs these tests use. They run under `node --import tsx +// --test`, and @types/node cannot be the source: its global `process` clashes +// with the one in packages/shoji_wm/src/runtime-globals.d.ts, which every test +// reaches through the SDK index. The signatures mirror @types/node's, so a +// wrong call fails here as it would there. Add to this file when a test needs +// more. The root tsconfig excludes it, so a `node:` import in the runtime or +// the config still fails to typecheck. + +declare module "node:test" { + type TestFn = () => void | Promise; + type HookFn = () => void | Promise; + + export function test(name: string, fn: TestFn): Promise; + export function beforeEach(fn: HookFn): void; + export function afterEach(fn: HookFn): void; +} + +declare module "node:assert/strict" { + type AssertPredicate = + | RegExp + | (new (...args: any[]) => object) + | ((thrown: unknown) => boolean) + | object + | Error; + + function assert(value: unknown, message?: string | Error): asserts value; + namespace assert { + function ok(value: unknown, message?: string | Error): asserts value; + function equal( + actual: unknown, + expected: T, + message?: string | Error, + ): asserts actual is T; + function deepEqual( + actual: unknown, + expected: T, + message?: string | Error, + ): asserts actual is T; + function throws(block: () => unknown, message?: string | Error): void; + function throws( + block: () => unknown, + error: AssertPredicate, + message?: string | Error, + ): void; + function doesNotThrow(block: () => unknown, message?: string | Error): void; + function rejects( + block: (() => Promise) | Promise, + message?: string | Error, + ): Promise; + function rejects( + block: (() => Promise) | Promise, + error: AssertPredicate, + message?: string | Error, + ): Promise; + } + export default assert; +} + +declare function setImmediate(callback: () => void): unknown; diff --git a/tests/output-direct-scanout.test.ts b/tests/output-direct-scanout.test.ts index 43d9d2562..9e1b3a897 100644 --- a/tests/output-direct-scanout.test.ts +++ b/tests/output-direct-scanout.test.ts @@ -8,15 +8,18 @@ import { test("directScanout reaches the compositor with an output's config, and only when set", () => { updateOutputState({ - "DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] }, - "eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] }, + "DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false }, + "eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false }, }); configureOutputs(() => ({ "DP-1": { mode: "extend", directScanout: false }, "eDP-1": { mode: "extend" }, })); const config = takePendingDisplayConfig(); - assert.equal(config?.["DP-1"]?.directScanout, false); - assert.equal(config?.["eDP-1"]?.directScanout, undefined); + const dp1 = config?.["DP-1"]; + const edp1 = config?.["eDP-1"]; + assert.ok(dp1?.mode === "extend" && edp1?.mode === "extend"); + assert.equal(dp1.directScanout, false); + assert.equal(edp1.directScanout, undefined); assert.equal(JSON.stringify(config?.["eDP-1"]).includes("directScanout"), false); }); diff --git a/tests/output-vrr.test.ts b/tests/output-vrr.test.ts index 7079d3e04..c8e1d582a 100644 --- a/tests/output-vrr.test.ts +++ b/tests/output-vrr.test.ts @@ -8,15 +8,18 @@ import { test("vrr reaches the compositor with an output's config, and only when set", () => { updateOutputState({ - "DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] }, - "eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] }, + "DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false }, + "eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false }, }); configureOutputs(() => ({ "DP-1": { mode: "extend", vrr: true }, "eDP-1": { mode: "extend" }, })); const config = takePendingDisplayConfig(); - assert.equal(config?.["DP-1"]?.vrr, true); - assert.equal(config?.["eDP-1"]?.vrr, undefined); + const dp1 = config?.["DP-1"]; + const edp1 = config?.["eDP-1"]; + assert.ok(dp1?.mode === "extend" && edp1?.mode === "extend"); + assert.equal(dp1.vrr, true); + assert.equal(edp1.vrr, undefined); assert.equal(JSON.stringify(config?.["eDP-1"]).includes("vrr"), false); }); diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 000000000..512d79fca --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../tsconfig.json", + "include": ["*.ts"], + "exclude": [] +} diff --git a/tools/decoration-runtime.ts b/tools/decoration-runtime.ts index 4b1e93ff0..3a89ab8fb 100644 --- a/tools/decoration-runtime.ts +++ b/tools/decoration-runtime.ts @@ -1088,6 +1088,7 @@ interface WindowStateRequestSuccess { workspaceConfig?: WorkspaceConfigPayload; keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] }; pointerConfig?: RuntimePointerConfig; + inputConfig?: { config: InputConfigDraft }; eventConfig?: RuntimeEventConfig; processConfig?: { entries: RuntimeProcessConfigEntry[] }; processActions?: RuntimeProcessSpawnAction[]; @@ -1121,6 +1122,7 @@ interface StartCloseSuccess { workspaceConfig?: WorkspaceConfigPayload; keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] }; pointerConfig?: RuntimePointerConfig; + inputConfig?: { config: InputConfigDraft }; eventConfig?: RuntimeEventConfig; processConfig?: { entries: RuntimeProcessConfigEntry[] }; processActions?: RuntimeProcessSpawnAction[]; @@ -1178,6 +1180,7 @@ interface EvaluateLayerEffectsSuccess { workspaceConfig?: WorkspaceConfigPayload; keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] }; pointerConfig?: RuntimePointerConfig; + inputConfig?: { config: InputConfigDraft }; eventConfig?: RuntimeEventConfig; processConfig?: { entries: RuntimeProcessConfigEntry[] }; processActions?: RuntimeProcessSpawnAction[]; @@ -1207,6 +1210,7 @@ interface LifecycleEnableSuccess { workspaceConfig?: WorkspaceConfigPayload; keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] }; pointerConfig?: RuntimePointerConfig; + inputConfig?: { config: InputConfigDraft }; eventConfig?: RuntimeEventConfig; processConfig?: { entries: RuntimeProcessConfigEntry[] }; processActions?: RuntimeProcessSpawnAction[]; @@ -1656,7 +1660,7 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) { for await (const request of readEmbeddedMessages(embeddedBridge)) { activeRequest = ++requestSerial; try { - if ("displayState" in request) { + if ("displayState" in request && request.displayState) { updateOutputState(request.displayState); } if ("inputState" in request) { @@ -2093,7 +2097,7 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) { const inputConfig = pendingInputConfigPayload(); const processConfig = pendingProcessConfigPayload(); const processActions = pendingProcessActionsPayload(); - const response: EvaluateSuccess = { + const response: StartCloseSuccess = { requestId: request.requestId, ok: true, kind: "startClose", @@ -2565,10 +2569,15 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) { processActions, }); } else { + // The pointerMove and gestureSwipe requests each carry two kinds, + // and narrowing on `kind === a || kind === b` cannot drop a + // union member whose kind is itself a union, so only + // invokeHandler is left here at runtime but not to the checker. + const handlerRequest = request as InvokeHandlerRequest; const result = invokeHandler( effectConfig, - request.windowId, - request.handlerId, + handlerRequest.windowId, + handlerRequest.handlerId, ); const keyBindingConfig = pendingKeyBindingConfigPayload(); const pointerConfig = pendingPointerConfigPayload(); @@ -2580,7 +2589,7 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) { ok: true, kind: "invokeHandler", ...result, - effectTargetId: request.windowId, + effectTargetId: handlerRequest.windowId, displayConfig: pendingDisplayConfigPayload(), workspaceConfig: pendingWorkspaceConfigPayload(), keyBindingConfig, @@ -3191,7 +3200,7 @@ function numericUniformSnapshot( } const flattened: number[] = []; for (const element of value.values) { - const entries = width === 1 ? [element] : element; + const entries: unknown = width === 1 ? [element] : element; if ( !Array.isArray(entries) || entries.length !== width || @@ -3569,6 +3578,7 @@ function evaluateWindowDecorationPolicy( fullscreen: unsupportedAction, unfullscreen: unsupportedAction, focus: unsupportedAction, + unfocus: unsupportedAction, scheduleAnimation: unsupportedAction, cancelAnimation: unsupportedAction, setCloseAnimationDuration: unsupportedAction, @@ -3978,7 +3988,9 @@ function layerUsableAreaChanged( read(layer.outputName) !== snapshot.outputName || read(layer.exclusiveEdge) !== snapshot.exclusiveEdge || currentExclusiveZone.mode !== nextExclusiveZone.mode || - currentExclusiveZone.size !== nextExclusiveZone.size || + (currentExclusiveZone.mode === "exclusive" && + nextExclusiveZone.mode === "exclusive" && + currentExclusiveZone.size !== nextExclusiveZone.size) || currentAnchor.top !== nextAnchor.top || currentAnchor.right !== nextAnchor.right || currentAnchor.bottom !== nextAnchor.bottom || @@ -4075,6 +4087,7 @@ function identityManagedWindow(): ManagedWindowState { idle: false, interactive: true, forceRectSize: false, + tiled: false, zIndex: 0, transform: identityTransform(), }; @@ -4511,6 +4524,7 @@ function processSchedulerTick(tickOutput: string | undefined): { dirtyWindowIds: string[]; dirtyManagedWindowIds?: string[]; dirtyWindowNodeIds?: Record; + dirtyLayerIds?: string[]; dirtyLayerNodeIds?: Record; actions: RuntimeWindowAction[]; nextPollInMs?: number; @@ -5112,7 +5126,7 @@ function countSerializedNodes(node: unknown): number { const record = node as { children?: unknown[] }; return ( 1 + - (record.children ?? []).reduce( + (record.children ?? []).reduce( (sum, child) => sum + countSerializedNodes(child), 0, ) @@ -5327,7 +5341,7 @@ const nativeCachedResponseView = new DataView( function tryWriteNativeCachedResponse( output: EmbeddedRuntimeBridge, - response: EvaluateSuccess, + response: EvaluateSuccess | StartCloseSuccess, updates: PendingRuntimeResponseUpdates, windowId: string, ): boolean { @@ -5383,12 +5397,13 @@ function tryWriteNativeCachedResponse( if (managedWindow.confinePointer) flags |= 1 << 13; const rect = managedWindow.rect; + const origin = read(transform.origin); const fields = [ response.requestId, response.nextPollInMs ?? -1, flags, - transform.origin.x, - transform.origin.y, + origin.x, + origin.y, transform.translateX, transform.translateY, transform.scaleX, @@ -5400,7 +5415,14 @@ function tryWriteNativeCachedResponse( rect?.height ?? 0, managedWindow.zIndex ?? 0, ]; - if (fields.some((value) => !Number.isFinite(value))) { + // The transform is a snapshot of plain numbers; anything else (a signal + // that was never read) falls back to the JSON response. + if ( + !fields.every( + (value): value is number => + typeof value === "number" && Number.isFinite(value), + ) + ) { return false; } for (let index = 0; index < fields.length; index++) { diff --git a/tsconfig.json b/tsconfig.json index bd9c0ab05..9d6f566d0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,16 +7,17 @@ "jsxImportSource": "shoji_wm", "strict": true, "verbatimModuleSyntax": true, + "allowImportingTsExtensions": true, "noEmit": true, "types": [], - "baseUrl": ".", "paths": { "shoji_wm": [ - "packages/shoji_wm/src/index.ts" + "./packages/shoji_wm/src/index.ts" ], "shoji_wm/*": [ - "packages/shoji_wm/src/*" + "./packages/shoji_wm/src/*" ] } - } + }, + "exclude": ["node_modules", "target", "docs", "tests/*.test.ts", "tests/node-test.d.ts"] }