Files
scriptc/packages/compiler/test/node-pin.test.ts
T
Chris Tate 8c3b1f9e60 Add the zlib stream classes
Deflate, Inflate, Gzip, Gunzip, DeflateRaw, InflateRaw and Unzip, from
createGzip() and the other factories or new zlib.Gzip(options), are
runtime Transform streams over zlib.

- scr_zlib.c gains a step engine that follows Node's ZlibContext: lazy
  init, Unzip's gzip-magic detection, the dictionary retry, Gunzip's
  multi-member loop, and Node's error messages, codes and errno.
- scr_zlib_stream.c, linked when a program uses zlib and streams, runs
  each write as engine steps on the worker pool with Node's output
  chunking, the finish flush from 'prefinish', read-side backpressure,
  flush(), params(), close(), reset() and bytesWritten, and validates
  options in Node's order.
- The fallback declarations add the classes, factories and a
  literal-typed ZlibConstants; zlib.constants and the module-level Z_*
  copies bake as literals. Brotli streams and their factories are refused
  by name.

Corpus programs 5370-5377 cover round trips, chunking and event order,
errors, options, flush and params, stream/promises, constants and
backpressure.
2026-10-14 21:09:51 -05:00

60 lines
2.5 KiB
TypeScript

/* Every Node pin names the same release: .node-version (the
* differential oracle), Dockerfile.sandbox, the compatibility pin, the fetch
* profile, the docs matrix fallback, and the version the compiled binary
* reports. */
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { expect, test } from "vitest";
import { NODE24_FETCH_COMPAT_PROFILE } from "../src/compat/fetch-profile.js";
import { NODE_COMPAT_VERSION } from "../src/frontend/lowering/builtins/process.js";
import { CRYPTO_CONSTANTS } from "../src/frontend/lowering/crypto-tables.js";
import { ZLIB_CONSTANTS } from "../src/frontend/lowering/zlib-constants.js";
const repoRoot = join(import.meta.dirname, "../../..");
const read = (path: string): string => readFileSync(join(repoRoot, path), "utf8");
test("the Node pins agree", () => {
const pinned = read(".node-version").trim();
const compat = JSON.parse(read("internal/compatibility/node-v24.json")) as {
version: string;
tag: string;
};
expect(compat.version).toBe(pinned);
expect(compat.tag).toBe(`v${pinned}`);
expect(read("Dockerfile.sandbox")).toMatch(new RegExp(`^ARG NODE_VERSION=${pinned}$`, "m"));
expect(NODE_COMPAT_VERSION).toBe(pinned);
expect(NODE24_FETCH_COMPAT_PROFILE.target.node).toBe(pinned);
expect(read("packages/runtime/src/scr_lib.c")).toContain(
`#define SCR_NODE_COMPAT_VERSION "${pinned}"`,
);
expect(read("docs/src/components/node-compatibility-matrix.tsx")).toContain(
`snapshot?.nodeVersion ?? "${pinned}"`,
);
});
test("the crypto.constants declaration matches the baked table", () => {
const dts = read("packages/compiler/ambient/scriptc-node-fallback.d.ts");
const start = dts.indexOf("export interface CryptoConstants {");
const body = dts.slice(start, dts.indexOf("\n }\n", start));
const declared = Object.fromEntries(
[...body.matchAll(/readonly (\w+): (-?\d+|"[^"]*");/g)].map(([, name, value]) => [
name!,
JSON.parse(value!) as number | string,
]),
);
expect(declared).toEqual(CRYPTO_CONSTANTS);
});
test("the zlib.constants declaration matches the baked table", () => {
const dts = read("packages/compiler/ambient/scriptc-node-fallback.d.ts");
const start = dts.indexOf("export interface ZlibConstants {");
const body = dts.slice(start, dts.indexOf("\n }\n", start));
const declared = Object.fromEntries(
[...body.matchAll(/readonly (\w+): (-?\d+|number);/g)].map(([, name, value]) => [
name!,
value === "number" ? Infinity : Number(value),
]),
);
expect(declared).toEqual(ZLIB_CONSTANTS);
});