@agentsmarket/pipeline-runtime 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -1
- package/dist/adapters/minimax.d.ts +16 -8
- package/dist/adapters/minimax.js +105 -26
- package/dist/adapters/multimodal-convert.d.ts +54 -0
- package/dist/adapters/multimodal-convert.js +105 -0
- package/dist/adapters/openrouter.d.ts +5 -0
- package/dist/adapters/openrouter.js +53 -6
- package/dist/index.d.ts +20 -4
- package/dist/index.js +15 -3
- package/dist/loop.d.ts +90 -0
- package/dist/loop.js +200 -0
- package/dist/memory.d.ts +73 -0
- package/dist/memory.js +119 -0
- package/dist/model-resolver.d.ts +52 -1
- package/dist/multimodal.d.ts +43 -0
- package/dist/multimodal.js +23 -0
- package/dist/output-errors.d.ts +93 -0
- package/dist/output-errors.js +128 -0
- package/dist/output-schema-validate.d.ts +10 -0
- package/dist/output-schema-validate.js +149 -0
- package/dist/output-schema.d.ts +66 -0
- package/dist/output-schema.js +141 -0
- package/dist/pipeline-refs.d.ts +15 -0
- package/dist/pipeline-refs.js +155 -0
- package/dist/provider-registry.d.ts +22 -1
- package/dist/provider-registry.js +62 -2
- package/dist/providers/anthropic.d.ts +28 -0
- package/dist/providers/anthropic.js +118 -0
- package/dist/providers/openai-chat.d.ts +28 -0
- package/dist/providers/openai-chat.js +106 -0
- package/dist/providers/openai-dalle.d.ts +19 -0
- package/dist/providers/openai-dalle.js +41 -0
- package/dist/providers/openai-tts.d.ts +19 -0
- package/dist/providers/openai-tts.js +46 -0
- package/dist/providers/openai-vision.d.ts +15 -0
- package/dist/providers/openai-vision.js +43 -0
- package/dist/providers/openai-whisper.d.ts +16 -0
- package/dist/providers/openai-whisper.js +43 -0
- package/dist/providers/replicate.d.ts +19 -0
- package/dist/providers/replicate.js +61 -0
- package/dist/providers/types.d.ts +23 -0
- package/dist/providers/types.js +31 -0
- package/dist/runtime-constraints.d.ts +2 -1
- package/dist/stages.d.ts +14 -2
- package/dist/stages.js +339 -34
- package/dist/streaming-events.d.ts +17 -2
- package/dist/streaming-events.js +12 -0
- package/dist/testing/assertions.d.ts +17 -0
- package/dist/testing/assertions.js +149 -0
- package/dist/testing/conformance.d.ts +3 -0
- package/dist/testing/conformance.js +28 -0
- package/dist/testing/coverage.d.ts +11 -0
- package/dist/testing/coverage.js +35 -0
- package/dist/testing/index.d.ts +9 -0
- package/dist/testing/index.js +9 -0
- package/dist/testing/reporters/json.d.ts +5 -0
- package/dist/testing/reporters/json.js +23 -0
- package/dist/testing/reporters/junit.d.ts +5 -0
- package/dist/testing/reporters/junit.js +31 -0
- package/dist/testing/reporters/text.d.ts +5 -0
- package/dist/testing/reporters/text.js +36 -0
- package/dist/testing/runner.d.ts +25 -0
- package/dist/testing/runner.js +222 -0
- package/dist/testing/spec-parser.d.ts +366 -0
- package/dist/testing/spec-parser.js +60 -0
- package/dist/testing/stage-extractor.d.ts +16 -0
- package/dist/testing/stage-extractor.js +25 -0
- package/dist/tools/audio-transcribe.d.ts +11 -0
- package/dist/tools/audio-transcribe.js +45 -0
- package/dist/tools/image-describe.d.ts +12 -0
- package/dist/tools/image-describe.js +47 -0
- package/dist/tools/image-generate.d.ts +12 -0
- package/dist/tools/image-generate.js +47 -0
- package/dist/tools/memory-recall.d.ts +13 -0
- package/dist/tools/memory-recall.js +63 -0
- package/dist/tools/memory-shared.d.ts +8 -0
- package/dist/tools/memory-shared.js +8 -0
- package/dist/tools/memory-store.d.ts +14 -0
- package/dist/tools/memory-store.js +68 -0
- package/dist/tools/tool-skills.js +14 -0
- package/dist/tools/tts-synthesize.d.ts +12 -0
- package/dist/tools/tts-synthesize.js +50 -0
- package/dist/tools/video-generate.d.ts +12 -0
- package/dist/tools/video-generate.js +47 -0
- package/dist/types.d.ts +8 -0
- package/dist/validate-inputs.d.ts +115 -0
- package/dist/validate-inputs.js +273 -0
- package/package.json +3 -3
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — 8 assertion types for pipeline test specs.
|
|
3
|
+
*
|
|
4
|
+
* Each: (output, assertion) => AssertionResult. Pure, synchronous except
|
|
5
|
+
* `schema` which reads a file synchronously via injected loader.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import { deepEqual } from '../output-schema.js';
|
|
10
|
+
import { validateAgainstSchema } from '../output-schema-validate.js';
|
|
11
|
+
/** Traverse dot path with [n] array indices. Returns {found, value}. */
|
|
12
|
+
export function getPath(root, dotPath) {
|
|
13
|
+
if (dotPath === '' || dotPath === '$')
|
|
14
|
+
return { found: true, value: root };
|
|
15
|
+
const normalized = dotPath.replace(/^\$\.?/, '');
|
|
16
|
+
if (normalized === '')
|
|
17
|
+
return { found: true, value: root };
|
|
18
|
+
const tokens = normalized.split('.').filter((t) => t.length > 0);
|
|
19
|
+
let cur = root;
|
|
20
|
+
for (const tok of tokens) {
|
|
21
|
+
const m = tok.match(/^([A-Za-z_][A-Za-z0-9_]*)((\[\d+\])*)$/);
|
|
22
|
+
if (!m)
|
|
23
|
+
return { found: false };
|
|
24
|
+
const key = m[1];
|
|
25
|
+
if (cur === null || typeof cur !== 'object' || Array.isArray(cur))
|
|
26
|
+
return { found: false };
|
|
27
|
+
cur = cur[key];
|
|
28
|
+
if (cur === undefined)
|
|
29
|
+
return { found: false };
|
|
30
|
+
const idxs = m[2] ? [...m[2].matchAll(/\[(\d+)\]/g)].map((x) => Number(x[1])) : [];
|
|
31
|
+
for (const i of idxs) {
|
|
32
|
+
if (!Array.isArray(cur) || i >= cur.length)
|
|
33
|
+
return { found: false };
|
|
34
|
+
cur = cur[i];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { found: true, value: cur };
|
|
38
|
+
}
|
|
39
|
+
function ok(message, expected, actual, t0) {
|
|
40
|
+
return { passed: true, message, expected, actual, duration_ms: t0 !== undefined ? Date.now() - t0 : 0 };
|
|
41
|
+
}
|
|
42
|
+
function fail(message, expected, actual, t0) {
|
|
43
|
+
return { passed: false, message, expected, actual, duration_ms: t0 !== undefined ? Date.now() - t0 : 0 };
|
|
44
|
+
}
|
|
45
|
+
export function runAssertion(output, assertion, ctx = {}) {
|
|
46
|
+
const t0 = Date.now();
|
|
47
|
+
switch (assertion.type) {
|
|
48
|
+
case 'equality': {
|
|
49
|
+
const r = getPath(output, assertion.path);
|
|
50
|
+
if (!r.found)
|
|
51
|
+
return fail(`equality: ${assertion.path} not found`, assertion.value, undefined, t0);
|
|
52
|
+
if (deepEqual(r.value, assertion.value))
|
|
53
|
+
return ok(`equality: ${assertion.path} == ${JSON.stringify(assertion.value)}`, assertion.value, r.value, t0);
|
|
54
|
+
return fail(`equality: ${assertion.path} != ${JSON.stringify(assertion.value)} (got ${JSON.stringify(r.value)})`, assertion.value, r.value, t0);
|
|
55
|
+
}
|
|
56
|
+
case 'contains': {
|
|
57
|
+
const r = getPath(output, assertion.path);
|
|
58
|
+
if (!r.found)
|
|
59
|
+
return fail(`contains: ${assertion.path} not found`, assertion.value, undefined, t0);
|
|
60
|
+
const v = r.value;
|
|
61
|
+
if (typeof v === 'string' && typeof assertion.value === 'string') {
|
|
62
|
+
return v.includes(assertion.value)
|
|
63
|
+
? ok(`contains: ${assertion.path} contains "${assertion.value}"`, assertion.value, v, t0)
|
|
64
|
+
: fail(`contains: ${assertion.path} does not contain "${assertion.value}"`, assertion.value, v, t0);
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(v)) {
|
|
67
|
+
return v.some((el) => deepEqual(el, assertion.value))
|
|
68
|
+
? ok(`contains: ${assertion.path} includes ${JSON.stringify(assertion.value)}`, assertion.value, v, t0)
|
|
69
|
+
: fail(`contains: ${assertion.path} does not include ${JSON.stringify(assertion.value)}`, assertion.value, v, t0);
|
|
70
|
+
}
|
|
71
|
+
return fail(`contains: ${assertion.path} is neither string nor array`, assertion.value, v, t0);
|
|
72
|
+
}
|
|
73
|
+
case 'regex': {
|
|
74
|
+
const r = getPath(output, assertion.path);
|
|
75
|
+
if (!r.found)
|
|
76
|
+
return fail(`regex: ${assertion.path} not found`, assertion.pattern, undefined, t0);
|
|
77
|
+
if (typeof r.value !== 'string')
|
|
78
|
+
return fail(`regex: ${assertion.path} is not a string`, assertion.pattern, r.value, t0);
|
|
79
|
+
let re;
|
|
80
|
+
try {
|
|
81
|
+
re = new RegExp(assertion.pattern, assertion.flags);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return fail(`regex: invalid pattern /${assertion.pattern}/: ${e.message}`, assertion.pattern, r.value, t0);
|
|
85
|
+
}
|
|
86
|
+
return re.test(r.value)
|
|
87
|
+
? ok(`regex: ${assertion.path} matches /${assertion.pattern}/${assertion.flags ?? ''}`, assertion.pattern, r.value, t0)
|
|
88
|
+
: fail(`regex: ${assertion.path} does not match /${assertion.pattern}/${assertion.flags ?? ''}`, assertion.pattern, r.value, t0);
|
|
89
|
+
}
|
|
90
|
+
case 'gte':
|
|
91
|
+
case 'lte':
|
|
92
|
+
case 'gt':
|
|
93
|
+
case 'lt': {
|
|
94
|
+
const r = getPath(output, assertion.path);
|
|
95
|
+
if (!r.found)
|
|
96
|
+
return fail(`${assertion.type}: ${assertion.path} not found`, assertion.value, undefined, t0);
|
|
97
|
+
if (typeof r.value !== 'number')
|
|
98
|
+
return fail(`${assertion.type}: ${assertion.path} is not a number`, assertion.value, r.value, t0);
|
|
99
|
+
const ops = {
|
|
100
|
+
gte: (a, b) => a >= b, lte: (a, b) => a <= b, gt: (a, b) => a > b, lt: (a, b) => a < b,
|
|
101
|
+
};
|
|
102
|
+
const symbols = { gte: '>=', lte: '<=', gt: '>', lt: '<' };
|
|
103
|
+
const pass = ops[assertion.type](r.value, assertion.value);
|
|
104
|
+
return pass
|
|
105
|
+
? ok(`${assertion.type}: ${assertion.path} ${symbols[assertion.type]} ${assertion.value}`, assertion.value, r.value, t0)
|
|
106
|
+
: fail(`${assertion.type}: ${assertion.path} ${symbols[assertion.type]} ${assertion.value} (got ${r.value})`, assertion.value, r.value, t0);
|
|
107
|
+
}
|
|
108
|
+
case 'exists': {
|
|
109
|
+
const r = getPath(output, assertion.path);
|
|
110
|
+
return r.found ? ok(`exists: ${assertion.path} present`, undefined, r.value, t0) : fail(`exists: ${assertion.path} missing`, undefined, undefined, t0);
|
|
111
|
+
}
|
|
112
|
+
case 'absent': {
|
|
113
|
+
const r = getPath(output, assertion.path);
|
|
114
|
+
return !r.found ? ok(`absent: ${assertion.path} absent`, undefined, undefined, t0) : fail(`absent: ${assertion.path} present (expected absent)`, undefined, r.value, t0);
|
|
115
|
+
}
|
|
116
|
+
case 'jsonpath': {
|
|
117
|
+
const r = getPath(output, assertion.path);
|
|
118
|
+
if (!r.found)
|
|
119
|
+
return fail(`jsonpath: ${assertion.path} not found`, assertion.value, undefined, t0);
|
|
120
|
+
if (deepEqual(r.value, assertion.value))
|
|
121
|
+
return ok(`jsonpath: ${assertion.path} == ${JSON.stringify(assertion.value)}`, assertion.value, r.value, t0);
|
|
122
|
+
return fail(`jsonpath: ${assertion.path} != ${JSON.stringify(assertion.value)} (got ${JSON.stringify(r.value)})`, assertion.value, r.value, t0);
|
|
123
|
+
}
|
|
124
|
+
case 'schema': {
|
|
125
|
+
const r = getPath(output, assertion.path);
|
|
126
|
+
if (!r.found)
|
|
127
|
+
return fail(`schema: ${assertion.path} not found`, assertion.schema_file, undefined, t0);
|
|
128
|
+
const schemaPath = ctx.baseDir ? path.resolve(ctx.baseDir, assertion.schema_file) : path.resolve(assertion.schema_file);
|
|
129
|
+
let schemaRaw;
|
|
130
|
+
try {
|
|
131
|
+
schemaRaw = fs.readFileSync(schemaPath, 'utf8');
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return fail(`schema: cannot read schema file ${assertion.schema_file}`, assertion.schema_file, undefined, t0);
|
|
135
|
+
}
|
|
136
|
+
let schema;
|
|
137
|
+
try {
|
|
138
|
+
schema = JSON.parse(schemaRaw);
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
return fail(`schema: invalid JSON in ${assertion.schema_file}: ${e.message}`, assertion.schema_file, undefined, t0);
|
|
142
|
+
}
|
|
143
|
+
const violations = validateAgainstSchema(r.value, schema);
|
|
144
|
+
if (violations.length === 0)
|
|
145
|
+
return ok(`schema: ${assertion.path} valid against ${assertion.schema_file}`, assertion.schema_file, r.value, t0);
|
|
146
|
+
return fail(`schema: ${assertion.path} invalid against ${assertion.schema_file}: ${violations.map((v) => `${v.path}: ${v.message}`).join('; ')}`, assertion.schema_file, r.value, t0);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — conformance test runner (thin wrapper over runTestSuite).
|
|
3
|
+
*/
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { parseTestSpec } from './spec-parser.js';
|
|
7
|
+
import { runTestSuite } from './runner.js';
|
|
8
|
+
export async function discoverTestFiles(dir) {
|
|
9
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const e of entries) {
|
|
12
|
+
const full = path.join(dir, e.name);
|
|
13
|
+
if (e.isDirectory())
|
|
14
|
+
out.push(...(await discoverTestFiles(full)));
|
|
15
|
+
else if (e.isFile() && e.name.endsWith('.test.yaml'))
|
|
16
|
+
out.push(full);
|
|
17
|
+
}
|
|
18
|
+
return out.sort();
|
|
19
|
+
}
|
|
20
|
+
export async function runConformanceDir(dir, opts = {}) {
|
|
21
|
+
const files = await discoverTestFiles(dir);
|
|
22
|
+
const specs = files.map((f) => {
|
|
23
|
+
const raw = fs.readFileSync(f, 'utf8');
|
|
24
|
+
const spec = parseTestSpec(raw);
|
|
25
|
+
return { spec, file: f };
|
|
26
|
+
});
|
|
27
|
+
return runTestSuite(specs.map((s) => s.spec), { ...opts, baseDir: opts.baseDir ?? dir });
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SingleTestResult } from './runner.js';
|
|
2
|
+
export interface CoverageReport {
|
|
3
|
+
pipeline: string;
|
|
4
|
+
stages: string[];
|
|
5
|
+
covered: string[];
|
|
6
|
+
uncovered: string[];
|
|
7
|
+
coverage_pct: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function computeCoverage(pipelineYamlText: string, results: SingleTestResult[], pipelineLabel?: string): CoverageReport;
|
|
10
|
+
export declare function renderCoverageText(reports: CoverageReport[]): string;
|
|
11
|
+
export declare function loadCoverageForPipeline(pipelinePath: string, results: SingleTestResult[]): CoverageReport;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — stage coverage report: which stages were exercised by a test suite.
|
|
3
|
+
*/
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import { loadPipelineYaml } from '../resolve-vars.js';
|
|
6
|
+
export function computeCoverage(pipelineYamlText, results, pipelineLabel = 'pipeline') {
|
|
7
|
+
const spec = loadPipelineYaml(pipelineYamlText);
|
|
8
|
+
const stages = (spec.stages ?? []).map((s) => String(s.id ?? ''));
|
|
9
|
+
const coveredSet = new Set();
|
|
10
|
+
for (const r of results) {
|
|
11
|
+
const out = r.output;
|
|
12
|
+
if (!out || typeof out !== 'object')
|
|
13
|
+
continue;
|
|
14
|
+
for (const id of stages) {
|
|
15
|
+
if (id in out)
|
|
16
|
+
coveredSet.add(id);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const covered = stages.filter((s) => coveredSet.has(s));
|
|
20
|
+
const uncovered = stages.filter((s) => !coveredSet.has(s));
|
|
21
|
+
return { pipeline: pipelineLabel, stages, covered, uncovered, coverage_pct: stages.length === 0 ? 100 : Math.round((covered.length / stages.length) * 100) };
|
|
22
|
+
}
|
|
23
|
+
export function renderCoverageText(reports) {
|
|
24
|
+
const lines = ['Coverage:'];
|
|
25
|
+
for (const r of reports) {
|
|
26
|
+
lines.push(` ${r.pipeline}: ${r.coverage_pct}% (${r.covered.length}/${r.stages.length} stages)`);
|
|
27
|
+
if (r.uncovered.length > 0)
|
|
28
|
+
lines.push(` uncovered: ${r.uncovered.join(', ')}`);
|
|
29
|
+
}
|
|
30
|
+
return lines.join('\n');
|
|
31
|
+
}
|
|
32
|
+
export function loadCoverageForPipeline(pipelinePath, results) {
|
|
33
|
+
const raw = fs.readFileSync(pipelinePath, 'utf8');
|
|
34
|
+
return computeCoverage(raw, results, pipelinePath);
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { parseTestSpec, loadTestSpecFile, TestSpecParseError, type TestSpec, type Assertion } from './spec-parser.js';
|
|
2
|
+
export { runAssertion, getPath, type AssertionResult, type AssertionContext } from './assertions.js';
|
|
3
|
+
export { runSingleTest, runTestSuite, mockValueForField, buildMockProvider, type SingleTestResult, type RunTestOptions, type RunSuiteOptions } from './runner.js';
|
|
4
|
+
export { extractStage, StageNotFoundInSpecError, type ExtractedStage } from './stage-extractor.js';
|
|
5
|
+
export { renderText } from './reporters/text.js';
|
|
6
|
+
export { renderJson } from './reporters/json.js';
|
|
7
|
+
export { renderJunit } from './reporters/junit.js';
|
|
8
|
+
export { computeCoverage, renderCoverageText, loadCoverageForPipeline, type CoverageReport } from './coverage.js';
|
|
9
|
+
export { discoverTestFiles, runConformanceDir } from './conformance.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { parseTestSpec, loadTestSpecFile, TestSpecParseError } from './spec-parser.js';
|
|
2
|
+
export { runAssertion, getPath } from './assertions.js';
|
|
3
|
+
export { runSingleTest, runTestSuite, mockValueForField, buildMockProvider } from './runner.js';
|
|
4
|
+
export { extractStage, StageNotFoundInSpecError } from './stage-extractor.js';
|
|
5
|
+
export { renderText } from './reporters/text.js';
|
|
6
|
+
export { renderJson } from './reporters/json.js';
|
|
7
|
+
export { renderJunit } from './reporters/junit.js';
|
|
8
|
+
export { computeCoverage, renderCoverageText, loadCoverageForPipeline } from './coverage.js';
|
|
9
|
+
export { discoverTestFiles, runConformanceDir } from './conformance.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function renderJson(results) {
|
|
2
|
+
let passed = 0;
|
|
3
|
+
let failed = 0;
|
|
4
|
+
let skipped = 0;
|
|
5
|
+
let duration_ms = 0;
|
|
6
|
+
const tests = results.map((r) => {
|
|
7
|
+
duration_ms += r.duration_ms;
|
|
8
|
+
if (r.status === 'passed')
|
|
9
|
+
passed++;
|
|
10
|
+
else if (r.status === 'skipped')
|
|
11
|
+
skipped++;
|
|
12
|
+
else
|
|
13
|
+
failed++;
|
|
14
|
+
return {
|
|
15
|
+
name: r.name,
|
|
16
|
+
status: r.status,
|
|
17
|
+
duration_ms: r.duration_ms,
|
|
18
|
+
...(r.error ? { error: r.error } : {}),
|
|
19
|
+
assertions: r.assertions.map((a) => ({ type: a.type, passed: a.passed, message: a.message, duration_ms: a.duration_ms })),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
return JSON.stringify({ passed, failed, skipped, duration_ms, tests }, null, 2);
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function esc(s) {
|
|
2
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
3
|
+
}
|
|
4
|
+
export function renderJunit(results) {
|
|
5
|
+
const failures = results.filter((r) => r.status === 'failed' || r.status === 'error').length;
|
|
6
|
+
const totalS = (results.reduce((a, r) => a + r.duration_ms, 0) / 1000).toFixed(3);
|
|
7
|
+
const lines = ['<?xml version="1.0" encoding="UTF-8"?>'];
|
|
8
|
+
lines.push(`<testsuite name="agent-market-pipeline-tests" tests="${results.length}" failures="${failures}" time="${totalS}">`);
|
|
9
|
+
for (const r of results) {
|
|
10
|
+
const t = (r.duration_ms / 1000).toFixed(3);
|
|
11
|
+
const bad = r.status === 'failed' || r.status === 'error';
|
|
12
|
+
if (!bad) {
|
|
13
|
+
lines.push(` <testcase name="${esc(r.name)}" time="${t}"/>`);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
lines.push(` <testcase name="${esc(r.name)}" time="${t}">`);
|
|
17
|
+
const failedAs = r.assertions.filter((a) => !a.passed);
|
|
18
|
+
if (failedAs.length > 0) {
|
|
19
|
+
for (const a of failedAs) {
|
|
20
|
+
lines.push(` <failure type="${esc(a.type)}" message="${esc(a.message)}">${esc(`expected ${JSON.stringify(a.expected)}, got ${JSON.stringify(a.actual)}`)}</failure>`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
lines.push(` <failure type="error" message="${esc(r.error ?? 'unknown error')}">${esc(r.error ?? 'unknown error')}</failure>`);
|
|
25
|
+
}
|
|
26
|
+
lines.push(' </testcase>');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
lines.push('</testsuite>');
|
|
30
|
+
return lines.join('\n');
|
|
31
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function colorize(s, code) {
|
|
2
|
+
if (process.env.NO_COLOR === '1')
|
|
3
|
+
return s;
|
|
4
|
+
return `\u001b[${code}m${s}\u001b[0m`;
|
|
5
|
+
}
|
|
6
|
+
export function renderText(results) {
|
|
7
|
+
const lines = [];
|
|
8
|
+
let passed = 0;
|
|
9
|
+
let failed = 0;
|
|
10
|
+
let totalMs = 0;
|
|
11
|
+
for (const r of results) {
|
|
12
|
+
totalMs += r.duration_ms;
|
|
13
|
+
if (r.status === 'passed') {
|
|
14
|
+
passed++;
|
|
15
|
+
lines.push(`${colorize('PASS', '32')} ${r.name} (${r.duration_ms}ms)`);
|
|
16
|
+
for (const a of r.assertions)
|
|
17
|
+
lines.push(` ${colorize('✓', '32')} ${a.type}: ${a.message}`);
|
|
18
|
+
}
|
|
19
|
+
else if (r.status === 'skipped') {
|
|
20
|
+
lines.push(`${colorize('SKIP', '33')} ${r.name} (${r.duration_ms}ms)`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
failed++;
|
|
24
|
+
lines.push(`${colorize('FAIL', '31')} ${r.name} (${r.duration_ms}ms)`);
|
|
25
|
+
for (const a of r.assertions) {
|
|
26
|
+
const icon = a.passed ? colorize('✓', '32') : colorize('✗', '31');
|
|
27
|
+
lines.push(` ${icon} ${a.type}: ${a.message}`);
|
|
28
|
+
}
|
|
29
|
+
if (r.error)
|
|
30
|
+
lines.push(` ${colorize('error:', '31')} ${r.error}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
lines.push('');
|
|
34
|
+
lines.push(`Summary: ${passed} passed, ${failed} failed (${(totalMs / 1000).toFixed(1)}s total)`);
|
|
35
|
+
return lines.join('\n');
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LLMProvider } from '../types.js';
|
|
2
|
+
import { type AssertionResult } from './assertions.js';
|
|
3
|
+
import type { TestSpec } from './spec-parser.js';
|
|
4
|
+
export interface SingleTestResult {
|
|
5
|
+
name: string;
|
|
6
|
+
status: 'passed' | 'failed' | 'error' | 'skipped';
|
|
7
|
+
duration_ms: number;
|
|
8
|
+
assertions: Array<AssertionResult & {
|
|
9
|
+
type: string;
|
|
10
|
+
}>;
|
|
11
|
+
error?: string;
|
|
12
|
+
output?: unknown;
|
|
13
|
+
}
|
|
14
|
+
export declare function buildMockProvider(): LLMProvider;
|
|
15
|
+
export declare function mockValueForField(field: string): unknown;
|
|
16
|
+
export interface RunTestOptions {
|
|
17
|
+
baseDir?: string;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function runSingleTest(spec: TestSpec, opts?: RunTestOptions): Promise<SingleTestResult>;
|
|
21
|
+
export interface RunSuiteOptions extends RunTestOptions {
|
|
22
|
+
bail?: boolean;
|
|
23
|
+
parallel?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function runTestSuite(specs: TestSpec[], opts?: RunSuiteOptions): Promise<SingleTestResult[]>;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M9 — test runner: execute a TestSpec in mock mode via runPipelineV2.
|
|
3
|
+
*/
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { loadPipelineYaml } from '../resolve-vars.js';
|
|
7
|
+
import { runPipelineV2 } from '../stages.js';
|
|
8
|
+
import { createModelResolver } from '../model-resolver.js';
|
|
9
|
+
import { StaticPricingResolver } from '../pricing.js';
|
|
10
|
+
import { LLMProviderRegistry } from '../provider-registry.js';
|
|
11
|
+
import { runAssertion } from './assertions.js';
|
|
12
|
+
import { extractStage } from './stage-extractor.js';
|
|
13
|
+
export function buildMockProvider() {
|
|
14
|
+
return {
|
|
15
|
+
name: 'mock',
|
|
16
|
+
models: ['mock-model', 'MiniMax-M2.7', 'MiniMax-M3'],
|
|
17
|
+
simpleModel: 'mock-model',
|
|
18
|
+
complexModel: 'mock-model',
|
|
19
|
+
supports(_model) {
|
|
20
|
+
return true;
|
|
21
|
+
},
|
|
22
|
+
async generateJson(_prompt) {
|
|
23
|
+
return {};
|
|
24
|
+
},
|
|
25
|
+
async generateText(prompt, opts) {
|
|
26
|
+
await new Promise((r) => setTimeout(r, 5));
|
|
27
|
+
const fields = opts?.fields ?? [];
|
|
28
|
+
if (opts?.outputFormat === 'structured_json' || fields.length > 0) {
|
|
29
|
+
const obj = {};
|
|
30
|
+
for (const f of fields)
|
|
31
|
+
obj[f] = mockValueForField(f);
|
|
32
|
+
if (Object.keys(obj).length === 0)
|
|
33
|
+
obj['result'] = 'mock-output';
|
|
34
|
+
void prompt;
|
|
35
|
+
return { text: JSON.stringify(obj), usage: { inputTokens: 10, outputTokens: 10 } };
|
|
36
|
+
}
|
|
37
|
+
if (opts?.outputFormat === 'markdown')
|
|
38
|
+
return { text: '# Mock report\n\nMock summary.\n', usage: { inputTokens: 1, outputTokens: 1 } };
|
|
39
|
+
if (opts?.outputFormat === 'code')
|
|
40
|
+
return { text: '```\n// mock code\n```\n', usage: { inputTokens: 1, outputTokens: 1 } };
|
|
41
|
+
return { text: `mock-output for: ${prompt.slice(0, 80)}`, usage: { inputTokens: 1, outputTokens: 1 } };
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function mockValueForField(field) {
|
|
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
|
+
}
|
|
58
|
+
function buildLocalFetcher(pipelineDir) {
|
|
59
|
+
return async (id) => {
|
|
60
|
+
const candidate = path.join(pipelineDir, `${id}.yaml`);
|
|
61
|
+
if (!fs.existsSync(candidate))
|
|
62
|
+
return null;
|
|
63
|
+
const raw = fs.readFileSync(candidate, 'utf8');
|
|
64
|
+
const spec = loadPipelineYaml(raw);
|
|
65
|
+
if (!spec || !Array.isArray(spec.stages))
|
|
66
|
+
return null;
|
|
67
|
+
return { name: spec.name, version: spec.version, stages: spec.stages };
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function buildDeps(provider, pipelineDir) {
|
|
71
|
+
return {
|
|
72
|
+
provider,
|
|
73
|
+
forceMock: true,
|
|
74
|
+
pricing: new StaticPricingResolver({
|
|
75
|
+
'mock-model': { input: 0.0001, output: 0.0003 },
|
|
76
|
+
'MiniMax-M3': { input: 0.0001, output: 0.0003 },
|
|
77
|
+
'MiniMax-M2.7': { input: 0.0001, output: 0.0003 },
|
|
78
|
+
}),
|
|
79
|
+
modelResolver: createModelResolver(),
|
|
80
|
+
fetchSkill: async (skillId) => ({ id: skillId, name: skillId, version: '1.0.0', full_md: `# mock ${skillId}`, preferred_model: 'mock-model' }),
|
|
81
|
+
getCurrentAgentId: () => 'test-agent',
|
|
82
|
+
getPipelineAuthorId: () => 'test-agent',
|
|
83
|
+
isLocal: true,
|
|
84
|
+
registry: new LLMProviderRegistry([provider]),
|
|
85
|
+
...(pipelineDir ? { fetchPipeline: buildLocalFetcher(pipelineDir) } : {}),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export async function runSingleTest(spec, opts = {}) {
|
|
89
|
+
const t0 = Date.now();
|
|
90
|
+
const baseDir = opts.baseDir ?? process.cwd();
|
|
91
|
+
const withTimeout = async (p) => {
|
|
92
|
+
const ms = opts.timeoutMs ?? 60_000;
|
|
93
|
+
let timer;
|
|
94
|
+
try {
|
|
95
|
+
return await Promise.race([
|
|
96
|
+
p,
|
|
97
|
+
new Promise((_, reject) => {
|
|
98
|
+
timer = setTimeout(() => reject(new Error(`test timed out after ${ms}ms`)), ms);
|
|
99
|
+
}),
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
if (timer)
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
try {
|
|
108
|
+
let pipelineSpec;
|
|
109
|
+
let pipelinePath = '';
|
|
110
|
+
if (spec.pipeline) {
|
|
111
|
+
pipelinePath = path.isAbsolute(spec.pipeline) ? spec.pipeline : path.resolve(baseDir, spec.pipeline);
|
|
112
|
+
if (!fs.existsSync(pipelinePath)) {
|
|
113
|
+
return { name: spec.name, status: 'error', duration_ms: Date.now() - t0, assertions: [], error: `pipeline file not found: ${spec.pipeline}` };
|
|
114
|
+
}
|
|
115
|
+
const raw = fs.readFileSync(pipelinePath, 'utf8');
|
|
116
|
+
if (spec.stage) {
|
|
117
|
+
const extracted = extractStage(raw, spec.stage);
|
|
118
|
+
pipelineSpec = extracted.spec;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
pipelineSpec = loadPipelineYaml(raw);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else if (spec.stage) {
|
|
125
|
+
return { name: spec.name, status: 'error', duration_ms: Date.now() - t0, assertions: [], error: 'stage test requires pipeline field (path to pipeline.yaml)' };
|
|
126
|
+
}
|
|
127
|
+
else if (spec.expect_error) {
|
|
128
|
+
return { name: spec.name, status: 'error', duration_ms: Date.now() - t0, assertions: [], error: 'expect_error requires pipeline field' };
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return { name: spec.name, status: 'error', duration_ms: Date.now() - t0, assertions: [], error: 'no pipeline specified' };
|
|
132
|
+
}
|
|
133
|
+
const stages = pipelineSpec.stages ?? [];
|
|
134
|
+
for (let i = 0; i < stages.length; i++) {
|
|
135
|
+
const st = stages[i];
|
|
136
|
+
if (!st || typeof st.id !== 'string' || st.id.length === 0) {
|
|
137
|
+
throw new Error(`stage at index ${i} is missing required "id"`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const provider = buildMockProvider();
|
|
141
|
+
const deps = buildDeps(provider, pipelinePath ? path.dirname(pipelinePath) : undefined);
|
|
142
|
+
let outputs;
|
|
143
|
+
try {
|
|
144
|
+
const result = await withTimeout(runPipelineV2({
|
|
145
|
+
spec: pipelineSpec,
|
|
146
|
+
inputs: spec.inputs,
|
|
147
|
+
deps,
|
|
148
|
+
}));
|
|
149
|
+
outputs = result.outputs;
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
if (spec.expect_error) {
|
|
153
|
+
const msg = e.message;
|
|
154
|
+
const pass = msg.includes(spec.expect_error);
|
|
155
|
+
const dur = Date.now() - t0;
|
|
156
|
+
return {
|
|
157
|
+
name: spec.name, status: pass ? 'passed' : 'failed', duration_ms: dur,
|
|
158
|
+
assertions: [{ type: 'expect_error', passed: pass, message: pass ? `got expected error: ${spec.expect_error}` : `expected error "${spec.expect_error}", got "${msg}"`, duration_ms: dur }],
|
|
159
|
+
error: pass ? undefined : msg,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return { name: spec.name, status: 'error', duration_ms: Date.now() - t0, assertions: [], error: e.message };
|
|
163
|
+
}
|
|
164
|
+
if (spec.expect_error) {
|
|
165
|
+
return { name: spec.name, status: 'failed', duration_ms: Date.now() - t0, assertions: [{ type: 'expect_error', passed: false, message: `expected error "${spec.expect_error}" but pipeline succeeded`, duration_ms: 0 }], output: outputs };
|
|
166
|
+
}
|
|
167
|
+
const merged = { ...spec.inputs };
|
|
168
|
+
for (const [stageId, text] of Object.entries(outputs)) {
|
|
169
|
+
try {
|
|
170
|
+
merged[stageId] = JSON.parse(text);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
merged[stageId] = text;
|
|
174
|
+
}
|
|
175
|
+
merged[`stages.${stageId}`] = merged[stageId];
|
|
176
|
+
}
|
|
177
|
+
merged['outputs'] = merged;
|
|
178
|
+
void pipelinePath;
|
|
179
|
+
const results = [];
|
|
180
|
+
let allPass = true;
|
|
181
|
+
for (const a of spec.assertions) {
|
|
182
|
+
const r = runAssertion(merged, a, { baseDir });
|
|
183
|
+
results.push({ ...r, type: a.type });
|
|
184
|
+
if (!r.passed)
|
|
185
|
+
allPass = false;
|
|
186
|
+
}
|
|
187
|
+
return { name: spec.name, status: allPass ? 'passed' : 'failed', duration_ms: Date.now() - t0, assertions: results, output: merged };
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
const msg = e.message;
|
|
191
|
+
if (spec.expect_error) {
|
|
192
|
+
const pass = msg.includes(spec.expect_error);
|
|
193
|
+
return {
|
|
194
|
+
name: spec.name, status: pass ? 'passed' : 'failed', duration_ms: Date.now() - t0,
|
|
195
|
+
assertions: [{ type: 'expect_error', passed: pass, message: pass ? `got expected error: ${spec.expect_error}` : `expected error "${spec.expect_error}", got "${msg}"`, duration_ms: 0 }],
|
|
196
|
+
error: pass ? undefined : msg,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return { name: spec.name, status: 'error', duration_ms: Date.now() - t0, assertions: [], error: msg };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
export async function runTestSuite(specs, opts = {}) {
|
|
203
|
+
const results = [];
|
|
204
|
+
const n = Math.max(1, opts.parallel ?? 1);
|
|
205
|
+
if (n === 1) {
|
|
206
|
+
for (const s of specs) {
|
|
207
|
+
const r = await runSingleTest(s, opts);
|
|
208
|
+
results.push(r);
|
|
209
|
+
if (opts.bail && (r.status === 'failed' || r.status === 'error'))
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
return results;
|
|
213
|
+
}
|
|
214
|
+
for (let i = 0; i < specs.length; i += n) {
|
|
215
|
+
const batch = specs.slice(i, i + n);
|
|
216
|
+
const out = await Promise.all(batch.map((s) => runSingleTest(s, opts)));
|
|
217
|
+
results.push(...out);
|
|
218
|
+
if (opts.bail && out.some((r) => r.status === 'failed' || r.status === 'error'))
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
return results;
|
|
222
|
+
}
|