Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6dfcdaa427 |
No files matched your search
@@ -41,8 +41,7 @@ describe("VcsProjectConfig", () => {
|
|||||||
yield* fileSystem.makeDirectory(nested, { recursive: true });
|
yield* fileSystem.makeDirectory(nested, { recursive: true });
|
||||||
yield* fileSystem.writeFileString(
|
yield* fileSystem.writeFileString(
|
||||||
path.join(configDir, "vcs.json"),
|
path.join(configDir, "vcs.json"),
|
||||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
'{"vcs":{"kind":"jj"}}',
|
||||||
JSON.stringify({ vcs: { kind: "jj" } }),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||||
@@ -67,4 +66,24 @@ describe("VcsProjectConfig", () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.layer(TestLayer)("falls back to auto when config JSON is invalid", (it) => {
|
||||||
|
it.effect("returns 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"), "{invalid-json");
|
||||||
|
|
||||||
|
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||||
|
const kind = yield* config.resolveKind({ cwd: root });
|
||||||
|
|
||||||
|
assert.equal(kind, "auto");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -2,6 +2,7 @@ import * as Context from "effect/Context";
|
|||||||
import * as Effect from "effect/Effect";
|
import * as Effect from "effect/Effect";
|
||||||
import * as FileSystem from "effect/FileSystem";
|
import * as FileSystem from "effect/FileSystem";
|
||||||
import * as Layer from "effect/Layer";
|
import * as Layer from "effect/Layer";
|
||||||
|
import * as Option from "effect/Option";
|
||||||
import * as Path from "effect/Path";
|
import * as Path from "effect/Path";
|
||||||
import * as Schema from "effect/Schema";
|
import * as Schema from "effect/Schema";
|
||||||
|
|
||||||
@@ -15,16 +16,9 @@ const ProjectVcsConfig = Schema.Struct({
|
|||||||
),
|
),
|
||||||
vcsKind: Schema.optional(VcsDriverKind),
|
vcsKind: Schema.optional(VcsDriverKind),
|
||||||
});
|
});
|
||||||
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
|
const decodeProjectVcsConfig = Schema.decodeUnknownOption(Schema.fromJsonString(ProjectVcsConfig));
|
||||||
|
|
||||||
interface ProjectVcsConfigFile {
|
type ProjectVcsConfigFile = typeof ProjectVcsConfig.Type;
|
||||||
readonly vcs?:
|
|
||||||
| {
|
|
||||||
readonly kind?: VcsDriverKindType | undefined;
|
|
||||||
}
|
|
||||||
| undefined;
|
|
||||||
readonly vcsKind?: VcsDriverKindType | undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface VcsProjectConfigResolveInput {
|
export interface VcsProjectConfigResolveInput {
|
||||||
readonly cwd: string;
|
readonly cwd: string;
|
||||||
@@ -45,14 +39,8 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
|
|||||||
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseConfig(raw: string): ProjectVcsConfigFile | null {
|
const parseConfig = (raw: string): Option.Option<ProjectVcsConfigFile> =>
|
||||||
try {
|
decodeProjectVcsConfig(raw);
|
||||||
const parsed = JSON.parse(raw) as unknown;
|
|
||||||
return isProjectVcsConfig(parsed) ? parsed : null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||||
const fileSystem = yield* FileSystem.FileSystem;
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
@@ -63,12 +51,12 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
|||||||
while (true) {
|
while (true) {
|
||||||
const candidate = path.join(current, ".t3code", "vcs.json");
|
const candidate = path.join(current, ".t3code", "vcs.json");
|
||||||
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
|
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
|
||||||
return candidate;
|
return Option.some(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = path.dirname(current);
|
const parent = path.dirname(current);
|
||||||
if (parent === current) {
|
if (parent === current) {
|
||||||
return null;
|
return Option.none();
|
||||||
}
|
}
|
||||||
current = parent;
|
current = parent;
|
||||||
}
|
}
|
||||||
@@ -78,26 +66,25 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
|||||||
configPath: string,
|
configPath: string,
|
||||||
) {
|
) {
|
||||||
const raw = yield* fileSystem.readFileString(configPath).pipe(
|
const raw = yield* fileSystem.readFileString(configPath).pipe(
|
||||||
|
Effect.map(Option.some),
|
||||||
Effect.catch((error) =>
|
Effect.catch((error) =>
|
||||||
Effect.logWarning("failed to read VCS project config", {
|
Effect.logWarning("failed to read VCS project config", {
|
||||||
configPath,
|
configPath,
|
||||||
error,
|
error,
|
||||||
}).pipe(Effect.as(null)),
|
}).pipe(Effect.as(Option.none<string>())),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (raw === null) {
|
if (Option.isNone(raw)) return "auto" as const;
|
||||||
return "auto" as const;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsed = parseConfig(raw);
|
const parsed = parseConfig(raw.value);
|
||||||
if (parsed === null) {
|
if (Option.isNone(parsed)) {
|
||||||
yield* Effect.logWarning("invalid VCS project config", {
|
yield* Effect.logWarning("invalid VCS project config", {
|
||||||
configPath,
|
configPath,
|
||||||
});
|
});
|
||||||
return "auto" as const;
|
return "auto" as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
return configuredKind(parsed);
|
return configuredKind(parsed.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
||||||
@@ -108,11 +95,9 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const configPath = yield* findConfigPath(input.cwd);
|
const configPath = yield* findConfigPath(input.cwd);
|
||||||
if (configPath === null) {
|
if (Option.isNone(configPath)) return "auto";
|
||||||
return "auto";
|
|
||||||
}
|
|
||||||
|
|
||||||
return yield* readConfiguredKind(configPath);
|
return yield* readConfiguredKind(configPath.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
return VcsProjectConfig.of({
|
return VcsProjectConfig.of({
|
||||||
|
|||||||
@@ -242,9 +242,9 @@ describe("ssh tunnel scripts", () => {
|
|||||||
Effect.result(
|
Effect.result(
|
||||||
waitForHttpReady({
|
waitForHttpReady({
|
||||||
baseUrl: "http://127.0.0.1:41773/",
|
baseUrl: "http://127.0.0.1:41773/",
|
||||||
timeoutMs: 1_000,
|
timeout: Duration.seconds(1),
|
||||||
intervalMs: 100,
|
interval: Duration.millis(100),
|
||||||
probeTimeoutMs: 250,
|
probeTimeout: Duration.millis(250),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
+26
-23
@@ -50,11 +50,13 @@ import {
|
|||||||
|
|
||||||
export const DEFAULT_REMOTE_PORT = 3773;
|
export const DEFAULT_REMOTE_PORT = 3773;
|
||||||
const REMOTE_PORT_SCAN_WINDOW = 200;
|
const REMOTE_PORT_SCAN_WINDOW = 200;
|
||||||
const SSH_READY_TIMEOUT_MS = 20_000;
|
const DEFAULT_HTTP_READY_TIMEOUT = Duration.seconds(30);
|
||||||
const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
|
const DEFAULT_HTTP_READY_INTERVAL = Duration.millis(100);
|
||||||
const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
|
const SSH_READY_TIMEOUT = Duration.seconds(20);
|
||||||
const REMOTE_READY_TIMEOUT_MS = 15_000;
|
const SSH_READY_PROBE_TIMEOUT = Duration.seconds(1);
|
||||||
const REMOTE_REUSE_READY_TIMEOUT_MS = 2_000;
|
const TUNNEL_SHUTDOWN_TIMEOUT = Duration.seconds(2);
|
||||||
|
const REMOTE_READY_TIMEOUT = Duration.seconds(15);
|
||||||
|
const REMOTE_REUSE_READY_TIMEOUT = Duration.seconds(2);
|
||||||
|
|
||||||
export interface RemoteT3RunnerOptions {
|
export interface RemoteT3RunnerOptions {
|
||||||
readonly packageSpec?: string;
|
readonly packageSpec?: string;
|
||||||
@@ -686,9 +688,9 @@ export function buildRemoteLaunchScript(input?: RemoteT3RunnerOptions): string {
|
|||||||
T3_WAIT_READY_SCRIPT: stripTrailingNewlines(REMOTE_WAIT_READY_SCRIPT),
|
T3_WAIT_READY_SCRIPT: stripTrailingNewlines(REMOTE_WAIT_READY_SCRIPT),
|
||||||
T3_DEFAULT_REMOTE_PORT: String(DEFAULT_REMOTE_PORT),
|
T3_DEFAULT_REMOTE_PORT: String(DEFAULT_REMOTE_PORT),
|
||||||
T3_REMOTE_PORT_SCAN_WINDOW: String(REMOTE_PORT_SCAN_WINDOW),
|
T3_REMOTE_PORT_SCAN_WINDOW: String(REMOTE_PORT_SCAN_WINDOW),
|
||||||
T3_READY_TIMEOUT_MS: String(REMOTE_READY_TIMEOUT_MS),
|
T3_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_READY_TIMEOUT)),
|
||||||
T3_REUSE_READY_TIMEOUT_MS: String(REMOTE_REUSE_READY_TIMEOUT_MS),
|
T3_REUSE_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_REUSE_READY_TIMEOUT)),
|
||||||
T3_READY_PROBE_TIMEOUT_MS: String(SSH_READY_PROBE_TIMEOUT_MS),
|
T3_READY_PROBE_TIMEOUT_MS: String(Duration.toMillis(SSH_READY_PROBE_TIMEOUT)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -870,17 +872,18 @@ const readRemoteServerLogTail = Effect.fn("ssh/tunnel.readRemoteServerLogTail")(
|
|||||||
|
|
||||||
export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(function* (input: {
|
export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(function* (input: {
|
||||||
readonly baseUrl: string;
|
readonly baseUrl: string;
|
||||||
readonly timeoutMs?: number;
|
readonly timeout?: Duration.Duration;
|
||||||
readonly intervalMs?: number;
|
readonly interval?: Duration.Duration;
|
||||||
readonly probeTimeoutMs?: number;
|
readonly probeTimeout?: Duration.Duration;
|
||||||
readonly path?: string;
|
readonly path?: string;
|
||||||
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
|
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
|
||||||
const timeoutMs = input.timeoutMs ?? 30_000;
|
const timeout = input.timeout ?? DEFAULT_HTTP_READY_TIMEOUT;
|
||||||
const intervalMs = input.intervalMs ?? 100;
|
const interval = input.interval ?? DEFAULT_HTTP_READY_INTERVAL;
|
||||||
const probeTimeoutMs = input.probeTimeoutMs ?? SSH_READY_PROBE_TIMEOUT_MS;
|
const probeTimeout = input.probeTimeout ?? SSH_READY_PROBE_TIMEOUT;
|
||||||
const retryPolicy = Schedule.spaced(Duration.millis(intervalMs)).pipe(
|
const timeoutMs = Duration.toMillis(timeout);
|
||||||
Schedule.take(Math.max(0, Math.ceil(timeoutMs / intervalMs))),
|
const intervalMs = Duration.toMillis(interval);
|
||||||
);
|
const probeTimeoutMs = Duration.toMillis(probeTimeout);
|
||||||
|
const retryPolicy = Schedule.spaced(interval);
|
||||||
const requestUrl = new URL(input.path ?? "/", input.baseUrl).toString();
|
const requestUrl = new URL(input.path ?? "/", input.baseUrl).toString();
|
||||||
const client = yield* HttpClient.HttpClient;
|
const client = yield* HttpClient.HttpClient;
|
||||||
const lastProbeFailure = yield* Ref.make<unknown>(null);
|
const lastProbeFailure = yield* Ref.make<unknown>(null);
|
||||||
@@ -900,7 +903,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
|||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
attempt += 1;
|
attempt += 1;
|
||||||
const responseOption = yield* effect.pipe(
|
const responseOption = yield* effect.pipe(
|
||||||
Effect.timeoutOption(Duration.millis(probeTimeoutMs)),
|
Effect.timeoutOption(probeTimeout),
|
||||||
Effect.mapError(
|
Effect.mapError(
|
||||||
(cause) =>
|
(cause) =>
|
||||||
new SshReadinessError({
|
new SshReadinessError({
|
||||||
@@ -953,7 +956,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
|||||||
cause,
|
cause,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
Effect.timeoutOption(Duration.millis(timeoutMs)),
|
Effect.timeoutOption(timeout),
|
||||||
);
|
);
|
||||||
|
|
||||||
return yield* Option.match(result, {
|
return yield* Option.match(result, {
|
||||||
@@ -1236,7 +1239,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
|||||||
yield* Effect.raceFirst(
|
yield* Effect.raceFirst(
|
||||||
waitForHttpReady({
|
waitForHttpReady({
|
||||||
baseUrl: input.httpBaseUrl,
|
baseUrl: input.httpBaseUrl,
|
||||||
timeoutMs: SSH_READY_TIMEOUT_MS,
|
timeout: SSH_READY_TIMEOUT,
|
||||||
}),
|
}),
|
||||||
exitFailure,
|
exitFailure,
|
||||||
).pipe(
|
).pipe(
|
||||||
@@ -1296,7 +1299,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
|||||||
: child
|
: child
|
||||||
.kill({
|
.kill({
|
||||||
killSignal: "SIGTERM",
|
killSignal: "SIGTERM",
|
||||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
|
||||||
})
|
})
|
||||||
.pipe(Effect.ignore),
|
.pipe(Effect.ignore),
|
||||||
),
|
),
|
||||||
@@ -1540,7 +1543,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
|||||||
[
|
[
|
||||||
tunnelEntry.process.kill({
|
tunnelEntry.process.kill({
|
||||||
killSignal: "SIGTERM",
|
killSignal: "SIGTERM",
|
||||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
|
||||||
}),
|
}),
|
||||||
stopRemoteServer(
|
stopRemoteServer(
|
||||||
tunnelEntry.target,
|
tunnelEntry.target,
|
||||||
@@ -1594,7 +1597,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
|||||||
remotePort: entry.remotePort,
|
remotePort: entry.remotePort,
|
||||||
});
|
});
|
||||||
const readinessExit = yield* Effect.exit(
|
const readinessExit = yield* Effect.exit(
|
||||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeoutMs: 2_000 }),
|
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeout: REMOTE_REUSE_READY_TIMEOUT }),
|
||||||
);
|
);
|
||||||
if (Exit.isSuccess(readinessExit)) {
|
if (Exit.isSuccess(readinessExit)) {
|
||||||
yield* Effect.logDebug("ssh.environment.tunnel.reused", {
|
yield* Effect.logDebug("ssh.environment.tunnel.reused", {
|
||||||
|
|||||||
Reference in new issue
Block a user