bdy 1.25.38-dev-pr → 1.25.38-master

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.
Files changed (103) hide show
  1. package/distTs/package.json +1 -2
  2. package/distTs/src/api/client.js +1 -191
  3. package/distTs/src/cliError.js +0 -5
  4. package/distTs/src/cliIndex.js +0 -3
  5. package/distTs/src/command/login.js +1 -1
  6. package/distTs/src/output/pipeline.js +56 -54
  7. package/distTs/src/output.js +22 -72
  8. package/distTs/src/texts.js +1 -450
  9. package/distTs/src/tunnel/output/interactive/tunnel.js +10 -14
  10. package/distTs/src/tunnel/output/noninteractive/tunnel.js +1 -3
  11. package/distTs/src/utils.js +3 -133
  12. package/package.json +1 -2
  13. package/distTs/src/autocomplete.js +0 -90
  14. package/distTs/src/command/artifact/downloadDir.js +0 -110
  15. package/distTs/src/command/autocomplete/install.js +0 -16
  16. package/distTs/src/command/autocomplete/uninstall.js +0 -16
  17. package/distTs/src/command/autocomplete.js +0 -14
  18. package/distTs/src/command/environment/resolve.js +0 -39
  19. package/distTs/src/command/package/create.js +0 -64
  20. package/distTs/src/command/package/delete.js +0 -38
  21. package/distTs/src/command/package/docker/login.js +0 -26
  22. package/distTs/src/command/package/docker.js +0 -11
  23. package/distTs/src/command/package/download.js +0 -138
  24. package/distTs/src/command/package/get.js +0 -36
  25. package/distTs/src/command/package/list.js +0 -31
  26. package/distTs/src/command/package/publish.js +0 -241
  27. package/distTs/src/command/package/version/delete.js +0 -39
  28. package/distTs/src/command/package/version/get.js +0 -45
  29. package/distTs/src/command/package/version/list.js +0 -47
  30. package/distTs/src/command/package/version.js +0 -16
  31. package/distTs/src/command/package.js +0 -26
  32. package/distTs/src/command/pipeline/run/apply.js +0 -62
  33. package/distTs/src/command/pr/comment/add.js +0 -66
  34. package/distTs/src/command/pr/comment/list.js +0 -169
  35. package/distTs/src/command/pr/comment/status.js +0 -48
  36. package/distTs/src/command/pr/comment.js +0 -19
  37. package/distTs/src/command/pr/create.js +0 -43
  38. package/distTs/src/command/pr/diff.js +0 -227
  39. package/distTs/src/command/pr/file/list.js +0 -124
  40. package/distTs/src/command/pr/file/mark.js +0 -45
  41. package/distTs/src/command/pr/file.js +0 -16
  42. package/distTs/src/command/pr/get.js +0 -29
  43. package/distTs/src/command/pr/list.js +0 -79
  44. package/distTs/src/command/pr/merge.js +0 -66
  45. package/distTs/src/command/pr/review/request.js +0 -29
  46. package/distTs/src/command/pr/review/start.js +0 -29
  47. package/distTs/src/command/pr/review/verdict.js +0 -81
  48. package/distTs/src/command/pr/review.js +0 -18
  49. package/distTs/src/command/pr/shared.js +0 -595
  50. package/distTs/src/command/pr/state.js +0 -38
  51. package/distTs/src/command/pr/summary.js +0 -316
  52. package/distTs/src/command/pr/update.js +0 -54
  53. package/distTs/src/command/pr/updateBranch.js +0 -22
  54. package/distTs/src/command/pr/versions.js +0 -42
  55. package/distTs/src/command/pr.js +0 -39
  56. package/distTs/src/command/scrape/validation.js +0 -154
  57. package/distTs/src/command/scrape.js +0 -144
  58. package/distTs/src/command/suiteLink.js +0 -14
  59. package/distTs/src/command/tests/visual/result/download.js +0 -31
  60. package/distTs/src/command/tests/visual/result/get.js +0 -68
  61. package/distTs/src/command/tests/visual/result/list.js +0 -49
  62. package/distTs/src/command/tests/visual/result.js +0 -23
  63. package/distTs/src/command/tests/visual/session/get.js +0 -70
  64. package/distTs/src/command/tests/visual/session/list.js +0 -69
  65. package/distTs/src/command/tests/visual/session/open.js +0 -22
  66. package/distTs/src/command/tests/visual/session/reviewUrl.js +0 -37
  67. package/distTs/src/command/tests/visual/session/update.js +0 -26
  68. package/distTs/src/command/tests/visual/shared/context.js +0 -144
  69. package/distTs/src/command/tests/visual/shared/diffRegions.js +0 -172
  70. package/distTs/src/command/tests/visual/shared/format.js +0 -21
  71. package/distTs/src/command/tests/visual/shared/lookup.js +0 -107
  72. package/distTs/src/command/tests/visual/shared/options.js +0 -90
  73. package/distTs/src/command/tests/visual/shared/review.js +0 -146
  74. package/distTs/src/command/tests/visual/shared/reviewUrl.js +0 -62
  75. package/distTs/src/command/tests/visual/shared/session.js +0 -217
  76. package/distTs/src/command/tests/visual/snapshot/get.js +0 -46
  77. package/distTs/src/command/tests/visual/snapshot/list.js +0 -68
  78. package/distTs/src/command/tests/visual/snapshot/open.js +0 -26
  79. package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +0 -48
  80. package/distTs/src/command/tests/visual/snapshot.js +0 -28
  81. package/distTs/src/command/tests/visual/suite/create.js +0 -38
  82. package/distTs/src/command/tests/visual/suite/delete.js +0 -29
  83. package/distTs/src/command/tests/visual/suite/get.js +0 -43
  84. package/distTs/src/command/tests/visual/suite/list.js +0 -35
  85. package/distTs/src/command/tests/visual/suite/open.js +0 -20
  86. package/distTs/src/command/tests/visual/suite/update.js +0 -47
  87. package/distTs/src/command/tests/visual/suite.js +0 -30
  88. package/distTs/src/command/ut/upload.js +0 -86
  89. package/distTs/src/command/ut.js +0 -12
  90. package/distTs/src/command/vt/close.js +0 -27
  91. package/distTs/src/command/vt/compare/validation.js +0 -46
  92. package/distTs/src/command/vt/compare.js +0 -100
  93. package/distTs/src/command/vt/exec.js +0 -82
  94. package/distTs/src/command/vt/installBrowser.js +0 -20
  95. package/distTs/src/command/vt/shared/validation.js +0 -145
  96. package/distTs/src/command/vt/storybook.js +0 -138
  97. package/distTs/src/command/vt.js +0 -20
  98. package/distTs/src/command/yaml/agents.js +0 -88
  99. package/distTs/src/command/yaml/init.js +0 -110
  100. package/distTs/src/main.js +0 -190
  101. package/distTs/src/types/options.js +0 -2
  102. package/distTs/src/types/scrape.js +0 -2
  103. package/distTs/src/types/visualTests.js +0 -2
