bdy 1.25.38-stage → 1.25.39-dev-pr
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/distTs/package.json +2 -1
- package/distTs/src/api/client.js +207 -1
- package/distTs/src/autocomplete.js +90 -0
- package/distTs/src/cliError.js +5 -0
- package/distTs/src/cliIndex.js +3 -0
- package/distTs/src/command/artifact/downloadDir.js +110 -0
- package/distTs/src/command/artifact/version/create.js +28 -1
- package/distTs/src/command/artifact/version/get.js +1 -0
- package/distTs/src/command/artifact/version/list.js +2 -1
- package/distTs/src/command/autocomplete/install.js +16 -0
- package/distTs/src/command/autocomplete/uninstall.js +16 -0
- package/distTs/src/command/autocomplete.js +14 -0
- package/distTs/src/command/environment/resolve.js +39 -0
- package/distTs/src/command/login.js +1 -1
- package/distTs/src/command/package/create.js +64 -0
- package/distTs/src/command/package/delete.js +38 -0
- package/distTs/src/command/package/docker/login.js +26 -0
- package/distTs/src/command/package/docker.js +11 -0
- package/distTs/src/command/package/download.js +138 -0
- package/distTs/src/command/package/get.js +36 -0
- package/distTs/src/command/package/list.js +31 -0
- package/distTs/src/command/package/publish.js +241 -0
- package/distTs/src/command/package/version/delete.js +39 -0
- package/distTs/src/command/package/version/get.js +45 -0
- package/distTs/src/command/package/version/list.js +47 -0
- package/distTs/src/command/package/version.js +16 -0
- package/distTs/src/command/package.js +26 -0
- package/distTs/src/command/pipeline/run/apply.js +62 -0
- package/distTs/src/command/pr/comment/add.js +66 -0
- package/distTs/src/command/pr/comment/list.js +167 -0
- package/distTs/src/command/pr/comment/status.js +50 -0
- package/distTs/src/command/pr/comment.js +19 -0
- package/distTs/src/command/pr/create.js +44 -0
- package/distTs/src/command/pr/diff.js +337 -0
- package/distTs/src/command/pr/file/list.js +139 -0
- package/distTs/src/command/pr/file/mark.js +45 -0
- package/distTs/src/command/pr/file.js +16 -0
- package/distTs/src/command/pr/get.js +29 -0
- package/distTs/src/command/pr/list.js +79 -0
- package/distTs/src/command/pr/merge.js +67 -0
- package/distTs/src/command/pr/review/request.js +30 -0
- package/distTs/src/command/pr/review/start.js +29 -0
- package/distTs/src/command/pr/review/verdict.js +81 -0
- package/distTs/src/command/pr/review.js +18 -0
- package/distTs/src/command/pr/shared.js +704 -0
- package/distTs/src/command/pr/state.js +38 -0
- package/distTs/src/command/pr/summary.js +341 -0
- package/distTs/src/command/pr/update.js +56 -0
- package/distTs/src/command/pr/updateBranch.js +22 -0
- package/distTs/src/command/pr/versions.js +42 -0
- package/distTs/src/command/pr.js +39 -0
- package/distTs/src/command/scrape/validation.js +154 -0
- package/distTs/src/command/scrape.js +144 -0
- package/distTs/src/command/suiteLink.js +14 -0
- package/distTs/src/command/tests/visual/result/download.js +31 -0
- package/distTs/src/command/tests/visual/result/get.js +68 -0
- package/distTs/src/command/tests/visual/result/list.js +49 -0
- package/distTs/src/command/tests/visual/result.js +23 -0
- package/distTs/src/command/tests/visual/session/get.js +70 -0
- package/distTs/src/command/tests/visual/session/list.js +69 -0
- package/distTs/src/command/tests/visual/session/open.js +22 -0
- package/distTs/src/command/tests/visual/session/reviewUrl.js +37 -0
- package/distTs/src/command/tests/visual/session/update.js +26 -0
- package/distTs/src/command/tests/visual/shared/context.js +144 -0
- package/distTs/src/command/tests/visual/shared/diffRegions.js +172 -0
- package/distTs/src/command/tests/visual/shared/format.js +21 -0
- package/distTs/src/command/tests/visual/shared/lookup.js +107 -0
- package/distTs/src/command/tests/visual/shared/options.js +90 -0
- package/distTs/src/command/tests/visual/shared/review.js +146 -0
- package/distTs/src/command/tests/visual/shared/reviewUrl.js +62 -0
- package/distTs/src/command/tests/visual/shared/session.js +217 -0
- package/distTs/src/command/tests/visual/snapshot/get.js +46 -0
- package/distTs/src/command/tests/visual/snapshot/list.js +68 -0
- package/distTs/src/command/tests/visual/snapshot/open.js +26 -0
- package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +48 -0
- package/distTs/src/command/tests/visual/snapshot.js +28 -0
- package/distTs/src/command/tests/visual/suite/create.js +38 -0
- package/distTs/src/command/tests/visual/suite/delete.js +29 -0
- package/distTs/src/command/tests/visual/suite/get.js +43 -0
- package/distTs/src/command/tests/visual/suite/list.js +35 -0
- package/distTs/src/command/tests/visual/suite/open.js +20 -0
- package/distTs/src/command/tests/visual/suite/update.js +47 -0
- package/distTs/src/command/tests/visual/suite.js +30 -0
- package/distTs/src/command/ut/upload.js +86 -0
- package/distTs/src/command/ut.js +12 -0
- package/distTs/src/command/vt/close.js +27 -0
- package/distTs/src/command/vt/compare/validation.js +46 -0
- package/distTs/src/command/vt/compare.js +100 -0
- package/distTs/src/command/vt/exec.js +82 -0
- package/distTs/src/command/vt/installBrowser.js +20 -0
- package/distTs/src/command/vt/shared/validation.js +145 -0
- package/distTs/src/command/vt/storybook.js +138 -0
- package/distTs/src/command/vt.js +20 -0
- package/distTs/src/command/yaml/agents.js +88 -0
- package/distTs/src/command/yaml/init.js +110 -0
- package/distTs/src/input.js +15 -0
- package/distTs/src/main.js +190 -0
- package/distTs/src/output/pipeline.js +54 -56
- package/distTs/src/output.js +85 -22
- package/distTs/src/texts.js +545 -23
- package/distTs/src/tunnel/output/interactive/tunnel.js +14 -10
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +3 -1
- package/distTs/src/types/options.js +2 -0
- package/distTs/src/types/scrape.js +2 -0
- package/distTs/src/types/visualTests.js +2 -0
- package/distTs/src/utils.js +151 -6
- package/package.json +2 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../../utils");
|
|
7
|
+
const texts_1 = require("../../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../../output"));
|
|
9
|
+
const context_1 = require("../shared/context");
|
|
10
|
+
const lookup_1 = require("../shared/lookup");
|
|
11
|
+
const reviewUrl_1 = require("../shared/reviewUrl");
|
|
12
|
+
const commandSessionReviewUrl = (0, utils_1.newCommand)('review-url', texts_1.DESC_COMMAND_SESSION_REVIEW_URL, {
|
|
13
|
+
examples: texts_1.EXAMPLE_TESTS_VISUAL_SESSION_REVIEW_URL,
|
|
14
|
+
});
|
|
15
|
+
(0, context_1.vtCommandOptions)(commandSessionReviewUrl);
|
|
16
|
+
commandSessionReviewUrl.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
17
|
+
commandSessionReviewUrl.argument('<session-id>', texts_1.OPTION_VT_SESSION_ID);
|
|
18
|
+
commandSessionReviewUrl.action(async (sessionId, options) => {
|
|
19
|
+
const json = options.format === 'json';
|
|
20
|
+
const ctx = await (0, context_1.resolveVtApiContext)(options);
|
|
21
|
+
const session = await (0, lookup_1.getVtSessionOrExit)(ctx, sessionId);
|
|
22
|
+
const filters = (0, reviewUrl_1.reviewFiltersFor)(await (0, lookup_1.fetchAllVtSnapshots)(ctx, sessionId));
|
|
23
|
+
const url = (0, reviewUrl_1.vtSessionReviewUrl)(session.html_url, filters);
|
|
24
|
+
if (json) {
|
|
25
|
+
output_1.default.json({
|
|
26
|
+
url,
|
|
27
|
+
session_id: session.id,
|
|
28
|
+
status: session.status,
|
|
29
|
+
filter_types: filters,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
output_1.default.normal(url);
|
|
34
|
+
}
|
|
35
|
+
output_1.default.exitNormal();
|
|
36
|
+
});
|
|
37
|
+
exports.default = commandSessionReviewUrl;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../../utils");
|
|
7
|
+
const texts_1 = require("../../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../../output"));
|
|
9
|
+
const context_1 = require("../shared/context");
|
|
10
|
+
const lookup_1 = require("../shared/lookup");
|
|
11
|
+
const commandSessionUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_SESSION_UPDATE, {
|
|
12
|
+
examples: texts_1.EXAMPLE_TESTS_VISUAL_SESSION_UPDATE,
|
|
13
|
+
});
|
|
14
|
+
commandSessionUpdate.alias('edit');
|
|
15
|
+
(0, context_1.vtCommandOptions)(commandSessionUpdate);
|
|
16
|
+
commandSessionUpdate.requiredOption('--comment <comment>', texts_1.OPTION_VT_SESSION_COMMENT);
|
|
17
|
+
commandSessionUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
18
|
+
commandSessionUpdate.argument('<session-id>', texts_1.OPTION_VT_SESSION_ID);
|
|
19
|
+
commandSessionUpdate.action(async (sessionId, options) => {
|
|
20
|
+
const json = options.format === 'json';
|
|
21
|
+
const ctx = await (0, context_1.resolveVtApiContext)(options);
|
|
22
|
+
await (0, lookup_1.getVtSessionOrExit)(ctx, sessionId);
|
|
23
|
+
const session = await ctx.client.updateVtSession(ctx.workspace, ctx.project, ctx.suiteId, sessionId, { comment: options.comment });
|
|
24
|
+
output_1.default.exitResult(json, session, (0, texts_1.TXT_VT_SESSION_UPDATED)(session.id, session.html_url));
|
|
25
|
+
});
|
|
26
|
+
exports.default = commandSessionUpdate;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.vtCommandOptions = vtCommandOptions;
|
|
7
|
+
exports.vtContextFlags = vtContextFlags;
|
|
8
|
+
exports.resolveVtApiContext = resolveVtApiContext;
|
|
9
|
+
exports.resolveVtSessionContext = resolveVtSessionContext;
|
|
10
|
+
exports.resolveVtSuiteToken = resolveVtSuiteToken;
|
|
11
|
+
exports.resolveVtProjectContext = resolveVtProjectContext;
|
|
12
|
+
const client_1 = __importDefault(require("../../../../api/client"));
|
|
13
|
+
const cliError_1 = __importDefault(require("../../../../cliError"));
|
|
14
|
+
const input_1 = __importDefault(require("../../../../input"));
|
|
15
|
+
const output_1 = __importDefault(require("../../../../output"));
|
|
16
|
+
const cfg_1 = __importDefault(require("../../../../project/cfg"));
|
|
17
|
+
const texts_1 = require("../../../../texts");
|
|
18
|
+
const utils_1 = require("../../../../utils");
|
|
19
|
+
function vtCommandOptions(command, { suite = true } = {}) {
|
|
20
|
+
command.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
21
|
+
command.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
22
|
+
if (suite)
|
|
23
|
+
command.option('-s, --suite <identifier>', texts_1.OPTION_VT_SUITE);
|
|
24
|
+
return command;
|
|
25
|
+
}
|
|
26
|
+
function vtContextFlags(options) {
|
|
27
|
+
let flags = '';
|
|
28
|
+
if (options.workspace)
|
|
29
|
+
flags += ` -w ${options.workspace}`;
|
|
30
|
+
if (options.project)
|
|
31
|
+
flags += ` -p ${options.project}`;
|
|
32
|
+
if (options.suite)
|
|
33
|
+
flags += ` -s ${options.suite}`;
|
|
34
|
+
const context = input_1.default.contextName();
|
|
35
|
+
if (context && context !== 'default')
|
|
36
|
+
flags += ` --context ${context}`;
|
|
37
|
+
return flags;
|
|
38
|
+
}
|
|
39
|
+
const authMissing = () => new cliError_1.default('unauthorized', texts_1.ERR_VT_AUTH_MISSING, texts_1.HINT_VT_AUTH);
|
|
40
|
+
function vtTokenApiHost(token) {
|
|
41
|
+
const parts = token.split('_');
|
|
42
|
+
if (parts.length === 4) {
|
|
43
|
+
const region = parts[2];
|
|
44
|
+
if (region === 'eu')
|
|
45
|
+
return { explicit: utils_1.REST_API_ENDPOINT.EU, derived: '' };
|
|
46
|
+
if (region === 'asia')
|
|
47
|
+
return { explicit: utils_1.REST_API_ENDPOINT.AS, derived: '' };
|
|
48
|
+
if (region === 'us')
|
|
49
|
+
return { explicit: utils_1.REST_API_ENDPOINT.US, derived: '' };
|
|
50
|
+
}
|
|
51
|
+
if (parts.length === 5) {
|
|
52
|
+
try {
|
|
53
|
+
const host = new URL(Buffer.from(parts[3], 'base64url').toString('utf8'))
|
|
54
|
+
.hostname;
|
|
55
|
+
if (host.startsWith('vt.')) {
|
|
56
|
+
return { explicit: '', derived: host.replace(/^vt\./, 'api.') };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// not a service url - nothing to derive
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { explicit: '', derived: '' };
|
|
64
|
+
}
|
|
65
|
+
async function contextFromSuiteToken(token) {
|
|
66
|
+
const { explicit, derived } = vtTokenApiHost(token);
|
|
67
|
+
const override = input_1.default.context()?.api || process.env.BUDDY_API_ENDPOINT;
|
|
68
|
+
const baseUrl = input_1.default.restApiBaseUrl(explicit || override || derived);
|
|
69
|
+
const suite = await new client_1.default(baseUrl, token).getVtSuiteContext();
|
|
70
|
+
return {
|
|
71
|
+
client: new client_1.default(baseUrl, suite.token),
|
|
72
|
+
workspace: suite.workspace_domain,
|
|
73
|
+
project: suite.project_name,
|
|
74
|
+
suiteId: suite.suite_id,
|
|
75
|
+
flags: '',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function restApiSuiteContext(options, hasFallback) {
|
|
79
|
+
if (!input_1.default.restApiToken(true).token)
|
|
80
|
+
return null;
|
|
81
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace, true);
|
|
82
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
83
|
+
const suite = options.suite || cfg_1.default.getVtSuite();
|
|
84
|
+
if (workspace && project && suite) {
|
|
85
|
+
const client = input_1.default.restApiTokenClient();
|
|
86
|
+
const { visual_test_suite_id: suiteId } = await client.getVtSuiteByIdentifier(workspace, project, suite);
|
|
87
|
+
const flags = vtContextFlags(options);
|
|
88
|
+
if (!suiteId) {
|
|
89
|
+
output_1.default.exitError(new cliError_1.default('not_found', (0, texts_1.ERR_VT_SUITE_NOT_FOUND)(suite), (0, texts_1.HINT_VT_SUITE_LIST)(vtContextFlags({ ...options, suite: '' }))));
|
|
90
|
+
}
|
|
91
|
+
return { client, workspace, project, suiteId: String(suiteId), flags };
|
|
92
|
+
}
|
|
93
|
+
if (!hasFallback) {
|
|
94
|
+
// Without allowNull these exit with the standard missing-workspace/project
|
|
95
|
+
// error and hint.
|
|
96
|
+
input_1.default.restApiWorkspace(options.workspace);
|
|
97
|
+
input_1.default.restApiProject(options.project || '');
|
|
98
|
+
output_1.default.exitError(new cliError_1.default('usage_error', texts_1.ERR_VT_SUITE_REQUIRED, texts_1.HINT_VT_SUITE_REQUIRED));
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
async function resolveVtApiContext(options) {
|
|
103
|
+
const suiteToken = process.env.BUDDY_VT_TOKEN;
|
|
104
|
+
const ctx = await restApiSuiteContext(options, Boolean(suiteToken));
|
|
105
|
+
if (ctx)
|
|
106
|
+
return ctx;
|
|
107
|
+
if (suiteToken)
|
|
108
|
+
return await contextFromSuiteToken(suiteToken);
|
|
109
|
+
output_1.default.exitError(authMissing());
|
|
110
|
+
}
|
|
111
|
+
const addressed = (options) => Boolean(options.workspace || options.project || options.suite);
|
|
112
|
+
async function resolveVtSessionContext(options) {
|
|
113
|
+
const suiteToken = process.env.BUDDY_VT_TOKEN;
|
|
114
|
+
if (suiteToken && !addressed(options)) {
|
|
115
|
+
return await contextFromSuiteToken(suiteToken);
|
|
116
|
+
}
|
|
117
|
+
return await resolveVtApiContext(options);
|
|
118
|
+
}
|
|
119
|
+
async function resolveVtSuiteToken(options) {
|
|
120
|
+
const suiteToken = process.env.BUDDY_VT_TOKEN;
|
|
121
|
+
if (suiteToken && !addressed(options))
|
|
122
|
+
return suiteToken;
|
|
123
|
+
const ctx = await restApiSuiteContext(options, Boolean(suiteToken));
|
|
124
|
+
if (ctx) {
|
|
125
|
+
const result = await ctx.client.getVtSuiteToken(ctx.workspace, ctx.project, ctx.suiteId);
|
|
126
|
+
if (result?.token)
|
|
127
|
+
return String(result.token);
|
|
128
|
+
output_1.default.exitError(texts_1.ERR_VT_SUITE_TOKEN_UNAVAILABLE);
|
|
129
|
+
}
|
|
130
|
+
if (suiteToken)
|
|
131
|
+
return suiteToken;
|
|
132
|
+
output_1.default.exitError(authMissing());
|
|
133
|
+
}
|
|
134
|
+
async function resolveVtProjectContext(options) {
|
|
135
|
+
if (input_1.default.restApiToken(true).token) {
|
|
136
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
137
|
+
const project = input_1.default.restApiProject(options.project || '');
|
|
138
|
+
return { client: input_1.default.restApiTokenClient(), workspace, project };
|
|
139
|
+
}
|
|
140
|
+
const suiteToken = process.env.BUDDY_VT_TOKEN;
|
|
141
|
+
if (suiteToken)
|
|
142
|
+
return await contextFromSuiteToken(suiteToken);
|
|
143
|
+
output_1.default.exitError(authMissing());
|
|
144
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vtDiffRegions = vtDiffRegions;
|
|
4
|
+
const GRID_CELL = 10;
|
|
5
|
+
const MAX_BOXES = 256;
|
|
6
|
+
/**
|
|
7
|
+
* A diff image is transparent where nothing changed. Changed pixels are
|
|
8
|
+
* opaque (red); pixels whose green channel is 255 mark ignored regions and
|
|
9
|
+
* do not count as changed.
|
|
10
|
+
*/
|
|
11
|
+
function vtDiffRegions(png) {
|
|
12
|
+
const { PNG } = require('pngjs');
|
|
13
|
+
const { width, height, data } = PNG.sync.read(png);
|
|
14
|
+
let grid = buildGrid(data, width, height);
|
|
15
|
+
let boxes = boxesFromGrid(grid);
|
|
16
|
+
while (boxes.length > MAX_BOXES) {
|
|
17
|
+
grid = coarsenGrid(grid);
|
|
18
|
+
boxes = boxesFromGrid(grid);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
diff_boxes: mergeOverlapping(boxes),
|
|
22
|
+
ignored_regions: findIgnoredRegions(data, width, height),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const isIgnored = (data, pixel) => data[pixel * 4 + 1] === 255;
|
|
26
|
+
// Each green area is grown right along its first scanline, then down while
|
|
27
|
+
// the whole span below stays green, so a rectangular area is one region.
|
|
28
|
+
function findIgnoredRegions(data, width, height) {
|
|
29
|
+
const taken = new Uint8Array(width * height);
|
|
30
|
+
const free = (pixel) => !taken[pixel] && isIgnored(data, pixel);
|
|
31
|
+
const regions = [];
|
|
32
|
+
for (let y = 0; y < height; y++) {
|
|
33
|
+
for (let x = 0; x < width; x++) {
|
|
34
|
+
if (!free(y * width + x))
|
|
35
|
+
continue;
|
|
36
|
+
let maxX = x;
|
|
37
|
+
while (maxX + 1 < width && free(y * width + maxX + 1))
|
|
38
|
+
maxX++;
|
|
39
|
+
let maxY = y;
|
|
40
|
+
const rowFree = (row) => {
|
|
41
|
+
for (let rx = x; rx <= maxX; rx++)
|
|
42
|
+
if (!free(row * width + rx))
|
|
43
|
+
return false;
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
while (maxY + 1 < height && rowFree(maxY + 1))
|
|
47
|
+
maxY++;
|
|
48
|
+
for (let ry = y; ry <= maxY; ry++)
|
|
49
|
+
taken.fill(1, ry * width + x, ry * width + maxX + 1);
|
|
50
|
+
regions.push({ x, y, width: maxX - x + 1, height: maxY - y + 1 });
|
|
51
|
+
x = maxX;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return regions;
|
|
55
|
+
}
|
|
56
|
+
function emptyGrid(cols, rows) {
|
|
57
|
+
return {
|
|
58
|
+
cols,
|
|
59
|
+
rows,
|
|
60
|
+
occupied: new Uint8Array(cols * rows),
|
|
61
|
+
minXs: new Int32Array(cols * rows),
|
|
62
|
+
maxXs: new Int32Array(cols * rows),
|
|
63
|
+
minYs: new Int32Array(cols * rows),
|
|
64
|
+
maxYs: new Int32Array(cols * rows),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function extendCell(grid, cell, minX, maxX, minY, maxY) {
|
|
68
|
+
if (!grid.occupied[cell]) {
|
|
69
|
+
grid.occupied[cell] = 1;
|
|
70
|
+
grid.minXs[cell] = minX;
|
|
71
|
+
grid.maxXs[cell] = maxX;
|
|
72
|
+
grid.minYs[cell] = minY;
|
|
73
|
+
grid.maxYs[cell] = maxY;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
grid.minXs[cell] = Math.min(grid.minXs[cell], minX);
|
|
77
|
+
grid.maxXs[cell] = Math.max(grid.maxXs[cell], maxX);
|
|
78
|
+
grid.minYs[cell] = Math.min(grid.minYs[cell], minY);
|
|
79
|
+
grid.maxYs[cell] = Math.max(grid.maxYs[cell], maxY);
|
|
80
|
+
}
|
|
81
|
+
function buildGrid(data, width, height) {
|
|
82
|
+
const grid = emptyGrid(Math.ceil(width / GRID_CELL), Math.ceil(height / GRID_CELL));
|
|
83
|
+
for (let y = 0; y < height; y++) {
|
|
84
|
+
const cellRow = Math.floor(y / GRID_CELL) * grid.cols;
|
|
85
|
+
for (let x = 0; x < width; x++) {
|
|
86
|
+
const pixel = y * width + x;
|
|
87
|
+
const changed = data[pixel * 4 + 3] !== 0 && !isIgnored(data, pixel);
|
|
88
|
+
if (changed)
|
|
89
|
+
extendCell(grid, cellRow + Math.floor(x / GRID_CELL), x, x, y, y);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return grid;
|
|
93
|
+
}
|
|
94
|
+
function coarsenGrid(grid) {
|
|
95
|
+
const coarse = emptyGrid(Math.ceil(grid.cols / 2), Math.ceil(grid.rows / 2));
|
|
96
|
+
for (let cellY = 0; cellY < grid.rows; cellY++) {
|
|
97
|
+
for (let cellX = 0; cellX < grid.cols; cellX++) {
|
|
98
|
+
const cell = cellY * grid.cols + cellX;
|
|
99
|
+
if (!grid.occupied[cell])
|
|
100
|
+
continue;
|
|
101
|
+
extendCell(coarse, (cellY >> 1) * coarse.cols + (cellX >> 1), grid.minXs[cell], grid.maxXs[cell], grid.minYs[cell], grid.maxYs[cell]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return coarse;
|
|
105
|
+
}
|
|
106
|
+
function boxesFromGrid(grid) {
|
|
107
|
+
const { cols, rows, occupied, minXs, maxXs, minYs, maxYs } = grid;
|
|
108
|
+
const visited = new Uint8Array(cols * rows);
|
|
109
|
+
const boxes = [];
|
|
110
|
+
const stack = [];
|
|
111
|
+
for (let start = 0; start < occupied.length; start++) {
|
|
112
|
+
if (!occupied[start] || visited[start])
|
|
113
|
+
continue;
|
|
114
|
+
visited[start] = 1;
|
|
115
|
+
stack.push(start);
|
|
116
|
+
let minX = Number.MAX_SAFE_INTEGER;
|
|
117
|
+
let maxX = 0;
|
|
118
|
+
let minY = Number.MAX_SAFE_INTEGER;
|
|
119
|
+
let maxY = 0;
|
|
120
|
+
while (stack.length > 0) {
|
|
121
|
+
const cell = stack.pop();
|
|
122
|
+
minX = Math.min(minX, minXs[cell]);
|
|
123
|
+
maxX = Math.max(maxX, maxXs[cell]);
|
|
124
|
+
minY = Math.min(minY, minYs[cell]);
|
|
125
|
+
maxY = Math.max(maxY, maxYs[cell]);
|
|
126
|
+
const cellX = cell % cols;
|
|
127
|
+
const cellY = (cell - cellX) / cols;
|
|
128
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
129
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
130
|
+
const x = cellX + dx;
|
|
131
|
+
const y = cellY + dy;
|
|
132
|
+
if (x < 0 || x >= cols || y < 0 || y >= rows)
|
|
133
|
+
continue;
|
|
134
|
+
const neighbor = y * cols + x;
|
|
135
|
+
if (occupied[neighbor] && !visited[neighbor]) {
|
|
136
|
+
visited[neighbor] = 1;
|
|
137
|
+
stack.push(neighbor);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
boxes.push({ x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1 });
|
|
143
|
+
}
|
|
144
|
+
return boxes;
|
|
145
|
+
}
|
|
146
|
+
function mergeOverlapping(boxes) {
|
|
147
|
+
let merged = boxes;
|
|
148
|
+
let changed = true;
|
|
149
|
+
while (changed) {
|
|
150
|
+
changed = false;
|
|
151
|
+
const kept = [];
|
|
152
|
+
for (const box of merged) {
|
|
153
|
+
const other = kept.find((k) => k.x < box.x + box.width &&
|
|
154
|
+
box.x < k.x + k.width &&
|
|
155
|
+
k.y < box.y + box.height &&
|
|
156
|
+
box.y < k.y + k.height);
|
|
157
|
+
if (!other) {
|
|
158
|
+
kept.push(box);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const right = Math.max(other.x + other.width, box.x + box.width);
|
|
162
|
+
const bottom = Math.max(other.y + other.height, box.y + box.height);
|
|
163
|
+
other.x = Math.min(other.x, box.x);
|
|
164
|
+
other.y = Math.min(other.y, box.y);
|
|
165
|
+
other.width = right - other.x;
|
|
166
|
+
other.height = bottom - other.y;
|
|
167
|
+
changed = true;
|
|
168
|
+
}
|
|
169
|
+
merged = kept;
|
|
170
|
+
}
|
|
171
|
+
return merged;
|
|
172
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatVtDate = formatVtDate;
|
|
4
|
+
exports.formatVtFlag = formatVtFlag;
|
|
5
|
+
exports.dash = dash;
|
|
6
|
+
// API timestamps are epoch milliseconds; tolerate seconds just in case.
|
|
7
|
+
function formatVtDate(timestamp) {
|
|
8
|
+
if (!timestamp)
|
|
9
|
+
return '-';
|
|
10
|
+
const ms = timestamp < 1e11 ? timestamp * 1000 : timestamp;
|
|
11
|
+
return new Date(ms).toISOString();
|
|
12
|
+
}
|
|
13
|
+
function formatVtFlag(value) {
|
|
14
|
+
return value ? 'true' : 'false';
|
|
15
|
+
}
|
|
16
|
+
// Detail views print '-' for anything the API left out or empty.
|
|
17
|
+
function dash(value) {
|
|
18
|
+
return value === undefined || value === null || value === ''
|
|
19
|
+
? '-'
|
|
20
|
+
: String(value);
|
|
21
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getVtSessionOrExit = getVtSessionOrExit;
|
|
7
|
+
exports.getVtSnapshotOrExit = getVtSnapshotOrExit;
|
|
8
|
+
exports.vtResultFileOrExit = vtResultFileOrExit;
|
|
9
|
+
exports.vtSessionResult = vtSessionResult;
|
|
10
|
+
exports.fetchVtPages = fetchVtPages;
|
|
11
|
+
exports.fetchAllVtSnapshots = fetchAllVtSnapshots;
|
|
12
|
+
exports.vtPagingNote = vtPagingNote;
|
|
13
|
+
const cliError_1 = __importDefault(require("../../../../cliError"));
|
|
14
|
+
const output_1 = __importDefault(require("../../../../output"));
|
|
15
|
+
const texts_1 = require("../../../../texts");
|
|
16
|
+
const context_1 = require("./context");
|
|
17
|
+
const utils_1 = require("../../../../utils");
|
|
18
|
+
const isNotFound = (err) => err instanceof cliError_1.default && err.code === 'not_found';
|
|
19
|
+
async function getVtSessionOrExit(ctx, sessionId) {
|
|
20
|
+
try {
|
|
21
|
+
return await ctx.client.getVtSession(ctx.workspace, ctx.project, ctx.suiteId, sessionId);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (isNotFound(err)) {
|
|
25
|
+
output_1.default.exitError(new cliError_1.default('not_found', (0, texts_1.ERR_VT_SESSION_NOT_FOUND)(sessionId), (0, texts_1.HINT_VT_SESSION_LIST)(ctx.flags)));
|
|
26
|
+
}
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function getVtSnapshotOrExit(ctx, sessionId, snapshotId) {
|
|
31
|
+
if (snapshotId.includes('/')) {
|
|
32
|
+
output_1.default.exitError(new cliError_1.default('usage_error', (0, texts_1.ERR_VT_SNAPSHOT_ID_IS_NAME)(snapshotId), (0, texts_1.HINT_VT_SNAPSHOT_ID_FROM_NAME)(sessionId, snapshotId, ctx.flags)));
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return await ctx.client.getVtSnapshot(ctx.workspace, ctx.project, ctx.suiteId, sessionId, snapshotId);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (isNotFound(err)) {
|
|
39
|
+
output_1.default.exitError(new cliError_1.default('not_found', (0, texts_1.ERR_VT_SNAPSHOT_NOT_FOUND)(sessionId, snapshotId), (0, texts_1.HINT_VT_SNAPSHOT_LIST)(sessionId, ctx.flags)));
|
|
40
|
+
}
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// The file server answers a missing path with its own wording
|
|
45
|
+
// ("File server error (code: 9): path not exists"); callers get one message
|
|
46
|
+
// naming the path and the folder to list instead.
|
|
47
|
+
async function vtResultFileOrExit(request, sessionId, path, options) {
|
|
48
|
+
try {
|
|
49
|
+
return await request();
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (isNotFound(err) ||
|
|
53
|
+
(err instanceof Error && /path not exists|not found/i.test(err.message))) {
|
|
54
|
+
output_1.default.exitError(new cliError_1.default('not_found', (0, texts_1.ERR_VT_RESULT_PATH_NOT_FOUND)(path), (0, texts_1.HINT_VT_RESULT_LIST)(sessionId, path, (0, context_1.vtContextFlags)(options))));
|
|
55
|
+
}
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Results are stored in the suite artifact once the session finishes; a
|
|
60
|
+
// running session is told apart so the user is not sent to look for a file
|
|
61
|
+
// that does not exist yet.
|
|
62
|
+
function vtSessionResult(session, ctx) {
|
|
63
|
+
if (session.status === utils_1.VT_SESSION_STATUS.IN_PROGRESS) {
|
|
64
|
+
output_1.default.exitError(new cliError_1.default('command_failed', (0, texts_1.ERR_VT_SESSION_IN_PROGRESS)(session.id), (0, texts_1.HINT_VT_SESSION_GET)(session.id, ctx.flags)));
|
|
65
|
+
}
|
|
66
|
+
const result = session.result;
|
|
67
|
+
if (!result?.artifact_id || !result?.version_id) {
|
|
68
|
+
output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_VT_SESSION_NO_RESULTS));
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Runs a paged list call for one page, or - with `all` - for every page,
|
|
74
|
+
* returning one envelope whose items are merged. Warns when the API served a
|
|
75
|
+
* smaller page than requested, since a caller that skips paging would miss
|
|
76
|
+
* items.
|
|
77
|
+
*/
|
|
78
|
+
async function fetchVtPages(key, page, perPage, all, request) {
|
|
79
|
+
let current = await request(all ? 1 : page);
|
|
80
|
+
if (current.page_size && current.page_size < perPage && current[key].length) {
|
|
81
|
+
output_1.default.noteWarning((0, texts_1.WARN_VT_PER_PAGE_CLAMPED)(perPage, current.page_size));
|
|
82
|
+
}
|
|
83
|
+
if (!all)
|
|
84
|
+
return current;
|
|
85
|
+
const items = [...current[key]];
|
|
86
|
+
for (let p = 2; p <= (current.total_page_count || 1); p += 1) {
|
|
87
|
+
current = await request(p);
|
|
88
|
+
items.push(...current[key]);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
...current,
|
|
92
|
+
page: 1,
|
|
93
|
+
page_size: items.length,
|
|
94
|
+
total_page_count: 1,
|
|
95
|
+
element_count: items.length,
|
|
96
|
+
total_element_count: current.total_element_count ?? items.length,
|
|
97
|
+
[key]: items,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// Every snapshot of a session, all pages.
|
|
101
|
+
async function fetchAllVtSnapshots(ctx, sessionId) {
|
|
102
|
+
const view = await fetchVtPages('snapshots', 1, 100, true, (page) => ctx.client.getVtSnapshots(ctx.workspace, ctx.project, ctx.suiteId, sessionId, { page, per_page: 100 }));
|
|
103
|
+
return view.snapshots || [];
|
|
104
|
+
}
|
|
105
|
+
function vtPagingNote(view, shown) {
|
|
106
|
+
output_1.default.note((0, texts_1.TXT_VT_PAGING)(view.page || 1, view.total_page_count || 1, shown, view.total_element_count ?? shown));
|
|
107
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.vtSnapshotReviewUrlOptions = exports.vtSuiteUpdateOptions = exports.vtSnapshotListOptions = exports.vtSessionListOptions = void 0;
|
|
7
|
+
exports.parseVtOptions = parseVtOptions;
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const cliError_1 = __importDefault(require("../../../../cliError"));
|
|
10
|
+
const output_1 = __importDefault(require("../../../../output"));
|
|
11
|
+
const input_1 = __importDefault(require("../../../../input"));
|
|
12
|
+
const texts_1 = require("../../../../texts");
|
|
13
|
+
const utils_1 = require("../../../../utils");
|
|
14
|
+
/**
|
|
15
|
+
* Validates commander's raw option values (strings) for a visual test command.
|
|
16
|
+
* Unknown keys (-w/-p/-s, --format, which commander checks itself) are
|
|
17
|
+
* dropped; callers keep using the raw `options` for those and this result for
|
|
18
|
+
* everything validated.
|
|
19
|
+
*/
|
|
20
|
+
function parseVtOptions(schema, options) {
|
|
21
|
+
const result = schema.safeParse(options);
|
|
22
|
+
if (result.success)
|
|
23
|
+
return result.data;
|
|
24
|
+
output_1.default.exitError(new cliError_1.default('usage_error', result.error.issues.map((e) => e.message).join(', ')));
|
|
25
|
+
}
|
|
26
|
+
const upperCased = (value) => typeof value === 'string' ? value.toUpperCase() : value;
|
|
27
|
+
const lowerCased = (value) => typeof value === 'string' ? value.toLowerCase() : value;
|
|
28
|
+
// Case-insensitive member of a string enum.
|
|
29
|
+
function enumOf(values, message) {
|
|
30
|
+
return zod_1.z.preprocess(upperCased, zod_1.z.enum(values, { error: message }));
|
|
31
|
+
}
|
|
32
|
+
// Same rule as Input.restApiPage: digits only, no sign, no leading zero.
|
|
33
|
+
function positiveInt(message) {
|
|
34
|
+
return zod_1.z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(/^[1-9]\d*$/, { message })
|
|
37
|
+
.transform(Number)
|
|
38
|
+
.refine(Number.isSafeInteger, { message });
|
|
39
|
+
}
|
|
40
|
+
// A number typed on the command line: '' and 'abc' are refused, not coerced.
|
|
41
|
+
function numberFrom(message, check) {
|
|
42
|
+
return zod_1.z
|
|
43
|
+
.string()
|
|
44
|
+
.trim()
|
|
45
|
+
.min(1, { message })
|
|
46
|
+
.transform(Number)
|
|
47
|
+
.pipe(check(zod_1.z.number({ error: message })));
|
|
48
|
+
}
|
|
49
|
+
// `--flag true|false`; the option name is only used for the error message.
|
|
50
|
+
function booleanFrom(option) {
|
|
51
|
+
return zod_1.z.preprocess(lowerCased, zod_1.z
|
|
52
|
+
.enum(['true', 'false'], { error: (0, texts_1.ERR_VT_BOOLEAN)(option) })
|
|
53
|
+
.transform((v) => v === 'true'));
|
|
54
|
+
}
|
|
55
|
+
const paging = {
|
|
56
|
+
page: positiveInt(texts_1.ERR_REST_API_PAGE),
|
|
57
|
+
perPage: positiveInt(texts_1.ERR_VT_PER_PAGE).refine((n) => n <= 100, {
|
|
58
|
+
message: texts_1.ERR_VT_PER_PAGE,
|
|
59
|
+
}),
|
|
60
|
+
all: zod_1.z.boolean().optional(),
|
|
61
|
+
};
|
|
62
|
+
exports.vtSessionListOptions = zod_1.z.object({
|
|
63
|
+
...paging,
|
|
64
|
+
branch: zod_1.z.string().optional(),
|
|
65
|
+
tag: zod_1.z.string().optional(),
|
|
66
|
+
revision: zod_1.z.string().optional(),
|
|
67
|
+
pullRequest: positiveInt(texts_1.ERR_VT_PULL_REQUEST).optional(),
|
|
68
|
+
status: enumOf(utils_1.VT_SESSION_STATUS, texts_1.ERR_VT_SESSION_STATUS).optional(),
|
|
69
|
+
});
|
|
70
|
+
exports.vtSnapshotListOptions = zod_1.z.object({
|
|
71
|
+
...paging,
|
|
72
|
+
name: zod_1.z.string().optional(),
|
|
73
|
+
status: enumOf(utils_1.VT_SNAPSHOT_STATUS, texts_1.ERR_VT_SNAPSHOT_STATUS).optional(),
|
|
74
|
+
});
|
|
75
|
+
exports.vtSuiteUpdateOptions = zod_1.z.object({
|
|
76
|
+
name: zod_1.z.string().optional(),
|
|
77
|
+
baseBranch: zod_1.z.string().optional(),
|
|
78
|
+
threshold: numberFrom(texts_1.ERR_VT_THRESHOLD, (n) => n.min(0, { message: texts_1.ERR_VT_THRESHOLD }).max(1, { message: texts_1.ERR_VT_THRESHOLD })).optional(),
|
|
79
|
+
timeout: positiveInt(texts_1.ERR_VT_TIMEOUT).optional(),
|
|
80
|
+
enableJavascript: booleanFrom('--enable-javascript').optional(),
|
|
81
|
+
fullPage: booleanFrom('--full-page').optional(),
|
|
82
|
+
autoApprovedWildcard: zod_1.z.string().optional(),
|
|
83
|
+
ignoredSnapshots: zod_1.z.string().transform(input_1.default.tags).optional(),
|
|
84
|
+
});
|
|
85
|
+
exports.vtSnapshotReviewUrlOptions = zod_1.z.object({
|
|
86
|
+
browser: enumOf(utils_1.VT_BROWSER, texts_1.ERR_VT_BROWSER).optional(),
|
|
87
|
+
width: positiveInt(texts_1.ERR_VT_REVIEW_WIDTH).optional(),
|
|
88
|
+
scale: numberFrom(texts_1.ERR_VT_REVIEW_SCALE, (n) => n.positive({ message: texts_1.ERR_VT_REVIEW_SCALE })).optional(),
|
|
89
|
+
colorScheme: enumOf(utils_1.VT_COLOR_SCHEME, texts_1.ERR_VT_COLOR_SCHEME).optional(),
|
|
90
|
+
});
|