@agentsmarket/pipeline-runtime 0.5.6 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -4
- package/dist/http-shell-executor.d.ts +66 -0
- package/dist/http-shell-executor.js +99 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/pipeline-refs.d.ts +12 -0
- package/dist/pipeline-refs.js +22 -0
- package/dist/shell-stage.d.ts +66 -4
- package/dist/shell-stage.js +82 -6
- package/dist/stages.d.ts +25 -1
- package/dist/stages.js +26 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/mock-fields.d.ts +14 -0
- package/dist/testing/mock-fields.js +25 -0
- package/dist/testing/mock-schema.d.ts +31 -0
- package/dist/testing/mock-schema.js +113 -0
- package/dist/testing/runner.d.ts +1 -1
- package/dist/testing/runner.js +11 -14
- package/dist/types.d.ts +11 -0
- package/package.json +11 -11
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -165,12 +165,44 @@ const serverDeps = { isLocal: false, shellExecutor: new ThrowingShellExecutor('s
|
|
|
165
165
|
```
|
|
166
166
|
|
|
167
167
|
`NodeShellExecutor` uses `child_process.spawn(cmd, args, { shell: false, timeout })`:
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
SIGTERM on `timeout_ms` expiry (maps to `ShellStageTimeoutError`), non-zero
|
|
169
|
+
exit → `ShellStageExecError`, stdout/stderr truncated at 1 MB each.
|
|
170
|
+
|
|
171
|
+
**Two forms, two different things:**
|
|
172
|
+
|
|
173
|
+
| form | what it is | how it runs |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| `shell: "npm test && npm run lint"` | a **command line** | `/bin/sh -c "npm test && npm run lint"` — `&&`, `\|`, `>`, `;` and quotes work as written |
|
|
176
|
+
| `shell: { cmd: "npm", args: ["test"] }` | an **exact argv** | `spawn(cmd, args, { shell: false })` — nothing is interpreted, nothing is re-quoted |
|
|
177
|
+
|
|
178
|
+
The string form is a real shell because the stage is called `shell:` — a line
|
|
179
|
+
that auto-splits into an argv would make `&&` an ordinary argument and quotes
|
|
180
|
+
literal. The translation happens once, in `normalizeShellStage`, so every
|
|
181
|
+
executor (local Node, remote sandbox) runs the exact same argv. The object
|
|
182
|
+
form stays shell-free: it is the form to use when the program must receive
|
|
183
|
+
precisely these arguments.
|
|
184
|
+
|
|
185
|
+
```yaml
|
|
186
|
+
stages:
|
|
187
|
+
- id: lint-and-test
|
|
188
|
+
shell: "npm run lint && npm test"
|
|
189
|
+
- id: pytest
|
|
190
|
+
shell:
|
|
191
|
+
cmd: pytest
|
|
192
|
+
args: ["-x", "tests/"]
|
|
193
|
+
cwd: ./backend
|
|
194
|
+
timeout_ms: 120000
|
|
195
|
+
```
|
|
171
196
|
|
|
172
197
|
Limits: `timeout_ms` default 30000, max 600000 (10 min). Output cap 1 MB
|
|
173
|
-
per stream.
|
|
198
|
+
per stream. The string form runs under POSIX `/bin/sh` (`SHELL_BIN`).
|
|
199
|
+
|
|
200
|
+
**One collision to know about:** `${VAR}` is substituted by the runtime
|
|
201
|
+
(v0.3 env-var substitution) before the YAML is parsed, so `${VAR}` inside a
|
|
202
|
+
shell line is resolved from the run's environment — not by the shell. That is
|
|
203
|
+
what you want for `shell: "curl -H 'Bearer ${API_KEY}' …"`, but a shell
|
|
204
|
+
construct that wants `${...}` for itself (a positional parameter, `${1}`)
|
|
205
|
+
never reaches the shell.
|
|
174
206
|
|
|
175
207
|
## Status
|
|
176
208
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P4 — the HTTP shell executor: the server's way of running a command.
|
|
3
|
+
*
|
|
4
|
+
* The runtime asks "who runs this?" and the executor answers. Locally that is
|
|
5
|
+
* `NodeShellExecutor` (a child process on the machine). On the server the
|
|
6
|
+
* Worker has no processes, so the command goes to a sandbox service over
|
|
7
|
+
* HTTP and comes back as stdout/stderr/exit code.
|
|
8
|
+
*
|
|
9
|
+
* Why HTTP and not a binding: the sandbox is a separate process boundary. It
|
|
10
|
+
* holds no marketplace secret, it can be killed as a unit, and it can live on
|
|
11
|
+
* a different machine than the API. The protocol is deliberately small:
|
|
12
|
+
*
|
|
13
|
+
* POST /exec
|
|
14
|
+
* { "cmd": "python3", "args": ["verify.py"], "cwd": "/work",
|
|
15
|
+
* "env": {}, "files": [], "timeout_ms": 60000 }
|
|
16
|
+
*
|
|
17
|
+
* → { "stdout": "...", "stderr": "...", "exit_code": 0,
|
|
18
|
+
* "wall_ms": 812, "timed_out": false }
|
|
19
|
+
*
|
|
20
|
+
* The command is spawned WITHOUT a shell (`shell: false`), so the argv the
|
|
21
|
+
* runtime produced is the argv the sandbox runs. The runtime translates the
|
|
22
|
+
* string form into `/bin/sh -c <line>` before it gets here, which means the
|
|
23
|
+
* sandbox needs no idea that a "shell stage" exists — it runs argv.
|
|
24
|
+
*
|
|
25
|
+
* The sandbox is a trust boundary, not a convenience: it must not be able to
|
|
26
|
+
* reach the API, the database or the metadata service, and it must not see
|
|
27
|
+
* our keys. Those are properties of the sandbox's container, not of this
|
|
28
|
+
* client — this client only refuses to send anything the runtime did not
|
|
29
|
+
* ask for.
|
|
30
|
+
*/
|
|
31
|
+
import { type ShellExecOptions, type ShellExecResult, type ShellExecutor, type ShellStageSpec } from './shell-stage.js';
|
|
32
|
+
/** The body the sandbox accepts. */
|
|
33
|
+
export interface SandboxExecRequest {
|
|
34
|
+
cmd: string;
|
|
35
|
+
args: string[];
|
|
36
|
+
cwd: string;
|
|
37
|
+
env?: Record<string, string>;
|
|
38
|
+
files?: Array<{
|
|
39
|
+
path: string;
|
|
40
|
+
content_b64: string;
|
|
41
|
+
}>;
|
|
42
|
+
timeout_ms: number;
|
|
43
|
+
}
|
|
44
|
+
/** The body the sandbox returns. */
|
|
45
|
+
export interface SandboxExecResponse {
|
|
46
|
+
stdout: string;
|
|
47
|
+
stderr: string;
|
|
48
|
+
exit_code: number;
|
|
49
|
+
wall_ms?: number;
|
|
50
|
+
timed_out?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface HttpShellExecutorOptions {
|
|
53
|
+
/** Base URL of the sandbox service, e.g. https://sandbox.agentsmarket.world */
|
|
54
|
+
url: string;
|
|
55
|
+
/** Shared secret for the sandbox. Sent as a bearer token; never a pipeline value. */
|
|
56
|
+
token?: string;
|
|
57
|
+
/** Injectable for tests. Defaults to the global fetch. */
|
|
58
|
+
fetchImpl?: typeof fetch;
|
|
59
|
+
/** Milliseconds to wait for the sandbox before giving up on it. */
|
|
60
|
+
requestTimeoutMs?: number;
|
|
61
|
+
}
|
|
62
|
+
export declare class HttpShellExecutor implements ShellExecutor {
|
|
63
|
+
private readonly options;
|
|
64
|
+
constructor(options: HttpShellExecutorOptions);
|
|
65
|
+
exec(spec: ShellStageSpec, opts: ShellExecOptions): Promise<ShellExecResult>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P4 — the HTTP shell executor: the server's way of running a command.
|
|
3
|
+
*
|
|
4
|
+
* The runtime asks "who runs this?" and the executor answers. Locally that is
|
|
5
|
+
* `NodeShellExecutor` (a child process on the machine). On the server the
|
|
6
|
+
* Worker has no processes, so the command goes to a sandbox service over
|
|
7
|
+
* HTTP and comes back as stdout/stderr/exit code.
|
|
8
|
+
*
|
|
9
|
+
* Why HTTP and not a binding: the sandbox is a separate process boundary. It
|
|
10
|
+
* holds no marketplace secret, it can be killed as a unit, and it can live on
|
|
11
|
+
* a different machine than the API. The protocol is deliberately small:
|
|
12
|
+
*
|
|
13
|
+
* POST /exec
|
|
14
|
+
* { "cmd": "python3", "args": ["verify.py"], "cwd": "/work",
|
|
15
|
+
* "env": {}, "files": [], "timeout_ms": 60000 }
|
|
16
|
+
*
|
|
17
|
+
* → { "stdout": "...", "stderr": "...", "exit_code": 0,
|
|
18
|
+
* "wall_ms": 812, "timed_out": false }
|
|
19
|
+
*
|
|
20
|
+
* The command is spawned WITHOUT a shell (`shell: false`), so the argv the
|
|
21
|
+
* runtime produced is the argv the sandbox runs. The runtime translates the
|
|
22
|
+
* string form into `/bin/sh -c <line>` before it gets here, which means the
|
|
23
|
+
* sandbox needs no idea that a "shell stage" exists — it runs argv.
|
|
24
|
+
*
|
|
25
|
+
* The sandbox is a trust boundary, not a convenience: it must not be able to
|
|
26
|
+
* reach the API, the database or the metadata service, and it must not see
|
|
27
|
+
* our keys. Those are properties of the sandbox's container, not of this
|
|
28
|
+
* client — this client only refuses to send anything the runtime did not
|
|
29
|
+
* ask for.
|
|
30
|
+
*/
|
|
31
|
+
import { ShellStageExecError, ShellStageTimeoutError, ShellStageUnsupportedError, } from './shell-stage.js';
|
|
32
|
+
export class HttpShellExecutor {
|
|
33
|
+
options;
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.options = options;
|
|
36
|
+
}
|
|
37
|
+
async exec(spec, opts) {
|
|
38
|
+
const fetchImpl = this.options.fetchImpl ?? globalThis.fetch;
|
|
39
|
+
if (typeof fetchImpl !== 'function') {
|
|
40
|
+
throw new ShellStageUnsupportedError('<shell>', 'no fetch implementation is available');
|
|
41
|
+
}
|
|
42
|
+
const body = {
|
|
43
|
+
cmd: spec.cmd,
|
|
44
|
+
args: spec.args ?? [],
|
|
45
|
+
cwd: opts.cwd,
|
|
46
|
+
// Sent as exactly what the runtime resolved for this stage — the
|
|
47
|
+
// sandbox builds PATH/HOME/LANG itself and adds nothing else, so this
|
|
48
|
+
// object IS the stage's universe. It used to be omitted entirely,
|
|
49
|
+
// which meant a stage handed a granted secret still ran without it.
|
|
50
|
+
env: { ...(opts.env ?? {}) },
|
|
51
|
+
// The author's bundle, written into the working directory before the
|
|
52
|
+
// command starts. Omitted when the pipeline ships no files — the
|
|
53
|
+
// sandbox treats a missing list as "nothing to write".
|
|
54
|
+
...(opts.files && opts.files.length > 0 ? { files: opts.files } : {}),
|
|
55
|
+
timeout_ms: opts.timeoutMs,
|
|
56
|
+
};
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
const requestTimeout = this.options.requestTimeoutMs ?? opts.timeoutMs + 5_000;
|
|
59
|
+
const timer = setTimeout(() => controller.abort(), requestTimeout);
|
|
60
|
+
const t0 = Date.now();
|
|
61
|
+
let response;
|
|
62
|
+
try {
|
|
63
|
+
response = await fetchImpl(`${this.options.url.replace(/\/$/, '')}/exec`, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
'content-type': 'application/json',
|
|
67
|
+
...(this.options.token ? { authorization: `Bearer ${this.options.token}` } : {}),
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(body),
|
|
70
|
+
signal: controller.signal,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
throw new ShellStageUnsupportedError('<shell>', `the sandbox at ${this.options.url} is unreachable (${e instanceof Error ? e.message : String(e)})`);
|
|
76
|
+
}
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
const text = await response.text().catch(() => '');
|
|
80
|
+
throw new ShellStageUnsupportedError('<shell>', `the sandbox at ${this.options.url} answered HTTP ${response.status}${text ? `: ${text.slice(0, 200)}` : ''}`);
|
|
81
|
+
}
|
|
82
|
+
const payload = (await response.json());
|
|
83
|
+
const durationMs = payload.wall_ms ?? Date.now() - t0;
|
|
84
|
+
if (payload.timed_out) {
|
|
85
|
+
throw new ShellStageTimeoutError('<shell>', opts.timeoutMs);
|
|
86
|
+
}
|
|
87
|
+
if (payload.exit_code !== 0) {
|
|
88
|
+
throw new ShellStageExecError('<shell>', payload.exit_code, payload.stderr || payload.stdout);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
stdout: payload.stdout ?? '',
|
|
92
|
+
stderr: payload.stderr ?? '',
|
|
93
|
+
exitCode: payload.exit_code,
|
|
94
|
+
durationMs,
|
|
95
|
+
cmd: spec.cmd,
|
|
96
|
+
args: spec.args ?? [],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUses
|
|
|
44
44
|
export { validateInputs, formatInputErrors, type InputDecl, type InputSpec, type InputValidationError, } from './validate-inputs.js';
|
|
45
45
|
export { validateMultimodalInput, type MultimodalValidationError, type MultimodalValidationResult, } from './validate-inputs.js';
|
|
46
46
|
export { parseMediaUrl, detectMime, isImageMime, isAudioMime, isVideoMime, SUPPORTED_IMAGE_MIME, SUPPORTED_AUDIO_MIME, SUPPORTED_VIDEO_MIME, toAnthropicContent, type ParsedMedia, type AnthropicContentBlock, } from './adapters/multimodal-convert.js';
|
|
47
|
-
export { resolveInputRefs, containsInputRef, resolveSpecialKeys, resolveDoubleBraceRefs, type PipelineRefContext, type DoubleBraceContext, } from './pipeline-refs.js';
|
|
47
|
+
export { resolveInputRefs, containsInputRef, inputRefName, resolveSpecialKeys, resolveDoubleBraceRefs, type PipelineRefContext, type DoubleBraceContext, } from './pipeline-refs.js';
|
|
48
48
|
export { isToolSkill, invokeToolSkill, type ToolSkillContext, type ToolSkillResult, type ToolSkillHandler, } from './tools/tool-skills.js';
|
|
49
49
|
export { validateOutputSpec, DEFAULT_OUTPUT_FORMAT, DEFAULT_OUTPUT_DELIVERY, DEFAULT_OUTPUT_EXPIRES_IN, MIN_OUTPUT_EXPIRES_IN, MAX_OUTPUT_EXPIRES_IN, type PipelineOutputSpec, type PipelineOutputDelivery, type PipelineOutputFormat, type PipelineOutputSpecError, } from './output-spec.js';
|
|
50
50
|
export { validateJsonSchema, MAX_VALIDATION_DEPTH, type JsonSchema, type JsonSchemaType, type OutputValidationViolation, type OutputValidationResult, } from './output-schema.js';
|
|
@@ -53,7 +53,8 @@ export { OutputValidationError, OUTPUT_VALIDATION_RETRY_ATTEMPTS, isOutputValida
|
|
|
53
53
|
export { validateOutput, type ValidateOutputOptions, type ValidateOutputResult, } from './validate-inputs.js';
|
|
54
54
|
export { analyzeCapabilities, type PipelineCapabilities, type NetworkCapability, type PipelineSpecLikeForCaps, type PipelineStageLikeForCaps, } from './capabilities.js';
|
|
55
55
|
export { extractProducedFiles, globToRegex, MAX_FILE_BYTES, MAX_TOTAL_BYTES, MAX_FILES, type ProducedFile, type ExtractResult, } from './file-output.js';
|
|
56
|
-
export {
|
|
56
|
+
export { HttpShellExecutor, type HttpShellExecutorOptions, type SandboxExecRequest, type SandboxExecResponse, } from './http-shell-executor.js';
|
|
57
|
+
export { normalizeShellStage, ThrowingShellExecutor, NodeShellExecutor, ShellStageUnsupportedError, ShellStageExecError, ShellStageTimeoutError, SHELL_DEFAULT_TIMEOUT_MS, SHELL_MAX_TIMEOUT_MS, SHELL_MAX_OUTPUT_BYTES, SHELL_BIN, validateShellStageSecretUsage, type ShellStageSpec, type ShellExecutor, type ShellExecOptions, type ShellExecResult, } from './shell-stage.js';
|
|
57
58
|
export interface PipelineStageSpec {
|
|
58
59
|
id: string;
|
|
59
60
|
model: string;
|
|
@@ -84,5 +85,5 @@ export declare function runPipeline(spec: PipelineSpec, inputs: Record<string, u
|
|
|
84
85
|
}): Promise<Record<string, string>>;
|
|
85
86
|
export { LOOP_SCHEMA_VERSION, DEFAULT_MAX_ITERATIONS, ABSOLUTE_MAX_ITERATIONS, LoopConfigError, LoopMaxIterationsExceededError, parseExitExpression, evaluateExitExpression, executeLoop, type LoopOperator, type LoopExitExpression, type LoopSpec, type LoopIteration, type LoopTrace, type RunBodyStage, type LoopExecutionOptions, } from './loop.js';
|
|
86
87
|
export { MEMORY_SCHEMA_VERSION, MAX_MEMORY_VALUE_BYTES, InMemoryMemoryStore, R2MemoryStore, createMemoryStore, type MemoryScope, type MemoryPartition, type MemoryEntry, type MemoryStore, type MemoryR2Like, } from './memory.js';
|
|
87
|
-
export { parseTestSpec, loadTestSpecFile, TestSpecParseError, runAssertion, getPath, runSingleTest, runTestSuite, mockValueForField, buildMockProvider, extractStage, StageNotFoundInSpecError, renderText, renderJson, renderJunit, computeCoverage, renderCoverageText, loadCoverageForPipeline, discoverTestFiles, runConformanceDir, } from './testing/index.js';
|
|
88
|
+
export { parseTestSpec, loadTestSpecFile, TestSpecParseError, runAssertion, getPath, runSingleTest, runTestSuite, mockValueForField, buildMockProvider, extractStage, StageNotFoundInSpecError, renderText, renderJson, renderJunit, computeCoverage, renderCoverageText, loadCoverageForPipeline, discoverTestFiles, runConformanceDir, mockValueForSchema, } from './testing/index.js';
|
|
88
89
|
export type { TestSpec, Assertion, AssertionResult, AssertionContext, SingleTestResult, RunTestOptions, RunSuiteOptions, ExtractedStage, CoverageReport, } from './testing/index.js';
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUses
|
|
|
28
28
|
export { validateInputs, formatInputErrors, } from './validate-inputs.js';
|
|
29
29
|
export { validateMultimodalInput, } from './validate-inputs.js';
|
|
30
30
|
export { parseMediaUrl, detectMime, isImageMime, isAudioMime, isVideoMime, SUPPORTED_IMAGE_MIME, SUPPORTED_AUDIO_MIME, SUPPORTED_VIDEO_MIME, toAnthropicContent, } from './adapters/multimodal-convert.js';
|
|
31
|
-
export { resolveInputRefs, containsInputRef, resolveSpecialKeys, resolveDoubleBraceRefs, } from './pipeline-refs.js';
|
|
31
|
+
export { resolveInputRefs, containsInputRef, inputRefName, resolveSpecialKeys, resolveDoubleBraceRefs, } from './pipeline-refs.js';
|
|
32
32
|
export { isToolSkill, invokeToolSkill, } from './tools/tool-skills.js';
|
|
33
33
|
export { validateOutputSpec, DEFAULT_OUTPUT_FORMAT, DEFAULT_OUTPUT_DELIVERY, DEFAULT_OUTPUT_EXPIRES_IN, MIN_OUTPUT_EXPIRES_IN, MAX_OUTPUT_EXPIRES_IN, } from './output-spec.js';
|
|
34
34
|
export { validateJsonSchema, MAX_VALIDATION_DEPTH, } from './output-schema.js';
|
|
@@ -37,7 +37,8 @@ export { OutputValidationError, OUTPUT_VALIDATION_RETRY_ATTEMPTS, isOutputValida
|
|
|
37
37
|
export { validateOutput, } from './validate-inputs.js';
|
|
38
38
|
export { analyzeCapabilities, } from './capabilities.js';
|
|
39
39
|
export { extractProducedFiles, globToRegex, MAX_FILE_BYTES, MAX_TOTAL_BYTES, MAX_FILES, } from './file-output.js';
|
|
40
|
-
export {
|
|
40
|
+
export { HttpShellExecutor, } from './http-shell-executor.js';
|
|
41
|
+
export { normalizeShellStage, ThrowingShellExecutor, NodeShellExecutor, ShellStageUnsupportedError, ShellStageExecError, ShellStageTimeoutError, SHELL_DEFAULT_TIMEOUT_MS, SHELL_MAX_TIMEOUT_MS, SHELL_MAX_OUTPUT_BYTES, SHELL_BIN, validateShellStageSecretUsage, } from './shell-stage.js';
|
|
41
42
|
export async function runStage(stage, ctx) {
|
|
42
43
|
const vars = [];
|
|
43
44
|
for (const [key, val] of Object.entries(ctx.outputs)) {
|
|
@@ -77,4 +78,4 @@ export async function runPipeline(spec, inputs, opts) {
|
|
|
77
78
|
}
|
|
78
79
|
export { LOOP_SCHEMA_VERSION, DEFAULT_MAX_ITERATIONS, ABSOLUTE_MAX_ITERATIONS, LoopConfigError, LoopMaxIterationsExceededError, parseExitExpression, evaluateExitExpression, executeLoop, } from './loop.js';
|
|
79
80
|
export { MEMORY_SCHEMA_VERSION, MAX_MEMORY_VALUE_BYTES, InMemoryMemoryStore, R2MemoryStore, createMemoryStore, } from './memory.js';
|
|
80
|
-
export { parseTestSpec, loadTestSpecFile, TestSpecParseError, runAssertion, getPath, runSingleTest, runTestSuite, mockValueForField, buildMockProvider, extractStage, StageNotFoundInSpecError, renderText, renderJson, renderJunit, computeCoverage, renderCoverageText, loadCoverageForPipeline, discoverTestFiles, runConformanceDir, } from './testing/index.js';
|
|
81
|
+
export { parseTestSpec, loadTestSpecFile, TestSpecParseError, runAssertion, getPath, runSingleTest, runTestSuite, mockValueForField, buildMockProvider, extractStage, StageNotFoundInSpecError, renderText, renderJson, renderJunit, computeCoverage, renderCoverageText, loadCoverageForPipeline, discoverTestFiles, runConformanceDir, mockValueForSchema, } from './testing/index.js';
|
package/dist/pipeline-refs.d.ts
CHANGED
|
@@ -59,6 +59,18 @@ export declare function resolveDoubleBraceRefs(value: unknown, ctx: DoubleBraceC
|
|
|
59
59
|
* in a consumer would drift the moment either side gains a form.
|
|
60
60
|
*/
|
|
61
61
|
export declare function containsInputRef(value: unknown): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The input a value refers to — or null when it is not a reference.
|
|
64
|
+
*
|
|
65
|
+
* `containsInputRef` answers "is this a reference"; this answers "which
|
|
66
|
+
* input". A caller that has the declared defaults (the spec's `inputs:`)
|
|
67
|
+
* can then know what the value will be at run time, without running it.
|
|
68
|
+
*
|
|
69
|
+
* Only a value that IS the reference counts. `MiniMax-${input.suffix}`
|
|
70
|
+
* resolves to something only the runtime can compute, so the answer there
|
|
71
|
+
* is null — and the caller checks what it can and leaves the rest alone.
|
|
72
|
+
*/
|
|
73
|
+
export declare function inputRefName(value: unknown): string | null;
|
|
62
74
|
export declare function resolveInputRefs(value: unknown, ctx: PipelineRefContext): unknown;
|
|
63
75
|
/**
|
|
64
76
|
* Substitute built-in special keys (\$today, \$now, \$year, \$month, \$weekday)
|
package/dist/pipeline-refs.js
CHANGED
|
@@ -197,6 +197,28 @@ export function resolveDoubleBraceRefs(value, ctx) {
|
|
|
197
197
|
export function containsInputRef(value) {
|
|
198
198
|
return typeof value === 'string' && INPUT_REF_PROBE.test(value);
|
|
199
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* The input a value refers to — or null when it is not a reference.
|
|
202
|
+
*
|
|
203
|
+
* `containsInputRef` answers "is this a reference"; this answers "which
|
|
204
|
+
* input". A caller that has the declared defaults (the spec's `inputs:`)
|
|
205
|
+
* can then know what the value will be at run time, without running it.
|
|
206
|
+
*
|
|
207
|
+
* Only a value that IS the reference counts. `MiniMax-${input.suffix}`
|
|
208
|
+
* resolves to something only the runtime can compute, so the answer there
|
|
209
|
+
* is null — and the caller checks what it can and leaves the rest alone.
|
|
210
|
+
*/
|
|
211
|
+
export function inputRefName(value) {
|
|
212
|
+
if (typeof value !== 'string')
|
|
213
|
+
return null;
|
|
214
|
+
const match = INPUT_REF_PROBE.exec(value);
|
|
215
|
+
if (!match)
|
|
216
|
+
return null;
|
|
217
|
+
const name = match[1] ?? match[2];
|
|
218
|
+
if (!name)
|
|
219
|
+
return null;
|
|
220
|
+
return match[0].length === value.length ? name : null;
|
|
221
|
+
}
|
|
200
222
|
// One definition of the ref syntax, two regexes over it. Substitution needs the
|
|
201
223
|
// global flag; the predicate must NOT have it — a global regex carries
|
|
202
224
|
// `lastIndex` between `.test()` calls, so `containsInputRef` answered
|
package/dist/shell-stage.d.ts
CHANGED
|
@@ -13,8 +13,12 @@
|
|
|
13
13
|
* change here.
|
|
14
14
|
*
|
|
15
15
|
* **Execution model:**
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
16
|
+
* - The STRING form is a command LINE, not an argv. It is translated once,
|
|
17
|
+
* in `normalizeShellStage`, into `/bin/sh -c <line>` — so `&&`, `|`, `>`
|
|
18
|
+
* and quotes behave the way the author wrote them, and every executor
|
|
19
|
+
* (local Node, remote sandbox) runs the exact same argv.
|
|
20
|
+
* - The OBJECT form is an exact argv: `spawn(cmd, args, { shell: false })`,
|
|
21
|
+
* no shell interpretation, nothing re-quoted.
|
|
18
22
|
* - `timeout` option sends SIGTERM after `timeout_ms`; the executor
|
|
19
23
|
* maps that to `ShellStageTimeoutError`.
|
|
20
24
|
* - Non-zero exit code → `ShellStageExecError` with stderr in message.
|
|
@@ -26,8 +30,8 @@
|
|
|
26
30
|
* never touch the binding (the server uses a throwing stub).
|
|
27
31
|
*
|
|
28
32
|
* Stage schema (two forms):
|
|
29
|
-
* shell: "npm test"
|
|
30
|
-
* shell: # explicit form
|
|
33
|
+
* shell: "npm test && npm run lint" # shorthand: a shell line
|
|
34
|
+
* shell: # explicit form: exact argv
|
|
31
35
|
* cmd: "npm"
|
|
32
36
|
* args: ["test"]
|
|
33
37
|
* cwd: "./my-project"
|
|
@@ -42,10 +46,68 @@ export interface ShellStageSpec {
|
|
|
42
46
|
export declare const SHELL_DEFAULT_TIMEOUT_MS = 30000;
|
|
43
47
|
export declare const SHELL_MAX_OUTPUT_BYTES: number;
|
|
44
48
|
export declare const SHELL_MAX_TIMEOUT_MS = 600000;
|
|
49
|
+
/**
|
|
50
|
+
* The shell that runs the STRING form of a shell stage.
|
|
51
|
+
*
|
|
52
|
+
* A string is a command line, not an argv — without a shell `&&` would be an
|
|
53
|
+
* argument and quotes would be literal. POSIX `/bin/sh`; the stage's `cwd`
|
|
54
|
+
* and the runner's environment apply as usual.
|
|
55
|
+
*/
|
|
56
|
+
export declare const SHELL_BIN = "/bin/sh";
|
|
45
57
|
export declare function normalizeShellStage(raw: unknown): ShellStageSpec | null;
|
|
58
|
+
/**
|
|
59
|
+
* The exact-argv form does not expand `$NAME` — and a secret can only reach
|
|
60
|
+
* a program through the environment.
|
|
61
|
+
*
|
|
62
|
+
* A shell stage has two forms and they deliver a secret differently:
|
|
63
|
+
*
|
|
64
|
+
* the STRING form → `/bin/sh -c <line>`, so the shell expands `$TOKEN`
|
|
65
|
+
* from the stage's environment;
|
|
66
|
+
* the OBJECT form → an exact argv, spawned without a shell, so `$TOKEN`
|
|
67
|
+
* is a literal string and `${TOKEN}` is refused at
|
|
68
|
+
* publish time (a secret's value never belongs in the
|
|
69
|
+
* text of a spec — the owner's rule §8.1).
|
|
70
|
+
*
|
|
71
|
+
* In the object form the secret still arrives: the runtime resolves the
|
|
72
|
+
* names the stage declared against the buyer's grants and passes them as
|
|
73
|
+
* that stage's environment, so the program reads `os.environ['TOKEN']` (or
|
|
74
|
+
* `process.env.TOKEN`). What does NOT work is the author writing `$TOKEN`
|
|
75
|
+
* inside `args` and expecting the value there — it would reach the program
|
|
76
|
+
* as the four characters `$TOKEN`.
|
|
77
|
+
*
|
|
78
|
+
* This check turns that silent mistake into an error at publish time, where
|
|
79
|
+
* the author is still looking at the spec. The string form is left alone:
|
|
80
|
+
* there the shell does the expanding, which is the whole point of it.
|
|
81
|
+
*/
|
|
82
|
+
export declare function validateShellStageSecretUsage(stage: unknown): string | null;
|
|
46
83
|
export interface ShellExecOptions {
|
|
47
84
|
cwd: string;
|
|
48
85
|
timeoutMs: number;
|
|
86
|
+
/**
|
|
87
|
+
* Variables this stage is allowed to see.
|
|
88
|
+
*
|
|
89
|
+
* The runtime resolves a stage's declared `secrets:` against the buyer's
|
|
90
|
+
* granted set and passes only those values here. A stage that declares
|
|
91
|
+
* nothing gets an empty object — the executor's job is to run the command in
|
|
92
|
+
* exactly this environment, so whatever the host process happens to hold must
|
|
93
|
+
* not leak in by default.
|
|
94
|
+
*/
|
|
95
|
+
env?: Record<string, string>;
|
|
96
|
+
/**
|
|
97
|
+
* The author's bundle — the files that ship with the pipeline — to be
|
|
98
|
+
* written into the working directory before the command runs.
|
|
99
|
+
*
|
|
100
|
+
* Without this a stage that runs `node scripts/verify.js` finds no
|
|
101
|
+
* `scripts/`: the pipeline's files were stored with the pipeline but never
|
|
102
|
+
* travelled to the process that runs them. The content is base64 because
|
|
103
|
+
* a bundle entry is binary as often as it is text.
|
|
104
|
+
*/
|
|
105
|
+
files?: ShellExecFile[];
|
|
106
|
+
}
|
|
107
|
+
/** One file of the author's bundle, on its way to the working directory. */
|
|
108
|
+
export interface ShellExecFile {
|
|
109
|
+
path: string;
|
|
110
|
+
content_b64: string;
|
|
49
111
|
}
|
|
50
112
|
export interface ShellExecResult {
|
|
51
113
|
stdout: string;
|
package/dist/shell-stage.js
CHANGED
|
@@ -13,8 +13,12 @@
|
|
|
13
13
|
* change here.
|
|
14
14
|
*
|
|
15
15
|
* **Execution model:**
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
16
|
+
* - The STRING form is a command LINE, not an argv. It is translated once,
|
|
17
|
+
* in `normalizeShellStage`, into `/bin/sh -c <line>` — so `&&`, `|`, `>`
|
|
18
|
+
* and quotes behave the way the author wrote them, and every executor
|
|
19
|
+
* (local Node, remote sandbox) runs the exact same argv.
|
|
20
|
+
* - The OBJECT form is an exact argv: `spawn(cmd, args, { shell: false })`,
|
|
21
|
+
* no shell interpretation, nothing re-quoted.
|
|
18
22
|
* - `timeout` option sends SIGTERM after `timeout_ms`; the executor
|
|
19
23
|
* maps that to `ShellStageTimeoutError`.
|
|
20
24
|
* - Non-zero exit code → `ShellStageExecError` with stderr in message.
|
|
@@ -26,8 +30,8 @@
|
|
|
26
30
|
* never touch the binding (the server uses a throwing stub).
|
|
27
31
|
*
|
|
28
32
|
* Stage schema (two forms):
|
|
29
|
-
* shell: "npm test"
|
|
30
|
-
* shell: # explicit form
|
|
33
|
+
* shell: "npm test && npm run lint" # shorthand: a shell line
|
|
34
|
+
* shell: # explicit form: exact argv
|
|
31
35
|
* cmd: "npm"
|
|
32
36
|
* args: ["test"]
|
|
33
37
|
* cwd: "./my-project"
|
|
@@ -36,13 +40,23 @@
|
|
|
36
40
|
export const SHELL_DEFAULT_TIMEOUT_MS = 30_000;
|
|
37
41
|
export const SHELL_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
38
42
|
export const SHELL_MAX_TIMEOUT_MS = 600_000;
|
|
43
|
+
/**
|
|
44
|
+
* The shell that runs the STRING form of a shell stage.
|
|
45
|
+
*
|
|
46
|
+
* A string is a command line, not an argv — without a shell `&&` would be an
|
|
47
|
+
* argument and quotes would be literal. POSIX `/bin/sh`; the stage's `cwd`
|
|
48
|
+
* and the runner's environment apply as usual.
|
|
49
|
+
*/
|
|
50
|
+
export const SHELL_BIN = '/bin/sh';
|
|
39
51
|
export function normalizeShellStage(raw) {
|
|
40
52
|
if (typeof raw === 'string') {
|
|
41
53
|
const trimmed = raw.trim();
|
|
42
54
|
if (trimmed.length === 0)
|
|
43
55
|
return null;
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
// Translated HERE, once, so every executor runs the same argv: the local
|
|
57
|
+
// Node executor and a remote sandbox must not disagree about what the
|
|
58
|
+
// author's `&&` means.
|
|
59
|
+
return { cmd: SHELL_BIN, args: ['-c', trimmed] };
|
|
46
60
|
}
|
|
47
61
|
if (!raw || typeof raw !== 'object')
|
|
48
62
|
return null;
|
|
@@ -62,6 +76,68 @@ export function normalizeShellStage(raw) {
|
|
|
62
76
|
}
|
|
63
77
|
return spec;
|
|
64
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* The exact-argv form does not expand `$NAME` — and a secret can only reach
|
|
81
|
+
* a program through the environment.
|
|
82
|
+
*
|
|
83
|
+
* A shell stage has two forms and they deliver a secret differently:
|
|
84
|
+
*
|
|
85
|
+
* the STRING form → `/bin/sh -c <line>`, so the shell expands `$TOKEN`
|
|
86
|
+
* from the stage's environment;
|
|
87
|
+
* the OBJECT form → an exact argv, spawned without a shell, so `$TOKEN`
|
|
88
|
+
* is a literal string and `${TOKEN}` is refused at
|
|
89
|
+
* publish time (a secret's value never belongs in the
|
|
90
|
+
* text of a spec — the owner's rule §8.1).
|
|
91
|
+
*
|
|
92
|
+
* In the object form the secret still arrives: the runtime resolves the
|
|
93
|
+
* names the stage declared against the buyer's grants and passes them as
|
|
94
|
+
* that stage's environment, so the program reads `os.environ['TOKEN']` (or
|
|
95
|
+
* `process.env.TOKEN`). What does NOT work is the author writing `$TOKEN`
|
|
96
|
+
* inside `args` and expecting the value there — it would reach the program
|
|
97
|
+
* as the four characters `$TOKEN`.
|
|
98
|
+
*
|
|
99
|
+
* This check turns that silent mistake into an error at publish time, where
|
|
100
|
+
* the author is still looking at the spec. The string form is left alone:
|
|
101
|
+
* there the shell does the expanding, which is the whole point of it.
|
|
102
|
+
*/
|
|
103
|
+
export function validateShellStageSecretUsage(stage) {
|
|
104
|
+
if (!stage || typeof stage !== 'object')
|
|
105
|
+
return null;
|
|
106
|
+
const s = stage;
|
|
107
|
+
// Only the object form: the string form goes through a shell.
|
|
108
|
+
if (!s.shell || typeof s.shell !== 'object' || Array.isArray(s.shell))
|
|
109
|
+
return null;
|
|
110
|
+
const shell = s.shell;
|
|
111
|
+
const declared = Array.isArray(s.secrets)
|
|
112
|
+
? s.secrets.filter((n) => typeof n === 'string')
|
|
113
|
+
: [];
|
|
114
|
+
if (declared.length === 0)
|
|
115
|
+
return null;
|
|
116
|
+
const texts = [];
|
|
117
|
+
if (typeof shell.cmd === 'string')
|
|
118
|
+
texts.push(shell.cmd);
|
|
119
|
+
if (Array.isArray(shell.args)) {
|
|
120
|
+
for (const a of shell.args)
|
|
121
|
+
if (typeof a === 'string')
|
|
122
|
+
texts.push(a);
|
|
123
|
+
}
|
|
124
|
+
if (texts.length === 0)
|
|
125
|
+
return null;
|
|
126
|
+
const label = typeof s.id === 'string' && s.id.length > 0 ? `Stage '${s.id}'` : 'Stage';
|
|
127
|
+
for (const name of declared) {
|
|
128
|
+
// `$NAME` or `${NAME}` — both are the author's intent to put the value
|
|
129
|
+
// into the argument, and neither can work here.
|
|
130
|
+
const re = new RegExp(`\\$\\{?${name}\\b`);
|
|
131
|
+
if (!texts.some((t) => re.test(t)))
|
|
132
|
+
continue;
|
|
133
|
+
return (`${label}: the exact-argv form ({cmd, args}) does not expand $${name}, and a secret's ` +
|
|
134
|
+
`value never belongs in the text of a spec. The secret reaches the program as the ` +
|
|
135
|
+
`environment variable ${name}: declare it in this stage's \`secrets:\` and read it from ` +
|
|
136
|
+
`the environment (os.environ['${name}']). To let a shell expand $${name} itself, use the ` +
|
|
137
|
+
`string form (\`shell: "…$$\{${name}\}…"\`), which runs through /bin/sh.`);
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
65
141
|
export class ShellStageUnsupportedError extends Error {
|
|
66
142
|
stageId;
|
|
67
143
|
reason;
|
package/dist/stages.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { PricingResolver } from './pricing.js';
|
|
|
18
18
|
import { createModelResolver, type ModelResolver, type PipelineLike, type PipelineStageLike, type SkillLike } from './model-resolver.js';
|
|
19
19
|
import { type PipelineEventSink } from './streaming-events.js';
|
|
20
20
|
import { type RuntimeConstraints } from './runtime-constraints.js';
|
|
21
|
-
import { type ShellExecutor } from './shell-stage.js';
|
|
21
|
+
import { type ShellExecutor, type ShellExecFile } from './shell-stage.js';
|
|
22
22
|
import { type PipelineFetcher, type CompositionConfig } from './composition.js';
|
|
23
23
|
export interface ResolvedUse {
|
|
24
24
|
id: string;
|
|
@@ -129,6 +129,30 @@ export interface StageExecutorDeps {
|
|
|
129
129
|
* When absent, stages declaring `shell:` throw `ShellStageUnsupportedError`.
|
|
130
130
|
*/
|
|
131
131
|
shellExecutor?: ShellExecutor;
|
|
132
|
+
/**
|
|
133
|
+
* Values of the secrets granted for this run, by name.
|
|
134
|
+
*
|
|
135
|
+
* A shell stage receives only the names it declared in its own `secrets:`
|
|
136
|
+
* list, resolved out of this map. The host's own environment is never a
|
|
137
|
+
* source — the caller builds this from the buyer's grants, so a stage
|
|
138
|
+
* cannot read the platform's bindings by naming them.
|
|
139
|
+
*/
|
|
140
|
+
grantedSecrets?: Record<string, string>;
|
|
141
|
+
/**
|
|
142
|
+
* The author's bundle, by path — written into the working directory before
|
|
143
|
+
* the command runs, so a stage can call the script that ships with the
|
|
144
|
+
* pipeline. Empty/absent for a pipeline that ships no files.
|
|
145
|
+
*/
|
|
146
|
+
stageFiles?: ShellExecFile[];
|
|
147
|
+
/**
|
|
148
|
+
* The working directory for stages that do not name one.
|
|
149
|
+
*
|
|
150
|
+
* The server sets a per-run directory: the sandbox container has one
|
|
151
|
+
* filesystem, and two runs writing the same file name into the same place
|
|
152
|
+
* would race. Left undefined locally, where the caller's own directory is
|
|
153
|
+
* the right answer.
|
|
154
|
+
*/
|
|
155
|
+
shellWorkdir?: string;
|
|
132
156
|
}
|
|
133
157
|
export interface RetryContext {
|
|
134
158
|
stageId: string;
|
package/dist/stages.js
CHANGED
|
@@ -484,10 +484,33 @@ correctionHint) {
|
|
|
484
484
|
throw new StageBadConfigError(`Stage '${stage.id}' has a malformed 'shell' spec (expected string or { cmd, args?, cwd?, timeout_ms? })`);
|
|
485
485
|
}
|
|
486
486
|
const shellT0 = Date.now();
|
|
487
|
+
// Only the names THIS stage declared, and only those the host actually
|
|
488
|
+
// granted. The sandbox executor runs the command in exactly this
|
|
489
|
+
// environment — nothing crosses the boundary but what is listed here.
|
|
490
|
+
// The local executor merges it over the caller's own shell env, because
|
|
491
|
+
// that is where a local run's variables come from (the CLI substitutes
|
|
492
|
+
// ${VAR} from the same place).
|
|
493
|
+
const stageEnv = {};
|
|
494
|
+
const declaredRaw = stage.secrets;
|
|
495
|
+
const declared = Array.isArray(declaredRaw)
|
|
496
|
+
? declaredRaw.filter((n) => typeof n === 'string')
|
|
497
|
+
: [];
|
|
498
|
+
for (const name of declared) {
|
|
499
|
+
const v = deps.grantedSecrets?.[name];
|
|
500
|
+
if (typeof v === 'string' && v.length > 0)
|
|
501
|
+
stageEnv[name] = v;
|
|
502
|
+
}
|
|
487
503
|
try {
|
|
488
504
|
const result = await deps.shellExecutor.exec(spec, {
|
|
489
|
-
|
|
505
|
+
// The host's working directory when the author did not pick one: on
|
|
506
|
+
// the server that is a per-run directory (a Worker has no meaningful
|
|
507
|
+
// cwd of its own, and '/' is not writable inside the sandbox).
|
|
508
|
+
cwd: spec.cwd ?? deps.shellWorkdir ?? process.cwd(),
|
|
490
509
|
timeoutMs: spec.timeout_ms ?? SHELL_DEFAULT_TIMEOUT_MS,
|
|
510
|
+
env: stageEnv,
|
|
511
|
+
// The author's bundle, written into the working directory before the
|
|
512
|
+
// command starts. Absent for a pipeline that ships no files.
|
|
513
|
+
files: deps.stageFiles,
|
|
491
514
|
});
|
|
492
515
|
const output = JSON.stringify({
|
|
493
516
|
cmd: spec.cmd,
|
|
@@ -698,6 +721,7 @@ correctionHint) {
|
|
|
698
721
|
...stageModelParams(stage),
|
|
699
722
|
fields: stage.fields,
|
|
700
723
|
outputFormat: stage.output_format,
|
|
724
|
+
outputSchema: stage.output_schema,
|
|
701
725
|
messages: correctionHint
|
|
702
726
|
? [
|
|
703
727
|
...(ctxPrefix.length > 0 ? [{ role: 'user', content: ctxPrefix }] : []),
|
|
@@ -723,6 +747,7 @@ correctionHint) {
|
|
|
723
747
|
...stageModelParams(stage),
|
|
724
748
|
fields: stage.fields,
|
|
725
749
|
outputFormat: stage.output_format,
|
|
750
|
+
outputSchema: stage.output_schema,
|
|
726
751
|
});
|
|
727
752
|
})(), stage.retry, retryCtx);
|
|
728
753
|
const result = ran.value;
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { parseTestSpec, loadTestSpecFile, TestSpecParseError, type TestSpec, type Assertion } from './spec-parser.js';
|
|
2
2
|
export { runAssertion, getPath, type AssertionResult, type AssertionContext } from './assertions.js';
|
|
3
3
|
export { runSingleTest, runTestSuite, mockValueForField, buildMockProvider, type SingleTestResult, type RunTestOptions, type RunSuiteOptions } from './runner.js';
|
|
4
|
+
export { mockValueForSchema } from './mock-schema.js';
|
|
4
5
|
export { extractStage, StageNotFoundInSpecError, type ExtractedStage } from './stage-extractor.js';
|
|
5
6
|
export { renderText } from './reporters/text.js';
|
|
6
7
|
export { renderJson } from './reporters/json.js';
|
package/dist/testing/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { parseTestSpec, loadTestSpecFile, TestSpecParseError } from './spec-parser.js';
|
|
2
2
|
export { runAssertion, getPath } from './assertions.js';
|
|
3
3
|
export { runSingleTest, runTestSuite, mockValueForField, buildMockProvider } from './runner.js';
|
|
4
|
+
export { mockValueForSchema } from './mock-schema.js';
|
|
4
5
|
export { extractStage, StageNotFoundInSpecError } from './stage-extractor.js';
|
|
5
6
|
export { renderText } from './reporters/text.js';
|
|
6
7
|
export { renderJson } from './reporters/json.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — the values the mock knows by field name.
|
|
3
|
+
*
|
|
4
|
+
* These are the shapes the published example pipelines assert on
|
|
5
|
+
* (`markdown_report` matches /Mock report/, `summary.test_score >= 1`), so
|
|
6
|
+
* the mock has to answer with them rather than with a generic placeholder.
|
|
7
|
+
*
|
|
8
|
+
* They are also the candidates for a schema-shaped answer: a property named
|
|
9
|
+
* `summary` gets this value when it satisfies that property's schema, and a
|
|
10
|
+
* schema-driven value when it does not.
|
|
11
|
+
*/
|
|
12
|
+
/** Field name → the value the mock answers with. */
|
|
13
|
+
export declare const KNOWN_FIELDS: Record<string, unknown>;
|
|
14
|
+
export declare function mockValueForField(field: string): unknown;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — the values the mock knows by field name.
|
|
3
|
+
*
|
|
4
|
+
* These are the shapes the published example pipelines assert on
|
|
5
|
+
* (`markdown_report` matches /Mock report/, `summary.test_score >= 1`), so
|
|
6
|
+
* the mock has to answer with them rather than with a generic placeholder.
|
|
7
|
+
*
|
|
8
|
+
* They are also the candidates for a schema-shaped answer: a property named
|
|
9
|
+
* `summary` gets this value when it satisfies that property's schema, and a
|
|
10
|
+
* schema-driven value when it does not.
|
|
11
|
+
*/
|
|
12
|
+
/** Field name → the value the mock answers with. */
|
|
13
|
+
export const KNOWN_FIELDS = {
|
|
14
|
+
findings: [{ severity: 'high', line: 10, description: 'mock finding: unsanitized input', fix_suggestion: 'sanitize input', cwe_id: 'CWE-89', confidence: 0.9 }],
|
|
15
|
+
summary: { total_findings: 1, critical_count: 0, high_count: 1, medium_count: 0, low_count: 0, overall_risk_score: 7.5, total_packages: 3, vulnerable_count: 1, perf_score: 6.5, estimated_speedup: 'mock 2x speedup', style_score: 7.0, regions_analyzed: 1, doc_score: 7.0, test_score: 7.0, refactor_score: 7.0, design_score: 7.0, endpoints_reviewed: 1, units_analyzed: 1 },
|
|
16
|
+
recommendations: ['mock recommendation: sanitize inputs'],
|
|
17
|
+
markdown_report: '# Mock report\n\nMock summary.\n',
|
|
18
|
+
packages: [{ name: 'mock-pkg', version: '1.0.0', is_vulnerable: true, cves: [{ id: 'CVE-2024-0001', severity: 'high', description: 'mock CVE', fix_version: '1.0.1', confidence: 0.9 }], fix_version: '1.0.1' }],
|
|
19
|
+
stats: { lines_scanned: 10, hunks_scanned: 1 },
|
|
20
|
+
rejected: [],
|
|
21
|
+
new_findings_count: 0,
|
|
22
|
+
};
|
|
23
|
+
export function mockValueForField(field) {
|
|
24
|
+
return field in KNOWN_FIELDS ? KNOWN_FIELDS[field] : `mock-${field}`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — a mock answer that satisfies a JSON Schema.
|
|
3
|
+
*
|
|
4
|
+
* The mock used to answer by field name (`mockValueForField`), and a stage
|
|
5
|
+
* that declares `output_schema` without `fields` got `{"result":"mock-output"}`
|
|
6
|
+
* — which no schema accepts. So a spec with an output schema was not
|
|
7
|
+
* executable in mock mode: the stage failed its own validation and the test
|
|
8
|
+
* errored out. The runtime validated the answer correctly; the mock simply
|
|
9
|
+
* did not know what was being asked for.
|
|
10
|
+
*
|
|
11
|
+
* This builds the answer from the schema instead: the same shape the prompt
|
|
12
|
+
* asks the model for, so the mock answer passes the check the model answer
|
|
13
|
+
* has to pass. That is what makes `pipeline test` a gate: a spec whose
|
|
14
|
+
* schema cannot be satisfied fails the test, and a spec that can be
|
|
15
|
+
* satisfied passes.
|
|
16
|
+
*
|
|
17
|
+
* The schema is the draft-07 subset the runtime supports (see
|
|
18
|
+
* `output-schema.ts`). Unsupported keywords are rejected by the runtime's
|
|
19
|
+
* own meta-validation before this ever runs, so the shapes handled here are
|
|
20
|
+
* the ones the runtime accepts.
|
|
21
|
+
*/
|
|
22
|
+
import type { JsonSchema } from '../output-schema.js';
|
|
23
|
+
/**
|
|
24
|
+
* A value that satisfies `schema`.
|
|
25
|
+
*
|
|
26
|
+
* Every `properties` entry gets a value — not only the required ones — so
|
|
27
|
+
* that a schema which asks for optional fields is still answered completely.
|
|
28
|
+
* A schema with no `properties` at all yields `{}`, which is the honest
|
|
29
|
+
* answer: there is nothing to produce.
|
|
30
|
+
*/
|
|
31
|
+
export declare function mockValueForSchema(schema: JsonSchema | undefined, depth?: number): unknown;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — a mock answer that satisfies a JSON Schema.
|
|
3
|
+
*
|
|
4
|
+
* The mock used to answer by field name (`mockValueForField`), and a stage
|
|
5
|
+
* that declares `output_schema` without `fields` got `{"result":"mock-output"}`
|
|
6
|
+
* — which no schema accepts. So a spec with an output schema was not
|
|
7
|
+
* executable in mock mode: the stage failed its own validation and the test
|
|
8
|
+
* errored out. The runtime validated the answer correctly; the mock simply
|
|
9
|
+
* did not know what was being asked for.
|
|
10
|
+
*
|
|
11
|
+
* This builds the answer from the schema instead: the same shape the prompt
|
|
12
|
+
* asks the model for, so the mock answer passes the check the model answer
|
|
13
|
+
* has to pass. That is what makes `pipeline test` a gate: a spec whose
|
|
14
|
+
* schema cannot be satisfied fails the test, and a spec that can be
|
|
15
|
+
* satisfied passes.
|
|
16
|
+
*
|
|
17
|
+
* The schema is the draft-07 subset the runtime supports (see
|
|
18
|
+
* `output-schema.ts`). Unsupported keywords are rejected by the runtime's
|
|
19
|
+
* own meta-validation before this ever runs, so the shapes handled here are
|
|
20
|
+
* the ones the runtime accepts.
|
|
21
|
+
*/
|
|
22
|
+
import { validateAgainstSchema } from '../output-schema-validate.js';
|
|
23
|
+
import { KNOWN_FIELDS, mockValueForField } from './mock-fields.js';
|
|
24
|
+
/** Depth guard, mirroring the runtime's own validation bound. */
|
|
25
|
+
const MAX_DEPTH = 32;
|
|
26
|
+
/**
|
|
27
|
+
* A value that satisfies `schema`.
|
|
28
|
+
*
|
|
29
|
+
* Every `properties` entry gets a value — not only the required ones — so
|
|
30
|
+
* that a schema which asks for optional fields is still answered completely.
|
|
31
|
+
* A schema with no `properties` at all yields `{}`, which is the honest
|
|
32
|
+
* answer: there is nothing to produce.
|
|
33
|
+
*/
|
|
34
|
+
export function mockValueForSchema(schema, depth = 0) {
|
|
35
|
+
if (!schema || depth > MAX_DEPTH)
|
|
36
|
+
return {};
|
|
37
|
+
// An enum is a closed set: the first value is the answer.
|
|
38
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0)
|
|
39
|
+
return schema.enum[0];
|
|
40
|
+
const type = pickType(schema);
|
|
41
|
+
switch (type) {
|
|
42
|
+
case 'object': {
|
|
43
|
+
const obj = {};
|
|
44
|
+
for (const [key, sub] of Object.entries(schema.properties ?? {})) {
|
|
45
|
+
obj[key] = valueForProperty(key, sub, depth + 1);
|
|
46
|
+
}
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
case 'array': {
|
|
50
|
+
const items = schema.items;
|
|
51
|
+
if (!items)
|
|
52
|
+
return [];
|
|
53
|
+
// One element is enough to satisfy `minItems: 1` and to show the shape.
|
|
54
|
+
return [mockValueForSchema(items, depth + 1)];
|
|
55
|
+
}
|
|
56
|
+
case 'string':
|
|
57
|
+
return mockString(schema);
|
|
58
|
+
case 'integer':
|
|
59
|
+
return 1;
|
|
60
|
+
case 'number':
|
|
61
|
+
return 1;
|
|
62
|
+
case 'boolean':
|
|
63
|
+
return true;
|
|
64
|
+
case 'null':
|
|
65
|
+
return null;
|
|
66
|
+
default:
|
|
67
|
+
// No type declared: an object is the safest answer, because a schema
|
|
68
|
+
// without a type accepts an object.
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The value for one property.
|
|
74
|
+
*
|
|
75
|
+
* A property the mock knows by name gets that value — but only when the
|
|
76
|
+
* value actually satisfies this property's schema. Otherwise the schema
|
|
77
|
+
* decides, because a known value that does not fit the schema is a worse
|
|
78
|
+
* answer than a generic one that does.
|
|
79
|
+
*/
|
|
80
|
+
function valueForProperty(key, schema, depth) {
|
|
81
|
+
const known = key in KNOWN_FIELDS ? KNOWN_FIELDS[key] : mockValueForField(key);
|
|
82
|
+
if (validateAgainstSchema(known, schema).length === 0)
|
|
83
|
+
return known;
|
|
84
|
+
return mockValueForSchema(schema, depth);
|
|
85
|
+
}
|
|
86
|
+
function pickType(schema) {
|
|
87
|
+
const declared = schema.type;
|
|
88
|
+
if (Array.isArray(declared)) {
|
|
89
|
+
// The first type that is not null — null alone would answer "nothing".
|
|
90
|
+
return declared.find((t) => t !== 'null') ?? 'null';
|
|
91
|
+
}
|
|
92
|
+
if (typeof declared === 'string')
|
|
93
|
+
return declared;
|
|
94
|
+
if (schema.properties)
|
|
95
|
+
return 'object';
|
|
96
|
+
if (schema.items)
|
|
97
|
+
return 'array';
|
|
98
|
+
return 'object';
|
|
99
|
+
}
|
|
100
|
+
function mockString(schema) {
|
|
101
|
+
const min = schema.minLength ?? 0;
|
|
102
|
+
let value = 'mock';
|
|
103
|
+
if (value.length < min)
|
|
104
|
+
value = value.padEnd(min, 'x');
|
|
105
|
+
if (schema.pattern) {
|
|
106
|
+
// A pattern cannot be satisfied by guessing. The honest answer is a
|
|
107
|
+
// string that at least honours the length, and the test fails on the
|
|
108
|
+
// pattern — which is the point: a schema nobody can satisfy is a spec
|
|
109
|
+
// nobody can run.
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
package/dist/testing/runner.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface SingleTestResult {
|
|
|
12
12
|
output?: unknown;
|
|
13
13
|
}
|
|
14
14
|
export declare function buildMockProvider(): LLMProvider;
|
|
15
|
-
export
|
|
15
|
+
export { mockValueForField } from './mock-fields.js';
|
|
16
16
|
export interface RunTestOptions {
|
|
17
17
|
baseDir?: string;
|
|
18
18
|
timeoutMs?: number;
|
package/dist/testing/runner.js
CHANGED
|
@@ -9,6 +9,8 @@ import { createModelResolver } from '../model-resolver.js';
|
|
|
9
9
|
import { StaticPricingResolver } from '../pricing.js';
|
|
10
10
|
import { LLMProviderRegistry } from '../provider-registry.js';
|
|
11
11
|
import { runAssertion } from './assertions.js';
|
|
12
|
+
import { mockValueForSchema } from './mock-schema.js';
|
|
13
|
+
import { mockValueForField } from './mock-fields.js';
|
|
12
14
|
import { extractStage } from './stage-extractor.js';
|
|
13
15
|
export function buildMockProvider() {
|
|
14
16
|
return {
|
|
@@ -25,13 +27,20 @@ export function buildMockProvider() {
|
|
|
25
27
|
async generateText(prompt, opts) {
|
|
26
28
|
await new Promise((r) => setTimeout(r, 5));
|
|
27
29
|
const fields = opts?.fields ?? [];
|
|
30
|
+
// A stage that declares an output schema is validated against it, and
|
|
31
|
+
// the mock has to answer the shape the schema asks for — a mock answer
|
|
32
|
+
// that does not satisfy the schema fails the stage's own validation,
|
|
33
|
+
// and the test errors out instead of testing anything.
|
|
34
|
+
if (opts?.outputSchema) {
|
|
35
|
+
const shaped = mockValueForSchema(opts.outputSchema);
|
|
36
|
+
return { text: JSON.stringify(shaped), usage: { inputTokens: 10, outputTokens: 10 } };
|
|
37
|
+
}
|
|
28
38
|
if (opts?.outputFormat === 'structured_json' || fields.length > 0) {
|
|
29
39
|
const obj = {};
|
|
30
40
|
for (const f of fields)
|
|
31
41
|
obj[f] = mockValueForField(f);
|
|
32
42
|
if (Object.keys(obj).length === 0)
|
|
33
43
|
obj['result'] = 'mock-output';
|
|
34
|
-
void prompt;
|
|
35
44
|
return { text: JSON.stringify(obj), usage: { inputTokens: 10, outputTokens: 10 } };
|
|
36
45
|
}
|
|
37
46
|
if (opts?.outputFormat === 'markdown')
|
|
@@ -42,19 +51,7 @@ export function buildMockProvider() {
|
|
|
42
51
|
},
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
|
-
export
|
|
46
|
-
switch (field) {
|
|
47
|
-
case 'findings': return [{ severity: 'high', line: 10, description: 'mock finding: unsanitized input', fix_suggestion: 'sanitize input', cwe_id: 'CWE-89', confidence: 0.9 }];
|
|
48
|
-
case 'summary': return { total_findings: 1, critical_count: 0, high_count: 1, medium_count: 0, low_count: 0, overall_risk_score: 7.5, total_packages: 3, vulnerable_count: 1, perf_score: 6.5, estimated_speedup: 'mock 2x speedup', style_score: 7.0, regions_analyzed: 1, doc_score: 7.0, test_score: 7.0, refactor_score: 7.0, design_score: 7.0, endpoints_reviewed: 1, units_analyzed: 1 };
|
|
49
|
-
case 'recommendations': return ['mock recommendation: sanitize inputs'];
|
|
50
|
-
case 'markdown_report': return '# Mock report\n\nMock summary.\n';
|
|
51
|
-
case 'packages': return [{ name: 'mock-pkg', version: '1.0.0', is_vulnerable: true, cves: [{ id: 'CVE-2024-0001', severity: 'high', description: 'mock CVE', fix_version: '1.0.1', confidence: 0.9 }], fix_version: '1.0.1' }];
|
|
52
|
-
case 'stats': return { lines_scanned: 10, hunks_scanned: 1 };
|
|
53
|
-
case 'rejected': return [];
|
|
54
|
-
case 'new_findings_count': return 0;
|
|
55
|
-
default: return `mock-${field}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
54
|
+
export { mockValueForField } from './mock-fields.js';
|
|
58
55
|
function buildLocalFetcher(pipelineDir) {
|
|
59
56
|
return async (id) => {
|
|
60
57
|
const candidate = path.join(pipelineDir, `${id}.yaml`);
|
package/dist/types.d.ts
CHANGED
|
@@ -54,6 +54,17 @@ export interface GenerateOptions {
|
|
|
54
54
|
* demo/QA without a real LLM.
|
|
55
55
|
*/
|
|
56
56
|
outputFormat?: OutputFormat;
|
|
57
|
+
/**
|
|
58
|
+
* The stage's `output_schema`, when it has one.
|
|
59
|
+
*
|
|
60
|
+
* The executor validates the answer against this schema before the next
|
|
61
|
+
* stage runs, so a mock that does not know the schema cannot produce a
|
|
62
|
+
* valid answer: the stage fails its own validation and the test errors
|
|
63
|
+
* out instead of testing anything. A provider that can shape its answer
|
|
64
|
+
* (the mock) uses this; a real provider ignores it and answers the
|
|
65
|
+
* prompt, which asks for the same shape.
|
|
66
|
+
*/
|
|
67
|
+
outputSchema?: import('./output-schema.js').JsonSchema;
|
|
57
68
|
/**
|
|
58
69
|
* M1 NEW — Multimodal messages (image / audio / video parts). When set,
|
|
59
70
|
* takes precedence over the string `prompt` argument. Adapters transform
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentsmarket/pipeline-runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"description": "Runtime for executing PIPELINE.md workflows (multi-skill orchestration). Provider-agnostic (MiniMax, Claude, OpenAI).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
"dist",
|
|
10
10
|
"README.md"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:coverage": "vitest run --coverage",
|
|
16
|
+
"dev": "tsx src/index.ts",
|
|
17
|
+
"lint": "tsc --noEmit",
|
|
18
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
19
|
+
},
|
|
12
20
|
"dependencies": {
|
|
13
21
|
"@anthropic-ai/sdk": "^0.135.0",
|
|
14
22
|
"@hono/node-server": "^1.13.0",
|
|
@@ -34,13 +42,5 @@
|
|
|
34
42
|
"publishConfig": {
|
|
35
43
|
"access": "public"
|
|
36
44
|
},
|
|
37
|
-
"types": "./dist/index.d.ts"
|
|
38
|
-
|
|
39
|
-
"build": "tsc",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"test:coverage": "vitest run --coverage",
|
|
42
|
-
"dev": "tsx src/index.ts",
|
|
43
|
-
"lint": "tsc --noEmit",
|
|
44
|
-
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
45
|
+
"types": "./dist/index.d.ts"
|
|
46
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 agentsmarket.world contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|