@midscene/core 1.15.2-beta-20261012123219.0 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/agent/action-readiness.mjs +6 -3
- package/dist/es/agent/action-readiness.mjs.map +1 -1
- package/dist/es/agent/agent.mjs +4 -2
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/execution-session.mjs.map +1 -1
- package/dist/es/agent/task-builder.mjs +35 -16
- package/dist/es/agent/task-builder.mjs.map +1 -1
- package/dist/es/agent/tasks.mjs +35 -12
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +1 -1
- package/dist/es/device/index.mjs +7 -6
- package/dist/es/device/index.mjs.map +1 -1
- package/dist/es/report-generator.mjs +30 -14
- package/dist/es/report-generator.mjs.map +1 -1
- package/dist/es/report-html-template.mjs +1 -1
- package/dist/es/report.mjs +121 -44
- package/dist/es/report.mjs.map +1 -1
- package/dist/es/service/index.mjs.map +1 -1
- package/dist/es/task-runner.mjs +22 -12
- package/dist/es/task-runner.mjs.map +1 -1
- package/dist/es/test-run-report.mjs.map +1 -1
- package/dist/es/test-runner/engine/case-runner.mjs +1 -1
- package/dist/es/test-runner/engine/case-runner.mjs.map +1 -1
- package/dist/es/test-runner/engine/document-runtime.mjs +42 -12
- package/dist/es/test-runner/engine/document-runtime.mjs.map +1 -1
- package/dist/es/test-runner/engine/execute-step.mjs +130 -12
- package/dist/es/test-runner/engine/execute-step.mjs.map +1 -1
- package/dist/es/test-runner/engine/index.mjs +1 -0
- package/dist/es/test-runner/engine/project-runtime.mjs +14 -5
- package/dist/es/test-runner/engine/project-runtime.mjs.map +1 -1
- package/dist/es/test-runner/engine/resource-operations.mjs +286 -35
- package/dist/es/test-runner/engine/resource-operations.mjs.map +1 -1
- package/dist/es/test-runner/engine/result-metadata.mjs +21 -0
- package/dist/es/test-runner/engine/result-metadata.mjs.map +1 -0
- package/dist/es/test-runner/engine/run-collected-case.mjs +30 -9
- package/dist/es/test-runner/engine/run-collected-case.mjs.map +1 -1
- package/dist/es/test-runner/engine/run-workflow-document.mjs +57 -10
- package/dist/es/test-runner/engine/run-workflow-document.mjs.map +1 -1
- package/dist/es/test-runner/errors.mjs +26 -13
- package/dist/es/test-runner/errors.mjs.map +1 -1
- package/dist/es/test-runner/execution-record.mjs +2 -0
- package/dist/es/test-runner/execution-record.mjs.map +1 -1
- package/dist/es/test-runner/index.mjs +3 -0
- package/dist/es/test-runner/reporting/agent-report.mjs +2 -7
- package/dist/es/test-runner/reporting/agent-report.mjs.map +1 -1
- package/dist/es/test-runner/reporting/merge-report.mjs +207 -6
- package/dist/es/test-runner/reporting/merge-report.mjs.map +1 -1
- package/dist/es/test-runner/reporting/metrics.mjs +77 -0
- package/dist/es/test-runner/reporting/metrics.mjs.map +1 -0
- package/dist/es/test-runner/reporting/sanitize.mjs +92 -16
- package/dist/es/test-runner/reporting/sanitize.mjs.map +1 -1
- package/dist/es/test-runner/reporting/test-plan.mjs +56 -0
- package/dist/es/test-runner/reporting/test-plan.mjs.map +1 -0
- package/dist/es/test-runner/reporting/test-run-report.mjs +208 -21
- package/dist/es/test-runner/reporting/test-run-report.mjs.map +1 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +1 -1
- package/dist/es/yaml/legacy-yaml-runtime.mjs +3 -3
- package/dist/es/yaml/legacy-yaml-runtime.mjs.map +1 -1
- package/dist/lib/agent/action-readiness.js +6 -3
- package/dist/lib/agent/action-readiness.js.map +1 -1
- package/dist/lib/agent/agent.js +4 -2
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/execution-session.js.map +1 -1
- package/dist/lib/agent/task-builder.js +42 -23
- package/dist/lib/agent/task-builder.js.map +1 -1
- package/dist/lib/agent/tasks.js +35 -12
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/utils.js +1 -1
- package/dist/lib/device/index.js +7 -6
- package/dist/lib/device/index.js.map +1 -1
- package/dist/lib/report-generator.js +30 -14
- package/dist/lib/report-generator.js.map +1 -1
- package/dist/lib/report-html-template.js +1 -1
- package/dist/lib/report.js +121 -44
- package/dist/lib/report.js.map +1 -1
- package/dist/lib/service/index.js.map +1 -1
- package/dist/lib/task-runner.js +22 -12
- package/dist/lib/task-runner.js.map +1 -1
- package/dist/lib/test-run-report.js.map +1 -1
- package/dist/lib/test-runner/engine/case-runner.js +1 -1
- package/dist/lib/test-runner/engine/case-runner.js.map +1 -1
- package/dist/lib/test-runner/engine/document-runtime.js +41 -11
- package/dist/lib/test-runner/engine/document-runtime.js.map +1 -1
- package/dist/lib/test-runner/engine/execute-step.js +131 -10
- package/dist/lib/test-runner/engine/execute-step.js.map +1 -1
- package/dist/lib/test-runner/engine/index.js +9 -2
- package/dist/lib/test-runner/engine/index.js.map +1 -1
- package/dist/lib/test-runner/engine/project-runtime.js +13 -4
- package/dist/lib/test-runner/engine/project-runtime.js.map +1 -1
- package/dist/lib/test-runner/engine/resource-operations.js +319 -38
- package/dist/lib/test-runner/engine/resource-operations.js.map +1 -1
- package/dist/lib/test-runner/engine/result-metadata.js +58 -0
- package/dist/lib/test-runner/engine/result-metadata.js.map +1 -0
- package/dist/lib/test-runner/engine/run-collected-case.js +29 -8
- package/dist/lib/test-runner/engine/run-collected-case.js.map +1 -1
- package/dist/lib/test-runner/engine/run-workflow-document.js +57 -10
- package/dist/lib/test-runner/engine/run-workflow-document.js.map +1 -1
- package/dist/lib/test-runner/errors.js +42 -23
- package/dist/lib/test-runner/errors.js.map +1 -1
- package/dist/lib/test-runner/execution-record.js +2 -0
- package/dist/lib/test-runner/execution-record.js.map +1 -1
- package/dist/lib/test-runner/index.js +88 -16
- package/dist/lib/test-runner/index.js.map +1 -1
- package/dist/lib/test-runner/node/index.js +2 -2
- package/dist/lib/test-runner/reporting/agent-report.js +2 -7
- package/dist/lib/test-runner/reporting/agent-report.js.map +1 -1
- package/dist/lib/test-runner/reporting/merge-report.js +207 -6
- package/dist/lib/test-runner/reporting/merge-report.js.map +1 -1
- package/dist/lib/test-runner/reporting/metrics.js +114 -0
- package/dist/lib/test-runner/reporting/metrics.js.map +1 -0
- package/dist/lib/test-runner/reporting/sanitize.js +94 -15
- package/dist/lib/test-runner/reporting/sanitize.js.map +1 -1
- package/dist/lib/test-runner/reporting/test-plan.js +90 -0
- package/dist/lib/test-runner/reporting/test-plan.js.map +1 -0
- package/dist/lib/test-runner/reporting/test-run-report.js +208 -21
- package/dist/lib/test-runner/reporting/test-run-report.js.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/yaml/legacy-yaml-runtime.js +2 -2
- package/dist/lib/yaml/legacy-yaml-runtime.js.map +1 -1
- package/dist/types/agent/action-readiness.d.ts +1 -1
- package/dist/types/agent/action-readiness.d.ts.map +1 -1
- package/dist/types/agent/agent.d.ts +1 -1
- package/dist/types/agent/agent.d.ts.map +1 -1
- package/dist/types/agent/execution-session.d.ts +1 -1
- package/dist/types/agent/execution-session.d.ts.map +1 -1
- package/dist/types/agent/task-builder.d.ts +4 -2
- package/dist/types/agent/task-builder.d.ts.map +1 -1
- package/dist/types/agent/tasks.d.ts +3 -0
- package/dist/types/agent/tasks.d.ts.map +1 -1
- package/dist/types/device/index.d.ts +3 -3
- package/dist/types/device/index.d.ts.map +1 -1
- package/dist/types/report-generator.d.ts +4 -2
- package/dist/types/report-generator.d.ts.map +1 -1
- package/dist/types/report.d.ts.map +1 -1
- package/dist/types/service/index.d.ts +2 -2
- package/dist/types/service/index.d.ts.map +1 -1
- package/dist/types/task-runner.d.ts +1 -1
- package/dist/types/task-runner.d.ts.map +1 -1
- package/dist/types/test-run-report.d.ts +157 -8
- package/dist/types/test-run-report.d.ts.map +1 -1
- package/dist/types/test-runner/engine/document-runtime.d.ts.map +1 -1
- package/dist/types/test-runner/engine/execute-step.d.ts +1 -0
- package/dist/types/test-runner/engine/execute-step.d.ts.map +1 -1
- package/dist/types/test-runner/engine/index.d.ts +1 -0
- package/dist/types/test-runner/engine/index.d.ts.map +1 -1
- package/dist/types/test-runner/engine/project-runtime.d.ts.map +1 -1
- package/dist/types/test-runner/engine/resource-operations.d.ts +41 -3
- package/dist/types/test-runner/engine/resource-operations.d.ts.map +1 -1
- package/dist/types/test-runner/engine/result-metadata.d.ts +18 -0
- package/dist/types/test-runner/engine/result-metadata.d.ts.map +1 -0
- package/dist/types/test-runner/engine/run-collected-case.d.ts.map +1 -1
- package/dist/types/test-runner/engine/run-workflow-document.d.ts.map +1 -1
- package/dist/types/test-runner/engine/types.d.ts +47 -8
- package/dist/types/test-runner/engine/types.d.ts.map +1 -1
- package/dist/types/test-runner/errors.d.ts +7 -0
- package/dist/types/test-runner/errors.d.ts.map +1 -1
- package/dist/types/test-runner/execution-record.d.ts.map +1 -1
- package/dist/types/test-runner/index.d.ts +2 -0
- package/dist/types/test-runner/index.d.ts.map +1 -1
- package/dist/types/test-runner/node/types.d.ts +9 -1
- package/dist/types/test-runner/node/types.d.ts.map +1 -1
- package/dist/types/test-runner/parser/types.d.ts +5 -0
- package/dist/types/test-runner/parser/types.d.ts.map +1 -1
- package/dist/types/test-runner/reporting/agent-report.d.ts.map +1 -1
- package/dist/types/test-runner/reporting/merge-report.d.ts +1 -1
- package/dist/types/test-runner/reporting/merge-report.d.ts.map +1 -1
- package/dist/types/test-runner/reporting/metrics.d.ts +7 -0
- package/dist/types/test-runner/reporting/metrics.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/sanitize.d.ts +1 -0
- package/dist/types/test-runner/reporting/sanitize.d.ts.map +1 -1
- package/dist/types/test-runner/reporting/test-plan.d.ts +8 -0
- package/dist/types/test-runner/reporting/test-plan.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/test-run-report.d.ts.map +1 -1
- package/dist/types/test-runner/reporting/types.d.ts +6 -1
- package/dist/types/test-runner/reporting/types.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -3,7 +3,8 @@ import { uuid } from "@midscene/shared/utils";
|
|
|
3
3
|
import { NodeScopeTeardownError, WorkflowLifecycleError } from "../errors.mjs";
|
|
4
4
|
import { executeStep } from "./execute-step.mjs";
|
|
5
5
|
import { WorkflowExecutionFailure, asExecutionError } from "./execution-failure.mjs";
|
|
6
|
-
import { ResourceCleanupDeferredError, cleanupScopeResources, createResourceScope, recoverCancelledScopeResources } from "./resource-operations.mjs";
|
|
6
|
+
import { ResourceCleanupDeferredError, cleanupScopeResources, createResourceScope, getPendingScopeOperations, getResourceCleanupSnapshot, recoverCancelledScopeResources, setResourceOperationIdentity } from "./resource-operations.mjs";
|
|
7
|
+
import { phaseResult } from "./result-metadata.mjs";
|
|
7
8
|
import { reportPathsFromTeardown } from "./scope-teardown.mjs";
|
|
8
9
|
async function runCollectedCase(collectedCase, options) {
|
|
9
10
|
const phases = {
|
|
@@ -20,9 +21,13 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
20
21
|
const scopeSignal = resourceScope.signal;
|
|
21
22
|
const runId = options.createRunId?.() ?? uuid();
|
|
22
23
|
const startedAt = new Date();
|
|
24
|
+
setResourceOperationIdentity(scopeSignal, {
|
|
25
|
+
scopeId: runId
|
|
26
|
+
});
|
|
23
27
|
const beforeEach = [];
|
|
24
28
|
const steps = [];
|
|
25
29
|
const afterEach = [];
|
|
30
|
+
const capturedSources = new Map();
|
|
26
31
|
const teardownStack = [];
|
|
27
32
|
let acceptingTeardowns = true;
|
|
28
33
|
const onTeardown = (node, teardown)=>{
|
|
@@ -42,7 +47,7 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
42
47
|
};
|
|
43
48
|
const runPhase = async (phase, results, signal = scopeSignal)=>{
|
|
44
49
|
for (const [stepIndex, step] of phases[phase].entries()){
|
|
45
|
-
|
|
50
|
+
const waitForPreviousOperationMs = stepIndex > 0 ? await recoverCancelledScopeResources(signal) : 0;
|
|
46
51
|
const caseContext = {
|
|
47
52
|
caseId: collectedCase.caseId,
|
|
48
53
|
runId,
|
|
@@ -69,15 +74,17 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
69
74
|
defaultTimeoutMs: options.defaultTimeoutMs,
|
|
70
75
|
onTeardown
|
|
71
76
|
});
|
|
77
|
+
if (waitForPreviousOperationMs > 0) result.waitForPreviousOperationMs = waitForPreviousOperationMs;
|
|
72
78
|
results.push(result);
|
|
79
|
+
for (const source of result.report?.sources ?? [])capturedSources.set(`${source.sourcePath}\u0000${source.dumpPath ?? ''}`, source);
|
|
73
80
|
await options.onStepResult?.(stepInfo, result);
|
|
74
|
-
if ('
|
|
81
|
+
if ('success' !== result.status && !result.continuedAfterError) break;
|
|
75
82
|
}
|
|
76
83
|
};
|
|
77
84
|
const executionErrors = [];
|
|
78
85
|
try {
|
|
79
86
|
await runPhase('beforeEach', beforeEach);
|
|
80
|
-
if (!beforeEach.some((step)=>'
|
|
87
|
+
if (!beforeEach.some((step)=>'success' !== step.status)) await runPhase('steps', steps);
|
|
81
88
|
} catch (error) {
|
|
82
89
|
executionErrors.push(error);
|
|
83
90
|
}
|
|
@@ -101,12 +108,12 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
101
108
|
registrationIndex
|
|
102
109
|
}));
|
|
103
110
|
}
|
|
104
|
-
|
|
111
|
+
{
|
|
105
112
|
const errors = [
|
|
106
113
|
...cleanupExecutionErrors,
|
|
107
114
|
...teardownErrors.slice(priorTeardownErrors)
|
|
108
115
|
];
|
|
109
|
-
if (errors.length) throw new AggregateError(errors, '
|
|
116
|
+
if (errors.length) throw new AggregateError(errors, 'Case cleanup failed');
|
|
110
117
|
}
|
|
111
118
|
};
|
|
112
119
|
try {
|
|
@@ -127,7 +134,7 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
127
134
|
} catch (error) {
|
|
128
135
|
deferredCleanup = error instanceof ResourceCleanupDeferredError;
|
|
129
136
|
if (!deferredCleanup) acceptingTeardowns = false;
|
|
130
|
-
teardownErrors.push(new NodeScopeTeardownError(error, {
|
|
137
|
+
if (!deferredCleanup && !teardownErrors.length && !cleanupExecutionErrors.length) teardownErrors.push(new NodeScopeTeardownError(error, {
|
|
131
138
|
scope: 'case',
|
|
132
139
|
scopeId: runId,
|
|
133
140
|
node: 'resource-drain',
|
|
@@ -135,6 +142,13 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
135
142
|
}));
|
|
136
143
|
}
|
|
137
144
|
const endedAt = new Date();
|
|
145
|
+
const cleanupSnapshot = getResourceCleanupSnapshot(scopeSignal);
|
|
146
|
+
const pendingOperations = getPendingScopeOperations(scopeSignal);
|
|
147
|
+
const phaseResults = {
|
|
148
|
+
beforeEach: phaseResult(phases.beforeEach.length, beforeEach),
|
|
149
|
+
steps: phaseResult(phases.steps.length, steps),
|
|
150
|
+
afterEach: phaseResult(phases.afterEach.length, afterEach)
|
|
151
|
+
};
|
|
138
152
|
const result = {
|
|
139
153
|
caseId: collectedCase.caseId,
|
|
140
154
|
runId,
|
|
@@ -143,7 +157,7 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
143
157
|
name: collectedCase.definition.name,
|
|
144
158
|
sourcePath: collectedCase.sourcePath,
|
|
145
159
|
caseIndex: collectedCase.caseIndex,
|
|
146
|
-
status: executionErrors.length > 0 || beforeEach.some((step)=>'
|
|
160
|
+
status: executionErrors.length > 0 || beforeEach.some((step)=>'success' !== step.status) || steps.some((step)=>'success' !== step.status) || afterEach.some((step)=>'success' !== step.status) || 'pending' === cleanupSnapshot.status || 'failed' === cleanupSnapshot.status || pendingOperations.length > 0 || teardownErrors.length > 0 ? 'failed' : 'success',
|
|
147
161
|
beforeEach: [
|
|
148
162
|
...beforeEach
|
|
149
163
|
],
|
|
@@ -153,6 +167,12 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
153
167
|
afterEach: [
|
|
154
168
|
...afterEach
|
|
155
169
|
],
|
|
170
|
+
executionStatus: Object.values(phaseResults).some((phase)=>'failed' === phase.status) ? 'failed' : Object.values(phaseResults).some((phase)=>'not-run' === phase.status) ? 'not-run' : 'success',
|
|
171
|
+
phases: phaseResults,
|
|
172
|
+
cleanup: cleanupSnapshot,
|
|
173
|
+
...pendingOperations.length ? {
|
|
174
|
+
pendingOperations
|
|
175
|
+
} : {},
|
|
156
176
|
...executionErrors.length ? {
|
|
157
177
|
executionErrors: executionErrors.map(asExecutionError)
|
|
158
178
|
} : {},
|
|
@@ -166,8 +186,9 @@ async function runCollectedCase(collectedCase, options) {
|
|
|
166
186
|
...reportPaths
|
|
167
187
|
]
|
|
168
188
|
} : {},
|
|
169
|
-
...reportSources.length ? {
|
|
189
|
+
...capturedSources.size || reportSources.length ? {
|
|
170
190
|
reportSources: [
|
|
191
|
+
...capturedSources.values(),
|
|
171
192
|
...reportSources
|
|
172
193
|
]
|
|
173
194
|
} : {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-runner/engine/run-collected-case.mjs","sources":["../../../../src/test-runner/engine/run-collected-case.ts"],"sourcesContent":["import { getDebug } from '@midscene/shared/logger';\nimport { uuid as randomUUID } from '@midscene/shared/utils';\nimport { NodeScopeTeardownError, WorkflowLifecycleError } from '../errors';\nimport type { CollectedCase, NormalizedStep } from '../parser/types';\nimport { executeStep } from './execute-step';\nimport {\n WorkflowExecutionFailure,\n asExecutionError,\n} from './execution-failure';\nimport {\n ResourceCleanupDeferredError,\n cleanupScopeResources,\n createResourceScope,\n recoverCancelledScopeResources,\n} from './resource-operations';\nimport { reportPathsFromTeardown } from './scope-teardown';\nimport type {\n CaseNodePhase,\n CaseRunResult,\n NodeCaseContext,\n NodeScopeTeardown,\n RunCollectedCaseOptions,\n StepRunResult,\n} from './types';\n\nexport async function runCollectedCase<TContext = undefined>(\n collectedCase: CollectedCase,\n options: RunCollectedCaseOptions<TContext>,\n): Promise<CaseRunResult> {\n const phases: Record<CaseNodePhase, readonly NormalizedStep[]> = {\n beforeEach: options.beforeEach ?? [],\n steps: collectedCase.definition.steps,\n afterEach: options.afterEach ?? [],\n };\n const nodes = {\n beforeEach: phases.beforeEach.map((step) => options.resolveNode(step.node)),\n steps: phases.steps.map((step) => options.resolveNode(step.node)),\n afterEach: phases.afterEach.map((step) => options.resolveNode(step.node)),\n };\n const resourceScope = createResourceScope(options.signal);\n const scopeSignal = resourceScope.signal;\n const runId = options.createRunId?.() ?? randomUUID();\n const startedAt = new Date();\n const beforeEach: StepRunResult[] = [];\n const steps: StepRunResult[] = [];\n const afterEach: StepRunResult[] = [];\n const teardownStack: Array<{\n registrationIndex: number;\n node: string;\n teardown: NodeScopeTeardown;\n }> = [];\n let acceptingTeardowns = true;\n\n const onTeardown = (node: string, teardown: NodeScopeTeardown): void => {\n if (!acceptingTeardowns) {\n throw new WorkflowLifecycleError(\n 'Node teardown can only be registered while a case attempt is running.',\n { runId, node },\n );\n }\n if (typeof teardown !== 'function') {\n throw new WorkflowLifecycleError(\n 'Node onTeardown() requires a teardown function.',\n { runId, node },\n );\n }\n teardownStack.push({\n registrationIndex: teardownStack.length,\n node,\n teardown,\n });\n };\n\n const runPhase = async (\n phase: CaseNodePhase,\n results: StepRunResult[],\n signal = scopeSignal,\n ): Promise<void> => {\n for (const [stepIndex, step] of phases[phase].entries()) {\n // A Step timeout ends the Runner's wait, not the underlying operation.\n // Recovery belongs between Steps, outside the next Step's timeout budget.\n if (stepIndex > 0) await recoverCancelledScopeResources(signal);\n const caseContext: NodeCaseContext = {\n caseId: collectedCase.caseId,\n runId,\n projectName: options.projectName ?? collectedCase.projectId,\n attemptIndex: options.attemptIndex ?? 0,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n phase,\n stepIndex,\n };\n const stepInfo = {\n scope: 'case' as const,\n node: step.node,\n stepCount: phases[phase].length,\n case: caseContext,\n };\n await options.onStepStart?.(stepInfo);\n const result = await executeStep(\n step,\n nodes[phase][stepIndex],\n { scope: 'case', case: caseContext },\n options.context as TContext,\n {\n signal,\n defaultTimeoutMs: options.defaultTimeoutMs,\n onTeardown,\n },\n );\n results.push(result);\n await options.onStepResult?.(stepInfo, result);\n if (result.status === 'failed' && !result.continuedAfterError) break;\n }\n };\n\n const executionErrors: unknown[] = [];\n try {\n await runPhase('beforeEach', beforeEach);\n if (!beforeEach.some((step) => step.status === 'failed')) {\n await runPhase('steps', steps);\n }\n } catch (error) {\n executionErrors.push(error);\n }\n const teardownErrors: NodeScopeTeardownError[] = [];\n const reportPaths = new Set<string>();\n const reportSources: import('./types').WorkflowReportSource[] = [];\n const cleanupExecutionErrors: unknown[] = [];\n let deferredCleanup = false;\n const cleanup = async () => {\n const priorTeardownErrors = teardownErrors.length;\n acceptingTeardowns = false;\n for (const {\n registrationIndex,\n node,\n teardown,\n } of teardownStack.reverse()) {\n try {\n const released = await teardown();\n reportSources.push(...(released?.reportSources ?? []));\n for (const path of reportPathsFromTeardown(released)) {\n reportPaths.add(path);\n }\n } catch (error) {\n teardownErrors.push(\n new NodeScopeTeardownError(error, {\n scope: 'case',\n scopeId: runId,\n node,\n registrationIndex,\n }),\n );\n }\n }\n if (deferredCleanup) {\n const errors = [\n ...cleanupExecutionErrors,\n ...teardownErrors.slice(priorTeardownErrors),\n ];\n if (errors.length)\n throw new AggregateError(errors, 'Deferred Case cleanup failed');\n }\n };\n try {\n if (phases.afterEach.length || teardownStack.length)\n await cleanupScopeResources(scopeSignal, cleanup, {\n beforeCleanup: async (cleanupSignal) => {\n try {\n await runPhase('afterEach', afterEach, cleanupSignal);\n } catch (error) {\n executionErrors.push(error);\n cleanupExecutionErrors.push(error);\n }\n },\n onDeferredError: (error) =>\n getDebug('runner:cleanup', { console: true })(\n `Deferred Case cleanup failed: ${String(error)}`,\n ),\n });\n else acceptingTeardowns = false;\n } catch (error) {\n deferredCleanup = error instanceof ResourceCleanupDeferredError;\n if (!deferredCleanup) acceptingTeardowns = false;\n teardownErrors.push(\n new NodeScopeTeardownError(error, {\n scope: 'case',\n scopeId: runId,\n node: 'resource-drain',\n registrationIndex: -1,\n }),\n );\n }\n const endedAt = new Date();\n const result: CaseRunResult = {\n caseId: collectedCase.caseId,\n runId,\n projectName: options.projectName ?? collectedCase.projectId,\n attemptIndex: options.attemptIndex ?? 0,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n status:\n executionErrors.length > 0 ||\n beforeEach.some((step) => step.status === 'failed') ||\n steps.some((step) => step.status === 'failed') ||\n afterEach.some((step) => step.status === 'failed') ||\n teardownErrors.length > 0\n ? 'failed'\n : 'success',\n beforeEach: [...beforeEach],\n steps: [...steps],\n afterEach: [...afterEach],\n ...(executionErrors.length\n ? { executionErrors: executionErrors.map(asExecutionError) }\n : {}),\n ...(teardownErrors.length > 0\n ? { teardownErrors: [...teardownErrors] }\n : {}),\n ...(reportPaths.size > 0 ? { reportPaths: [...reportPaths] } : {}),\n ...(reportSources.length ? { reportSources: [...reportSources] } : {}),\n ...(options.reportScopeId ? { reportScopeId: options.reportScopeId } : {}),\n startedAt: startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),\n };\n\n try {\n await options.onResult?.(result);\n } catch (error) {\n executionErrors.push(error);\n result.status = 'failed';\n result.executionErrors = executionErrors.map(asExecutionError);\n }\n resourceScope.dispose();\n if (executionErrors.length)\n throw new WorkflowExecutionFailure(result, executionErrors);\n return result;\n}\n"],"names":["runCollectedCase","collectedCase","options","phases","nodes","step","resourceScope","createResourceScope","scopeSignal","runId","randomUUID","startedAt","Date","beforeEach","steps","afterEach","teardownStack","acceptingTeardowns","onTeardown","node","teardown","WorkflowLifecycleError","runPhase","phase","results","signal","stepIndex","recoverCancelledScopeResources","caseContext","stepInfo","result","executeStep","executionErrors","error","teardownErrors","reportPaths","Set","reportSources","cleanupExecutionErrors","deferredCleanup","cleanup","priorTeardownErrors","registrationIndex","released","path","reportPathsFromTeardown","NodeScopeTeardownError","errors","AggregateError","cleanupScopeResources","cleanupSignal","getDebug","String","ResourceCleanupDeferredError","endedAt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,MAAM,EACxB,MAAM,IAAIyB,yBAAyB3B,QAAQE;IAC7C,OAAOF;AACT"}
|
|
1
|
+
{"version":3,"file":"test-runner/engine/run-collected-case.mjs","sources":["../../../../src/test-runner/engine/run-collected-case.ts"],"sourcesContent":["import { getDebug } from '@midscene/shared/logger';\nimport { uuid as randomUUID } from '@midscene/shared/utils';\nimport { NodeScopeTeardownError, WorkflowLifecycleError } from '../errors';\nimport type { CollectedCase, NormalizedStep } from '../parser/types';\nimport { executeStep } from './execute-step';\nimport {\n WorkflowExecutionFailure,\n asExecutionError,\n} from './execution-failure';\nimport {\n ResourceCleanupDeferredError,\n cleanupScopeResources,\n createResourceScope,\n getPendingScopeOperations,\n getResourceCleanupSnapshot,\n recoverCancelledScopeResources,\n setResourceOperationIdentity,\n} from './resource-operations';\nimport { phaseResult } from './result-metadata';\nimport { reportPathsFromTeardown } from './scope-teardown';\nimport type {\n CaseNodePhase,\n CaseRunResult,\n NodeCaseContext,\n NodeScopeTeardown,\n RunCollectedCaseOptions,\n StepRunResult,\n} from './types';\n\nexport async function runCollectedCase<TContext = undefined>(\n collectedCase: CollectedCase,\n options: RunCollectedCaseOptions<TContext>,\n): Promise<CaseRunResult> {\n const phases: Record<CaseNodePhase, readonly NormalizedStep[]> = {\n beforeEach: options.beforeEach ?? [],\n steps: collectedCase.definition.steps,\n afterEach: options.afterEach ?? [],\n };\n const nodes = {\n beforeEach: phases.beforeEach.map((step) => options.resolveNode(step.node)),\n steps: phases.steps.map((step) => options.resolveNode(step.node)),\n afterEach: phases.afterEach.map((step) => options.resolveNode(step.node)),\n };\n const resourceScope = createResourceScope(options.signal);\n const scopeSignal = resourceScope.signal;\n const runId = options.createRunId?.() ?? randomUUID();\n const startedAt = new Date();\n setResourceOperationIdentity(scopeSignal, { scopeId: runId });\n const beforeEach: StepRunResult[] = [];\n const steps: StepRunResult[] = [];\n const afterEach: StepRunResult[] = [];\n const capturedSources = new Map<\n string,\n import('./types').WorkflowReportSource\n >();\n const teardownStack: Array<{\n registrationIndex: number;\n node: string;\n teardown: NodeScopeTeardown;\n }> = [];\n let acceptingTeardowns = true;\n\n const onTeardown = (node: string, teardown: NodeScopeTeardown): void => {\n if (!acceptingTeardowns) {\n throw new WorkflowLifecycleError(\n 'Node teardown can only be registered while a case attempt is running.',\n { runId, node },\n );\n }\n if (typeof teardown !== 'function') {\n throw new WorkflowLifecycleError(\n 'Node onTeardown() requires a teardown function.',\n { runId, node },\n );\n }\n teardownStack.push({\n registrationIndex: teardownStack.length,\n node,\n teardown,\n });\n };\n\n const runPhase = async (\n phase: CaseNodePhase,\n results: StepRunResult[],\n signal = scopeSignal,\n ): Promise<void> => {\n for (const [stepIndex, step] of phases[phase].entries()) {\n // A Step timeout ends the Runner's wait, not the underlying operation.\n // Recovery belongs between Steps, outside the next Step's timeout budget.\n const waitForPreviousOperationMs =\n stepIndex > 0 ? await recoverCancelledScopeResources(signal) : 0;\n const caseContext: NodeCaseContext = {\n caseId: collectedCase.caseId,\n runId,\n projectName: options.projectName ?? collectedCase.projectId,\n attemptIndex: options.attemptIndex ?? 0,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n phase,\n stepIndex,\n };\n const stepInfo = {\n scope: 'case' as const,\n node: step.node,\n stepCount: phases[phase].length,\n case: caseContext,\n };\n await options.onStepStart?.(stepInfo);\n const result = await executeStep(\n step,\n nodes[phase][stepIndex],\n { scope: 'case', case: caseContext },\n options.context as TContext,\n {\n signal,\n defaultTimeoutMs: options.defaultTimeoutMs,\n onTeardown,\n },\n );\n if (waitForPreviousOperationMs > 0)\n result.waitForPreviousOperationMs = waitForPreviousOperationMs;\n results.push(result);\n for (const source of result.report?.sources ?? [])\n capturedSources.set(\n `${source.sourcePath}\\u0000${source.dumpPath ?? ''}`,\n source,\n );\n await options.onStepResult?.(stepInfo, result);\n if (result.status !== 'success' && !result.continuedAfterError) break;\n }\n };\n\n const executionErrors: unknown[] = [];\n try {\n await runPhase('beforeEach', beforeEach);\n if (!beforeEach.some((step) => step.status !== 'success')) {\n await runPhase('steps', steps);\n }\n } catch (error) {\n executionErrors.push(error);\n }\n const teardownErrors: NodeScopeTeardownError[] = [];\n const reportPaths = new Set<string>();\n const reportSources: import('./types').WorkflowReportSource[] = [];\n const cleanupExecutionErrors: unknown[] = [];\n let deferredCleanup = false;\n const cleanup = async () => {\n const priorTeardownErrors = teardownErrors.length;\n acceptingTeardowns = false;\n for (const {\n registrationIndex,\n node,\n teardown,\n } of teardownStack.reverse()) {\n try {\n const released = await teardown();\n reportSources.push(...(released?.reportSources ?? []));\n for (const path of reportPathsFromTeardown(released)) {\n reportPaths.add(path);\n }\n } catch (error) {\n teardownErrors.push(\n new NodeScopeTeardownError(error, {\n scope: 'case',\n scopeId: runId,\n node,\n registrationIndex,\n }),\n );\n }\n }\n {\n const errors = [\n ...cleanupExecutionErrors,\n ...teardownErrors.slice(priorTeardownErrors),\n ];\n if (errors.length)\n throw new AggregateError(errors, 'Case cleanup failed');\n }\n };\n try {\n if (phases.afterEach.length || teardownStack.length)\n await cleanupScopeResources(scopeSignal, cleanup, {\n beforeCleanup: async (cleanupSignal) => {\n try {\n await runPhase('afterEach', afterEach, cleanupSignal);\n } catch (error) {\n executionErrors.push(error);\n cleanupExecutionErrors.push(error);\n }\n },\n onDeferredError: (error) =>\n getDebug('runner:cleanup', { console: true })(\n `Deferred Case cleanup failed: ${String(error)}`,\n ),\n });\n else acceptingTeardowns = false;\n } catch (error) {\n deferredCleanup = error instanceof ResourceCleanupDeferredError;\n if (!deferredCleanup) acceptingTeardowns = false;\n if (\n !deferredCleanup &&\n !teardownErrors.length &&\n !cleanupExecutionErrors.length\n )\n teardownErrors.push(\n new NodeScopeTeardownError(error, {\n scope: 'case',\n scopeId: runId,\n node: 'resource-drain',\n registrationIndex: -1,\n }),\n );\n }\n const endedAt = new Date();\n const cleanupSnapshot = getResourceCleanupSnapshot(scopeSignal);\n const pendingOperations = getPendingScopeOperations(scopeSignal);\n const phaseResults = {\n beforeEach: phaseResult(phases.beforeEach.length, beforeEach),\n steps: phaseResult(phases.steps.length, steps),\n afterEach: phaseResult(phases.afterEach.length, afterEach),\n };\n const result: CaseRunResult = {\n caseId: collectedCase.caseId,\n runId,\n projectName: options.projectName ?? collectedCase.projectId,\n attemptIndex: options.attemptIndex ?? 0,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n status:\n executionErrors.length > 0 ||\n beforeEach.some((step) => step.status !== 'success') ||\n steps.some((step) => step.status !== 'success') ||\n afterEach.some((step) => step.status !== 'success') ||\n cleanupSnapshot.status === 'pending' ||\n cleanupSnapshot.status === 'failed' ||\n pendingOperations.length > 0 ||\n teardownErrors.length > 0\n ? 'failed'\n : 'success',\n beforeEach: [...beforeEach],\n steps: [...steps],\n afterEach: [...afterEach],\n executionStatus: Object.values(phaseResults).some(\n (phase) => phase.status === 'failed',\n )\n ? 'failed'\n : Object.values(phaseResults).some((phase) => phase.status === 'not-run')\n ? 'not-run'\n : 'success',\n phases: phaseResults,\n cleanup: cleanupSnapshot,\n ...(pendingOperations.length ? { pendingOperations } : {}),\n ...(executionErrors.length\n ? { executionErrors: executionErrors.map(asExecutionError) }\n : {}),\n ...(teardownErrors.length > 0\n ? { teardownErrors: [...teardownErrors] }\n : {}),\n ...(reportPaths.size > 0 ? { reportPaths: [...reportPaths] } : {}),\n ...(capturedSources.size || reportSources.length\n ? { reportSources: [...capturedSources.values(), ...reportSources] }\n : {}),\n ...(options.reportScopeId ? { reportScopeId: options.reportScopeId } : {}),\n startedAt: startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),\n };\n\n try {\n await options.onResult?.(result);\n } catch (error) {\n executionErrors.push(error);\n result.status = 'failed';\n result.executionErrors = executionErrors.map(asExecutionError);\n }\n resourceScope.dispose();\n if (executionErrors.length)\n throw new WorkflowExecutionFailure(result, executionErrors);\n return result;\n}\n"],"names":["runCollectedCase","collectedCase","options","phases","nodes","step","resourceScope","createResourceScope","scopeSignal","runId","randomUUID","startedAt","Date","setResourceOperationIdentity","beforeEach","steps","afterEach","capturedSources","Map","teardownStack","acceptingTeardowns","onTeardown","node","teardown","WorkflowLifecycleError","runPhase","phase","results","signal","stepIndex","waitForPreviousOperationMs","recoverCancelledScopeResources","caseContext","stepInfo","result","executeStep","source","executionErrors","error","teardownErrors","reportPaths","Set","reportSources","cleanupExecutionErrors","deferredCleanup","cleanup","priorTeardownErrors","registrationIndex","released","path","reportPathsFromTeardown","NodeScopeTeardownError","errors","AggregateError","cleanupScopeResources","cleanupSignal","getDebug","String","ResourceCleanupDeferredError","endedAt","cleanupSnapshot","getResourceCleanupSnapshot","pendingOperations","getPendingScopeOperations","phaseResults","phaseResult","Object","asExecutionError","Math","WorkflowExecutionFailure"],"mappings":";;;;;;;;AA6BO,eAAeA,iBACpBC,aAA4B,EAC5BC,OAA0C;IAE1C,MAAMC,SAA2D;QAC/D,YAAYD,QAAQ,UAAU,IAAI,EAAE;QACpC,OAAOD,cAAc,UAAU,CAAC,KAAK;QACrC,WAAWC,QAAQ,SAAS,IAAI,EAAE;IACpC;IACA,MAAME,QAAQ;QACZ,YAAYD,OAAO,UAAU,CAAC,GAAG,CAAC,CAACE,OAASH,QAAQ,WAAW,CAACG,KAAK,IAAI;QACzE,OAAOF,OAAO,KAAK,CAAC,GAAG,CAAC,CAACE,OAASH,QAAQ,WAAW,CAACG,KAAK,IAAI;QAC/D,WAAWF,OAAO,SAAS,CAAC,GAAG,CAAC,CAACE,OAASH,QAAQ,WAAW,CAACG,KAAK,IAAI;IACzE;IACA,MAAMC,gBAAgBC,oBAAoBL,QAAQ,MAAM;IACxD,MAAMM,cAAcF,cAAc,MAAM;IACxC,MAAMG,QAAQP,QAAQ,WAAW,QAAQQ;IACzC,MAAMC,YAAY,IAAIC;IACtBC,6BAA6BL,aAAa;QAAE,SAASC;IAAM;IAC3D,MAAMK,aAA8B,EAA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AASgD,QAAQ,WAAW;QAC5B,YAAYS,KAAK,GAAG,CAAC,GAAGT,QAAQ,OAAO,KAAKhD,UAAU,OAAO;IAC/D;IAEA,IAAI;QACF,MAAMT,QAAQ,QAAQ,GAAGgC;IAC3B,EAAE,OAAOI,OAAO;QACdD,gBAAgB,IAAI,CAACC;QACrBJ,OAAO,MAAM,GAAG;QAChBA,OAAO,eAAe,GAAGG,gBAAgB,GAAG,CAAC8B;IAC/C;IACA7D,cAAc,OAAO;IACrB,IAAI+B,gBAAgB,MAAM,EACxB,MAAM,IAAIgC,yBAAyBnC,QAAQG;IAC7C,OAAOH;AACT"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { isResourceRecoveryError } from "../errors.mjs";
|
|
2
|
+
import { buildTestRunReportPlan } from "../reporting/test-plan.mjs";
|
|
1
3
|
import { createDocumentRuntime } from "./document-runtime.mjs";
|
|
2
4
|
import { WorkflowExecutionFailure, asExecutionError } from "./execution-failure.mjs";
|
|
5
|
+
import { decideRetry } from "./result-metadata.mjs";
|
|
3
6
|
import { runCollectedCase } from "./run-collected-case.mjs";
|
|
4
7
|
const asNotRun = (collectedCase, projectName, reason)=>({
|
|
5
8
|
caseId: collectedCase.caseId,
|
|
@@ -21,6 +24,13 @@ async function runWorkflowDocument(document, options) {
|
|
|
21
24
|
const retry = options.retry ?? options.project?.retry ?? 0;
|
|
22
25
|
if (!Number.isInteger(retry) || retry < 0) throw new TypeError('Workflow document retry must be a non-negative integer.');
|
|
23
26
|
const runtime = createDocumentRuntime(document, {
|
|
27
|
+
plan: options.plan ?? buildTestRunReportPlan(document, {
|
|
28
|
+
defaultTimeoutMs: options.defaultTimeoutMs,
|
|
29
|
+
retry: {
|
|
30
|
+
scope: 'case',
|
|
31
|
+
count: retry
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
24
34
|
documentSetup: options.documentSetup,
|
|
25
35
|
documentAttemptIndex: options.documentAttemptIndex,
|
|
26
36
|
resolveNode: options.resolveNode,
|
|
@@ -41,13 +51,13 @@ async function runWorkflowDocument(document, options) {
|
|
|
41
51
|
let documentResult;
|
|
42
52
|
const executionErrors = [];
|
|
43
53
|
let fatalError = false;
|
|
44
|
-
let
|
|
54
|
+
let documentStopReason;
|
|
45
55
|
try {
|
|
46
56
|
runtimeStarted = true;
|
|
47
57
|
const startedDocument = await runtime.start();
|
|
48
58
|
if (runtime.canRunCases) for (const collectedCase of document.cases){
|
|
49
|
-
if (
|
|
50
|
-
const outcome = asNotRun(collectedCase, projectName, signal.aborted ? options.stopReason?.() ?? 'interrupted' : fatalError ? 'fatal-error' :
|
|
59
|
+
if (documentStopReason || fatalError || signal.aborted || options.shouldStop?.()) {
|
|
60
|
+
const outcome = asNotRun(collectedCase, projectName, signal.aborted ? options.stopReason?.() ?? 'interrupted' : fatalError ? 'fatal-error' : documentStopReason ?? options.stopReason?.() ?? 'interrupted');
|
|
51
61
|
cases.push(outcome);
|
|
52
62
|
await options.onCaseOutcome?.(outcome);
|
|
53
63
|
continue;
|
|
@@ -55,6 +65,7 @@ async function runWorkflowDocument(document, options) {
|
|
|
55
65
|
await options.onCaseStart?.(collectedCase);
|
|
56
66
|
const attempts = [];
|
|
57
67
|
for(let attemptIndex = 0; attemptIndex <= retry; attemptIndex += 1){
|
|
68
|
+
let attemptFatalError = false;
|
|
58
69
|
let attemptFailure;
|
|
59
70
|
const run = await runCollectedCase(collectedCase, {
|
|
60
71
|
resolveNode: options.resolveNode,
|
|
@@ -67,7 +78,23 @@ async function runWorkflowDocument(document, options) {
|
|
|
67
78
|
defaultTimeoutMs: options.defaultTimeoutMs,
|
|
68
79
|
onStepStart: options.onStepStart,
|
|
69
80
|
onStepResult: options.onStepResult,
|
|
70
|
-
onResult:
|
|
81
|
+
onResult: async (result)=>{
|
|
82
|
+
attemptFatalError = options.isFatalError?.(result) ?? false;
|
|
83
|
+
result.retryDecision = decideRetry({
|
|
84
|
+
scope: 'case',
|
|
85
|
+
retryCount: retry,
|
|
86
|
+
attemptIndex,
|
|
87
|
+
status: result.status,
|
|
88
|
+
cleanupPending: result.cleanup?.status === 'pending',
|
|
89
|
+
operationPending: !!result.pendingOperations?.length,
|
|
90
|
+
cleanupFailed: result.cleanup?.status === 'failed' || !!result.teardownErrors?.length,
|
|
91
|
+
infrastructureError: result.executionErrors?.some((error)=>!isResourceRecoveryError(error)),
|
|
92
|
+
fatalError: attemptFatalError,
|
|
93
|
+
interrupted: signal.aborted,
|
|
94
|
+
shouldStop: options.shouldStop?.()
|
|
95
|
+
});
|
|
96
|
+
await options.onCaseResult?.(result);
|
|
97
|
+
},
|
|
71
98
|
reportScopeId: options.resolveCaseReportScopeId?.(collectedCase, attemptIndex, startedDocument.documentRunId),
|
|
72
99
|
createRunId: createCaseRunId ? ()=>createCaseRunId(collectedCase, attemptIndex) : void 0
|
|
73
100
|
}).catch((error)=>{
|
|
@@ -76,7 +103,14 @@ async function runWorkflowDocument(document, options) {
|
|
|
76
103
|
return attemptFailure.result;
|
|
77
104
|
});
|
|
78
105
|
attempts.push(run);
|
|
79
|
-
if (attemptFailure) {
|
|
106
|
+
if (attemptFailure && !attemptFailure.errors.every(isResourceRecoveryError)) {
|
|
107
|
+
run.retryDecision = decideRetry({
|
|
108
|
+
scope: 'case',
|
|
109
|
+
retryCount: retry,
|
|
110
|
+
attemptIndex,
|
|
111
|
+
status: run.status,
|
|
112
|
+
infrastructureError: true
|
|
113
|
+
});
|
|
80
114
|
cases.push({
|
|
81
115
|
caseId: collectedCase.caseId,
|
|
82
116
|
projectName,
|
|
@@ -92,8 +126,20 @@ async function runWorkflowDocument(document, options) {
|
|
|
92
126
|
});
|
|
93
127
|
throw attemptFailure;
|
|
94
128
|
}
|
|
95
|
-
fatalError =
|
|
96
|
-
|
|
129
|
+
fatalError = attemptFatalError;
|
|
130
|
+
run.retryDecision = decideRetry({
|
|
131
|
+
scope: 'case',
|
|
132
|
+
retryCount: retry,
|
|
133
|
+
attemptIndex,
|
|
134
|
+
status: run.status,
|
|
135
|
+
cleanupPending: run.cleanup?.status === 'pending',
|
|
136
|
+
cleanupFailed: run.cleanup?.status === 'failed' || !!run.teardownErrors?.length,
|
|
137
|
+
operationPending: !!run.pendingOperations?.length,
|
|
138
|
+
fatalError: fatalError || !!run.executionErrors?.some(isResourceRecoveryError),
|
|
139
|
+
interrupted: signal.aborted,
|
|
140
|
+
shouldStop: options.shouldStop?.()
|
|
141
|
+
});
|
|
142
|
+
if (run.retryDecision?.decision !== 'retry') break;
|
|
97
143
|
}
|
|
98
144
|
const run = attempts.at(-1);
|
|
99
145
|
const outcome = {
|
|
@@ -110,7 +156,8 @@ async function runWorkflowDocument(document, options) {
|
|
|
110
156
|
attempts
|
|
111
157
|
};
|
|
112
158
|
cases.push(outcome);
|
|
113
|
-
|
|
159
|
+
const retryStopReason = run.retryDecision?.reason;
|
|
160
|
+
documentStopReason = 'cleanup-pending' === retryStopReason || 'cleanup-failed' === retryStopReason || 'operation-pending' === retryStopReason || 'fatal-error' === retryStopReason ? retryStopReason : 'failed' === outcome.status && 'stop-document' === collectedCase.definition.onFailure ? 'bail' : void 0;
|
|
114
161
|
await options.onCaseOutcome?.(outcome);
|
|
115
162
|
}
|
|
116
163
|
else {
|
|
@@ -137,9 +184,9 @@ async function runWorkflowDocument(document, options) {
|
|
|
137
184
|
}
|
|
138
185
|
if (executionErrors.length) {
|
|
139
186
|
const completed = new Set(cases.map((outcome)=>outcome.caseId));
|
|
140
|
-
cases.push(...document.cases.filter((item)=>!completed.has(item.caseId)).map((item)=>asNotRun(item, projectName, 'interrupted')));
|
|
187
|
+
cases.push(...document.cases.filter((item)=>!completed.has(item.caseId)).map((item)=>asNotRun(item, projectName, executionErrors.every(isResourceRecoveryError) ? 'operation-pending' : 'interrupted')));
|
|
141
188
|
documentResult.status = 'failed';
|
|
142
|
-
documentResult.executionErrors = executionErrors.map(asExecutionError);
|
|
189
|
+
documentResult.executionErrors = executionErrors.filter((error)=>!documentResult.hostErrors?.some((host)=>host.error === error)).map(asExecutionError);
|
|
143
190
|
throw new WorkflowExecutionFailure({
|
|
144
191
|
document: documentResult,
|
|
145
192
|
cases
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-runner/engine/run-workflow-document.mjs","sources":["../../../../src/test-runner/engine/run-workflow-document.ts"],"sourcesContent":["import type { CollectedCase, CollectedWorkflowDocument } from '../parser/types';\nimport { createDocumentRuntime } from './document-runtime';\nimport {\n WorkflowExecutionFailure,\n asExecutionError,\n} from './execution-failure';\nimport { runCollectedCase } from './run-collected-case';\nimport type {\n CaseRunOutcome,\n CaseRunResult,\n RunWorkflowDocumentOptions,\n WorkflowDocumentExecutionResult,\n WorkflowDocumentRunResult,\n} from './types';\n\nconst asNotRun = (\n collectedCase: CollectedCase,\n projectName: string,\n reason: NonNullable<CaseRunOutcome['notRunReason']>,\n): CaseRunOutcome => ({\n caseId: collectedCase.caseId,\n projectName,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n ...(collectedCase.definition.onFailure\n ? { onFailure: collectedCase.definition.onFailure }\n : {}),\n status: 'not-run',\n notRunReason: reason,\n});\n\nexport async function runWorkflowDocument<TContext = undefined>(\n document: CollectedWorkflowDocument,\n options: RunWorkflowDocumentOptions<TContext>,\n): Promise<WorkflowDocumentExecutionResult> {\n const signal = options.signal ?? new AbortController().signal;\n const createDocumentRunId = options.createDocumentRunId;\n const createCaseRunId = options.createCaseRunId;\n const projectName = options.project?.name ?? document.projectId;\n const retry = options.retry ?? options.project?.retry ?? 0;\n if (!Number.isInteger(retry) || retry < 0) {\n throw new TypeError(\n 'Workflow document retry must be a non-negative integer.',\n );\n }\n const runtime = createDocumentRuntime(document, {\n documentSetup: options.documentSetup,\n documentAttemptIndex: options.documentAttemptIndex,\n resolveNode: options.resolveNode,\n project: options.project,\n projectContext: options.projectContext,\n signal,\n defaultTimeoutMs: options.defaultTimeoutMs,\n onStepStart: options.onStepStart,\n onStepResult: options.onStepResult,\n onResult: async (result) => {\n await options.documentSetup?.onDocumentResult?.(result, runtime.context);\n await options.onDocumentResult?.(result);\n },\n createDocumentRunId: createDocumentRunId\n ? () => createDocumentRunId(document)\n : undefined,\n });\n const cases: CaseRunOutcome[] = [];\n let runtimeStarted = false;\n let documentResult: WorkflowDocumentRunResult | undefined;\n const executionErrors: unknown[] = [];\n let fatalError = false;\n let stoppedByCase = false;\n\n try {\n runtimeStarted = true;\n const startedDocument = await runtime.start();\n\n if (!runtime.canRunCases) {\n const reason = signal.aborted\n ? (options.stopReason?.() ?? 'interrupted')\n : 'document-start-failed';\n cases.push(\n ...document.cases.map((collectedCase) =>\n asNotRun(collectedCase, projectName, reason),\n ),\n );\n } else {\n for (const collectedCase of document.cases) {\n if (\n stoppedByCase ||\n fatalError ||\n signal.aborted ||\n options.shouldStop?.()\n ) {\n const outcome = asNotRun(\n collectedCase,\n projectName,\n signal.aborted\n ? (options.stopReason?.() ?? 'interrupted')\n : fatalError\n ? 'fatal-error'\n : stoppedByCase\n ? 'bail'\n : (options.stopReason?.() ?? 'interrupted'),\n );\n cases.push(outcome);\n await options.onCaseOutcome?.(outcome);\n continue;\n }\n\n await options.onCaseStart?.(collectedCase);\n const attempts = [];\n for (let attemptIndex = 0; attemptIndex <= retry; attemptIndex += 1) {\n let attemptFailure:\n | WorkflowExecutionFailure<CaseRunResult>\n | undefined;\n const run = await runCollectedCase(collectedCase, {\n resolveNode: options.resolveNode,\n beforeEach: document.lifecycle.beforeEach,\n afterEach: document.lifecycle.afterEach,\n context: runtime.context,\n projectName,\n attemptIndex,\n signal: runtime.signal,\n defaultTimeoutMs: options.defaultTimeoutMs,\n onStepStart: options.onStepStart,\n onStepResult: options.onStepResult,\n onResult: options.onCaseResult,\n reportScopeId: options.resolveCaseReportScopeId?.(\n collectedCase,\n attemptIndex,\n startedDocument.documentRunId,\n ),\n createRunId: createCaseRunId\n ? () => createCaseRunId(collectedCase, attemptIndex)\n : undefined,\n }).catch((error: unknown) => {\n if (!(error instanceof WorkflowExecutionFailure)) throw error;\n attemptFailure = error as WorkflowExecutionFailure<CaseRunResult>;\n return attemptFailure.result;\n });\n attempts.push(run);\n if (attemptFailure) {\n cases.push({\n caseId: collectedCase.caseId,\n projectName,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n ...(collectedCase.definition.onFailure\n ? { onFailure: collectedCase.definition.onFailure }\n : {}),\n status: 'failed',\n run,\n attempts,\n });\n throw attemptFailure;\n }\n fatalError = options.isFatalError?.(run) ?? false;\n if (\n run.status === 'success' ||\n // Retrying cannot repair cleanup/report publication and would\n // replay actions that may already have completed successfully.\n !!run.teardownErrors?.length ||\n fatalError ||\n signal.aborted ||\n options.shouldStop?.()\n )\n break;\n }\n const run = attempts.at(-1)!;\n const outcome: CaseRunOutcome = {\n caseId: collectedCase.caseId,\n projectName,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n ...(collectedCase.definition.onFailure\n ? { onFailure: collectedCase.definition.onFailure }\n : {}),\n status: run.status,\n run,\n attempts,\n };\n cases.push(outcome);\n stoppedByCase =\n outcome.status === 'failed' &&\n collectedCase.definition.onFailure === 'stop-document';\n await options.onCaseOutcome?.(outcome);\n }\n }\n } catch (error) {\n executionErrors.push(\n ...(error instanceof WorkflowExecutionFailure ? error.errors : [error]),\n );\n } finally {\n if (runtimeStarted) {\n try {\n documentResult = await runtime.finish();\n } catch (error) {\n if (error instanceof WorkflowExecutionFailure) {\n documentResult = error.result as WorkflowDocumentRunResult;\n for (const failure of error.errors)\n if (!executionErrors.includes(failure))\n executionErrors.push(failure);\n } else executionErrors.push(error);\n }\n }\n }\n\n if (!documentResult) {\n if (executionErrors.length)\n throw new AggregateError(\n executionErrors,\n 'Workflow execution did not produce a document result.',\n );\n throw new Error(\n `Workflow document \"${document.sourcePath}\" did not produce a result.`,\n );\n }\n if (executionErrors.length) {\n const completed = new Set(cases.map((outcome) => outcome.caseId));\n cases.push(\n ...document.cases\n .filter((item) => !completed.has(item.caseId))\n .map((item) => asNotRun(item, projectName, 'interrupted')),\n );\n documentResult.status = 'failed';\n documentResult.executionErrors = executionErrors.map(asExecutionError);\n throw new WorkflowExecutionFailure(\n { document: documentResult, cases },\n executionErrors,\n );\n }\n return { document: documentResult, cases };\n}\n"],"names":["asNotRun","collectedCase","projectName","reason","runWorkflowDocument","document","options","signal","AbortController","createDocumentRunId","createCaseRunId","retry","Number","TypeError","runtime","createDocumentRuntime","result","undefined","cases","runtimeStarted","documentResult","executionErrors","fatalError","stoppedByCase","startedDocument","outcome","attempts","attemptIndex","attemptFailure","run","runCollectedCase","error","WorkflowExecutionFailure","failure","AggregateError","Error","completed","Set","item","asExecutionError"],"mappings":";;;AAeA,MAAMA,WAAW,CACfC,eACAC,aACAC,SACoB;QACpB,QAAQF,cAAc,MAAM;QAC5BC;QACA,MAAMD,cAAc,UAAU,CAAC,IAAI;QACnC,YAAYA,cAAc,UAAU;QACpC,WAAWA,cAAc,SAAS;QAClC,GAAIA,cAAc,UAAU,CAAC,SAAS,GAClC;YAAE,WAAWA,cAAc,UAAU,CAAC,SAAS;QAAC,IAChD,CAAC,CAAC;QACN,QAAQ;QACR,cAAcE;IAChB;AAEO,eAAeC,oBACpBC,QAAmC,EACnCC,OAA6C;IAE7C,MAAMC,SAASD,QAAQ,MAAM,IAAI,IAAIE,kBAAkB,MAAM;IAC7D,MAAMC,sBAAsBH,QAAQ,mBAAmB;IACvD,MAAMI,kBAAkBJ,QAAQ,eAAe;IAC/C,MAAMJ,cAAcI,QAAQ,OAAO,EAAE,QAAQD,SAAS,SAAS;IAC/D,MAAMM,QAAQL,QAAQ,KAAK,IAAIA,QAAQ,OAAO,EAAE,SAAS;IACzD,IAAI,CAACM,OAAO,SAAS,CAACD,UAAUA,QAAQ,GACtC,MAAM,IAAIE,UACR;IAGJ,MAAMC,UAAUC,sBAAsBV,UAAU;QAC9C,eAAeC,QAAQ,aAAa;QACpC,sBAAsBA,QAAQ,oBA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ACA,OAAStC,SAASsC,MAAMpC,aAAa;QAE/CkB,eAAe,MAAM,GAAG;QACxBA,eAAe,eAAe,GAAGC,gBAAgB,GAAG,CAACkB;QACrD,MAAM,IAAIP,yBACR;YAAE,UAAUZ;YAAgBF;QAAM,GAClCG;IAEJ;IACA,OAAO;QAAE,UAAUD;QAAgBF;IAAM;AAC3C"}
|
|
1
|
+
{"version":3,"file":"test-runner/engine/run-workflow-document.mjs","sources":["../../../../src/test-runner/engine/run-workflow-document.ts"],"sourcesContent":["import { isResourceRecoveryError } from '../errors';\nimport type { CollectedCase, CollectedWorkflowDocument } from '../parser/types';\nimport { buildTestRunReportPlan } from '../reporting/test-plan';\nimport { createDocumentRuntime } from './document-runtime';\nimport {\n WorkflowExecutionFailure,\n asExecutionError,\n} from './execution-failure';\nimport { decideRetry } from './result-metadata';\nimport { runCollectedCase } from './run-collected-case';\nimport type {\n CaseRunOutcome,\n CaseRunResult,\n RunWorkflowDocumentOptions,\n WorkflowDocumentExecutionResult,\n WorkflowDocumentRunResult,\n} from './types';\n\nconst asNotRun = (\n collectedCase: CollectedCase,\n projectName: string,\n reason: NonNullable<CaseRunOutcome['notRunReason']>,\n): CaseRunOutcome => ({\n caseId: collectedCase.caseId,\n projectName,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n ...(collectedCase.definition.onFailure\n ? { onFailure: collectedCase.definition.onFailure }\n : {}),\n status: 'not-run',\n notRunReason: reason,\n});\n\nexport async function runWorkflowDocument<TContext = undefined>(\n document: CollectedWorkflowDocument,\n options: RunWorkflowDocumentOptions<TContext>,\n): Promise<WorkflowDocumentExecutionResult> {\n const signal = options.signal ?? new AbortController().signal;\n const createDocumentRunId = options.createDocumentRunId;\n const createCaseRunId = options.createCaseRunId;\n const projectName = options.project?.name ?? document.projectId;\n const retry = options.retry ?? options.project?.retry ?? 0;\n if (!Number.isInteger(retry) || retry < 0) {\n throw new TypeError(\n 'Workflow document retry must be a non-negative integer.',\n );\n }\n const runtime = createDocumentRuntime(document, {\n plan:\n options.plan ??\n buildTestRunReportPlan(document, {\n defaultTimeoutMs: options.defaultTimeoutMs,\n retry: { scope: 'case', count: retry },\n }),\n documentSetup: options.documentSetup,\n documentAttemptIndex: options.documentAttemptIndex,\n resolveNode: options.resolveNode,\n project: options.project,\n projectContext: options.projectContext,\n signal,\n defaultTimeoutMs: options.defaultTimeoutMs,\n onStepStart: options.onStepStart,\n onStepResult: options.onStepResult,\n onResult: async (result) => {\n await options.documentSetup?.onDocumentResult?.(result, runtime.context);\n await options.onDocumentResult?.(result);\n },\n createDocumentRunId: createDocumentRunId\n ? () => createDocumentRunId(document)\n : undefined,\n });\n const cases: CaseRunOutcome[] = [];\n let runtimeStarted = false;\n let documentResult: WorkflowDocumentRunResult | undefined;\n const executionErrors: unknown[] = [];\n let fatalError = false;\n let documentStopReason: CaseRunOutcome['notRunReason'];\n\n try {\n runtimeStarted = true;\n const startedDocument = await runtime.start();\n\n if (!runtime.canRunCases) {\n const reason = signal.aborted\n ? (options.stopReason?.() ?? 'interrupted')\n : 'document-start-failed';\n cases.push(\n ...document.cases.map((collectedCase) =>\n asNotRun(collectedCase, projectName, reason),\n ),\n );\n } else {\n for (const collectedCase of document.cases) {\n if (\n documentStopReason ||\n fatalError ||\n signal.aborted ||\n options.shouldStop?.()\n ) {\n const outcome = asNotRun(\n collectedCase,\n projectName,\n signal.aborted\n ? (options.stopReason?.() ?? 'interrupted')\n : fatalError\n ? 'fatal-error'\n : (documentStopReason ??\n options.stopReason?.() ??\n 'interrupted'),\n );\n cases.push(outcome);\n await options.onCaseOutcome?.(outcome);\n continue;\n }\n\n await options.onCaseStart?.(collectedCase);\n const attempts = [];\n for (let attemptIndex = 0; attemptIndex <= retry; attemptIndex += 1) {\n let attemptFatalError = false;\n let attemptFailure:\n | WorkflowExecutionFailure<CaseRunResult>\n | undefined;\n const run = await runCollectedCase(collectedCase, {\n resolveNode: options.resolveNode,\n beforeEach: document.lifecycle.beforeEach,\n afterEach: document.lifecycle.afterEach,\n context: runtime.context,\n projectName,\n attemptIndex,\n signal: runtime.signal,\n defaultTimeoutMs: options.defaultTimeoutMs,\n onStepStart: options.onStepStart,\n onStepResult: options.onStepResult,\n onResult: async (result) => {\n attemptFatalError = options.isFatalError?.(result) ?? false;\n result.retryDecision = decideRetry({\n scope: 'case',\n retryCount: retry,\n attemptIndex,\n status: result.status,\n cleanupPending: result.cleanup?.status === 'pending',\n operationPending: !!result.pendingOperations?.length,\n cleanupFailed:\n result.cleanup?.status === 'failed' ||\n !!result.teardownErrors?.length,\n infrastructureError: result.executionErrors?.some(\n (error) => !isResourceRecoveryError(error),\n ),\n fatalError: attemptFatalError,\n interrupted: signal.aborted,\n shouldStop: options.shouldStop?.(),\n });\n await options.onCaseResult?.(result);\n },\n reportScopeId: options.resolveCaseReportScopeId?.(\n collectedCase,\n attemptIndex,\n startedDocument.documentRunId,\n ),\n createRunId: createCaseRunId\n ? () => createCaseRunId(collectedCase, attemptIndex)\n : undefined,\n }).catch((error: unknown) => {\n if (!(error instanceof WorkflowExecutionFailure)) throw error;\n attemptFailure = error as WorkflowExecutionFailure<CaseRunResult>;\n return attemptFailure.result;\n });\n attempts.push(run);\n if (\n attemptFailure &&\n !attemptFailure.errors.every(isResourceRecoveryError)\n ) {\n run.retryDecision = decideRetry({\n scope: 'case',\n retryCount: retry,\n attemptIndex,\n status: run.status,\n infrastructureError: true,\n });\n cases.push({\n caseId: collectedCase.caseId,\n projectName,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n ...(collectedCase.definition.onFailure\n ? { onFailure: collectedCase.definition.onFailure }\n : {}),\n status: 'failed',\n run,\n attempts,\n });\n throw attemptFailure;\n }\n fatalError = attemptFatalError;\n // Result callbacks can interrupt execution or trigger bail. Observe\n // that boundary again before admitting another attempt.\n run.retryDecision = decideRetry({\n scope: 'case',\n retryCount: retry,\n attemptIndex,\n status: run.status,\n cleanupPending: run.cleanup?.status === 'pending',\n cleanupFailed:\n run.cleanup?.status === 'failed' || !!run.teardownErrors?.length,\n operationPending: !!run.pendingOperations?.length,\n fatalError:\n fatalError ||\n !!run.executionErrors?.some(isResourceRecoveryError),\n interrupted: signal.aborted,\n shouldStop: options.shouldStop?.(),\n });\n if (run.retryDecision?.decision !== 'retry') break;\n }\n const run = attempts.at(-1)!;\n const outcome: CaseRunOutcome = {\n caseId: collectedCase.caseId,\n projectName,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n ...(collectedCase.definition.onFailure\n ? { onFailure: collectedCase.definition.onFailure }\n : {}),\n status: run.status,\n run,\n attempts,\n };\n cases.push(outcome);\n const retryStopReason = run.retryDecision?.reason;\n documentStopReason =\n retryStopReason === 'cleanup-pending' ||\n retryStopReason === 'cleanup-failed' ||\n retryStopReason === 'operation-pending' ||\n retryStopReason === 'fatal-error'\n ? retryStopReason\n : outcome.status === 'failed' &&\n collectedCase.definition.onFailure === 'stop-document'\n ? 'bail'\n : undefined;\n await options.onCaseOutcome?.(outcome);\n }\n }\n } catch (error) {\n executionErrors.push(\n ...(error instanceof WorkflowExecutionFailure ? error.errors : [error]),\n );\n } finally {\n if (runtimeStarted) {\n try {\n documentResult = await runtime.finish();\n } catch (error) {\n if (error instanceof WorkflowExecutionFailure) {\n documentResult = error.result as WorkflowDocumentRunResult;\n for (const failure of error.errors)\n if (!executionErrors.includes(failure))\n executionErrors.push(failure);\n } else executionErrors.push(error);\n }\n }\n }\n\n if (!documentResult) {\n if (executionErrors.length)\n throw new AggregateError(\n executionErrors,\n 'Workflow execution did not produce a document result.',\n );\n throw new Error(\n `Workflow document \"${document.sourcePath}\" did not produce a result.`,\n );\n }\n if (executionErrors.length) {\n const completed = new Set(cases.map((outcome) => outcome.caseId));\n cases.push(\n ...document.cases\n .filter((item) => !completed.has(item.caseId))\n .map((item) =>\n asNotRun(\n item,\n projectName,\n executionErrors.every(isResourceRecoveryError)\n ? 'operation-pending'\n : 'interrupted',\n ),\n ),\n );\n documentResult.status = 'failed';\n documentResult.executionErrors = executionErrors\n .filter(\n (error) =>\n !documentResult.hostErrors?.some((host) => host.error === error),\n )\n .map(asExecutionError);\n throw new WorkflowExecutionFailure(\n { document: documentResult, cases },\n executionErrors,\n );\n }\n return { document: documentResult, cases };\n}\n"],"names":["asNotRun","collectedCase","projectName","reason","runWorkflowDocument","document","options","signal","AbortController","createDocumentRunId","createCaseRunId","retry","Number","TypeError","runtime","createDocumentRuntime","buildTestRunReportPlan","result","undefined","cases","runtimeStarted","documentResult","executionErrors","fatalError","documentStopReason","startedDocument","outcome","attempts","attemptIndex","attemptFatalError","attemptFailure","run","runCollectedCase","decideRetry","error","isResourceRecoveryError","WorkflowExecutionFailure","retryStopReason","failure","AggregateError","Error","completed","Set","item","host","asExecutionError"],"mappings":";;;;;;AAkBA,MAAMA,WAAW,CACfC,eACAC,aACAC,SACoB;QACpB,QAAQF,cAAc,MAAM;QAC5BC;QACA,MAAMD,cAAc,UAAU,CAAC,IAAI;QACnC,YAAYA,cAAc,UAAU;QACpC,WAAWA,cAAc,SAAS;QAClC,GAAIA,cAAc,UAAU,CAAC,SAAS,GAClC;YAAE,WAAWA,cAAc,UAAU,CAAC,SAAS;QAAC,IAChD,CAAC,CAAC;QACN,QAAQ;QACR,cAAcE;IAChB;AAEO,eAAeC,oBACpBC,QAAmC,EACnCC,OAA6C;IAE7C,MAAMC,SAASD,QAAQ,MAAM,IAAI,IAAIE,kBAAkB,MAAM;IAC7D,MAAMC,sBAAsBH,QAAQ,mBAAmB;IACvD,MAAMI,kBAAkBJ,QAAQ,eAAe;IAC/C,MAAMJ,cAAcI,QAAQ,OAAO,EAAE,QAAQD,SAAS,SAAS;IAC/D,MAAMM,QAAQL,QAAQ,KAAK,IAAIA,QAAQ,OAAO,EAAE,SAAS;IACzD,IAAI,CAACM,OAAO,SAAS,CAACD,UAAUA,QAAQ,GACtC,MAAM,IAAIE,UACR;IA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KAAK,CACd,MAAM,CAAC,CAACsC,OAAS,CAACF,UAAU,GAAG,CAACE,KAAK,MAAM,GAC3C,GAAG,CAAC,CAACA,OACJ3C,SACE2C,MACAzC,aACAoB,gBAAgB,KAAK,CAACa,2BAClB,sBACA;QAIZd,eAAe,MAAM,GAAG;QACxBA,eAAe,eAAe,GAAGC,gBAC9B,MAAM,CACL,CAACY,QACC,CAACb,eAAe,UAAU,EAAE,KAAK,CAACuB,OAASA,KAAK,KAAK,KAAKV,QAE7D,GAAG,CAACW;QACP,MAAM,IAAIT,yBACR;YAAE,UAAUf;YAAgBF;QAAM,GAClCG;IAEJ;IACA,OAAO;QAAE,UAAUD;QAAgBF;IAAM;AAC3C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sanitizeReportError } from "./reporting/sanitize.mjs";
|
|
1
2
|
function _define_property(obj, key, value) {
|
|
2
3
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
3
4
|
value: value,
|
|
@@ -8,21 +9,18 @@ function _define_property(obj, key, value) {
|
|
|
8
9
|
else obj[key] = value;
|
|
9
10
|
return obj;
|
|
10
11
|
}
|
|
12
|
+
const workflowErrorKey = Symbol.for('@midscene/core/workflow-error');
|
|
13
|
+
let _workflowErrorKey = workflowErrorKey;
|
|
11
14
|
class WorkflowError extends Error {
|
|
12
15
|
toJSON() {
|
|
13
16
|
return {
|
|
14
|
-
|
|
15
|
-
message: this.message,
|
|
16
|
-
code: this.code,
|
|
17
|
-
...void 0 === this.details ? {} : {
|
|
18
|
-
details: this.details
|
|
19
|
-
}
|
|
17
|
+
...sanitizeReportError(this)
|
|
20
18
|
};
|
|
21
19
|
}
|
|
22
20
|
constructor(message, options = {}){
|
|
23
21
|
super(message, {
|
|
24
22
|
cause: options.cause
|
|
25
|
-
}), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
|
|
23
|
+
}), _define_property(this, _workflowErrorKey, true), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
|
|
26
24
|
this.name = new.target.name;
|
|
27
25
|
this.code = options.code ?? 'WORKFLOW_ERROR';
|
|
28
26
|
this.details = options.details;
|
|
@@ -164,10 +162,21 @@ class FatalDeviceError extends WorkflowError {
|
|
|
164
162
|
}
|
|
165
163
|
}
|
|
166
164
|
const isFatalDeviceError = (error)=>{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
const seen = new Set();
|
|
166
|
+
const pending = [
|
|
167
|
+
error
|
|
168
|
+
];
|
|
169
|
+
while(pending.length && seen.size < 50){
|
|
170
|
+
const current = pending.pop();
|
|
171
|
+
if ('object' != typeof current || null === current || seen.has(current)) continue;
|
|
172
|
+
seen.add(current);
|
|
173
|
+
if (current instanceof FatalDeviceError || 'FATAL_DEVICE_ERROR' === current.code) return true;
|
|
174
|
+
if (current instanceof Error && /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(current.message)) return true;
|
|
175
|
+
const nested = current;
|
|
176
|
+
if (void 0 !== nested.cause) pending.push(nested.cause);
|
|
177
|
+
if (Array.isArray(nested.errors)) pending.push(...nested.errors.slice(0, 50));
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
171
180
|
};
|
|
172
181
|
class CaseExecutionError extends WorkflowError {
|
|
173
182
|
constructor(result){
|
|
@@ -194,8 +203,12 @@ class WorkflowDocumentExecutionError extends WorkflowError {
|
|
|
194
203
|
}
|
|
195
204
|
}
|
|
196
205
|
function normalizeNodeExecutionError(error, node) {
|
|
197
|
-
return error
|
|
206
|
+
return isWorkflowError(error) ? error : new NodeExecutionError(node, error);
|
|
207
|
+
}
|
|
208
|
+
function isWorkflowError(error) {
|
|
209
|
+
return 'object' == typeof error && null !== error && true === error[workflowErrorKey];
|
|
198
210
|
}
|
|
199
|
-
|
|
211
|
+
const isResourceRecoveryError = (error)=>isWorkflowError(error) && 'RESOURCE_RECOVERY_TIMEOUT' === error.code;
|
|
212
|
+
export { CaseExecutionError, DuplicateNodeError, FatalDeviceError, NodeDefinitionError, NodeExecutionError, NodeInputValidationError, NodeNotFoundError, NodeScopeTeardownError, ProjectSetupError, ProjectTeardownError, StepTimeoutError, WorkflowDocumentExecutionError, WorkflowError, WorkflowLifecycleError, WorkflowParseError, isFatalDeviceError, isResourceRecoveryError, isWorkflowError, normalizeNodeExecutionError };
|
|
200
213
|
|
|
201
214
|
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-runner/errors.mjs","sources":["../../../src/test-runner/errors.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nexport interface WorkflowErrorOptions {\n code?: string;\n details?: unknown;\n cause?: unknown;\n}\n\nexport class WorkflowError extends Error {\n readonly code: string;\n readonly details?: unknown;\n\n constructor(message: string, options: WorkflowErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? 'WORKFLOW_ERROR';\n this.details = options.details;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n ...(this.details === undefined ? {} : { details: this.details }),\n };\n }\n}\n\nexport class WorkflowParseError extends WorkflowError {\n constructor(message: string, details?: unknown, cause?: unknown) {\n super(message, { code: 'WORKFLOW_PARSE_ERROR', details, cause });\n }\n}\n\nexport class NodeDefinitionError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_DEFINITION_ERROR', details });\n }\n}\n\nexport class DuplicateNodeError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is already registered.`, {\n code: 'DUPLICATE_NODE',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeNotFoundError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is not registered.`, {\n code: 'NODE_NOT_FOUND',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeInputValidationError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_INPUT_VALIDATION_ERROR', details });\n }\n\n static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\n }\n}\n\nexport class StepTimeoutError extends WorkflowError {\n readonly timeoutMs: number;\n readonly node?: string;\n\n constructor(timeoutMs: number, node?: string) {\n super(\n node\n ? `Node \"${node}\" timed out after ${timeoutMs}ms.`\n : `Step timed out after ${timeoutMs}ms.`,\n {\n code: 'STEP_TIMEOUT',\n details: { timeoutMs, ...(node === undefined ? {} : { node }) },\n },\n );\n this.timeoutMs = timeoutMs;\n this.node = node;\n }\n}\n\nexport class NodeExecutionError extends WorkflowError {\n readonly node: string;\n\n constructor(\n node: string,\n cause: unknown,\n /** Failed actions can still produce useful, JSON-compatible diagnostic data. */\n readonly output?: import('./node/types').NodeResult,\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Node \"${node}\" failed: ${causeMessage}`, {\n code: 'NODE_EXECUTION_ERROR',\n details: { node },\n cause,\n });\n this.node = node;\n }\n}\n\nexport class WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\n};\n\nexport class CaseExecutionError extends WorkflowError {\n readonly result: import('./engine/types').CaseRunResult;\n\n constructor(result: import('./engine/types').CaseRunResult) {\n super(`Case \"${result.name}\" failed.`, {\n code: 'CASE_EXECUTION_FAILED',\n details: { caseId: result.caseId, runId: result.runId },\n });\n this.result = result;\n }\n}\n\nexport class WorkflowDocumentExecutionError extends WorkflowError {\n readonly result: import('./engine/types').WorkflowDocumentRunResult;\n\n constructor(result: import('./engine/types').WorkflowDocumentRunResult) {\n super(`Workflow document \"${result.sourcePath}\" failed.`, {\n code: 'WORKFLOW_DOCUMENT_EXECUTION_FAILED',\n details: {\n documentId: result.documentId,\n documentRunId: result.documentRunId,\n },\n });\n this.result = result;\n }\n}\n\nexport function normalizeNodeExecutionError(\n error: unknown,\n node: string,\n): WorkflowError {\n return error instanceof WorkflowError\n ? error\n : new NodeExecutionError(node, error);\n}\n"],"names":["WorkflowError","Error","undefined","message","options","WorkflowParseError","details","cause","NodeDefinitionError","DuplicateNodeError","node","NodeNotFoundError","NodeInputValidationError","error","issues","issue","String","firstIssue","path","StepTimeoutError","timeoutMs","NodeExecutionError","output","causeMessage","WorkflowLifecycleError","ProjectSetupError","ProjectTeardownError","NodeScopeTeardownError","FatalDeviceError","isFatalDeviceError","CaseExecutionError","result","WorkflowDocumentExecutionError","normalizeNodeExecutionError"],"mappings":";;;;;;;;;;AAQO,MAAMA,sBAAsBC;IAWjC,SAAkC;QAChC,OAAO;YACL,MAAM,IAAI,CAAC,IAAI;YACf,SAAS,IAAI,CAAC,OAAO;YACrB,MAAM,IAAI,CAAC,IAAI;YACf,GAAI,AAAiBC,WAAjB,IAAI,CAAC,OAAO,GAAiB,CAAC,IAAI;gBAAE,SAAS,IAAI,CAAC,OAAO;YAAC,CAAC;QACjE;IACF;IAdA,YAAYC,OAAe,EAAEC,UAAgC,CAAC,CAAC,CAAE;QAC/D,KAAK,CAACD,SAAS;YAAE,OAAOC,QAAQ,KAAK;QAAC,IAJxC,uBAAS,QAAT,SACA,uBAAS,WAAT;QAIE,IAAI,CAAC,IAAI,GAAG,WAAW,IAAI;QAC3B,IAAI,CAAC,IAAI,GAAGA,QAAQ,IAAI,IAAI;QAC5B,IAAI,CAAC,OAAO,GAAGA,QAAQ,OAAO;IAChC;AAUF;AAEO,MAAMC,2BAA2BL;IACtC,YAAYG,OAAe,EAAEG,OAAiB,EAAEC,KAAe,CAAE;QAC/D,KAAK,CAACJ,SAAS;YAAE,MAAM;YAAwBG;YAASC;QAAM;IAChE;AACF;AAEO,MAAMC,4BAA4BR;IACvC,YAAYG,OAAe,EAAEG,OAAiB,CAAE;QAC9C,KAAK,CAACH,SAAS;YAAE,MAAM;YAAyBG;QAAQ;IAC1D;AACF;AAEO,MAAMG,2BAA2BT;IAGtC,YAAYU,IAAY,CAAE;Q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F;AAEO,SAASE,4BACdpB,KAAc,EACdH,IAAY;IAEZ,OAAOG,iBAAiBb,gBACpBa,QACA,IAAIQ,mBAAmBX,MAAMG;AACnC"}
|
|
1
|
+
{"version":3,"file":"test-runner/errors.mjs","sources":["../../../src/test-runner/errors.ts"],"sourcesContent":["import type { z } from 'zod/v4';\nimport { sanitizeReportError } from './reporting/sanitize';\n\nconst workflowErrorKey = Symbol.for('@midscene/core/workflow-error');\n\nexport interface WorkflowErrorOptions {\n code?: string;\n details?: unknown;\n cause?: unknown;\n}\n\nexport class WorkflowError extends Error {\n readonly [workflowErrorKey] = true;\n readonly code: string;\n readonly details?: unknown;\n\n constructor(message: string, options: WorkflowErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? 'WORKFLOW_ERROR';\n this.details = options.details;\n }\n\n toJSON(): Record<string, unknown> {\n return { ...sanitizeReportError(this) };\n }\n}\n\nexport class WorkflowParseError extends WorkflowError {\n constructor(message: string, details?: unknown, cause?: unknown) {\n super(message, { code: 'WORKFLOW_PARSE_ERROR', details, cause });\n }\n}\n\nexport class NodeDefinitionError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_DEFINITION_ERROR', details });\n }\n}\n\nexport class DuplicateNodeError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is already registered.`, {\n code: 'DUPLICATE_NODE',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeNotFoundError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is not registered.`, {\n code: 'NODE_NOT_FOUND',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeInputValidationError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_INPUT_VALIDATION_ERROR', details });\n }\n\n static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\n }\n}\n\nexport class StepTimeoutError extends WorkflowError {\n readonly timeoutMs: number;\n readonly node?: string;\n\n constructor(timeoutMs: number, node?: string) {\n super(\n node\n ? `Node \"${node}\" timed out after ${timeoutMs}ms.`\n : `Step timed out after ${timeoutMs}ms.`,\n {\n code: 'STEP_TIMEOUT',\n details: { timeoutMs, ...(node === undefined ? {} : { node }) },\n },\n );\n this.timeoutMs = timeoutMs;\n this.node = node;\n }\n}\n\nexport class NodeExecutionError extends WorkflowError {\n readonly node: string;\n\n constructor(\n node: string,\n cause: unknown,\n /** Failed actions can still produce useful, JSON-compatible diagnostic data. */\n readonly output?: import('./node/types').NodeResult,\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Node \"${node}\" failed: ${causeMessage}`, {\n code: 'NODE_EXECUTION_ERROR',\n details: { node },\n cause,\n });\n this.node = node;\n }\n}\n\nexport class WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n const seen = new Set<object>();\n const pending: unknown[] = [error];\n while (pending.length && seen.size < 50) {\n const current = pending.pop();\n if (typeof current !== 'object' || current === null || seen.has(current))\n continue;\n seen.add(current);\n if (\n current instanceof FatalDeviceError ||\n (current as { code?: unknown }).code === 'FATAL_DEVICE_ERROR'\n )\n return true;\n if (\n current instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n current.message,\n )\n )\n return true;\n const nested = current as { cause?: unknown; errors?: unknown };\n if (nested.cause !== undefined) pending.push(nested.cause);\n if (Array.isArray(nested.errors))\n pending.push(...nested.errors.slice(0, 50));\n }\n return false;\n};\n\nexport class CaseExecutionError extends WorkflowError {\n readonly result: import('./engine/types').CaseRunResult;\n\n constructor(result: import('./engine/types').CaseRunResult) {\n super(`Case \"${result.name}\" failed.`, {\n code: 'CASE_EXECUTION_FAILED',\n details: { caseId: result.caseId, runId: result.runId },\n });\n this.result = result;\n }\n}\n\nexport class WorkflowDocumentExecutionError extends WorkflowError {\n readonly result: import('./engine/types').WorkflowDocumentRunResult;\n\n constructor(result: import('./engine/types').WorkflowDocumentRunResult) {\n super(`Workflow document \"${result.sourcePath}\" failed.`, {\n code: 'WORKFLOW_DOCUMENT_EXECUTION_FAILED',\n details: {\n documentId: result.documentId,\n documentRunId: result.documentRunId,\n },\n });\n this.result = result;\n }\n}\n\nexport function normalizeNodeExecutionError(\n error: unknown,\n node: string,\n): WorkflowError {\n return isWorkflowError(error) ? error : new NodeExecutionError(node, error);\n}\n\n/** CJS and ESM integrations share error identity without wrapping it twice. */\nexport function isWorkflowError(error: unknown): error is WorkflowError {\n return (\n typeof error === 'object' &&\n error !== null &&\n (error as WorkflowError)[workflowErrorKey] === true\n );\n}\n\n/** A cancelled operation exhausted its recovery budget within its owning scope. */\nexport const isResourceRecoveryError = (error: unknown): boolean =>\n isWorkflowError(error) && error.code === 'RESOURCE_RECOVERY_TIMEOUT';\n"],"names":["workflowErrorKey","Symbol","_workflowErrorKey","WorkflowError","Error","sanitizeReportError","message","options","WorkflowParseError","details","cause","NodeDefinitionError","DuplicateNodeError","node","NodeNotFoundError","NodeInputValidationError","error","issues","issue","String","firstIssue","path","StepTimeoutError","timeoutMs","undefined","NodeExecutionError","output","causeMessage","WorkflowLifecycleError","ProjectSetupError","ProjectTeardownError","NodeScopeTeardownError","FatalDeviceError","isFatalDeviceError","seen","Set","pending","current","nested","Array","CaseExecutionError","result","WorkflowDocumentExecutionError","normalizeNodeExecutionError","isWorkflowError","isResourceRecoveryError"],"mappings":";;;;;;;;;;;AAGA,MAAMA,mBAAmBC,OAAO,GAAG,CAAC;IASxBC,oBAAAA;AADL,MAAMC,sBAAsBC;IAYjC,SAAkC;QAChC,OAAO;YAAE,GAAGC,oBAAoB,IAAI,CAAC;QAAC;IACxC;IATA,YAAYC,OAAe,EAAEC,UAAgC,CAAC,CAAC,CAAE;QAC/D,KAAK,CAACD,SAAS;YAAE,OAAOC,QAAQ,KAAK;QAAC,IALxC,uBAAUL,mBAAoB,OAC9B,uBAAS,QAAT,SACA,uBAAS,WAAT;QAIE,IAAI,CAAC,IAAI,GAAG,WAAW,IAAI;QAC3B,IAAI,CAAC,IAAI,GAAGK,QAAQ,IAAI,IAAI;QAC5B,IAAI,CAAC,OAAO,GAAGA,QAAQ,OAAO;IAChC;AAKF;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KAAK;QACzD,IAAIC,MAAM,OAAO,CAACD,OAAO,MAAM,GAC7BF,QAAQ,IAAI,IAAIE,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG;IAC3C;IACA,OAAO;AACT;AAEO,MAAME,2BAA2BrC;IAGtC,YAAYsC,MAA8C,CAAE;QAC1D,KAAK,CAAC,CAAC,MAAM,EAAEA,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE;YACrC,MAAM;YACN,SAAS;gBAAE,QAAQA,OAAO,MAAM;gBAAE,OAAOA,OAAO,KAAK;YAAC;QACxD,IANF,uBAAS,UAAT;QAOE,IAAI,CAAC,MAAM,GAAGA;IAChB;AACF;AAEO,MAAMC,uCAAuCvC;IAGlD,YAAYsC,MAA0D,CAAE;QACtE,KAAK,CAAC,CAAC,mBAAmB,EAAEA,OAAO,UAAU,CAAC,SAAS,CAAC,EAAE;YACxD,MAAM;YACN,SAAS;gBACP,YAAYA,OAAO,UAAU;gBAC7B,eAAeA,OAAO,aAAa;YACrC;QACF,IATF,uBAAS,UAAT;QAUE,IAAI,CAAC,MAAM,GAAGA;IAChB;AACF;AAEO,SAASE,4BACd3B,KAAc,EACdH,IAAY;IAEZ,OAAO+B,gBAAgB5B,SAASA,QAAQ,IAAIS,mBAAmBZ,MAAMG;AACvE;AAGO,SAAS4B,gBAAgB5B,KAAc;IAC5C,OACE,AAAiB,YAAjB,OAAOA,SACPA,AAAU,SAAVA,SACCA,AAA8C,SAA9CA,KAAuB,CAAChB,iBAAiB;AAE9C;AAGO,MAAM6C,0BAA0B,CAAC7B,QACtC4B,gBAAgB5B,UAAUA,AAAe,gCAAfA,MAAM,IAAI"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildTestRunReportPlan } from "./reporting/test-plan.mjs";
|
|
1
2
|
function executionRecordToResult(record) {
|
|
2
3
|
const execution = record.execution?.document;
|
|
3
4
|
const hostErrors = [
|
|
@@ -18,6 +19,7 @@ function executionRecordToResult(record) {
|
|
|
18
19
|
const projectName = record.projectName ?? execution?.projectName ?? record.platform;
|
|
19
20
|
return {
|
|
20
21
|
document: {
|
|
22
|
+
plan: execution?.plan ?? buildTestRunReportPlan(record.document),
|
|
21
23
|
documentId: record.document.documentId,
|
|
22
24
|
documentRunId: record.runId,
|
|
23
25
|
attemptIndex: record.attemptIndex,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-runner/execution-record.mjs","sources":["../../../src/test-runner/execution-record.ts"],"sourcesContent":["import type {\n WorkflowDocumentExecutionResult,\n WorkflowHostError,\n WorkflowReportSource,\n} from './engine/types';\nimport type { CollectedWorkflowDocument } from './parser/types';\n\n/**\n * One complete document invocation, including work outside the pure kernel.\n * The entry adapter owns resources and records their lifecycle here. A failed\n * setup has a record even though no document could be executed.\n *\n * runId identifies this invocation, not an Agent/report resource. File retries\n * create new records; they do not become per-Case retries. Report projection\n * must not mutate these records or redact the original API output.\n */\nexport interface WorkflowExecutionRecord {\n readonly runId: string;\n readonly attemptIndex: number;\n readonly sourcePath: string;\n readonly platform: string;\n readonly projectName?: string;\n readonly document: CollectedWorkflowDocument;\n readonly status: 'success' | 'failed';\n readonly startedAt: string;\n readonly endedAt: string;\n readonly durationMs: number;\n readonly execution?: WorkflowDocumentExecutionResult;\n readonly setupError?: unknown;\n readonly executionError?: unknown;\n readonly cleanupErrors: readonly unknown[];\n readonly outputs: Readonly<Record<string, unknown>>;\n readonly reportPaths: readonly string[];\n readonly reportSources?: readonly WorkflowReportSource[];\n readonly children?: readonly WorkflowExecutionRecord[];\n readonly reportError?: unknown;\n /** Entry-owned report copies or result files failed after execution finished. */\n readonly publicationErrors?: readonly unknown[];\n /** Entry progress/result observers failed, independently of action outcomes. */\n readonly observerErrors?: readonly unknown[];\n}\n\n/** Complete host facts as a kernel result. Report and summary consume this view. */\nexport function executionRecordToResult(\n record: WorkflowExecutionRecord,\n): WorkflowDocumentExecutionResult {\n const execution = record.execution?.document;\n const hostErrors: WorkflowHostError[] = [...(execution?.hostErrors ?? [])];\n const add = (phase: WorkflowHostError['phase'], error: unknown) => {\n if (error !== undefined) hostErrors.push({ phase, error });\n };\n add('setup', record.setupError);\n add('execution', record.executionError);\n for (const error of record.cleanupErrors) add('cleanup', error);\n add('report', record.reportError);\n for (const error of record.publicationErrors ?? []) add('publication', error);\n for (const error of record.observerErrors ?? []) add('observer', error);\n const projectName =\n record.projectName ?? execution?.projectName ?? record.platform;\n return {\n document: {\n documentId: record.document.documentId,\n documentRunId: record.runId,\n attemptIndex: record.attemptIndex,\n projectId: record.document.projectId,\n projectName,\n sourcePath: record.sourcePath,\n // Case failures are counted separately; host failures must not convert\n // successful Cases into retryable action failures.\n status:\n hostErrors.length || execution?.status === 'failed'\n ? 'failed'\n : 'success',\n startedAt: record.startedAt,\n endedAt: record.endedAt,\n durationMs: record.durationMs,\n beforeAll: execution?.beforeAll ?? [],\n afterAll: execution?.afterAll ?? [],\n ...(hostErrors.length ? { hostErrors } : {}),\n ...(execution?.executionErrors?.length\n ? { executionErrors: execution.executionErrors }\n : {}),\n ...(execution?.teardownErrors?.length\n ? { teardownErrors: execution.teardownErrors }\n : {}),\n reportScopeId: execution?.reportScopeId ?? record.runId,\n reportPaths: [...record.reportPaths],\n ...(record.reportSources?.length\n ? { reportSources: [...record.reportSources] }\n : {}),\n },\n cases:\n record.execution?.cases ??\n record.document.cases.map((item) => ({\n caseId: item.caseId,\n projectName,\n name: item.definition.name,\n sourcePath: item.sourcePath,\n caseIndex: item.caseIndex,\n status: 'not-run' as const,\n notRunReason: 'document-start-failed' as const,\n })),\n };\n}\n\n/** Persist execution facts across workers without dropping native Error fields. */\nexport function serializeWorkflowExecutionRecord(\n record: WorkflowExecutionRecord,\n): string {\n return serializeWorkflowValue(record);\n}\n\n/** The same error-preserving encoding for entry results and worker envelopes. */\nexport function serializeWorkflowValue(value: unknown): string {\n return JSON.stringify(\n value,\n (_key, value) =>\n value instanceof Error\n ? {\n name: value.name,\n message: value.message,\n ...('code' in value ? { code: value.code } : {}),\n ...('details' in value ? { details: value.details } : {}),\n ...(value instanceof AggregateError\n ? { errors: value.errors }\n : {}),\n }\n : value,\n 2,\n );\n}\n"],"names":["executionRecordToResult","record","execution","hostErrors","add","phase","error","undefined","projectName","item","serializeWorkflowExecutionRecord","serializeWorkflowValue","value","JSON","_key","Error","AggregateError"],"mappings":"
|
|
1
|
+
{"version":3,"file":"test-runner/execution-record.mjs","sources":["../../../src/test-runner/execution-record.ts"],"sourcesContent":["import type {\n WorkflowDocumentExecutionResult,\n WorkflowHostError,\n WorkflowReportSource,\n} from './engine/types';\nimport type { CollectedWorkflowDocument } from './parser/types';\nimport { buildTestRunReportPlan } from './reporting/test-plan';\n\n/**\n * One complete document invocation, including work outside the pure kernel.\n * The entry adapter owns resources and records their lifecycle here. A failed\n * setup has a record even though no document could be executed.\n *\n * runId identifies this invocation, not an Agent/report resource. File retries\n * create new records; they do not become per-Case retries. Report projection\n * must not mutate these records or redact the original API output.\n */\nexport interface WorkflowExecutionRecord {\n readonly runId: string;\n readonly attemptIndex: number;\n readonly sourcePath: string;\n readonly platform: string;\n readonly projectName?: string;\n readonly document: CollectedWorkflowDocument;\n readonly status: 'success' | 'failed';\n readonly startedAt: string;\n readonly endedAt: string;\n readonly durationMs: number;\n readonly execution?: WorkflowDocumentExecutionResult;\n readonly setupError?: unknown;\n readonly executionError?: unknown;\n readonly cleanupErrors: readonly unknown[];\n readonly outputs: Readonly<Record<string, unknown>>;\n readonly reportPaths: readonly string[];\n readonly reportSources?: readonly WorkflowReportSource[];\n readonly children?: readonly WorkflowExecutionRecord[];\n readonly reportError?: unknown;\n /** Entry-owned report copies or result files failed after execution finished. */\n readonly publicationErrors?: readonly unknown[];\n /** Entry progress/result observers failed, independently of action outcomes. */\n readonly observerErrors?: readonly unknown[];\n}\n\n/** Complete host facts as a kernel result. Report and summary consume this view. */\nexport function executionRecordToResult(\n record: WorkflowExecutionRecord,\n): WorkflowDocumentExecutionResult {\n const execution = record.execution?.document;\n const hostErrors: WorkflowHostError[] = [...(execution?.hostErrors ?? [])];\n const add = (phase: WorkflowHostError['phase'], error: unknown) => {\n if (error !== undefined) hostErrors.push({ phase, error });\n };\n add('setup', record.setupError);\n add('execution', record.executionError);\n for (const error of record.cleanupErrors) add('cleanup', error);\n add('report', record.reportError);\n for (const error of record.publicationErrors ?? []) add('publication', error);\n for (const error of record.observerErrors ?? []) add('observer', error);\n const projectName =\n record.projectName ?? execution?.projectName ?? record.platform;\n return {\n document: {\n plan: execution?.plan ?? buildTestRunReportPlan(record.document),\n documentId: record.document.documentId,\n documentRunId: record.runId,\n attemptIndex: record.attemptIndex,\n projectId: record.document.projectId,\n projectName,\n sourcePath: record.sourcePath,\n // Case failures are counted separately; host failures must not convert\n // successful Cases into retryable action failures.\n status:\n hostErrors.length || execution?.status === 'failed'\n ? 'failed'\n : 'success',\n startedAt: record.startedAt,\n endedAt: record.endedAt,\n durationMs: record.durationMs,\n beforeAll: execution?.beforeAll ?? [],\n afterAll: execution?.afterAll ?? [],\n ...(hostErrors.length ? { hostErrors } : {}),\n ...(execution?.executionErrors?.length\n ? { executionErrors: execution.executionErrors }\n : {}),\n ...(execution?.teardownErrors?.length\n ? { teardownErrors: execution.teardownErrors }\n : {}),\n reportScopeId: execution?.reportScopeId ?? record.runId,\n reportPaths: [...record.reportPaths],\n ...(record.reportSources?.length\n ? { reportSources: [...record.reportSources] }\n : {}),\n },\n cases:\n record.execution?.cases ??\n record.document.cases.map((item) => ({\n caseId: item.caseId,\n projectName,\n name: item.definition.name,\n sourcePath: item.sourcePath,\n caseIndex: item.caseIndex,\n status: 'not-run' as const,\n notRunReason: 'document-start-failed' as const,\n })),\n };\n}\n\n/** Persist execution facts across workers without dropping native Error fields. */\nexport function serializeWorkflowExecutionRecord(\n record: WorkflowExecutionRecord,\n): string {\n return serializeWorkflowValue(record);\n}\n\n/** The same error-preserving encoding for entry results and worker envelopes. */\nexport function serializeWorkflowValue(value: unknown): string {\n return JSON.stringify(\n value,\n (_key, value) =>\n value instanceof Error\n ? {\n name: value.name,\n message: value.message,\n ...('code' in value ? { code: value.code } : {}),\n ...('details' in value ? { details: value.details } : {}),\n ...(value instanceof AggregateError\n ? { errors: value.errors }\n : {}),\n }\n : value,\n 2,\n );\n}\n"],"names":["executionRecordToResult","record","execution","hostErrors","add","phase","error","undefined","projectName","buildTestRunReportPlan","item","serializeWorkflowExecutionRecord","serializeWorkflowValue","value","JSON","_key","Error","AggregateError"],"mappings":";AA4CO,SAASA,wBACdC,MAA+B;IAE/B,MAAMC,YAAYD,OAAO,SAAS,EAAE;IACpC,MAAME,aAAkC;WAAKD,WAAW,cAAc,EAAE;KAAE;IAC1E,MAAME,MAAM,CAACC,OAAmCC;QAC9C,IAAIA,AAAUC,WAAVD,OAAqBH,WAAW,IAAI,CAAC;YAAEE;YAAOC;QAAM;IAC1D;IACAF,IAAI,SAASH,OAAO,UAAU;IAC9BG,IAAI,aAAaH,OAAO,cAAc;IACtC,KAAK,MAAMK,SAASL,OAAO,aAAa,CAAEG,IAAI,WAAWE;IACzDF,IAAI,UAAUH,OAAO,WAAW;IAChC,KAAK,MAAMK,SAASL,OAAO,iBAAiB,IAAI,EAAE,CAAEG,IAAI,eAAeE;IACvE,KAAK,MAAMA,SAASL,OAAO,cAAc,IAAI,EAAE,CAAEG,IAAI,YAAYE;IACjE,MAAME,cACJP,OAAO,WAAW,IAAIC,WAAW,eAAeD,OAAO,QAAQ;IACjE,OAAO;QACL,UAAU;YACR,MAAMC,WAAW,QAAQO,uBAAuBR,OAAO,QAAQ;YAC/D,YAAYA,OAAO,QAAQ,CAAC,UAAU;YACtC,eAAeA,OAAO,KAAK;YAC3B,cAAcA,OAAO,YAAY;YACjC,WAAWA,OAAO,QAAQ,CAAC,SAAS;YACpCO;YACA,YAAYP,OAAO,UAAU;YAG7B,QACEE,WAAW,MAAM,IAAID,WAAW,WAAW,WACvC,WACA;YACN,WAAWD,OAAO,SAAS;YAC3B,SAASA,OAAO,OAAO;YACvB,YAAYA,OAAO,UAAU;YA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4 @@
|
|
|
1
|
+
import { collectTestRunReportMetrics, sumTestRunReportMetrics } from "./reporting/metrics.mjs";
|
|
1
2
|
export * from "./engine/index.mjs";
|
|
2
3
|
export * from "./errors.mjs";
|
|
3
4
|
export * from "./execution-record.mjs";
|
|
@@ -7,6 +8,8 @@ export * from "./parser/document-format.mjs";
|
|
|
7
8
|
export * from "./parser/types.mjs";
|
|
8
9
|
export * from "./project.mjs";
|
|
9
10
|
export * from "./reporting/types.mjs";
|
|
11
|
+
export * from "./reporting/test-plan.mjs";
|
|
10
12
|
export * from "./reporting/sanitize.mjs";
|
|
11
13
|
export * from "./reporting/test-run-report.mjs";
|
|
12
14
|
export * from "./reporting/execution-record.mjs";
|
|
15
|
+
export { collectTestRunReportMetrics, sumTestRunReportMetrics };
|