import { test } from "node:test"; import assert from "node:assert/strict"; import type { StreamActionResult } from "../jobs/streamCommand"; import type { StreamActionView } from "./streamAction"; // THE ASSIGNABILITY, ASSERTED AT COMPILE TIME. // // `StreamActionLog` takes a `() => Promise` while every // caller hands it a server action returning `StreamActionResult`. That only // keeps working while the richer dispatch-layer type stays assignable to the // narrower view. If someone renames a field on either side, `tsc --noEmit` // fails HERE, naming both types, instead of failing at the twenty-odd call // sites with a wall of structural mismatch. // // tsc sees this file; the runtime assertion below only exists so the file is a // test rather than a lint the suite would skip. // // BOTH SIDES ARE WRAPPED IN TUPLES, and that is the whole assertion. A bare // `A extends B ? …` DISTRIBUTES over a naked union type parameter: it would // check each member of `StreamActionResult` separately and union the results, // so a member that does not fit contributes `never` — and `true | never` is // `true`. The check would pass while being wrong about exactly the case it // exists to catch. `[A] extends [B]` defeats the distribution and compares the // unions whole. type AssignableTo = [A] extends [B] ? true : never; const _resultIsAView: AssignableTo = true; test("StreamActionResult is assignable to StreamActionView", () => { assert.equal(_resultIsAView, true); });