Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2de125352 |
No files matched your search
@@ -14,6 +14,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { SshPasswordPrompt } from "./auth.ts";
|
||||
import {
|
||||
buildSupervisedSshTunnelArgs,
|
||||
buildRemoteLaunchScript,
|
||||
buildRemotePairingScript,
|
||||
buildRemoteStopScript,
|
||||
@@ -89,6 +90,50 @@ function commandArgs(command: ChildProcess.Command): ReadonlyArray<string> {
|
||||
}
|
||||
|
||||
describe("ssh tunnel scripts", () => {
|
||||
it("disables connection multiplexing for the supervised port-forward command", () => {
|
||||
const target = {
|
||||
alias: "devbox",
|
||||
hostname: "devbox.example.com",
|
||||
username: "julius",
|
||||
port: 2222,
|
||||
} as const;
|
||||
|
||||
assert.deepEqual(
|
||||
buildSupervisedSshTunnelArgs({
|
||||
target,
|
||||
batchMode: "no",
|
||||
localPort: 41_773,
|
||||
remotePort: 3_773,
|
||||
hostSpec: "julius@devbox",
|
||||
}),
|
||||
[
|
||||
"-o",
|
||||
"BatchMode=no",
|
||||
"-o",
|
||||
"ConnectTimeout=10",
|
||||
"-p",
|
||||
"2222",
|
||||
"-o",
|
||||
"ControlMaster=no",
|
||||
"-o",
|
||||
"ControlPath=none",
|
||||
"-o",
|
||||
"ControlPersist=no",
|
||||
"-o",
|
||||
"ExitOnForwardFailure=yes",
|
||||
"-o",
|
||||
"ServerAliveInterval=15",
|
||||
"-o",
|
||||
"ServerAliveCountMax=3",
|
||||
"-n",
|
||||
"-N",
|
||||
"-L",
|
||||
"41773:127.0.0.1:3773",
|
||||
"julius@devbox",
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
it("builds the remote t3 runner with npx and npm fallbacks", () => {
|
||||
const script = buildRemoteT3RunnerScript({ nodeEngineRange: TEST_NODE_ENGINE_RANGE });
|
||||
|
||||
@@ -382,6 +427,17 @@ describe("ssh tunnel scripts", () => {
|
||||
const first = yield* manager.ensureEnvironment(target);
|
||||
assert.equal(first.httpBaseUrl, "http://127.0.0.1:41773/");
|
||||
|
||||
const firstTunnelArgs = spawnedCommands.find((args) => args.includes("-N"));
|
||||
assert.isDefined(firstTunnelArgs);
|
||||
assert.include(firstTunnelArgs, "ControlMaster=no");
|
||||
assert.include(firstTunnelArgs, "ControlPath=none");
|
||||
assert.include(firstTunnelArgs, "ControlPersist=no");
|
||||
for (const args of spawnedCommands.filter((entry) => !entry.includes("-N"))) {
|
||||
assert.notInclude(args, "ControlMaster=no");
|
||||
assert.notInclude(args, "ControlPath=none");
|
||||
assert.notInclude(args, "ControlPersist=no");
|
||||
}
|
||||
|
||||
yield* manager.disconnectEnvironment(target);
|
||||
assert.equal(tunnelKillCount, 1);
|
||||
assert.equal(stopCommandCount, 1);
|
||||
|
||||
+38
-15
@@ -917,6 +917,38 @@ const reserveLocalTunnelPort = Effect.fn("ssh/tunnel.reserveLocalTunnelPort")(fu
|
||||
return yield* net.reserveLoopbackPort();
|
||||
});
|
||||
|
||||
export function buildSupervisedSshTunnelArgs(input: {
|
||||
readonly target: DesktopSshEnvironmentTarget;
|
||||
readonly batchMode: "yes" | "no";
|
||||
readonly localPort: number;
|
||||
readonly remotePort: number;
|
||||
readonly hostSpec: string;
|
||||
}): ReadonlyArray<string> {
|
||||
return [
|
||||
...baseSshArgs(input.target, { batchMode: input.batchMode }),
|
||||
// This process owns the tunnel lifecycle. Inherited ControlMaster settings
|
||||
// can otherwise hand the forward to an existing master and let `ssh -N`
|
||||
// exit while the manager believes it still supervises the connection.
|
||||
"-o",
|
||||
"ControlMaster=no",
|
||||
"-o",
|
||||
"ControlPath=none",
|
||||
"-o",
|
||||
"ControlPersist=no",
|
||||
"-o",
|
||||
"ExitOnForwardFailure=yes",
|
||||
"-o",
|
||||
"ServerAliveInterval=15",
|
||||
"-o",
|
||||
"ServerAliveCountMax=3",
|
||||
"-n",
|
||||
"-N",
|
||||
"-L",
|
||||
`${input.localPort}:127.0.0.1:${input.remotePort}`,
|
||||
input.hostSpec,
|
||||
];
|
||||
}
|
||||
|
||||
const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input: {
|
||||
readonly key: string;
|
||||
readonly resolvedTarget: DesktopSshEnvironmentTarget;
|
||||
@@ -956,22 +988,13 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
}),
|
||||
),
|
||||
);
|
||||
const args = [
|
||||
...baseSshArgs(input.resolvedTarget, {
|
||||
batchMode: input.authOptions.batchMode ?? "no",
|
||||
}),
|
||||
"-o",
|
||||
"ExitOnForwardFailure=yes",
|
||||
"-o",
|
||||
"ServerAliveInterval=15",
|
||||
"-o",
|
||||
"ServerAliveCountMax=3",
|
||||
"-n",
|
||||
"-N",
|
||||
"-L",
|
||||
`${input.localPort}:127.0.0.1:${input.remotePort}`,
|
||||
const args = buildSupervisedSshTunnelArgs({
|
||||
target: input.resolvedTarget,
|
||||
batchMode: input.authOptions.batchMode ?? "no",
|
||||
localPort: input.localPort,
|
||||
remotePort: input.remotePort,
|
||||
hostSpec,
|
||||
];
|
||||
});
|
||||
const sshCommand = yield* resolveSshCommand;
|
||||
const tunnelCommand = [sshCommand, ...args];
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
createStagePatchedDependencies,
|
||||
createBuildConfig,
|
||||
DESKTOP_ASAR_UNPACK,
|
||||
DESKTOP_AFTER_PACK_HOOK_FILE,
|
||||
InvalidMacPasskeyRpDomainError,
|
||||
InvalidMacPasskeyPublishableKeyError,
|
||||
InvalidMockUpdateServerPortError,
|
||||
@@ -306,7 +305,6 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
|
||||
it("unpacks the fff shared library for filesystem and FFI access", () => {
|
||||
assert.deepStrictEqual(DESKTOP_ASAR_UNPACK, ["node_modules/@ff-labs/fff-bin-*/**/*"]);
|
||||
assert.equal(DESKTOP_AFTER_PACK_HOOK_FILE, "desktop-after-pack.ts");
|
||||
});
|
||||
|
||||
it.effect("preserves both Linux icon resize failures with structural context", () => {
|
||||
@@ -491,11 +489,9 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
false,
|
||||
undefined,
|
||||
undefined,
|
||||
"C:\\stage\\desktop-after-pack.ts",
|
||||
);
|
||||
|
||||
const win = config.win as Record<string, unknown>;
|
||||
assert.equal(config.afterPack, "C:\\stage\\desktop-after-pack.ts");
|
||||
assert.equal(win.icon, "icon.ico");
|
||||
assert.equal(win.signAndEditExecutable, true);
|
||||
assert.notProperty(win, "azureSignOptions");
|
||||
|
||||
@@ -580,7 +580,6 @@ interface StagePackageJson {
|
||||
|
||||
export const STAGE_INSTALL_ARGS = ["install", "--prod"] as const;
|
||||
export const DESKTOP_ASAR_UNPACK = ["node_modules/@ff-labs/fff-bin-*/**/*"] as const;
|
||||
export const DESKTOP_AFTER_PACK_HOOK_FILE = "desktop-after-pack.ts";
|
||||
|
||||
export interface MacPasskeySigningConfiguration {
|
||||
readonly appId: string;
|
||||
@@ -1386,7 +1385,6 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
readonly provisioningProfilePath: string;
|
||||
}
|
||||
| undefined,
|
||||
afterPackHookPath?: string,
|
||||
) {
|
||||
const buildConfig: Record<string, unknown> = {
|
||||
appId: DESKTOP_APP_ID,
|
||||
@@ -1409,7 +1407,6 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
// files through the asar (transparently redirected to the unpacked copy), so
|
||||
// there's no duplication.
|
||||
asarUnpack: [...DESKTOP_ASAR_UNPACK, "apps/server/dist/**", "**/node_modules/**"],
|
||||
...(afterPackHookPath ? { afterPack: afterPackHookPath } : {}),
|
||||
};
|
||||
const updateChannel = resolveDesktopUpdateChannel(version);
|
||||
const publishConfig = yield* resolveGitHubPublishConfig(updateChannel);
|
||||
@@ -1779,7 +1776,6 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
provisioningProfilePath: macPasskeySigning.provisioningProfilePath,
|
||||
}
|
||||
: undefined,
|
||||
path.join(stageAppDir, DESKTOP_AFTER_PACK_HOOK_FILE),
|
||||
),
|
||||
dependencies: stageDependencies,
|
||||
devDependencies: {
|
||||
@@ -1788,10 +1784,6 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
};
|
||||
|
||||
const stagePackageJsonString = yield* encodeJsonString(stagePackageJson);
|
||||
yield* fs.copyFile(
|
||||
path.join(repoRoot, "scripts", DESKTOP_AFTER_PACK_HOOK_FILE),
|
||||
path.join(stageAppDir, DESKTOP_AFTER_PACK_HOOK_FILE),
|
||||
);
|
||||
yield* fs.writeFileString(path.join(stageAppDir, "package.json"), `${stagePackageJsonString}\n`);
|
||||
const stageWorkspaceConfig = createStageWorkspaceConfig({
|
||||
platform: options.platform,
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off - This fixture verifies the packaging filesystem boundary.
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodeOS from "node:os";
|
||||
import * as NodePath from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import {
|
||||
REQUIRED_UNPACKED_RUNTIME_FILES,
|
||||
resolveUnpackedNodeModules,
|
||||
verifyUnpackedRuntimeFiles,
|
||||
} from "./desktop-after-pack.ts";
|
||||
|
||||
const temporaryDirectories: string[] = [];
|
||||
|
||||
async function createPackagedRuntimeFixture(platform: "darwin" | "linux" | "win32"): Promise<{
|
||||
readonly root: string;
|
||||
readonly context: Parameters<typeof verifyUnpackedRuntimeFiles>[0];
|
||||
readonly unpackedNodeModules: string;
|
||||
}> {
|
||||
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3code-after-pack-"));
|
||||
temporaryDirectories.push(root);
|
||||
const appOutDir = NodePath.join(root, `${platform}-unpacked`);
|
||||
const productFilename = "T3 Code";
|
||||
const context = {
|
||||
appOutDir,
|
||||
electronPlatformName: platform,
|
||||
packager: { appInfo: { productFilename } },
|
||||
};
|
||||
const unpackedNodeModules = NodePath.join(
|
||||
appOutDir,
|
||||
...(platform === "darwin"
|
||||
? [`${productFilename}.app`, "Contents", "Resources"]
|
||||
: ["resources"]),
|
||||
"app.asar.unpacked",
|
||||
"node_modules",
|
||||
);
|
||||
|
||||
for (const relativeFile of REQUIRED_UNPACKED_RUNTIME_FILES) {
|
||||
const filePath = NodePath.join(unpackedNodeModules, ...relativeFile.split("/"));
|
||||
await NodeFSP.mkdir(NodePath.dirname(filePath), { recursive: true });
|
||||
await NodeFSP.writeFile(filePath, `${relativeFile}\n`);
|
||||
}
|
||||
|
||||
return { root, context, unpackedNodeModules };
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryDirectories
|
||||
.splice(0)
|
||||
.map((directory) => NodeFSP.rm(directory, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
describe("desktop afterPack", () => {
|
||||
it.each(["win32", "linux", "darwin"] as const)(
|
||||
"accepts a complete %s unpacked runtime closure",
|
||||
async (platform) => {
|
||||
const fixture = await createPackagedRuntimeFixture(platform);
|
||||
|
||||
expect(resolveUnpackedNodeModules(fixture.context)).toBe(fixture.unpackedNodeModules);
|
||||
await verifyUnpackedRuntimeFiles(fixture.context);
|
||||
},
|
||||
);
|
||||
|
||||
it("fails the build when unpacked runtime payloads are missing", async () => {
|
||||
const fixture = await createPackagedRuntimeFixture("win32");
|
||||
await NodeFSP.rm(NodePath.join(fixture.unpackedNodeModules, "effect/dist/Context.js"));
|
||||
await NodeFSP.rm(NodePath.join(fixture.unpackedNodeModules, "mime/package.json"));
|
||||
|
||||
await expect(verifyUnpackedRuntimeFiles(fixture.context)).rejects.toThrow(
|
||||
/effect\/dist\/Context\.js, mime\/package\.json/u,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,63 +0,0 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off - electron-builder hooks run outside an Effect runtime.
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodePath from "node:path";
|
||||
|
||||
export const REQUIRED_UNPACKED_RUNTIME_FILES = [
|
||||
"effect/package.json",
|
||||
"effect/dist/Context.js",
|
||||
"@effect/platform-node/package.json",
|
||||
"@effect/platform-node/dist/NodeHttpClient.js",
|
||||
"@effect/platform-node-shared/package.json",
|
||||
"mime/package.json",
|
||||
"undici/package.json",
|
||||
] as const;
|
||||
|
||||
interface DesktopAfterPackContext {
|
||||
readonly appOutDir: string;
|
||||
readonly electronPlatformName: string;
|
||||
readonly packager: {
|
||||
readonly appInfo: {
|
||||
readonly productFilename: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveUnpackedNodeModules(context: DesktopAfterPackContext): string {
|
||||
const resourcesDirectory =
|
||||
context.electronPlatformName === "darwin"
|
||||
? NodePath.join(
|
||||
context.appOutDir,
|
||||
`${context.packager.appInfo.productFilename}.app`,
|
||||
"Contents",
|
||||
"Resources",
|
||||
)
|
||||
: NodePath.join(context.appOutDir, "resources");
|
||||
|
||||
return NodePath.join(resourcesDirectory, "app.asar.unpacked", "node_modules");
|
||||
}
|
||||
|
||||
export async function verifyUnpackedRuntimeFiles(context: DesktopAfterPackContext): Promise<void> {
|
||||
const unpackedNodeModules = resolveUnpackedNodeModules(context);
|
||||
const missingFiles: string[] = [];
|
||||
|
||||
for (const relativeFile of REQUIRED_UNPACKED_RUNTIME_FILES) {
|
||||
try {
|
||||
await NodeFSP.access(NodePath.join(unpackedNodeModules, ...relativeFile.split("/")));
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
|
||||
throw error;
|
||||
}
|
||||
missingFiles.push(relativeFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (missingFiles.length > 0) {
|
||||
throw new Error(
|
||||
`Packaged runtime verification failed: app.asar references unpacked runtime files whose payloads are missing: ${missingFiles.join(", ")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function afterPack(context: DesktopAfterPackContext): Promise<void> {
|
||||
await verifyUnpackedRuntimeFiles(context);
|
||||
}
|
||||
Reference in new issue
Block a user