@@ -1,144 +0,0 @@
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
- }
@@ -1,172 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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
- }
@@ -1,107 +0,0 @@
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
- }
@@ -1,90 +0,0 @@
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
- });
@@ -1,146 +0,0 @@
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.vtReviewCommands = vtReviewCommands;
7
- const cliError_1 = __importDefault(require("../../../../cliError"));
8
- const output_1 = __importDefault(require("../../../../output"));
9
- const utils_1 = require("../../../../utils");
10
- const texts_1 = require("../../../../texts");
11
- const context_1 = require("./context");
12
- const lookup_1 = require("./lookup");
13
- // Mirrors the backend's per-snapshot validation (UpdateSnapshotStatusCommand):
14
- // the API rejects the whole batch if any member cannot legally change, so the
15
- // CLI only ever sends snapshots that will pass.
16
- function skipReason(snapshot, target) {
17
- if (snapshot.status === target)
18
- return 'already';
19
- if (target === utils_1.VT_SNAPSHOT_STATUS.WAITING_FOR_APPROVE &&
20
- snapshot.auto_approved) {
21
- return 'auto-approved';
22
- }
23
- if (snapshot.status === utils_1.VT_SNAPSHOT_STATUS.IN_PROGRESS ||
24
- snapshot.status === utils_1.VT_SNAPSHOT_STATUS.ERROR) {
25
- return 'in-progress-or-error';
26
- }
27
- if (snapshot.used_as_baseline)
28
- return 'baseline';
29
- return null;
30
- }
31
- const ACTIONS = {
32
- [utils_1.VT_SNAPSHOT_STATUS.APPROVED]: { verb: 'approve', done: 'Approved' },
33
- [utils_1.VT_SNAPSHOT_STATUS.REJECTED]: { verb: 'reject', done: 'Rejected' },
34
- [utils_1.VT_SNAPSHOT_STATUS.WAITING_FOR_APPROVE]: {
35
- verb: 'unreview',
36
- done: 'Unreviewed',
37
- },
38
- };
39
- function pickSnapshots(all, ids, sessionId, flags) {
40
- const byId = new Map(all.map((s) => [s.id, s]));
41
- const missing = ids.filter((id) => !byId.has(id));
42
- if (missing.length) {
43
- output_1.default.exitError(new cliError_1.default('not_found', (0, texts_1.ERR_VT_REVIEW_NOT_FOUND)(missing), (0, texts_1.HINT_VT_SNAPSHOT_LIST)(sessionId, flags)));
44
- }
45
- return ids.map((id) => byId.get(id));
46
- }
47
- /**
48
- * Splits the candidate snapshots into ones that can move to `target` and ones
49
- * to skip (with the reason), sends the bulk update and reports the resulting
50
- * session status. `snapshotIds` limits the candidates to the named snapshots;
51
- * without it every snapshot of the session is a candidate. The JSON result is
52
- * assembled by the CLI: the bulk endpoint returns only the changed snapshots
53
- * and says nothing about the skipped ones or the session.
54
- */
55
- async function review(sessionId, snapshotIds, target, options) {
56
- const json = options.format === 'json';
57
- const ctx = await (0, context_1.resolveVtApiContext)(options);
58
- const before = await (0, lookup_1.getVtSessionOrExit)(ctx, sessionId);
59
- const all = await (0, lookup_1.fetchAllVtSnapshots)(ctx, sessionId);
60
- const candidates = snapshotIds
61
- ? pickSnapshots(all, snapshotIds, sessionId, ctx.flags)
62
- : all;
63
- const eligible = [];
64
- const skipped = new Map();
65
- for (const snapshot of candidates) {
66
- const reason = skipReason(snapshot, target);
67
- if (reason) {
68
- const ids = skipped.get(reason) || [];
69
- ids.push(snapshot.id);
70
- skipped.set(reason, ids);
71
- }
72
- else {
73
- eligible.push(snapshot);
74
- }
75
- }
76
- const summary = (updated, sessionStatus) => ({
77
- session_id: sessionId,
78
- status: target,
79
- updated: updated.map((s) => s.id),
80
- skipped: [...skipped].flatMap(([reason, ids]) => ids.map((id) => ({ id, reason }))),
81
- session_status: sessionStatus,
82
- });
83
- // Named snapshots are echoed back; a whole session would be dozens of ids.
84
- if (!json) {
85
- for (const [reason, ids] of skipped) {
86
- output_1.default.note((0, texts_1.TXT_VT_REVIEW_SKIPPED)(texts_1.VT_REVIEW_SKIP_REASON[reason], ids, snapshotIds !== null));
87
- }
88
- }
89
- const action = ACTIONS[target];
90
- if (!eligible.length) {
91
- if (json)
92
- output_1.default.exitResult(json, summary([], before.status));
93
- output_1.default.exitNormal((0, texts_1.ERR_VT_REVIEW_NOTHING_ELIGIBLE)(action.verb));
94
- }
95
- await ctx.client.updateVtSnapshotsStatuses(ctx.workspace, ctx.project, ctx.suiteId, sessionId, { snapshot_ids: eligible.map((s) => s.id), status: target });
96
- // The bulk response only carries the changed snapshots; refetch the session
97
- // to report its recomputed status.
98
- const session = await (0, lookup_1.getVtSessionOrExit)(ctx, sessionId);
99
- output_1.default.exitResult(json, summary(eligible, session.status), (0, texts_1.TXT_VT_REVIEW_DONE)(action.done, eligible.length, session.status));
100
- }
101
- const TARGETS = {
102
- approve: utils_1.VT_SNAPSHOT_STATUS.APPROVED,
103
- reject: utils_1.VT_SNAPSHOT_STATUS.REJECTED,
104
- unreview: utils_1.VT_SNAPSHOT_STATUS.WAITING_FOR_APPROVE,
105
- };
106
- const DESCRIPTIONS = {
107
- session: {
108
- approve: texts_1.DESC_COMMAND_SESSION_APPROVE,
109
- reject: texts_1.DESC_COMMAND_SESSION_REJECT,
110
- unreview: texts_1.DESC_COMMAND_SESSION_UNREVIEW,
111
- },
112
- snapshot: {
113
- approve: texts_1.DESC_COMMAND_VT_SNAPSHOT_APPROVE,
114
- reject: texts_1.DESC_COMMAND_VT_SNAPSHOT_REJECT,
115
- unreview: texts_1.DESC_COMMAND_VT_SNAPSHOT_UNREVIEW,
116
- },
117
- };
118
- const EXAMPLES = {
119
- session: texts_1.EXAMPLE_TESTS_VISUAL_SESSION_APPROVE,
120
- snapshot: texts_1.EXAMPLE_TESTS_VISUAL_SNAPSHOT_APPROVE,
121
- };
122
- /**
123
- * The approve, reject and unreview commands of one group (unreview puts
124
- * snapshots back to WAITING_FOR_APPROVE). The snapshot group takes the
125
- * snapshot ids to act on; the session group acts on every snapshot of the
126
- * session, since a session has no status endpoint of its own and the API
127
- * recomputes its status from the snapshots.
128
- */
129
- function vtReviewCommands(scope) {
130
- const names = ['approve', 'reject', 'unreview'];
131
- return names.map((name) => reviewCommand(name, DESCRIPTIONS[scope][name], EXAMPLES[scope], TARGETS[name], scope === 'snapshot'));
132
- }
133
- function reviewCommand(name, description, examples, target, withSnapshotIds) {
134
- const command = (0, utils_1.newCommand)(name, description, { examples });
135
- (0, context_1.vtCommandOptions)(command);
136
- command.option('--format <text|json>', texts_1.OPTION_FORMAT);
137
- command.argument('<session-id>', texts_1.OPTION_VT_SESSION_ID);
138
- if (withSnapshotIds) {
139
- command.argument('<snapshot-ids...>', texts_1.OPTION_VT_SNAPSHOT_IDS);
140
- command.action((sessionId, snapshotIds, options) => review(sessionId, snapshotIds, target, options));
141
- }
142
- else {
143
- command.action((sessionId, options) => review(sessionId, null, target, options));
144
- }
145
- return command;
146
- }