Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f16e15240 |
No files matched your search
@@ -1,8 +1,7 @@
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime";
|
||||
import { ThreadId } from "@t3tools/contracts";
|
||||
import * as Option from "effect/Option";
|
||||
import { useState } from "react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
import { render } from "vitest-browser-react";
|
||||
|
||||
const SHARED_THREAD_ID = ThreadId.make("thread-shared");
|
||||
@@ -27,8 +26,6 @@ const {
|
||||
activeRunStackedActionDeferredRef,
|
||||
activeDraftThreadRef,
|
||||
hasServerThreadRef,
|
||||
sourceControlDiscoveryRef,
|
||||
vcsStatusRef,
|
||||
invalidateSourceControlStateSpy,
|
||||
refreshVcsStatusSpy,
|
||||
runStackedActionSpy,
|
||||
@@ -42,26 +39,6 @@ const {
|
||||
activeRunStackedActionDeferredRef: { current: createDeferredPromise<never>() },
|
||||
activeDraftThreadRef: { current: null as unknown },
|
||||
hasServerThreadRef: { current: true },
|
||||
sourceControlDiscoveryRef: { current: null as unknown },
|
||||
vcsStatusRef: {
|
||||
current: {
|
||||
isRepo: true,
|
||||
sourceControlProvider: {
|
||||
kind: "github",
|
||||
name: "GitHub",
|
||||
baseUrl: "https://github.com",
|
||||
},
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
refName: "feature/toast-scope",
|
||||
hasWorkingTreeChanges: false,
|
||||
workingTree: { files: [], insertions: 0, deletions: 0 },
|
||||
hasUpstream: true,
|
||||
aheadCount: 1,
|
||||
behindCount: 0,
|
||||
pr: null,
|
||||
},
|
||||
},
|
||||
invalidateSourceControlStateSpy: vi.fn(() => Promise.resolve()),
|
||||
refreshVcsStatusSpy: vi.fn(() => Promise.resolve(null)),
|
||||
runStackedActionSpy: vi.fn(() => activeRunStackedActionDeferredRef.current.promise),
|
||||
@@ -87,10 +64,6 @@ vi.mock("~/editorPreferences", () => ({
|
||||
openInPreferredEditor: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/lib/sourceControlDiscoveryState", () => ({
|
||||
useSourceControlDiscovery: vi.fn(() => sourceControlDiscoveryRef.current),
|
||||
}));
|
||||
|
||||
vi.mock("~/lib/sourceControlActions", () => ({
|
||||
invalidateSourceControlState: invalidateSourceControlStateSpy,
|
||||
useGitStackedAction: vi.fn(() => ({
|
||||
@@ -124,7 +97,23 @@ vi.mock("~/lib/vcsStatusState", () => ({
|
||||
refreshVcsStatus: refreshVcsStatusSpy,
|
||||
resetVcsStatusStateForTests: () => undefined,
|
||||
useVcsStatus: vi.fn(() => ({
|
||||
data: vcsStatusRef.current,
|
||||
data: {
|
||||
isRepo: true,
|
||||
sourceControlProvider: {
|
||||
kind: "github",
|
||||
name: "GitHub",
|
||||
baseUrl: "https://github.com",
|
||||
},
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
refName: BRANCH_NAME,
|
||||
hasWorkingTreeChanges: false,
|
||||
workingTree: { files: [], insertions: 0, deletions: 0 },
|
||||
hasUpstream: true,
|
||||
aheadCount: 1,
|
||||
behindCount: 0,
|
||||
pr: null,
|
||||
},
|
||||
error: null,
|
||||
isPending: false,
|
||||
})),
|
||||
@@ -256,77 +245,6 @@ function findButtonByText(text: string): HTMLButtonElement | null {
|
||||
) ?? null) as HTMLButtonElement | null;
|
||||
}
|
||||
|
||||
function findRadioByText(text: string): HTMLElement | null {
|
||||
return (Array.from(document.querySelectorAll('[role="radio"]')).find((radio) =>
|
||||
radio.textContent?.includes(text),
|
||||
) ?? null) as HTMLElement | null;
|
||||
}
|
||||
|
||||
function setInputValue(input: HTMLInputElement, value: string) {
|
||||
input.value = value;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}
|
||||
|
||||
function createDefaultVcsStatus() {
|
||||
return {
|
||||
isRepo: true,
|
||||
sourceControlProvider: {
|
||||
kind: "github",
|
||||
name: "GitHub",
|
||||
baseUrl: "https://github.com",
|
||||
},
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
refName: BRANCH_NAME,
|
||||
hasWorkingTreeChanges: false,
|
||||
workingTree: { files: [], insertions: 0, deletions: 0 },
|
||||
hasUpstream: true,
|
||||
aheadCount: 1,
|
||||
behindCount: 0,
|
||||
pr: null,
|
||||
};
|
||||
}
|
||||
|
||||
function createDefaultSourceControlDiscovery() {
|
||||
return {
|
||||
data: {
|
||||
versionControlSystems: [],
|
||||
sourceControlProviders: [
|
||||
{
|
||||
kind: "github",
|
||||
label: "GitHub",
|
||||
status: "available",
|
||||
version: Option.some("2.85.0"),
|
||||
installHint: "Install GitHub CLI.",
|
||||
detail: Option.none(),
|
||||
auth: {
|
||||
status: "authenticated",
|
||||
account: Option.some("octo"),
|
||||
host: Option.some("github.com"),
|
||||
detail: Option.none(),
|
||||
},
|
||||
},
|
||||
{
|
||||
kind: "gitlab",
|
||||
label: "GitLab",
|
||||
status: "available",
|
||||
version: Option.some("19.0.0"),
|
||||
installHint: "Install GitLab CLI.",
|
||||
detail: Option.none(),
|
||||
auth: {
|
||||
status: "authenticated",
|
||||
account: Option.some("tanuki"),
|
||||
host: Option.some("gitlab.com"),
|
||||
detail: Option.none(),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
error: null,
|
||||
isPending: false,
|
||||
};
|
||||
}
|
||||
|
||||
function Harness() {
|
||||
const [activeThreadRef, setActiveThreadRef] = useState(
|
||||
scopeThreadRef(ENVIRONMENT_A, SHARED_THREAD_ID),
|
||||
@@ -346,19 +264,12 @@ function Harness() {
|
||||
}
|
||||
|
||||
describe("GitActionsControl thread-scoped progress toast", () => {
|
||||
beforeEach(() => {
|
||||
vcsStatusRef.current = createDefaultVcsStatus();
|
||||
sourceControlDiscoveryRef.current = createDefaultSourceControlDiscovery();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.clearAllMocks();
|
||||
activeRunStackedActionDeferredRef.current = createDeferredPromise<never>();
|
||||
activeDraftThreadRef.current = null;
|
||||
hasServerThreadRef.current = true;
|
||||
vcsStatusRef.current = createDefaultVcsStatus();
|
||||
sourceControlDiscoveryRef.current = createDefaultSourceControlDiscovery();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
@@ -424,58 +335,6 @@ describe("GitActionsControl thread-scoped progress toast", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("derives publish provider and repository defaults while preserving user edits", async () => {
|
||||
vcsStatusRef.current = {
|
||||
...createDefaultVcsStatus(),
|
||||
hasPrimaryRemote: false,
|
||||
hasUpstream: false,
|
||||
aheadCount: 0,
|
||||
};
|
||||
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
const screen = await render(
|
||||
<GitActionsControl
|
||||
gitCwd={GIT_CWD}
|
||||
activeThreadRef={scopeThreadRef(ENVIRONMENT_A, SHARED_THREAD_ID)}
|
||||
/>,
|
||||
{ container: host },
|
||||
);
|
||||
|
||||
try {
|
||||
findButtonByText("Publish repository")?.click();
|
||||
await Promise.resolve();
|
||||
expect(document.querySelector('[role="dialog"]')?.textContent).toContain(
|
||||
"Publish repository",
|
||||
);
|
||||
|
||||
findButtonByText("Next")?.click();
|
||||
await Promise.resolve();
|
||||
const repositoryInput = document.querySelector<HTMLInputElement>("#publish-repository-path");
|
||||
expect(repositoryInput?.value).toBe("octo/");
|
||||
|
||||
if (!repositoryInput) {
|
||||
throw new Error("Repository input was not rendered.");
|
||||
}
|
||||
setInputValue(repositoryInput, "octo/demo");
|
||||
expect(repositoryInput.value).toBe("octo/demo");
|
||||
|
||||
findButtonByText("Back")?.click();
|
||||
await Promise.resolve();
|
||||
findRadioByText("GitLab")?.click();
|
||||
await Promise.resolve();
|
||||
findButtonByText("Next")?.click();
|
||||
await Promise.resolve();
|
||||
|
||||
expect(document.querySelector<HTMLInputElement>("#publish-repository-path")?.value).toBe(
|
||||
"tanuki/",
|
||||
);
|
||||
} finally {
|
||||
await screen.unmount();
|
||||
host.remove();
|
||||
}
|
||||
});
|
||||
|
||||
it("debounces focus-driven git status refreshes", async () => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
|
||||
@@ -348,9 +348,8 @@ interface PublishRepositoryDialogProps {
|
||||
function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
const navigate = useNavigate();
|
||||
const sourceControlDiscovery = useSourceControlDiscovery();
|
||||
const [requestedPublishProvider, setRequestedPublishProvider] =
|
||||
useState<PublishProviderKind>("github");
|
||||
const [publishRepositoryOverride, setPublishRepositoryOverride] = useState<string | null>(null);
|
||||
const [publishProvider, setPublishProvider] = useState<PublishProviderKind>("github");
|
||||
const [publishRepository, setPublishRepository] = useState("");
|
||||
const [publishVisibility, setPublishVisibility] =
|
||||
useState<SourceControlRepositoryVisibility>("private");
|
||||
const [publishRemoteName, setPublishRemoteName] = useState("origin");
|
||||
@@ -361,6 +360,7 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
const [publishResult, setPublishResult] = useState<SourceControlPublishRepositoryResult | null>(
|
||||
null,
|
||||
);
|
||||
const [hasUserEditedPublishRepository, setHasUserEditedPublishRepository] = useState(false);
|
||||
const sourceControlScope = useMemo(
|
||||
() => ({
|
||||
environmentId: props.environmentId,
|
||||
@@ -395,13 +395,6 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
]),
|
||||
) as Record<PublishProviderKind, { readonly ready: boolean; readonly hint: string | null }>;
|
||||
}, [sourceControlDiscovery.data]);
|
||||
const firstReadyPublishProvider = PUBLISH_PROVIDER_OPTIONS.find(
|
||||
(option) => publishProviderReadiness[option.value].ready,
|
||||
);
|
||||
const publishProvider =
|
||||
publishProviderReadiness[requestedPublishProvider].ready || !firstReadyPublishProvider
|
||||
? requestedPublishProvider
|
||||
: firstReadyPublishProvider.value;
|
||||
const hasReadyPublishProvider = useMemo(
|
||||
() => PUBLISH_PROVIDER_OPTIONS.some((option) => publishProviderReadiness[option.value].ready),
|
||||
[publishProviderReadiness],
|
||||
@@ -422,7 +415,6 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
const publishRepositoryPrefill = publishAccountByProvider[publishProvider]
|
||||
? `${publishAccountByProvider[publishProvider]}/`
|
||||
: "";
|
||||
const publishRepository = publishRepositoryOverride ?? publishRepositoryPrefill;
|
||||
const currentPublishProvider = publishProviderOption(publishProvider);
|
||||
const publishHost = currentPublishProvider.host;
|
||||
const publishPathPlaceholder = currentPublishProvider.pathPlaceholder;
|
||||
@@ -434,6 +426,13 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
null,
|
||||
] as const;
|
||||
|
||||
useEffect(() => {
|
||||
if (!props.open || hasUserEditedPublishRepository) {
|
||||
return;
|
||||
}
|
||||
setPublishRepository(publishRepositoryPrefill);
|
||||
}, [hasUserEditedPublishRepository, props.open, publishRepositoryPrefill]);
|
||||
|
||||
const canSubmitPublishRepository = useMemo(() => {
|
||||
if (!selectedPublishProviderReadiness.ready) return false;
|
||||
if (publishRepositoryAction.isPending) return false;
|
||||
@@ -444,6 +443,21 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
return owner.length > 0 && name.length > 0;
|
||||
}, [publishRepository, publishRepositoryAction.isPending, selectedPublishProviderReadiness]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!props.open) {
|
||||
return;
|
||||
}
|
||||
if (publishProviderReadiness[publishProvider].ready) {
|
||||
return;
|
||||
}
|
||||
const firstReadyProvider = PUBLISH_PROVIDER_OPTIONS.find(
|
||||
(option) => publishProviderReadiness[option.value].ready,
|
||||
);
|
||||
if (firstReadyProvider) {
|
||||
setPublishProvider(firstReadyProvider.value);
|
||||
}
|
||||
}, [props.open, publishProvider, publishProviderReadiness]);
|
||||
|
||||
const submitPublishRepository = useCallback(() => {
|
||||
if (!canSubmitPublishRepository) {
|
||||
return;
|
||||
@@ -485,7 +499,8 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
|
||||
const resetState = useCallback(() => {
|
||||
setPublishRemoteName("origin");
|
||||
setPublishRepositoryOverride(null);
|
||||
setPublishRepository("");
|
||||
setHasUserEditedPublishRepository(false);
|
||||
setPublishWizardStep(0);
|
||||
setPublishAdvancedOpen(false);
|
||||
setPublishError(null);
|
||||
@@ -578,10 +593,7 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
</span>
|
||||
<RadioGroup
|
||||
value={publishProvider}
|
||||
onValueChange={(value) => {
|
||||
setRequestedPublishProvider(value as PublishProviderKind);
|
||||
setPublishRepositoryOverride(null);
|
||||
}}
|
||||
onValueChange={(value) => setPublishProvider(value as PublishProviderKind)}
|
||||
aria-labelledby="publish-provider-cards-label"
|
||||
className="grid grid-cols-2 gap-2.5"
|
||||
>
|
||||
@@ -667,7 +679,8 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
|
||||
name="publish-repository-path"
|
||||
value={publishRepository}
|
||||
onChange={(event) => {
|
||||
setPublishRepositoryOverride(event.target.value);
|
||||
setPublishRepository(event.target.value);
|
||||
setHasUserEditedPublishRepository(true);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
|
||||
@@ -219,7 +219,7 @@ describe("ssh command", () => {
|
||||
username: "julius",
|
||||
port: 2222,
|
||||
},
|
||||
{ timeoutMs: 1 },
|
||||
{ timeout: Duration.millis(1) },
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ import { buildSshChildEnvironment, type SshAuthOptions } from "./auth.ts";
|
||||
import { SshCommandError, SshInvalidTargetError } from "./errors.ts";
|
||||
|
||||
const PUBLISHABLE_T3_VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u;
|
||||
const DEFAULT_SSH_COMMAND_TIMEOUT_MS = 60_000;
|
||||
const DEFAULT_SSH_COMMAND_TIMEOUT = Duration.minutes(1);
|
||||
const MAX_SSH_ERROR_OUTPUT_LENGTH = 4_000;
|
||||
export const SSH_COMMAND = process.platform === "win32" ? "ssh.exe" : "ssh";
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface RunSshCommandOptions extends SshAuthOptions {
|
||||
readonly preHostArgs?: ReadonlyArray<string>;
|
||||
readonly remoteCommandArgs?: ReadonlyArray<string>;
|
||||
readonly stdin?: string;
|
||||
readonly timeoutMs?: number;
|
||||
readonly timeout?: Duration.Input;
|
||||
}
|
||||
|
||||
export function parseSshResolveOutput(alias: string, stdout: string): DesktopSshEnvironmentTarget {
|
||||
@@ -157,6 +157,10 @@ function stdinStream(input: string | undefined) {
|
||||
return input === undefined ? Stream.empty : Stream.make(encoder.encode(input));
|
||||
}
|
||||
|
||||
function resolveSshCommandTimeout(input: RunSshCommandOptions): Duration.Duration {
|
||||
return Duration.fromInputUnsafe(input.timeout ?? DEFAULT_SSH_COMMAND_TIMEOUT);
|
||||
}
|
||||
|
||||
const runSshCommandInScope = Effect.fn("ssh/command.runSshCommand.inScope")(function* (
|
||||
target: DesktopSshEnvironmentTarget,
|
||||
input: RunSshCommandOptions,
|
||||
@@ -195,7 +199,7 @@ const runSshCommandInScope = Effect.fn("ssh/command.runSshCommand.inScope")(func
|
||||
...sshTargetLogFields(target),
|
||||
command: [SSH_COMMAND, ...args],
|
||||
hasStdin: input.stdin !== undefined,
|
||||
timeoutMs: input.timeoutMs ?? DEFAULT_SSH_COMMAND_TIMEOUT_MS,
|
||||
timeoutMs: Duration.toMillis(resolveSshCommandTimeout(input)),
|
||||
});
|
||||
const child = yield* spawner
|
||||
.spawn(
|
||||
@@ -282,10 +286,12 @@ export const runSshCommand = Effect.fn("ssh/command.runSshCommand")(function* (
|
||||
SshCommandError | SshInvalidTargetError,
|
||||
ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path
|
||||
> {
|
||||
const timeout = resolveSshCommandTimeout(input);
|
||||
const timeoutMs = Duration.toMillis(timeout);
|
||||
return yield* Effect.scopedWith((commandScope) =>
|
||||
runSshCommandInScope(target, input, commandScope),
|
||||
).pipe(
|
||||
Effect.timeoutOption(Duration.millis(input.timeoutMs ?? DEFAULT_SSH_COMMAND_TIMEOUT_MS)),
|
||||
Effect.timeoutOption(timeout),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onSome: Effect.succeed,
|
||||
@@ -293,7 +299,7 @@ export const runSshCommand = Effect.fn("ssh/command.runSshCommand")(function* (
|
||||
Effect.gen(function* () {
|
||||
yield* Effect.logWarning("ssh.command.timedOut", {
|
||||
...sshTargetLogFields(target),
|
||||
timeoutMs: input.timeoutMs ?? DEFAULT_SSH_COMMAND_TIMEOUT_MS,
|
||||
timeoutMs,
|
||||
remoteCommandArgs: input.remoteCommandArgs ?? [],
|
||||
preHostArgs: input.preHostArgs ?? [],
|
||||
hasStdin: input.stdin !== undefined,
|
||||
@@ -302,7 +308,7 @@ export const runSshCommand = Effect.fn("ssh/command.runSshCommand")(function* (
|
||||
command: ["ssh"],
|
||||
exitCode: null,
|
||||
stderr: "",
|
||||
message: `SSH command timed out after ${input.timeoutMs ?? DEFAULT_SSH_COMMAND_TIMEOUT_MS}ms.`,
|
||||
message: `SSH command timed out after ${timeoutMs}ms.`,
|
||||
});
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -242,9 +242,9 @@ describe("ssh tunnel scripts", () => {
|
||||
Effect.result(
|
||||
waitForHttpReady({
|
||||
baseUrl: "http://127.0.0.1:41773/",
|
||||
timeoutMs: 1_000,
|
||||
intervalMs: 100,
|
||||
probeTimeoutMs: 250,
|
||||
timeout: { seconds: 1 },
|
||||
interval: Duration.millis(100),
|
||||
probeTimeout: { milliseconds: 250 },
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
+37
-29
@@ -51,11 +51,13 @@ import {
|
||||
|
||||
export const DEFAULT_REMOTE_PORT = 3773;
|
||||
const REMOTE_PORT_SCAN_WINDOW = 200;
|
||||
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;
|
||||
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 DEFAULT_HTTP_READY_TIMEOUT = Duration.seconds(30);
|
||||
const DEFAULT_HTTP_READY_INTERVAL = Duration.millis(100);
|
||||
|
||||
export interface RemoteT3RunnerOptions {
|
||||
readonly packageSpec?: string;
|
||||
@@ -682,9 +684,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(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),
|
||||
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)),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -856,7 +858,7 @@ const readRemoteServerLogTail = Effect.fn("ssh/tunnel.readRemoteServerLogTail")(
|
||||
const result = yield* runSshCommand(target, {
|
||||
remoteCommandArgs: ["sh", "-s"],
|
||||
stdin: buildRemoteLogTailScript(target),
|
||||
timeoutMs: 10_000,
|
||||
timeout: Duration.seconds(10),
|
||||
...(input?.authSecret === undefined ? {} : { authSecret: input.authSecret }),
|
||||
...(input?.batchMode === undefined ? {} : { batchMode: input.batchMode }),
|
||||
...(input?.interactiveAuth === undefined ? {} : { interactiveAuth: input.interactiveAuth }),
|
||||
@@ -866,20 +868,23 @@ const readRemoteServerLogTail = Effect.fn("ssh/tunnel.readRemoteServerLogTail")(
|
||||
|
||||
export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(function* (input: {
|
||||
readonly baseUrl: string;
|
||||
readonly timeoutMs?: number;
|
||||
readonly intervalMs?: number;
|
||||
readonly probeTimeoutMs?: number;
|
||||
readonly timeout?: Duration.Input;
|
||||
readonly interval?: Duration.Input;
|
||||
readonly probeTimeout?: Duration.Input;
|
||||
readonly path?: string;
|
||||
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
|
||||
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(
|
||||
const timeout = Duration.fromInputUnsafe(input.timeout ?? DEFAULT_HTTP_READY_TIMEOUT);
|
||||
const interval = Duration.fromInputUnsafe(input.interval ?? DEFAULT_HTTP_READY_INTERVAL);
|
||||
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).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<unknown>(null);
|
||||
const lastProbeFailure = yield* Ref.make<Option.Option<unknown>>(Option.none());
|
||||
let attempt = 0;
|
||||
|
||||
yield* Effect.logDebug("ssh.tunnel.httpReady.start", {
|
||||
@@ -896,7 +901,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
Effect.gen(function* () {
|
||||
attempt += 1;
|
||||
const responseOption = yield* effect.pipe(
|
||||
Effect.timeoutOption(Duration.millis(probeTimeoutMs)),
|
||||
Effect.timeoutOption(probeTimeout),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new SshReadinessError({
|
||||
@@ -929,10 +934,13 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
}),
|
||||
),
|
||||
Effect.tapError((cause) =>
|
||||
Ref.set(lastProbeFailure, {
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
Ref.set(
|
||||
lastProbeFailure,
|
||||
Option.some({
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -949,7 +957,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.timeoutOption(Duration.millis(timeoutMs)),
|
||||
Effect.timeoutOption(timeout),
|
||||
);
|
||||
|
||||
return yield* Option.match(result, {
|
||||
@@ -969,11 +977,11 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
intervalMs,
|
||||
probeTimeoutMs,
|
||||
attempts: attempt,
|
||||
lastFailure,
|
||||
...(Option.isSome(lastFailure) ? { lastFailure: lastFailure.value } : {}),
|
||||
});
|
||||
return yield* new SshReadinessError({
|
||||
message: `Timed out waiting ${timeoutMs}ms for backend readiness at ${input.baseUrl}.`,
|
||||
cause: lastFailure,
|
||||
cause: Option.getOrUndefined(lastFailure),
|
||||
});
|
||||
}),
|
||||
});
|
||||
@@ -1166,7 +1174,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
yield* Effect.raceFirst(
|
||||
waitForHttpReady({
|
||||
baseUrl: input.httpBaseUrl,
|
||||
timeoutMs: SSH_READY_TIMEOUT_MS,
|
||||
timeout: SSH_READY_TIMEOUT,
|
||||
}),
|
||||
exitFailure,
|
||||
).pipe(
|
||||
@@ -1226,7 +1234,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
: child
|
||||
.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
|
||||
})
|
||||
.pipe(Effect.ignore),
|
||||
),
|
||||
@@ -1470,7 +1478,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
[
|
||||
tunnelEntry.process.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
|
||||
}),
|
||||
stopRemoteServer(
|
||||
tunnelEntry.target,
|
||||
@@ -1524,7 +1532,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
remotePort: entry.remotePort,
|
||||
});
|
||||
const readinessExit = yield* Effect.exit(
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeoutMs: 2_000 }),
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeout: Duration.seconds(2) }),
|
||||
);
|
||||
if (Exit.isSuccess(readinessExit)) {
|
||||
yield* Effect.logDebug("ssh.environment.tunnel.reused", {
|
||||
|
||||
Reference in new issue
Block a user