Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a0c606fb5 | ||
|
|
7dbf3105b4 | ||
|
|
fdf2210cfa |
No files matched your search
@@ -17,7 +17,7 @@ import {
|
||||
SshLaunchError,
|
||||
SshPairingError,
|
||||
SshPasswordPromptError,
|
||||
type SshReadinessError,
|
||||
SshReadinessError,
|
||||
} from "@t3tools/ssh/errors";
|
||||
import { SshEnvironmentManager, type RemoteT3RunnerOptions } from "@t3tools/ssh/tunnel";
|
||||
import * as Context from "effect/Context";
|
||||
@@ -25,7 +25,6 @@ import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
@@ -80,13 +79,11 @@ function discoverDesktopSshHostsEffect(input?: { readonly homeDir?: string }) {
|
||||
return discoverSshHosts(input ?? {});
|
||||
}
|
||||
|
||||
const isSshPasswordPromptError = Schema.is(SshPasswordPromptError);
|
||||
|
||||
export function isDesktopSshPasswordPromptCancellation(
|
||||
error: unknown,
|
||||
): error is SshPasswordPromptError {
|
||||
return (
|
||||
isSshPasswordPromptError(error) &&
|
||||
error instanceof SshPasswordPromptError &&
|
||||
DesktopSshPasswordPrompts.isDesktopSshPasswordPromptCancellation(error.cause)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { assert, describe, it } from "@effect/vitest";
|
||||
import { SshHttpBridgeError } from "@t3tools/ssh/errors";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
|
||||
|
||||
import * as DesktopSshRemoteApi from "./DesktopSshRemoteApi.ts";
|
||||
@@ -32,8 +31,6 @@ function makeLayer(
|
||||
);
|
||||
}
|
||||
|
||||
const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
|
||||
|
||||
describe("DesktopSshRemoteApi", () => {
|
||||
it.effect("fetches and decodes the remote environment descriptor", () => {
|
||||
const requestUrls: string[] = [];
|
||||
@@ -76,7 +73,7 @@ describe("DesktopSshRemoteApi", () => {
|
||||
|
||||
assert.instanceOf(error, DesktopSshRemoteApi.DesktopSshRemoteApiError);
|
||||
assert.equal(error.operation, "fetch-environment-descriptor");
|
||||
assert.equal(isSshHttpBridgeError(error.cause), false);
|
||||
assert.equal(error.cause instanceof SshHttpBridgeError, false);
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
});
|
||||
@@ -121,6 +121,8 @@ import type { ChatComposerHandle } from "./chat/ChatComposer";
|
||||
|
||||
const EMPTY_BROWSE_ENTRIES: FilesystemBrowseResult["entries"] = [];
|
||||
const BROWSE_STALE_TIME_MS = 30_000;
|
||||
type CommandPaletteOpenIntent = ReturnType<typeof useCommandPaletteStore.getState>["openIntent"];
|
||||
type BrowseEntry = FilesystemBrowseResult["entries"][number];
|
||||
|
||||
function getLocalFileManagerName(platform: string): string {
|
||||
if (isMacPlatform(platform)) {
|
||||
@@ -327,11 +329,31 @@ function errorMessage(error: unknown): string {
|
||||
}
|
||||
|
||||
export function CommandPalette({ children }: { children: ReactNode }) {
|
||||
const composerHandleRef = useRef<ChatComposerHandle | null>(null);
|
||||
|
||||
return (
|
||||
<ComposerHandleContext value={composerHandleRef}>
|
||||
{children}
|
||||
<CommandPaletteController />
|
||||
</ComposerHandleContext>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandPaletteController() {
|
||||
const open = useCommandPaletteStore((store) => store.open);
|
||||
const setOpen = useCommandPaletteStore((store) => store.setOpen);
|
||||
useCommandPaletteShortcut();
|
||||
|
||||
return (
|
||||
<CommandDialog open={open} onOpenChange={setOpen}>
|
||||
<CommandPaletteDialog />
|
||||
</CommandDialog>
|
||||
);
|
||||
}
|
||||
|
||||
function useCommandPaletteShortcut() {
|
||||
const toggleOpen = useCommandPaletteStore((store) => store.toggleOpen);
|
||||
const keybindings = useServerKeybindings();
|
||||
const composerHandleRef = useRef<ChatComposerHandle | null>(null);
|
||||
const routeTarget = useParams({
|
||||
strict: false,
|
||||
select: (params) => resolveThreadRouteTarget(params),
|
||||
@@ -362,26 +384,12 @@ export function CommandPalette({ children }: { children: ReactNode }) {
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [keybindings, terminalOpen, toggleOpen]);
|
||||
|
||||
return (
|
||||
<ComposerHandleContext value={composerHandleRef}>
|
||||
<CommandDialog open={open} onOpenChange={setOpen}>
|
||||
{children}
|
||||
<CommandPaletteDialog />
|
||||
</CommandDialog>
|
||||
</ComposerHandleContext>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandPaletteDialog() {
|
||||
const open = useCommandPaletteStore((store) => store.open);
|
||||
const setOpen = useCommandPaletteStore((store) => store.setOpen);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
setOpen(false);
|
||||
};
|
||||
}, [setOpen]);
|
||||
useCloseCommandPaletteOnUnmount(setOpen);
|
||||
|
||||
if (!open) {
|
||||
return null;
|
||||
@@ -390,6 +398,70 @@ function CommandPaletteDialog() {
|
||||
return <OpenCommandPaletteDialog />;
|
||||
}
|
||||
|
||||
function useCloseCommandPaletteOnUnmount(setOpen: (open: boolean) => void) {
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
setOpen(false);
|
||||
};
|
||||
}, [setOpen]);
|
||||
}
|
||||
|
||||
function usePrefetchBrowsePaths({
|
||||
exactBrowseEntry,
|
||||
filteredBrowseEntryCount,
|
||||
highlightedBrowseEntry,
|
||||
isBrowsing,
|
||||
prefetchBrowsePath,
|
||||
query,
|
||||
}: {
|
||||
readonly exactBrowseEntry: BrowseEntry | null;
|
||||
readonly filteredBrowseEntryCount: number;
|
||||
readonly highlightedBrowseEntry: BrowseEntry | null;
|
||||
readonly isBrowsing: boolean;
|
||||
readonly prefetchBrowsePath: (partialPath: string) => void;
|
||||
readonly query: string;
|
||||
}) {
|
||||
// Prefetch the parent and the most likely next child so browse navigation
|
||||
// stays warm without scanning every child directory in large trees.
|
||||
useEffect(() => {
|
||||
if (!isBrowsing || filteredBrowseEntryCount === 0) return;
|
||||
|
||||
if (canNavigateUp(query)) {
|
||||
prefetchBrowsePath(getBrowseParentPath(query)!);
|
||||
}
|
||||
|
||||
const nextChild = highlightedBrowseEntry ?? exactBrowseEntry;
|
||||
if (nextChild) {
|
||||
prefetchBrowsePath(appendBrowsePathSegment(query, nextChild.name));
|
||||
}
|
||||
}, [
|
||||
exactBrowseEntry,
|
||||
filteredBrowseEntryCount,
|
||||
highlightedBrowseEntry,
|
||||
isBrowsing,
|
||||
prefetchBrowsePath,
|
||||
query,
|
||||
]);
|
||||
}
|
||||
|
||||
function useOpenAddProjectIntent({
|
||||
clearOpenIntent,
|
||||
openAddProjectFlow,
|
||||
openIntent,
|
||||
}: {
|
||||
readonly clearOpenIntent: () => void;
|
||||
readonly openAddProjectFlow: () => void;
|
||||
readonly openIntent: CommandPaletteOpenIntent;
|
||||
}) {
|
||||
useLayoutEffect(() => {
|
||||
if (openIntent?.kind !== "add-project") {
|
||||
return;
|
||||
}
|
||||
clearOpenIntent();
|
||||
openAddProjectFlow();
|
||||
}, [clearOpenIntent, openAddProjectFlow, openIntent]);
|
||||
}
|
||||
|
||||
function OpenCommandPaletteDialog() {
|
||||
const navigate = useNavigate();
|
||||
const setOpen = useCommandPaletteStore((store) => store.setOpen);
|
||||
@@ -587,27 +659,14 @@ function OpenCommandPaletteDialog() {
|
||||
[browseEnvironmentId, currentProjectCwdForBrowse, fetchBrowseResult, queryClient],
|
||||
);
|
||||
|
||||
// Prefetch the parent and the most likely next child so browse navigation
|
||||
// stays warm without scanning every child directory in large trees.
|
||||
useEffect(() => {
|
||||
if (!isBrowsing || filteredBrowseEntries.length === 0) return;
|
||||
|
||||
if (canNavigateUp(query)) {
|
||||
prefetchBrowsePath(getBrowseParentPath(query)!);
|
||||
}
|
||||
|
||||
const nextChild = highlightedBrowseEntry ?? exactBrowseEntry;
|
||||
if (nextChild) {
|
||||
prefetchBrowsePath(appendBrowsePathSegment(query, nextChild.name));
|
||||
}
|
||||
}, [
|
||||
usePrefetchBrowsePaths({
|
||||
exactBrowseEntry,
|
||||
filteredBrowseEntries.length,
|
||||
filteredBrowseEntryCount: filteredBrowseEntries.length,
|
||||
highlightedBrowseEntry,
|
||||
isBrowsing,
|
||||
prefetchBrowsePath,
|
||||
query,
|
||||
]);
|
||||
});
|
||||
|
||||
const openProjectFromSearch = useMemo(
|
||||
() => async (project: (typeof projects)[number]) => {
|
||||
@@ -971,13 +1030,7 @@ function OpenCommandPaletteDialog() {
|
||||
startAddProjectSourceSelection,
|
||||
]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (openIntent?.kind !== "add-project") {
|
||||
return;
|
||||
}
|
||||
clearOpenIntent();
|
||||
openAddProjectFlow();
|
||||
}, [clearOpenIntent, openAddProjectFlow, openIntent]);
|
||||
useOpenAddProjectIntent({ clearOpenIntent, openAddProjectFlow, openIntent });
|
||||
|
||||
const actionItems: Array<CommandPaletteActionItem | CommandPaletteSubmenuItem> = [];
|
||||
|
||||
|
||||
@@ -175,7 +175,6 @@ import {
|
||||
import { sortThreads } from "../lib/threadSort";
|
||||
import { SidebarUpdatePill } from "./sidebar/SidebarUpdatePill";
|
||||
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
|
||||
import { CommandDialogTrigger } from "./ui/command";
|
||||
import { readEnvironmentApi } from "../environmentApi";
|
||||
import { useSettings, useUpdateSettings } from "~/hooks/useSettings";
|
||||
import { useServerKeybindings } from "../rpc/serverState";
|
||||
@@ -2619,20 +2618,22 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(
|
||||
},
|
||||
[updateSettings],
|
||||
);
|
||||
const setCommandPaletteOpen = useCommandPaletteStore((store) => store.setOpen);
|
||||
const handleCommandPaletteClick = useCallback(() => {
|
||||
setCommandPaletteOpen(true);
|
||||
}, [setCommandPaletteOpen]);
|
||||
|
||||
return (
|
||||
<SidebarContent className="gap-0">
|
||||
<SidebarGroup className="px-2 pt-2 pb-1">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<CommandDialogTrigger
|
||||
render={
|
||||
<SidebarMenuButton
|
||||
size="sm"
|
||||
className="gap-2 px-2 py-1.5 text-muted-foreground/70 hover:bg-accent hover:text-foreground focus-visible:ring-0"
|
||||
data-testid="command-palette-trigger"
|
||||
/>
|
||||
}
|
||||
<SidebarMenuButton
|
||||
size="sm"
|
||||
className="gap-2 px-2 py-1.5 text-muted-foreground/70 hover:bg-accent hover:text-foreground focus-visible:ring-0"
|
||||
data-testid="command-palette-trigger"
|
||||
aria-haspopup="dialog"
|
||||
onClick={handleCommandPaletteClick}
|
||||
>
|
||||
<SearchIcon className="size-3.5" />
|
||||
<span className="flex-1 truncate text-left text-xs">Search</span>
|
||||
@@ -2641,7 +2642,7 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(
|
||||
{commandPaletteShortcutLabel}
|
||||
</Kbd>
|
||||
) : null}
|
||||
</CommandDialogTrigger>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroup>
|
||||
|
||||
+38
-95
@@ -1,103 +1,46 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Data from "effect/Data";
|
||||
|
||||
export class SshHostDiscoveryError extends Schema.TaggedErrorClass<SshHostDiscoveryError>()(
|
||||
"SshHostDiscoveryError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.Defect,
|
||||
},
|
||||
) {}
|
||||
export class SshHostDiscoveryError extends Data.TaggedError("SshHostDiscoveryError")<{
|
||||
readonly message: string;
|
||||
readonly cause: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshInvalidTargetError extends Schema.TaggedErrorClass<SshInvalidTargetError>()(
|
||||
"SshInvalidTargetError",
|
||||
{
|
||||
message: Schema.String,
|
||||
},
|
||||
) {}
|
||||
export class SshInvalidTargetError extends Data.TaggedError("SshInvalidTargetError")<{
|
||||
readonly message: string;
|
||||
}> {}
|
||||
|
||||
export class SshCommandError extends Schema.TaggedErrorClass<SshCommandError>()("SshCommandError", {
|
||||
message: Schema.String,
|
||||
command: Schema.Array(Schema.String),
|
||||
exitCode: Schema.NullOr(Schema.Number),
|
||||
stderr: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshCommandError extends Data.TaggedError("SshCommandError")<{
|
||||
readonly message: string;
|
||||
readonly command: readonly string[];
|
||||
readonly exitCode: number | null;
|
||||
readonly stderr: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshLaunchError extends Schema.TaggedErrorClass<SshLaunchError>()("SshLaunchError", {
|
||||
message: Schema.String,
|
||||
stdout: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshLaunchError extends Data.TaggedError("SshLaunchError")<{
|
||||
readonly message: string;
|
||||
readonly stdout: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshPairingError extends Schema.TaggedErrorClass<SshPairingError>()("SshPairingError", {
|
||||
message: Schema.String,
|
||||
stdout: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshPairingError extends Data.TaggedError("SshPairingError")<{
|
||||
readonly message: string;
|
||||
readonly stdout: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshHttpBridgeError extends Schema.TaggedErrorClass<SshHttpBridgeError>()(
|
||||
"SshHttpBridgeError",
|
||||
{
|
||||
message: Schema.String,
|
||||
status: Schema.optional(Schema.Number),
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshHttpBridgeError extends Data.TaggedError("SshHttpBridgeError")<{
|
||||
readonly message: string;
|
||||
readonly status?: number;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshReadinessProbeFailedError extends Schema.TaggedErrorClass<SshReadinessProbeFailedError>()(
|
||||
"SshReadinessProbeFailedError",
|
||||
{
|
||||
message: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshReadinessError extends Data.TaggedError("SshReadinessError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshReadinessProbeTimedOutError extends Schema.TaggedErrorClass<SshReadinessProbeTimedOutError>()(
|
||||
"SshReadinessProbeTimedOutError",
|
||||
{
|
||||
message: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
attempt: Schema.Number,
|
||||
probeTimeoutMs: Schema.Number,
|
||||
},
|
||||
) {}
|
||||
|
||||
export class SshReadinessTimedOutError extends Schema.TaggedErrorClass<SshReadinessTimedOutError>()(
|
||||
"SshReadinessTimedOutError",
|
||||
{
|
||||
message: Schema.String,
|
||||
baseUrl: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
timeoutMs: Schema.Number,
|
||||
intervalMs: Schema.Number,
|
||||
probeTimeoutMs: Schema.Number,
|
||||
attempts: Schema.Number,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
|
||||
export type SshReadinessError =
|
||||
| SshReadinessProbeFailedError
|
||||
| SshReadinessProbeTimedOutError
|
||||
| SshReadinessTimedOutError;
|
||||
|
||||
const isSshReadinessProbeFailedError = Schema.is(SshReadinessProbeFailedError);
|
||||
const isSshReadinessProbeTimedOutError = Schema.is(SshReadinessProbeTimedOutError);
|
||||
const isSshReadinessTimedOutError = Schema.is(SshReadinessTimedOutError);
|
||||
|
||||
export function isSshReadinessError(cause: unknown): cause is SshReadinessError {
|
||||
return (
|
||||
isSshReadinessProbeFailedError(cause) ||
|
||||
isSshReadinessProbeTimedOutError(cause) ||
|
||||
isSshReadinessTimedOutError(cause)
|
||||
);
|
||||
}
|
||||
|
||||
export class SshPasswordPromptError extends Schema.TaggedErrorClass<SshPasswordPromptError>()(
|
||||
"SshPasswordPromptError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshPasswordPromptError extends Data.TaggedError("SshPasswordPromptError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
@@ -242,9 +242,9 @@ describe("ssh tunnel scripts", () => {
|
||||
Effect.result(
|
||||
waitForHttpReady({
|
||||
baseUrl: "http://127.0.0.1:41773/",
|
||||
timeout: Duration.seconds(1),
|
||||
interval: Duration.millis(100),
|
||||
probeTimeout: Duration.millis(250),
|
||||
timeoutMs: 1_000,
|
||||
intervalMs: 100,
|
||||
probeTimeoutMs: 250,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
+46
-86
@@ -45,20 +45,16 @@ import {
|
||||
SshLaunchError,
|
||||
SshPairingError,
|
||||
SshPasswordPromptError,
|
||||
SshReadinessProbeFailedError,
|
||||
SshReadinessProbeTimedOutError,
|
||||
SshReadinessTimedOutError,
|
||||
isSshReadinessError,
|
||||
type SshReadinessError,
|
||||
SshReadinessError,
|
||||
} from "./errors.ts";
|
||||
|
||||
export const DEFAULT_REMOTE_PORT = 3773;
|
||||
const REMOTE_PORT_SCAN_WINDOW = 200;
|
||||
const SSH_READY_TIMEOUT = Duration.seconds(20);
|
||||
const SSH_READY_PROBE_TIMEOUT = Duration.seconds(1);
|
||||
const TUNNEL_SHUTDOWN_TIMEOUT = Duration.seconds(2);
|
||||
const REMOTE_READY_TIMEOUT = Duration.seconds(15);
|
||||
const REMOTE_REUSE_READY_TIMEOUT = Duration.seconds(2);
|
||||
const SSH_READY_TIMEOUT_MS = 20_000;
|
||||
const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
|
||||
const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
|
||||
const REMOTE_READY_TIMEOUT_MS = 15_000;
|
||||
const REMOTE_REUSE_READY_TIMEOUT_MS = 2_000;
|
||||
|
||||
export interface RemoteT3RunnerOptions {
|
||||
readonly packageSpec?: string;
|
||||
@@ -241,37 +237,12 @@ function applyScriptPlaceholders(
|
||||
}
|
||||
|
||||
export function describeReadinessCause(cause: unknown): unknown {
|
||||
if (isSshReadinessError(cause)) {
|
||||
const base = {
|
||||
if (cause instanceof SshReadinessError) {
|
||||
return {
|
||||
_tag: cause._tag,
|
||||
message: cause.message,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
switch (cause._tag) {
|
||||
case "SshReadinessProbeFailedError":
|
||||
return {
|
||||
...base,
|
||||
requestUrl: cause.requestUrl,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
case "SshReadinessProbeTimedOutError":
|
||||
return {
|
||||
...base,
|
||||
requestUrl: cause.requestUrl,
|
||||
attempt: cause.attempt,
|
||||
probeTimeoutMs: cause.probeTimeoutMs,
|
||||
};
|
||||
case "SshReadinessTimedOutError":
|
||||
return {
|
||||
...base,
|
||||
baseUrl: cause.baseUrl,
|
||||
requestUrl: cause.requestUrl,
|
||||
timeoutMs: cause.timeoutMs,
|
||||
intervalMs: cause.intervalMs,
|
||||
probeTimeoutMs: cause.probeTimeoutMs,
|
||||
attempts: cause.attempts,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
}
|
||||
}
|
||||
if (cause instanceof Error) {
|
||||
return {
|
||||
@@ -715,9 +686,9 @@ export function buildRemoteLaunchScript(input?: RemoteT3RunnerOptions): string {
|
||||
T3_WAIT_READY_SCRIPT: stripTrailingNewlines(REMOTE_WAIT_READY_SCRIPT),
|
||||
T3_DEFAULT_REMOTE_PORT: String(DEFAULT_REMOTE_PORT),
|
||||
T3_REMOTE_PORT_SCAN_WINDOW: String(REMOTE_PORT_SCAN_WINDOW),
|
||||
T3_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_READY_TIMEOUT)),
|
||||
T3_REUSE_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_REUSE_READY_TIMEOUT)),
|
||||
T3_READY_PROBE_TIMEOUT_MS: String(Duration.toMillis(SSH_READY_PROBE_TIMEOUT)),
|
||||
T3_READY_TIMEOUT_MS: String(REMOTE_READY_TIMEOUT_MS),
|
||||
T3_REUSE_READY_TIMEOUT_MS: String(REMOTE_REUSE_READY_TIMEOUT_MS),
|
||||
T3_READY_PROBE_TIMEOUT_MS: String(SSH_READY_PROBE_TIMEOUT_MS),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -899,21 +870,20 @@ const readRemoteServerLogTail = Effect.fn("ssh/tunnel.readRemoteServerLogTail")(
|
||||
|
||||
export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(function* (input: {
|
||||
readonly baseUrl: string;
|
||||
readonly timeout?: Duration.Input;
|
||||
readonly interval?: Duration.Input;
|
||||
readonly probeTimeout?: Duration.Input;
|
||||
readonly timeoutMs?: number;
|
||||
readonly intervalMs?: number;
|
||||
readonly probeTimeoutMs?: number;
|
||||
readonly path?: string;
|
||||
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
|
||||
const timeout = Duration.fromInputUnsafe(input.timeout ?? Duration.seconds(30));
|
||||
const interval = Duration.fromInputUnsafe(input.interval ?? Duration.millis(100));
|
||||
const probeTimeout = Duration.fromInputUnsafe(input.probeTimeout ?? SSH_READY_PROBE_TIMEOUT);
|
||||
const timeoutMs = Duration.toMillis(timeout);
|
||||
const intervalMs = Duration.toMillis(interval);
|
||||
const probeTimeoutMs = Duration.toMillis(probeTimeout);
|
||||
const retryPolicy = Schedule.spaced(interval);
|
||||
const timeoutMs = input.timeoutMs ?? 30_000;
|
||||
const intervalMs = input.intervalMs ?? 100;
|
||||
const probeTimeoutMs = input.probeTimeoutMs ?? SSH_READY_PROBE_TIMEOUT_MS;
|
||||
const retryPolicy = Schedule.spaced(Duration.millis(intervalMs)).pipe(
|
||||
Schedule.take(Math.max(0, Math.ceil(timeoutMs / intervalMs))),
|
||||
);
|
||||
const requestUrl = new URL(input.path ?? "/", input.baseUrl).toString();
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
const lastProbeFailure = yield* Ref.make<Option.Option<unknown>>(Option.none());
|
||||
const lastProbeFailure = yield* Ref.make<unknown>(null);
|
||||
let attempt = 0;
|
||||
|
||||
yield* Effect.logDebug("ssh.tunnel.httpReady.start", {
|
||||
@@ -930,12 +900,11 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
Effect.gen(function* () {
|
||||
attempt += 1;
|
||||
const responseOption = yield* effect.pipe(
|
||||
Effect.timeoutOption(probeTimeout),
|
||||
Effect.timeoutOption(Duration.millis(probeTimeoutMs)),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new SshReadinessProbeFailedError({
|
||||
new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
@@ -944,32 +913,30 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
onSome: Effect.succeed,
|
||||
onNone: () =>
|
||||
Effect.fail(
|
||||
new SshReadinessProbeTimedOutError({
|
||||
new SshReadinessError({
|
||||
message: `Backend readiness probe exceeded ${probeTimeoutMs}ms at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
attempt,
|
||||
probeTimeoutMs,
|
||||
cause: {
|
||||
kind: "probe-timeout",
|
||||
attempt,
|
||||
probeTimeoutMs,
|
||||
},
|
||||
}),
|
||||
),
|
||||
});
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessProbeFailedError({
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.tapError((cause) =>
|
||||
Ref.set(
|
||||
lastProbeFailure,
|
||||
Option.some({
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
),
|
||||
Ref.set(lastProbeFailure, {
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -979,15 +946,14 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
|
||||
const result = yield* readinessClient.execute(HttpClientRequest.get(requestUrl)).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessProbeFailedError({
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.timeoutOption(timeout),
|
||||
Effect.timeoutOption(Duration.millis(timeoutMs)),
|
||||
);
|
||||
|
||||
return yield* Option.match(result, {
|
||||
@@ -1007,17 +973,11 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
intervalMs,
|
||||
probeTimeoutMs,
|
||||
attempts: attempt,
|
||||
lastFailure: Option.getOrUndefined(lastFailure),
|
||||
lastFailure,
|
||||
});
|
||||
return yield* new SshReadinessTimedOutError({
|
||||
return yield* new SshReadinessError({
|
||||
message: `Timed out waiting ${timeoutMs}ms for backend readiness at ${input.baseUrl}.`,
|
||||
baseUrl: input.baseUrl,
|
||||
requestUrl,
|
||||
timeoutMs,
|
||||
intervalMs,
|
||||
probeTimeoutMs,
|
||||
attempts: attempt,
|
||||
...(Option.isSome(lastFailure) ? { cause: lastFailure.value } : {}),
|
||||
cause: lastFailure,
|
||||
});
|
||||
}),
|
||||
});
|
||||
@@ -1276,7 +1236,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
yield* Effect.raceFirst(
|
||||
waitForHttpReady({
|
||||
baseUrl: input.httpBaseUrl,
|
||||
timeout: SSH_READY_TIMEOUT,
|
||||
timeoutMs: SSH_READY_TIMEOUT_MS,
|
||||
}),
|
||||
exitFailure,
|
||||
).pipe(
|
||||
@@ -1336,7 +1296,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
: child
|
||||
.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: Duration.toMillis(TUNNEL_SHUTDOWN_TIMEOUT),
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
})
|
||||
.pipe(Effect.ignore),
|
||||
),
|
||||
@@ -1580,7 +1540,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
[
|
||||
tunnelEntry.process.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: Duration.toMillis(TUNNEL_SHUTDOWN_TIMEOUT),
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
}),
|
||||
stopRemoteServer(
|
||||
tunnelEntry.target,
|
||||
@@ -1634,7 +1594,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
remotePort: entry.remotePort,
|
||||
});
|
||||
const readinessExit = yield* Effect.exit(
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeout: Duration.seconds(2) }),
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeoutMs: 2_000 }),
|
||||
);
|
||||
if (Exit.isSuccess(readinessExit)) {
|
||||
yield* Effect.logDebug("ssh.environment.tunnel.reused", {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 84 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Reference in new issue
Block a user