Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0593260f66 | ||
|
|
9e8e6e9abd |
No files matched your search
@@ -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";
|
||||
|
||||
@@ -76,8 +75,6 @@ export interface DesktopSshEnvironmentLayerOptions {
|
||||
readonly resolveCliRunner?: Effect.Effect<RemoteT3RunnerOptions>;
|
||||
}
|
||||
|
||||
const isSshPasswordPromptError = Schema.is(SshPasswordPromptError);
|
||||
|
||||
function discoverDesktopSshHostsEffect(input?: { readonly homeDir?: string }) {
|
||||
return discoverSshHosts(input ?? {});
|
||||
}
|
||||
@@ -86,7 +83,7 @@ export function isDesktopSshPasswordPromptCancellation(
|
||||
error: unknown,
|
||||
): error is SshPasswordPromptError {
|
||||
return (
|
||||
isSshPasswordPromptError(error) &&
|
||||
error instanceof SshPasswordPromptError &&
|
||||
DesktopSshPasswordPrompts.isDesktopSshPasswordPromptCancellation(error.cause)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,10 @@ 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";
|
||||
|
||||
const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
|
||||
|
||||
function jsonResponse(request: HttpClientRequest.HttpClientRequest, body: unknown, status = 200) {
|
||||
return HttpClientResponse.fromWeb(
|
||||
request,
|
||||
@@ -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));
|
||||
});
|
||||
});
|
||||
@@ -41,8 +41,7 @@ describe("VcsProjectConfig", () => {
|
||||
yield* fileSystem.makeDirectory(nested, { recursive: true });
|
||||
yield* fileSystem.writeFileString(
|
||||
path.join(configDir, "vcs.json"),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify({ vcs: { kind: "jj" } }),
|
||||
'{"vcs":{"kind":"jj"}}',
|
||||
);
|
||||
|
||||
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||
@@ -53,6 +52,26 @@ describe("VcsProjectConfig", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.layer(TestLayer)("ignores malformed .t3code/vcs.json files", (it) => {
|
||||
it.effect("falls back to auto", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const root = yield* fileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-vcs-config-test-",
|
||||
});
|
||||
const configDir = path.join(root, ".t3code");
|
||||
yield* fileSystem.makeDirectory(configDir, { recursive: true });
|
||||
yield* fileSystem.writeFileString(path.join(configDir, "vcs.json"), "{ not-json");
|
||||
|
||||
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||
const kind = yield* config.resolveKind({ cwd: root });
|
||||
|
||||
assert.equal(kind, "auto");
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.layer(TestLayer)("falls back to auto when no config exists", (it) => {
|
||||
it.effect("returns auto", () =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
@@ -15,16 +16,10 @@ const ProjectVcsConfig = Schema.Struct({
|
||||
),
|
||||
vcsKind: Schema.optional(VcsDriverKind),
|
||||
});
|
||||
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
|
||||
const ProjectVcsConfigJson = Schema.fromJsonString(ProjectVcsConfig);
|
||||
const decodeProjectVcsConfig = Schema.decodeUnknownOption(ProjectVcsConfigJson);
|
||||
|
||||
interface ProjectVcsConfigFile {
|
||||
readonly vcs?:
|
||||
| {
|
||||
readonly kind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
| undefined;
|
||||
readonly vcsKind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
type ProjectVcsConfigFile = Schema.Schema.Type<typeof ProjectVcsConfig>;
|
||||
|
||||
export interface VcsProjectConfigResolveInput {
|
||||
readonly cwd: string;
|
||||
@@ -45,13 +40,8 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
|
||||
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
||||
}
|
||||
|
||||
function parseConfig(raw: string): ProjectVcsConfigFile | null {
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
return isProjectVcsConfig(parsed) ? parsed : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
function parseConfig(raw: string): Option.Option<ProjectVcsConfigFile> {
|
||||
return decodeProjectVcsConfig(raw);
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
@@ -63,12 +53,12 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
while (true) {
|
||||
const candidate = path.join(current, ".t3code", "vcs.json");
|
||||
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
|
||||
return candidate;
|
||||
return Option.some(candidate);
|
||||
}
|
||||
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) {
|
||||
return null;
|
||||
return Option.none<string>();
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
@@ -78,26 +68,27 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
configPath: string,
|
||||
) {
|
||||
const raw = yield* fileSystem.readFileString(configPath).pipe(
|
||||
Effect.map(Option.some),
|
||||
Effect.catch((error) =>
|
||||
Effect.logWarning("failed to read VCS project config", {
|
||||
configPath,
|
||||
error,
|
||||
}).pipe(Effect.as(null)),
|
||||
}).pipe(Effect.as(Option.none<string>())),
|
||||
),
|
||||
);
|
||||
if (raw === null) {
|
||||
if (Option.isNone(raw)) {
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
const parsed = parseConfig(raw);
|
||||
if (parsed === null) {
|
||||
const parsed = parseConfig(raw.value);
|
||||
if (Option.isNone(parsed)) {
|
||||
yield* Effect.logWarning("invalid VCS project config", {
|
||||
configPath,
|
||||
});
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
return configuredKind(parsed);
|
||||
return configuredKind(parsed.value);
|
||||
});
|
||||
|
||||
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
||||
@@ -108,11 +99,11 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
}
|
||||
|
||||
const configPath = yield* findConfigPath(input.cwd);
|
||||
if (configPath === null) {
|
||||
if (Option.isNone(configPath)) {
|
||||
return "auto";
|
||||
}
|
||||
|
||||
return yield* readConfiguredKind(configPath);
|
||||
return yield* readConfiguredKind(configPath.value);
|
||||
});
|
||||
|
||||
return VcsProjectConfig.of({
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
} from "../Services/WorkspaceEntries.ts";
|
||||
import { WorkspacePaths } from "../Services/WorkspacePaths.ts";
|
||||
|
||||
const WORKSPACE_CACHE_TTL_MS = 15_000;
|
||||
const WORKSPACE_CACHE_TTL = Duration.seconds(15);
|
||||
const WORKSPACE_CACHE_MAX_KEYS = 4;
|
||||
const WORKSPACE_INDEX_MAX_ENTRIES = 25_000;
|
||||
const WORKSPACE_SCAN_READDIR_CONCURRENCY = 32;
|
||||
@@ -402,8 +402,7 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
|
||||
buildWorkspaceIndex,
|
||||
{
|
||||
capacity: WORKSPACE_CACHE_MAX_KEYS,
|
||||
timeToLive: (exit) =>
|
||||
Exit.isSuccess(exit) ? Duration.millis(WORKSPACE_CACHE_TTL_MS) : Duration.zero,
|
||||
timeToLive: (exit) => (Exit.isSuccess(exit) ? WORKSPACE_CACHE_TTL : Duration.zero),
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
+38
-53
@@ -1,61 +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 SshReadinessError extends Schema.TaggedErrorClass<SshReadinessError>()(
|
||||
"SshReadinessError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshReadinessError extends Data.TaggedError("SshReadinessError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
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;
|
||||
}> {}
|
||||
@@ -167,7 +167,6 @@ const RemoteHttpError = Schema.Struct({
|
||||
const decodeRemoteLaunchResult = Schema.decodeEffect(fromLenientJson(RemoteLaunchResult));
|
||||
const decodeRemotePairingResult = Schema.decodeEffect(fromLenientJson(RemotePairingResult));
|
||||
const decodeRemoteHttpError = Schema.decodeEffect(Schema.fromJsonString(RemoteHttpError));
|
||||
const isSshReadinessError = Schema.is(SshReadinessError);
|
||||
|
||||
const decodeRemoteJsonOutput = <A, E>(
|
||||
stdout: string,
|
||||
@@ -238,7 +237,7 @@ function applyScriptPlaceholders(
|
||||
}
|
||||
|
||||
export function describeReadinessCause(cause: unknown): unknown {
|
||||
if (isSshReadinessError(cause)) {
|
||||
if (cause instanceof SshReadinessError) {
|
||||
return {
|
||||
_tag: cause._tag,
|
||||
message: cause.message,
|
||||
@@ -926,7 +925,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
});
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
@@ -947,7 +946,7 @@ 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 SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -7,36 +7,24 @@ import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
export const DEFAULT_TAILSCALE_SERVE_PORT = 443;
|
||||
export const TAILSCALE_STATUS_TIMEOUT = Duration.millis(1_500);
|
||||
export const TAILSCALE_SERVE_TIMEOUT = Duration.seconds(10);
|
||||
export const TAILSCALE_PROBE_TIMEOUT = Duration.millis(2_500);
|
||||
export const TAILSCALE_STATUS_TIMEOUT_MS = Duration.toMillis(TAILSCALE_STATUS_TIMEOUT);
|
||||
export const TAILSCALE_SERVE_TIMEOUT_MS = Duration.toMillis(TAILSCALE_SERVE_TIMEOUT);
|
||||
export const TAILSCALE_PROBE_TIMEOUT_MS = Duration.toMillis(TAILSCALE_PROBE_TIMEOUT);
|
||||
export const TAILSCALE_STATUS_TIMEOUT_MS = 1_500;
|
||||
export const TAILSCALE_SERVE_TIMEOUT_MS = 10_000;
|
||||
export const TAILSCALE_PROBE_TIMEOUT_MS = 2_500;
|
||||
|
||||
export class TailscaleCommandError extends Schema.TaggedErrorClass<TailscaleCommandError>()(
|
||||
"TailscaleCommandError",
|
||||
{
|
||||
command: Schema.Array(Schema.String),
|
||||
message: Schema.String,
|
||||
exitCode: Schema.NullOr(Schema.Number),
|
||||
stderr: Schema.String,
|
||||
},
|
||||
) {}
|
||||
export class TailscaleCommandError extends Data.TaggedError("TailscaleCommandError")<{
|
||||
readonly command: readonly string[];
|
||||
readonly message: string;
|
||||
readonly exitCode: number | null;
|
||||
readonly stderr: string;
|
||||
}> {}
|
||||
|
||||
export class TailscaleStatusParseError extends Schema.TaggedErrorClass<TailscaleStatusParseError>()(
|
||||
"TailscaleStatusParseError",
|
||||
{
|
||||
cause: Schema.Defect,
|
||||
},
|
||||
) {}
|
||||
export class TailscaleStatusParseError extends Data.TaggedError("TailscaleStatusParseError")<{
|
||||
readonly cause: unknown;
|
||||
}> {}
|
||||
|
||||
export class TailscaleUnavailableError extends Schema.TaggedErrorClass<TailscaleUnavailableError>()(
|
||||
"TailscaleUnavailableError",
|
||||
{
|
||||
reason: Schema.String,
|
||||
},
|
||||
) {}
|
||||
export class TailscaleUnavailableError extends Data.TaggedError("TailscaleUnavailableError")<{
|
||||
readonly reason: string;
|
||||
}> {}
|
||||
|
||||
const TailscaleStatusSelf = Schema.Struct({
|
||||
DNSName: Schema.optional(Schema.Unknown),
|
||||
@@ -186,7 +174,7 @@ export const readTailscaleStatus: Effect.Effect<
|
||||
return yield* parseTailscaleStatus(stdout);
|
||||
}).pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(TAILSCALE_STATUS_TIMEOUT),
|
||||
Effect.timeoutOption(TAILSCALE_STATUS_TIMEOUT_MS),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () =>
|
||||
@@ -218,7 +206,7 @@ const runTailscaleCommand = (
|
||||
readonly runMessage: string;
|
||||
readonly exitMessage: (exitCode: number) => string;
|
||||
readonly timeoutMessage: string;
|
||||
readonly timeout: Duration.Input;
|
||||
readonly timeoutMs: number;
|
||||
},
|
||||
): Effect.Effect<void, TailscaleCommandError, ChildProcessSpawner.ChildProcessSpawner> =>
|
||||
Effect.gen(function* () {
|
||||
@@ -255,7 +243,7 @@ const runTailscaleCommand = (
|
||||
}
|
||||
}).pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(input.timeout),
|
||||
Effect.timeoutOption(input.timeoutMs),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () => Effect.fail(tailscaleCommandError(args, input.timeoutMessage, null)),
|
||||
@@ -277,7 +265,7 @@ export const ensureTailscaleServe = (input: {
|
||||
runMessage: "Failed to run tailscale serve.",
|
||||
exitMessage: (exitCode) => `Tailscale serve exited with code ${exitCode}.`,
|
||||
timeoutMessage: "Tailscale serve timed out.",
|
||||
timeout: TAILSCALE_SERVE_TIMEOUT,
|
||||
timeoutMs: TAILSCALE_SERVE_TIMEOUT_MS,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -293,13 +281,13 @@ export const disableTailscaleServe = (
|
||||
runMessage: "Failed to run tailscale serve off.",
|
||||
exitMessage: (exitCode) => `Tailscale serve off exited with code ${exitCode}.`,
|
||||
timeoutMessage: "Tailscale serve off timed out.",
|
||||
timeout: TAILSCALE_SERVE_TIMEOUT,
|
||||
timeoutMs: TAILSCALE_SERVE_TIMEOUT_MS,
|
||||
});
|
||||
});
|
||||
|
||||
export const probeTailscaleHttpsEndpoint = (input: {
|
||||
readonly baseUrl: string;
|
||||
readonly timeout?: Duration.Input;
|
||||
readonly timeoutMs?: number;
|
||||
}): Effect.Effect<boolean, never, HttpClient.HttpClient> =>
|
||||
Effect.gen(function* () {
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
@@ -307,7 +295,7 @@ export const probeTailscaleHttpsEndpoint = (input: {
|
||||
const url = new URL("/.well-known/t3/environment", input.baseUrl);
|
||||
const request = HttpClientRequest.get(url.toString());
|
||||
return yield* client.execute(request);
|
||||
}).pipe(Effect.timeoutOption(input.timeout ?? TAILSCALE_PROBE_TIMEOUT));
|
||||
}).pipe(Effect.timeoutOption(input.timeoutMs ?? TAILSCALE_PROBE_TIMEOUT_MS));
|
||||
|
||||
return Option.match(response, {
|
||||
onNone: () => false,
|
||||
|
||||
Reference in new issue
Block a user