Files
scriptc/tests/harness/self-hosting-ts7-client.test.ts
Chris Tate 3f66c8e20b Make LLVM the sole production backend
- Remove C emission, debugging options, and automatic backend fallback.
- Complete LLVM lowering and native bootstrap coverage across supported targets.
- Link executables and libraries with precompiled C runtime packs, including iOS and Android.
2026-09-29 20:54:09 -05:00

57 lines
3.3 KiB
TypeScript

import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, test } from "vitest";
import { analyze, compile } from "@scriptc/compiler";
import { runClient } from "./ts7-client-harness.js";
const root = fileURLToPath(new URL("../..", import.meta.url));
const entry = join(root, "tests/fixtures/self-hosting/ts7-client.ts");
const tempRoot = process.platform === "win32" ? tmpdir() : "/tmp";
test("the production TypeScript RPC and filesystem client lowers entirely statically", () => {
const { coverage } = analyze(entry, { dynamic: false });
expect(coverage.preflightFailed).toBe(false);
expect(coverage.stats.statementsTotal).toBeGreaterThan(200);
expect(coverage.stats.statementsFailed, JSON.stringify(coverage.diagnostics)).toBe(0);
expect(coverage.stats.statementsIsland).toBe(0);
expect(coverage.stats.functionsSkipped).toBe(0);
});
for (const backend of ["llvm"] as const) {
test(`native TypeScript client talks directly to the pinned parser/checker (${backend})`, async () => {
const dir = mkdtempSync(join(tempRoot, "scriptc-native-ts7-"));
try {
writeFileSync(join(dir, "disk.ts"), "export const disk = true;\n");
// The callback must hide real content, and an empty virtual file must
// override this invalid disk file instead of falling back to it.
writeFileSync(join(dir, "hidden.ts"), "export const hidden = true;\n");
writeFileSync(join(dir, "empty.ts"), "THIS IS NOT TYPESCRIPT !!!\n");
const built = await compile(entry, {
outDir: dir, outPath: join(dir, process.platform === "win32" ? "client.exe" : "client"),
backend, dynamic: false, optimization: "dev", sanitize: process.env["SCRIPTC_SAN"] === "1",
});
if (!built.ok) throw new Error(built.diagnostics.map((d) => `${d.code}: ${d.message}`).join("\n"));
expect(built.backend).toBe(backend);
const oracle = await runClient(process.execPath, ["--import", "tsx", entry], dir, join(dir, "oracle.json"));
const native = await runClient(built.binaryPath, [], dir, join(dir, "native.json"));
const { surrogateBoundary: oracleSurrogates, semanticSurrogateBoundary: oracleSemanticSurrogates, ...oracleFacts } = JSON.parse(oracle);
const { surrogateBoundary: nativeSurrogates, semanticSurrogateBoundary: nativeSemanticSurrogates, ...nativeFacts } = JSON.parse(native);
// The native runtime's documented UTF-16 limit must surface as an
// explicit AST refusal; replacing a checker name would be corruption.
expect(oracleSurrogates).toBe("preserved");
expect(nativeSurrogates).toBe("refused");
expect(oracleSemanticSurrogates).toBe("preserved");
expect(nativeSemanticSurrogates).toBe("refused");
expect(nativeFacts).toEqual(oracleFacts);
expect(nativeFacts).toEqual({
typeText: "42", symbol: "answer", diagnostics: [2322], echo: true, binaryAst: true, astIdentity: true, astViews: true, checkerFacade: true, checkerSnapshots: true, semanticModel: true, sessionLifecycle: true,
virtualFiles: true, retainedSnapshot: true, serverErrorRecovery: true, protocolFailures: true,
});
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
}