@toloka-platform/sdk 0.26.0 → 0.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/toloka.js +178 -176
- package/dist/cli/toloka.js.jsc +0 -0
- package/dist/cli/toloka.js.jsc.sha256 +1 -1
- package/dist/cli/toloka.js.sha256 +1 -1
- package/package.json +2 -2
- package/skills/catalog.json +6 -6
- package/skills/toloka-build/SKILL.md +9 -7
- package/skills/toloka-build/references/workflow-and-cli.md +6 -6
- package/src/cli/check.ts +60 -30
- package/src/cli/commands/source.ts +14 -6
- package/src/cli/pipeline-selector.ts +68 -0
- package/src/cli/poll.ts +26 -0
- package/src/cli/project.ts +63 -50
- package/src/cli/runs.ts +22 -14
- package/src/cli/source.ts +16 -2
package/dist/cli/toloka.js.jsc
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
41ea5ed778785de3bc1c7d7afc22672e77a8a9cd390e96c24b1cf6bc9696b0f6 toloka.js.jsc
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
9f8d3ba912063ce04cf5a16fc76889223c36d33646678072c37a426b1c178b31 toloka.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toloka-platform/sdk",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Build, inspect, and operate Toloka pipeline projects as TypeScript source. The public API may change between minor versions before 1.0.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -78,6 +78,6 @@
|
|
|
78
78
|
"bun": ">=1.4.0"
|
|
79
79
|
},
|
|
80
80
|
"tolokaBuild": {
|
|
81
|
-
"commit": "
|
|
81
|
+
"commit": "760207ffdf03139ad90ac44acec02779a575bb10"
|
|
82
82
|
}
|
|
83
83
|
}
|
package/skills/catalog.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"testing",
|
|
12
12
|
"checks"
|
|
13
13
|
],
|
|
14
|
-
"version": "0.26.
|
|
15
|
-
"digest": "
|
|
14
|
+
"version": "0.26.2",
|
|
15
|
+
"digest": "9207bbd632069a209a588b711a40c7e8bddb44c25775cfebee5068cc8c86b11c",
|
|
16
16
|
"files": [
|
|
17
17
|
"SKILL.md",
|
|
18
18
|
"references/human-work.md",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"bug",
|
|
34
34
|
"report"
|
|
35
35
|
],
|
|
36
|
-
"version": "0.26.
|
|
36
|
+
"version": "0.26.2",
|
|
37
37
|
"digest": "70f0bd2c80b32f87896aeb27c363b8a2d37f40e22424f57fe1aad142e125ad67",
|
|
38
38
|
"files": [
|
|
39
39
|
"SKILL.md",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"getting-started",
|
|
51
51
|
"agent"
|
|
52
52
|
],
|
|
53
|
-
"version": "0.26.
|
|
53
|
+
"version": "0.26.2",
|
|
54
54
|
"digest": "2278adeb46a792356579395fcf73c42322cb23bcd0c61e20856ccabdad6762d1",
|
|
55
55
|
"files": [
|
|
56
56
|
"SKILL.md"
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"sft",
|
|
68
68
|
"models"
|
|
69
69
|
],
|
|
70
|
-
"version": "0.26.
|
|
70
|
+
"version": "0.26.2",
|
|
71
71
|
"digest": "3ce10dee5d3c283d8b5fdea15134a58fc738c7af2c1bb19eb5a0bf70ea0bca13",
|
|
72
72
|
"files": [
|
|
73
73
|
"SKILL.md"
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"prompt",
|
|
85
85
|
"models"
|
|
86
86
|
],
|
|
87
|
-
"version": "0.26.
|
|
87
|
+
"version": "0.26.2",
|
|
88
88
|
"digest": "be8bce8d9cf7241ccb60d2b2a9b7cc07d7755a76e8ff8ec1b0847c49efbb3469",
|
|
89
89
|
"files": [
|
|
90
90
|
"SKILL.md"
|
|
@@ -34,10 +34,12 @@ For an applied change, the dependencies are read → edit → check/validate →
|
|
|
34
34
|
|
|
35
35
|
1. Read `toloka.json` when present, then read the relevant `pipelines/**/pipeline.ts` module and everything it imports.
|
|
36
36
|
2. Edit the TypeScript source. Treat it as authoritative desired state.
|
|
37
|
-
3. Iterate with `toloka check <pipeline> --node <name-or-id>` while you edit. `toloka apply
|
|
38
|
-
4. Run `toloka plan
|
|
39
|
-
5. Run `toloka apply && toloka validate --wait` as one command when the changes match the requested work. Apply reruns the
|
|
40
|
-
6. Act on the source/spec errors and lint findings `toloka validate --wait` reports.
|
|
37
|
+
3. Iterate with `toloka check <pipeline> --node <name-or-id>` while you edit. `toloka apply <pipeline>` runs the local gate of that pipeline: do not run `toloka check <pipeline>` separately right before it.
|
|
38
|
+
4. Run `toloka plan <pipeline>` when you need to review the diff without applying it, such as for a change that may reach beyond the request. Resolve every conflict or missing prerequisite it reports.
|
|
39
|
+
5. Run `toloka apply <pipeline> && toloka validate <pipeline> --wait` as one command when the changes match the requested work. Apply reruns the local gate of the pipelines it applies and writes nothing when it fails, prints the plan it applies before writing, and prints the plan again after writing, which must say `No changes.`; when it does not converge it says so and exits 1. It holds back a pipeline whose plan removes a node or graph field (a rewired connection is applied), lists what it skipped, and exits 1: resolve removals, immutable-field conflicts, or changes outside the scope with the user first, then run `toloka apply <pipeline> --allow-removals` with the same pipelines, or pass it from the start when the user asked for the removal. Never retry a selected apply without its pipelines: that would also remove nodes and fields the user has not seen in every other pipeline whose source is behind the platform. It never asks for confirmation.
|
|
40
|
+
6. Act on the source/spec errors and lint findings `toloka validate <pipeline> --wait` reports.
|
|
41
|
+
|
|
42
|
+
Pass `check`, `plan`, `apply`, and `validate` the source directories of the pipelines whose source you changed for this request, such as `pipelines/image-collection`; the last segment, the pipeline id, or the platform name as the directory spells it (`general_knowledge_qa` for `pipelines/general-knowledge-qa`) also work. They then load, check, compare, write, and validate only those pipelines and the datasets they declare, so another pipeline of the project neither slows them down nor blocks them; leave other pipelines alone unless the request covers them. Run them without pipelines when the request covers the whole project (a sync after pulling changes, an import, an edit across pipelines), when you removed or renamed a pipeline directory, or when you are not sure which pipelines changed: only that mode applies every pipeline and notices a dataset removed from source. With pipelines, apply still refuses while a pipeline directory bound in `toloka.json` is missing.
|
|
41
43
|
|
|
42
44
|
The CLI reads source, compares it with live state, and reconciles the platform. Edit files; never mutate a pipeline through raw HTTP, SDK client methods, or internal platform tool calls. Do not make a live edit and then reverse-engineer it into source.
|
|
43
45
|
|
|
@@ -76,9 +78,9 @@ Let constructors mint IDs for new declarations. Preserve `id` options generated
|
|
|
76
78
|
|
|
77
79
|
`definePipeline` and typed ports check local declaration and connection invariants. The published JSON contract is still available as `validate(graph)` for importer and fixture tests; it makes no server call.
|
|
78
80
|
|
|
79
|
-
`toloka check` is the required local gate. It runs the project TypeScript compiler, typechecks every authored Task UI against declarations bundled with this SDK version, runs Vitest, and requires passing typed `test.code`, `test.ui`, and `test.pipeline` evidence for every checkable node and pipeline. Use `toloka check <pipeline> --node <name-or-id>` while iterating, where `<name-or-id>` is the node's name or ID, not the name of the TypeScript constant that holds it, then let `toloka apply
|
|
81
|
+
`toloka check` is the required local gate. It runs the project TypeScript compiler, typechecks every authored Task UI against declarations bundled with this SDK version, runs Vitest, and requires passing typed `test.code`, `test.ui`, and `test.pipeline` evidence for every checkable node and pipeline. Use `toloka check <pipeline> --node <name-or-id>` while iterating, where `<name-or-id>` is the node's name or ID, not the name of the TypeScript constant that holds it, then let `toloka apply <pipeline>` run the gate of that pipeline, which it does before writing anything; run it yourself only when you are not applying, such as for a check-only request or before `toloka pipeline run` on source you did not apply. Status `missing` means required test evidence does not exist; `failed` means a check ran and failed; `infrastructure_error` means the checker could not run. All three block apply. `partial` means a Task UI has upload or recording fields the headless browser cannot exercise; it does not block apply, but tell the user to try the task on a real device before launching a run. `warning` on `platform-rules` lists nodes connected to the root that break a platform rule (names, quality elements, thresholds, review time, price, data collection media, exam limits, Training structure, and the 150,000-character limit for one node setting): check still passes, but apply refuses to write that pipeline until they are fixed, so fix them before apply.
|
|
80
82
|
|
|
81
|
-
`toloka validate` posts each bound graph to the platform and prints one status per pipeline. It exits 1 when any pipeline is `invalid` or `checks-running`, otherwise 0.
|
|
83
|
+
`toloka validate [pipelines...]` posts each bound graph, or the selected ones, to the platform and prints one status per pipeline. It exits 1 when any pipeline is `invalid` or `checks-running`, otherwise 0.
|
|
82
84
|
|
|
83
85
|
| Status | Meaning |
|
|
84
86
|
| --- | --- |
|
|
@@ -88,7 +90,7 @@ Let constructors mint IDs for new declarations. Preserve `id` options generated
|
|
|
88
90
|
| `checks-running` | Only with `--wait`: a lint was still running when the wait ended. |
|
|
89
91
|
| `skipped` | The pipeline or its dataset is not on the platform yet; `toloka apply` creates it. |
|
|
90
92
|
|
|
91
|
-
The platform's lints, such as the Task UI interface lint and the quality-criteria lint, start by themselves a few seconds after every apply and take about a minute. Until they finish, plain `toloka validate` lists each as a `running_node_check` warning and can still print `valid` with exit 0, so it does not prove the lints passed. After applying a change, run `toloka validate --wait`: it validates again
|
|
93
|
+
The platform's lints, such as the Task UI interface lint and the quality-criteria lint, start by themselves a few seconds after every apply and take about a minute. Until they finish, plain `toloka validate` lists each as a `running_node_check` warning and can still print `valid` with exit 0, so it does not prove the lints passed. After applying a change, run `toloka validate --wait`: it validates again after 1 second, then at growing intervals of up to 5 seconds, for up to 5 minutes, until no lint is running, and does not wait for a pipeline whose source has unapplied changes. Report the pipeline as valid only after that. A lint does not restart by itself when dataset items or their values change, or after it fails or times out (after 5 minutes running or 15 minutes waiting to start): run `toloka pipeline lint <name> --wait`, which starts every lint without a current result and waits for it, then validate again. `validate` names this case: `Check "<name>" ran before the dataset changed`. When a reviewed plan adds a dataset field already bound by an existing live pipeline, pre-apply validation can report that exact field as missing; apply only the reviewed additive plan, then require post-apply validation to clear source/spec errors. Never rewrite valid source because a stored test case on the Checks tab has not run.
|
|
92
94
|
|
|
93
95
|
Register every code-node behavior with `test.code(pipeline, node, name, callback)`; its callback receives a bound `run(inputs, options?)` helper with the node's Python execution contract, and the test counts only after `run` executes, an assertion runs, and the callback passes. Register required human-work behavior with `test.ui(pipeline, node, name, callback)`; its callback receives a bound `render(options?)`, and the test counts only after a successful `submit`, at least one assertion, and a passing callback. Add at least one `test.pipeline(pipeline, name, callback)` scenario: treat the fixture as `root.started` item state, execute connected nodes in order with the callback's bound `runCode` and `renderUi` helpers, merge only each node's declared outputs, and assert the final `root.completed` fields. Cover meaningful match branches, optional paths, and failures as well as the happy path.
|
|
94
96
|
|
|
@@ -66,15 +66,15 @@ Use `training cost` to validate inputs and show the maximum charge before `train
|
|
|
66
66
|
|
|
67
67
|
## Check locally and validate against the platform
|
|
68
68
|
|
|
69
|
-
Check the nodes you edit locally, then apply and validate
|
|
69
|
+
Check the nodes you edit locally, then apply and validate the pipeline in one command; apply runs the local gate of the pipelines it applies itself:
|
|
70
70
|
|
|
71
71
|
```sh
|
|
72
|
-
toloka check <pipeline> --node <name-or-id>
|
|
73
|
-
toloka apply && toloka validate --wait
|
|
74
|
-
toloka pipeline lint <
|
|
72
|
+
toloka check <pipeline> --node <name-or-id> # while you edit a node
|
|
73
|
+
toloka apply <pipeline> && toloka validate <pipeline> --wait # runs toloka check <pipeline> first, writes nothing when it fails, then waits for the pipeline's lints
|
|
74
|
+
toloka pipeline lint <pipeline> --wait # after dataset changes or a failed lint: reruns the lints
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
`<pipeline>` is the source directory of a pipeline whose source you changed for the request, such as `pipelines/image-collection`; its last segment, the id, or the platform name as the directory spells it also work, and `check`, `plan`, `apply`, and `validate` take several. With pipelines, these commands load, check, and write only those pipelines and the datasets they declare: TypeScript errors and tests of other pipelines are not part of their gate. Run them without pipelines for project-wide work, after removing or renaming a pipeline directory, or when you are not sure which pipelines changed. Run `toloka check <pipeline>` on its own only when you are not about to apply, since apply would run it again. `toloka check` requires no credentials or live pipeline; SKILL.md describes what it runs and what its statuses mean. Use `toloka check <pipeline> --node <name-or-id>` for a focused edit loop, `--watch` for serialized reruns, and `--json` for automation. When it reports an unknown property or a type mismatch on an SDK type, run `toloka schema <that type>` before the next edit instead of trying another shape.
|
|
78
78
|
|
|
79
79
|
With `--watch --json`, each completed rerun writes one JSON line. Do not start another watcher while one is active.
|
|
80
80
|
|
|
@@ -87,7 +87,7 @@ The authored API still supplies extra local safety:
|
|
|
87
87
|
- It rejects a `connect()` endpoint whose node is absent from `nodes`.
|
|
88
88
|
- Typed ports prevent reversing input and output handles.
|
|
89
89
|
|
|
90
|
-
`toloka apply` runs the
|
|
90
|
+
`toloka apply` runs the local gate, `toloka check` of the same pipelines, again before resolving credentials or writing platform state. Plan compares source with live resources but does not submit the desired graph for acceptance. Apply can still expose graph-wide references, layout identity, or concurrent-version assumptions that only the backend owns.
|
|
91
91
|
|
|
92
92
|
## Read and apply a plan
|
|
93
93
|
|
package/src/cli/check.ts
CHANGED
|
@@ -27,7 +27,9 @@ import { platformRuleIssues } from "../validate";
|
|
|
27
27
|
import { cliRelaunchCommand } from "./cli-entry";
|
|
28
28
|
import { bunSubprocessEnvironment } from "./native-runtime";
|
|
29
29
|
import { CREDENTIAL_ENVIRONMENT_NAMES } from "./environment";
|
|
30
|
-
import { loadProjectSource, type ProjectSource } from "./source";
|
|
30
|
+
import { listPipelineSourceDirectories, loadProjectSource, type ProjectSource } from "./source";
|
|
31
|
+
import { resolvePipelineDirectories } from "./pipeline-selector";
|
|
32
|
+
import { readTolokaState } from "../state";
|
|
31
33
|
import { assertCli, REPORT_HINT, TolokaCliError } from "./cli-error";
|
|
32
34
|
import type { TolokaCliErrorOptions } from "./cli-error";
|
|
33
35
|
|
|
@@ -93,6 +95,7 @@ export type RunVitestOptions = {
|
|
|
93
95
|
readonly evidenceDirectory: string;
|
|
94
96
|
readonly environment: NodeJS.ProcessEnv;
|
|
95
97
|
readonly inventory: readonly CheckInventoryPipeline[];
|
|
98
|
+
readonly testPaths?: readonly string[];
|
|
96
99
|
readonly signal?: AbortSignal;
|
|
97
100
|
};
|
|
98
101
|
|
|
@@ -100,6 +103,7 @@ export type CheckProjectDependencies = {
|
|
|
100
103
|
readonly loadSource: (
|
|
101
104
|
sourceRoot: string,
|
|
102
105
|
environment: NodeJS.ProcessEnv,
|
|
106
|
+
sourceDirectories?: readonly string[],
|
|
103
107
|
) => Promise<ProjectSource>;
|
|
104
108
|
readonly runTypeScript: (
|
|
105
109
|
sourceRoot: string,
|
|
@@ -112,8 +116,9 @@ export type CheckProjectDependencies = {
|
|
|
112
116
|
|
|
113
117
|
export type CheckProjectOptions = {
|
|
114
118
|
readonly sourceRoot: string;
|
|
115
|
-
readonly
|
|
119
|
+
readonly pipelines?: readonly string[];
|
|
116
120
|
readonly node?: string;
|
|
121
|
+
readonly allTests?: boolean;
|
|
117
122
|
readonly json?: boolean;
|
|
118
123
|
readonly environment?: NodeJS.ProcessEnv;
|
|
119
124
|
readonly signal?: AbortSignal;
|
|
@@ -246,6 +251,7 @@ export const classifyVitestRun = (run: ToolRunResult): ToolRunResult => {
|
|
|
246
251
|
const runVitest = async ({
|
|
247
252
|
sourceRoot,
|
|
248
253
|
environment,
|
|
254
|
+
testPaths,
|
|
249
255
|
signal,
|
|
250
256
|
}: RunVitestOptions): Promise<ToolRunResult> => {
|
|
251
257
|
try {
|
|
@@ -261,6 +267,7 @@ const runVitest = async ({
|
|
|
261
267
|
[
|
|
262
268
|
resolveProjectModule(sourceRoot, "vitest", "vitest.mjs"),
|
|
263
269
|
"run",
|
|
270
|
+
...(testPaths === undefined ? [] : [...testPaths, "--passWithNoTests"]),
|
|
264
271
|
...(focusedPattern === undefined ? [] : ["--testNamePattern", focusedPattern]),
|
|
265
272
|
],
|
|
266
273
|
bunSubprocessEnvironment(environment),
|
|
@@ -282,12 +289,13 @@ const bundledTypechecker = createBundledTaskUiTypechecker();
|
|
|
282
289
|
const loadSourceWithoutPlatformCredentials = async (
|
|
283
290
|
sourceRoot: string,
|
|
284
291
|
environment: NodeJS.ProcessEnv,
|
|
292
|
+
sourceDirectories?: readonly string[],
|
|
285
293
|
): Promise<ProjectSource> => {
|
|
286
294
|
const targets = [process.env, environment];
|
|
287
295
|
const saved = targets.map((current) => CREDENTIAL_ENVIRONMENT_NAMES.map((name) => current[name]));
|
|
288
296
|
for (const current of targets) for (const name of CREDENTIAL_ENVIRONMENT_NAMES) delete current[name];
|
|
289
297
|
try {
|
|
290
|
-
return await loadProjectSource(sourceRoot);
|
|
298
|
+
return await loadProjectSource(sourceRoot, sourceDirectories);
|
|
291
299
|
} finally {
|
|
292
300
|
targets.forEach((current, target) => {
|
|
293
301
|
CREDENTIAL_ENVIRONMENT_NAMES.forEach((name, index) => {
|
|
@@ -358,30 +366,9 @@ type SelectedInventory = {
|
|
|
358
366
|
|
|
359
367
|
const filterInventory = (
|
|
360
368
|
inventory: readonly CheckInventoryPipeline[],
|
|
361
|
-
pipelineSelector: string | undefined,
|
|
362
369
|
nodeSelector: string | undefined,
|
|
363
370
|
): SelectedInventory => {
|
|
364
|
-
const pipelines =
|
|
365
|
-
pipelineSelector === undefined
|
|
366
|
-
? [...inventory]
|
|
367
|
-
: inventory.filter(
|
|
368
|
-
(pipeline) =>
|
|
369
|
-
pipeline.sourceDirectory === pipelineSelector ||
|
|
370
|
-
pipeline.name === pipelineSelector ||
|
|
371
|
-
pipeline.sourceDirectory.split("/").at(-1) === pipelineSelector,
|
|
372
|
-
);
|
|
373
|
-
if (pipelineSelector !== undefined) {
|
|
374
|
-
assertCli(
|
|
375
|
-
pipelines.length > 0,
|
|
376
|
-
`Unknown pipeline ${JSON.stringify(pipelineSelector)}. Available: ${inventory.map((item) => item.sourceDirectory).join(", ")}`,
|
|
377
|
-
{ hint: { description: "Pass one of the listed source directories." } },
|
|
378
|
-
);
|
|
379
|
-
assertCli(
|
|
380
|
-
pipelines.length === 1,
|
|
381
|
-
`Pipeline selector ${JSON.stringify(pipelineSelector)} is ambiguous: ${pipelines.map((item) => item.sourceDirectory).join(", ")}`,
|
|
382
|
-
{ hint: { description: "Pass the full source directory of the pipeline you mean." } },
|
|
383
|
-
);
|
|
384
|
-
}
|
|
371
|
+
const pipelines = [...inventory];
|
|
385
372
|
if (nodeSelector === undefined) return { pipelines };
|
|
386
373
|
const matches = pipelines.flatMap((pipeline) =>
|
|
387
374
|
pipeline.nodes
|
|
@@ -423,6 +410,24 @@ const boundedDiagnostics = (diagnostics: readonly CheckDiagnostic[]) => ({
|
|
|
423
410
|
: { truncatedDiagnosticCount: diagnostics.length - MAX_DIAGNOSTICS }),
|
|
424
411
|
});
|
|
425
412
|
|
|
413
|
+
const TYPESCRIPT_DIAGNOSTIC = /^(?<file>[^\s(][^(]*)\(\d+,\d+\): (?:error|warning) TS\d+/u;
|
|
414
|
+
|
|
415
|
+
const withoutDiagnosticsOf = (run: ToolRunResult, directories: readonly string[]): ToolRunResult => {
|
|
416
|
+
if (directories.length === 0 || run.exitCode === 0 || run.infrastructureError === true) return run;
|
|
417
|
+
const ignored = (file: string) => directories.some((directory) => file.startsWith(`${directory}/`));
|
|
418
|
+
const kept: string[] = [];
|
|
419
|
+
let dropping = false;
|
|
420
|
+
for (const line of run.stdout.split("\n")) {
|
|
421
|
+
const file = TYPESCRIPT_DIAGNOSTIC.exec(line)?.groups?.file;
|
|
422
|
+
if (file !== undefined) dropping = ignored(file);
|
|
423
|
+
else if (!/^\s/u.test(line)) dropping = false;
|
|
424
|
+
if (!dropping) kept.push(line);
|
|
425
|
+
}
|
|
426
|
+
const stdout = kept.join("\n");
|
|
427
|
+
const passed = stdout.trim().length === 0 && run.stderr.trim().length === 0;
|
|
428
|
+
return { ...run, stdout, exitCode: passed ? 0 : run.exitCode };
|
|
429
|
+
};
|
|
430
|
+
|
|
426
431
|
const projectToolResult = (
|
|
427
432
|
kind: "project-types" | "test-runner",
|
|
428
433
|
run: ToolRunResult,
|
|
@@ -711,10 +716,26 @@ export async function checkProject(
|
|
|
711
716
|
options: CheckProjectOptions,
|
|
712
717
|
dependencies: CheckProjectDependencies = defaultDependencies,
|
|
713
718
|
): Promise<CheckProjectResult> {
|
|
719
|
+
const allDirectories =
|
|
720
|
+
options.pipelines === undefined || options.pipelines.length === 0
|
|
721
|
+
? undefined
|
|
722
|
+
: await listPipelineSourceDirectories(options.sourceRoot);
|
|
723
|
+
const selectedDirectories =
|
|
724
|
+
allDirectories === undefined
|
|
725
|
+
? undefined
|
|
726
|
+
: resolvePipelineDirectories({
|
|
727
|
+
selectors: options.pipelines ?? [],
|
|
728
|
+
directories: allDirectories,
|
|
729
|
+
state: await readTolokaState(options.sourceRoot),
|
|
730
|
+
});
|
|
714
731
|
let source: ProjectSource;
|
|
715
732
|
try {
|
|
716
733
|
options.signal?.throwIfAborted();
|
|
717
|
-
source = await dependencies.loadSource(
|
|
734
|
+
source = await dependencies.loadSource(
|
|
735
|
+
options.sourceRoot,
|
|
736
|
+
options.environment ?? process.env,
|
|
737
|
+
selectedDirectories,
|
|
738
|
+
);
|
|
718
739
|
options.signal?.throwIfAborted();
|
|
719
740
|
} catch (error) {
|
|
720
741
|
const results: CheckResult[] = [
|
|
@@ -756,7 +777,11 @@ export async function checkProject(
|
|
|
756
777
|
};
|
|
757
778
|
}
|
|
758
779
|
|
|
759
|
-
const selected = filterInventory(inventoryFor(source), options.
|
|
780
|
+
const selected = filterInventory(inventoryFor(source), options.node);
|
|
781
|
+
const otherDirectories =
|
|
782
|
+
selectedDirectories === undefined
|
|
783
|
+
? []
|
|
784
|
+
: (allDirectories ?? []).filter((directory) => !selectedDirectories.includes(directory));
|
|
760
785
|
const evidenceDirectory = await mkdtemp(join(tmpdir(), "toloka-check-"));
|
|
761
786
|
try {
|
|
762
787
|
const selectedPipeline = selected.pipelines.length === 1 ? selected.pipelines[0] : undefined;
|
|
@@ -769,18 +794,23 @@ export async function checkProject(
|
|
|
769
794
|
? {}
|
|
770
795
|
: { [TEST_PIPELINE_FILTER_ENV]: selectedPipeline.pipelineFingerprint }),
|
|
771
796
|
...(selected.nodeId === undefined ? {} : { [TEST_NODE_FILTER_ENV]: selected.nodeId }),
|
|
772
|
-
...(options.
|
|
797
|
+
...(options.allTests === true || (selectedDirectories === undefined && options.node === undefined)
|
|
773
798
|
? {}
|
|
774
799
|
: { [TEST_TYPED_ONLY_ENV]: "1" }),
|
|
775
800
|
};
|
|
776
801
|
const [typeScriptRun, uiResults, vitestRun] = await Promise.all([
|
|
777
|
-
dependencies
|
|
802
|
+
dependencies
|
|
803
|
+
.runTypeScript(options.sourceRoot, checkEnvironment, options.signal)
|
|
804
|
+
.then((run) => withoutDiagnosticsOf(run, otherDirectories)),
|
|
778
805
|
uiTypeResults(source, selected.pipelines, selected.nodeId, dependencies.typecheckUi),
|
|
779
806
|
dependencies.runVitest({
|
|
780
807
|
sourceRoot: options.sourceRoot,
|
|
781
808
|
evidenceDirectory,
|
|
782
809
|
environment,
|
|
783
810
|
inventory: selected.pipelines,
|
|
811
|
+
...(selectedDirectories === undefined
|
|
812
|
+
? {}
|
|
813
|
+
: { testPaths: selectedDirectories.map((directory) => `${directory}/`) }),
|
|
784
814
|
signal: options.signal,
|
|
785
815
|
}),
|
|
786
816
|
]);
|
|
@@ -1052,7 +1082,7 @@ export const runFreshCheck = async (options: CheckProjectOptions): Promise<Check
|
|
|
1052
1082
|
"--source-root",
|
|
1053
1083
|
options.sourceRoot,
|
|
1054
1084
|
"check",
|
|
1055
|
-
...(options.
|
|
1085
|
+
...(options.pipelines ?? []),
|
|
1056
1086
|
...(options.node === undefined ? [] : ["--node", options.node]),
|
|
1057
1087
|
"--json",
|
|
1058
1088
|
],
|
|
@@ -91,12 +91,14 @@ export const registerSourceCommands = (program: Command, host: CommandHost): voi
|
|
|
91
91
|
|
|
92
92
|
program
|
|
93
93
|
.command("plan")
|
|
94
|
+
.argument("[pipelines...]", "pipeline source directories, their last segments, ids, or platform names as the directory spells them; omit to work on every pipeline of the project")
|
|
94
95
|
.option("--json", "print the planned changes and missing secrets as JSON", false)
|
|
95
96
|
.description("show what apply would change")
|
|
96
|
-
.action(async (options: { json: boolean }) => {
|
|
97
|
+
.action(async (pipelines: string[], options: { json: boolean }) => {
|
|
97
98
|
const { sourceRoot, client, projectId } = await resolveContext(globals(), context);
|
|
98
99
|
const result = await planProject(client, {
|
|
99
100
|
sourceRoot,
|
|
101
|
+
pipelines,
|
|
100
102
|
...(projectId === undefined ? {} : { projectId }),
|
|
101
103
|
});
|
|
102
104
|
writeOutput(
|
|
@@ -109,12 +111,14 @@ export const registerSourceCommands = (program: Command, host: CommandHost): voi
|
|
|
109
111
|
|
|
110
112
|
program
|
|
111
113
|
.command("validate")
|
|
114
|
+
.argument("[pipelines...]", "pipeline source directories, their last segments, ids, or platform names as the directory spells them; omit to work on every pipeline of the project")
|
|
112
115
|
.option("--wait", "wait up to 5 minutes for running lints and checks to finish", false)
|
|
113
116
|
.description("run platform spec validation and report matching checks")
|
|
114
|
-
.action(async (options: { wait: boolean }) => {
|
|
117
|
+
.action(async (pipelines: string[], options: { wait: boolean }) => {
|
|
115
118
|
const { sourceRoot, client, projectId } = await resolveContext(globals(), context);
|
|
116
119
|
const result = await validateProject(client, {
|
|
117
120
|
sourceRoot,
|
|
121
|
+
pipelines,
|
|
118
122
|
...(projectId === undefined ? {} : { projectId }),
|
|
119
123
|
...(options.wait ? { wait: VALIDATE_WAIT } : {}),
|
|
120
124
|
});
|
|
@@ -124,21 +128,21 @@ export const registerSourceCommands = (program: Command, host: CommandHost): voi
|
|
|
124
128
|
|
|
125
129
|
program
|
|
126
130
|
.command("check")
|
|
127
|
-
.argument("[
|
|
131
|
+
.argument("[pipelines...]", "pipeline source directories, their last segments, ids, or platform names as the directory spells them; omit to work on every pipeline of the project")
|
|
128
132
|
.option("--node <node>", "check one code or human-work node by name or id")
|
|
129
133
|
.option("--json", "print the structured check report", false)
|
|
130
134
|
.option("--watch", "rerun checks when project files change", false)
|
|
131
135
|
.description("run the complete local source, type, and test gate")
|
|
132
136
|
.action(
|
|
133
137
|
async (
|
|
134
|
-
|
|
138
|
+
pipelines: string[],
|
|
135
139
|
options: { node?: string; json: boolean; watch: boolean },
|
|
136
140
|
) => {
|
|
137
141
|
const sourceRoot = await resolveSourceRoot(globals(), context.io);
|
|
138
142
|
const checkOptions = {
|
|
139
143
|
environment: context.environment,
|
|
140
144
|
sourceRoot,
|
|
141
|
-
|
|
145
|
+
pipelines,
|
|
142
146
|
...(options.node === undefined ? {} : { node: options.node }),
|
|
143
147
|
...(options.json ? { json: true } : {}),
|
|
144
148
|
};
|
|
@@ -184,17 +188,20 @@ export const registerSourceCommands = (program: Command, host: CommandHost): voi
|
|
|
184
188
|
|
|
185
189
|
program
|
|
186
190
|
.command("apply")
|
|
191
|
+
.argument("[pipelines...]", "pipeline source directories, their last segments, ids, or platform names as the directory spells them; omit to work on every pipeline of the project")
|
|
187
192
|
.option(
|
|
188
193
|
"--allow-removals",
|
|
189
194
|
"also apply pipelines whose plan removes nodes or graph fields",
|
|
190
195
|
false,
|
|
191
196
|
)
|
|
192
197
|
.description("check source, print the plan, make the platform match it, then plan again")
|
|
193
|
-
.action(async (options: { allowRemovals: boolean }) => {
|
|
198
|
+
.action(async (pipelines: string[], options: { allowRemovals: boolean }) => {
|
|
194
199
|
const sourceRoot = await resolveSourceRoot(globals(), context.io);
|
|
195
200
|
const { result: checked, interruptedExitCode } = await runChecksInterruptibly(
|
|
196
201
|
{
|
|
197
202
|
sourceRoot,
|
|
203
|
+
pipelines,
|
|
204
|
+
allTests: true,
|
|
198
205
|
environment: context.environment,
|
|
199
206
|
},
|
|
200
207
|
runChecks,
|
|
@@ -213,6 +220,7 @@ export const registerSourceCommands = (program: Command, host: CommandHost): voi
|
|
|
213
220
|
const result = await applyProject(client, {
|
|
214
221
|
sourceRoot,
|
|
215
222
|
source: checked.source,
|
|
223
|
+
pipelines,
|
|
216
224
|
...(projectId === undefined ? {} : { projectId }),
|
|
217
225
|
...(options.allowRemovals ? { allowRemovals: true } : {}),
|
|
218
226
|
onPlan: (plan) => context.io.stdout(plan),
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TolokaState } from "../state";
|
|
2
|
+
import { assertCli } from "./cli-error";
|
|
3
|
+
|
|
4
|
+
export const pipelineDirectoryName = (name: string): string =>
|
|
5
|
+
name
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.match(/[a-z0-9]+/gu)
|
|
8
|
+
?.join("-") || "pipeline";
|
|
9
|
+
|
|
10
|
+
export const lastDirectorySegment = (directory: string): string =>
|
|
11
|
+
directory.split("/").at(-1) ?? directory;
|
|
12
|
+
|
|
13
|
+
export const matchesNormalizedPipelineName = (
|
|
14
|
+
selector: string,
|
|
15
|
+
{ name, sourceDirectory }: { readonly name?: string; readonly sourceDirectory?: string },
|
|
16
|
+
): boolean => {
|
|
17
|
+
const normalized = pipelineDirectoryName(selector);
|
|
18
|
+
return (
|
|
19
|
+
(sourceDirectory !== undefined && lastDirectorySegment(sourceDirectory) === normalized) ||
|
|
20
|
+
(name !== undefined && pipelineDirectoryName(name) === normalized)
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const resolvePipelineDirectories = ({
|
|
25
|
+
selectors,
|
|
26
|
+
directories,
|
|
27
|
+
state,
|
|
28
|
+
}: {
|
|
29
|
+
readonly selectors: readonly string[];
|
|
30
|
+
readonly directories: readonly string[];
|
|
31
|
+
readonly state: TolokaState | undefined;
|
|
32
|
+
}): readonly string[] => {
|
|
33
|
+
const pipelineIds = new Map(
|
|
34
|
+
Object.entries(state?.pipelines ?? {}).map(([directory, { pipelineId }]) => [directory, pipelineId]),
|
|
35
|
+
);
|
|
36
|
+
const describe = (candidates: readonly string[]) =>
|
|
37
|
+
candidates
|
|
38
|
+
.map((directory) => {
|
|
39
|
+
const pipelineId = pipelineIds.get(directory);
|
|
40
|
+
return pipelineId === undefined ? directory : `${directory} (${pipelineId})`;
|
|
41
|
+
})
|
|
42
|
+
.join(", ");
|
|
43
|
+
const tiers: readonly ((selector: string, directory: string) => boolean)[] = [
|
|
44
|
+
(selector, directory) => directory === selector || pipelineIds.get(directory) === selector,
|
|
45
|
+
(selector, directory) => lastDirectorySegment(directory) === selector,
|
|
46
|
+
(selector, directory) => matchesNormalizedPipelineName(selector, { sourceDirectory: directory }),
|
|
47
|
+
];
|
|
48
|
+
const resolved = selectors.map((selector) => {
|
|
49
|
+
const matches =
|
|
50
|
+
tiers
|
|
51
|
+
.map((tier) => directories.filter((directory) => tier(selector, directory)))
|
|
52
|
+
.find((tierMatches) => tierMatches.length > 0) ?? [];
|
|
53
|
+
assertCli(
|
|
54
|
+
matches.length > 0,
|
|
55
|
+
directories.length === 0
|
|
56
|
+
? `Unknown pipeline ${JSON.stringify(selector)}: this project has no pipeline sources.`
|
|
57
|
+
: `Unknown pipeline ${JSON.stringify(selector)}. This project's pipelines: ${describe(directories)}.`,
|
|
58
|
+
{ hint: { description: "Pass a source directory, its last segment, or a pipeline id." } },
|
|
59
|
+
);
|
|
60
|
+
assertCli(
|
|
61
|
+
matches.length === 1,
|
|
62
|
+
`Pipeline ${JSON.stringify(selector)} is ambiguous: ${describe(matches)}.`,
|
|
63
|
+
{ hint: { description: "Pass the full source directory or the pipeline id." } },
|
|
64
|
+
);
|
|
65
|
+
return matches[0]!;
|
|
66
|
+
});
|
|
67
|
+
return [...new Set(resolved)];
|
|
68
|
+
};
|
package/src/cli/poll.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const FIRST_POLL_INTERVAL_MS = 1_000;
|
|
2
|
+
|
|
3
|
+
export const pollUntil = async <T>({
|
|
4
|
+
initial,
|
|
5
|
+
settled,
|
|
6
|
+
poll,
|
|
7
|
+
deadline,
|
|
8
|
+
maxIntervalMs,
|
|
9
|
+
}: {
|
|
10
|
+
readonly initial: T;
|
|
11
|
+
readonly settled: (state: T) => boolean;
|
|
12
|
+
readonly poll: (state: T) => Promise<T>;
|
|
13
|
+
readonly deadline: number;
|
|
14
|
+
readonly maxIntervalMs: number;
|
|
15
|
+
}): Promise<T> => {
|
|
16
|
+
let state = initial;
|
|
17
|
+
let intervalMs = Math.min(FIRST_POLL_INTERVAL_MS, maxIntervalMs);
|
|
18
|
+
while (!settled(state) && Date.now() < deadline) {
|
|
19
|
+
await new Promise<void>((resolve) => {
|
|
20
|
+
setTimeout(resolve, Math.min(intervalMs, deadline - Date.now()));
|
|
21
|
+
});
|
|
22
|
+
state = await poll(state);
|
|
23
|
+
intervalMs = Math.min(intervalMs * 2, maxIntervalMs);
|
|
24
|
+
}
|
|
25
|
+
return state;
|
|
26
|
+
};
|