Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d73e66a1c |
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
const reactMock = vi.hoisted(() => ({
|
||||
useDeferredValue: vi.fn<(text: string) => string>(),
|
||||
}));
|
||||
|
||||
vi.mock("react", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("react")>()),
|
||||
useDeferredValue: reactMock.useDeferredValue,
|
||||
}));
|
||||
|
||||
import ChatMarkdown from "./ChatMarkdown";
|
||||
|
||||
describe("ChatMarkdown streaming rendering", () => {
|
||||
beforeEach(() => {
|
||||
reactMock.useDeferredValue.mockReset();
|
||||
});
|
||||
|
||||
it("renders the scheduled markdown text instead of the latest streaming source", () => {
|
||||
reactMock.useDeferredValue.mockReturnValue("**deferred markdown**");
|
||||
|
||||
const markup = renderToStaticMarkup(
|
||||
<ChatMarkdown text="latest markdown" cwd={undefined} isStreaming />,
|
||||
);
|
||||
|
||||
expect(reactMock.useDeferredValue).toHaveBeenCalledWith("latest markdown");
|
||||
expect(markup).toContain("<strong>deferred markdown</strong>");
|
||||
expect(markup).not.toContain("latest markdown");
|
||||
});
|
||||
|
||||
it("renders the latest markdown immediately after streaming finishes", () => {
|
||||
reactMock.useDeferredValue.mockReturnValue("stale markdown");
|
||||
|
||||
const markup = renderToStaticMarkup(<ChatMarkdown text="final markdown" cwd={undefined} />);
|
||||
|
||||
expect(markup).toContain("final markdown");
|
||||
expect(markup).not.toContain("stale markdown");
|
||||
});
|
||||
});
|
||||
@@ -25,6 +25,7 @@ import React, {
|
||||
isValidElement,
|
||||
use,
|
||||
useCallback,
|
||||
useDeferredValue,
|
||||
memo,
|
||||
useEffect,
|
||||
useMemo,
|
||||
@@ -1172,12 +1173,14 @@ function ChatMarkdown({
|
||||
serverConfig?.availableEditors ?? [],
|
||||
);
|
||||
const diffThemeName = resolveDiffThemeName(resolvedTheme);
|
||||
const deferredText = useDeferredValue(text);
|
||||
const markdownText = isStreaming ? deferredText : text;
|
||||
const markdownFileLinkMetaByHref = useMemo(() => {
|
||||
const metaByHref = new Map<
|
||||
string,
|
||||
NonNullable<ReturnType<typeof resolveMarkdownFileLinkMeta>>
|
||||
>();
|
||||
for (const href of extractMarkdownLinkHrefs(text)) {
|
||||
for (const href of extractMarkdownLinkHrefs(markdownText)) {
|
||||
const normalizedHref = normalizeMarkdownLinkHrefKey(href);
|
||||
if (metaByHref.has(normalizedHref)) continue;
|
||||
const meta = resolveMarkdownFileLinkMeta(normalizedHref, cwd);
|
||||
@@ -1186,7 +1189,7 @@ function ChatMarkdown({
|
||||
}
|
||||
}
|
||||
return metaByHref;
|
||||
}, [cwd, text]);
|
||||
}, [cwd, markdownText]);
|
||||
const fileLinkParentSuffixByPath = useMemo(() => {
|
||||
const filePaths = [...markdownFileLinkMetaByHref.values()].map((meta) => meta.filePath);
|
||||
return buildFileLinkParentSuffixByPath(filePaths);
|
||||
@@ -1253,7 +1256,9 @@ function ChatMarkdown({
|
||||
li({ node, children, ...props }) {
|
||||
const listItemStart = node?.position?.start.offset;
|
||||
const markerOffset =
|
||||
typeof listItemStart === "number" ? findTaskListMarkerOffset(text, listItemStart) : null;
|
||||
typeof listItemStart === "number"
|
||||
? findTaskListMarkerOffset(markdownText, listItemStart)
|
||||
: null;
|
||||
return (
|
||||
<li {...props} data-task-marker-offset={markerOffset ?? undefined}>
|
||||
{renderSkillInlineMarkdownChildren(children, skills)}
|
||||
@@ -1439,7 +1444,7 @@ function ChatMarkdown({
|
||||
openMarkdownFileInPreview,
|
||||
resolvedTheme,
|
||||
skills,
|
||||
text,
|
||||
markdownText,
|
||||
threadRef,
|
||||
],
|
||||
);
|
||||
@@ -1462,7 +1467,7 @@ function ChatMarkdown({
|
||||
components={markdownComponents}
|
||||
urlTransform={markdownUrlTransform}
|
||||
>
|
||||
{text}
|
||||
{markdownText}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import * as NodeCrypto from "node:crypto";
|
||||
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import * as Option from "effect/Option";
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
|
||||
import {
|
||||
computeDpopAccessTokenHash,
|
||||
computeDpopJwkThumbprint,
|
||||
normalizeDpopHtu,
|
||||
normalizeDpopHtuOption,
|
||||
type DpopPublicJwk,
|
||||
verifyDpopProof,
|
||||
} from "./dpop.ts";
|
||||
@@ -58,58 +56,59 @@ describe("verifyDpopProof", () => {
|
||||
|
||||
it("verifies an ES256 DPoP proof and returns the RFC 7638 thumbprint", () => {
|
||||
const thumbprint = computeDpopJwkThumbprint(publicJwk);
|
||||
const result = verifyDpopProof({
|
||||
proof,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
thumbprint,
|
||||
jti: "proof-1",
|
||||
});
|
||||
assert.isTrue(result.ok);
|
||||
if (result.ok) {
|
||||
assert.equal(result.thumbprint, thumbprint);
|
||||
assert.equal(result.jti, "proof-1");
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects method, URL, thumbprint, and time-window mismatches", () => {
|
||||
const thumbprint = computeDpopJwkThumbprint(publicJwk);
|
||||
assert.isFalse(
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof,
|
||||
method: "GET",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
}).ok,
|
||||
);
|
||||
assert.isFalse(
|
||||
}),
|
||||
).toMatchObject({ ok: false });
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof,
|
||||
method: "POST",
|
||||
url: "https://example.com/other",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
}).ok,
|
||||
);
|
||||
assert.isFalse(
|
||||
}),
|
||||
).toMatchObject({ ok: false });
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: "other-thumbprint",
|
||||
}).ok,
|
||||
);
|
||||
assert.isFalse(
|
||||
}),
|
||||
).toMatchObject({ ok: false });
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 1_000,
|
||||
expectedThumbprint: thumbprint,
|
||||
}).ok,
|
||||
);
|
||||
}),
|
||||
).toMatchObject({ ok: false });
|
||||
});
|
||||
|
||||
it("requires the RFC 9449 access token hash when an access token is expected", () => {
|
||||
@@ -123,7 +122,7 @@ describe("verifyDpopProof", () => {
|
||||
accessToken: "clerk-access-token",
|
||||
});
|
||||
|
||||
assert.isTrue(
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof: accessTokenProof,
|
||||
method: "POST",
|
||||
@@ -131,42 +130,32 @@ describe("verifyDpopProof", () => {
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
expectedAccessToken: "clerk-access-token",
|
||||
}).ok,
|
||||
);
|
||||
const missingAth = verifyDpopProof({
|
||||
proof,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
expectedAccessToken: "clerk-access-token",
|
||||
});
|
||||
assert.isFalse(missingAth.ok);
|
||||
if (!missingAth.ok) {
|
||||
assert.equal(missingAth.reason, "DPoP access token hash mismatch.");
|
||||
}
|
||||
const mismatchedAth = verifyDpopProof({
|
||||
proof: accessTokenProof,
|
||||
method: "POST",
|
||||
url: "https://example.com/v1/environments/env/connect",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
expectedAccessToken: "other-access-token",
|
||||
});
|
||||
assert.isFalse(mismatchedAth.ok);
|
||||
if (!mismatchedAth.ok) {
|
||||
assert.equal(mismatchedAth.reason, "DPoP access token hash mismatch.");
|
||||
}
|
||||
}),
|
||||
).toMatchObject({ ok: true });
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
expectedAccessToken: "clerk-access-token",
|
||||
}),
|
||||
).toMatchObject({ ok: false, reason: "DPoP access token hash mismatch." });
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof: accessTokenProof,
|
||||
method: "POST",
|
||||
url: "https://example.com/v1/environments/env/connect",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
expectedAccessToken: "other-access-token",
|
||||
}),
|
||||
).toMatchObject({ ok: false, reason: "DPoP access token hash mismatch." });
|
||||
});
|
||||
|
||||
it("normalizes htu by excluding query and fragment components per RFC 9449", () => {
|
||||
const normalized = normalizeDpopHtuOption(
|
||||
"https://example.com/v1/environments/env/connect?foo=bar#frag",
|
||||
);
|
||||
assert.isTrue(Option.isSome(normalized));
|
||||
assert.equal(Option.getOrThrow(normalized), "https://example.com/v1/environments/env/connect");
|
||||
assert.equal(
|
||||
normalizeDpopHtu("https://example.com/v1/environments/env/connect?foo=bar#frag"),
|
||||
expect(normalizeDpopHtu("https://example.com/v1/environments/env/connect?foo=bar#frag")).toBe(
|
||||
"https://example.com/v1/environments/env/connect",
|
||||
);
|
||||
|
||||
@@ -179,15 +168,15 @@ describe("verifyDpopProof", () => {
|
||||
publicJwk,
|
||||
});
|
||||
|
||||
assert.isTrue(
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof: queryProof,
|
||||
method: "POST",
|
||||
url: "https://example.com/v1/environments/env/connect?foo=bar#frag",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
}).ok,
|
||||
);
|
||||
}),
|
||||
).toMatchObject({ ok: true });
|
||||
});
|
||||
|
||||
it("rejects DPoP public JWK headers that expose private key material", () => {
|
||||
@@ -203,16 +192,14 @@ describe("verifyDpopProof", () => {
|
||||
publicJwk: privateJwk,
|
||||
});
|
||||
|
||||
const result = verifyDpopProof({
|
||||
proof: proofWithPrivateJwk,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
});
|
||||
assert.isFalse(result.ok);
|
||||
if (!result.ok) {
|
||||
assert.equal(result.reason, "Invalid DPoP JWT header.");
|
||||
}
|
||||
expect(
|
||||
verifyDpopProof({
|
||||
proof: proofWithPrivateJwk,
|
||||
method: "POST",
|
||||
url: "https://example.com/oauth/token",
|
||||
nowEpochSeconds: 101,
|
||||
expectedThumbprint: thumbprint,
|
||||
}),
|
||||
).toMatchObject({ ok: false, reason: "Invalid DPoP JWT header." });
|
||||
});
|
||||
});
|
||||
+62
-46
@@ -1,51 +1,38 @@
|
||||
import { p256 } from "@noble/curves/nist";
|
||||
import { sha256 } from "@noble/hashes/sha2";
|
||||
import * as Encoding from "effect/Encoding";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Result from "effect/Result";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import {
|
||||
DpopPublicJwk as DpopPublicJwkSchema,
|
||||
normalizeDpopHtuOption,
|
||||
type DpopPublicJwk as DpopPublicJwkType,
|
||||
} from "./dpopCommon.ts";
|
||||
import { stableStringify } from "./relaySigning.ts";
|
||||
|
||||
export const DpopPublicJwk = DpopPublicJwkSchema;
|
||||
export type DpopPublicJwk = DpopPublicJwkType;
|
||||
export { normalizeDpopHtu, normalizeDpopHtuOption } from "./dpopCommon.ts";
|
||||
|
||||
const DPOP_TYP = "dpop+jwt";
|
||||
const DPOP_ALG = "ES256";
|
||||
const DEFAULT_MAX_AGE_SECONDS = 300;
|
||||
|
||||
export const DpopPublicJwk = Schema.Struct({
|
||||
kty: Schema.Literal("EC"),
|
||||
crv: Schema.Literal("P-256"),
|
||||
x: Schema.String.check(Schema.isNonEmpty()),
|
||||
y: Schema.String.check(Schema.isNonEmpty()),
|
||||
});
|
||||
export type DpopPublicJwk = typeof DpopPublicJwk.Type;
|
||||
const isDpopPublicJwk = Schema.is(DpopPublicJwk);
|
||||
|
||||
interface DpopJwtHeader {
|
||||
readonly typ: string;
|
||||
readonly alg: string;
|
||||
readonly jwk: DpopPublicJwk;
|
||||
}
|
||||
|
||||
interface DpopJwtPayload {
|
||||
readonly htm: string;
|
||||
readonly htu: string;
|
||||
readonly jti: string;
|
||||
readonly iat: number;
|
||||
readonly ath?: string | undefined;
|
||||
readonly ath?: string;
|
||||
}
|
||||
|
||||
const DpopJwtHeaderSchema = Schema.Struct({
|
||||
typ: Schema.Literal(DPOP_TYP),
|
||||
alg: Schema.Literal(DPOP_ALG),
|
||||
jwk: DpopPublicJwkSchema,
|
||||
});
|
||||
const decodeDpopJwtHeader = Schema.decodeUnknownOption(DpopJwtHeaderSchema);
|
||||
|
||||
const DpopJwtPayloadSchema = Schema.Struct({
|
||||
htm: Schema.String.check(Schema.isNonEmpty()),
|
||||
htu: Schema.String.check(Schema.isNonEmpty()),
|
||||
jti: Schema.String.check(Schema.isNonEmpty()),
|
||||
iat: Schema.Number.check(Schema.isInt()),
|
||||
ath: Schema.optional(Schema.String),
|
||||
});
|
||||
const decodeDpopJwtPayload = Schema.decodeUnknownOption(DpopJwtPayloadSchema);
|
||||
|
||||
const decodeJsonString = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
||||
|
||||
export type DpopVerificationResult =
|
||||
| {
|
||||
readonly ok: true;
|
||||
@@ -62,24 +49,43 @@ function base64UrlToBytes(value: string): Uint8Array {
|
||||
return Result.getOrThrow(Encoding.decodeBase64Url(value));
|
||||
}
|
||||
|
||||
function decodeBase64UrlJson(value: string): Option.Option<unknown> {
|
||||
const decoded = Encoding.decodeBase64UrlString(value);
|
||||
return Result.isSuccess(decoded) ? decodeJsonString(decoded.success) : Option.none();
|
||||
function decodeBase64UrlJson(value: string): unknown {
|
||||
return JSON.parse(Result.getOrThrow(Encoding.decodeBase64UrlString(value))) as unknown;
|
||||
}
|
||||
|
||||
function dpopJwtHeaderHasPrivateJwkMaterial(value: unknown): boolean {
|
||||
function isDpopJwtHeader(value: unknown): value is DpopJwtHeader {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
return false;
|
||||
}
|
||||
const jwk = (value as Record<string, unknown>).jwk;
|
||||
return typeof jwk === "object" && jwk !== null && "d" in jwk;
|
||||
const record = value as Record<string, unknown>;
|
||||
return (
|
||||
record.typ === DPOP_TYP &&
|
||||
record.alg === DPOP_ALG &&
|
||||
typeof record.jwk === "object" &&
|
||||
record.jwk !== null &&
|
||||
!("d" in record.jwk) &&
|
||||
isDpopPublicJwk(record.jwk)
|
||||
);
|
||||
}
|
||||
|
||||
function decodeDpopJwtPayloadPart(value: string): Option.Option<DpopJwtPayload> {
|
||||
return decodeBase64UrlJson(value).pipe(Option.flatMap(decodeDpopJwtPayload));
|
||||
function isDpopJwtPayload(value: unknown): value is DpopJwtPayload {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
return false;
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
return (
|
||||
typeof record.htm === "string" &&
|
||||
record.htm.length > 0 &&
|
||||
typeof record.htu === "string" &&
|
||||
record.htu.length > 0 &&
|
||||
typeof record.jti === "string" &&
|
||||
record.jti.length > 0 &&
|
||||
typeof record.iat === "number" &&
|
||||
Number.isInteger(record.iat)
|
||||
);
|
||||
}
|
||||
|
||||
function dpopThumbprintInput(jwk: DpopPublicJwkType): string {
|
||||
function dpopThumbprintInput(jwk: DpopPublicJwk): string {
|
||||
return stableStringify({
|
||||
crv: jwk.crv,
|
||||
kty: jwk.kty,
|
||||
@@ -88,7 +94,18 @@ function dpopThumbprintInput(jwk: DpopPublicJwkType): string {
|
||||
});
|
||||
}
|
||||
|
||||
export function computeDpopJwkThumbprint(jwk: DpopPublicJwkType): string {
|
||||
export function normalizeDpopHtu(url: string): string | null {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
parsed.hash = "";
|
||||
parsed.search = "";
|
||||
return parsed.toString();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function computeDpopJwkThumbprint(jwk: DpopPublicJwk): string {
|
||||
return Encoding.encodeBase64Url(sha256(new TextEncoder().encode(dpopThumbprintInput(jwk))));
|
||||
}
|
||||
|
||||
@@ -96,7 +113,7 @@ export function computeDpopAccessTokenHash(accessToken: string): string {
|
||||
return Encoding.encodeBase64Url(sha256(new TextEncoder().encode(accessToken)));
|
||||
}
|
||||
|
||||
function publicKeyBytesFromJwk(jwk: DpopPublicJwkType): Uint8Array {
|
||||
function publicKeyBytesFromJwk(jwk: DpopPublicJwk): Uint8Array {
|
||||
const x = base64UrlToBytes(jwk.x);
|
||||
const y = base64UrlToBytes(jwk.y);
|
||||
if (x.length !== 32 || y.length !== 32) {
|
||||
@@ -128,13 +145,12 @@ export function verifyDpopProof(input: {
|
||||
}
|
||||
|
||||
try {
|
||||
const rawHeader = Option.getOrNull(decodeBase64UrlJson(parts[0]));
|
||||
const header = rawHeader === null ? null : Option.getOrNull(decodeDpopJwtHeader(rawHeader));
|
||||
const payload = Option.getOrNull(decodeDpopJwtPayloadPart(parts[1]));
|
||||
if (header === null || dpopJwtHeaderHasPrivateJwkMaterial(rawHeader)) {
|
||||
const header = decodeBase64UrlJson(parts[0]);
|
||||
const payload = decodeBase64UrlJson(parts[1]);
|
||||
if (!isDpopJwtHeader(header)) {
|
||||
return { ok: false, reason: "Invalid DPoP JWT header." };
|
||||
}
|
||||
if (payload === null) {
|
||||
if (!isDpopJwtPayload(payload)) {
|
||||
return { ok: false, reason: "Invalid DPoP JWT payload." };
|
||||
}
|
||||
|
||||
@@ -145,7 +161,7 @@ export function verifyDpopProof(input: {
|
||||
if (payload.htm.toUpperCase() !== input.method.toUpperCase()) {
|
||||
return { ok: false, reason: "DPoP method mismatch." };
|
||||
}
|
||||
const normalizedHtu = Option.getOrNull(normalizeDpopHtuOption(input.url));
|
||||
const normalizedHtu = normalizeDpopHtu(input.url);
|
||||
if (normalizedHtu === null || payload.htu !== normalizedHtu) {
|
||||
return { ok: false, reason: "DPoP URL mismatch." };
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
export const DpopPublicJwk = Schema.Struct({
|
||||
@@ -9,17 +8,13 @@ export const DpopPublicJwk = Schema.Struct({
|
||||
});
|
||||
export type DpopPublicJwk = typeof DpopPublicJwk.Type;
|
||||
|
||||
export function normalizeDpopHtuOption(url: string): Option.Option<string> {
|
||||
export function normalizeDpopHtu(url: string): string | null {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
parsed.hash = "";
|
||||
parsed.search = "";
|
||||
return Option.some(parsed.toString());
|
||||
return parsed.toString();
|
||||
} catch {
|
||||
return Option.none();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeDpopHtu(url: string): string | null {
|
||||
return Option.getOrNull(normalizeDpopHtuOption(url));
|
||||
}
|
||||
@@ -244,9 +244,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,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
+18
-30
@@ -51,11 +51,11 @@ import {
|
||||
|
||||
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;
|
||||
@@ -683,9 +683,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),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -867,27 +867,15 @@ 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 timeoutMs?: number;
|
||||
readonly interval?: Duration.Input;
|
||||
readonly intervalMs?: number;
|
||||
readonly probeTimeout?: Duration.Input;
|
||||
readonly probeTimeoutMs?: number;
|
||||
readonly path?: string;
|
||||
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
|
||||
const timeout = Duration.fromInputUnsafe(
|
||||
input.timeout ?? input.timeoutMs ?? Duration.seconds(30),
|
||||
);
|
||||
const interval = Duration.fromInputUnsafe(
|
||||
input.interval ?? input.intervalMs ?? Duration.millis(100),
|
||||
);
|
||||
const probeTimeout = Duration.fromInputUnsafe(
|
||||
input.probeTimeout ?? input.probeTimeoutMs ?? 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(
|
||||
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();
|
||||
@@ -909,7 +897,7 @@ 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 SshReadinessError({
|
||||
@@ -962,7 +950,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.timeoutOption(timeout),
|
||||
Effect.timeoutOption(Duration.millis(timeoutMs)),
|
||||
);
|
||||
|
||||
return yield* Option.match(result, {
|
||||
@@ -1181,7 +1169,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(
|
||||
@@ -1241,7 +1229,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
: child
|
||||
.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
})
|
||||
.pipe(Effect.ignore),
|
||||
),
|
||||
@@ -1485,7 +1473,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
[
|
||||
tunnelEntry.process.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
}),
|
||||
stopRemoteServer(
|
||||
tunnelEntry.target,
|
||||
@@ -1539,7 +1527,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", {
|
||||
|
||||
Reference in new issue
Block a user