From cebe6977339b3583926035d718d20575b310335e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 17 Apr 2026 15:26:05 -0700 Subject: [PATCH] Fix PR CI failures - use type-only imports required by verbatim module syntax - fix SSH desktop build/typecheck regressions and auth test isolation - tighten browser test selectors for the add-environment dialog Co-authored-by: codex --- apps/desktop/src/sshEnvironment.test.ts | 2 +- apps/desktop/src/sshEnvironment.ts | 42 ++++++++++++------- apps/server/src/server.test.ts | 8 ++-- .../settings/SettingsPanels.browser.tsx | 8 +++- packages/contracts/src/ipc.ts | 3 +- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/apps/desktop/src/sshEnvironment.test.ts b/apps/desktop/src/sshEnvironment.test.ts index 2b4f0cadc8..fe7274b8b9 100644 --- a/apps/desktop/src/sshEnvironment.test.ts +++ b/apps/desktop/src/sshEnvironment.test.ts @@ -5,7 +5,7 @@ import * as Path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; -import { __test, discoverDesktopSshHosts } from "./sshEnvironment"; +import { __test, discoverDesktopSshHosts } from "./sshEnvironment.ts"; const tempDirectories: string[] = []; diff --git a/apps/desktop/src/sshEnvironment.ts b/apps/desktop/src/sshEnvironment.ts index 12a790968c..16a75dc8cb 100644 --- a/apps/desktop/src/sshEnvironment.ts +++ b/apps/desktop/src/sshEnvironment.ts @@ -17,7 +17,7 @@ import type { ExecutionEnvironmentDescriptor, } from "@t3tools/contracts"; -import { waitForHttpReady } from "./backendReadiness"; +import { waitForHttpReady } from "./backendReadiness.ts"; const DEFAULT_REMOTE_PORT = 3773; const REMOTE_PORT_SCAN_WINDOW = 200; @@ -101,13 +101,13 @@ function expandHomePath(input: string, homeDir: string = OS.homedir()): string { function resolveSshConfigIncludePattern( includePattern: string, - directory: string, + _directory: string, homeDir: string = OS.homedir(), ): string { const expandedPattern = expandHomePath(includePattern, homeDir); return Path.isAbsolute(expandedPattern) ? expandedPattern - : Path.resolve(directory, expandedPattern); + : Path.resolve(Path.join(homeDir, ".ssh"), expandedPattern); } function hasSshPattern(value: string): boolean { @@ -147,6 +147,7 @@ function expandGlob(pattern: string): ReadonlyArray { function collectSshConfigAliasesFromFile( filePath: string, visited = new Set(), + homeDir: string = OS.homedir(), ): ReadonlyArray { const resolvedPath = Path.resolve(filePath); if (visited.has(resolvedPath) || !FS.existsSync(resolvedPath)) { @@ -168,9 +169,9 @@ function collectSshConfigAliasesFromFile( const normalizedDirective = directive.toLowerCase(); if (normalizedDirective === "include") { for (const includePattern of rawArgs) { - const resolvedPattern = resolveSshConfigIncludePattern(includePattern, directory); + const resolvedPattern = resolveSshConfigIncludePattern(includePattern, directory, homeDir); for (const includedPath of expandGlob(resolvedPattern)) { - for (const alias of collectSshConfigAliasesFromFile(includedPath, visited)) { + for (const alias of collectSshConfigAliasesFromFile(includedPath, visited, homeDir)) { aliases.add(alias); } } @@ -689,8 +690,8 @@ async function issueRemotePairingToken( ...(input?.batchMode === undefined ? {} : { batchMode: input.batchMode }), ...(input?.interactiveAuth === undefined ? {} : { interactiveAuth: input.interactiveAuth }), }); - const stdout = result.stdout.trim(); - if (!stdout) { + const line = getLastNonEmptyOutputLine(result.stdout); + if (!line) { throw new Error( `SSH pairing did not return a credential. stdout=${JSON.stringify(result.stdout)}`, ); @@ -698,10 +699,10 @@ async function issueRemotePairingToken( let parsed: { credential?: unknown }; try { - parsed = JSON.parse(stdout) as { credential?: unknown }; + parsed = JSON.parse(line) as { credential?: unknown }; } catch (cause) { throw new Error( - `SSH pairing returned unparseable output. stdout=${JSON.stringify(result.stdout)}`, + `SSH pairing returned unparseable output. line=${JSON.stringify(line)} stdout=${JSON.stringify(result.stdout)}`, { cause }, ); } @@ -768,8 +769,13 @@ async function stopTunnel(entry: SshTunnelEntry): Promise { export async function discoverDesktopSshHosts(input?: { readonly homeDir?: string; }): Promise { - const sshDirectory = Path.join(input?.homeDir ?? OS.homedir(), ".ssh"); - const configAliases = collectSshConfigAliasesFromFile(Path.join(sshDirectory, "config")); + const homeDir = input?.homeDir ?? OS.homedir(); + const sshDirectory = Path.join(homeDir, ".ssh"); + const configAliases = collectSshConfigAliasesFromFile( + Path.join(sshDirectory, "config"), + new Set(), + homeDir, + ); const knownHosts = readKnownHostsHostnames(Path.join(sshDirectory, "known_hosts")); const discovered = new Map(); @@ -803,8 +809,11 @@ export class DesktopSshEnvironmentManager { private readonly tunnels = new Map(); private readonly pendingTunnelEntries = new Map>(); private readonly authSecrets = new Map(); + private readonly options: DesktopSshEnvironmentManagerOptions; - constructor(private readonly options: DesktopSshEnvironmentManagerOptions = {}) {} + constructor(options: DesktopSshEnvironmentManagerOptions = {}) { + this.options = options; + } private deleteTunnelIfCurrent(entry: SshTunnelEntry): void { if (this.tunnels.get(entry.key) === entry) { @@ -886,7 +895,12 @@ export class DesktopSshEnvironmentManager { target: DesktopSshEnvironmentTarget, options?: { readonly issuePairingToken?: boolean }, ): Promise { - const resolvedTarget = await resolveDesktopSshTarget(target.alias || target.hostname); + const baseResolved = await resolveDesktopSshTarget(target.alias || target.hostname); + const resolvedTarget: DesktopSshEnvironmentTarget = { + ...baseResolved, + ...(target.username !== null ? { username: target.username } : {}), + ...(target.port !== null ? { port: target.port } : {}), + }; const key = targetConnectionKey(resolvedTarget); const packageSpec = this.options.resolveCliPackageSpec?.(); const entry = await this.ensureTunnelEntry(key, resolvedTarget, packageSpec); @@ -1003,7 +1017,7 @@ export class DesktopSshEnvironmentManager { }); waitForHttpReady(httpBaseUrl, { timeoutMs: SSH_READY_TIMEOUT_MS }) .then(() => resolve()) - .catch((error) => reject(error)); + .catch((error: unknown) => reject(error)); }); this.tunnels.set(key, tunnelEntry); try { diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.ts index 47e159d303..61795bdd85 100644 --- a/apps/server/src/server.test.ts +++ b/apps/server/src/server.test.ts @@ -209,10 +209,8 @@ const browserOtlpTracingLayer = Layer.mergeAll( Layer.succeed(HttpClient.TracerDisabledWhen, () => true), ); -const authTestLayer = ServerAuthLive.pipe( - Layer.provide(SqlitePersistenceMemory), - Layer.provide(ServerSecretStoreLive), -); +const makeAuthTestLayer = () => + ServerAuthLive.pipe(Layer.provide(SqlitePersistenceMemory), Layer.provide(ServerSecretStoreLive)); const makeBrowserOtlpPayload = (spanName: string) => Effect.gen(function* () { @@ -539,7 +537,7 @@ const buildAppUnderTest = (options?: { ...options?.layers?.repositoryIdentityResolver, }), ), - Layer.provideMerge(authTestLayer), + Layer.provideMerge(makeAuthTestLayer()), Layer.provide(workspaceAndProjectServicesLayer), Layer.provideMerge(FetchHttpClient.layer), Layer.provide(layerConfig), diff --git a/apps/web/src/components/settings/SettingsPanels.browser.tsx b/apps/web/src/components/settings/SettingsPanels.browser.tsx index 336424a704..cb3cb0ee87 100644 --- a/apps/web/src/components/settings/SettingsPanels.browser.tsx +++ b/apps/web/src/components/settings/SettingsPanels.browser.tsx @@ -938,12 +938,16 @@ describe("GeneralSettingsPanel observability", () => { ); await page.getByRole("button", { name: "Add environment", exact: true }).click(); - await expect.element(page.getByText("Add Environment")).toBeInTheDocument(); + await expect + .element(page.getByRole("heading", { name: "Add Environment", exact: true })) + .toBeInTheDocument(); await page.getByRole("button", { name: "SSH", exact: true }).click(); await vi.waitFor(() => { expect(discoverSshHosts).toHaveBeenCalledTimes(1); }); - await expect.element(page.getByText("devbox")).toBeInTheDocument(); + await expect + .element(page.getByRole("heading", { name: "devbox", exact: true })) + .toBeInTheDocument(); await page.getByText("Enter a host manually").click(); await page.getByLabelText("Label").fill("Build box"); diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index b3181504fb..f6cdbacfa7 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -60,7 +60,8 @@ import type { import type { AdvertisedEndpoint } from "./remoteAccess.ts"; import { EditorId } from "./editor.ts"; import type { ExecutionEnvironmentDescriptor } from "./environment.ts"; -import { ClientSettings, ServerSettings, ServerSettingsPatch } from "./settings.ts"; +import type { ClientSettings } from "./settings.ts"; +import { ServerSettings, ServerSettingsPatch } from "./settings.ts"; export interface ContextMenuItem { id: T;