@shipfox/api-definitions 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 +215 -0
- package/LICENSE +21 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +35 -0
- package/dist/config.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 +6 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/integration-context.d.ts +11 -0
- package/dist/core/entities/integration-context.d.ts.map +1 -0
- package/dist/core/entities/integration-context.js +3 -0
- package/dist/core/entities/integration-context.js.map +1 -0
- package/dist/core/entities/sync-state.d.ts +19 -0
- package/dist/core/entities/sync-state.d.ts.map +1 -0
- package/dist/core/entities/sync-state.js +20 -0
- package/dist/core/entities/sync-state.js.map +1 -0
- package/dist/core/entities/workflow-definition.d.ts +35 -0
- package/dist/core/entities/workflow-definition.d.ts.map +1 -0
- package/dist/core/entities/workflow-definition.js +3 -0
- package/dist/core/entities/workflow-definition.js.map +1 -0
- package/dist/core/entities/workflow-model.d.ts +138 -0
- package/dist/core/entities/workflow-model.d.ts.map +1 -0
- package/dist/core/entities/workflow-model.js +3 -0
- package/dist/core/entities/workflow-model.js.map +1 -0
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +14 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/has-agent-step-integrations.d.ts +3 -0
- package/dist/core/has-agent-step-integrations.d.ts.map +1 -0
- package/dist/core/has-agent-step-integrations.js +5 -0
- package/dist/core/has-agent-step-integrations.js.map +1 -0
- package/dist/core/index.d.ts +9 -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/parse-definition.d.ts +9 -0
- package/dist/core/parse-definition.d.ts.map +1 -0
- package/dist/core/parse-definition.js +17 -0
- package/dist/core/parse-definition.js.map +1 -0
- package/dist/core/sync-definitions.d.ts +44 -0
- package/dist/core/sync-definitions.d.ts.map +1 -0
- package/dist/core/sync-definitions.js +140 -0
- package/dist/core/sync-definitions.js.map +1 -0
- package/dist/core/validate-definition.d.ts +20 -0
- package/dist/core/validate-definition.d.ts.map +1 -0
- package/dist/core/validate-definition.js +61 -0
- package/dist/core/validate-definition.js.map +1 -0
- package/dist/core/workflow-model/constants.d.ts +2 -0
- package/dist/core/workflow-model/constants.d.ts.map +1 -0
- package/dist/core/workflow-model/constants.js +3 -0
- package/dist/core/workflow-model/constants.js.map +1 -0
- package/dist/core/workflow-model/cron-trigger.d.ts +16 -0
- package/dist/core/workflow-model/cron-trigger.d.ts.map +1 -0
- package/dist/core/workflow-model/cron-trigger.js +85 -0
- package/dist/core/workflow-model/cron-trigger.js.map +1 -0
- package/dist/core/workflow-model/index.d.ts +4 -0
- package/dist/core/workflow-model/index.d.ts.map +1 -0
- package/dist/core/workflow-model/index.js +5 -0
- package/dist/core/workflow-model/index.js.map +1 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts +15 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts.map +1 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.js +9 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.js.map +1 -0
- package/dist/core/workflow-model/map-job-ids.d.ts +4 -0
- package/dist/core/workflow-model/map-job-ids.d.ts.map +1 -0
- package/dist/core/workflow-model/map-job-ids.js +33 -0
- package/dist/core/workflow-model/map-job-ids.js.map +1 -0
- package/dist/core/workflow-model/normalize-agent-integrations.d.ts +12 -0
- package/dist/core/workflow-model/normalize-agent-integrations.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-agent-integrations.js +157 -0
- package/dist/core/workflow-model/normalize-agent-integrations.js.map +1 -0
- package/dist/core/workflow-model/normalize-dependencies.d.ts +6 -0
- package/dist/core/workflow-model/normalize-dependencies.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-dependencies.js +119 -0
- package/dist/core/workflow-model/normalize-dependencies.js.map +1 -0
- package/dist/core/workflow-model/normalize-env.d.ts +17 -0
- package/dist/core/workflow-model/normalize-env.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-env.js +40 -0
- package/dist/core/workflow-model/normalize-env.js.map +1 -0
- package/dist/core/workflow-model/normalize-if-condition.d.ts +14 -0
- package/dist/core/workflow-model/normalize-if-condition.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-if-condition.js +75 -0
- package/dist/core/workflow-model/normalize-if-condition.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-checkout.d.ts +5 -0
- package/dist/core/workflow-model/normalize-job-checkout.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-checkout.js +16 -0
- package/dist/core/workflow-model/normalize-job-checkout.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-listening.d.ts +10 -0
- package/dist/core/workflow-model/normalize-job-listening.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-listening.js +125 -0
- package/dist/core/workflow-model/normalize-job-listening.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-success.d.ts +11 -0
- package/dist/core/workflow-model/normalize-job-success.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-success.js +23 -0
- package/dist/core/workflow-model/normalize-job-success.js.map +1 -0
- package/dist/core/workflow-model/normalize-jobs.d.ts +12 -0
- package/dist/core/workflow-model/normalize-jobs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-jobs.js +935 -0
- package/dist/core/workflow-model/normalize-jobs.js.map +1 -0
- package/dist/core/workflow-model/normalize-needs.d.ts +2 -0
- package/dist/core/workflow-model/normalize-needs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-needs.js +16 -0
- package/dist/core/workflow-model/normalize-needs.js.map +1 -0
- package/dist/core/workflow-model/normalize-step-gate.d.ts +15 -0
- package/dist/core/workflow-model/normalize-step-gate.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-step-gate.js +89 -0
- package/dist/core/workflow-model/normalize-step-gate.js.map +1 -0
- package/dist/core/workflow-model/normalize-step-outputs.d.ts +10 -0
- package/dist/core/workflow-model/normalize-step-outputs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-step-outputs.js +32 -0
- package/dist/core/workflow-model/normalize-step-outputs.js.map +1 -0
- package/dist/core/workflow-model/normalize-triggers.d.ts +11 -0
- package/dist/core/workflow-model/normalize-triggers.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-triggers.js +128 -0
- package/dist/core/workflow-model/normalize-triggers.js.map +1 -0
- package/dist/core/workflow-model/normalize-workflow-document.d.ts +11 -0
- package/dist/core/workflow-model/normalize-workflow-document.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-workflow-document.js +43 -0
- package/dist/core/workflow-model/normalize-workflow-document.js.map +1 -0
- package/dist/core/workflow-model/parse-duration-ms.d.ts +11 -0
- package/dist/core/workflow-model/parse-duration-ms.d.ts.map +1 -0
- package/dist/core/workflow-model/parse-duration-ms.js +47 -0
- package/dist/core/workflow-model/parse-duration-ms.js.map +1 -0
- package/dist/core/workflow-model/parse-interpolation-field.d.ts +14 -0
- package/dist/core/workflow-model/parse-interpolation-field.d.ts.map +1 -0
- package/dist/core/workflow-model/parse-interpolation-field.js +377 -0
- package/dist/core/workflow-model/parse-interpolation-field.js.map +1 -0
- package/dist/core/workflow-model/stable-id.d.ts +2 -0
- package/dist/core/workflow-model/stable-id.d.ts.map +1 -0
- package/dist/core/workflow-model/stable-id.js +8 -0
- package/dist/core/workflow-model/stable-id.js.map +1 -0
- package/dist/core/workflow-model/validate-job-references.d.ts +10 -0
- package/dist/core/workflow-model/validate-job-references.d.ts.map +1 -0
- package/dist/core/workflow-model/validate-job-references.js +42 -0
- package/dist/core/workflow-model/validate-job-references.js.map +1 -0
- package/dist/core/workflow-model/validate-predicate-expression.d.ts +14 -0
- package/dist/core/workflow-model/validate-predicate-expression.d.ts.map +1 -0
- package/dist/core/workflow-model/validate-predicate-expression.js +273 -0
- package/dist/core/workflow-model/validate-predicate-expression.js.map +1 -0
- package/dist/core/workflow-model/validation-issue.d.ts +8 -0
- package/dist/core/workflow-model/validation-issue.d.ts.map +1 -0
- package/dist/core/workflow-model/validation-issue.js +17 -0
- package/dist/core/workflow-model/validation-issue.js.map +1 -0
- package/dist/core/workflow-model/workflow-field-label.d.ts +3 -0
- package/dist/core/workflow-model/workflow-field-label.d.ts.map +1 -0
- package/dist/core/workflow-model/workflow-field-label.js +47 -0
- package/dist/core/workflow-model/workflow-field-label.js.map +1 -0
- package/dist/core/workflow-yaml/index.d.ts +3 -0
- package/dist/core/workflow-yaml/index.d.ts.map +1 -0
- package/dist/core/workflow-yaml/index.js +4 -0
- package/dist/core/workflow-yaml/index.js.map +1 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.d.ts +16 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.d.ts.map +1 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.js +12 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.js.map +1 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.d.ts +9 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.d.ts.map +1 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.js +52 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.js.map +1 -0
- package/dist/core/workflow-yaml/source-locations.d.ts +3 -0
- package/dist/core/workflow-yaml/source-locations.d.ts.map +1 -0
- package/dist/core/workflow-yaml/source-locations.js +48 -0
- package/dist/core/workflow-yaml/source-locations.js.map +1 -0
- package/dist/db/db.d.ts +1277 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +22 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/definition-triggers.d.ts +4 -0
- package/dist/db/definition-triggers.d.ts.map +1 -0
- package/dist/db/definition-triggers.js +17 -0
- package/dist/db/definition-triggers.js.map +1 -0
- package/dist/db/definitions.d.ts +63 -0
- package/dist/db/definitions.d.ts.map +1 -0
- package/dist/db/definitions.js +208 -0
- package/dist/db/definitions.js.map +1 -0
- package/dist/db/index.d.ts +8 -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/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/definitions.d.ts +237 -0
- package/dist/db/schema/definitions.d.ts.map +1 -0
- package/dist/db/schema/definitions.js +63 -0
- package/dist/db/schema/definitions.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/sync-states.d.ts +218 -0
- package/dist/db/schema/sync-states.d.ts.map +1 -0
- package/dist/db/schema/sync-states.js +68 -0
- package/dist/db/schema/sync-states.js.map +1 -0
- package/dist/db/sync-states.d.ts +21 -0
- package/dist/db/sync-states.d.ts.map +1 -0
- package/dist/db/sync-states.js +47 -0
- package/dist/db/sync-states.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/presentation/dto/definition.d.ts +6 -0
- package/dist/presentation/dto/definition.d.ts.map +1 -0
- package/dist/presentation/dto/definition.js +35 -0
- package/dist/presentation/dto/definition.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +2 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +3 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/index.d.ts +2 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +3 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/create-definition.d.ts +9 -0
- package/dist/presentation/routes/create-definition.d.ts.map +1 -0
- package/dist/presentation/routes/create-definition.js +76 -0
- package/dist/presentation/routes/create-definition.js.map +1 -0
- package/dist/presentation/routes/get-definition.d.ts +2 -0
- package/dist/presentation/routes/get-definition.d.ts.map +1 -0
- package/dist/presentation/routes/get-definition.js +43 -0
- package/dist/presentation/routes/get-definition.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +7 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +22 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-definitions.d.ts +2 -0
- package/dist/presentation/routes/list-definitions.d.ts.map +1 -0
- package/dist/presentation/routes/list-definitions.js +56 -0
- package/dist/presentation/routes/list-definitions.js.map +1 -0
- package/dist/presentation/routes/validate-definition.d.ts +2 -0
- package/dist/presentation/routes/validate-definition.d.ts.map +1 -0
- package/dist/presentation/routes/validate-definition.js +43 -0
- package/dist/presentation/routes/validate-definition.js.map +1 -0
- package/dist/presentation/subscribers/index.d.ts +3 -0
- package/dist/presentation/subscribers/index.d.ts.map +1 -0
- package/dist/presentation/subscribers/index.js +4 -0
- package/dist/presentation/subscribers/index.js.map +1 -0
- package/dist/presentation/subscribers/on-project-source-bound.d.ts +3 -0
- package/dist/presentation/subscribers/on-project-source-bound.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-project-source-bound.js +11 -0
- package/dist/presentation/subscribers/on-project-source-bound.js.map +1 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.d.ts +3 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.js +13 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.js.map +1 -0
- package/dist/presentation/subscribers/start-definition-sync.d.ts +10 -0
- package/dist/presentation/subscribers/start-definition-sync.d.ts.map +1 -0
- package/dist/presentation/subscribers/start-definition-sync.js +26 -0
- package/dist/presentation/subscribers/start-definition-sync.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +3 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +3 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/sync-activities.d.ts +47 -0
- package/dist/temporal/activities/sync-activities.d.ts.map +1 -0
- package/dist/temporal/activities/sync-activities.js +128 -0
- package/dist/temporal/activities/sync-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +3 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +4 -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/workflows/definition-sync.d.ts +20 -0
- package/dist/temporal/workflows/definition-sync.d.ts.map +1 -0
- package/dist/temporal/workflows/definition-sync.js +95 -0
- package/dist/temporal/workflows/definition-sync.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +2 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +3 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +64 -0
- package/drizzle/0001_definition_list_pagination.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +527 -0
- package/drizzle/meta/_journal.json +20 -0
- package/drizzle.config.ts +11 -0
- package/package.json +89 -0
- package/src/config.test.ts +23 -0
- package/src/config.ts +50 -0
- package/src/core/entities/index.ts +4 -0
- package/src/core/entities/integration-context.ts +21 -0
- package/src/core/entities/sync-state.ts +40 -0
- package/src/core/entities/workflow-definition.ts +38 -0
- package/src/core/entities/workflow-model.ts +162 -0
- package/src/core/errors.ts +21 -0
- package/src/core/has-agent-step-integrations.ts +7 -0
- package/src/core/index.ts +23 -0
- package/src/core/parse-definition.test.ts +200 -0
- package/src/core/parse-definition.ts +28 -0
- package/src/core/sync-definitions.test.ts +390 -0
- package/src/core/sync-definitions.ts +216 -0
- package/src/core/validate-definition.test.ts +152 -0
- package/src/core/validate-definition.ts +72 -0
- package/src/core/workflow-model/README.md +129 -0
- package/src/core/workflow-model/constants.ts +1 -0
- package/src/core/workflow-model/cron-trigger.test.ts +29 -0
- package/src/core/workflow-model/cron-trigger.ts +83 -0
- package/src/core/workflow-model/index.ts +9 -0
- package/src/core/workflow-model/invalid-workflow-model-error.ts +71 -0
- package/src/core/workflow-model/map-job-ids.ts +33 -0
- package/src/core/workflow-model/normalize-agent-integrations.ts +208 -0
- package/src/core/workflow-model/normalize-dependencies.ts +139 -0
- package/src/core/workflow-model/normalize-env.ts +48 -0
- package/src/core/workflow-model/normalize-if-condition.ts +126 -0
- package/src/core/workflow-model/normalize-job-checkout.ts +19 -0
- package/src/core/workflow-model/normalize-job-listening.ts +121 -0
- package/src/core/workflow-model/normalize-job-success.ts +28 -0
- package/src/core/workflow-model/normalize-jobs.ts +1010 -0
- package/src/core/workflow-model/normalize-needs.ts +12 -0
- package/src/core/workflow-model/normalize-step-gate.ts +90 -0
- package/src/core/workflow-model/normalize-step-outputs.ts +36 -0
- package/src/core/workflow-model/normalize-triggers.ts +130 -0
- package/src/core/workflow-model/normalize-workflow-document.test.ts +4463 -0
- package/src/core/workflow-model/normalize-workflow-document.ts +63 -0
- package/src/core/workflow-model/parse-duration-ms.ts +58 -0
- package/src/core/workflow-model/parse-interpolation-field.ts +566 -0
- package/src/core/workflow-model/stable-id.ts +12 -0
- package/src/core/workflow-model/validate-job-references.ts +54 -0
- package/src/core/workflow-model/validate-predicate-expression.test.ts +161 -0
- package/src/core/workflow-model/validate-predicate-expression.ts +406 -0
- package/src/core/workflow-model/validation-issue.ts +27 -0
- package/src/core/workflow-model/workflow-field-label.ts +50 -0
- package/src/core/workflow-yaml/README.md +77 -0
- package/src/core/workflow-yaml/index.ts +11 -0
- package/src/core/workflow-yaml/invalid-workflow-yaml-error.ts +23 -0
- package/src/core/workflow-yaml/parse-workflow-yaml.test.ts +71 -0
- package/src/core/workflow-yaml/parse-workflow-yaml.ts +74 -0
- package/src/core/workflow-yaml/source-locations.ts +62 -0
- package/src/db/db.ts +18 -0
- package/src/db/definition-triggers.test.ts +95 -0
- package/src/db/definition-triggers.ts +17 -0
- package/src/db/definitions.test.ts +1309 -0
- package/src/db/definitions.ts +357 -0
- package/src/db/index.ts +31 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/definitions.test.ts +36 -0
- package/src/db/schema/definitions.ts +76 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/sync-states.ts +79 -0
- package/src/db/sync-states.test.ts +90 -0
- package/src/db/sync-states.ts +86 -0
- package/src/index.ts +104 -0
- package/src/presentation/dto/definition.test.ts +59 -0
- package/src/presentation/dto/definition.ts +41 -0
- package/src/presentation/dto/index.ts +1 -0
- package/src/presentation/index.ts +1 -0
- package/src/presentation/routes/create-definition.test.ts +356 -0
- package/src/presentation/routes/create-definition.ts +101 -0
- package/src/presentation/routes/get-definition.test.ts +79 -0
- package/src/presentation/routes/get-definition.ts +37 -0
- package/src/presentation/routes/index.test.ts +41 -0
- package/src/presentation/routes/index.ts +28 -0
- package/src/presentation/routes/list-definitions.test.ts +195 -0
- package/src/presentation/routes/list-definitions.ts +49 -0
- package/src/presentation/routes/validate-definition.test.ts +63 -0
- package/src/presentation/routes/validate-definition.ts +46 -0
- package/src/presentation/subscribers/index.ts +2 -0
- package/src/presentation/subscribers/on-project-source-bound.test.ts +65 -0
- package/src/presentation/subscribers/on-project-source-bound.ts +11 -0
- package/src/presentation/subscribers/on-project-source-commit-observed.test.ts +56 -0
- package/src/presentation/subscribers/on-project-source-commit-observed.ts +15 -0
- package/src/presentation/subscribers/start-definition-sync.ts +38 -0
- package/src/temporal/activities/index.ts +10 -0
- package/src/temporal/activities/sync-activities.test.ts +337 -0
- package/src/temporal/activities/sync-activities.ts +206 -0
- package/src/temporal/constants.ts +2 -0
- package/src/temporal/index.ts +2 -0
- package/src/temporal/workflows/definition-sync.test.ts +59 -0
- package/src/temporal/workflows/definition-sync.ts +116 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/test/env.ts +7 -0
- package/test/factories/definition.ts +66 -0
- package/test/fixtures/invalid-cycle.yml +13 -0
- package/test/fixtures/invalid-missing-name.yml +4 -0
- package/test/fixtures/invalid-yaml-syntax.yml +6 -0
- package/test/fixtures/valid-dag.yml +25 -0
- package/test/fixtures/valid-listening-job.yml +21 -0
- package/test/fixtures/valid-simple.yml +18 -0
- package/test/fixtures/workflow-yaml/invalid/invalid-yaml-syntax.yaml +6 -0
- package/test/fixtures/workflow-yaml/invalid/missing-step-run.yaml +5 -0
- package/test/fixtures/workflow-yaml/valid/simple-build.document.json +26 -0
- package/test/fixtures/workflow-yaml/valid/simple-build.yaml +14 -0
- package/test/globalSetup.ts +25 -0
- package/test/index.ts +1 -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 +11 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {and, desc, eq} from 'drizzle-orm';
|
|
2
|
+
import type {
|
|
3
|
+
DefinitionSyncErrorCode,
|
|
4
|
+
DefinitionSyncState,
|
|
5
|
+
DefinitionSyncStatus,
|
|
6
|
+
} from '#core/entities/sync-state.js';
|
|
7
|
+
import {db} from './db.js';
|
|
8
|
+
import {definitionSyncStates, toDefinitionSyncState} from './schema/sync-states.js';
|
|
9
|
+
|
|
10
|
+
export interface DefinitionSyncStateKey {
|
|
11
|
+
projectId: string;
|
|
12
|
+
sourceConnectionId: string;
|
|
13
|
+
sourceExternalRepositoryId: string;
|
|
14
|
+
ref: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface MarkDefinitionSyncParams extends DefinitionSyncStateKey {
|
|
18
|
+
status: DefinitionSyncStatus;
|
|
19
|
+
lastErrorCode?: DefinitionSyncErrorCode | null | undefined;
|
|
20
|
+
lastErrorMessage?: string | null | undefined;
|
|
21
|
+
startedAt?: Date | null | undefined;
|
|
22
|
+
finishedAt?: Date | null | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function markDefinitionSyncState(
|
|
26
|
+
params: MarkDefinitionSyncParams,
|
|
27
|
+
): Promise<DefinitionSyncState> {
|
|
28
|
+
const now = new Date();
|
|
29
|
+
const [row] = await db()
|
|
30
|
+
.insert(definitionSyncStates)
|
|
31
|
+
.values({
|
|
32
|
+
projectId: params.projectId,
|
|
33
|
+
sourceConnectionId: params.sourceConnectionId,
|
|
34
|
+
sourceExternalRepositoryId: params.sourceExternalRepositoryId,
|
|
35
|
+
ref: params.ref,
|
|
36
|
+
status: params.status,
|
|
37
|
+
lastErrorCode: params.lastErrorCode ?? null,
|
|
38
|
+
lastErrorMessage: params.lastErrorMessage ?? null,
|
|
39
|
+
startedAt: params.startedAt ?? null,
|
|
40
|
+
finishedAt: params.finishedAt ?? null,
|
|
41
|
+
updatedAt: now,
|
|
42
|
+
})
|
|
43
|
+
.onConflictDoUpdate({
|
|
44
|
+
target: [
|
|
45
|
+
definitionSyncStates.projectId,
|
|
46
|
+
definitionSyncStates.sourceConnectionId,
|
|
47
|
+
definitionSyncStates.sourceExternalRepositoryId,
|
|
48
|
+
definitionSyncStates.ref,
|
|
49
|
+
],
|
|
50
|
+
set: {
|
|
51
|
+
status: params.status,
|
|
52
|
+
lastErrorCode: params.lastErrorCode ?? null,
|
|
53
|
+
lastErrorMessage: params.lastErrorMessage ?? null,
|
|
54
|
+
...(params.startedAt !== undefined ? {startedAt: params.startedAt} : {}),
|
|
55
|
+
...(params.finishedAt !== undefined ? {finishedAt: params.finishedAt} : {}),
|
|
56
|
+
updatedAt: now,
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
.returning();
|
|
60
|
+
|
|
61
|
+
if (!row) throw new Error('Definition sync state upsert returned no rows');
|
|
62
|
+
return toDefinitionSyncState(row);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function getLatestDefinitionSyncState(params: {
|
|
66
|
+
projectId: string;
|
|
67
|
+
sourceConnectionId: string;
|
|
68
|
+
sourceExternalRepositoryId: string;
|
|
69
|
+
}): Promise<DefinitionSyncState | undefined> {
|
|
70
|
+
const rows = await db()
|
|
71
|
+
.select()
|
|
72
|
+
.from(definitionSyncStates)
|
|
73
|
+
.where(
|
|
74
|
+
and(
|
|
75
|
+
eq(definitionSyncStates.projectId, params.projectId),
|
|
76
|
+
eq(definitionSyncStates.sourceConnectionId, params.sourceConnectionId),
|
|
77
|
+
eq(definitionSyncStates.sourceExternalRepositoryId, params.sourceExternalRepositoryId),
|
|
78
|
+
),
|
|
79
|
+
)
|
|
80
|
+
.orderBy(desc(definitionSyncStates.updatedAt))
|
|
81
|
+
.limit(1);
|
|
82
|
+
|
|
83
|
+
const row = rows[0];
|
|
84
|
+
if (!row) return undefined;
|
|
85
|
+
return toDefinitionSyncState(row);
|
|
86
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {dirname, resolve} from 'node:path';
|
|
2
|
+
import {fileURLToPath} from 'node:url';
|
|
3
|
+
import {
|
|
4
|
+
DEFINITION_RESOLVED,
|
|
5
|
+
type DefinitionsEventMap,
|
|
6
|
+
definitionsEventSchemas,
|
|
7
|
+
} from '@shipfox/api-definitions-dto';
|
|
8
|
+
import type {
|
|
9
|
+
AgentToolSelectionCatalogs,
|
|
10
|
+
GetIntegrationConnectionByIdFn,
|
|
11
|
+
IntegrationSourceControlService,
|
|
12
|
+
LoadWorkspaceConnectionSnapshot,
|
|
13
|
+
} from '@shipfox/api-integration-core';
|
|
14
|
+
import {
|
|
15
|
+
PROJECT_SOURCE_BOUND,
|
|
16
|
+
PROJECT_SOURCE_COMMIT_OBSERVED,
|
|
17
|
+
type ProjectsEventMap,
|
|
18
|
+
} from '@shipfox/api-projects-dto';
|
|
19
|
+
import {type ShipfoxModule, subscriberFactory} from '@shipfox/node-module';
|
|
20
|
+
import {logger} from '@shipfox/node-opentelemetry';
|
|
21
|
+
import {db, definitionsOutbox, migrationsPath} from '#db/index.js';
|
|
22
|
+
import {createDefinitionRoutes} from '#presentation/index.js';
|
|
23
|
+
import {
|
|
24
|
+
onProjectSourceBound,
|
|
25
|
+
onProjectSourceCommitObserved,
|
|
26
|
+
} from '#presentation/subscribers/index.js';
|
|
27
|
+
import {createDefinitionSyncActivities, DEFINITIONS_TASK_QUEUE} from '#temporal/index.js';
|
|
28
|
+
|
|
29
|
+
export type {
|
|
30
|
+
WorkflowDefinition,
|
|
31
|
+
WorkflowDefinitionPayload,
|
|
32
|
+
WorkflowEnvTemplates,
|
|
33
|
+
WorkflowModel,
|
|
34
|
+
WorkflowModelJobCheckout,
|
|
35
|
+
WorkflowSourceSnapshot,
|
|
36
|
+
WorkflowSpec,
|
|
37
|
+
} from '#core/index.js';
|
|
38
|
+
export {
|
|
39
|
+
DEFAULT_JOB_CHECKOUT,
|
|
40
|
+
DEFAULT_JOB_SUCCESS,
|
|
41
|
+
DEFAULT_RUN_TIMEOUT_MS,
|
|
42
|
+
normalizeWorkflowDocument,
|
|
43
|
+
} from '#core/index.js';
|
|
44
|
+
export {db, definitionsOutbox, getDefinitionById, migrationsPath} from '#db/index.js';
|
|
45
|
+
export {routes} from '#presentation/index.js';
|
|
46
|
+
|
|
47
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
48
|
+
const workflowsPath = resolve(packageRoot, 'dist/temporal/workflows/index.js');
|
|
49
|
+
|
|
50
|
+
const subscriber = subscriberFactory<DefinitionsEventMap & ProjectsEventMap>();
|
|
51
|
+
|
|
52
|
+
export interface CreateDefinitionsModuleOptions {
|
|
53
|
+
sourceControl: IntegrationSourceControlService;
|
|
54
|
+
agentToolSelectionCatalogs?: AgentToolSelectionCatalogs | undefined;
|
|
55
|
+
loadWorkspaceConnectionSnapshot?: LoadWorkspaceConnectionSnapshot | undefined;
|
|
56
|
+
getIntegrationConnectionById?: GetIntegrationConnectionByIdFn | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function createDefinitionsModule({
|
|
60
|
+
sourceControl,
|
|
61
|
+
agentToolSelectionCatalogs,
|
|
62
|
+
loadWorkspaceConnectionSnapshot,
|
|
63
|
+
getIntegrationConnectionById,
|
|
64
|
+
}: CreateDefinitionsModuleOptions): ShipfoxModule {
|
|
65
|
+
const integrationValidation =
|
|
66
|
+
agentToolSelectionCatalogs === undefined ||
|
|
67
|
+
loadWorkspaceConnectionSnapshot === undefined ||
|
|
68
|
+
getIntegrationConnectionById === undefined
|
|
69
|
+
? undefined
|
|
70
|
+
: {
|
|
71
|
+
agentToolSelectionCatalogs,
|
|
72
|
+
loadWorkspaceConnectionSnapshot,
|
|
73
|
+
getIntegrationConnectionById,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
name: 'definitions',
|
|
78
|
+
database: {db, migrationsPath},
|
|
79
|
+
routes: createDefinitionRoutes({
|
|
80
|
+
agentToolSelectionCatalogs,
|
|
81
|
+
loadWorkspaceConnectionSnapshot,
|
|
82
|
+
getIntegrationConnectionById,
|
|
83
|
+
}),
|
|
84
|
+
publishers: [
|
|
85
|
+
{name: 'definitions', table: definitionsOutbox, db, eventSchemas: definitionsEventSchemas},
|
|
86
|
+
],
|
|
87
|
+
subscribers: [
|
|
88
|
+
subscriber(DEFINITION_RESOLVED, (_payload, event) => {
|
|
89
|
+
logger().info({event}, 'Definition resolved');
|
|
90
|
+
return Promise.resolve();
|
|
91
|
+
}),
|
|
92
|
+
subscriber(PROJECT_SOURCE_BOUND, onProjectSourceBound),
|
|
93
|
+
subscriber(PROJECT_SOURCE_COMMIT_OBSERVED, onProjectSourceCommitObserved),
|
|
94
|
+
],
|
|
95
|
+
workers: [
|
|
96
|
+
{
|
|
97
|
+
taskQueue: DEFINITIONS_TASK_QUEUE,
|
|
98
|
+
workflowsPath,
|
|
99
|
+
activities: () => createDefinitionSyncActivities(sourceControl, integrationValidation),
|
|
100
|
+
workflows: [],
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {WorkflowDefinition} from '#core/entities/workflow-definition.js';
|
|
2
|
+
import {normalizeWorkflowDocument} from '#core/workflow-model/index.js';
|
|
3
|
+
import {toDefinitionDto} from './definition.js';
|
|
4
|
+
|
|
5
|
+
describe('toDefinitionDto', () => {
|
|
6
|
+
it('maps the workflow definition entity to the public DTO shape', () => {
|
|
7
|
+
const document = {
|
|
8
|
+
name: 'Manual workflow',
|
|
9
|
+
runner: 'ubuntu-latest',
|
|
10
|
+
triggers: {
|
|
11
|
+
run_now: {
|
|
12
|
+
source: 'manual',
|
|
13
|
+
event: 'fire',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
jobs: {
|
|
17
|
+
build: {
|
|
18
|
+
steps: [{run: 'pnpm build'}],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const definition: WorkflowDefinition = {
|
|
23
|
+
id: '019e98ab-6656-7ca1-b9ad-1ca4442c479d',
|
|
24
|
+
projectId: '019e98ab-b90f-7265-b13c-8b441c991381',
|
|
25
|
+
configPath: '.shipfox/workflows/manual.yml',
|
|
26
|
+
source: 'manual',
|
|
27
|
+
sha: null,
|
|
28
|
+
ref: null,
|
|
29
|
+
name: document.name,
|
|
30
|
+
definition: document,
|
|
31
|
+
document,
|
|
32
|
+
model: normalizeWorkflowDocument(document),
|
|
33
|
+
sourceSnapshot: null,
|
|
34
|
+
contentHash: null,
|
|
35
|
+
fetchedAt: new Date('2026-06-09T10:00:00.000Z'),
|
|
36
|
+
createdAt: new Date('2026-06-09T10:00:01.000Z'),
|
|
37
|
+
updatedAt: new Date('2026-06-09T10:00:02.000Z'),
|
|
38
|
+
deletedAt: null,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const result = toDefinitionDto(definition);
|
|
42
|
+
|
|
43
|
+
expect(result).toEqual({
|
|
44
|
+
id: definition.id,
|
|
45
|
+
project_id: definition.projectId,
|
|
46
|
+
config_path: definition.configPath,
|
|
47
|
+
source: 'manual',
|
|
48
|
+
sha: null,
|
|
49
|
+
ref: null,
|
|
50
|
+
name: document.name,
|
|
51
|
+
workflow_document: document,
|
|
52
|
+
workflow_model: definition.model,
|
|
53
|
+
manual_trigger: {name: 'run_now'},
|
|
54
|
+
fetched_at: '2026-06-09T10:00:00.000Z',
|
|
55
|
+
created_at: '2026-06-09T10:00:01.000Z',
|
|
56
|
+
updated_at: '2026-06-09T10:00:02.000Z',
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type {DefinitionDto, DefinitionSyncSummaryDto} from '@shipfox/api-definitions-dto';
|
|
2
|
+
import type {DefinitionSyncState} from '#core/entities/sync-state.js';
|
|
3
|
+
import type {WorkflowDefinition} from '#core/entities/workflow-definition.js';
|
|
4
|
+
import {UNRESOLVED_SYNC_REF} from '#core/sync-definitions.js';
|
|
5
|
+
|
|
6
|
+
export function toDefinitionDto(definition: WorkflowDefinition): DefinitionDto {
|
|
7
|
+
const manualEntry = Object.entries(definition.document.triggers ?? {}).find(
|
|
8
|
+
([, trigger]) => trigger.source === 'manual',
|
|
9
|
+
);
|
|
10
|
+
return {
|
|
11
|
+
id: definition.id,
|
|
12
|
+
project_id: definition.projectId,
|
|
13
|
+
config_path: definition.configPath,
|
|
14
|
+
source: definition.source,
|
|
15
|
+
sha: definition.sha,
|
|
16
|
+
ref: definition.ref,
|
|
17
|
+
name: definition.name,
|
|
18
|
+
workflow_document: definition.document,
|
|
19
|
+
workflow_model: definition.model,
|
|
20
|
+
manual_trigger: manualEntry ? {name: manualEntry[0]} : null,
|
|
21
|
+
fetched_at: definition.fetchedAt.toISOString(),
|
|
22
|
+
created_at: definition.createdAt.toISOString(),
|
|
23
|
+
updated_at: definition.updatedAt.toISOString(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function toDefinitionSyncSummaryDto(
|
|
28
|
+
syncState: DefinitionSyncState | undefined,
|
|
29
|
+
): DefinitionSyncSummaryDto | null {
|
|
30
|
+
if (!syncState) return null;
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
ref: syncState.ref === UNRESOLVED_SYNC_REF ? null : syncState.ref,
|
|
34
|
+
status: syncState.status,
|
|
35
|
+
last_sync_at: (syncState.finishedAt ?? syncState.updatedAt).toISOString(),
|
|
36
|
+
started_at: syncState.startedAt?.toISOString() ?? null,
|
|
37
|
+
finished_at: syncState.finishedAt?.toISOString() ?? null,
|
|
38
|
+
last_error_code: syncState.lastErrorCode,
|
|
39
|
+
last_error_message: syncState.lastErrorMessage,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {toDefinitionDto, toDefinitionSyncSummaryDto} from './definition.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {createDefinitionRoutes, definitionRoutes as routes} from './routes/index.js';
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import {buildUserContext, setUserContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import type {FastifyInstance} from 'fastify';
|
|
3
|
+
import Fastify from 'fastify';
|
|
4
|
+
import {serializerCompiler, validatorCompiler} from 'fastify-type-provider-zod';
|
|
5
|
+
import {buildCreateDefinitionRoute, createDefinitionRoute} from './create-definition.js';
|
|
6
|
+
|
|
7
|
+
const projectAccessState = vi.hoisted(() => ({workspaceId: '', sourceConnectionId: ''}));
|
|
8
|
+
|
|
9
|
+
vi.mock('@shipfox/api-projects', () => ({
|
|
10
|
+
ProjectNotFoundError: class ProjectNotFoundError extends Error {},
|
|
11
|
+
requireProjectAccess: vi.fn(({projectId}) =>
|
|
12
|
+
Promise.resolve({
|
|
13
|
+
project: {
|
|
14
|
+
id: projectId,
|
|
15
|
+
workspaceId: projectAccessState.workspaceId,
|
|
16
|
+
sourceConnectionId: projectAccessState.sourceConnectionId,
|
|
17
|
+
},
|
|
18
|
+
workspaceId: projectAccessState.workspaceId,
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
describe('POST /api/definitions', () => {
|
|
24
|
+
let app: FastifyInstance;
|
|
25
|
+
let workspaceId: string;
|
|
26
|
+
let projectId: string;
|
|
27
|
+
|
|
28
|
+
beforeAll(async () => {
|
|
29
|
+
app = Fastify();
|
|
30
|
+
app.setValidatorCompiler(validatorCompiler);
|
|
31
|
+
app.setSerializerCompiler(serializerCompiler);
|
|
32
|
+
app.addHook('onRequest', (request, _reply, done) => {
|
|
33
|
+
setUserContext(
|
|
34
|
+
request,
|
|
35
|
+
buildUserContext({
|
|
36
|
+
userId: crypto.randomUUID(),
|
|
37
|
+
email: 'user@example.com',
|
|
38
|
+
memberships: [{workspaceId, role: 'admin'}],
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
done();
|
|
42
|
+
});
|
|
43
|
+
app.post('/api/definitions', createDefinitionRoute);
|
|
44
|
+
await app.ready();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
workspaceId = crypto.randomUUID();
|
|
49
|
+
projectId = crypto.randomUUID();
|
|
50
|
+
projectAccessState.workspaceId = workspaceId;
|
|
51
|
+
projectAccessState.sourceConnectionId = crypto.randomUUID();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const validYaml = `
|
|
55
|
+
name: Test Workflow
|
|
56
|
+
runner: ubuntu-latest
|
|
57
|
+
jobs:
|
|
58
|
+
build:
|
|
59
|
+
steps:
|
|
60
|
+
- run: echo hello
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
test('valid YAML returns 200 with definition response', async () => {
|
|
64
|
+
const res = await app.inject({
|
|
65
|
+
method: 'POST',
|
|
66
|
+
url: '/api/definitions',
|
|
67
|
+
payload: {project_id: projectId, config_path: '.shipfox/workflows/test.yml', yaml: validYaml},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(res.statusCode).toBe(200);
|
|
71
|
+
const body = res.json();
|
|
72
|
+
expect(body.id).toBeDefined();
|
|
73
|
+
expect(body.project_id).toBe(projectId);
|
|
74
|
+
expect(body.config_path).toBe('.shipfox/workflows/test.yml');
|
|
75
|
+
expect(body.source).toBe('manual');
|
|
76
|
+
expect(body.name).toBe('Test Workflow');
|
|
77
|
+
expect(body.workflow_document.name).toBe('Test Workflow');
|
|
78
|
+
expect(body.workflow_model.kind).toBe('workflow');
|
|
79
|
+
expect(body.sha).toBeNull();
|
|
80
|
+
expect(body.ref).toBeNull();
|
|
81
|
+
expect(body.fetched_at).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('skips connection snapshot loading when YAML has no integrations', async () => {
|
|
85
|
+
const loadWorkspaceConnectionSnapshot = vi.fn(() => Promise.resolve(new Map()));
|
|
86
|
+
const appWithOptions = Fastify();
|
|
87
|
+
appWithOptions.setValidatorCompiler(validatorCompiler);
|
|
88
|
+
appWithOptions.setSerializerCompiler(serializerCompiler);
|
|
89
|
+
appWithOptions.addHook('onRequest', (request, _reply, done) => {
|
|
90
|
+
setUserContext(
|
|
91
|
+
request,
|
|
92
|
+
buildUserContext({
|
|
93
|
+
userId: crypto.randomUUID(),
|
|
94
|
+
email: 'user@example.com',
|
|
95
|
+
memberships: [{workspaceId, role: 'admin'}],
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
done();
|
|
99
|
+
});
|
|
100
|
+
appWithOptions.post(
|
|
101
|
+
'/api/definitions',
|
|
102
|
+
buildCreateDefinitionRoute({
|
|
103
|
+
agentToolSelectionCatalogs: new Map(),
|
|
104
|
+
loadWorkspaceConnectionSnapshot,
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
await appWithOptions.ready();
|
|
108
|
+
|
|
109
|
+
const res = await appWithOptions.inject({
|
|
110
|
+
method: 'POST',
|
|
111
|
+
url: '/api/definitions',
|
|
112
|
+
payload: {
|
|
113
|
+
project_id: projectId,
|
|
114
|
+
config_path: '.shipfox/workflows/test.yml',
|
|
115
|
+
yaml: validYaml,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(res.statusCode).toBe(200);
|
|
120
|
+
expect(loadWorkspaceConnectionSnapshot).not.toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('uses the project source connection as the default integration connection', async () => {
|
|
124
|
+
const loadWorkspaceConnectionSnapshot = vi.fn(() =>
|
|
125
|
+
Promise.resolve(
|
|
126
|
+
new Map([
|
|
127
|
+
[
|
|
128
|
+
'github-main',
|
|
129
|
+
{
|
|
130
|
+
id: projectAccessState.sourceConnectionId,
|
|
131
|
+
provider: 'github',
|
|
132
|
+
capabilities: ['agent_tools'] as const,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
]),
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
const getIntegrationConnectionById = vi.fn(() =>
|
|
139
|
+
Promise.resolve({
|
|
140
|
+
id: projectAccessState.sourceConnectionId,
|
|
141
|
+
workspaceId,
|
|
142
|
+
provider: 'github',
|
|
143
|
+
externalAccountId: 'installation-1',
|
|
144
|
+
slug: 'github-main',
|
|
145
|
+
displayName: 'GitHub',
|
|
146
|
+
lifecycleStatus: 'active' as const,
|
|
147
|
+
createdAt: new Date(),
|
|
148
|
+
updatedAt: new Date(),
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
const appWithOptions = Fastify();
|
|
152
|
+
appWithOptions.setValidatorCompiler(validatorCompiler);
|
|
153
|
+
appWithOptions.setSerializerCompiler(serializerCompiler);
|
|
154
|
+
appWithOptions.addHook('onRequest', (request, _reply, done) => {
|
|
155
|
+
setUserContext(
|
|
156
|
+
request,
|
|
157
|
+
buildUserContext({
|
|
158
|
+
userId: crypto.randomUUID(),
|
|
159
|
+
email: 'user@example.com',
|
|
160
|
+
memberships: [{workspaceId, role: 'admin'}],
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
done();
|
|
164
|
+
});
|
|
165
|
+
appWithOptions.post(
|
|
166
|
+
'/api/definitions',
|
|
167
|
+
buildCreateDefinitionRoute({
|
|
168
|
+
agentToolSelectionCatalogs: new Map([
|
|
169
|
+
[
|
|
170
|
+
'github',
|
|
171
|
+
{
|
|
172
|
+
selectors: [
|
|
173
|
+
{token: 'issue_read', kind: 'family', sensitivity: 'read', sensitive: false},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
]),
|
|
178
|
+
loadWorkspaceConnectionSnapshot,
|
|
179
|
+
getIntegrationConnectionById,
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
await appWithOptions.ready();
|
|
183
|
+
|
|
184
|
+
const res = await appWithOptions.inject({
|
|
185
|
+
method: 'POST',
|
|
186
|
+
url: '/api/definitions',
|
|
187
|
+
payload: {
|
|
188
|
+
project_id: projectId,
|
|
189
|
+
config_path: '.shipfox/workflows/test.yml',
|
|
190
|
+
yaml: `
|
|
191
|
+
name: Agent Workflow
|
|
192
|
+
runner: ubuntu-latest
|
|
193
|
+
jobs:
|
|
194
|
+
build:
|
|
195
|
+
steps:
|
|
196
|
+
- prompt: Fix the issue
|
|
197
|
+
integrations:
|
|
198
|
+
- include: [issue_read]
|
|
199
|
+
`,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
expect(res.statusCode).toBe(200);
|
|
204
|
+
expect(getIntegrationConnectionById).toHaveBeenCalledWith(
|
|
205
|
+
projectAccessState.sourceConnectionId,
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('invalid YAML syntax returns 400', async () => {
|
|
210
|
+
const res = await app.inject({
|
|
211
|
+
method: 'POST',
|
|
212
|
+
url: '/api/definitions',
|
|
213
|
+
payload: {
|
|
214
|
+
project_id: projectId,
|
|
215
|
+
config_path: 'test.yml',
|
|
216
|
+
yaml: 'name: Bad\n invalid:\nindentation',
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
expect(res.statusCode).toBe(400);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('valid YAML with invalid definition returns 400 with error code', async () => {
|
|
224
|
+
const yamlMissingName = `
|
|
225
|
+
jobs:
|
|
226
|
+
build:
|
|
227
|
+
steps:
|
|
228
|
+
- run: echo hello
|
|
229
|
+
`;
|
|
230
|
+
const res = await app.inject({
|
|
231
|
+
method: 'POST',
|
|
232
|
+
url: '/api/definitions',
|
|
233
|
+
payload: {project_id: projectId, config_path: 'test.yml', yaml: yamlMissingName},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(res.statusCode).toBe(400);
|
|
237
|
+
expect(res.json().code).toBe('invalid-workflow-definition');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('cyclic DAG returns 400 with dag error code', async () => {
|
|
241
|
+
const cyclicYaml = `
|
|
242
|
+
name: Cyclic
|
|
243
|
+
runner: ubuntu-latest
|
|
244
|
+
jobs:
|
|
245
|
+
a:
|
|
246
|
+
needs: b
|
|
247
|
+
steps:
|
|
248
|
+
- run: echo a
|
|
249
|
+
b:
|
|
250
|
+
needs: a
|
|
251
|
+
steps:
|
|
252
|
+
- run: echo b
|
|
253
|
+
`;
|
|
254
|
+
const res = await app.inject({
|
|
255
|
+
method: 'POST',
|
|
256
|
+
url: '/api/definitions',
|
|
257
|
+
payload: {project_id: projectId, config_path: 'test.yml', yaml: cyclicYaml},
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
expect(res.statusCode).toBe(400);
|
|
261
|
+
expect(res.json().code).toBe('invalid-workflow-definition');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('upsert same config_path updates the definition', async () => {
|
|
265
|
+
const payload1 = {project_id: projectId, config_path: 'deploy.yml', yaml: validYaml};
|
|
266
|
+
|
|
267
|
+
const res1 = await app.inject({
|
|
268
|
+
method: 'POST',
|
|
269
|
+
url: '/api/definitions',
|
|
270
|
+
payload: payload1,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
const updatedYaml = `
|
|
274
|
+
name: Updated Workflow
|
|
275
|
+
runner: ubuntu-latest
|
|
276
|
+
jobs:
|
|
277
|
+
deploy:
|
|
278
|
+
steps:
|
|
279
|
+
- run: ./deploy.sh
|
|
280
|
+
`;
|
|
281
|
+
const res2 = await app.inject({
|
|
282
|
+
method: 'POST',
|
|
283
|
+
url: '/api/definitions',
|
|
284
|
+
payload: {project_id: projectId, config_path: 'deploy.yml', yaml: updatedYaml},
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
expect(res2.statusCode).toBe(200);
|
|
288
|
+
expect(res2.json().id).toBe(res1.json().id);
|
|
289
|
+
expect(res2.json().name).toBe('Updated Workflow');
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('runner-less YAML returns validation details with the runner path', async () => {
|
|
293
|
+
const yaml = `
|
|
294
|
+
name: Missing Runner
|
|
295
|
+
jobs:
|
|
296
|
+
build:
|
|
297
|
+
steps:
|
|
298
|
+
- run: echo hello
|
|
299
|
+
`;
|
|
300
|
+
|
|
301
|
+
const res = await app.inject({
|
|
302
|
+
method: 'POST',
|
|
303
|
+
url: '/api/definitions',
|
|
304
|
+
payload: {project_id: projectId, config_path: 'test.yml', yaml},
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
expect(res.statusCode).toBe(400);
|
|
308
|
+
expect(res.json()).toMatchObject({
|
|
309
|
+
code: 'invalid-workflow-definition',
|
|
310
|
+
details: [expect.objectContaining({path: 'jobs.build.runner'})],
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test('missing body fields returns 400', async () => {
|
|
315
|
+
const res = await app.inject({
|
|
316
|
+
method: 'POST',
|
|
317
|
+
url: '/api/definitions',
|
|
318
|
+
payload: {},
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
expect(res.statusCode).toBe(400);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test('invalid projectId UUID returns 400', async () => {
|
|
325
|
+
const res = await app.inject({
|
|
326
|
+
method: 'POST',
|
|
327
|
+
url: '/api/definitions',
|
|
328
|
+
payload: {project_id: 'not-a-uuid', config_path: 'test.yml', yaml: validYaml},
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
expect(res.statusCode).toBe(400);
|
|
332
|
+
expect(res.json().message).toBeDefined();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test('creates a manual definition without a config path', async () => {
|
|
336
|
+
const res = await app.inject({
|
|
337
|
+
method: 'POST',
|
|
338
|
+
url: '/api/definitions',
|
|
339
|
+
payload: {project_id: projectId, yaml: validYaml},
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
expect(res.statusCode).toBe(200);
|
|
343
|
+
expect(res.json().config_path).toBeNull();
|
|
344
|
+
expect(res.json().source).toBe('manual');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('rejects a VCS definition without a config path', async () => {
|
|
348
|
+
const res = await app.inject({
|
|
349
|
+
method: 'POST',
|
|
350
|
+
url: '/api/definitions',
|
|
351
|
+
payload: {project_id: projectId, source: 'vcs', yaml: validYaml},
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
expect(res.statusCode).toBe(400);
|
|
355
|
+
});
|
|
356
|
+
});
|