@tempo-ai/visual-review 0.0.132 → 0.0.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -7,11 +7,11 @@ async function main(argv = process.argv.slice(2)) {
7
7
  const [command, ...commandArgs] = argv;
8
8
  switch (command) {
9
9
  case "capture":
10
- return await (await import("./cli-ZR27KAIU.js")).main(commandArgs);
10
+ return await (await import("./cli-JDNETRAU.js")).main(commandArgs);
11
11
  case "claim":
12
- return await (await import("./claim-C5UVLSMX.js")).main(commandArgs);
12
+ return await (await import("./claim-WYI6X53C.js")).main(commandArgs);
13
13
  case "report":
14
- return await (await import("./report-PERKWEX4.js")).main(commandArgs);
14
+ return await (await import("./report-TDZOUKSY.js")).main(commandArgs);
15
15
  case "install-browsers":
16
16
  return await (await import("./install-browsers-VPIMDVB6.js")).main(commandArgs);
17
17
  default:
@@ -0,0 +1,181 @@
1
+ import { createRequire as __tempoCreateRequire } from 'node:module'; const require = __tempoCreateRequire(import.meta.url);
2
+
3
+ // src/constants.ts
4
+ var DEFAULT_VISUAL_REVIEW_INGEST_URL = "https://greedy-jackal-526.convex.site";
5
+
6
+ // src/github-actions.ts
7
+ import { readFileSync } from "fs";
8
+ function readGithubActionsEvent(eventPath = process.env.GITHUB_EVENT_PATH) {
9
+ if (!eventPath) return null;
10
+ try {
11
+ return JSON.parse(readFileSync(eventPath, "utf8"));
12
+ } catch {
13
+ return null;
14
+ }
15
+ }
16
+ function githubPullRequestContext(event = readGithubActionsEvent()) {
17
+ const pullRequest = event?.pull_request;
18
+ if (!pullRequest) return null;
19
+ return {
20
+ number: pullRequest.number ?? event?.number,
21
+ headRef: pullRequest.head?.ref,
22
+ headSha: pullRequest.head?.sha,
23
+ baseRef: pullRequest.base?.ref,
24
+ baseSha: pullRequest.base?.sha
25
+ };
26
+ }
27
+ function visualReviewPrDeclaration(event = readGithubActionsEvent()) {
28
+ const pullRequest = event?.pull_request;
29
+ return {
30
+ bypass: pullRequest?.labels?.some(
31
+ (label) => label.name === "visual-review:bypass"
32
+ ) ?? false,
33
+ noVisualChange: pullRequest?.body?.includes("<!-- tempo-no-visual-change -->") ?? false
34
+ };
35
+ }
36
+
37
+ // src/http.ts
38
+ var ATTEMPTS = 3;
39
+ var REQUEST_TIMEOUT_MS = 3e4;
40
+ var TRANSIENT_STATUS = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
41
+ var TRANSIENT_CODE = /* @__PURE__ */ new Set([
42
+ "ECONNRESET",
43
+ "ECONNREFUSED",
44
+ "EPIPE",
45
+ "ETIMEDOUT",
46
+ "EAI_AGAIN",
47
+ "ENOTFOUND",
48
+ "UND_ERR_SOCKET",
49
+ "UND_ERR_CONNECT_TIMEOUT",
50
+ "UND_ERR_HEADERS_TIMEOUT",
51
+ "UND_ERR_BODY_TIMEOUT"
52
+ ]);
53
+ function networkFailure(error) {
54
+ const codes = [];
55
+ let timeout = false;
56
+ let current = error;
57
+ for (let depth = 0; depth < 5 && current instanceof Error; depth++) {
58
+ timeout ||= current.name === "TimeoutError";
59
+ const code = current.code;
60
+ if (typeof code === "string" && /^[A-Z][A-Z0-9_]{1,50}$/.test(code))
61
+ codes.push(code);
62
+ current = current.cause;
63
+ }
64
+ return {
65
+ detail: timeout ? "request timed out" : codes.join(" / ") || "fetch failed",
66
+ retryable: timeout || codes.some((code) => TRANSIENT_CODE.has(code)) || codes.length === 0 && error instanceof TypeError && error.message === "fetch failed"
67
+ };
68
+ }
69
+ async function fetchWithRetry(url, init, operation, retryResponse = async () => true) {
70
+ const endpoint = new URL(url);
71
+ const label = `${operation} (${endpoint.origin}${endpoint.pathname})`;
72
+ for (let attempt = 1; attempt <= ATTEMPTS; attempt++) {
73
+ const request = typeof init === "function" ? await init() : init;
74
+ const controller = new AbortController();
75
+ const timeout = setTimeout(
76
+ () => controller.abort(new DOMException("Request timed out", "TimeoutError")),
77
+ REQUEST_TIMEOUT_MS
78
+ );
79
+ let response;
80
+ let failure;
81
+ let retryAfter = 0;
82
+ try {
83
+ response = await fetch(url, { ...request, signal: controller.signal });
84
+ const body = await response.arrayBuffer();
85
+ response = new Response(body.byteLength ? body : null, {
86
+ status: response.status,
87
+ statusText: response.statusText,
88
+ headers: response.headers
89
+ });
90
+ if (!TRANSIENT_STATUS.has(response.status) || !await retryResponse(response.clone()) || attempt === ATTEMPTS)
91
+ return response;
92
+ failure = `HTTP ${response.status}`;
93
+ const retryHeader = response.headers.get("retry-after");
94
+ if (retryHeader) {
95
+ const seconds = Number(retryHeader);
96
+ const requestedDelay = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(retryHeader) - Date.now();
97
+ if (requestedDelay > 5e3) return response;
98
+ if (Number.isFinite(requestedDelay))
99
+ retryAfter = Math.max(0, requestedDelay);
100
+ }
101
+ } catch (error) {
102
+ const info = networkFailure(
103
+ controller.signal.aborted ? controller.signal.reason : error
104
+ );
105
+ failure = info.detail;
106
+ if (!info.retryable || attempt === ATTEMPTS) {
107
+ throw new Error(
108
+ `${label} failed after ${attempt}/${ATTEMPTS} attempts: ${failure}`
109
+ );
110
+ }
111
+ } finally {
112
+ clearTimeout(timeout);
113
+ }
114
+ const delay = Math.max(retryAfter, 250 * 4 ** (attempt - 1));
115
+ console.warn(
116
+ `[visual-review] ${label}: ${failure}; retrying after ${delay}ms (attempt ${attempt + 1}/${ATTEMPTS})`
117
+ );
118
+ await new Promise((resolve) => setTimeout(resolve, delay));
119
+ }
120
+ throw new Error(`${label}: retry budget exhausted`);
121
+ }
122
+
123
+ // src/oidc.ts
124
+ var OIDC_TOKEN_LIFETIME_MS = 5 * 6e4;
125
+ var OIDC_TOKEN_REFRESH_MARGIN_MS = 6e4;
126
+ var VISUAL_REVIEW_OIDC_AUDIENCE = "tempo-visual-review";
127
+ function githubOidcProvider(requestUrl, requestToken) {
128
+ let cached = null;
129
+ let pending = null;
130
+ const mint = async () => {
131
+ const separator = requestUrl.includes("?") ? "&" : "?";
132
+ const response = await fetchWithRetry(
133
+ `${requestUrl}${separator}audience=${VISUAL_REVIEW_OIDC_AUDIENCE}`,
134
+ { headers: { Authorization: `Bearer ${requestToken}` } },
135
+ "GitHub OIDC token mint/refresh"
136
+ );
137
+ if (!response.ok) {
138
+ throw new Error(
139
+ `minting the GitHub OIDC token failed: ${response.status} ${(await response.text()).slice(0, 200)}`
140
+ );
141
+ }
142
+ const body = await response.json();
143
+ if (!body.value)
144
+ throw new Error("GitHub OIDC token endpoint returned no value");
145
+ cached = { value: body.value, mintedAtMs: Date.now() };
146
+ return { kind: "oidc", value: body.value };
147
+ };
148
+ return async () => {
149
+ if (cached && Date.now() - cached.mintedAtMs < OIDC_TOKEN_LIFETIME_MS - OIDC_TOKEN_REFRESH_MARGIN_MS) {
150
+ return { kind: "oidc", value: cached.value };
151
+ }
152
+ pending ??= mint().finally(() => {
153
+ pending = null;
154
+ });
155
+ return pending;
156
+ };
157
+ }
158
+ function resolveIngestCredential(oidcOnly = false) {
159
+ const requestUrl = process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
160
+ const requestToken = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
161
+ if (requestUrl && requestToken)
162
+ return githubOidcProvider(requestUrl, requestToken);
163
+ const oidc = process.env.VISUAL_REVIEW_OIDC_TOKEN;
164
+ if (oidc) return async () => ({ kind: "oidc", value: oidc });
165
+ const secret = process.env.VISUAL_REVIEW_UPLOAD_SECRET;
166
+ if (!oidcOnly && secret)
167
+ return async () => ({ kind: "secret", value: secret });
168
+ throw new Error(
169
+ oidcOnly ? "GitHub Actions id-token: write or VISUAL_REVIEW_OIDC_TOKEN is required to publish through the Tempo GitHub App" : "GitHub Actions id-token permission, VISUAL_REVIEW_OIDC_TOKEN, or VISUAL_REVIEW_UPLOAD_SECRET is required for --upload"
170
+ );
171
+ }
172
+
173
+ export {
174
+ DEFAULT_VISUAL_REVIEW_INGEST_URL,
175
+ githubPullRequestContext,
176
+ visualReviewPrDeclaration,
177
+ fetchWithRetry,
178
+ VISUAL_REVIEW_OIDC_AUDIENCE,
179
+ resolveIngestCredential
180
+ };
181
+ //# sourceMappingURL=chunk-CKMUCU6E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/github-actions.ts","../src/http.ts","../src/oidc.ts"],"sourcesContent":["/** The production Convex HTTP origin customers ingest visual-review runs to. */\nexport const DEFAULT_VISUAL_REVIEW_INGEST_URL =\n \"https://greedy-jackal-526.convex.site\";\n","import { readFileSync } from \"node:fs\";\n\nexport type GithubActionsEvent = {\n number?: number;\n pull_request?: {\n number?: number;\n body?: string | null;\n labels?: Array<{ name?: string | null }>;\n head?: { ref?: string; sha?: string };\n base?: { ref?: string; sha?: string };\n };\n};\n\n/** Read Actions' event payload when it is available, without making a local\n * invocation depend on it. */\nexport function readGithubActionsEvent(\n eventPath = process.env.GITHUB_EVENT_PATH,\n): GithubActionsEvent | null {\n if (!eventPath) return null;\n try {\n return JSON.parse(readFileSync(eventPath, \"utf8\")) as GithubActionsEvent;\n } catch {\n return null;\n }\n}\n\nexport function githubPullRequestContext(event = readGithubActionsEvent()) {\n const pullRequest = event?.pull_request;\n if (!pullRequest) return null;\n return {\n number: pullRequest.number ?? event?.number,\n headRef: pullRequest.head?.ref,\n headSha: pullRequest.head?.sha,\n baseRef: pullRequest.base?.ref,\n baseSha: pullRequest.base?.sha,\n };\n}\n\n/** These PR-owned declarations are handled by the portable `report` command,\n * keeping customer workflow files free of dogfood-specific bypass jobs. */\nexport function visualReviewPrDeclaration(\n event: GithubActionsEvent | null = readGithubActionsEvent(),\n): { bypass: boolean; noVisualChange: boolean } {\n const pullRequest = event?.pull_request;\n return {\n bypass:\n pullRequest?.labels?.some(\n (label) => label.name === \"visual-review:bypass\",\n ) ?? false,\n noVisualChange:\n pullRequest?.body?.includes(\"<!-- tempo-no-visual-change -->\") ?? false,\n };\n}\n","const ATTEMPTS = 3;\nconst REQUEST_TIMEOUT_MS = 30_000;\nconst TRANSIENT_STATUS = new Set([408, 429, 500, 502, 503, 504]);\nconst TRANSIENT_CODE = new Set([\n \"ECONNRESET\",\n \"ECONNREFUSED\",\n \"EPIPE\",\n \"ETIMEDOUT\",\n \"EAI_AGAIN\",\n \"ENOTFOUND\",\n \"UND_ERR_SOCKET\",\n \"UND_ERR_CONNECT_TIMEOUT\",\n \"UND_ERR_HEADERS_TIMEOUT\",\n \"UND_ERR_BODY_TIMEOUT\",\n]);\n\nfunction networkFailure(error: unknown): {\n detail: string;\n retryable: boolean;\n} {\n const codes: string[] = [];\n let timeout = false;\n let current = error;\n for (let depth = 0; depth < 5 && current instanceof Error; depth++) {\n timeout ||= current.name === \"TimeoutError\";\n const code = (current as Error & { code?: unknown }).code;\n // Never print arbitrary messages: fetch errors can contain credentials,\n // query strings, headers, or response bodies. Node error codes are enough.\n if (typeof code === \"string\" && /^[A-Z][A-Z0-9_]{1,50}$/.test(code))\n codes.push(code);\n current = (current as Error & { cause?: unknown }).cause;\n }\n return {\n detail: timeout ? \"request timed out\" : codes.join(\" / \") || \"fetch failed\",\n retryable:\n timeout ||\n codes.some((code) => TRANSIENT_CODE.has(code)) ||\n (codes.length === 0 &&\n error instanceof TypeError &&\n error.message === \"fetch failed\"),\n };\n}\n\n/** Only for replayable, idempotent API requests. Ingest hashes, manifests and\n * claim identities make retries safe even when the server committed a write\n * before its response was lost. Stream request bodies must not be passed here. */\nexport async function fetchWithRetry(\n url: string,\n init: RequestInit | (() => Promise<RequestInit>),\n operation: string,\n retryResponse: (response: Response) => Promise<boolean> = async () => true,\n): Promise<Response> {\n const endpoint = new URL(url);\n const label = `${operation} (${endpoint.origin}${endpoint.pathname})`;\n for (let attempt = 1; attempt <= ATTEMPTS; attempt++) {\n // Auth has its own retry budget; do not multiply it by this request's\n // budget. Resolve again before each attempt so tokens can refresh.\n const request = typeof init === \"function\" ? await init() : init;\n const controller = new AbortController();\n const timeout = setTimeout(\n () =>\n controller.abort(new DOMException(\"Request timed out\", \"TimeoutError\")),\n REQUEST_TIMEOUT_MS,\n );\n let response: Response;\n let failure: string;\n let retryAfter = 0;\n try {\n response = await fetch(url, { ...request, signal: controller.signal });\n // These APIs return small JSON bodies. Consume under the same deadline\n // so a connection lost after headers is also retried and diagnosed.\n const body = await response.arrayBuffer();\n response = new Response(body.byteLength ? body : null, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n });\n if (\n !TRANSIENT_STATUS.has(response.status) ||\n !(await retryResponse(response.clone())) ||\n attempt === ATTEMPTS\n )\n return response;\n failure = `HTTP ${response.status}`;\n const retryHeader = response.headers.get(\"retry-after\");\n if (retryHeader) {\n const seconds = Number(retryHeader);\n const requestedDelay = Number.isFinite(seconds)\n ? seconds * 1_000\n : Date.parse(retryHeader) - Date.now();\n // Respect the server's retry window. If it exceeds our short recovery\n // budget, fail with its response instead of retrying too early.\n if (requestedDelay > 5_000) return response;\n if (Number.isFinite(requestedDelay))\n retryAfter = Math.max(0, requestedDelay);\n }\n } catch (error) {\n // Body reads may reject with AbortError rather than our timeout reason.\n const info = networkFailure(\n controller.signal.aborted ? controller.signal.reason : error,\n );\n failure = info.detail;\n if (!info.retryable || attempt === ATTEMPTS) {\n throw new Error(\n `${label} failed after ${attempt}/${ATTEMPTS} attempts: ${failure}`,\n );\n }\n } finally {\n clearTimeout(timeout);\n }\n const delay = Math.max(retryAfter, 250 * 4 ** (attempt - 1));\n console.warn(\n `[visual-review] ${label}: ${failure}; retrying after ${delay}ms (attempt ${attempt + 1}/${ATTEMPTS})`,\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n throw new Error(`${label}: retry budget exhausted`);\n}\n","import type { IngestCredentialProvider } from \"./ingest-client\";\nimport { fetchWithRetry } from \"./http\";\n\nconst OIDC_TOKEN_LIFETIME_MS = 5 * 60_000;\nconst OIDC_TOKEN_REFRESH_MARGIN_MS = 60_000;\nexport const VISUAL_REVIEW_OIDC_AUDIENCE = \"tempo-visual-review\";\n\n/** Refresh lazily: captures can outlive GitHub's five-minute id-tokens. */\nfunction githubOidcProvider(\n requestUrl: string,\n requestToken: string,\n): IngestCredentialProvider {\n let cached: { value: string; mintedAtMs: number } | null = null;\n let pending: ReturnType<IngestCredentialProvider> | null = null;\n const mint: IngestCredentialProvider = async () => {\n const separator = requestUrl.includes(\"?\") ? \"&\" : \"?\";\n const response = await fetchWithRetry(\n `${requestUrl}${separator}audience=${VISUAL_REVIEW_OIDC_AUDIENCE}`,\n { headers: { Authorization: `Bearer ${requestToken}` } },\n \"GitHub OIDC token mint/refresh\",\n );\n if (!response.ok) {\n throw new Error(\n `minting the GitHub OIDC token failed: ${response.status} ${(await response.text()).slice(0, 200)}`,\n );\n }\n const body = (await response.json()) as { value?: string };\n if (!body.value)\n throw new Error(\"GitHub OIDC token endpoint returned no value\");\n cached = { value: body.value, mintedAtMs: Date.now() };\n return { kind: \"oidc\", value: body.value };\n };\n return async () => {\n if (\n cached &&\n Date.now() - cached.mintedAtMs <\n OIDC_TOKEN_LIFETIME_MS - OIDC_TOKEN_REFRESH_MARGIN_MS\n ) {\n return { kind: \"oidc\", value: cached.value };\n }\n // Concurrent blob uploads share the refresh, including its failure.\n // Clear it afterwards so a later request can retry a failed mint.\n pending ??= mint().finally(() => {\n pending = null;\n });\n return pending;\n };\n}\n\n/** Prefer ambient Actions OIDC, then an explicit debug token. Preview\n * capture may use the shared secret; publishing real statuses may not. */\nexport function resolveIngestCredential(\n oidcOnly = false,\n): IngestCredentialProvider {\n const requestUrl = process.env.ACTIONS_ID_TOKEN_REQUEST_URL;\n const requestToken = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;\n if (requestUrl && requestToken)\n return githubOidcProvider(requestUrl, requestToken);\n const oidc = process.env.VISUAL_REVIEW_OIDC_TOKEN;\n if (oidc) return async () => ({ kind: \"oidc\", value: oidc });\n const secret = process.env.VISUAL_REVIEW_UPLOAD_SECRET;\n if (!oidcOnly && secret)\n return async () => ({ kind: \"secret\", value: secret });\n throw new Error(\n oidcOnly\n ? \"GitHub Actions id-token: write or VISUAL_REVIEW_OIDC_TOKEN is required to publish through the Tempo GitHub App\"\n : \"GitHub Actions id-token permission, VISUAL_REVIEW_OIDC_TOKEN, or VISUAL_REVIEW_UPLOAD_SECRET is required for --upload\",\n );\n}\n"],"mappings":";;;AACO,IAAM,mCACX;;;ACFF,SAAS,oBAAoB;AAetB,SAAS,uBACd,YAAY,QAAQ,IAAI,mBACG;AAC3B,MAAI,CAAC,UAAW,QAAO;AACvB,MAAI;AACF,WAAO,KAAK,MAAM,aAAa,WAAW,MAAM,CAAC;AAAA,EACnD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,yBAAyB,QAAQ,uBAAuB,GAAG;AACzE,QAAM,cAAc,OAAO;AAC3B,MAAI,CAAC,YAAa,QAAO;AACzB,SAAO;AAAA,IACL,QAAQ,YAAY,UAAU,OAAO;AAAA,IACrC,SAAS,YAAY,MAAM;AAAA,IAC3B,SAAS,YAAY,MAAM;AAAA,IAC3B,SAAS,YAAY,MAAM;AAAA,IAC3B,SAAS,YAAY,MAAM;AAAA,EAC7B;AACF;AAIO,SAAS,0BACd,QAAmC,uBAAuB,GACZ;AAC9C,QAAM,cAAc,OAAO;AAC3B,SAAO;AAAA,IACL,QACE,aAAa,QAAQ;AAAA,MACnB,CAAC,UAAU,MAAM,SAAS;AAAA,IAC5B,KAAK;AAAA,IACP,gBACE,aAAa,MAAM,SAAS,iCAAiC,KAAK;AAAA,EACtE;AACF;;;ACpDA,IAAM,WAAW;AACjB,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB,oBAAI,IAAI,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG,CAAC;AAC/D,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,eAAe,OAGtB;AACA,QAAM,QAAkB,CAAC;AACzB,MAAI,UAAU;A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BAA2B;AAAA,MAChE,EAAE,SAAS,EAAE,eAAe,UAAU,YAAY,GAAG,EAAE;AAAA,MACvD;AAAA,IACF;AACA,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI;AAAA,QACR,yCAAyC,SAAS,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,MAAM,GAAG,GAAG,CAAC;AAAA,MACnG;AAAA,IACF;AACA,UAAM,OAAQ,MAAM,SAAS,KAAK;AAClC,QAAI,CAAC,KAAK;AACR,YAAM,IAAI,MAAM,8CAA8C;AAChE,aAAS,EAAE,OAAO,KAAK,OAAO,YAAY,KAAK,IAAI,EAAE;AACrD,WAAO,EAAE,MAAM,QAAQ,OAAO,KAAK,MAAM;AAAA,EAC3C;AACA,SAAO,YAAY;AACjB,QACE,UACA,KAAK,IAAI,IAAI,OAAO,aAClB,yBAAyB,8BAC3B;AACA,aAAO,EAAE,MAAM,QAAQ,OAAO,OAAO,MAAM;AAAA,IAC7C;AAGA,gBAAY,KAAK,EAAE,QAAQ,MAAM;AAC/B,gBAAU;AAAA,IACZ,CAAC;AACD,WAAO;AAAA,EACT;AACF;AAIO,SAAS,wBACd,WAAW,OACe;AAC1B,QAAM,aAAa,QAAQ,IAAI;AAC/B,QAAM,eAAe,QAAQ,IAAI;AACjC,MAAI,cAAc;AAChB,WAAO,mBAAmB,YAAY,YAAY;AACpD,QAAM,OAAO,QAAQ,IAAI;AACzB,MAAI,KAAM,QAAO,aAAa,EAAE,MAAM,QAAQ,OAAO,KAAK;AAC1D,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,CAAC,YAAY;AACf,WAAO,aAAa,EAAE,MAAM,UAAU,OAAO,OAAO;AACtD,QAAM,IAAI;AAAA,IACR,WACI,mHACA;AAAA,EACN;AACF;","names":[]}
@@ -1,9 +1,10 @@
1
1
  import { createRequire as __tempoCreateRequire } from 'node:module'; const require = __tempoCreateRequire(import.meta.url);
2
2
  import {
3
3
  DEFAULT_VISUAL_REVIEW_INGEST_URL,
4
+ fetchWithRetry,
4
5
  githubPullRequestContext,
5
6
  resolveIngestCredential
6
- } from "./chunk-WZN4UX2B.js";
7
+ } from "./chunk-CKMUCU6E.js";
7
8
  import {
8
9
  __commonJS,
9
10
  __require,
@@ -40201,7 +40202,7 @@ var MissingRootDepsError = class extends TempoDevServerError {
40201
40202
  // ../tempo-sdk/package.json
40202
40203
  var package_default = {
40203
40204
  name: "tempo-sdk",
40204
- version: "0.0.79",
40205
+ version: "0.0.81",
40205
40206
  publishConfig: {
40206
40207
  tag: "sdk-v2-latest"
40207
40208
  },
@@ -52455,6 +52456,9 @@ var TempoDevServer = class _TempoDevServer {
52455
52456
  // one. URL equality is not enough of a fence: a replacement process on the
52456
52457
  // same URL would inherit the old process's last failure.
52457
52458
  this.urlHealthProbeGeneration = 0;
52459
+ this.urlHealthProbeInFlight = null;
52460
+ this.hostConnectionListeners = /* @__PURE__ */ new Set();
52461
+ this.hostConnectionStatus = null;
52458
52462
  // Tempo-managed Next hosts never share the user's ordinary `.next` cache.
52459
52463
  // This starts at the stable Tempo-owned directory and only receives a suffix
52460
52464
  // after Next reports an observed lock conflict for that directory.
@@ -52542,6 +52546,15 @@ var TempoDevServer = class _TempoDevServer {
52542
52546
  // crash→restart cycles in one snapshot.
52543
52547
  this.RECENT_EXITS_LIMIT = 30;
52544
52548
  }
52549
+ publishHostConnection(status) {
52550
+ this.hostConnectionStatus = status;
52551
+ for (const listener of this.hostConnectionListeners) {
52552
+ try {
52553
+ listener(status);
52554
+ } catch {
52555
+ }
52556
+ }
52557
+ }
52545
52558
  static {
52546
52559
  this.installBarriers = /* @__PURE__ */ new Map();
52547
52560
  }
@@ -53013,6 +53026,16 @@ var TempoDevServer = class _TempoDevServer {
53013
53026
  hintListeners.push(listener);
53014
53027
  process2.onHint(listener);
53015
53028
  },
53029
+ onConnectionStatus(listener) {
53030
+ const current = (status) => {
53031
+ if (self.activeHostProcess === process2) listener(status);
53032
+ };
53033
+ self.hostConnectionListeners.add(current);
53034
+ if (self.hostConnectionStatus) current(self.hostConnectionStatus);
53035
+ return () => {
53036
+ self.hostConnectionListeners.delete(current);
53037
+ };
53038
+ },
53016
53039
  onFlutterStatus(listener) {
53017
53040
  self.flutterStatusListeners.add(listener);
53018
53041
  const status = self.flutterDevServer?.status();
@@ -54132,6 +54155,7 @@ var TempoDevServer = class _TempoDevServer {
54132
54155
  }
54133
54156
  async dispose() {
54134
54157
  this.disposed = true;
54158
+ this.hostConnectionListeners.clear();
54135
54159
  this.managedReconciliation.dispose();
54136
54160
  this.flutterReconciliation.dispose();
54137
54161
  this.restartHostForFlutter = null;
@@ -54158,9 +54182,10 @@ var TempoDevServer = class _TempoDevServer {
54158
54182
  }
54159
54183
  // Periodic HTTP probe that re-asserts the dev server URL is reachable.
54160
54184
  // Foreground starts clear the URL through their child exit; daemonized
54161
- // starts have no live child after launch, so three consecutive failures are
54162
- // their terminal signal. A failed probe against a child we still hold alive
54163
- // never demotes — it only records urlUnreachableSince.
54185
+ // starts have no live child after launch. HTTP failures report connection
54186
+ // state to the workspace owner, which owns the shared restart budget.
54187
+ // Reachability alone never proves that an external runtime has exited.
54188
+ // A failed probe against a child we still hold alive never demotes it.
54164
54189
  startUrlHealthProbe(url) {
54165
54190
  this.stopUrlHealthProbe();
54166
54191
  if (this.disposed) return;
@@ -54181,20 +54206,41 @@ var TempoDevServer = class _TempoDevServer {
54181
54206
  }
54182
54207
  this.urlHealthProbeUrl = null;
54183
54208
  this.urlHealthProbeConsecutiveFailures = 0;
54209
+ this.hostConnectionStatus = null;
54184
54210
  this.urlHealthProbeGeneration += 1;
54185
54211
  }
54186
54212
  async runUrlHealthProbeTick() {
54187
54213
  const probedUrl = this.urlHealthProbeUrl;
54188
54214
  const generation = this.urlHealthProbeGeneration;
54189
54215
  if (!probedUrl || this.disposed) return;
54190
- const reachable = await probeUrlOnce(
54216
+ if (this.urlHealthProbeInFlight === generation) return;
54217
+ this.urlHealthProbeInFlight = generation;
54218
+ try {
54219
+ await this.performUrlHealthProbeTick(probedUrl, generation);
54220
+ } finally {
54221
+ if (this.urlHealthProbeInFlight === generation) {
54222
+ this.urlHealthProbeInFlight = null;
54223
+ }
54224
+ }
54225
+ }
54226
+ async performUrlHealthProbeTick(probedUrl, generation) {
54227
+ const observation = await probeHostHealth(
54191
54228
  probedUrl,
54192
54229
  1500,
54193
54230
  this.projectRoot,
54194
54231
  this.activeHostIdentity
54195
54232
  );
54196
54233
  if (this.urlHealthProbeGeneration !== generation) return;
54197
- if (reachable) {
54234
+ if (observation.outcome === "ok") {
54235
+ if (this.state.urlUnreachableSince !== null) {
54236
+ devLog("supervisor:url_probe_recovered", { url: probedUrl });
54237
+ }
54238
+ if (this.activeHostLivenessSource() === "probe") {
54239
+ this.publishHostConnection({
54240
+ state: "connected",
54241
+ unreachableSince: null
54242
+ });
54243
+ }
54198
54244
  this.state.urlUnreachableSince = null;
54199
54245
  this.urlHealthProbeConsecutiveFailures = 0;
54200
54246
  this.activeHostProcess?.clearSupervisorHint("host-unresponsive");
@@ -54225,11 +54271,17 @@ var TempoDevServer = class _TempoDevServer {
54225
54271
  requiredFailures: _TempoDevServer.URL_HEALTH_FAILURES_TO_DEMOTE,
54226
54272
  unreachableSince: this.state.urlUnreachableSince
54227
54273
  });
54228
- if (this.urlHealthProbeConsecutiveFailures < _TempoDevServer.URL_HEALTH_FAILURES_TO_DEMOTE) {
54274
+ const incompatible = this.activeHostIdentity !== null && (observation.outcome === "wrong-responder" || observation.outcome === "verified-incompatible");
54275
+ this.publishHostConnection({
54276
+ state: incompatible ? "incompatible" : "unreachable",
54277
+ unreachableSince: this.state.urlUnreachableSince
54278
+ });
54279
+ if (this.urlHealthProbeConsecutiveFailures < _TempoDevServer.URL_HEALTH_FAILURES_TO_DEMOTE)
54229
54280
  return;
54230
- }
54281
+ if (!incompatible) return;
54231
54282
  const activeProcess = this.activeHostProcess;
54232
54283
  activeProcess?.reportProbeBackedDeath();
54284
+ if (this.urlHealthProbeGeneration !== generation) return;
54233
54285
  if (this.state.devserverUrl === probedUrl) {
54234
54286
  this.state.devserverUrl = null;
54235
54287
  this.state.urlUnreachableSince = null;
@@ -56462,6 +56514,11 @@ function fetchBodyTextViaNodeHttp(url, timeoutMs) {
56462
56514
  return Promise.resolve(null);
56463
56515
  }
56464
56516
  return new Promise((resolve2) => {
56517
+ let deadline;
56518
+ const finish = (response) => {
56519
+ clearTimeout(deadline);
56520
+ resolve2(response);
56521
+ };
56465
56522
  const request = httpRequest2(
56466
56523
  parsed,
56467
56524
  { headers: { accept: "text/html" } },
@@ -56477,19 +56534,19 @@ function fetchBodyTextViaNodeHttp(url, timeoutMs) {
56477
56534
  });
56478
56535
  response.on(
56479
56536
  "end",
56480
- () => resolve2({
56537
+ () => finish({
56481
56538
  status: response.statusCode ?? 0,
56482
56539
  body: Buffer.concat(chunks).toString("utf-8")
56483
56540
  })
56484
56541
  );
56485
- response.on("error", () => resolve2(null));
56542
+ response.on("error", () => finish(null));
56486
56543
  }
56487
56544
  );
56488
- request.setTimeout(timeoutMs, () => {
56545
+ deadline = setTimeout(() => {
56489
56546
  request.destroy();
56490
- resolve2(null);
56491
- });
56492
- request.on("error", () => resolve2(null));
56547
+ finish(null);
56548
+ }, timeoutMs);
56549
+ request.on("error", () => finish(null));
56493
56550
  request.end();
56494
56551
  });
56495
56552
  }
@@ -56524,9 +56581,15 @@ async function fetchProbeResponse(url, timeoutMs) {
56524
56581
  fetchBodyTextViaNodeHttp,
56525
56582
  ...extraProbeTransports
56526
56583
  ];
56527
- return firstNonNullResponse(
56528
- transports.map((transport) => transport(url, timeoutMs).catch(() => null))
56529
- );
56584
+ return withTimeout(
56585
+ firstNonNullResponse(
56586
+ transports.map(
56587
+ (transport) => transport(url, timeoutMs).catch(() => null)
56588
+ )
56589
+ ),
56590
+ timeoutMs,
56591
+ "Host probe response timeout"
56592
+ ).catch(() => null);
56530
56593
  }
56531
56594
  async function probeTempoHost(url, timeoutMs, expectedProjectRoot, expectedIdentity) {
56532
56595
  const response = await fetchProbeResponse(url, timeoutMs);
@@ -56545,7 +56608,7 @@ async function probeTempoHost(url, timeoutMs, expectedProjectRoot, expectedIdent
56545
56608
  }
56546
56609
  if (!expectedIdentity && advertisedRootMismatch) return "wrong-responder";
56547
56610
  if (!expectedIdentity && hasLegacyMarker) return "ok";
56548
- const identity = await probeTempoIdentityEndpoint(
56611
+ const { outcome: identity } = await probeTempoIdentityEndpoint(
56549
56612
  url,
56550
56613
  timeoutMs,
56551
56614
  expectedIdentity
@@ -56561,45 +56624,45 @@ async function probeTempoHost(url, timeoutMs, expectedProjectRoot, expectedIdent
56561
56624
  }
56562
56625
  return body !== null ? "wrong-responder" : identity;
56563
56626
  }
56564
- async function fetchIsTempoHost(url, timeoutMs, expectedProjectRoot, expectedIdentity) {
56565
- return await probeTempoHost(
56566
- url,
56567
- timeoutMs,
56568
- expectedProjectRoot,
56569
- expectedIdentity
56570
- ) === "ok";
56571
- }
56572
56627
  async function probeTempoIdentityEndpoint(tempoHostUrl, timeoutMs, expectedIdentity) {
56628
+ const startedAt = performance.now();
56629
+ let status = null;
56630
+ const observed = (outcome) => ({
56631
+ outcome,
56632
+ status,
56633
+ elapsedMs: Math.round(performance.now() - startedAt)
56634
+ });
56573
56635
  let identityUrl;
56574
56636
  try {
56575
56637
  identityUrl = `${new URL(tempoHostUrl).origin}/__tempo/identity`;
56576
56638
  } catch {
56577
- return "unreachable";
56639
+ return observed("unreachable");
56578
56640
  }
56579
56641
  const response = await fetchProbeResponse(identityUrl, timeoutMs);
56642
+ status = response?.status ?? null;
56580
56643
  if (response === null) {
56581
- return "unreachable";
56644
+ return observed("unreachable");
56582
56645
  }
56583
56646
  if (response.status < 200 || response.status >= 300) {
56584
- return "identity-incompatible";
56647
+ return observed("identity-incompatible");
56585
56648
  }
56586
56649
  let parsed;
56587
56650
  try {
56588
56651
  parsed = JSON.parse(response.body);
56589
56652
  } catch {
56590
- return "identity-incompatible";
56653
+ return observed("identity-incompatible");
56591
56654
  }
56592
56655
  if (parsed.tempoHost !== true) {
56593
- return "identity-incompatible";
56656
+ return observed("identity-incompatible");
56594
56657
  }
56595
- if (!expectedIdentity) return "ok";
56658
+ if (!expectedIdentity) return observed("ok");
56596
56659
  if (parsed.workspaceNonce !== expectedIdentity.workspaceNonce) {
56597
- return "wrong-responder";
56660
+ return observed("wrong-responder");
56598
56661
  }
56599
56662
  if (typeof parsed.contractVersion !== "number" || parsed.contractVersion < 1 || parsed.pluginActive !== true || parsed.framework !== expectedIdentity.framework || typeof parsed.sdkVersion !== "string" || !tempoSdkVersionSatisfiesCanvasHost(parsed.sdkVersion, parsed.sdkChannel)) {
56600
- return "verified-incompatible";
56663
+ return observed("verified-incompatible");
56601
56664
  }
56602
- return "ok";
56665
+ return observed("ok");
56603
56666
  }
56604
56667
  async function waitForHttpReachable(url, timeoutMs, expectedProjectRoot, expectedIdentity) {
56605
56668
  const startedAt = Date.now();
@@ -56704,12 +56767,29 @@ async function waitForHttpUnreachable(url, timeoutMs) {
56704
56767
  return false;
56705
56768
  }
56706
56769
  async function probeUrlOnce(url, timeoutMs, expectedProjectRoot, expectedIdentity) {
56707
- return fetchIsTempoHost(
56770
+ return (await probeHostHealth(
56708
56771
  url,
56709
56772
  timeoutMs,
56710
56773
  expectedProjectRoot,
56711
56774
  expectedIdentity
56712
- );
56775
+ )).outcome === "ok";
56776
+ }
56777
+ async function probeHostHealth(url, timeoutMs, expectedProjectRoot, expectedIdentity) {
56778
+ const startedAt = performance.now();
56779
+ const observation = expectedIdentity ? await probeTempoIdentityEndpoint(url, timeoutMs, expectedIdentity) : {
56780
+ outcome: await probeTempoHost(url, timeoutMs, expectedProjectRoot),
56781
+ status: null,
56782
+ elapsedMs: Math.round(performance.now() - startedAt)
56783
+ };
56784
+ if (observation.outcome !== "ok") {
56785
+ devLog("supervisor:url_probe_failed", {
56786
+ url,
56787
+ probe: expectedIdentity ? "identity" : "document",
56788
+ timeoutMs,
56789
+ ...observation
56790
+ });
56791
+ }
56792
+ return observation;
56713
56793
  }
56714
56794
  async function withTimeout(promise, timeoutMs, message) {
56715
56795
  return await new Promise((resolve2, reject) => {
@@ -62697,13 +62777,19 @@ var VisualReviewIngestClient = class {
62697
62777
  return credential.kind === "oidc" ? { "x-visual-review-oidc": credential.value } : { "x-visual-review-secret": credential.value };
62698
62778
  }
62699
62779
  async request(path44, init) {
62700
- const response = await fetch(`${this.baseUrl}${path44}`, {
62701
- ...init,
62702
- headers: {
62703
- ...await this.authHeader(),
62704
- ...init.headers ?? {}
62780
+ const response = await fetchWithRetry(
62781
+ `${this.baseUrl}${path44}`,
62782
+ async () => ({
62783
+ ...init,
62784
+ headers: { ...await this.authHeader(), ...init.headers ?? {} }
62785
+ }),
62786
+ `ingest ${init.method ?? "GET"}`,
62787
+ async (response2) => {
62788
+ if (response2.status !== 503) return true;
62789
+ const reason = await this.errorReason(response2);
62790
+ return !reason || reason === "jwks_unavailable";
62705
62791
  }
62706
- });
62792
+ );
62707
62793
  if (response.status === 503) {
62708
62794
  const reason = await this.errorReason(response);
62709
62795
  if (reason === "jwks_unavailable") {
@@ -63711,4 +63797,4 @@ export {
63711
63797
  buildBaselineCaptureArgs,
63712
63798
  main
63713
63799
  };
63714
- //# sourceMappingURL=chunk-2DMOFAJO.js.map
63800
+ //# sourceMappingURL=chunk-GURIHSP6.js.map