@tempo-ai/visual-review 0.0.138 → 0.0.139
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/README.md +34 -0
- package/dist/bin.js +3 -3
- package/dist/{chunk-HEFIVQ57.js → chunk-BTZJDIC4.js} +86 -15
- package/dist/chunk-BTZJDIC4.js.map +1 -0
- package/dist/chunk-H7MXR6QX.js +360 -0
- package/dist/chunk-H7MXR6QX.js.map +1 -0
- package/dist/{chunk-IID6AAUD.js → chunk-PI6TS733.js} +100 -34
- package/dist/chunk-PI6TS733.js.map +1 -0
- package/dist/chunk-TEVWNWZ6.js +376 -0
- package/dist/chunk-TEVWNWZ6.js.map +1 -0
- package/dist/{chunk-V4U3XAR5.js → chunk-VZDQYZCX.js} +115 -26
- package/dist/{chunk-V4U3XAR5.js.map → chunk-VZDQYZCX.js.map} +1 -1
- package/dist/{claim-WYI6X53C.js → claim-TARSUW6K.js} +3 -4
- package/dist/{cli-774NVTY7.js → cli-HWGJAH23.js} +4 -3
- package/dist/index.d.ts +66 -1
- package/dist/index.js +8 -6
- package/dist/{report-TDZOUKSY.js → report-XRYE2D5O.js} +4 -4
- package/package.json +3 -2
- package/templates/bitbucket-pipelines.yml +86 -0
- package/dist/chunk-CKMUCU6E.js +0 -181
- package/dist/chunk-CKMUCU6E.js.map +0 -1
- package/dist/chunk-HEFIVQ57.js.map +0 -1
- package/dist/chunk-IID6AAUD.js.map +0 -1
- package/dist/chunk-PDNKZ3PI.js +0 -38
- package/dist/chunk-PDNKZ3PI.js.map +0 -1
- /package/dist/{claim-WYI6X53C.js.map → claim-TARSUW6K.js.map} +0 -0
- /package/dist/{cli-774NVTY7.js.map → cli-HWGJAH23.js.map} +0 -0
- /package/dist/{report-TDZOUKSY.js.map → report-XRYE2D5O.js.map} +0 -0
|
@@ -3,13 +3,12 @@ import {
|
|
|
3
3
|
announceCapture,
|
|
4
4
|
main,
|
|
5
5
|
releaseCaptureClaim
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-CKMUCU6E.js";
|
|
6
|
+
} from "./chunk-BTZJDIC4.js";
|
|
7
|
+
import "./chunk-H7MXR6QX.js";
|
|
9
8
|
import "./chunk-WRI3HTCJ.js";
|
|
10
9
|
export {
|
|
11
10
|
announceCapture,
|
|
12
11
|
main,
|
|
13
12
|
releaseCaptureClaim
|
|
14
13
|
};
|
|
15
|
-
//# sourceMappingURL=claim-
|
|
14
|
+
//# sourceMappingURL=claim-TARSUW6K.js.map
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
explicitTempoDirRelative,
|
|
5
5
|
main,
|
|
6
6
|
resolveOrClaimBaseline
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VZDQYZCX.js";
|
|
8
|
+
import "./chunk-TEVWNWZ6.js";
|
|
8
9
|
import {
|
|
9
10
|
VISUAL_REVIEW_OIDC_AUDIENCE
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-H7MXR6QX.js";
|
|
11
12
|
import "./chunk-WRI3HTCJ.js";
|
|
12
13
|
export {
|
|
13
14
|
VISUAL_REVIEW_OIDC_AUDIENCE,
|
|
@@ -16,4 +17,4 @@ export {
|
|
|
16
17
|
main,
|
|
17
18
|
resolveOrClaimBaseline
|
|
18
19
|
};
|
|
19
|
-
//# sourceMappingURL=cli-
|
|
20
|
+
//# sourceMappingURL=cli-HWGJAH23.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,61 @@ export { TimingReport, percentile, summarize } from './src/timing';
|
|
|
6
6
|
import { NewerSdkStoryboard, CaptureStatus } from './src/types';
|
|
7
7
|
export { CaptureStatus, EnvFingerprint } from './src/types';
|
|
8
8
|
|
|
9
|
+
type GithubActionsEvent = {
|
|
10
|
+
number?: number;
|
|
11
|
+
pull_request?: {
|
|
12
|
+
number?: number;
|
|
13
|
+
body?: string | null;
|
|
14
|
+
labels?: Array<{
|
|
15
|
+
name?: string | null;
|
|
16
|
+
}>;
|
|
17
|
+
head?: {
|
|
18
|
+
ref?: string;
|
|
19
|
+
sha?: string;
|
|
20
|
+
};
|
|
21
|
+
base?: {
|
|
22
|
+
ref?: string;
|
|
23
|
+
sha?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type Env = Record<string, string | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Where a capture runs, as the CLI needs it — independent of which CI
|
|
31
|
+
* produced it (TEM-2737). GitHub Actions fills it from the event payload and
|
|
32
|
+
* GITHUB_* environment exactly as the CLI always has; Bitbucket Pipelines
|
|
33
|
+
* fills it from BITBUCKET_*; anything else is a local, Convex-free run.
|
|
34
|
+
*/
|
|
35
|
+
type CiContext = {
|
|
36
|
+
provider: "github" | "bitbucket" | "local";
|
|
37
|
+
/** A CI run that uploads by default (local capture is opt-in). */
|
|
38
|
+
isCi: boolean;
|
|
39
|
+
trigger: "pr" | "main" | "manual";
|
|
40
|
+
prNumber?: number;
|
|
41
|
+
headSha?: string;
|
|
42
|
+
branch?: string;
|
|
43
|
+
/** The PR's target branch — the merge-base anchor. */
|
|
44
|
+
baseRef?: string;
|
|
45
|
+
/** The PR's base SHA from the event payload (GitHub only), a fallback
|
|
46
|
+
* when the checkout carries no remote branch to compute a merge-base. */
|
|
47
|
+
baseSha?: string;
|
|
48
|
+
/** `owner/repo` (GitHub) or `workspace/repo` (Bitbucket) as the
|
|
49
|
+
* provider spells it. */
|
|
50
|
+
repoFullName?: string;
|
|
51
|
+
/** Tempo's repo key when the provider fixes it (Bitbucket). GitHub runs
|
|
52
|
+
* derive it from `repoFullName` exactly as before. */
|
|
53
|
+
repoKey?: string;
|
|
54
|
+
/** PR-owned declarations visible from the environment. Bitbucket has no
|
|
55
|
+
* labels and no description in its environment; Tempo reads the
|
|
56
|
+
* description server-side instead (`declareNoVisualChangeIfPresent`). */
|
|
57
|
+
declaration: {
|
|
58
|
+
bypass: boolean;
|
|
59
|
+
noVisualChange: boolean;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
declare function detectCiContext(env?: Env, readEvent?: () => GithubActionsEvent | null): CiContext;
|
|
63
|
+
|
|
9
64
|
declare function main$3(argv?: string[]): Promise<number>;
|
|
10
65
|
|
|
11
66
|
type VrtIgnoreRegion = {
|
|
@@ -60,6 +115,12 @@ type EnumerationResult = {
|
|
|
60
115
|
type RunManifest = {
|
|
61
116
|
repoKey: string;
|
|
62
117
|
githubRepo?: string;
|
|
118
|
+
/** The repository on a non-GitHub host (Bitbucket: `workspace/repo`).
|
|
119
|
+
* GitHub runs keep using `githubRepo` and leave this unset. */
|
|
120
|
+
scm?: {
|
|
121
|
+
provider: "bitbucket";
|
|
122
|
+
fullName: string;
|
|
123
|
+
};
|
|
63
124
|
headSha: string;
|
|
64
125
|
branch: string;
|
|
65
126
|
trigger: "pr" | "main" | "manual";
|
|
@@ -99,6 +160,10 @@ type RunManifest = {
|
|
|
99
160
|
type IngestCredential = {
|
|
100
161
|
kind: "oidc";
|
|
101
162
|
value: string;
|
|
163
|
+
/** Bitbucket Pipelines only: the repo key the step token is used for.
|
|
164
|
+
* Its token carries workspace/repository UUIDs, not a name, so the
|
|
165
|
+
* server resolves the key's grant and checks the two agree. */
|
|
166
|
+
repoKey?: string;
|
|
102
167
|
} | {
|
|
103
168
|
kind: "secret";
|
|
104
169
|
value: string;
|
|
@@ -254,4 +319,4 @@ declare function main$1(argv?: string[]): Promise<number>;
|
|
|
254
319
|
|
|
255
320
|
declare function main(argv?: string[]): Promise<number>;
|
|
256
321
|
|
|
257
|
-
export { type BaselineClaimIdentity, type BaselineClaimResult, DEFAULT_VISUAL_REVIEW_INGEST_URL, type EnumerationResult, type RunManifest, type TrackedStoryboard, VisualReviewHttpError, VisualReviewIngestClient, type VrtIgnoreRegion, enumerateTrackedStoryboards, resolveOrClaimBaseline, main$2 as runCaptureCli, main$3 as runClaimCli, main$1 as runInstallBrowsersCli, main as runReportCli, scaleIgnoreRegionsToDevicePx };
|
|
322
|
+
export { type BaselineClaimIdentity, type BaselineClaimResult, type CiContext, DEFAULT_VISUAL_REVIEW_INGEST_URL, type EnumerationResult, type RunManifest, type TrackedStoryboard, VisualReviewHttpError, VisualReviewIngestClient, type VrtIgnoreRegion, detectCiContext, enumerateTrackedStoryboards, resolveOrClaimBaseline, main$2 as runCaptureCli, main$3 as runClaimCli, main$1 as runInstallBrowsersCli, main as runReportCli, scaleIgnoreRegionsToDevicePx };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tempoCreateRequire } from 'node:module'; const require = __tempoCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
main
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-BTZJDIC4.js";
|
|
5
5
|
import {
|
|
6
6
|
CHROMIUM_LAUNCH_ARGS,
|
|
7
7
|
DEVICE_SCALE_FACTOR,
|
|
@@ -26,17 +26,18 @@ import {
|
|
|
26
26
|
startDevserverSession,
|
|
27
27
|
storyboardRenderId,
|
|
28
28
|
summarize
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-VZDQYZCX.js";
|
|
30
30
|
import {
|
|
31
31
|
main as main3
|
|
32
32
|
} from "./chunk-EYRAT56C.js";
|
|
33
33
|
import {
|
|
34
34
|
main as main4
|
|
35
|
-
} from "./chunk-
|
|
36
|
-
import "./chunk-
|
|
35
|
+
} from "./chunk-PI6TS733.js";
|
|
36
|
+
import "./chunk-TEVWNWZ6.js";
|
|
37
37
|
import {
|
|
38
|
-
DEFAULT_VISUAL_REVIEW_INGEST_URL
|
|
39
|
-
|
|
38
|
+
DEFAULT_VISUAL_REVIEW_INGEST_URL,
|
|
39
|
+
detectCiContext
|
|
40
|
+
} from "./chunk-H7MXR6QX.js";
|
|
40
41
|
import "./chunk-WRI3HTCJ.js";
|
|
41
42
|
export {
|
|
42
43
|
CHROMIUM_LAUNCH_ARGS,
|
|
@@ -51,6 +52,7 @@ export {
|
|
|
51
52
|
VisualReviewIngestClient,
|
|
52
53
|
buildEnvFingerprint,
|
|
53
54
|
buildFreezeInitScript,
|
|
55
|
+
detectCiContext,
|
|
54
56
|
enumerateTrackedStoryboards,
|
|
55
57
|
looksBlank,
|
|
56
58
|
percentile,
|
|
@@ -2,12 +2,12 @@ import { createRequire as __tempoCreateRequire } from 'node:module'; const requi
|
|
|
2
2
|
import {
|
|
3
3
|
main,
|
|
4
4
|
publisherDeliveryFailure
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-PI6TS733.js";
|
|
6
|
+
import "./chunk-TEVWNWZ6.js";
|
|
7
|
+
import "./chunk-H7MXR6QX.js";
|
|
8
8
|
import "./chunk-WRI3HTCJ.js";
|
|
9
9
|
export {
|
|
10
10
|
main,
|
|
11
11
|
publisherDeliveryFailure
|
|
12
12
|
};
|
|
13
|
-
//# sourceMappingURL=report-
|
|
13
|
+
//# sourceMappingURL=report-XRYE2D5O.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tempo-ai/visual-review",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.139",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tempo-visual-review": "dist/bin.js"
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"@types/pngjs": "^6.0.5",
|
|
41
41
|
"tsup": "^8.5.1",
|
|
42
42
|
"typescript": "catalog:",
|
|
43
|
-
"vitest": "^3.1.1"
|
|
43
|
+
"vitest": "^3.1.1",
|
|
44
|
+
"@tempo-modules/git-provider": "workspace:*"
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "tsup",
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Written by Tempo visual-review onboarding (visual_review_init). Bitbucket
|
|
2
|
+
# reads ONE bitbucket-pipelines.yml per repository: when you already have
|
|
3
|
+
# one, merge the `tempo-visual-review` step and the two pipeline entries
|
|
4
|
+
# below into it and keep your own pipelines. The corepack line and the two
|
|
5
|
+
# install lines are the package-manager-specific part; init rewrites them
|
|
6
|
+
# for npm / yarn / bun. Keep every `npx --yes @tempo-ai/visual-review@latest …`
|
|
7
|
+
# line as it is. The CLI comes from npm, never from this checkout; the
|
|
8
|
+
# checkout's own install scripts and canvas host do run inside the step (as
|
|
9
|
+
# in any CI), so treat it like your other pipelines.
|
|
10
|
+
#
|
|
11
|
+
# What Bitbucket can and cannot do here:
|
|
12
|
+
# - Identity: `oidc: true` gives the step a Bitbucket-signed token
|
|
13
|
+
# (BITBUCKET_STEP_OIDC_TOKEN). It cannot be re-minted mid-step, so claim,
|
|
14
|
+
# capture and report run in ONE step, within that token's lifetime.
|
|
15
|
+
# - The `visual-review` build status is posted by Tempo through the
|
|
16
|
+
# repository grant you authorize in Tempo (visual_review_doctor →
|
|
17
|
+
# bitbucket_grant). Portal approvals update it without re-running this
|
|
18
|
+
# step, and a new push needs a new approval.
|
|
19
|
+
# - Reporting works on every plan. BLOCKING merges on the verdict needs the
|
|
20
|
+
# Tempo custom merge check (a Bitbucket Forge app) on a plan that supports
|
|
21
|
+
# custom merge checks (Premium). "Minimum successful builds" counts every
|
|
22
|
+
# build status, so it is not an exact "Tempo approved" requirement.
|
|
23
|
+
# - Bitbucket has no pull-request labels, so there is no bypass label. The
|
|
24
|
+
# `<!-- tempo-no-visual-change -->` declaration in the PR description works.
|
|
25
|
+
# - The sticky report comment needs a repository access token with
|
|
26
|
+
# pull-request write access, stored as the secured repository variable
|
|
27
|
+
# TEMPO_VISUAL_REVIEW_BITBUCKET_TOKEN. Without it the comment is skipped;
|
|
28
|
+
# the build status still posts.
|
|
29
|
+
image: node:24-bookworm
|
|
30
|
+
|
|
31
|
+
definitions:
|
|
32
|
+
caches:
|
|
33
|
+
tempo-vite: tempo/node_modules/.vite
|
|
34
|
+
steps:
|
|
35
|
+
- step: &tempo-visual-review
|
|
36
|
+
name: Tempo visual review
|
|
37
|
+
oidc: true
|
|
38
|
+
clone:
|
|
39
|
+
# Full history: the merge-base ancestor chain is the baseline key.
|
|
40
|
+
depth: full
|
|
41
|
+
# A PR may first wait for another run's baseline and then render both
|
|
42
|
+
# the merge-base and its own head.
|
|
43
|
+
max-time: 90
|
|
44
|
+
# Chromium plus the canvas host's devserver need more than 4 GB.
|
|
45
|
+
size: 2x
|
|
46
|
+
caches:
|
|
47
|
+
- tempo-vite
|
|
48
|
+
script:
|
|
49
|
+
# Capture the PR head commit, not a merge of the destination branch.
|
|
50
|
+
- git checkout --force --detach "$BITBUCKET_COMMIT"
|
|
51
|
+
# Announces intent before dependency/browser setup so stacked PRs
|
|
52
|
+
# wait on the baseline lease instead of duplicating a capture.
|
|
53
|
+
- npx --yes @tempo-ai/visual-review@latest claim || echo "capture claim announcement unavailable; capture claims after setup"
|
|
54
|
+
- corepack enable
|
|
55
|
+
- pnpm install --frozen-lockfile
|
|
56
|
+
# The canvas host under `tempo/` is its own package. Capture never
|
|
57
|
+
# mutates this checkout (TEMPO_DEVSERVER_PROTECTED_ROOTS below), so
|
|
58
|
+
# the host's dependencies are installed here, explicitly.
|
|
59
|
+
- (cd tempo && pnpm install --no-frozen-lockfile)
|
|
60
|
+
# Chromium matching the CLI's own pinned playwright, plus its shared
|
|
61
|
+
# libraries.
|
|
62
|
+
- npx --yes @tempo-ai/visual-review@latest install-browsers
|
|
63
|
+
# `capture` infers PR-vs-main, head SHA, branch, merge-base and
|
|
64
|
+
# repository from the BITBUCKET_* environment and authenticates with
|
|
65
|
+
# the step's OIDC token. A PR whose description carries the
|
|
66
|
+
# no-visual-change declaration is skipped here.
|
|
67
|
+
- TEMPO_DEVSERVER_PROTECTED_ROOTS="$BITBUCKET_CLONE_DIR" npx --yes @tempo-ai/visual-review@latest capture --parallel 2
|
|
68
|
+
# Polls the run until Tempo has compared it, then upserts the sticky
|
|
69
|
+
# PR comment. A no-op on branch pipelines.
|
|
70
|
+
- npx --yes @tempo-ai/visual-review@latest report
|
|
71
|
+
after-script:
|
|
72
|
+
# A finished capture has already consumed its claim; this only
|
|
73
|
+
# releases a lease left behind by a setup failure.
|
|
74
|
+
- npx --yes @tempo-ai/visual-review@latest claim --release || echo "capture claim release unavailable; the lease expires on its own"
|
|
75
|
+
# A failed step must not strand the status at in progress. Only
|
|
76
|
+
# replaces an in-progress or absent status, never a delivered verdict.
|
|
77
|
+
- if [ "$BITBUCKET_EXIT_CODE" != "0" ]; then npx --yes @tempo-ai/visual-review@latest report --fallback-failure; fi
|
|
78
|
+
|
|
79
|
+
pipelines:
|
|
80
|
+
pull-requests:
|
|
81
|
+
'**':
|
|
82
|
+
- step: *tempo-visual-review
|
|
83
|
+
branches:
|
|
84
|
+
# Your default branch: pushes here publish the baseline PRs compare against.
|
|
85
|
+
main:
|
|
86
|
+
- step: *tempo-visual-review
|
package/dist/chunk-CKMUCU6E.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,E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EACN;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/claim.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { appendFile } from \"node:fs/promises\";\n\nimport { DEFAULT_VISUAL_REVIEW_INGEST_URL } from \"./constants\";\nimport { githubPullRequestContext } from \"./github-actions\";\nimport { publishWorkflowStatus } from \"./workflow-status\";\n\nconst PENDING_ENVIRONMENT = \"pending\";\nconst OIDC_AUDIENCE = \"tempo-visual-review\";\n\n/** The slice of `fetch` the claim protocol uses. A plain `(url, init)` mock\n * satisfies it without impersonating the overloaded global. */\ntype FetchLike = (input: string, init?: RequestInit) => Promise<Response>;\n\nasync function mintOidcToken(options: {\n oidcRequestUrl: string;\n oidcRequestToken: string;\n fetchImpl: FetchLike;\n}): Promise<string> {\n const separator = options.oidcRequestUrl.includes(\"?\") ? \"&\" : \"?\";\n const tokenResponse = await options.fetchImpl(\n `${options.oidcRequestUrl}${separator}audience=${OIDC_AUDIENCE}`,\n { headers: { Authorization: `Bearer ${options.oidcRequestToken}` } },\n );\n if (!tokenResponse.ok) {\n throw new Error(`OIDC token request failed: ${tokenResponse.status}`);\n }\n const { value } = (await tokenResponse.json()) as { value?: string };\n if (!value) throw new Error(\"OIDC token response had no value\");\n return value;\n}\n\nasync function postClaimRequest(options: {\n ingestUrl: string;\n oidcToken: string;\n path: \"claim\" | \"fail\";\n body: Record<string, string>;\n fetchImpl: FetchLike;\n}): Promise<Record<string, unknown>> {\n const response = await options.fetchImpl(\n `${options.ingestUrl.replace(/\\/$/, \"\")}/visual-review/baseline/${options.path}`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-visual-review-oidc\": options.oidcToken,\n },\n body: JSON.stringify(options.body),\n },\n );\n if (!response.ok) {\n throw new Error(\n `capture ${options.path} failed: ${response.status} ${(await response.text()).slice(0, 200)}`,\n );\n }\n return (await response.json()) as Record<string, unknown>;\n}\n\nexport async function announceCapture(options: {\n ingestUrl: string;\n repository: string;\n headSha: string;\n oidcRequestUrl: string;\n oidcRequestToken: string;\n ownerToken?: string;\n fetchImpl?: FetchLike;\n}): Promise<{ ownerToken?: string; status?: string }> {\n const ownerToken = options.ownerToken ?? randomUUID();\n const fetchImpl = options.fetchImpl ?? fetch;\n const oidcToken = await mintOidcToken({ ...options, fetchImpl });\n const result = await postClaimRequest({\n ingestUrl: options.ingestUrl,\n oidcToken,\n path: \"claim\",\n body: {\n repoKey: `github.com/${options.repository.toLowerCase()}`,\n commitSha: options.headSha,\n envFingerprint: PENDING_ENVIRONMENT,\n ownerToken,\n },\n fetchImpl,\n });\n const status = typeof result.status === \"string\" ? result.status : undefined;\n return {\n ownerToken: status === \"claimed\" ? ownerToken : undefined,\n status,\n };\n}\n\nexport async function releaseCaptureClaim(options: {\n ingestUrl: string;\n repository: string;\n headSha: string;\n ownerToken: string;\n oidcRequestUrl: string;\n oidcRequestToken: string;\n fetchImpl?: FetchLike;\n}): Promise<{ released?: boolean }> {\n const fetchImpl = options.fetchImpl ?? fetch;\n const oidcToken = await mintOidcToken({ ...options, fetchImpl });\n const result = await postClaimRequest({\n ingestUrl: options.ingestUrl,\n oidcToken,\n path: \"fail\",\n body: {\n repoKey: `github.com/${options.repository.toLowerCase()}`,\n commitSha: options.headSha,\n ownerToken: options.ownerToken,\n error: \"workflow ended before the capture claim completed\",\n },\n fetchImpl,\n });\n return { released: result.released === true };\n}\n\nfunction parseArgs(argv: string[]) {\n if (argv.some((arg) => arg !== \"--release\")) {\n throw new Error(\"claim accepts only the optional --release flag\");\n }\n return { release: argv.includes(\"--release\") };\n}\n\nexport async function main(argv = process.argv.slice(2)): Promise<number> {\n const { release } = parseArgs(argv);\n const pullRequest = githubPullRequestContext();\n const required = {\n ingestUrl:\n process.env.VISUAL_REVIEW_INGEST_URL ?? DEFAULT_VISUAL_REVIEW_INGEST_URL,\n repository: process.env.GITHUB_REPOSITORY,\n // GITHUB_SHA is a merge ref on pull_request runs; the event payload is\n // the only standard environment source for the actual PR head SHA.\n headSha:\n process.env.CAPTURE_HEAD_SHA ??\n pullRequest?.headSha ??\n process.env.GITHUB_SHA,\n oidcRequestUrl: process.env.ACTIONS_ID_TOKEN_REQUEST_URL,\n oidcRequestToken: process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN,\n ...(release\n ? { ownerToken: process.env.VISUAL_REVIEW_CAPTURE_OWNER_TOKEN }\n : {}),\n };\n const missing = Object.entries(required)\n .filter(([, value]) => !value)\n .map(([name]) => name);\n if (missing.length > 0) {\n console.warn(\n `capture announcement skipped; missing ${missing.join(\", \")} (capture will claim after setup)`,\n );\n return 0;\n }\n\n if (\n !release &&\n process.env.GITHUB_EVENT_NAME === \"pull_request\" &&\n required.headSha\n ) {\n try {\n await publishWorkflowStatus(\"capture-started\", required.headSha);\n } catch (error) {\n // Capture still gets a chance to complete and publish its real gate.\n console.warn(\n `pending status unavailable: ${error instanceof Error ? error.message : error}`,\n );\n }\n }\n\n try {\n if (release) {\n const result = await releaseCaptureClaim(\n required as Parameters<typeof releaseCaptureClaim>[0],\n );\n console.log(\n `capture claim release: ${result.released ? \"released\" : \"already complete or transferred\"}`,\n );\n return 0;\n }\n const result = await announceCapture(\n required as Parameters<typeof announceCapture>[0],\n );\n console.log(`capture announcement: ${result.status}`);\n if (result.ownerToken && process.env.GITHUB_ENV) {\n await appendFile(\n process.env.GITHUB_ENV,\n `VISUAL_REVIEW_CAPTURE_OWNER_TOKEN=${result.ownerToken}\\n`,\n );\n }\n return 0;\n } catch (error) {\n // The capture command repeats the atomic claim with the real environment\n // fingerprint; an early announcement outage must not suppress coverage.\n console.warn(\n `capture announcement failed; deferring to capture: ${error instanceof Error ? error.message : error}`,\n );\n return 0;\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAM3B,IAAM,sBAAsB;AAC5B,IAAM,gBAAgB;AAMtB,eAAe,cAAc,SAIT;AAClB,QAAM,YAAY,QAAQ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E,YAAY,QAAQ,IAAI,kCAAkC,IAC5D,CAAC;AAAA,EACP;AACA,QAAM,UAAU,OAAO,QAAQ,QAAQ,EACpC,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,KAAK,EAC5B,IAAI,CAAC,CAAC,IAAI,MAAM,IAAI;AACvB,MAAI,QAAQ,SAAS,GAAG;AACtB,YAAQ;AAAA,MACN,yCAAyC,QAAQ,KAAK,IAAI,CAAC;AAAA,IAC7D;AACA,WAAO;AAAA,EACT;AAEA,MACE,CAAC,WACD,QAAQ,IAAI,sBAAsB,kBAClC,SAAS,SACT;AACA,QAAI;AACF,YAAM,sBAAsB,mBAAmB,SAAS,OAAO;AAAA,IACjE,SAAS,OAAO;AAEd,cAAQ;AAAA,QACN,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAAA,MAC/E;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AACF,QAAI,SAAS;AACX,YAAMA,UAAS,MAAM;AAAA,QACnB;AAAA,MACF;AACA,cAAQ;AAAA,QACN,0BAA0BA,QAAO,WAAW,aAAa,iCAAiC;AAAA,MAC5F;AACA,aAAO;AAAA,IACT;AACA,UAAM,SAAS,MAAM;AAAA,MACnB;AAAA,IACF;AACA,YAAQ,IAAI,yBAAyB,OAAO,MAAM,EAAE;AACpD,QAAI,OAAO,cAAc,QAAQ,IAAI,YAAY;AAC/C,YAAM;AAAA,QACJ,QAAQ,IAAI;AAAA,QACZ,qCAAqC,OAAO,UAAU;AAAA;AAAA,MACxD;AAAA,IACF;AACA,WAAO;AAAA,EACT,SAAS,OAAO;AAGd,YAAQ;AAAA,MACN,sDAAsD,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAAA,IACtG;AACA,WAAO;AAAA,EACT;AACF;","names":["result"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/report.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\n\nimport { visualReviewPrDeclaration } from \"./github-actions\";\nimport { publishWorkflowStatus } from \"./workflow-status\";\n\nconst STICKY_MARKER = \"<!-- tempo-visual-review -->\";\n\ntype ReportArgs = {\n pollTimeoutS: number;\n bypass: boolean;\n noVisualChange: boolean;\n fallbackFailure: boolean;\n statusUrl?: string;\n pr?: number;\n sha?: string;\n};\n\ntype Gate = {\n satisfied?: boolean;\n required?: number;\n approvalsNeeded?: number;\n rejected?: number;\n blockingErrors?: number;\n};\n\n/**\n * Shape of the `/visual-review/status` poll. Convex serialises absent\n * optional fields as `null`, not `undefined` — every optional here must be\n * read null-safely.\n */\nexport type ReportStatus = {\n state?: \"complete\" | \"error\" | string;\n reportUrl?: string;\n trackedTotal?: number;\n counts?: Record<string, number | undefined>;\n gate?: Gate;\n topChanged?: Array<{\n name?: string;\n storyboardId: string;\n diffRatio?: number | null;\n verdict: string;\n error?: string;\n baselineHash?: string;\n candidateHash?: string;\n }>;\n blobUrlTemplate?: string;\n approximateBase?: boolean;\n freshEpoch?: boolean;\n publisherConfigured?: boolean;\n lastPublishError?: { revision: number; error: string } | null;\n lastPublish?: { revision: number } | null;\n statusPublishing?: boolean | null;\n};\n\n/**\n * `publisherConfigured` only means the GitHub App env is set GLOBALLY — it\n * does NOT mean the app can post on THIS repo (it may not be installed\n * there, or lack the permission). When the publisher has a TERMINAL\n * outstanding failure for the current revision, the report job fails\n * visibly without changing publisher identity. Terminal means the error is\n * current (revision-compare, mirroring the portal's \"delivery failing\"\n * banner) AND no publish worker holds the singleflight claim\n * (`statusPublishing === false`). A transient failure mid-retry-ladder keeps\n * the claim, so the report lets the publisher's retry finish.\n *\n * Returns the terminal failure, or `null` while publishing is healthy or retrying.\n */\nexport function publisherDeliveryFailure(\n status: ReportStatus,\n): { revision: number; error: string } | null {\n const publishError = status.lastPublishError;\n // A healthy run reports `lastPublishError: null` (0.0.1 compared against\n // `undefined` only and crashed on `.revision`).\n if (publishError == null) return null;\n if (publishError.revision < (status.lastPublish?.revision ?? 0)) return null;\n if (status.statusPublishing !== false) return null;\n return publishError;\n}\n\nfunction parseArgs(argv: string[]): ReportArgs {\n const args: ReportArgs = {\n pollTimeoutS: 900,\n bypass: false,\n noVisualChange: false,\n fallbackFailure: false,\n };\n for (let index = 0; index < argv.length; index += 1) {\n const flag = argv[index];\n const next = () => {\n const value = argv[++index];\n if (value === undefined) throw new Error(`${flag} needs a value`);\n return value;\n };\n if (flag === \"--status-url\") args.statusUrl = next();\n else if (flag === \"--pr\") args.pr = Number(next());\n else if (flag === \"--sha\") args.sha = next();\n else if (flag === \"--poll-timeout-s\") args.pollTimeoutS = Number(next());\n else if (flag === \"--bypass\") args.bypass = true;\n else if (flag === \"--no-visual-change\") args.noVisualChange = true;\n else if (flag === \"--fallback-failure\") args.fallbackFailure = true;\n else throw new Error(`unknown flag ${flag}`);\n }\n if (!args.sha) throw new Error(\"--sha is required\");\n return args;\n}\n\nfunction gh(...ghArgs: string[]): string {\n return execFileSync(\"gh\", ghArgs, { encoding: \"utf-8\", windowsHide: true });\n}\n\nfunction upsertStickyComment(repo: string, pr: number, body: string): void {\n const comments = (\n JSON.parse(\n gh(\"api\", `repos/${repo}/issues/${pr}/comments`, \"--paginate\", \"--slurp\"),\n ) as Array<Array<{ id: number; body?: string }>>\n ).flat();\n const existing = comments.find(\n (comment) =>\n typeof comment.body === \"string\" && comment.body.includes(STICKY_MARKER),\n );\n if (existing) {\n gh(\n \"api\",\n \"--method\",\n \"PATCH\",\n `repos/${repo}/issues/comments/${existing.id}`,\n \"-f\",\n `body=${body}`,\n );\n } else {\n gh(\"api\", `repos/${repo}/issues/${pr}/comments`, \"-f\", `body=${body}`);\n }\n}\n\nfunction describeGate(\n gate: Gate,\n state: ReportStatus[\"state\"],\n): { state: \"success\" | \"failure\" | \"pending\"; description: string } {\n if (state === \"error\") {\n return {\n state: \"failure\",\n description: \"visual review run failed — see report\",\n };\n }\n if (state !== \"complete\") {\n return {\n state: \"pending\",\n description: \"capturing & comparing storyboards…\",\n };\n }\n if (gate.satisfied) {\n return {\n state: \"success\",\n description:\n gate.required === 0\n ? \"no visual changes\"\n : `${gate.required} visual change${gate.required === 1 ? \"\" : \"s\"} approved`,\n };\n }\n const parts: string[] = [];\n if ((gate.approvalsNeeded ?? 0) > 0) {\n parts.push(`${gate.approvalsNeeded} of ${gate.required} need approval`);\n }\n if ((gate.rejected ?? 0) > 0) parts.push(`${gate.rejected} rejected`);\n if ((gate.blockingErrors ?? 0) > 0) {\n parts.push(\n `${gate.blockingErrors} render error${gate.blockingErrors === 1 ? \"\" : \"s\"}`,\n );\n }\n return {\n state: \"failure\",\n description: `visual review: ${parts.join(\", \")} — see report`,\n };\n}\n\nfunction buildCommentBody(status: ReportStatus): string {\n const counts = status.counts ?? {};\n const gateLine = status.gate?.satisfied\n ? \"✅ **Check passing** — every visual change is approved.\"\n : `🔴 **Check failing** — ${status.gate?.approvalsNeeded ?? \"?\"} of ${status.gate?.required ?? \"?\"} storyboards need approval${status.gate?.blockingErrors ? `, ${status.gate.blockingErrors} render error(s)` : \"\"}${status.gate?.rejected ? `, ${status.gate.rejected} rejected` : \"\"}. Approving in the report flips the check instantly — no CI re-run.`;\n const summary = `| tracked | changed | new | removed | render errors | unchanged |\n| --- | --- | --- | --- | --- | --- |\n| ${status.trackedTotal ?? 0} | ${counts.changed ?? 0} | ${counts.added ?? 0} | ${counts.removed ?? 0} | ${counts.errors ?? 0} | ${counts.unchanged ?? 0} |`;\n\n const thumbs = (status.topChanged ?? [])\n .slice(0, 6)\n .map((board) => {\n const title = board.name ?? board.storyboardId;\n const meta =\n board.diffRatio !== undefined && board.diffRatio !== null\n ? ` · ${(board.diffRatio * 100).toFixed(2)}%`\n : \"\";\n if (board.verdict === \"render-error\") {\n return `**${title}** — render error${board.error ? `: \\`${board.error.slice(0, 120)}\\`` : \"\"}`;\n }\n const cell = (hash: string | undefined, label: string) =>\n hash && status.blobUrlTemplate\n ? `<img src=\"${status.blobUrlTemplate}${hash}\" alt=\"${label}\" width=\"360\" />`\n : \"—\";\n return `<details><summary><b>${title}</b> — ${board.verdict}${meta}</summary>\n\n| baseline | candidate |\n| --- | --- |\n| ${cell(board.baselineHash, \"baseline\")} | ${cell(board.candidateHash, \"candidate\")} |\n\n</details>`;\n })\n .join(\"\\n\");\n\n const notes: string[] = [];\n if (status.approximateBase) {\n notes.push(\n \"⚠ exact merge-base had no visual run — compared against the nearest captured ancestor.\",\n );\n }\n if (status.freshEpoch) {\n notes.push(\n \"ℹ fresh baseline epoch (capture environment changed) — everything reports as new.\",\n );\n }\n\n return `${STICKY_MARKER}\n## 👁 Visual review\n\n${gateLine}\n\n${summary}\n\n${notes.length > 0 ? `${notes.join(\"\\n\")}\\n` : \"\"}${thumbs}\n\n📷 **[Open the visual review report](${status.reportUrl})** — side-by-side, onion-skin and diff views; approve, reject, and comment there.`;\n}\n\nfunction buildNoVisualChangeComment(): string {\n return `${STICKY_MARKER}\n## 👁 Visual review\n\n✅ **Not applicable — no storyboard changes expected.** Storyboard capture was skipped from the PR declaration.`;\n}\n\nfunction isPermanentError(error: unknown): boolean {\n return (\n error instanceof Error && \"permanent\" in error && error.permanent === true\n );\n}\n\nexport async function main(argv = process.argv.slice(2)): Promise<number> {\n const args = parseArgs(argv);\n const repo = process.env.GITHUB_REPOSITORY;\n if (!repo) throw new Error(\"GITHUB_REPOSITORY is not set\");\n const sha = args.sha;\n if (!sha) throw new Error(\"--sha is required\");\n const declaration = visualReviewPrDeclaration();\n\n if (args.bypass || declaration.bypass) {\n await publishWorkflowStatus(\"bypass\", sha);\n console.log(\"bypass label present — posted success and skipped the report\");\n return 0;\n }\n\n if (args.noVisualChange || declaration.noVisualChange) {\n await publishWorkflowStatus(\"no-visual-change\", sha);\n if (args.pr)\n upsertStickyComment(repo, args.pr, buildNoVisualChangeComment());\n console.log(\n \"no-visual-change declaration present — posted success and skipped capture\",\n );\n return 0;\n }\n\n if (args.fallbackFailure) {\n await publishWorkflowStatus(\"workflow-failed\", sha);\n return 0;\n }\n\n const statusUrl = args.statusUrl;\n if (!statusUrl) throw new Error(\"--status-url is required\");\n const deadline = Date.now() + args.pollTimeoutS * 1_000;\n let status: ReportStatus | undefined;\n for (;;) {\n try {\n const response = await fetch(statusUrl);\n if (response.status === 404) {\n const error = new Error(\"status poll 404 — wrong report key\");\n Object.assign(error, { permanent: true });\n throw error;\n }\n if (!response.ok)\n throw new Error(`status poll failed: ${response.status}`);\n status = (await response.json()) as ReportStatus;\n } catch (error) {\n if (isPermanentError(error)) throw error;\n console.warn(\n `transient status poll failure, retrying: ${error instanceof Error ? error.message : error}`,\n );\n }\n if (status && (status.state === \"complete\" || status.state === \"error\")) {\n break;\n }\n if (Date.now() > deadline) {\n await publishWorkflowStatus(\"workflow-failed\", sha);\n throw new Error(\"timed out waiting for the run to complete\");\n }\n await new Promise((resolve) => setTimeout(resolve, 5_000));\n }\n\n const publishFailure = publisherDeliveryFailure(status);\n if (!status.publisherConfigured || publishFailure !== null) {\n throw new Error(\n `Tempo GitHub App could not publish visual-review: ${publishFailure?.error ?? \"publisher unconfigured\"}. Restore the app installation/configuration and retry; Actions cannot substitute for the required app.`,\n );\n }\n console.log(\"visual-review verdict is owned by the Tempo GitHub App\");\n\n if (args.pr) {\n upsertStickyComment(repo, args.pr, buildCommentBody(status));\n console.log(`sticky comment upserted on #${args.pr}`);\n }\n return 0;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,oBAAoB;AAK7B,IAAM,gBAAgB;AA8Df,SAAS,yBACd,QAC4C;AAC5C,QAAM,eAAe,OAAO;AAG5B,MAAI,gBAAgB,KAAM,QAAO;AACjC,MAAI,aAAa,YAAY,OAAO,aAAa,YAAY,GAAI,QAAO;AACxE,MAAI,OAAO,qBAAqB,MAAO,QAAO;AAC9C,SAAO;AACT;AAEA,SAAS,UAAU,MAA4B;AAC7C,QAAM,OAAmB;AAAA,IACvB,cAAc;AAAA,IACd,QAAQ;AAAA,IACR,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,EACnB;AACA,WAAS,QAAQ,GAAG,QAAQ,KAAK,QA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from 'node:module'; const require = __tempoCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_VISUAL_REVIEW_INGEST_URL,
|
|
4
|
-
resolveIngestCredential
|
|
5
|
-
} from "./chunk-CKMUCU6E.js";
|
|
6
|
-
|
|
7
|
-
// src/workflow-status.ts
|
|
8
|
-
async function publishWorkflowStatus(kind, headSha) {
|
|
9
|
-
const credential = await resolveIngestCredential(true)();
|
|
10
|
-
const origin = (process.env.VISUAL_REVIEW_INGEST_URL ?? DEFAULT_VISUAL_REVIEW_INGEST_URL).replace(/\/$/, "");
|
|
11
|
-
const response = await fetch(`${origin}/visual-review/workflow-status`, {
|
|
12
|
-
method: "POST",
|
|
13
|
-
headers: {
|
|
14
|
-
"Content-Type": "application/json",
|
|
15
|
-
"x-visual-review-oidc": credential.value
|
|
16
|
-
},
|
|
17
|
-
body: JSON.stringify({ headSha, kind })
|
|
18
|
-
});
|
|
19
|
-
if (!response.ok) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Tempo GitHub App status publishing failed (${response.status}): ${(await response.text()).slice(0, 500)}`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
const result = await response.json();
|
|
25
|
-
if (result.status !== "posted" && result.status !== "skipped") {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"Tempo GitHub App returned an invalid status publishing response"
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
console.log(
|
|
31
|
-
`Tempo GitHub App status: ${result.status}${result.reason ? ` (${result.reason})` : ""}`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export {
|
|
36
|
-
publishWorkflowStatus
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=chunk-PDNKZ3PI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/workflow-status.ts"],"sourcesContent":["import { DEFAULT_VISUAL_REVIEW_INGEST_URL } from \"./constants\";\nimport { resolveIngestCredential } from \"./oidc\";\n\ntype WorkflowStatusKind =\n | \"bypass\"\n | \"no-visual-change\"\n | \"capture-started\"\n | \"workflow-failed\";\n\n/** Ask Tempo to publish as its GitHub App. The server derives the repo/PR\n * from OIDC and verifies the live declaration; CI cannot choose success. */\nexport async function publishWorkflowStatus(\n kind: WorkflowStatusKind,\n headSha: string,\n): Promise<void> {\n const credential = await resolveIngestCredential(true)();\n const origin = (\n process.env.VISUAL_REVIEW_INGEST_URL ?? DEFAULT_VISUAL_REVIEW_INGEST_URL\n ).replace(/\\/$/, \"\");\n const response = await fetch(`${origin}/visual-review/workflow-status`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-visual-review-oidc\": credential.value,\n },\n body: JSON.stringify({ headSha, kind }),\n });\n if (!response.ok) {\n throw new Error(\n `Tempo GitHub App status publishing failed (${response.status}): ${(await response.text()).slice(0, 500)}`,\n );\n }\n const result = (await response.json()) as {\n status?: string;\n reason?: string;\n };\n if (result.status !== \"posted\" && result.status !== \"skipped\") {\n throw new Error(\n \"Tempo GitHub App returned an invalid status publishing response\",\n );\n }\n console.log(\n `Tempo GitHub App status: ${result.status}${result.reason ? ` (${result.reason})` : \"\"}`,\n );\n}\n"],"mappings":";;;;;;;AAWA,eAAsB,sBACpB,MACA,SACe;AACf,QAAM,aAAa,MAAM,wBAAwB,IAAI,EAAE;AACvD,QAAM,UACJ,QAAQ,IAAI,4BAA4B,kCACxC,QAAQ,OAAO,EAAE;AACnB,QAAM,WAAW,MAAM,MAAM,GAAG,MAAM,kCAAkC;AAAA,IACtE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,wBAAwB,WAAW;AAAA,IACrC;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,SAAS,KAAK,CAAC;AAAA,EACxC,CAAC;AACD,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI;AAAA,MACR,8CAA8C,SAAS,MAAM,OAAO,MAAM,SAAS,KAAK,GAAG,MAAM,GAAG,GAAG,CAAC;AAAA,IAC1G;AAAA,EACF;AACA,QAAM,SAAU,MAAM,SAAS,KAAK;AAIpC,MAAI,OAAO,WAAW,YAAY,OAAO,WAAW,WAAW;AAC7D,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,UAAQ;AAAA,IACN,4BAA4B,OAAO,MAAM,GAAG,OAAO,SAAS,KAAK,OAAO,MAAM,MAAM,EAAE;AAAA,EACxF;AACF;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|