@shipfox/api-workflows 2.0.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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +311 -0
- package/LICENSE +21 -0
- package/dist/core/agent-tool-capability-warning.d.ts +7 -0
- package/dist/core/agent-tool-capability-warning.d.ts.map +1 -0
- package/dist/core/agent-tool-capability-warning.js +149 -0
- package/dist/core/agent-tool-capability-warning.js.map +1 -0
- package/dist/core/agent-tools.d.ts +51 -0
- package/dist/core/agent-tools.d.ts.map +1 -0
- package/dist/core/agent-tools.js +296 -0
- package/dist/core/agent-tools.js.map +1 -0
- package/dist/core/checkout.d.ts +29 -0
- package/dist/core/checkout.d.ts.map +1 -0
- package/dist/core/checkout.js +42 -0
- package/dist/core/checkout.js.map +1 -0
- package/dist/core/condition-trace.d.ts +13 -0
- package/dist/core/condition-trace.d.ts.map +1 -0
- package/dist/core/condition-trace.js +51 -0
- package/dist/core/condition-trace.js.map +1 -0
- package/dist/core/entities/index.d.ts +5 -0
- package/dist/core/entities/index.d.ts.map +1 -0
- package/dist/core/entities/index.js +3 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/job-execution.d.ts +30 -0
- package/dist/core/entities/job-execution.d.ts.map +1 -0
- package/dist/core/entities/job-execution.js +3 -0
- package/dist/core/entities/job-execution.js.map +1 -0
- package/dist/core/entities/job-listener-event.d.ts +15 -0
- package/dist/core/entities/job-listener-event.d.ts.map +1 -0
- package/dist/core/entities/job-listener-event.js +3 -0
- package/dist/core/entities/job-listener-event.js.map +1 -0
- package/dist/core/entities/job.d.ts +54 -0
- package/dist/core/entities/job.d.ts.map +1 -0
- package/dist/core/entities/job.js +29 -0
- package/dist/core/entities/job.js.map +1 -0
- package/dist/core/entities/step.d.ts +86 -0
- package/dist/core/entities/step.d.ts.map +1 -0
- package/dist/core/entities/step.js +12 -0
- package/dist/core/entities/step.js.map +1 -0
- package/dist/core/entities/workflow-run-attempt.d.ts +20 -0
- package/dist/core/entities/workflow-run-attempt.d.ts.map +1 -0
- package/dist/core/entities/workflow-run-attempt.js +3 -0
- package/dist/core/entities/workflow-run-attempt.js.map +1 -0
- package/dist/core/entities/workflow-run.d.ts +66 -0
- package/dist/core/entities/workflow-run.d.ts.map +1 -0
- package/dist/core/entities/workflow-run.js +10 -0
- package/dist/core/entities/workflow-run.js.map +1 -0
- package/dist/core/errors.d.ts +85 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +134 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/job-execution-outcome.d.ts +29 -0
- package/dist/core/job-execution-outcome.d.ts.map +1 -0
- package/dist/core/job-execution-outcome.js +31 -0
- package/dist/core/job-execution-outcome.js.map +1 -0
- package/dist/core/job-execution.d.ts +37 -0
- package/dist/core/job-execution.d.ts.map +1 -0
- package/dist/core/job-execution.js +425 -0
- package/dist/core/job-execution.js.map +1 -0
- package/dist/core/job-transition/decide-job-activation.d.ts +29 -0
- package/dist/core/job-transition/decide-job-activation.d.ts.map +1 -0
- package/dist/core/job-transition/decide-job-activation.js +51 -0
- package/dist/core/job-transition/decide-job-activation.js.map +1 -0
- package/dist/core/job-transition/derive-job-execution-outputs.d.ts +18 -0
- package/dist/core/job-transition/derive-job-execution-outputs.d.ts.map +1 -0
- package/dist/core/job-transition/derive-job-execution-outputs.js +23 -0
- package/dist/core/job-transition/derive-job-execution-outputs.js.map +1 -0
- package/dist/core/job-transition/derive-job-success.d.ts +16 -0
- package/dist/core/job-transition/derive-job-success.d.ts.map +1 -0
- package/dist/core/job-transition/derive-job-success.js +47 -0
- package/dist/core/job-transition/derive-job-success.js.map +1 -0
- package/dist/core/job-transition/index.d.ts +5 -0
- package/dist/core/job-transition/index.d.ts.map +1 -0
- package/dist/core/job-transition/index.js +6 -0
- package/dist/core/job-transition/index.js.map +1 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.d.ts +4 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.d.ts.map +1 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.js +8 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.js.map +1 -0
- package/dist/core/listener-execution-materialization.d.ts +30 -0
- package/dist/core/listener-execution-materialization.d.ts.map +1 -0
- package/dist/core/listener-execution-materialization.js +87 -0
- package/dist/core/listener-execution-materialization.js.map +1 -0
- package/dist/core/run-workflow.d.ts +11 -0
- package/dist/core/run-workflow.d.ts.map +1 -0
- package/dist/core/run-workflow.js +28 -0
- package/dist/core/run-workflow.js.map +1 -0
- package/dist/core/source-control.d.ts +5 -0
- package/dist/core/source-control.d.ts.map +1 -0
- package/dist/core/source-control.js +19 -0
- package/dist/core/source-control.js.map +1 -0
- package/dist/core/step-config/agent.d.ts +49 -0
- package/dist/core/step-config/agent.d.ts.map +1 -0
- package/dist/core/step-config/agent.js +337 -0
- package/dist/core/step-config/agent.js.map +1 -0
- package/dist/core/step-config/assemble-run-context.d.ts +94 -0
- package/dist/core/step-config/assemble-run-context.d.ts.map +1 -0
- package/dist/core/step-config/assemble-run-context.js +393 -0
- package/dist/core/step-config/assemble-run-context.js.map +1 -0
- package/dist/core/step-config/complete-step-dispatch-config.d.ts +13 -0
- package/dist/core/step-config/complete-step-dispatch-config.d.ts.map +1 -0
- package/dist/core/step-config/complete-step-dispatch-config.js +38 -0
- package/dist/core/step-config/complete-step-dispatch-config.js.map +1 -0
- package/dist/core/step-config/fields.d.ts +38 -0
- package/dist/core/step-config/fields.d.ts.map +1 -0
- package/dist/core/step-config/fields.js +72 -0
- package/dist/core/step-config/fields.js.map +1 -0
- package/dist/core/step-config/index.d.ts +8 -0
- package/dist/core/step-config/index.d.ts.map +1 -0
- package/dist/core/step-config/index.js +7 -0
- package/dist/core/step-config/index.js.map +1 -0
- package/dist/core/step-config/materialize-job-execution-steps.d.ts +35 -0
- package/dist/core/step-config/materialize-job-execution-steps.d.ts.map +1 -0
- package/dist/core/step-config/materialize-job-execution-steps.js +92 -0
- package/dist/core/step-config/materialize-job-execution-steps.js.map +1 -0
- package/dist/core/step-config/materialize-workflow-model.d.ts +42 -0
- package/dist/core/step-config/materialize-workflow-model.d.ts.map +1 -0
- package/dist/core/step-config/materialize-workflow-model.js +96 -0
- package/dist/core/step-config/materialize-workflow-model.js.map +1 -0
- package/dist/core/step-config/resolve-job-execution-name.d.ts +18 -0
- package/dist/core/step-config/resolve-job-execution-name.d.ts.map +1 -0
- package/dist/core/step-config/resolve-job-execution-name.js +36 -0
- package/dist/core/step-config/resolve-job-execution-name.js.map +1 -0
- package/dist/core/step-config/resolve-step-config.d.ts +33 -0
- package/dist/core/step-config/resolve-step-config.d.ts.map +1 -0
- package/dist/core/step-config/resolve-step-config.js +164 -0
- package/dist/core/step-config/resolve-step-config.js.map +1 -0
- package/dist/core/step-config/run.d.ts +39 -0
- package/dist/core/step-config/run.d.ts.map +1 -0
- package/dist/core/step-config/run.js +360 -0
- package/dist/core/step-config/run.js.map +1 -0
- package/dist/core/step-config/workflow-evaluation-context.d.ts +6 -0
- package/dist/core/step-config/workflow-evaluation-context.d.ts.map +1 -0
- package/dist/core/step-config/workflow-evaluation-context.js +3 -0
- package/dist/core/step-config/workflow-evaluation-context.js.map +1 -0
- package/dist/core/step-transition/apply-step-transition.d.ts +26 -0
- package/dist/core/step-transition/apply-step-transition.d.ts.map +1 -0
- package/dist/core/step-transition/apply-step-transition.js +141 -0
- package/dist/core/step-transition/apply-step-transition.js.map +1 -0
- package/dist/core/step-transition/decide-step-transition.d.ts +71 -0
- package/dist/core/step-transition/decide-step-transition.d.ts.map +1 -0
- package/dist/core/step-transition/decide-step-transition.js +110 -0
- package/dist/core/step-transition/decide-step-transition.js.map +1 -0
- package/dist/core/step-transition/evaluate-gate.d.ts +28 -0
- package/dist/core/step-transition/evaluate-gate.d.ts.map +1 -0
- package/dist/core/step-transition/evaluate-gate.js +159 -0
- package/dist/core/step-transition/evaluate-gate.js.map +1 -0
- package/dist/core/step-transition/read-step-outputs.d.ts +3 -0
- package/dist/core/step-transition/read-step-outputs.d.ts.map +1 -0
- package/dist/core/step-transition/read-step-outputs.js +24 -0
- package/dist/core/step-transition/read-step-outputs.js.map +1 -0
- package/dist/core/workflow-run-creation.d.ts +43 -0
- package/dist/core/workflow-run-creation.d.ts.map +1 -0
- package/dist/core/workflow-run-creation.js +80 -0
- package/dist/core/workflow-run-creation.js.map +1 -0
- package/dist/core/workflow-scheduling/index.d.ts +5 -0
- package/dist/core/workflow-scheduling/index.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/index.js +4 -0
- package/dist/core/workflow-scheduling/index.js.map +1 -0
- package/dist/core/workflow-scheduling/run-progress.d.ts +20 -0
- package/dist/core/workflow-scheduling/run-progress.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/run-progress.js +40 -0
- package/dist/core/workflow-scheduling/run-progress.js.map +1 -0
- package/dist/core/workflow-scheduling/runtime-dag.d.ts +10 -0
- package/dist/core/workflow-scheduling/runtime-dag.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/runtime-dag.js +3 -0
- package/dist/core/workflow-scheduling/runtime-dag.js.map +1 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.d.ts +16 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.js +3 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.js.map +1 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.d.ts +9 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.js +72 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.js.map +1 -0
- package/dist/db/db.d.ts +4959 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +37 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/index.d.ts +9 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +10 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/job-listener-events.d.ts +18 -0
- package/dist/db/job-listener-events.d.ts.map +1 -0
- package/dist/db/job-listener-events.js +59 -0
- package/dist/db/job-listener-events.js.map +1 -0
- package/dist/db/job-listeners.d.ts +55 -0
- package/dist/db/job-listeners.d.ts.map +1 -0
- package/dist/db/job-listeners.js +358 -0
- package/dist/db/job-listeners.js.map +1 -0
- package/dist/db/outbox-writes.d.ts +12 -0
- package/dist/db/outbox-writes.d.ts.map +1 -0
- package/dist/db/outbox-writes.js +20 -0
- package/dist/db/outbox-writes.js.map +1 -0
- package/dist/db/runner-lease-table.d.ts +469 -0
- package/dist/db/runner-lease-table.d.ts.map +1 -0
- package/dist/db/runner-lease-table.js +42 -0
- package/dist/db/runner-lease-table.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/job-executions.d.ts +311 -0
- package/dist/db/schema/job-executions.d.ts.map +1 -0
- package/dist/db/schema/job-executions.js +76 -0
- package/dist/db/schema/job-executions.js.map +1 -0
- package/dist/db/schema/job-listener-events.d.ts +200 -0
- package/dist/db/schema/job-listener-events.d.ts.map +1 -0
- package/dist/db/schema/job-listener-events.js +50 -0
- package/dist/db/schema/job-listener-events.js.map +1 -0
- package/dist/db/schema/jobs.d.ts +542 -0
- package/dist/db/schema/jobs.d.ts.map +1 -0
- package/dist/db/schema/jobs.js +121 -0
- package/dist/db/schema/jobs.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/schema/step-attempts.d.ts +330 -0
- package/dist/db/schema/step-attempts.d.ts.map +1 -0
- package/dist/db/schema/step-attempts.js +80 -0
- package/dist/db/schema/step-attempts.js.map +1 -0
- package/dist/db/schema/steps.d.ts +352 -0
- package/dist/db/schema/steps.d.ts.map +1 -0
- package/dist/db/schema/steps.js +80 -0
- package/dist/db/schema/steps.js.map +1 -0
- package/dist/db/schema/workflow-run-attempts.d.ts +239 -0
- package/dist/db/schema/workflow-run-attempts.d.ts.map +1 -0
- package/dist/db/schema/workflow-run-attempts.js +53 -0
- package/dist/db/schema/workflow-run-attempts.js.map +1 -0
- package/dist/db/schema/workflow-runs.d.ts +360 -0
- package/dist/db/schema/workflow-runs.d.ts.map +1 -0
- package/dist/db/schema/workflow-runs.js +85 -0
- package/dist/db/schema/workflow-runs.js.map +1 -0
- package/dist/db/workflow-runs/job-executions.d.ts +49 -0
- package/dist/db/workflow-runs/job-executions.d.ts.map +1 -0
- package/dist/db/workflow-runs/job-executions.js +271 -0
- package/dist/db/workflow-runs/job-executions.js.map +1 -0
- package/dist/db/workflow-runs/jobs.d.ts +60 -0
- package/dist/db/workflow-runs/jobs.d.ts.map +1 -0
- package/dist/db/workflow-runs/jobs.js +288 -0
- package/dist/db/workflow-runs/jobs.js.map +1 -0
- package/dist/db/workflow-runs/outbox.d.ts +20 -0
- package/dist/db/workflow-runs/outbox.d.ts.map +1 -0
- package/dist/db/workflow-runs/outbox.js +68 -0
- package/dist/db/workflow-runs/outbox.js.map +1 -0
- package/dist/db/workflow-runs/queries.d.ts +71 -0
- package/dist/db/workflow-runs/queries.d.ts.map +1 -0
- package/dist/db/workflow-runs/queries.js +253 -0
- package/dist/db/workflow-runs/queries.js.map +1 -0
- package/dist/db/workflow-runs/run-create.d.ts +32 -0
- package/dist/db/workflow-runs/run-create.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-create.js +288 -0
- package/dist/db/workflow-runs/run-create.js.map +1 -0
- package/dist/db/workflow-runs/run-graph.d.ts +27 -0
- package/dist/db/workflow-runs/run-graph.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-graph.js +63 -0
- package/dist/db/workflow-runs/run-graph.js.map +1 -0
- package/dist/db/workflow-runs/run-rerun.d.ts +8 -0
- package/dist/db/workflow-runs/run-rerun.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-rerun.js +207 -0
- package/dist/db/workflow-runs/run-rerun.js.map +1 -0
- package/dist/db/workflow-runs/run-status.d.ts +24 -0
- package/dist/db/workflow-runs/run-status.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-status.js +249 -0
- package/dist/db/workflow-runs/run-status.js.map +1 -0
- package/dist/db/workflow-runs/runs.d.ts +7 -0
- package/dist/db/workflow-runs/runs.d.ts.map +1 -0
- package/dist/db/workflow-runs/runs.js +5 -0
- package/dist/db/workflow-runs/runs.js.map +1 -0
- package/dist/db/workflow-runs/shared.d.ts +24 -0
- package/dist/db/workflow-runs/shared.d.ts.map +1 -0
- package/dist/db/workflow-runs/shared.js +50 -0
- package/dist/db/workflow-runs/shared.js.map +1 -0
- package/dist/db/workflow-runs/steps.d.ts +83 -0
- package/dist/db/workflow-runs/steps.d.ts.map +1 -0
- package/dist/db/workflow-runs/steps.js +246 -0
- package/dist/db/workflow-runs/steps.js.map +1 -0
- package/dist/db/workflow-runs.d.ts +12 -0
- package/dist/db/workflow-runs.d.ts.map +1 -0
- package/dist/db/workflow-runs.js +8 -0
- package/dist/db/workflow-runs.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +20 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +127 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/metrics/service.d.ts +2 -0
- package/dist/metrics/service.d.ts.map +1 -0
- package/dist/metrics/service.js +30 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/dto/checkout-token.d.ts +6 -0
- package/dist/presentation/dto/checkout-token.d.ts.map +1 -0
- package/dist/presentation/dto/checkout-token.js +74 -0
- package/dist/presentation/dto/checkout-token.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +4 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +5 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/dto/job.d.ts +6 -0
- package/dist/presentation/dto/job.d.ts.map +1 -0
- package/dist/presentation/dto/job.js +59 -0
- package/dist/presentation/dto/job.js.map +1 -0
- package/dist/presentation/dto/step.d.ts +6 -0
- package/dist/presentation/dto/step.d.ts.map +1 -0
- package/dist/presentation/dto/step.js +162 -0
- package/dist/presentation/dto/step.js.map +1 -0
- package/dist/presentation/dto/workflow-run.d.ts +6 -0
- package/dist/presentation/dto/workflow-run.d.ts.map +1 -0
- package/dist/presentation/dto/workflow-run.js +35 -0
- package/dist/presentation/dto/workflow-run.js.map +1 -0
- package/dist/presentation/index.d.ts +3 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +4 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/agent-runtime-config.d.ts +2 -0
- package/dist/presentation/routes/agent-runtime-config.d.ts.map +1 -0
- package/dist/presentation/routes/agent-runtime-config.js +71 -0
- package/dist/presentation/routes/agent-runtime-config.js.map +1 -0
- package/dist/presentation/routes/cancel-run.d.ts +2 -0
- package/dist/presentation/routes/cancel-run.d.ts.map +1 -0
- package/dist/presentation/routes/cancel-run.js +46 -0
- package/dist/presentation/routes/cancel-run.js.map +1 -0
- package/dist/presentation/routes/checkout-token.d.ts +2 -0
- package/dist/presentation/routes/checkout-token.d.ts.map +1 -0
- package/dist/presentation/routes/checkout-token.js +64 -0
- package/dist/presentation/routes/checkout-token.js.map +1 -0
- package/dist/presentation/routes/get-run-aggregates.d.ts +2 -0
- package/dist/presentation/routes/get-run-aggregates.d.ts.map +1 -0
- package/dist/presentation/routes/get-run-aggregates.js +60 -0
- package/dist/presentation/routes/get-run-aggregates.js.map +1 -0
- package/dist/presentation/routes/get-run.d.ts +2 -0
- package/dist/presentation/routes/get-run.d.ts.map +1 -0
- package/dist/presentation/routes/get-run.js +60 -0
- package/dist/presentation/routes/get-run.js.map +1 -0
- package/dist/presentation/routes/get-step-secrets.d.ts +2 -0
- package/dist/presentation/routes/get-step-secrets.d.ts.map +1 -0
- package/dist/presentation/routes/get-step-secrets.js +115 -0
- package/dist/presentation/routes/get-step-secrets.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +4 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +41 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/leased-step.d.ts +14 -0
- package/dist/presentation/routes/leased-step.d.ts.map +1 -0
- package/dist/presentation/routes/leased-step.js +50 -0
- package/dist/presentation/routes/leased-step.js.map +1 -0
- package/dist/presentation/routes/list-run-attempts.d.ts +2 -0
- package/dist/presentation/routes/list-run-attempts.d.ts.map +1 -0
- package/dist/presentation/routes/list-run-attempts.js +35 -0
- package/dist/presentation/routes/list-run-attempts.js.map +1 -0
- package/dist/presentation/routes/list-runs.d.ts +2 -0
- package/dist/presentation/routes/list-runs.d.ts.map +1 -0
- package/dist/presentation/routes/list-runs.js +70 -0
- package/dist/presentation/routes/list-runs.js.map +1 -0
- package/dist/presentation/routes/next-step.d.ts +2 -0
- package/dist/presentation/routes/next-step.d.ts.map +1 -0
- package/dist/presentation/routes/next-step.js +65 -0
- package/dist/presentation/routes/next-step.js.map +1 -0
- package/dist/presentation/routes/report-step.d.ts +2 -0
- package/dist/presentation/routes/report-step.d.ts.map +1 -0
- package/dist/presentation/routes/report-step.js +73 -0
- package/dist/presentation/routes/report-step.js.map +1 -0
- package/dist/presentation/routes/require-accessible-run.d.ts +7 -0
- package/dist/presentation/routes/require-accessible-run.d.ts.map +1 -0
- package/dist/presentation/routes/require-accessible-run.js +25 -0
- package/dist/presentation/routes/require-accessible-run.js.map +1 -0
- package/dist/presentation/routes/rerun-run.d.ts +2 -0
- package/dist/presentation/routes/rerun-run.d.ts.map +1 -0
- package/dist/presentation/routes/rerun-run.js +56 -0
- package/dist/presentation/routes/rerun-run.js.map +1 -0
- package/dist/presentation/subscribers/index.d.ts +8 -0
- package/dist/presentation/subscribers/index.d.ts.map +1 -0
- package/dist/presentation/subscribers/index.js +9 -0
- package/dist/presentation/subscribers/index.js.map +1 -0
- package/dist/presentation/subscribers/on-job-event-delivered.d.ts +3 -0
- package/dist/presentation/subscribers/on-job-event-delivered.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-job-event-delivered.js +24 -0
- package/dist/presentation/subscribers/on-job-event-delivered.js.map +1 -0
- package/dist/presentation/subscribers/on-job-steps-settled.d.ts +3 -0
- package/dist/presentation/subscribers/on-job-steps-settled.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-job-steps-settled.js +36 -0
- package/dist/presentation/subscribers/on-job-steps-settled.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js +20 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.js +35 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-queued.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-queued.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-queued.js +20 -0
- package/dist/presentation/subscribers/on-runner-job-queued.js.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.js +35 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.js.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.js +25 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +23 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +26 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/orchestration-activities.d.ts +130 -0
- package/dist/temporal/activities/orchestration-activities.d.ts.map +1 -0
- package/dist/temporal/activities/orchestration-activities.js +188 -0
- package/dist/temporal/activities/orchestration-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +7 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +8 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/index.d.ts +3 -0
- package/dist/temporal/index.d.ts.map +1 -0
- package/dist/temporal/index.js +4 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/temporal/workflow-not-found.d.ts +2 -0
- package/dist/temporal/workflow-not-found.d.ts.map +1 -0
- package/dist/temporal/workflow-not-found.js +10 -0
- package/dist/temporal/workflow-not-found.js.map +1 -0
- package/dist/temporal/workflows/deadline.d.ts +3 -0
- package/dist/temporal/workflows/deadline.d.ts.map +1 -0
- package/dist/temporal/workflows/deadline.js +8 -0
- package/dist/temporal/workflows/deadline.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +4 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +5 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts +27 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/job-execution-orchestration.js +265 -0
- package/dist/temporal/workflows/job-execution-orchestration.js.map +1 -0
- package/dist/temporal/workflows/job-listener-orchestration.d.ts +40 -0
- package/dist/temporal/workflows/job-listener-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/job-listener-orchestration.js +332 -0
- package/dist/temporal/workflows/job-listener-orchestration.js.map +1 -0
- package/dist/temporal/workflows/run-orchestration.d.ts +8 -0
- package/dist/temporal/workflows/run-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/run-orchestration.js +243 -0
- package/dist/temporal/workflows/run-orchestration.js.map +1 -0
- package/dist/temporal/workflows/test-env.d.ts +114 -0
- package/dist/temporal/workflows/test-env.d.ts.map +1 -0
- package/dist/temporal/workflows/test-env.js +323 -0
- package/dist/temporal/workflows/test-env.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +211 -0
- package/drizzle/0001_agent_tool_materialization.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +1613 -0
- package/drizzle/meta/_journal.json +20 -0
- package/drizzle.config.ts +7 -0
- package/package.json +91 -0
- package/src/core/README.md +79 -0
- package/src/core/agent-tool-capability-warning.test.ts +280 -0
- package/src/core/agent-tool-capability-warning.ts +200 -0
- package/src/core/agent-tools.ts +422 -0
- package/src/core/checkout.test.ts +112 -0
- package/src/core/checkout.ts +63 -0
- package/src/core/condition-trace.ts +64 -0
- package/src/core/entities/index.ts +9 -0
- package/src/core/entities/job-execution.ts +32 -0
- package/src/core/entities/job-listener-event.ts +15 -0
- package/src/core/entities/job.ts +91 -0
- package/src/core/entities/step.ts +126 -0
- package/src/core/entities/workflow-run-attempt.ts +21 -0
- package/src/core/entities/workflow-run.ts +94 -0
- package/src/core/errors.test.ts +45 -0
- package/src/core/errors.ts +209 -0
- package/src/core/index.ts +54 -0
- package/src/core/job-execution-outcome.ts +64 -0
- package/src/core/job-execution.test.ts +1560 -0
- package/src/core/job-execution.ts +581 -0
- package/src/core/job-transition/decide-job-activation.test.ts +196 -0
- package/src/core/job-transition/decide-job-activation.ts +79 -0
- package/src/core/job-transition/derive-job-execution-outputs.ts +41 -0
- package/src/core/job-transition/derive-job-success.test.ts +133 -0
- package/src/core/job-transition/derive-job-success.ts +67 -0
- package/src/core/job-transition/index.ts +11 -0
- package/src/core/job-transition/runtime-completion-status-for-job.ts +14 -0
- package/src/core/listener-execution-materialization.test.ts +49 -0
- package/src/core/listener-execution-materialization.ts +162 -0
- package/src/core/run-workflow.test.ts +229 -0
- package/src/core/run-workflow.ts +41 -0
- package/src/core/source-control.test.ts +17 -0
- package/src/core/source-control.ts +22 -0
- package/src/core/step-config/agent.ts +459 -0
- package/src/core/step-config/assemble-run-context.test.ts +1021 -0
- package/src/core/step-config/assemble-run-context.ts +535 -0
- package/src/core/step-config/complete-step-dispatch-config.test.ts +354 -0
- package/src/core/step-config/complete-step-dispatch-config.ts +40 -0
- package/src/core/step-config/fields.ts +111 -0
- package/src/core/step-config/index.ts +41 -0
- package/src/core/step-config/materialize-job-execution-steps.test.ts +494 -0
- package/src/core/step-config/materialize-job-execution-steps.ts +136 -0
- package/src/core/step-config/materialize-workflow-model.test.ts +1214 -0
- package/src/core/step-config/materialize-workflow-model.ts +140 -0
- package/src/core/step-config/resolve-job-execution-name.test.ts +94 -0
- package/src/core/step-config/resolve-job-execution-name.ts +51 -0
- package/src/core/step-config/resolve-step-config.ts +199 -0
- package/src/core/step-config/run.ts +467 -0
- package/src/core/step-config/workflow-evaluation-context.ts +6 -0
- package/src/core/step-transition/apply-step-transition.ts +163 -0
- package/src/core/step-transition/decide-step-transition.test.ts +307 -0
- package/src/core/step-transition/decide-step-transition.ts +200 -0
- package/src/core/step-transition/evaluate-gate.test.ts +317 -0
- package/src/core/step-transition/evaluate-gate.ts +168 -0
- package/src/core/step-transition/read-step-outputs.ts +27 -0
- package/src/core/workflow-run-creation.test.ts +155 -0
- package/src/core/workflow-run-creation.ts +131 -0
- package/src/core/workflow-scheduling/index.ts +15 -0
- package/src/core/workflow-scheduling/run-progress.test.ts +46 -0
- package/src/core/workflow-scheduling/run-progress.ts +68 -0
- package/src/core/workflow-scheduling/runtime-dag.ts +10 -0
- package/src/core/workflow-scheduling/runtime-scheduling-command.ts +20 -0
- package/src/core/workflow-scheduling/schedule-runtime-dag.test.ts +197 -0
- package/src/core/workflow-scheduling/schedule-runtime-dag.ts +115 -0
- package/src/db/db.ts +40 -0
- package/src/db/index.ts +86 -0
- package/src/db/job-listener-events.test.ts +113 -0
- package/src/db/job-listener-events.ts +73 -0
- package/src/db/job-listeners.test.ts +865 -0
- package/src/db/job-listeners.ts +564 -0
- package/src/db/outbox-writes.ts +40 -0
- package/src/db/rerun-listener.test.ts +64 -0
- package/src/db/run-timeout.test.ts +102 -0
- package/src/db/runner-lease-table.ts +39 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/job-executions.ts +85 -0
- package/src/db/schema/job-listener-events.ts +58 -0
- package/src/db/schema/jobs.ts +136 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/step-attempts.ts +99 -0
- package/src/db/schema/steps.ts +99 -0
- package/src/db/schema/workflow-run-attempts.ts +59 -0
- package/src/db/schema/workflow-runs.ts +112 -0
- package/src/db/workflow-runs/job-executions.test.ts +99 -0
- package/src/db/workflow-runs/job-executions.ts +421 -0
- package/src/db/workflow-runs/job-status.test.ts +532 -0
- package/src/db/workflow-runs/jobs.test.ts +194 -0
- package/src/db/workflow-runs/jobs.ts +418 -0
- package/src/db/workflow-runs/outbox.ts +109 -0
- package/src/db/workflow-runs/queries.test.ts +256 -0
- package/src/db/workflow-runs/queries.ts +437 -0
- package/src/db/workflow-runs/run-create.test.ts +1281 -0
- package/src/db/workflow-runs/run-create.ts +373 -0
- package/src/db/workflow-runs/run-graph.ts +95 -0
- package/src/db/workflow-runs/run-rerun.test.ts +625 -0
- package/src/db/workflow-runs/run-rerun.ts +266 -0
- package/src/db/workflow-runs/run-status.test.ts +425 -0
- package/src/db/workflow-runs/run-status.ts +391 -0
- package/src/db/workflow-runs/runs.ts +17 -0
- package/src/db/workflow-runs/shared.ts +84 -0
- package/src/db/workflow-runs/steps.test.ts +191 -0
- package/src/db/workflow-runs/steps.ts +476 -0
- package/src/db/workflow-runs.ts +111 -0
- package/src/index.ts +99 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.ts +160 -0
- package/src/metrics/service.ts +30 -0
- package/src/presentation/dto/checkout-token.test.ts +107 -0
- package/src/presentation/dto/checkout-token.ts +85 -0
- package/src/presentation/dto/index.ts +3 -0
- package/src/presentation/dto/job.test.ts +108 -0
- package/src/presentation/dto/job.ts +64 -0
- package/src/presentation/dto/step.test.ts +307 -0
- package/src/presentation/dto/step.ts +145 -0
- package/src/presentation/dto/workflow-run.ts +38 -0
- package/src/presentation/index.ts +10 -0
- package/src/presentation/routes/agent-runtime-config.test.ts +478 -0
- package/src/presentation/routes/agent-runtime-config.ts +81 -0
- package/src/presentation/routes/cancel-run.test.ts +156 -0
- package/src/presentation/routes/cancel-run.ts +37 -0
- package/src/presentation/routes/checkout-token.test.ts +366 -0
- package/src/presentation/routes/checkout-token.ts +61 -0
- package/src/presentation/routes/get-run-aggregates.test.ts +114 -0
- package/src/presentation/routes/get-run-aggregates.ts +69 -0
- package/src/presentation/routes/get-run.test.ts +604 -0
- package/src/presentation/routes/get-run.ts +66 -0
- package/src/presentation/routes/get-step-secrets.test.ts +260 -0
- package/src/presentation/routes/get-step-secrets.ts +117 -0
- package/src/presentation/routes/index.test.ts +71 -0
- package/src/presentation/routes/index.ts +42 -0
- package/src/presentation/routes/leased-step.ts +54 -0
- package/src/presentation/routes/list-run-attempts.test.ts +163 -0
- package/src/presentation/routes/list-run-attempts.ts +27 -0
- package/src/presentation/routes/list-runs.test.ts +244 -0
- package/src/presentation/routes/list-runs.ts +83 -0
- package/src/presentation/routes/next-step.test.ts +366 -0
- package/src/presentation/routes/next-step.ts +62 -0
- package/src/presentation/routes/report-step.test.ts +374 -0
- package/src/presentation/routes/report-step.ts +61 -0
- package/src/presentation/routes/require-accessible-run.ts +27 -0
- package/src/presentation/routes/rerun-run.test.ts +202 -0
- package/src/presentation/routes/rerun-run.ts +48 -0
- package/src/presentation/subscribers/index.ts +7 -0
- package/src/presentation/subscribers/on-job-event-delivered.test.ts +71 -0
- package/src/presentation/subscribers/on-job-event-delivered.ts +30 -0
- package/src/presentation/subscribers/on-job-steps-settled.test.ts +75 -0
- package/src/presentation/subscribers/on-job-steps-settled.ts +42 -0
- package/src/presentation/subscribers/on-runner-job-claimed.test.ts +57 -0
- package/src/presentation/subscribers/on-runner-job-claimed.ts +23 -0
- package/src/presentation/subscribers/on-runner-job-lease-expired.test.ts +73 -0
- package/src/presentation/subscribers/on-runner-job-lease-expired.ts +36 -0
- package/src/presentation/subscribers/on-runner-job-queued.test.ts +57 -0
- package/src/presentation/subscribers/on-runner-job-queued.ts +23 -0
- package/src/presentation/subscribers/on-workflow-run-attempt-created.test.ts +69 -0
- package/src/presentation/subscribers/on-workflow-run-attempt-created.ts +40 -0
- package/src/presentation/subscribers/on-workflow-run-cancelled.test.ts +59 -0
- package/src/presentation/subscribers/on-workflow-run-cancelled.ts +29 -0
- package/src/temporal/activities/index.ts +45 -0
- package/src/temporal/activities/orchestration-activities.test.ts +115 -0
- package/src/temporal/activities/orchestration-activities.ts +305 -0
- package/src/temporal/constants.ts +6 -0
- package/src/temporal/index.ts +6 -0
- package/src/temporal/workflow-not-found.ts +9 -0
- package/src/temporal/workflows/deadline.ts +7 -0
- package/src/temporal/workflows/index.ts +11 -0
- package/src/temporal/workflows/job-execution-orchestration-timeout.test.ts +165 -0
- package/src/temporal/workflows/job-execution-orchestration.test.ts +311 -0
- package/src/temporal/workflows/job-execution-orchestration.ts +314 -0
- package/src/temporal/workflows/job-listener-orchestration-continuation.test.ts +93 -0
- package/src/temporal/workflows/job-listener-orchestration.test.ts +406 -0
- package/src/temporal/workflows/job-listener-orchestration.ts +490 -0
- package/src/temporal/workflows/run-orchestration.test.ts +409 -0
- package/src/temporal/workflows/run-orchestration.ts +283 -0
- package/src/temporal/workflows/test-env.ts +409 -0
- package/test/env.ts +11 -0
- package/test/factories/job.ts +83 -0
- package/test/factories/project.ts +16 -0
- package/test/factories/workflow-model.test.ts +26 -0
- package/test/factories/workflow-model.ts +268 -0
- package/test/factories/workflow-run.ts +58 -0
- package/test/fixtures/active-lease-token.ts +85 -0
- package/test/fixtures/job-with-steps.ts +42 -0
- package/test/fixtures/lease-token.ts +44 -0
- package/test/fixtures/strip-setup-step.ts +23 -0
- package/test/globalSetup.ts +54 -0
- package/test/helpers/workflow-runs.ts +210 -0
- package/test/index.ts +3 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WORKFLOWS_WORKFLOW_RUN_CANCELLED,
|
|
3
|
+
WORKFLOWS_WORKFLOW_RUN_TERMINATED,
|
|
4
|
+
} from '@shipfox/api-workflows-dto';
|
|
5
|
+
import {and, asc, eq, inArray, notInArray, sql} from 'drizzle-orm';
|
|
6
|
+
import {isJobTerminal, type Job, type JobStatusReason} from '#core/entities/job.js';
|
|
7
|
+
import {
|
|
8
|
+
isWorkflowRunTerminal,
|
|
9
|
+
type WorkflowRun,
|
|
10
|
+
type WorkflowRunStatus,
|
|
11
|
+
} from '#core/entities/workflow-run.js';
|
|
12
|
+
import {WorkflowRunNotCancellableError, WorkflowRunNotFoundError} from '#core/errors.js';
|
|
13
|
+
import {recordWorkflowJobStatusChanged, recordWorkflowRunStatusChanged} from '#metrics/instance.js';
|
|
14
|
+
import {db, type Tx} from '../db.js';
|
|
15
|
+
import {writeWorkflowsOutboxEvent} from '../outbox-writes.js';
|
|
16
|
+
import {jobExecutions} from '../schema/job-executions.js';
|
|
17
|
+
import {jobs} from '../schema/jobs.js';
|
|
18
|
+
import {steps} from '../schema/steps.js';
|
|
19
|
+
import {workflowRunAttempts} from '../schema/workflow-run-attempts.js';
|
|
20
|
+
import {toWorkflowRun, workflowRuns} from '../schema/workflow-runs.js';
|
|
21
|
+
import {updateJobStatusAtVersion} from './jobs.js';
|
|
22
|
+
import {
|
|
23
|
+
lockWorkflowRun,
|
|
24
|
+
TERMINAL_EXECUTION_STATUSES,
|
|
25
|
+
TERMINAL_WORKFLOW_RUN_STATUSES,
|
|
26
|
+
} from './shared.js';
|
|
27
|
+
import {bulkUpdateStepStatuses} from './steps.js';
|
|
28
|
+
|
|
29
|
+
export interface CancelWorkflowRunParams {
|
|
30
|
+
workflowRunId: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FailWorkflowRunAsTimedOutParams {
|
|
34
|
+
runAttemptId: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface RunTerminationSpec {
|
|
38
|
+
terminalStatus: Extract<WorkflowRunStatus, 'failed' | 'cancelled'>;
|
|
39
|
+
statusReason: Extract<JobStatusReason, 'timed_out' | 'run_cancelled'>;
|
|
40
|
+
markExecutionTimedOut: boolean;
|
|
41
|
+
emitCancelledEvent: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Shared terminal transition for a run attempt. The caller locks the run and the
|
|
46
|
+
* attempt (and decides how an already-terminal run is handled: timeout returns
|
|
47
|
+
* idempotently, cancellation rejects), then this drives every non-terminal job,
|
|
48
|
+
* execution, and step to `spec.terminalStatus`, resolves still-listening jobs,
|
|
49
|
+
* flips the attempt and run, and writes the outbox. Callers record metrics after
|
|
50
|
+
* the transaction commits.
|
|
51
|
+
*/
|
|
52
|
+
async function terminateRunAttempt(
|
|
53
|
+
tx: Tx,
|
|
54
|
+
params: {
|
|
55
|
+
lockedRun: typeof workflowRuns.$inferSelect;
|
|
56
|
+
lockedAttempt: typeof workflowRunAttempts.$inferSelect;
|
|
57
|
+
spec: RunTerminationSpec;
|
|
58
|
+
},
|
|
59
|
+
): Promise<{run: WorkflowRun; changedJobs: Job[]}> {
|
|
60
|
+
const {lockedRun, lockedAttempt, spec} = params;
|
|
61
|
+
|
|
62
|
+
const runJobExecutionIds = tx
|
|
63
|
+
.select({id: jobExecutions.id})
|
|
64
|
+
.from(jobExecutions)
|
|
65
|
+
.innerJoin(jobs, eq(jobExecutions.jobId, jobs.id))
|
|
66
|
+
.where(eq(jobs.workflowRunAttemptId, lockedAttempt.id));
|
|
67
|
+
|
|
68
|
+
await tx
|
|
69
|
+
.select({id: steps.id})
|
|
70
|
+
.from(steps)
|
|
71
|
+
.where(inArray(steps.jobExecutionId, runJobExecutionIds))
|
|
72
|
+
.orderBy(asc(steps.jobExecutionId), asc(steps.position))
|
|
73
|
+
.for('update');
|
|
74
|
+
|
|
75
|
+
const jobRows = await tx
|
|
76
|
+
.select()
|
|
77
|
+
.from(jobs)
|
|
78
|
+
.where(eq(jobs.workflowRunAttemptId, lockedAttempt.id))
|
|
79
|
+
.orderBy(asc(jobs.position), asc(jobs.id))
|
|
80
|
+
.for('update');
|
|
81
|
+
|
|
82
|
+
const changedJobs: Job[] = [];
|
|
83
|
+
for (const jobRow of jobRows) {
|
|
84
|
+
if (isJobTerminal(jobRow.status)) continue;
|
|
85
|
+
|
|
86
|
+
const updated = await updateJobStatusAtVersion(tx, {
|
|
87
|
+
jobId: jobRow.id,
|
|
88
|
+
status: spec.terminalStatus,
|
|
89
|
+
expectedVersion: jobRow.version,
|
|
90
|
+
statusReason: spec.statusReason,
|
|
91
|
+
});
|
|
92
|
+
if (updated?.changed) changedJobs.push(updated.job);
|
|
93
|
+
|
|
94
|
+
if (jobRow.mode === 'listening') {
|
|
95
|
+
await tx
|
|
96
|
+
.update(jobs)
|
|
97
|
+
.set({listenerStatus: 'resolved', resolutionReason: 'cancelled', updatedAt: new Date()})
|
|
98
|
+
.where(eq(jobs.id, jobRow.id));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const terminatedExecutions = await tx
|
|
102
|
+
.update(jobExecutions)
|
|
103
|
+
.set({
|
|
104
|
+
status: spec.terminalStatus,
|
|
105
|
+
statusReason: spec.statusReason,
|
|
106
|
+
version: sql`${jobExecutions.version} + 1`,
|
|
107
|
+
updatedAt: new Date(),
|
|
108
|
+
finishedAt: sql`now()`,
|
|
109
|
+
...(spec.markExecutionTimedOut ? {timedOutAt: sql`now()`} : {}),
|
|
110
|
+
})
|
|
111
|
+
.where(
|
|
112
|
+
and(
|
|
113
|
+
eq(jobExecutions.jobId, jobRow.id),
|
|
114
|
+
notInArray(jobExecutions.status, TERMINAL_EXECUTION_STATUSES),
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
.returning({id: jobExecutions.id});
|
|
118
|
+
for (const jobExecution of terminatedExecutions) {
|
|
119
|
+
await bulkUpdateStepStatuses(
|
|
120
|
+
{jobExecutionId: jobExecution.id, status: spec.terminalStatus},
|
|
121
|
+
tx,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
await tx
|
|
127
|
+
.update(workflowRunAttempts)
|
|
128
|
+
.set({
|
|
129
|
+
status: spec.terminalStatus,
|
|
130
|
+
version: sql`${workflowRunAttempts.version} + 1`,
|
|
131
|
+
updatedAt: new Date(),
|
|
132
|
+
finishedAt: sql`now()`,
|
|
133
|
+
})
|
|
134
|
+
.where(
|
|
135
|
+
and(
|
|
136
|
+
eq(workflowRunAttempts.id, lockedAttempt.id),
|
|
137
|
+
notInArray(workflowRunAttempts.status, TERMINAL_WORKFLOW_RUN_STATUSES),
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const [terminatedRunRow] = await tx
|
|
142
|
+
.update(workflowRuns)
|
|
143
|
+
.set({
|
|
144
|
+
status: spec.terminalStatus,
|
|
145
|
+
version: sql`${workflowRuns.version} + 1`,
|
|
146
|
+
updatedAt: new Date(),
|
|
147
|
+
finishedAt: sql`now()`,
|
|
148
|
+
})
|
|
149
|
+
.where(
|
|
150
|
+
and(
|
|
151
|
+
eq(workflowRuns.id, lockedRun.id),
|
|
152
|
+
notInArray(workflowRuns.status, TERMINAL_WORKFLOW_RUN_STATUSES),
|
|
153
|
+
),
|
|
154
|
+
)
|
|
155
|
+
.returning();
|
|
156
|
+
|
|
157
|
+
const run = toWorkflowRun(terminatedRunRow ?? lockedRun);
|
|
158
|
+
await writeWorkflowsOutboxEvent(tx, {
|
|
159
|
+
type: WORKFLOWS_WORKFLOW_RUN_TERMINATED,
|
|
160
|
+
payload: {
|
|
161
|
+
workflowRunId: run.id,
|
|
162
|
+
workflowRunAttemptId: lockedAttempt.id,
|
|
163
|
+
projectId: run.projectId,
|
|
164
|
+
status: spec.terminalStatus,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
if (spec.emitCancelledEvent) {
|
|
168
|
+
await writeWorkflowsOutboxEvent(tx, {
|
|
169
|
+
type: WORKFLOWS_WORKFLOW_RUN_CANCELLED,
|
|
170
|
+
payload: {
|
|
171
|
+
workflowRunId: run.id,
|
|
172
|
+
workflowRunAttemptId: lockedAttempt.id,
|
|
173
|
+
projectId: run.projectId,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {run, changedJobs};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function failWorkflowRunAsTimedOut(
|
|
182
|
+
params: FailWorkflowRunAsTimedOutParams,
|
|
183
|
+
): Promise<WorkflowRun> {
|
|
184
|
+
const result = await db().transaction(async (tx) => {
|
|
185
|
+
const [lockedAttempt] = await tx
|
|
186
|
+
.select()
|
|
187
|
+
.from(workflowRunAttempts)
|
|
188
|
+
.where(eq(workflowRunAttempts.id, params.runAttemptId))
|
|
189
|
+
.limit(1)
|
|
190
|
+
.for('update');
|
|
191
|
+
if (!lockedAttempt) throw new WorkflowRunNotFoundError(params.runAttemptId);
|
|
192
|
+
|
|
193
|
+
const lockedRun = await lockWorkflowRun(lockedAttempt.workflowRunId, tx);
|
|
194
|
+
if (!lockedRun) throw new WorkflowRunNotFoundError(lockedAttempt.workflowRunId);
|
|
195
|
+
if (isWorkflowRunTerminal(lockedRun.status)) {
|
|
196
|
+
return {run: toWorkflowRun(lockedRun), changedJobs: [], changed: false};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const result = await terminateRunAttempt(tx, {
|
|
200
|
+
lockedRun,
|
|
201
|
+
lockedAttempt,
|
|
202
|
+
spec: {
|
|
203
|
+
terminalStatus: 'failed',
|
|
204
|
+
statusReason: 'timed_out',
|
|
205
|
+
markExecutionTimedOut: true,
|
|
206
|
+
emitCancelledEvent: false,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
return {...result, changed: true};
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
if (result.changed) recordWorkflowRunStatusChanged(result.run.status);
|
|
213
|
+
for (const job of result.changedJobs) recordWorkflowJobStatusChanged(job.status);
|
|
214
|
+
return result.run;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export async function cancelWorkflowRun(params: CancelWorkflowRunParams): Promise<WorkflowRun> {
|
|
218
|
+
const result = await db().transaction(async (tx) => {
|
|
219
|
+
const lockedRun = await lockWorkflowRun(params.workflowRunId, tx);
|
|
220
|
+
|
|
221
|
+
if (!lockedRun) {
|
|
222
|
+
throw new WorkflowRunNotFoundError(params.workflowRunId);
|
|
223
|
+
}
|
|
224
|
+
if (isWorkflowRunTerminal(lockedRun.status)) {
|
|
225
|
+
throw new WorkflowRunNotCancellableError(lockedRun.id, lockedRun.status);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const [lockedAttempt] = await tx
|
|
229
|
+
.select()
|
|
230
|
+
.from(workflowRunAttempts)
|
|
231
|
+
.where(
|
|
232
|
+
and(
|
|
233
|
+
eq(workflowRunAttempts.workflowRunId, lockedRun.id),
|
|
234
|
+
eq(workflowRunAttempts.attempt, lockedRun.currentAttempt),
|
|
235
|
+
),
|
|
236
|
+
)
|
|
237
|
+
.limit(1)
|
|
238
|
+
.for('update');
|
|
239
|
+
if (!lockedAttempt) {
|
|
240
|
+
throw new Error(
|
|
241
|
+
`Current attempt ${lockedRun.currentAttempt} missing for run ${lockedRun.id}`,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return terminateRunAttempt(tx, {
|
|
246
|
+
lockedRun,
|
|
247
|
+
lockedAttempt,
|
|
248
|
+
spec: {
|
|
249
|
+
terminalStatus: 'cancelled',
|
|
250
|
+
statusReason: 'run_cancelled',
|
|
251
|
+
markExecutionTimedOut: false,
|
|
252
|
+
emitCancelledEvent: true,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
recordWorkflowRunStatusChanged(result.run.status);
|
|
258
|
+
for (const job of result.changedJobs) recordWorkflowJobStatusChanged(job.status);
|
|
259
|
+
|
|
260
|
+
return result.run;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface UpdateWorkflowRunStatusParams {
|
|
264
|
+
workflowRunId?: string;
|
|
265
|
+
workflowRunAttemptId?: string;
|
|
266
|
+
status: WorkflowRunStatus;
|
|
267
|
+
expectedVersion: number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export async function updateWorkflowRunStatus(
|
|
271
|
+
params: UpdateWorkflowRunStatusParams,
|
|
272
|
+
): Promise<WorkflowRun> {
|
|
273
|
+
const result = await db().transaction(async (tx) => {
|
|
274
|
+
const [attemptRef] = params.workflowRunAttemptId
|
|
275
|
+
? await tx
|
|
276
|
+
.select({
|
|
277
|
+
id: workflowRunAttempts.id,
|
|
278
|
+
workflowRunId: workflowRunAttempts.workflowRunId,
|
|
279
|
+
})
|
|
280
|
+
.from(workflowRunAttempts)
|
|
281
|
+
.where(eq(workflowRunAttempts.id, params.workflowRunAttemptId))
|
|
282
|
+
.limit(1)
|
|
283
|
+
: [];
|
|
284
|
+
|
|
285
|
+
const workflowRunId = attemptRef?.workflowRunId ?? params.workflowRunId ?? '';
|
|
286
|
+
const lockedRun = await lockWorkflowRun(workflowRunId, tx);
|
|
287
|
+
|
|
288
|
+
if (!lockedRun) {
|
|
289
|
+
throw new WorkflowRunNotFoundError(params.workflowRunId ?? params.workflowRunAttemptId ?? '');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const [lockedAttempt] = await tx
|
|
293
|
+
.select()
|
|
294
|
+
.from(workflowRunAttempts)
|
|
295
|
+
.where(
|
|
296
|
+
params.workflowRunAttemptId
|
|
297
|
+
? eq(workflowRunAttempts.id, params.workflowRunAttemptId)
|
|
298
|
+
: and(
|
|
299
|
+
eq(workflowRunAttempts.workflowRunId, lockedRun.id),
|
|
300
|
+
eq(workflowRunAttempts.attempt, lockedRun.currentAttempt),
|
|
301
|
+
),
|
|
302
|
+
)
|
|
303
|
+
.limit(1)
|
|
304
|
+
.for('update');
|
|
305
|
+
|
|
306
|
+
if (!lockedAttempt) {
|
|
307
|
+
throw new WorkflowRunNotFoundError(params.workflowRunId ?? params.workflowRunAttemptId ?? '');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const target = {run: lockedRun, attempt: lockedAttempt};
|
|
311
|
+
|
|
312
|
+
const rows = await tx
|
|
313
|
+
.update(workflowRunAttempts)
|
|
314
|
+
.set({
|
|
315
|
+
status: params.status,
|
|
316
|
+
version: sql`${workflowRunAttempts.version} + 1`,
|
|
317
|
+
updatedAt: new Date(),
|
|
318
|
+
...(params.status === 'running'
|
|
319
|
+
? {startedAt: sql`coalesce(${workflowRunAttempts.startedAt}, now())`}
|
|
320
|
+
: {}),
|
|
321
|
+
...(isWorkflowRunTerminal(params.status) ? {finishedAt: sql`now()`} : {}),
|
|
322
|
+
})
|
|
323
|
+
.where(
|
|
324
|
+
and(
|
|
325
|
+
eq(workflowRunAttempts.id, target.attempt.id),
|
|
326
|
+
eq(workflowRunAttempts.version, params.expectedVersion),
|
|
327
|
+
notInArray(workflowRunAttempts.status, TERMINAL_WORKFLOW_RUN_STATUSES),
|
|
328
|
+
),
|
|
329
|
+
)
|
|
330
|
+
.returning();
|
|
331
|
+
|
|
332
|
+
const attemptRow = rows[0];
|
|
333
|
+
if (!attemptRow) {
|
|
334
|
+
const existing = await tx
|
|
335
|
+
.select()
|
|
336
|
+
.from(workflowRunAttempts)
|
|
337
|
+
.where(eq(workflowRunAttempts.id, target.attempt.id))
|
|
338
|
+
.limit(1);
|
|
339
|
+
const existingRow = existing[0];
|
|
340
|
+
if (
|
|
341
|
+
existingRow &&
|
|
342
|
+
(existingRow.status === params.status || isWorkflowRunTerminal(existingRow.status))
|
|
343
|
+
) {
|
|
344
|
+
return {
|
|
345
|
+
run: {...toWorkflowRun(target.run), version: existingRow.version},
|
|
346
|
+
changed: false,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Optimistic lock failure: run attempt ${target.attempt.id} version ${params.expectedVersion}`,
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const shouldMirror = target.run.currentAttempt === attemptRow.attempt;
|
|
355
|
+
const [runRow] = shouldMirror
|
|
356
|
+
? await tx
|
|
357
|
+
.update(workflowRuns)
|
|
358
|
+
.set({
|
|
359
|
+
status: params.status,
|
|
360
|
+
version: sql`${workflowRuns.version} + 1`,
|
|
361
|
+
updatedAt: new Date(),
|
|
362
|
+
...(params.status === 'running'
|
|
363
|
+
? {startedAt: sql`coalesce(${workflowRuns.startedAt}, now())`}
|
|
364
|
+
: {}),
|
|
365
|
+
...(isWorkflowRunTerminal(params.status) ? {finishedAt: sql`now()`} : {}),
|
|
366
|
+
})
|
|
367
|
+
.where(eq(workflowRuns.id, target.run.id))
|
|
368
|
+
.returning()
|
|
369
|
+
: [target.run];
|
|
370
|
+
|
|
371
|
+
const run = {...toWorkflowRun(runRow ?? target.run), version: attemptRow.version};
|
|
372
|
+
|
|
373
|
+
if (shouldMirror && isWorkflowRunTerminal(run.status)) {
|
|
374
|
+
await writeWorkflowsOutboxEvent(tx, {
|
|
375
|
+
type: WORKFLOWS_WORKFLOW_RUN_TERMINATED,
|
|
376
|
+
payload: {
|
|
377
|
+
workflowRunId: run.id,
|
|
378
|
+
workflowRunAttemptId: attemptRow.id,
|
|
379
|
+
projectId: run.projectId,
|
|
380
|
+
status: run.status,
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return {run, changed: true};
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
if (result.changed) recordWorkflowRunStatusChanged(result.run.status);
|
|
389
|
+
|
|
390
|
+
return result.run;
|
|
391
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type {CreateWorkflowRunParams} from './run-create.js';
|
|
2
|
+
export {
|
|
3
|
+
createWorkflowRun,
|
|
4
|
+
loadReferencedVariables,
|
|
5
|
+
} from './run-create.js';
|
|
6
|
+
export type {CreateRerunWorkflowRunParams} from './run-rerun.js';
|
|
7
|
+
export {createRerunWorkflowRun} from './run-rerun.js';
|
|
8
|
+
export type {
|
|
9
|
+
CancelWorkflowRunParams,
|
|
10
|
+
FailWorkflowRunAsTimedOutParams,
|
|
11
|
+
UpdateWorkflowRunStatusParams,
|
|
12
|
+
} from './run-status.js';
|
|
13
|
+
export {
|
|
14
|
+
cancelWorkflowRun,
|
|
15
|
+
failWorkflowRunAsTimedOut,
|
|
16
|
+
updateWorkflowRunStatus,
|
|
17
|
+
} from './run-status.js';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {eq, sql} from 'drizzle-orm';
|
|
2
|
+
import type {JobStatus} from '#core/entities/job.js';
|
|
3
|
+
import type {JobExecutionStatus} from '#core/entities/job-execution.js';
|
|
4
|
+
import type {WorkflowRunStatus} from '#core/entities/workflow-run.js';
|
|
5
|
+
import type {Tx} from '../db.js';
|
|
6
|
+
import {jobs} from '../schema/jobs.js';
|
|
7
|
+
import {steps} from '../schema/steps.js';
|
|
8
|
+
import {workflowRunAttempts} from '../schema/workflow-run-attempts.js';
|
|
9
|
+
import {workflowRuns} from '../schema/workflow-runs.js';
|
|
10
|
+
|
|
11
|
+
export const TERMINAL_WORKFLOW_RUN_STATUSES: WorkflowRunStatus[] = [
|
|
12
|
+
'succeeded',
|
|
13
|
+
'failed',
|
|
14
|
+
'cancelled',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const TERMINAL_JOB_STATUSES: JobStatus[] = ['succeeded', 'failed', 'cancelled', 'skipped'];
|
|
18
|
+
|
|
19
|
+
export const TERMINAL_EXECUTION_STATUSES: JobExecutionStatus[] = [
|
|
20
|
+
'succeeded',
|
|
21
|
+
'failed',
|
|
22
|
+
'cancelled',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export const NON_TERMINAL_STEP_STATUS_FILTER = sql`${steps.status} NOT IN ('succeeded','failed','cancelled','skipped')`;
|
|
26
|
+
|
|
27
|
+
export async function lockWorkflowRun(
|
|
28
|
+
id: string,
|
|
29
|
+
tx: Tx,
|
|
30
|
+
): Promise<typeof workflowRuns.$inferSelect | undefined> {
|
|
31
|
+
const rows = await tx
|
|
32
|
+
.select()
|
|
33
|
+
.from(workflowRuns)
|
|
34
|
+
.where(eq(workflowRuns.id, id))
|
|
35
|
+
.limit(1)
|
|
36
|
+
.for('update');
|
|
37
|
+
return rows[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function optimisticLockRetry<TResult, TFetched>(params: {
|
|
41
|
+
updateFn: () => Promise<TResult | null>;
|
|
42
|
+
fetchFn: () => Promise<TFetched | undefined>;
|
|
43
|
+
matchFn: (value: TFetched) => TResult | null;
|
|
44
|
+
failureMessage: string;
|
|
45
|
+
}): Promise<TResult> {
|
|
46
|
+
const updated = await params.updateFn();
|
|
47
|
+
if (updated) return updated;
|
|
48
|
+
|
|
49
|
+
const existing = await params.fetchFn();
|
|
50
|
+
if (existing) {
|
|
51
|
+
const matched = params.matchFn(existing);
|
|
52
|
+
if (matched) return matched;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error(params.failureMessage);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function getWorkflowContextForJob(
|
|
59
|
+
jobId: string,
|
|
60
|
+
tx: Tx,
|
|
61
|
+
): Promise<{
|
|
62
|
+
jobId: string;
|
|
63
|
+
workflowRunId: string;
|
|
64
|
+
workflowRunAttemptId: string;
|
|
65
|
+
workspaceId: string;
|
|
66
|
+
projectId: string;
|
|
67
|
+
}> {
|
|
68
|
+
const rows = await tx
|
|
69
|
+
.select({
|
|
70
|
+
jobId: jobs.id,
|
|
71
|
+
workflowRunId: workflowRuns.id,
|
|
72
|
+
workflowRunAttemptId: workflowRunAttempts.id,
|
|
73
|
+
workspaceId: workflowRuns.workspaceId,
|
|
74
|
+
projectId: workflowRuns.projectId,
|
|
75
|
+
})
|
|
76
|
+
.from(jobs)
|
|
77
|
+
.innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))
|
|
78
|
+
.innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))
|
|
79
|
+
.where(eq(jobs.id, jobId))
|
|
80
|
+
.limit(1);
|
|
81
|
+
const context = rows[0];
|
|
82
|
+
if (!context) throw new Error(`Cannot load workflow context: job ${jobId} not found`);
|
|
83
|
+
return context;
|
|
84
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {eq} from 'drizzle-orm';
|
|
2
|
+
import {nextStepForJob} from '#core/job-execution.js';
|
|
3
|
+
import {stripSetupStep} from '#test/fixtures/strip-setup-step.js';
|
|
4
|
+
import {
|
|
5
|
+
buildModel,
|
|
6
|
+
bulkUpdateJobStepStatuses,
|
|
7
|
+
stepAttemptTerminatedEvents,
|
|
8
|
+
} from '#test/helpers/workflow-runs.js';
|
|
9
|
+
import {db} from '../db.js';
|
|
10
|
+
import {stepAttempts as stepAttemptsTable} from '../schema/step-attempts.js';
|
|
11
|
+
import {steps as stepsTable} from '../schema/steps.js';
|
|
12
|
+
import {
|
|
13
|
+
createWorkflowRun,
|
|
14
|
+
getJobsByWorkflowRunId,
|
|
15
|
+
getStepAttempts,
|
|
16
|
+
getStepsByJobId,
|
|
17
|
+
} from '../workflow-runs.js';
|
|
18
|
+
|
|
19
|
+
describe('workflow run queries', () => {
|
|
20
|
+
let workspaceId: string;
|
|
21
|
+
let projectId: string;
|
|
22
|
+
let definitionId: string;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
workspaceId = crypto.randomUUID();
|
|
26
|
+
projectId = crypto.randomUUID();
|
|
27
|
+
definitionId = crypto.randomUUID();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('getStepsByJobId', () => {
|
|
31
|
+
test('returns steps for a job ordered by position', async () => {
|
|
32
|
+
const run = await createWorkflowRun({
|
|
33
|
+
workspaceId,
|
|
34
|
+
projectId,
|
|
35
|
+
definitionId,
|
|
36
|
+
model: buildModel({
|
|
37
|
+
jobs: {
|
|
38
|
+
build: {
|
|
39
|
+
steps: [{run: 'step1'}, {run: 'step2'}, {run: 'step3'}],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
triggerPayload: {
|
|
44
|
+
source: 'manual',
|
|
45
|
+
event: 'fire',
|
|
46
|
+
subscriptionId: crypto.randomUUID(),
|
|
47
|
+
userId: crypto.randomUUID(),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const runJobs = await getJobsByWorkflowRunId(run.id);
|
|
52
|
+
const jobSteps = await getStepsByJobId(runJobs[0]?.id as string);
|
|
53
|
+
|
|
54
|
+
// The synthetic setup step occupies position 0; user steps follow at 1..3.
|
|
55
|
+
expect(jobSteps).toHaveLength(4);
|
|
56
|
+
expect(jobSteps[0]).toMatchObject({type: 'setup', position: 0});
|
|
57
|
+
expect(jobSteps[1]?.position).toBe(1);
|
|
58
|
+
expect(jobSteps[2]?.position).toBe(2);
|
|
59
|
+
expect(jobSteps[3]?.position).toBe(3);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('bulkUpdateStepStatuses', () => {
|
|
64
|
+
test('updates all steps for a job to the given sweep status', async () => {
|
|
65
|
+
const run = await createWorkflowRun({
|
|
66
|
+
workspaceId,
|
|
67
|
+
projectId,
|
|
68
|
+
definitionId,
|
|
69
|
+
model: buildModel({
|
|
70
|
+
jobs: {
|
|
71
|
+
build: {steps: [{run: 'step1'}, {run: 'step2'}, {run: 'step3'}]},
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
triggerPayload: {
|
|
75
|
+
source: 'manual',
|
|
76
|
+
event: 'fire',
|
|
77
|
+
subscriptionId: crypto.randomUUID(),
|
|
78
|
+
userId: crypto.randomUUID(),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const runJobs = await getJobsByWorkflowRunId(run.id);
|
|
82
|
+
|
|
83
|
+
const jobId = runJobs[0]?.id ?? '';
|
|
84
|
+
await bulkUpdateJobStepStatuses({jobId, status: 'failed'});
|
|
85
|
+
|
|
86
|
+
const jobSteps = await getStepsByJobId(jobId);
|
|
87
|
+
expect(jobSteps).toHaveLength(4);
|
|
88
|
+
for (const step of jobSteps) {
|
|
89
|
+
expect(step.status).toBe('failed');
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('does not downgrade a terminal step (terminal-state guard)', async () => {
|
|
94
|
+
const run = await createWorkflowRun({
|
|
95
|
+
workspaceId,
|
|
96
|
+
projectId,
|
|
97
|
+
definitionId,
|
|
98
|
+
model: buildModel({jobs: {build: {steps: [{run: 'a'}, {run: 'b'}]}}}),
|
|
99
|
+
triggerPayload: {
|
|
100
|
+
source: 'manual',
|
|
101
|
+
event: 'fire',
|
|
102
|
+
subscriptionId: crypto.randomUUID(),
|
|
103
|
+
userId: crypto.randomUUID(),
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const runJobs = await getJobsByWorkflowRunId(run.id);
|
|
107
|
+
const jobId = runJobs[0]?.id ?? '';
|
|
108
|
+
const seeded = await getStepsByJobId(jobId);
|
|
109
|
+
|
|
110
|
+
await db()
|
|
111
|
+
.update(stepsTable)
|
|
112
|
+
.set({status: 'succeeded'})
|
|
113
|
+
.where(eq(stepsTable.id, seeded[0]?.id as string));
|
|
114
|
+
await db()
|
|
115
|
+
.update(stepsTable)
|
|
116
|
+
.set({status: 'skipped', statusReason: 'condition_rejected'})
|
|
117
|
+
.where(eq(stepsTable.id, seeded[1]?.id as string));
|
|
118
|
+
|
|
119
|
+
await bulkUpdateJobStepStatuses({jobId, status: 'failed'});
|
|
120
|
+
|
|
121
|
+
const final = await getStepsByJobId(jobId);
|
|
122
|
+
expect(final[0]?.status).toBe('succeeded');
|
|
123
|
+
expect(final[1]?.status).toBe('skipped');
|
|
124
|
+
expect(final[1]?.statusReason).toBe('condition_rejected');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('step attempts cannot be skipped', async () => {
|
|
128
|
+
const run = await createWorkflowRun({
|
|
129
|
+
workspaceId,
|
|
130
|
+
projectId,
|
|
131
|
+
definitionId,
|
|
132
|
+
model: buildModel({jobs: {build: {steps: [{run: 'a'}]}}}),
|
|
133
|
+
triggerPayload: {
|
|
134
|
+
source: 'manual',
|
|
135
|
+
event: 'fire',
|
|
136
|
+
subscriptionId: crypto.randomUUID(),
|
|
137
|
+
userId: crypto.randomUUID(),
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
const runJobs = await getJobsByWorkflowRunId(run.id);
|
|
141
|
+
const jobId = runJobs[0]?.id ?? '';
|
|
142
|
+
const [step] = await getStepsByJobId(jobId);
|
|
143
|
+
if (!step) throw new Error('Expected arranged step');
|
|
144
|
+
|
|
145
|
+
await expect(
|
|
146
|
+
db().insert(stepAttemptsTable).values({
|
|
147
|
+
stepId: step.id,
|
|
148
|
+
jobExecutionId: step.jobExecutionId,
|
|
149
|
+
attempt: 1,
|
|
150
|
+
executionOrder: 1,
|
|
151
|
+
status: 'skipped',
|
|
152
|
+
}),
|
|
153
|
+
).rejects.toThrow();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('terminal sweeps finalize running attempts as abandoned and emit attempt events', async () => {
|
|
157
|
+
const run = await createWorkflowRun({
|
|
158
|
+
workspaceId,
|
|
159
|
+
projectId,
|
|
160
|
+
definitionId,
|
|
161
|
+
model: buildModel({jobs: {build: {steps: [{run: 'a'}]}}}),
|
|
162
|
+
triggerPayload: {
|
|
163
|
+
source: 'manual',
|
|
164
|
+
event: 'fire',
|
|
165
|
+
subscriptionId: crypto.randomUUID(),
|
|
166
|
+
userId: crypto.randomUUID(),
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
const runJobs = await getJobsByWorkflowRunId(run.id);
|
|
170
|
+
const jobId = runJobs[0]?.id ?? '';
|
|
171
|
+
await stripSetupStep(jobId);
|
|
172
|
+
await nextStepForJob(jobId);
|
|
173
|
+
|
|
174
|
+
await bulkUpdateJobStepStatuses({jobId, status: 'cancelled'});
|
|
175
|
+
|
|
176
|
+
const [attempt] = await getStepAttempts(jobId);
|
|
177
|
+
expect(attempt).toMatchObject({status: 'cancelled', logOutcome: 'abandoned'});
|
|
178
|
+
expect(await stepAttemptTerminatedEvents(jobId)).toMatchObject([
|
|
179
|
+
{
|
|
180
|
+
jobId,
|
|
181
|
+
workflowRunId: run.id,
|
|
182
|
+
workspaceId,
|
|
183
|
+
projectId,
|
|
184
|
+
stepId: attempt?.stepId,
|
|
185
|
+
attempt: 1,
|
|
186
|
+
logOutcome: 'abandoned',
|
|
187
|
+
},
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|