From 1b27505ca6f3815b0eeb7df7337db74d61903fba Mon Sep 17 00:00:00 2001 From: Carlos Ravelo Date: Wed, 4 Nov 2026 02:47:34 -0500 Subject: [PATCH] Convert remote runtime tests to TypeScript --- ...-package-and-qualify-remote-ssh-support.md | 2 +- scripts/bun-test-files.json | 2 +- .../{runtime.test.js => runtime.test.ts} | 44 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) rename src/shared/remote/{runtime.test.js => runtime.test.ts} (96%) diff --git a/docs/plans/remote-ssh-development/11-package-and-qualify-remote-ssh-support.md b/docs/plans/remote-ssh-development/11-package-and-qualify-remote-ssh-support.md index 992aeab32..78aed4821 100644 --- a/docs/plans/remote-ssh-development/11-package-and-qualify-remote-ssh-support.md +++ b/docs/plans/remote-ssh-development/11-package-and-qualify-remote-ssh-support.md @@ -246,7 +246,7 @@ sha256>/` on the server through the existing preparation protocol. The server ve - Helper module: the manifest parses, has both CPUs for both helpers, and every entry has a 64-hex SHA-256. The laptop path and remote path come from the same function. A cached helper archive with a wrong checksum is rejected. - Remote helper installation: run the preparation protocol's Python source locally against a disposable HOME, as the - existing `runtime.test.js` does. A first run installs the helper, and a second run reuses it without reading bytes. + existing `runtime.test.ts` does. A first run installs the helper, and a second run reuses it without reading bytes. An abandoned stage is repaired. A checksum mismatch leaves no installed file. - Supervisor `PATH`: a test starts the supervisor entry with a disposable HOME that contains the private helpers. It fails unless the started view's environment has them first on `PATH`, and unless a missing helper stops startup with diff --git a/scripts/bun-test-files.json b/scripts/bun-test-files.json index e9590e3e7..03850e119 100644 --- a/scripts/bun-test-files.json +++ b/scripts/bun-test-files.json @@ -379,7 +379,7 @@ "src/shared/remote/remote-runtime-workflows-records-reads.test.ts", "src/shared/remote/remote-runtime-workflows-records.test.ts", "src/shared/remote/remote-runtime-workflows-rollover.test.ts", - "src/shared/remote/runtime.test.js", + "src/shared/remote/runtime.test.ts", "src/shared/remote/see-image-usage.test.ts", "src/shared/remote/session-attachment-read.test.ts", "src/shared/remote/session-control.test.ts", diff --git a/src/shared/remote/runtime.test.js b/src/shared/remote/runtime.test.ts similarity index 96% rename from src/shared/remote/runtime.test.js rename to src/shared/remote/runtime.test.ts index 65bb7b6d1..bdbbd4e15 100644 --- a/src/shared/remote/runtime.test.js +++ b/src/shared/remote/runtime.test.ts @@ -24,25 +24,25 @@ import { linuxTarget } from "./runtime.js"; const BUILD_ID = "a".repeat(64); const PROTOCOL = 1; -/** - * @typedef {Object} RuntimeFixture - * @property {string} root - * @property {string} ssh - * @property {string} artifact - * @property {typeof import('./runtime.js')} module - * @property {FixtureMetadata} metadata - */ -/** - * @typedef {Object} FixtureMetadata - * @property {number} schema - * @property {number} protocol - * @property {string} buildId - * @property {string} target - * @property {string} version - * @property {string} sha256 - */ -/** @param {(fixture: RuntimeFixture) => Promise} fn */ -async function fixture(fn) { +import type { ArtifactMetadata } from "../../../scripts/build-metadata.ts"; + +type RuntimeModule = typeof import("./runtime.js"); +interface RuntimeFixture { + root: string; + ssh: string; + artifact: string; + module: RuntimeModule; + metadata: ArtifactMetadata; +} +interface RuntimeTransferHeader extends ArtifactMetadata { + size: number; +} +interface SshRequestLog { + args: string[]; + header: RuntimeTransferHeader; +} + +async function fixture(fn: (fixture: RuntimeFixture) => Promise) { const root = await fsRealpath(await fsMkdtemp(join(tmpdir(), "portable-fixture-"))); try { const shared = join(root, "src/shared"); @@ -70,7 +70,7 @@ async function fixture(fn) { `export const BUILD_ID = '${BUILD_ID}'; export const REMOTE_PROTOCOL_VERSION = ${PROTOCOL};`, ); await fsWriteFile(join(shared, "version.js"), 'export const VERSION = "test-build";'); - const module = await import(toFileUrl(join(remote, "runtime.js")).href); + const module: RuntimeModule = await import(toFileUrl(join(remote, "runtime.js")).href); const ssh = join(root, "ssh"); await fsWriteFile( ssh, @@ -83,7 +83,7 @@ async function fixture(fn) { const content = `#!/bin/sh\n[ "$1" = --remote-preflight ] || exit 2\necho '{"buildId":"${BUILD_ID}","protocol":${PROTOCOL},"version":"test-build"}'\n`; await fsWriteFile(artifact, content); const checksum = await sha256Bytes(new TextEncoder().encode(content)); - const metadata = { + const metadata: ArtifactMetadata = { schema: 1, protocol: PROTOCOL, buildId: BUILD_ID, @@ -371,7 +371,7 @@ if (config.mode !== "reuse") console.log(JSON.stringify({ ok: true, path: "/remo path: "/remote/cache/wld", reused: mode === "reuse", }); - const request = JSON.parse(await fsReadFile(log, "utf8")); + const request: SshRequestLog = JSON.parse(await fsReadFile(log, "utf8")); assertEquals(request.args, ["-T", "--", "example", module.REMOTE_PREPARE_COMMAND]); assertEquals(request.header, { ...metadata, sha256, size: bytes.length }); assertEquals(new Uint8Array(await fsReadFile(transfer)), mode === "reuse" ? new Uint8Array() : bytes);