@midscene/core 1.12.10-beta-20260920031616.0 → 1.13.0
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/agent.mjs +103 -6
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/index.mjs +4 -3
- package/dist/es/agent/tasks.mjs +2 -2
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/test-runner-nodes.mjs +291 -40
- package/dist/es/agent/test-runner-nodes.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +1 -1
- package/dist/es/device/index.mjs +15 -2
- package/dist/es/device/index.mjs.map +1 -1
- package/dist/es/dump/html-utils.mjs +37 -4
- package/dist/es/dump/html-utils.mjs.map +1 -1
- package/dist/es/dump/screenshot-store.mjs +8 -1
- package/dist/es/dump/screenshot-store.mjs.map +1 -1
- package/dist/es/report-cli.mjs +9 -4
- package/dist/es/report-cli.mjs.map +1 -1
- package/dist/es/report-generator.mjs +117 -4
- package/dist/es/report-generator.mjs.map +1 -1
- package/dist/es/report-html-template.mjs +1 -1
- package/dist/es/report.mjs +190 -41
- package/dist/es/report.mjs.map +1 -1
- package/dist/es/test-run-report.mjs.map +1 -1
- package/dist/es/test-runner/engine/case-runner.mjs +52 -0
- package/dist/es/test-runner/engine/case-runner.mjs.map +1 -0
- package/dist/es/test-runner/engine/document-runtime.mjs +273 -0
- package/dist/es/test-runner/engine/document-runtime.mjs.map +1 -0
- package/dist/es/test-runner/engine/execute-step.mjs +177 -0
- package/dist/es/test-runner/engine/execute-step.mjs.map +1 -0
- package/dist/es/test-runner/engine/execution-failure.mjs +39 -0
- package/dist/es/test-runner/engine/execution-failure.mjs.map +1 -0
- package/dist/es/test-runner/engine/index.mjs +12 -0
- package/dist/es/test-runner/engine/project-runtime.mjs +142 -0
- package/dist/es/test-runner/engine/project-runtime.mjs.map +1 -0
- package/dist/es/test-runner/engine/registry.mjs +61 -0
- package/dist/es/test-runner/engine/registry.mjs.map +1 -0
- package/dist/es/test-runner/engine/resource-operations.mjs +211 -0
- package/dist/es/test-runner/engine/resource-operations.mjs.map +1 -0
- package/dist/es/test-runner/engine/run-collected-case.mjs +193 -0
- package/dist/es/test-runner/engine/run-collected-case.mjs.map +1 -0
- package/dist/es/test-runner/engine/run-workflow-document.mjs +155 -0
- package/dist/es/test-runner/engine/run-workflow-document.mjs.map +1 -0
- package/dist/es/test-runner/engine/scheduler.mjs +27 -0
- package/dist/es/test-runner/engine/scheduler.mjs.map +1 -0
- package/dist/es/test-runner/engine/scope-teardown.mjs +16 -0
- package/dist/es/test-runner/engine/scope-teardown.mjs.map +1 -0
- package/dist/es/test-runner/engine/types.mjs +0 -0
- package/dist/es/test-runner/errors.mjs +201 -0
- package/dist/es/test-runner/errors.mjs.map +1 -0
- package/dist/es/test-runner/execution-record.mjs +83 -0
- package/dist/es/test-runner/execution-record.mjs.map +1 -0
- package/dist/es/test-runner/index.mjs +12 -0
- package/dist/es/test-runner/node/define-node.mjs +44 -0
- package/dist/es/test-runner/node/define-node.mjs.map +1 -0
- package/dist/es/test-runner/node/index.mjs +2 -0
- package/dist/es/test-runner/node/types.mjs +0 -0
- package/dist/es/test-runner/parser/document-format.mjs +21 -0
- package/dist/es/test-runner/parser/document-format.mjs.map +1 -0
- package/dist/es/test-runner/parser/normalize.mjs +87 -0
- package/dist/es/test-runner/parser/normalize.mjs.map +1 -0
- package/dist/es/test-runner/parser/types.mjs +0 -0
- package/dist/es/test-runner/project.mjs +0 -0
- package/dist/es/test-runner/reporting/agent-report.mjs +23 -0
- package/dist/es/test-runner/reporting/agent-report.mjs.map +1 -0
- package/dist/es/test-runner/reporting/execution-record.mjs +73 -0
- package/dist/es/test-runner/reporting/execution-record.mjs.map +1 -0
- package/dist/es/test-runner/reporting/merge-report.mjs +231 -0
- package/dist/es/test-runner/reporting/merge-report.mjs.map +1 -0
- package/dist/es/test-runner/reporting/sanitize.mjs +162 -0
- package/dist/es/test-runner/reporting/sanitize.mjs.map +1 -0
- package/dist/es/test-runner/reporting/test-run-report.mjs +327 -0
- package/dist/es/test-runner/reporting/test-run-report.mjs.map +1 -0
- package/dist/es/test-runner/reporting/types.mjs +0 -0
- package/dist/es/utils.mjs +1 -1
- package/dist/es/yaml/execution-context.node.mjs +6 -0
- package/dist/es/yaml/execution-context.node.mjs.map +1 -0
- package/dist/es/yaml/execution-context.stub.mjs +8 -0
- package/dist/es/yaml/execution-context.stub.mjs.map +1 -0
- package/dist/es/yaml/execution-session.mjs +90 -0
- package/dist/es/yaml/execution-session.mjs.map +1 -0
- package/dist/es/yaml/index.mjs +2 -1
- package/dist/es/yaml/legacy-yaml-execution-record.mjs +47 -0
- package/dist/es/yaml/legacy-yaml-execution-record.mjs.map +1 -0
- package/dist/es/yaml/legacy-yaml-report.mjs +52 -0
- package/dist/es/yaml/legacy-yaml-report.mjs.map +1 -0
- package/dist/es/yaml/legacy-yaml-runtime.mjs +119 -0
- package/dist/es/yaml/legacy-yaml-runtime.mjs.map +1 -0
- package/dist/es/yaml/player-state.mjs +15 -0
- package/dist/es/yaml/player-state.mjs.map +1 -0
- package/dist/es/yaml/player.mjs +214 -348
- package/dist/es/yaml/player.mjs.map +1 -1
- package/dist/es/yaml/report-policy.mjs +7 -0
- package/dist/es/yaml/report-policy.mjs.map +1 -0
- package/dist/es/yaml/test-runner-compat.mjs +301 -0
- package/dist/es/yaml/test-runner-compat.mjs.map +1 -0
- package/dist/es/yaml/test-runner-nodes.mjs +147 -0
- package/dist/es/yaml/test-runner-nodes.mjs.map +1 -0
- package/dist/es/yaml/utils.mjs +12 -1
- package/dist/es/yaml/utils.mjs.map +1 -1
- package/dist/es/yaml-runtime.mjs +7 -0
- package/dist/es/yaml.mjs.map +1 -1
- package/dist/lib/agent/agent.js +103 -6
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/index.js +37 -3
- package/dist/lib/agent/tasks.js +2 -2
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/test-runner-nodes.js +329 -45
- package/dist/lib/agent/test-runner-nodes.js.map +1 -1
- package/dist/lib/agent/utils.js +1 -1
- package/dist/lib/device/index.js +15 -2
- package/dist/lib/device/index.js.map +1 -1
- package/dist/lib/dump/html-utils.js +43 -4
- package/dist/lib/dump/html-utils.js.map +1 -1
- package/dist/lib/dump/screenshot-store.js +8 -1
- package/dist/lib/dump/screenshot-store.js.map +1 -1
- package/dist/lib/report-cli.js +8 -3
- package/dist/lib/report-cli.js.map +1 -1
- package/dist/lib/report-generator.js +114 -1
- package/dist/lib/report-generator.js.map +1 -1
- package/dist/lib/report-html-template.js +1 -1
- package/dist/lib/report.js +187 -38
- package/dist/lib/report.js.map +1 -1
- package/dist/lib/test-run-report.js.map +1 -1
- package/dist/lib/test-runner/engine/case-runner.js +89 -0
- package/dist/lib/test-runner/engine/case-runner.js.map +1 -0
- package/dist/lib/test-runner/engine/document-runtime.js +307 -0
- package/dist/lib/test-runner/engine/document-runtime.js.map +1 -0
- package/dist/lib/test-runner/engine/execute-step.js +211 -0
- package/dist/lib/test-runner/engine/execute-step.js.map +1 -0
- package/dist/lib/test-runner/engine/execution-failure.js +79 -0
- package/dist/lib/test-runner/engine/execution-failure.js.map +1 -0
- package/dist/lib/test-runner/engine/index.js +137 -0
- package/dist/lib/test-runner/engine/index.js.map +1 -0
- package/dist/lib/test-runner/engine/project-runtime.js +176 -0
- package/dist/lib/test-runner/engine/project-runtime.js.map +1 -0
- package/dist/lib/test-runner/engine/registry.js +95 -0
- package/dist/lib/test-runner/engine/registry.js.map +1 -0
- package/dist/lib/test-runner/engine/resource-operations.js +272 -0
- package/dist/lib/test-runner/engine/resource-operations.js.map +1 -0
- package/dist/lib/test-runner/engine/run-collected-case.js +227 -0
- package/dist/lib/test-runner/engine/run-collected-case.js.map +1 -0
- package/dist/lib/test-runner/engine/run-workflow-document.js +189 -0
- package/dist/lib/test-runner/engine/run-workflow-document.js.map +1 -0
- package/dist/lib/test-runner/engine/scheduler.js +64 -0
- package/dist/lib/test-runner/engine/scheduler.js.map +1 -0
- package/dist/lib/test-runner/engine/scope-teardown.js +50 -0
- package/dist/lib/test-runner/engine/scope-teardown.js.map +1 -0
- package/dist/lib/test-runner/engine/types.js +20 -0
- package/dist/lib/test-runner/engine/types.js.map +1 -0
- package/dist/lib/test-runner/errors.js +283 -0
- package/dist/lib/test-runner/errors.js.map +1 -0
- package/dist/lib/test-runner/execution-record.js +123 -0
- package/dist/lib/test-runner/execution-record.js.map +1 -0
- package/dist/lib/test-runner/index.js +137 -0
- package/dist/lib/test-runner/index.js.map +1 -0
- package/dist/lib/test-runner/node/define-node.js +78 -0
- package/dist/lib/test-runner/node/define-node.js.map +1 -0
- package/dist/lib/test-runner/node/index.js +67 -0
- package/dist/lib/test-runner/node/index.js.map +1 -0
- package/dist/lib/test-runner/node/types.js +20 -0
- package/dist/lib/test-runner/node/types.js.map +1 -0
- package/dist/lib/test-runner/parser/document-format.js +58 -0
- package/dist/lib/test-runner/parser/document-format.js.map +1 -0
- package/dist/lib/test-runner/parser/normalize.js +124 -0
- package/dist/lib/test-runner/parser/normalize.js.map +1 -0
- package/dist/lib/test-runner/parser/types.js +20 -0
- package/dist/lib/test-runner/parser/types.js.map +1 -0
- package/dist/lib/test-runner/project.js +20 -0
- package/dist/lib/test-runner/project.js.map +1 -0
- package/dist/lib/test-runner/reporting/agent-report.js +57 -0
- package/dist/lib/test-runner/reporting/agent-report.js.map +1 -0
- package/dist/lib/test-runner/reporting/execution-record.js +107 -0
- package/dist/lib/test-runner/reporting/execution-record.js.map +1 -0
- package/dist/lib/test-runner/reporting/merge-report.js +265 -0
- package/dist/lib/test-runner/reporting/merge-report.js.map +1 -0
- package/dist/lib/test-runner/reporting/sanitize.js +202 -0
- package/dist/lib/test-runner/reporting/sanitize.js.map +1 -0
- package/dist/lib/test-runner/reporting/test-run-report.js +364 -0
- package/dist/lib/test-runner/reporting/test-run-report.js.map +1 -0
- package/dist/lib/test-runner/reporting/types.js +20 -0
- package/dist/lib/test-runner/reporting/types.js.map +1 -0
- package/dist/lib/utils.js +1 -1
- package/dist/lib/yaml/execution-context.node.js +43 -0
- package/dist/lib/yaml/execution-context.node.js.map +1 -0
- package/dist/lib/yaml/execution-context.stub.js +45 -0
- package/dist/lib/yaml/execution-context.stub.js.map +1 -0
- package/dist/lib/yaml/execution-session.js +136 -0
- package/dist/lib/yaml/execution-session.js.map +1 -0
- package/dist/lib/yaml/index.js +49 -7
- package/dist/lib/yaml/legacy-yaml-execution-record.js +81 -0
- package/dist/lib/yaml/legacy-yaml-execution-record.js.map +1 -0
- package/dist/lib/yaml/legacy-yaml-report.js +86 -0
- package/dist/lib/yaml/legacy-yaml-report.js.map +1 -0
- package/dist/lib/yaml/legacy-yaml-runtime.js +156 -0
- package/dist/lib/yaml/legacy-yaml-runtime.js.map +1 -0
- package/dist/lib/yaml/player-state.js +52 -0
- package/dist/lib/yaml/player-state.js.map +1 -0
- package/dist/lib/yaml/player.js +213 -347
- package/dist/lib/yaml/player.js.map +1 -1
- package/dist/lib/yaml/report-policy.js +41 -0
- package/dist/lib/yaml/report-policy.js.map +1 -0
- package/dist/lib/yaml/test-runner-compat.js +344 -0
- package/dist/lib/yaml/test-runner-compat.js.map +1 -0
- package/dist/lib/yaml/test-runner-nodes.js +184 -0
- package/dist/lib/yaml/test-runner-nodes.js.map +1 -0
- package/dist/lib/yaml/utils.js +18 -1
- package/dist/lib/yaml/utils.js.map +1 -1
- package/dist/lib/yaml-runtime.js +67 -0
- package/dist/lib/yaml-runtime.js.map +1 -0
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/agent/agent.d.ts +14 -1
- package/dist/types/agent/agent.d.ts.map +1 -1
- package/dist/types/agent/index.d.ts +4 -3
- package/dist/types/agent/index.d.ts.map +1 -1
- package/dist/types/agent/tasks.d.ts +1 -1
- package/dist/types/agent/tasks.d.ts.map +1 -1
- package/dist/types/agent/test-runner-nodes.d.ts +226 -0
- package/dist/types/agent/test-runner-nodes.d.ts.map +1 -1
- package/dist/types/device/index.d.ts +1 -1
- package/dist/types/device/index.d.ts.map +1 -1
- package/dist/types/dump/html-utils.d.ts +4 -0
- package/dist/types/dump/html-utils.d.ts.map +1 -1
- package/dist/types/dump/screenshot-store.d.ts +2 -1
- package/dist/types/dump/screenshot-store.d.ts.map +1 -1
- package/dist/types/report-cli.d.ts.map +1 -1
- package/dist/types/report-generator.d.ts +10 -0
- package/dist/types/report-generator.d.ts.map +1 -1
- package/dist/types/report.d.ts +3 -1
- package/dist/types/report.d.ts.map +1 -1
- package/dist/types/test-run-report.d.ts +18 -2
- package/dist/types/test-run-report.d.ts.map +1 -1
- package/dist/types/test-runner/engine/case-runner.d.ts +13 -0
- package/dist/types/test-runner/engine/case-runner.d.ts.map +1 -0
- package/dist/types/test-runner/engine/document-runtime.d.ts +4 -0
- package/dist/types/test-runner/engine/document-runtime.d.ts.map +1 -0
- package/dist/types/test-runner/engine/execute-step.d.ts +17 -0
- package/dist/types/test-runner/engine/execute-step.d.ts.map +1 -0
- package/dist/types/test-runner/engine/execution-failure.d.ts +13 -0
- package/dist/types/test-runner/engine/execution-failure.d.ts.map +1 -0
- package/dist/types/test-runner/engine/index.d.ts +13 -0
- package/dist/types/test-runner/engine/index.d.ts.map +1 -0
- package/dist/types/test-runner/engine/project-runtime.d.ts +3 -0
- package/dist/types/test-runner/engine/project-runtime.d.ts.map +1 -0
- package/dist/types/test-runner/engine/registry.d.ts +12 -0
- package/dist/types/test-runner/engine/registry.d.ts.map +1 -0
- package/dist/types/test-runner/engine/resource-operations.d.ts +32 -0
- package/dist/types/test-runner/engine/resource-operations.d.ts.map +1 -0
- package/dist/types/test-runner/engine/run-collected-case.d.ts +4 -0
- package/dist/types/test-runner/engine/run-collected-case.d.ts.map +1 -0
- package/dist/types/test-runner/engine/run-workflow-document.d.ts +4 -0
- package/dist/types/test-runner/engine/run-workflow-document.d.ts.map +1 -0
- package/dist/types/test-runner/engine/scheduler.d.ts +12 -0
- package/dist/types/test-runner/engine/scheduler.d.ts.map +1 -0
- package/dist/types/test-runner/engine/scope-teardown.d.ts +3 -0
- package/dist/types/test-runner/engine/scope-teardown.d.ts.map +1 -0
- package/dist/types/test-runner/engine/types.d.ts +226 -0
- package/dist/types/test-runner/engine/types.d.ts.map +1 -0
- package/dist/types/test-runner/errors.d.ts +79 -0
- package/dist/types/test-runner/errors.d.ts.map +1 -0
- package/dist/types/test-runner/execution-record.d.ts +43 -0
- package/dist/types/test-runner/execution-record.d.ts.map +1 -0
- package/dist/types/test-runner/index.d.ts +20 -0
- package/dist/types/test-runner/index.d.ts.map +1 -0
- package/dist/types/test-runner/node/define-node.d.ts +4 -0
- package/dist/types/test-runner/node/define-node.d.ts.map +1 -0
- package/dist/types/test-runner/node/index.d.ts +3 -0
- package/dist/types/test-runner/node/index.d.ts.map +1 -0
- package/dist/types/test-runner/node/types.d.ts +66 -0
- package/dist/types/test-runner/node/types.d.ts.map +1 -0
- package/dist/types/test-runner/parser/document-format.d.ts +8 -0
- package/dist/types/test-runner/parser/document-format.d.ts.map +1 -0
- package/dist/types/test-runner/parser/normalize.d.ts +9 -0
- package/dist/types/test-runner/parser/normalize.d.ts.map +1 -0
- package/dist/types/test-runner/parser/types.d.ts +69 -0
- package/dist/types/test-runner/parser/types.d.ts.map +1 -0
- package/dist/types/test-runner/project.d.ts +75 -0
- package/dist/types/test-runner/project.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/agent-report.d.ts +9 -0
- package/dist/types/test-runner/reporting/agent-report.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/execution-record.d.ts +9 -0
- package/dist/types/test-runner/reporting/execution-record.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/merge-report.d.ts +15 -0
- package/dist/types/test-runner/reporting/merge-report.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/sanitize.d.ts +6 -0
- package/dist/types/test-runner/reporting/sanitize.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/test-run-report.d.ts +5 -0
- package/dist/types/test-runner/reporting/test-run-report.d.ts.map +1 -0
- package/dist/types/test-runner/reporting/types.d.ts +34 -0
- package/dist/types/test-runner/reporting/types.d.ts.map +1 -0
- package/dist/types/yaml/execution-context.node.d.ts +4 -0
- package/dist/types/yaml/execution-context.node.d.ts.map +1 -0
- package/dist/types/yaml/execution-context.stub.d.ts +6 -0
- package/dist/types/yaml/execution-context.stub.d.ts.map +1 -0
- package/dist/types/yaml/execution-session.d.ts +17 -0
- package/dist/types/yaml/execution-session.d.ts.map +1 -0
- package/dist/types/yaml/index.d.ts +1 -1
- package/dist/types/yaml/index.d.ts.map +1 -1
- package/dist/types/yaml/legacy-yaml-execution-record.d.ts +24 -0
- package/dist/types/yaml/legacy-yaml-execution-record.d.ts.map +1 -0
- package/dist/types/yaml/legacy-yaml-report.d.ts +19 -0
- package/dist/types/yaml/legacy-yaml-report.d.ts.map +1 -0
- package/dist/types/yaml/legacy-yaml-runtime.d.ts +23 -0
- package/dist/types/yaml/legacy-yaml-runtime.d.ts.map +1 -0
- package/dist/types/yaml/player-state.d.ts +11 -0
- package/dist/types/yaml/player-state.d.ts.map +1 -0
- package/dist/types/yaml/player.d.ts +11 -3
- package/dist/types/yaml/player.d.ts.map +1 -1
- package/dist/types/yaml/report-policy.d.ts +4 -0
- package/dist/types/yaml/report-policy.d.ts.map +1 -0
- package/dist/types/yaml/test-runner-compat.d.ts +17 -0
- package/dist/types/yaml/test-runner-compat.d.ts.map +1 -0
- package/dist/types/yaml/test-runner-nodes.d.ts +6 -0
- package/dist/types/yaml/test-runner-nodes.d.ts.map +1 -0
- package/dist/types/yaml/utils.d.ts +9 -0
- package/dist/types/yaml/utils.d.ts.map +1 -1
- package/dist/types/yaml-runtime.d.ts +13 -0
- package/dist/types/yaml-runtime.d.ts.map +1 -0
- package/dist/types/yaml.d.ts +25 -7
- package/dist/types/yaml.d.ts.map +1 -1
- package/package.json +28 -2
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { getDebug } from "@midscene/shared/logger";
|
|
2
|
+
import { uuid } from "@midscene/shared/utils";
|
|
3
|
+
import { NodeScopeTeardownError, WorkflowLifecycleError } from "../errors.mjs";
|
|
4
|
+
import { executeStep } from "./execute-step.mjs";
|
|
5
|
+
import { WorkflowExecutionFailure, asExecutionError } from "./execution-failure.mjs";
|
|
6
|
+
import { ResourceCleanupDeferredError, cleanupScopeResources, createResourceScope } from "./resource-operations.mjs";
|
|
7
|
+
import { reportPathsFromTeardown } from "./scope-teardown.mjs";
|
|
8
|
+
function createDocumentRuntime(document, options) {
|
|
9
|
+
const documentRunId = options.createDocumentRunId?.() ?? uuid();
|
|
10
|
+
const startedAt = new Date();
|
|
11
|
+
const beforeAll = [];
|
|
12
|
+
const afterAll = [];
|
|
13
|
+
const nodes = {
|
|
14
|
+
beforeAll: document.lifecycle.beforeAll.map((step)=>options.resolveNode(step.node)),
|
|
15
|
+
afterAll: document.lifecycle.afterAll.map((step)=>options.resolveNode(step.node))
|
|
16
|
+
};
|
|
17
|
+
const project = options.project ?? Object.freeze({
|
|
18
|
+
projectId: document.projectId,
|
|
19
|
+
name: document.projectId,
|
|
20
|
+
retry: 0
|
|
21
|
+
});
|
|
22
|
+
let context = options.projectContext;
|
|
23
|
+
const resourceScope = createResourceScope(options.signal);
|
|
24
|
+
const signal = resourceScope.signal;
|
|
25
|
+
const nodeTeardownStack = [];
|
|
26
|
+
let acceptingNodeTeardowns = true;
|
|
27
|
+
let started = false;
|
|
28
|
+
let finishedResult;
|
|
29
|
+
let finishPromise;
|
|
30
|
+
const reportPaths = new Set();
|
|
31
|
+
const reportSources = [];
|
|
32
|
+
const executionErrors = [];
|
|
33
|
+
const hostErrors = [];
|
|
34
|
+
let acceptingSetupTeardowns = false;
|
|
35
|
+
const createResult = (teardownErrors = [])=>{
|
|
36
|
+
const endedAt = new Date();
|
|
37
|
+
return {
|
|
38
|
+
documentId: document.documentId,
|
|
39
|
+
documentRunId,
|
|
40
|
+
...void 0 === options.documentAttemptIndex ? {} : {
|
|
41
|
+
attemptIndex: options.documentAttemptIndex
|
|
42
|
+
},
|
|
43
|
+
projectId: document.projectId,
|
|
44
|
+
projectName: project.name,
|
|
45
|
+
sourcePath: document.sourcePath,
|
|
46
|
+
status: executionErrors.length > 0 || hostErrors.length > 0 || beforeAll.some((step)=>'failed' === step.status) || afterAll.some((step)=>'failed' === step.status) || teardownErrors.length > 0 ? 'failed' : 'success',
|
|
47
|
+
startedAt: startedAt.toISOString(),
|
|
48
|
+
endedAt: endedAt.toISOString(),
|
|
49
|
+
durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),
|
|
50
|
+
beforeAll: [
|
|
51
|
+
...beforeAll
|
|
52
|
+
],
|
|
53
|
+
afterAll: [
|
|
54
|
+
...afterAll
|
|
55
|
+
],
|
|
56
|
+
...executionErrors.length ? {
|
|
57
|
+
executionErrors: executionErrors.map(asExecutionError)
|
|
58
|
+
} : {},
|
|
59
|
+
...hostErrors.length ? {
|
|
60
|
+
hostErrors: [
|
|
61
|
+
...hostErrors
|
|
62
|
+
]
|
|
63
|
+
} : {},
|
|
64
|
+
...teardownErrors.length > 0 ? {
|
|
65
|
+
teardownErrors: [
|
|
66
|
+
...teardownErrors
|
|
67
|
+
]
|
|
68
|
+
} : {},
|
|
69
|
+
...reportPaths.size > 0 ? {
|
|
70
|
+
reportPaths: [
|
|
71
|
+
...reportPaths
|
|
72
|
+
]
|
|
73
|
+
} : {},
|
|
74
|
+
...reportSources.length ? {
|
|
75
|
+
reportSources: [
|
|
76
|
+
...reportSources
|
|
77
|
+
]
|
|
78
|
+
} : {}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const runPhase = async (phase, results, executionSignal = signal)=>{
|
|
82
|
+
for (const [stepIndex, step] of document.lifecycle[phase].entries()){
|
|
83
|
+
const documentContext = {
|
|
84
|
+
documentId: document.documentId,
|
|
85
|
+
documentRunId,
|
|
86
|
+
projectId: document.projectId,
|
|
87
|
+
projectName: project.name,
|
|
88
|
+
sourcePath: document.sourcePath,
|
|
89
|
+
phase,
|
|
90
|
+
stepIndex
|
|
91
|
+
};
|
|
92
|
+
const stepInfo = {
|
|
93
|
+
scope: 'document',
|
|
94
|
+
node: step.node,
|
|
95
|
+
stepCount: document.lifecycle[phase].length,
|
|
96
|
+
document: documentContext
|
|
97
|
+
};
|
|
98
|
+
await options.onStepStart?.(stepInfo);
|
|
99
|
+
const result = await executeStep(step, nodes[phase][stepIndex], {
|
|
100
|
+
scope: 'document',
|
|
101
|
+
document: documentContext
|
|
102
|
+
}, context, {
|
|
103
|
+
signal: executionSignal,
|
|
104
|
+
defaultTimeoutMs: options.defaultTimeoutMs,
|
|
105
|
+
onTeardown (node, teardown) {
|
|
106
|
+
if (!acceptingNodeTeardowns) throw new WorkflowLifecycleError('Node teardown can only be registered while a workflow document is running.', {
|
|
107
|
+
documentId: document.documentId,
|
|
108
|
+
documentRunId,
|
|
109
|
+
node
|
|
110
|
+
});
|
|
111
|
+
if ('function' != typeof teardown) throw new WorkflowLifecycleError('Node onTeardown() requires a teardown function.', {
|
|
112
|
+
documentId: document.documentId,
|
|
113
|
+
documentRunId,
|
|
114
|
+
node
|
|
115
|
+
});
|
|
116
|
+
nodeTeardownStack.push({
|
|
117
|
+
registrationIndex: nodeTeardownStack.length,
|
|
118
|
+
node,
|
|
119
|
+
teardown
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
results.push(result);
|
|
124
|
+
await options.onStepResult?.(stepInfo, result);
|
|
125
|
+
if ('failed' === result.status && !result.continuedAfterError) break;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
signal,
|
|
130
|
+
get context () {
|
|
131
|
+
return context;
|
|
132
|
+
},
|
|
133
|
+
get canRunCases () {
|
|
134
|
+
return started && 0 === executionErrors.length && 0 === hostErrors.length && !signal.aborted && !beforeAll.some((step)=>'failed' === step.status);
|
|
135
|
+
},
|
|
136
|
+
async start () {
|
|
137
|
+
if (started) throw new WorkflowLifecycleError('Workflow document runtime has already started.', {
|
|
138
|
+
documentId: document.documentId,
|
|
139
|
+
documentRunId
|
|
140
|
+
});
|
|
141
|
+
started = true;
|
|
142
|
+
if (!signal.aborted && options.documentSetup) {
|
|
143
|
+
acceptingSetupTeardowns = true;
|
|
144
|
+
try {
|
|
145
|
+
context = await options.documentSetup.setup({
|
|
146
|
+
project,
|
|
147
|
+
projectContext: options.projectContext,
|
|
148
|
+
document: {
|
|
149
|
+
documentId: document.documentId,
|
|
150
|
+
documentRunId,
|
|
151
|
+
sourcePath: document.sourcePath,
|
|
152
|
+
attemptIndex: options.documentAttemptIndex ?? 0
|
|
153
|
+
},
|
|
154
|
+
signal,
|
|
155
|
+
onTeardown (teardown) {
|
|
156
|
+
if (!acceptingSetupTeardowns || 'function' != typeof teardown) throw new WorkflowLifecycleError('Document setup onTeardown() requires a function registered during setup.', {
|
|
157
|
+
documentId: document.documentId,
|
|
158
|
+
documentRunId
|
|
159
|
+
});
|
|
160
|
+
nodeTeardownStack.push({
|
|
161
|
+
registrationIndex: nodeTeardownStack.length,
|
|
162
|
+
node: options.documentSetup.name,
|
|
163
|
+
teardown,
|
|
164
|
+
host: true
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
hostErrors.push({
|
|
170
|
+
phase: 'setup',
|
|
171
|
+
error: asExecutionError(error)
|
|
172
|
+
});
|
|
173
|
+
} finally{
|
|
174
|
+
acceptingSetupTeardowns = false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
if (!signal.aborted && !hostErrors.length) await runPhase('beforeAll', beforeAll);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
executionErrors.push(error);
|
|
181
|
+
throw new WorkflowExecutionFailure(createResult(), [
|
|
182
|
+
...executionErrors
|
|
183
|
+
]);
|
|
184
|
+
}
|
|
185
|
+
return createResult();
|
|
186
|
+
},
|
|
187
|
+
async finish () {
|
|
188
|
+
if (finishPromise) return finishPromise;
|
|
189
|
+
if (!started) throw new WorkflowLifecycleError('Workflow document runtime must start before it can finish.', {
|
|
190
|
+
documentId: document.documentId,
|
|
191
|
+
documentRunId
|
|
192
|
+
});
|
|
193
|
+
finishPromise = (async ()=>{
|
|
194
|
+
const teardownErrors = [];
|
|
195
|
+
const cleanupExecutionErrors = [];
|
|
196
|
+
let deferredCleanup = false;
|
|
197
|
+
const cleanup = async ()=>{
|
|
198
|
+
const priorTeardownErrors = teardownErrors.length;
|
|
199
|
+
acceptingNodeTeardowns = false;
|
|
200
|
+
for (const { registrationIndex, node, teardown, host } of nodeTeardownStack.reverse())try {
|
|
201
|
+
const released = await teardown();
|
|
202
|
+
reportSources.push(...released?.reportSources ?? []);
|
|
203
|
+
for (const path of reportPathsFromTeardown(released))reportPaths.add(path);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (host) {
|
|
206
|
+
hostErrors.push({
|
|
207
|
+
phase: 'cleanup',
|
|
208
|
+
error: asExecutionError(error)
|
|
209
|
+
});
|
|
210
|
+
executionErrors.push(error);
|
|
211
|
+
cleanupExecutionErrors.push(error);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
teardownErrors.push(new NodeScopeTeardownError(error, {
|
|
215
|
+
scope: 'document',
|
|
216
|
+
scopeId: documentRunId,
|
|
217
|
+
node,
|
|
218
|
+
registrationIndex
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
if (deferredCleanup) {
|
|
222
|
+
const errors = [
|
|
223
|
+
...cleanupExecutionErrors,
|
|
224
|
+
...teardownErrors.slice(priorTeardownErrors)
|
|
225
|
+
];
|
|
226
|
+
if (errors.length) throw new AggregateError(errors, 'Deferred document cleanup failed');
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
try {
|
|
230
|
+
if (document.lifecycle.afterAll.length || nodeTeardownStack.length) await cleanupScopeResources(signal, cleanup, {
|
|
231
|
+
beforeCleanup: async (cleanupSignal)=>{
|
|
232
|
+
try {
|
|
233
|
+
if (!hostErrors.some((error)=>'setup' === error.phase)) await runPhase('afterAll', afterAll, cleanupSignal);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
executionErrors.push(error);
|
|
236
|
+
cleanupExecutionErrors.push(error);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
onDeferredError: (error)=>getDebug('runner:cleanup', {
|
|
240
|
+
console: true
|
|
241
|
+
})(`Deferred document cleanup failed: ${String(error)}`)
|
|
242
|
+
});
|
|
243
|
+
else acceptingNodeTeardowns = false;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
deferredCleanup = error instanceof ResourceCleanupDeferredError;
|
|
246
|
+
if (!deferredCleanup) acceptingNodeTeardowns = false;
|
|
247
|
+
teardownErrors.push(new NodeScopeTeardownError(error, {
|
|
248
|
+
scope: 'document',
|
|
249
|
+
scopeId: documentRunId,
|
|
250
|
+
node: 'resource-drain',
|
|
251
|
+
registrationIndex: -1
|
|
252
|
+
}));
|
|
253
|
+
}
|
|
254
|
+
finishedResult = createResult(teardownErrors);
|
|
255
|
+
try {
|
|
256
|
+
await options.onResult?.(finishedResult);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
executionErrors.push(error);
|
|
259
|
+
finishedResult = createResult(teardownErrors);
|
|
260
|
+
}
|
|
261
|
+
resourceScope.dispose();
|
|
262
|
+
if (executionErrors.length) throw new WorkflowExecutionFailure(finishedResult, [
|
|
263
|
+
...executionErrors
|
|
264
|
+
]);
|
|
265
|
+
return finishedResult;
|
|
266
|
+
})();
|
|
267
|
+
return finishPromise;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export { createDocumentRuntime };
|
|
272
|
+
|
|
273
|
+
//# sourceMappingURL=document-runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-runner/engine/document-runtime.mjs","sources":["../../../../src/test-runner/engine/document-runtime.ts"],"sourcesContent":["import { getDebug } from '@midscene/shared/logger';\nimport { uuid as randomUUID } from '@midscene/shared/utils';\nimport {\n NodeScopeTeardownError,\n type WorkflowError,\n WorkflowLifecycleError,\n} from '../errors';\nimport type { CollectedWorkflowDocument } 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} from './resource-operations';\nimport { reportPathsFromTeardown } from './scope-teardown';\nimport type {\n CreateDocumentRuntimeOptions,\n DocumentNodePhase,\n NodeDocumentContext,\n NodeScopeTeardown,\n StepRunResult,\n WorkflowDocumentRunResult,\n WorkflowDocumentRuntime,\n WorkflowHostError,\n} from './types';\n\nexport function createDocumentRuntime<TContext = undefined>(\n document: CollectedWorkflowDocument,\n options: CreateDocumentRuntimeOptions<TContext>,\n): WorkflowDocumentRuntime<TContext> {\n const documentRunId = options.createDocumentRunId?.() ?? randomUUID();\n const startedAt = new Date();\n const beforeAll: StepRunResult[] = [];\n const afterAll: StepRunResult[] = [];\n const nodes = {\n beforeAll: document.lifecycle.beforeAll.map((step) =>\n options.resolveNode(step.node),\n ),\n afterAll: document.lifecycle.afterAll.map((step) =>\n options.resolveNode(step.node),\n ),\n };\n const project =\n options.project ??\n Object.freeze({\n projectId: document.projectId,\n name: document.projectId,\n retry: 0,\n });\n let context = options.projectContext as TContext;\n const resourceScope = createResourceScope(options.signal);\n const signal = resourceScope.signal;\n const nodeTeardownStack: Array<{\n registrationIndex: number;\n node: string;\n teardown: NodeScopeTeardown;\n host?: boolean;\n }> = [];\n let acceptingNodeTeardowns = true;\n let started = false;\n let finishedResult: WorkflowDocumentRunResult | undefined;\n let finishPromise: Promise<WorkflowDocumentRunResult> | undefined;\n const reportPaths = new Set<string>();\n const reportSources: import('./types').WorkflowReportSource[] = [];\n const executionErrors: unknown[] = [];\n const hostErrors: WorkflowHostError[] = [];\n let acceptingSetupTeardowns = false;\n\n const createResult = (\n teardownErrors: WorkflowError[] = [],\n ): WorkflowDocumentRunResult => {\n const endedAt = new Date();\n return {\n documentId: document.documentId,\n documentRunId,\n ...(options.documentAttemptIndex === undefined\n ? {}\n : { attemptIndex: options.documentAttemptIndex }),\n projectId: document.projectId,\n projectName: project.name,\n sourcePath: document.sourcePath,\n status:\n executionErrors.length > 0 ||\n hostErrors.length > 0 ||\n beforeAll.some((step) => step.status === 'failed') ||\n afterAll.some((step) => step.status === 'failed') ||\n teardownErrors.length > 0\n ? 'failed'\n : 'success',\n startedAt: startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),\n beforeAll: [...beforeAll],\n afterAll: [...afterAll],\n ...(executionErrors.length\n ? { executionErrors: executionErrors.map(asExecutionError) }\n : {}),\n ...(hostErrors.length ? { hostErrors: [...hostErrors] } : {}),\n ...(teardownErrors.length > 0\n ? { teardownErrors: [...teardownErrors] }\n : {}),\n ...(reportPaths.size > 0 ? { reportPaths: [...reportPaths] } : {}),\n ...(reportSources.length ? { reportSources: [...reportSources] } : {}),\n };\n };\n\n const runPhase = async (\n phase: DocumentNodePhase,\n results: StepRunResult[],\n executionSignal = signal,\n ): Promise<void> => {\n for (const [stepIndex, step] of document.lifecycle[phase].entries()) {\n const documentContext: NodeDocumentContext = {\n documentId: document.documentId,\n documentRunId,\n projectId: document.projectId,\n projectName: project.name,\n sourcePath: document.sourcePath,\n phase,\n stepIndex,\n };\n const stepInfo = {\n scope: 'document' as const,\n node: step.node,\n stepCount: document.lifecycle[phase].length,\n document: documentContext,\n };\n await options.onStepStart?.(stepInfo);\n const result = await executeStep(\n step,\n nodes[phase][stepIndex],\n { scope: 'document', document: documentContext },\n context,\n {\n signal: executionSignal,\n defaultTimeoutMs: options.defaultTimeoutMs,\n onTeardown(node, teardown) {\n if (!acceptingNodeTeardowns) {\n throw new WorkflowLifecycleError(\n 'Node teardown can only be registered while a workflow document is running.',\n { documentId: document.documentId, documentRunId, node },\n );\n }\n if (typeof teardown !== 'function') {\n throw new WorkflowLifecycleError(\n 'Node onTeardown() requires a teardown function.',\n { documentId: document.documentId, documentRunId, node },\n );\n }\n nodeTeardownStack.push({\n registrationIndex: nodeTeardownStack.length,\n node,\n teardown,\n });\n },\n },\n );\n results.push(result);\n await options.onStepResult?.(stepInfo, result);\n if (result.status === 'failed' && !result.continuedAfterError) break;\n }\n };\n\n return {\n signal,\n get context() {\n return context;\n },\n get canRunCases() {\n return (\n started &&\n executionErrors.length === 0 &&\n hostErrors.length === 0 &&\n !signal.aborted &&\n !beforeAll.some((step) => step.status === 'failed')\n );\n },\n async start() {\n if (started) {\n throw new WorkflowLifecycleError(\n 'Workflow document runtime has already started.',\n { documentId: document.documentId, documentRunId },\n );\n }\n started = true;\n if (!signal.aborted && options.documentSetup) {\n acceptingSetupTeardowns = true;\n try {\n context = await options.documentSetup.setup({\n project,\n projectContext: options.projectContext,\n document: {\n documentId: document.documentId,\n documentRunId,\n sourcePath: document.sourcePath,\n attemptIndex: options.documentAttemptIndex ?? 0,\n },\n signal,\n onTeardown(teardown) {\n if (!acceptingSetupTeardowns || typeof teardown !== 'function')\n throw new WorkflowLifecycleError(\n 'Document setup onTeardown() requires a function registered during setup.',\n { documentId: document.documentId, documentRunId },\n );\n nodeTeardownStack.push({\n registrationIndex: nodeTeardownStack.length,\n node: options.documentSetup!.name,\n teardown,\n host: true,\n });\n },\n });\n } catch (error) {\n hostErrors.push({ phase: 'setup', error: asExecutionError(error) });\n } finally {\n acceptingSetupTeardowns = false;\n }\n }\n try {\n if (!signal.aborted && !hostErrors.length)\n await runPhase('beforeAll', beforeAll);\n } catch (error) {\n executionErrors.push(error);\n throw new WorkflowExecutionFailure(createResult(), [\n ...executionErrors,\n ]);\n }\n return createResult();\n },\n async finish() {\n if (finishPromise) return finishPromise;\n if (!started) {\n throw new WorkflowLifecycleError(\n 'Workflow document runtime must start before it can finish.',\n { documentId: document.documentId, documentRunId },\n );\n }\n finishPromise = (async () => {\n const teardownErrors: WorkflowError[] = [];\n const cleanupExecutionErrors: unknown[] = [];\n let deferredCleanup = false;\n const cleanup = async () => {\n const priorTeardownErrors = teardownErrors.length;\n acceptingNodeTeardowns = false;\n for (const {\n registrationIndex,\n node,\n teardown,\n host,\n } of nodeTeardownStack.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 if (host) {\n hostErrors.push({\n phase: 'cleanup',\n error: asExecutionError(error),\n });\n executionErrors.push(error);\n cleanupExecutionErrors.push(error);\n continue;\n }\n teardownErrors.push(\n new NodeScopeTeardownError(error, {\n scope: 'document',\n scopeId: documentRunId,\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(\n errors,\n 'Deferred document cleanup failed',\n );\n }\n };\n try {\n if (document.lifecycle.afterAll.length || nodeTeardownStack.length)\n await cleanupScopeResources(signal, cleanup, {\n beforeCleanup: async (cleanupSignal) => {\n try {\n if (!hostErrors.some((error) => error.phase === 'setup'))\n await runPhase('afterAll', afterAll, 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 document cleanup failed: ${String(error)}`,\n ),\n });\n else acceptingNodeTeardowns = false;\n } catch (error) {\n deferredCleanup = error instanceof ResourceCleanupDeferredError;\n if (!deferredCleanup) acceptingNodeTeardowns = false;\n teardownErrors.push(\n new NodeScopeTeardownError(error, {\n scope: 'document',\n scopeId: documentRunId,\n node: 'resource-drain',\n registrationIndex: -1,\n }),\n );\n }\n finishedResult = createResult(teardownErrors);\n try {\n await options.onResult?.(finishedResult);\n } catch (error) {\n executionErrors.push(error);\n finishedResult = createResult(teardownErrors);\n }\n resourceScope.dispose();\n if (executionErrors.length)\n throw new WorkflowExecutionFailure(finishedResult, [\n ...executionErrors,\n ]);\n return finishedResult;\n })();\n return finishPromise;\n },\n };\n}\n"],"names":["createDocumentRuntime","document","options","documentRunId","randomUUID","startedAt","Date","beforeAll","afterAll","nodes","step","project","Object","context","resourceScope","createResourceScope","signal","nodeTeardownStack","acceptingNodeTeardowns","started","finishedResult","finishPromise","reportPaths","Set","reportSources","executionErrors","hostErrors","acceptingSetupTeardowns","createResult","teardownErrors","endedAt","undefined","Math","asExecutionError","runPhase","phase","results","executionSignal","stepIndex","documentContext","stepInfo","result","executeStep","node","teardown","WorkflowLifecycleError","error","WorkflowExecutionFailure","cleanupExecutionErrors","deferredCleanup","cleanup","priorTeardownErrors","registrationIndex","host","released","path","reportPathsFromTeardown","NodeScopeTeardownError","errors","AggregateError","cleanupScopeResources","cleanupSignal","getDebug","String","ResourceCleanupDeferredError"],"mappings":";;;;;;;AA8BO,SAASA,sBACdC,QAAmC,EACnCC,OAA+C;IAE/C,MAAMC,gBAAgBD,QAAQ,mBAAmB,QAAQE;IACzD,MAAMC,YAAY,IAAIC;IACtB,MAAMC,YAA6B,EAAE;IACrC,MAAMC,WAA4B,EAAE;IACpC,MAAMC,QAAQ;QACZ,WAAWR,SAAS,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAACS,OAC3CR,QAAQ,WAAW,CAACQ,KAAK,IAAI;QAE/B,UAAUT,SAAS,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAACS,OACzCR,QAAQ,WAAW,CAACQ,KAAK,IAAI;IAEjC;IACA,MAAMC,UACJT,QAAQ,OAAO,IACfU,OAAO,MAAM,CAAC;QACZ,WAAWX,SAAS,SAAS;QAC7B,MAAMA,SAAS,SAAS;QACxB,OAAO;IACT;IACF,IAAIY,UAAUX,QAAQ,cAAc;IACpC,MAAMY,gBAAgBC,oBAAoBb,QAAQ,MAAM;IACxD,MAAMc,SAASF,cAAc,MAAM;IACnC,MAAMG,oBAKD,EAAE;IACP,IAAIC,yBAAyB;IAC7B,IAAIC,UAAU;IAC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,QAAQkC,SAAS;wBAC3C,eAAe,OAAOW;4BACpB,IAAI;gCACF,IAAI,CAACnC,WAAW,IAAI,CAAC,CAACoB,QAAUA,AAAgB,YAAhBA,MAAM,KAAK,GACzC,MAAMZ,SAAS,YAAY1B,UAAUqD;4BACzC,EAAE,OAAOf,OAAO;gCACdrB,gBAAgB,IAAI,CAACqB;gCACrBE,uBAAuB,IAAI,CAACF;4BAC9B;wBACF;wBACA,iBAAiB,CAACA,QAChBgB,SAAS,kBAAkB;gCAAE,SAAS;4BAAK,GACzC,CAAC,kCAAkC,EAAEC,OAAOjB,QAAQ;oBAE1D;yBACG5B,yBAAyB;gBAChC,EAAE,OAAO4B,OAAO;oBACdG,kBAAkBH,iBAAiBkB;oBACnC,IAAI,CAACf,iBAAiB/B,yBAAyB;oBAC/CW,eAAe,IAAI,CACjB,IAAI4B,uBAAuBX,OAAO;wBAChC,OAAO;wBACP,SAAS3C;wBACT,MAAM;wBACN,mBAAmB;oBACrB;gBAEJ;gBACAiB,iBAAiBQ,aAAaC;gBAC9B,IAAI;oBACF,MAAM3B,QAAQ,QAAQ,GAAGkB;gBAC3B,EAAE,OAAO0B,OAAO;oBACdrB,gBAAgB,IAAI,CAACqB;oBACrB1B,iBAAiBQ,aAAaC;gBAChC;gBACAf,cAAc,OAAO;gBACrB,IAAIW,gBAAgB,MAAM,EACxB,MAAM,IAAIsB,yBAAyB3B,gBAAgB;uBAC9CK;iBACJ;gBACH,OAAOL;YACT;YACA,OAAOC;QACT;IACF;AACF"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { NodeExecutionError, NodeInputValidationError, StepTimeoutError, normalizeNodeExecutionError } from "../errors.mjs";
|
|
2
|
+
import { linkResourceSignal } from "./resource-operations.mjs";
|
|
3
|
+
function validateNodeOutput(output, node) {
|
|
4
|
+
if (void 0 === output) return;
|
|
5
|
+
if ('object' != typeof output || null === output || Array.isArray(output)) throw new NodeExecutionError(node, new TypeError('Node output must be an object or undefined.'));
|
|
6
|
+
if ('summary' in output && void 0 !== output.summary && 'string' != typeof output.summary) throw new NodeExecutionError(node, new TypeError('Node output summary must be a string.'));
|
|
7
|
+
return output;
|
|
8
|
+
}
|
|
9
|
+
function createStepResultBase(step, startedAt, phase, stepIndex) {
|
|
10
|
+
const endedAt = new Date();
|
|
11
|
+
return {
|
|
12
|
+
node: step.node,
|
|
13
|
+
phase,
|
|
14
|
+
stepIndex,
|
|
15
|
+
input: step.input,
|
|
16
|
+
meta: step.meta,
|
|
17
|
+
startedAt: startedAt.toISOString(),
|
|
18
|
+
endedAt: endedAt.toISOString(),
|
|
19
|
+
durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime())
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function executeNode(step, execute, phase, stepIndex, options) {
|
|
23
|
+
const startedAt = new Date();
|
|
24
|
+
const abortController = new AbortController();
|
|
25
|
+
const parentSignal = options.parentSignal;
|
|
26
|
+
linkResourceSignal(abortController.signal, parentSignal);
|
|
27
|
+
const abortFromParent = ()=>abortController.abort(parentSignal?.reason);
|
|
28
|
+
if (parentSignal?.aborted) abortFromParent();
|
|
29
|
+
else parentSignal?.addEventListener('abort', abortFromParent, {
|
|
30
|
+
once: true
|
|
31
|
+
});
|
|
32
|
+
const timeoutMs = step.meta.timeoutMs ?? options.defaultTimeoutMs;
|
|
33
|
+
let timeout;
|
|
34
|
+
let abortGraceTimeout;
|
|
35
|
+
const execution = Promise.resolve().then(()=>{
|
|
36
|
+
abortController.signal.throwIfAborted();
|
|
37
|
+
return execute(abortController.signal);
|
|
38
|
+
});
|
|
39
|
+
let settleOnAbort;
|
|
40
|
+
const abortedExecution = new Promise((_, reject)=>{
|
|
41
|
+
settleOnAbort = ()=>{
|
|
42
|
+
abortGraceTimeout = setTimeout(()=>{
|
|
43
|
+
reject(abortController.signal.reason);
|
|
44
|
+
}, 0);
|
|
45
|
+
};
|
|
46
|
+
if (abortController.signal.aborted) settleOnAbort();
|
|
47
|
+
else abortController.signal.addEventListener('abort', settleOnAbort, {
|
|
48
|
+
once: true
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
const timeoutExecution = void 0 === timeoutMs ? void 0 : new Promise((_, reject)=>{
|
|
52
|
+
timeout = setTimeout(()=>{
|
|
53
|
+
if (abortController.signal.aborted) return void reject(abortController.signal.reason);
|
|
54
|
+
const timeoutError = new StepTimeoutError(timeoutMs, step.node);
|
|
55
|
+
abortController.abort(timeoutError);
|
|
56
|
+
reject(timeoutError);
|
|
57
|
+
}, timeoutMs);
|
|
58
|
+
});
|
|
59
|
+
const settledExecution = Promise.race([
|
|
60
|
+
execution,
|
|
61
|
+
abortedExecution,
|
|
62
|
+
...void 0 === timeoutExecution ? [] : [
|
|
63
|
+
timeoutExecution
|
|
64
|
+
]
|
|
65
|
+
]);
|
|
66
|
+
try {
|
|
67
|
+
const output = validateNodeOutput(await settledExecution, step.node);
|
|
68
|
+
return {
|
|
69
|
+
...createStepResultBase(step, startedAt, phase, stepIndex),
|
|
70
|
+
status: 'success',
|
|
71
|
+
continuedAfterError: false,
|
|
72
|
+
...void 0 === output ? {} : {
|
|
73
|
+
output
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
let output;
|
|
78
|
+
let failure = error;
|
|
79
|
+
if (error instanceof NodeExecutionError && void 0 !== error.output) try {
|
|
80
|
+
output = validateNodeOutput(error.output, step.node);
|
|
81
|
+
} catch (validationError) {
|
|
82
|
+
failure = validationError;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
...createStepResultBase(step, startedAt, phase, stepIndex),
|
|
86
|
+
status: 'failed',
|
|
87
|
+
continuedAfterError: step.meta.continueOnError,
|
|
88
|
+
error: normalizeNodeExecutionError(failure, step.node),
|
|
89
|
+
...void 0 === output ? {} : {
|
|
90
|
+
output
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
} finally{
|
|
94
|
+
if (void 0 !== timeout) clearTimeout(timeout);
|
|
95
|
+
if (void 0 !== abortGraceTimeout) clearTimeout(abortGraceTimeout);
|
|
96
|
+
if (void 0 !== settleOnAbort) abortController.signal.removeEventListener('abort', settleOnAbort);
|
|
97
|
+
parentSignal?.removeEventListener('abort', abortFromParent);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function createNodeReportCollector(node) {
|
|
101
|
+
const traces = new Map();
|
|
102
|
+
let accepting = true;
|
|
103
|
+
return {
|
|
104
|
+
collector: Object.freeze({
|
|
105
|
+
addTrace (trace) {
|
|
106
|
+
if (!accepting) throw new NodeExecutionError(node, new Error('Report traces can only be added while the current Step is running.'));
|
|
107
|
+
if (!trace || 'object' != typeof trace || 'midscene-execution' !== trace.type) throw new NodeExecutionError(node, new TypeError('Report trace type must be "midscene-execution".'));
|
|
108
|
+
if ('string' != typeof trace.executionId || 0 === trace.executionId.trim().length) throw new NodeExecutionError(node, new TypeError('Report trace executionId must be non-empty.'));
|
|
109
|
+
const normalized = Object.freeze({
|
|
110
|
+
type: 'midscene-execution',
|
|
111
|
+
executionId: trace.executionId
|
|
112
|
+
});
|
|
113
|
+
traces.set(`${normalized.type}:${normalized.executionId}`, normalized);
|
|
114
|
+
}
|
|
115
|
+
}),
|
|
116
|
+
close () {
|
|
117
|
+
accepting = false;
|
|
118
|
+
return Object.freeze([
|
|
119
|
+
...traces.values()
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async function parseNodeInput(node, input) {
|
|
125
|
+
if (!node.inputSchema) return input;
|
|
126
|
+
const parsed = await node.inputSchema.safeParseAsync(input);
|
|
127
|
+
if (!parsed.success) throw NodeInputValidationError.fromZod(node.name, parsed.error);
|
|
128
|
+
return parsed.data;
|
|
129
|
+
}
|
|
130
|
+
async function executeStep(step, node, target, context, execution = {}) {
|
|
131
|
+
const phase = 'case' === target.scope ? target.case.phase : target.document.phase;
|
|
132
|
+
const stepIndex = 'case' === target.scope ? target.case.stepIndex : target.document.stepIndex;
|
|
133
|
+
const reportCollector = createNodeReportCollector(step.node);
|
|
134
|
+
let result;
|
|
135
|
+
try {
|
|
136
|
+
result = await executeNode(step, async (signal)=>{
|
|
137
|
+
const input = await parseNodeInput(node, step.input);
|
|
138
|
+
signal.throwIfAborted();
|
|
139
|
+
const common = {
|
|
140
|
+
input,
|
|
141
|
+
$: step.meta,
|
|
142
|
+
signal,
|
|
143
|
+
context,
|
|
144
|
+
report: reportCollector.collector,
|
|
145
|
+
onTeardown: (teardown)=>{
|
|
146
|
+
if (!execution.onTeardown) throw new NodeExecutionError(step.node, new Error('The current execution scope cannot register teardown.'));
|
|
147
|
+
execution.onTeardown(step.node, teardown);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return 'case' === target.scope ? node.execute({
|
|
151
|
+
...common,
|
|
152
|
+
scope: 'case',
|
|
153
|
+
case: target.case
|
|
154
|
+
}) : node.execute({
|
|
155
|
+
...common,
|
|
156
|
+
scope: 'document',
|
|
157
|
+
document: target.document
|
|
158
|
+
});
|
|
159
|
+
}, phase, stepIndex, {
|
|
160
|
+
parentSignal: execution.signal,
|
|
161
|
+
defaultTimeoutMs: execution.defaultTimeoutMs
|
|
162
|
+
});
|
|
163
|
+
} finally{
|
|
164
|
+
const traces = reportCollector.close();
|
|
165
|
+
if (traces.length > 0 && result) result = {
|
|
166
|
+
...result,
|
|
167
|
+
report: {
|
|
168
|
+
traces
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (!result) throw new NodeExecutionError(step.node, new Error('Step execution completed without a result.'));
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
export { executeStep };
|
|
176
|
+
|
|
177
|
+
//# sourceMappingURL=execute-step.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-runner/engine/execute-step.mjs","sources":["../../../../src/test-runner/engine/execute-step.ts"],"sourcesContent":["import {\n NodeExecutionError,\n NodeInputValidationError,\n StepTimeoutError,\n normalizeNodeExecutionError,\n} from '../errors';\nimport type {\n NodeDefinition,\n NodeReportCollector,\n NodeReportTrace,\n NodeResult,\n} from '../node/types';\nimport type { NormalizedStep } from '../parser/types';\nimport { linkResourceSignal } from './resource-operations';\nimport type {\n NodeCaseContext,\n NodeDocumentContext,\n NodeExecutionPhase,\n NodeScopeTeardown,\n StepRunResult,\n} from './types';\n\nfunction validateNodeOutput<TData>(\n output: unknown,\n node: string,\n): NodeResult<TData> | undefined {\n if (output === undefined) {\n return undefined;\n }\n\n if (typeof output !== 'object' || output === null || Array.isArray(output)) {\n throw new NodeExecutionError(\n node,\n new TypeError('Node output must be an object or undefined.'),\n );\n }\n\n if (\n 'summary' in output &&\n output.summary !== undefined &&\n typeof output.summary !== 'string'\n ) {\n throw new NodeExecutionError(\n node,\n new TypeError('Node output summary must be a string.'),\n );\n }\n\n // Node data is an API value. JSON serialization belongs to the publisher;\n // serialization failure must not turn completed actions into retryable work.\n\n return output as NodeResult<TData>;\n}\n\nfunction createStepResultBase(\n step: NormalizedStep,\n startedAt: Date,\n phase: NodeExecutionPhase,\n stepIndex: number,\n) {\n const endedAt = new Date();\n return {\n node: step.node,\n phase,\n stepIndex,\n input: step.input,\n meta: step.meta,\n startedAt: startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),\n };\n}\n\nasync function executeNode<TOutputData>(\n step: NormalizedStep,\n execute: (signal: AbortSignal) => unknown,\n phase: NodeExecutionPhase,\n stepIndex: number,\n options: { parentSignal?: AbortSignal; defaultTimeoutMs?: number },\n): Promise<StepRunResult<TOutputData>> {\n const startedAt = new Date();\n const abortController = new AbortController();\n const parentSignal = options.parentSignal;\n linkResourceSignal(abortController.signal, parentSignal);\n const abortFromParent = () => abortController.abort(parentSignal?.reason);\n if (parentSignal?.aborted) abortFromParent();\n else parentSignal?.addEventListener('abort', abortFromParent, { once: true });\n const timeoutMs = step.meta.timeoutMs ?? options.defaultTimeoutMs;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let abortGraceTimeout: ReturnType<typeof setTimeout> | undefined;\n const execution = Promise.resolve().then(() => {\n abortController.signal.throwIfAborted();\n return execute(abortController.signal);\n });\n let settleOnAbort: (() => void) | undefined;\n const abortedExecution = new Promise<never>((_, reject) => {\n settleOnAbort = () => {\n // Abort listeners run synchronously. Wait one task before rejecting so a\n // cooperative node can settle in response to the forwarded abort first.\n abortGraceTimeout = setTimeout(() => {\n reject(abortController.signal.reason);\n }, 0);\n };\n if (abortController.signal.aborted) settleOnAbort();\n else\n abortController.signal.addEventListener('abort', settleOnAbort, {\n once: true,\n });\n });\n const timeoutExecution =\n timeoutMs === undefined\n ? undefined\n : new Promise<never>((_, reject) => {\n timeout = setTimeout(() => {\n if (abortController.signal.aborted) {\n reject(abortController.signal.reason);\n return;\n }\n const timeoutError = new StepTimeoutError(timeoutMs, step.node);\n abortController.abort(timeoutError);\n reject(timeoutError);\n }, timeoutMs);\n });\n const settledExecution = Promise.race([\n execution,\n abortedExecution,\n ...(timeoutExecution === undefined ? [] : [timeoutExecution]),\n ]);\n\n try {\n const output = validateNodeOutput<TOutputData>(\n await settledExecution,\n step.node,\n );\n return {\n ...createStepResultBase(step, startedAt, phase, stepIndex),\n status: 'success',\n continuedAfterError: false,\n ...(output === undefined ? {} : { output }),\n };\n } catch (error) {\n let output: NodeResult<TOutputData> | undefined;\n let failure = error;\n if (error instanceof NodeExecutionError && error.output !== undefined) {\n try {\n output = validateNodeOutput<TOutputData>(error.output, step.node);\n } catch (validationError) {\n failure = validationError;\n }\n }\n return {\n ...createStepResultBase(step, startedAt, phase, stepIndex),\n status: 'failed',\n continuedAfterError: step.meta.continueOnError,\n error: normalizeNodeExecutionError(failure, step.node),\n ...(output === undefined ? {} : { output }),\n };\n } finally {\n if (timeout !== undefined) clearTimeout(timeout);\n if (abortGraceTimeout !== undefined) clearTimeout(abortGraceTimeout);\n if (settleOnAbort !== undefined) {\n abortController.signal.removeEventListener('abort', settleOnAbort);\n }\n parentSignal?.removeEventListener('abort', abortFromParent);\n }\n}\n\ntype StepExecutionTarget =\n | { scope: 'case'; case: NodeCaseContext }\n | { scope: 'document'; document: NodeDocumentContext };\n\nfunction createNodeReportCollector(node: string): {\n collector: NodeReportCollector;\n close(): readonly NodeReportTrace[];\n} {\n const traces = new Map<string, NodeReportTrace>();\n let accepting = true;\n\n return {\n collector: Object.freeze({\n addTrace(trace: NodeReportTrace): void {\n if (!accepting) {\n throw new NodeExecutionError(\n node,\n new Error(\n 'Report traces can only be added while the current Step is running.',\n ),\n );\n }\n if (\n !trace ||\n typeof trace !== 'object' ||\n (trace as { type?: unknown }).type !== 'midscene-execution'\n ) {\n throw new NodeExecutionError(\n node,\n new TypeError('Report trace type must be \"midscene-execution\".'),\n );\n }\n if (\n typeof trace.executionId !== 'string' ||\n trace.executionId.trim().length === 0\n ) {\n throw new NodeExecutionError(\n node,\n new TypeError('Report trace executionId must be non-empty.'),\n );\n }\n const normalized = Object.freeze({\n type: 'midscene-execution' as const,\n executionId: trace.executionId,\n });\n traces.set(`${normalized.type}:${normalized.executionId}`, normalized);\n },\n }),\n close(): readonly NodeReportTrace[] {\n accepting = false;\n return Object.freeze([...traces.values()]);\n },\n };\n}\n\nasync function parseNodeInput<TInput, TData, TContext>(\n node: NodeDefinition<TInput, TData, TContext>,\n input: Record<string, unknown>,\n): Promise<TInput> {\n if (!node.inputSchema) {\n return input as TInput;\n }\n\n const parsed = await node.inputSchema.safeParseAsync(input);\n if (!parsed.success) {\n throw NodeInputValidationError.fromZod(node.name, parsed.error);\n }\n return parsed.data as TInput;\n}\n\nexport async function executeStep<\n TInput = unknown,\n TOutputData = unknown,\n TContext = unknown,\n>(\n step: NormalizedStep,\n node: NodeDefinition<TInput, TOutputData, TContext>,\n target: StepExecutionTarget,\n context: TContext,\n execution: {\n signal?: AbortSignal;\n defaultTimeoutMs?: number;\n onTeardown?(node: string, teardown: NodeScopeTeardown): void;\n } = {},\n): Promise<StepRunResult<TOutputData>> {\n const phase =\n target.scope === 'case' ? target.case.phase : target.document.phase;\n const stepIndex =\n target.scope === 'case' ? target.case.stepIndex : target.document.stepIndex;\n\n const reportCollector = createNodeReportCollector(step.node);\n let result: StepRunResult<TOutputData> | undefined;\n\n try {\n result = await executeNode<TOutputData>(\n step,\n async (signal) => {\n const input = await parseNodeInput(node, step.input);\n signal.throwIfAborted();\n const common = {\n input,\n $: step.meta,\n signal,\n context,\n report: reportCollector.collector,\n onTeardown: (teardown: NodeScopeTeardown) => {\n if (!execution.onTeardown) {\n throw new NodeExecutionError(\n step.node,\n new Error(\n 'The current execution scope cannot register teardown.',\n ),\n );\n }\n execution.onTeardown(step.node, teardown);\n },\n };\n return target.scope === 'case'\n ? node.execute({ ...common, scope: 'case', case: target.case })\n : node.execute({\n ...common,\n scope: 'document',\n document: target.document,\n });\n },\n phase,\n stepIndex,\n {\n parentSignal: execution.signal,\n defaultTimeoutMs: execution.defaultTimeoutMs,\n },\n );\n } finally {\n const traces = reportCollector.close();\n if (traces.length > 0 && result) {\n result = { ...result, report: { traces } };\n }\n }\n\n if (!result) {\n throw new NodeExecutionError(\n step.node,\n new Error('Step execution completed without a result.'),\n );\n }\n return result;\n}\n"],"names":["validateNodeOutput","output","node","undefined","Array","NodeExecutionError","TypeError","createStepResultBase","step","startedAt","phase","stepIndex","endedAt","Date","Math","executeNode","execute","options","abortController","AbortController","parentSignal","linkResourceSignal","abortFromParent","timeoutMs","timeout","abortGraceTimeout","execution","Promise","settleOnAbort","abortedExecution","_","reject","setTimeout","timeoutExecution","timeoutError","StepTimeoutError","settledExecution","error","failure","validationError","normalizeNodeExecutionError","clearTimeout","createNodeReportCollector","traces","Map","accepting","Object","trace","Error","normalized","parseNodeInput","input","parsed","NodeInputValidationError","executeStep","target","context","reportCollector","result","signal","common","teardown"],"mappings":";;AAsBA,SAASA,mBACPC,MAAe,EACfC,IAAY;IAEZ,IAAID,AAAWE,WAAXF,QACF;IAGF,IAAI,AAAkB,YAAlB,OA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,SAAU;QACR,MAAMiB,SAASc,gBAAgB,KAAK;QACpC,IAAId,OAAO,MAAM,GAAG,KAAKe,QACvBA,SAAS;YAAE,GAAGA,MAAM;YAAE,QAAQ;gBAAEf;YAAO;QAAE;IAE7C;IAEA,IAAI,CAACe,QACH,MAAM,IAAIrD,mBACRG,KAAK,IAAI,EACT,IAAIwC,MAAM;IAGd,OAAOU;AACT"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { WorkflowError } from "../errors.mjs";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
const errorMessage = (error)=>error && 'object' == typeof error && 'message' in error && 'string' == typeof error.message ? error.message : String(error);
|
|
13
|
+
class WorkflowExecutionFailure extends WorkflowError {
|
|
14
|
+
constructor(result, errors){
|
|
15
|
+
super(errors.map(errorMessage).join('; '), {
|
|
16
|
+
code: 'WORKFLOW_EXECUTION_FAILURE',
|
|
17
|
+
cause: errors[0]
|
|
18
|
+
}), _define_property(this, "result", void 0), _define_property(this, "errors", void 0), this.result = result, this.errors = errors;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class WorkflowPublicationError extends WorkflowError {
|
|
22
|
+
constructor(operation, path, cause){
|
|
23
|
+
super(`Failed to ${operation} at ${path}: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
24
|
+
code: 'WORKFLOW_PUBLICATION_FAILED',
|
|
25
|
+
details: {
|
|
26
|
+
operation,
|
|
27
|
+
path
|
|
28
|
+
},
|
|
29
|
+
cause
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const asExecutionError = (error)=>error instanceof WorkflowError ? error : new WorkflowError(errorMessage(error), {
|
|
34
|
+
code: 'WORKFLOW_EXECUTION_FAILURE',
|
|
35
|
+
cause: error
|
|
36
|
+
});
|
|
37
|
+
export { WorkflowExecutionFailure, WorkflowPublicationError, asExecutionError };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=execution-failure.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-runner/engine/execution-failure.mjs","sources":["../../../../src/test-runner/engine/execution-failure.ts"],"sourcesContent":["import { WorkflowError } from '../errors';\n\nconst errorMessage = (error: unknown): string =>\n error &&\n typeof error === 'object' &&\n 'message' in error &&\n typeof error.message === 'string'\n ? error.message\n : String(error);\n\n/** An infrastructure failure still carries all execution facts collected so far. */\nexport class WorkflowExecutionFailure<T> extends WorkflowError {\n constructor(\n readonly result: T,\n readonly errors: readonly unknown[],\n ) {\n super(errors.map(errorMessage).join('; '), {\n code: 'WORKFLOW_EXECUTION_FAILURE',\n cause: errors[0],\n });\n }\n}\n\n/** Publication is an infrastructure failure, not a failed test action. */\nexport class WorkflowPublicationError extends WorkflowError {\n constructor(\n operation: 'write-result' | 'write-report' | 'preserve-report',\n path: string,\n cause: unknown,\n ) {\n super(\n `Failed to ${operation} at ${path}: ${cause instanceof Error ? cause.message : String(cause)}`,\n {\n code: 'WORKFLOW_PUBLICATION_FAILED',\n details: { operation, path },\n cause,\n },\n );\n }\n}\n\nexport const asExecutionError = (error: unknown): WorkflowError =>\n error instanceof WorkflowError\n ? error\n : new WorkflowError(errorMessage(error), {\n code: 'WORKFLOW_EXECUTION_FAILURE',\n cause: error,\n });\n"],"names":["errorMessage","error","String","WorkflowExecutionFailure","WorkflowError","result","errors","WorkflowPublicationError","operation","path","cause","Error","asExecutionError"],"mappings":";;;;;;;;;;;AAEA,MAAMA,eAAe,CAACC,QACpBA,SACA,AAAiB,YAAjB,OAAOA,SACP,aAAaA,SACb,AAAyB,YAAzB,OAAOA,MAAM,OAAO,GAChBA,MAAM,OAAO,GACbC,OAAOD;AAGN,MAAME,iCAAoCC;IAC/C,YACWC,MAAS,EACTC,MAA0B,CACnC;QACA,KAAK,CAACA,OAAO,GAAG,CAACN,cAAc,IAAI,CAAC,OAAO;YACzC,MAAM;YACN,OAAOM,MAAM,CAAC,EAAE;QAClB,6FANSD,MAAM,GAANA,QAAAA,IAAAA,CACAC,MAAM,GAANA;IAMX;AACF;AAGO,MAAMC,iCAAiCH;IAC5C,YACEI,SAA8D,EAC9DC,IAAY,EACZC,KAAc,CACd;QACA,KAAK,CACH,CAAC,UAAU,EAAEF,UAAU,IAAI,EAAEC,KAAK,EAAE,EAAEC,iBAAiBC,QAAQD,MAAM,OAAO,GAAGR,OAAOQ,QAAQ,EAC9F;YACE,MAAM;YACN,SAAS;gBAAEF;gBAAWC;YAAK;YAC3BC;QACF;IAEJ;AACF;AAEO,MAAME,mBAAmB,CAACX,QAC/BA,iBAAiBG,gBACbH,QACA,IAAIG,cAAcJ,aAAaC,QAAQ;QACrC,MAAM;QACN,OAAOA;IACT"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./case-runner.mjs";
|
|
2
|
+
export * from "./document-runtime.mjs";
|
|
3
|
+
export * from "./registry.mjs";
|
|
4
|
+
export * from "./run-collected-case.mjs";
|
|
5
|
+
export * from "./run-workflow-document.mjs";
|
|
6
|
+
export * from "./types.mjs";
|
|
7
|
+
export * from "./project-runtime.mjs";
|
|
8
|
+
export * from "./execute-step.mjs";
|
|
9
|
+
export * from "./scope-teardown.mjs";
|
|
10
|
+
export * from "./execution-failure.mjs";
|
|
11
|
+
export * from "./resource-operations.mjs";
|
|
12
|
+
export * from "./scheduler.mjs";
|