@toloka-platform/sdk 0.26.0 → 0.26.1
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 +8 -6
- 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/project.ts +47 -27
- package/src/cli/runs.ts +9 -0
- package/src/cli/source.ts +16 -2
package/dist/cli/toloka.js.jsc
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
b0b4312198e71dbecbe58e125011eeaa3c439681112bc3723c9fad23e4baa526 toloka.js.jsc
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
46d3efc8283c57df9141f304d5f5b553d134d6c207e6b86b85363fc39188be93 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.1",
|
|
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": "3205a19f1246dfc6dd9bdb9e01352ebcddc75348"
|
|
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.1",
|
|
15
|
+
"digest": "1901466b2dfef81e9af019676225dfc00a6670ebf8c0df3499e3efdee5e35af2",
|
|
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.1",
|
|
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.1",
|
|
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.1",
|
|
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.1",
|
|
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
|
| --- | --- |
|
|
@@ -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/project.ts
CHANGED
|
@@ -14,8 +14,9 @@ import { platformRuleIssues } from "../validate";
|
|
|
14
14
|
import type { TolokaState } from "../state";
|
|
15
15
|
import { assertProjectSelected } from "./project-context";
|
|
16
16
|
import { collectGraphSecretNames } from "./secrets";
|
|
17
|
-
import { loadProjectSource } from "./source";
|
|
17
|
+
import { listPipelineSourceDirectories, loadProjectSource } from "./source";
|
|
18
18
|
import type { ProjectPipelineSource, ProjectSource } from "./source";
|
|
19
|
+
import { pipelineDirectoryName, resolvePipelineDirectories } from "./pipeline-selector";
|
|
19
20
|
import { assertCli, REPORT_HINT } from "./cli-error";
|
|
20
21
|
|
|
21
22
|
export type PipelinePlanChange = {
|
|
@@ -57,6 +58,7 @@ export type ImportProjectResult = {
|
|
|
57
58
|
export type PlanProjectOptions = {
|
|
58
59
|
readonly sourceRoot: string;
|
|
59
60
|
readonly source?: ProjectSource;
|
|
61
|
+
readonly pipelines?: readonly string[];
|
|
60
62
|
readonly projectId?: string;
|
|
61
63
|
readonly listAllSecrets?: boolean;
|
|
62
64
|
};
|
|
@@ -138,6 +140,7 @@ type PipelineInspection = {
|
|
|
138
140
|
type ProjectInspection = {
|
|
139
141
|
readonly projectId: string;
|
|
140
142
|
readonly source: ProjectSource;
|
|
143
|
+
readonly selected: boolean;
|
|
141
144
|
readonly state: TolokaState | undefined;
|
|
142
145
|
readonly datasets: readonly DatasetInspection[];
|
|
143
146
|
readonly pipelines: readonly PipelineInspection[];
|
|
@@ -701,9 +704,19 @@ const inspectProject = async (
|
|
|
701
704
|
client: PotatoClient,
|
|
702
705
|
options: PlanProjectOptions,
|
|
703
706
|
): Promise<ProjectInspection> => {
|
|
704
|
-
const source = options.source ?? (await loadProjectSource(options.sourceRoot));
|
|
705
|
-
validateSource(source);
|
|
706
707
|
const state = await readTolokaState(options.sourceRoot);
|
|
708
|
+
const sourceDirectories =
|
|
709
|
+
options.pipelines === undefined || options.pipelines.length === 0
|
|
710
|
+
? undefined
|
|
711
|
+
: await listPipelineSourceDirectories(options.sourceRoot);
|
|
712
|
+
const selectedDirectories =
|
|
713
|
+
sourceDirectories === undefined
|
|
714
|
+
? undefined
|
|
715
|
+
: resolvePipelineDirectories({ selectors: options.pipelines ?? [], directories: sourceDirectories, state });
|
|
716
|
+
const source =
|
|
717
|
+
options.source ?? (await loadProjectSource(options.sourceRoot, selectedDirectories));
|
|
718
|
+
validateSource(source);
|
|
719
|
+
const selected = selectedDirectories !== undefined;
|
|
707
720
|
const projectId = options.projectId ?? state?.projectId;
|
|
708
721
|
assertProjectSelected(projectId);
|
|
709
722
|
|
|
@@ -718,14 +731,16 @@ const inspectProject = async (
|
|
|
718
731
|
shouldListSecrets ? client.secrets.list({ projectId }) : Promise.resolve([]),
|
|
719
732
|
]);
|
|
720
733
|
const requiredDatasets = desiredDatasets(source);
|
|
721
|
-
const removedDatasets =
|
|
722
|
-
|
|
723
|
-
.
|
|
734
|
+
const removedDatasets = selected
|
|
735
|
+
? []
|
|
736
|
+
: Object.keys(bindings?.datasets ?? {})
|
|
737
|
+
.filter((name) => !requiredDatasets.some((dataset) => dataset.name === name))
|
|
738
|
+
.toSorted();
|
|
739
|
+
const presentDirectories = new Set(
|
|
740
|
+
sourceDirectories ?? source.pipelines.map((pipeline) => pipeline.sourceDirectory),
|
|
741
|
+
);
|
|
724
742
|
const removedPipelines = Object.keys(bindings?.pipelines ?? {})
|
|
725
|
-
.filter(
|
|
726
|
-
(sourceDirectory) =>
|
|
727
|
-
!source.pipelines.some((pipeline) => pipeline.sourceDirectory === sourceDirectory),
|
|
728
|
-
)
|
|
743
|
+
.filter((sourceDirectory) => !presentDirectories.has(sourceDirectory))
|
|
729
744
|
.toSorted();
|
|
730
745
|
const datasets = await inspectDatasets(client, requiredDatasets, bindings, liveDatasets);
|
|
731
746
|
const pipelines = await inspectPipelines(client, source, bindings, datasets, livePipelines);
|
|
@@ -736,6 +751,7 @@ const inspectProject = async (
|
|
|
736
751
|
return {
|
|
737
752
|
projectId,
|
|
738
753
|
source,
|
|
754
|
+
selected,
|
|
739
755
|
state,
|
|
740
756
|
datasets,
|
|
741
757
|
pipelines,
|
|
@@ -749,12 +765,6 @@ const inspectProject = async (
|
|
|
749
765
|
};
|
|
750
766
|
};
|
|
751
767
|
|
|
752
|
-
const sourceDirectoryBase = (name: string) =>
|
|
753
|
-
name
|
|
754
|
-
.toLowerCase()
|
|
755
|
-
.match(/[a-z0-9]+/gu)
|
|
756
|
-
?.join("-") || "pipeline";
|
|
757
|
-
|
|
758
768
|
const hash = (value: string) => {
|
|
759
769
|
let result = 0x811c9dc5;
|
|
760
770
|
for (let index = 0; index < value.length; index += 1) {
|
|
@@ -765,10 +775,10 @@ const hash = (value: string) => {
|
|
|
765
775
|
};
|
|
766
776
|
|
|
767
777
|
const pipelineSourceDirectories = (pipelines: readonly Pipeline[]) => {
|
|
768
|
-
const groups = Map.groupBy(pipelines, (pipeline) =>
|
|
778
|
+
const groups = Map.groupBy(pipelines, (pipeline) => pipelineDirectoryName(pipeline.name));
|
|
769
779
|
return new Map(
|
|
770
780
|
pipelines.map((pipeline) => {
|
|
771
|
-
const base =
|
|
781
|
+
const base = pipelineDirectoryName(pipeline.name);
|
|
772
782
|
const collision = (groups.get(base)?.length ?? 0) > 1;
|
|
773
783
|
return [pipeline.id, `pipelines/${collision ? `${base}-${hash(pipeline.id)}` : base}`];
|
|
774
784
|
}),
|
|
@@ -1089,9 +1099,15 @@ export async function applyProject(
|
|
|
1089
1099
|
writes += applied.writes;
|
|
1090
1100
|
}
|
|
1091
1101
|
|
|
1102
|
+
const keptBindings =
|
|
1103
|
+
inspection.selected && inspection.state?.projectId === inspection.projectId
|
|
1104
|
+
? inspection.state
|
|
1105
|
+
: undefined;
|
|
1092
1106
|
const nextState: TolokaState = {
|
|
1093
1107
|
projectId: inspection.projectId,
|
|
1094
|
-
pipelines:
|
|
1108
|
+
pipelines: {
|
|
1109
|
+
...keptBindings?.pipelines,
|
|
1110
|
+
...Object.fromEntries(
|
|
1095
1111
|
inspection.source.pipelines.map((pipeline) => {
|
|
1096
1112
|
const pipelineId = pipelineIds.get(pipeline.sourceDirectory);
|
|
1097
1113
|
assertCli(
|
|
@@ -1101,14 +1117,18 @@ export async function applyProject(
|
|
|
1101
1117
|
);
|
|
1102
1118
|
return [pipeline.sourceDirectory, { pipelineId }];
|
|
1103
1119
|
}),
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1120
|
+
),
|
|
1121
|
+
},
|
|
1122
|
+
datasets: {
|
|
1123
|
+
...keptBindings?.datasets,
|
|
1124
|
+
...Object.fromEntries(
|
|
1125
|
+
inspection.datasets.map((dataset) => {
|
|
1126
|
+
const datasetId = datasetIds.get(dataset.name);
|
|
1127
|
+
assertCli(datasetId, `Dataset ${dataset.name} has no resolved ID.`, { hint: REPORT_HINT });
|
|
1128
|
+
return [dataset.name, { datasetId }];
|
|
1129
|
+
}),
|
|
1130
|
+
),
|
|
1131
|
+
},
|
|
1112
1132
|
};
|
|
1113
1133
|
if (valueKey(inspection.state) !== valueKey(nextState))
|
|
1114
1134
|
await writeTolokaState(options.sourceRoot, nextState);
|