@shipfox/api-runners 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 +187 -0
- package/LICENSE +21 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +208 -0
- package/dist/config.js.map +1 -0
- package/dist/core/demand.d.ts +33 -0
- package/dist/core/demand.d.ts.map +1 -0
- package/dist/core/demand.js +169 -0
- package/dist/core/demand.js.map +1 -0
- package/dist/core/entities/ephemeral-registration-token.d.ts +14 -0
- package/dist/core/entities/ephemeral-registration-token.d.ts.map +1 -0
- package/dist/core/entities/ephemeral-registration-token.js +3 -0
- package/dist/core/entities/ephemeral-registration-token.js.map +1 -0
- package/dist/core/entities/manual-registration-token.d.ts +12 -0
- package/dist/core/entities/manual-registration-token.d.ts.map +1 -0
- package/dist/core/entities/manual-registration-token.js +3 -0
- package/dist/core/entities/manual-registration-token.js.map +1 -0
- package/dist/core/entities/provisioned-runner.d.ts +24 -0
- package/dist/core/entities/provisioned-runner.d.ts.map +1 -0
- package/dist/core/entities/provisioned-runner.js +3 -0
- package/dist/core/entities/provisioned-runner.js.map +1 -0
- package/dist/core/entities/provisioner-token.d.ts +18 -0
- package/dist/core/entities/provisioner-token.d.ts.map +1 -0
- package/dist/core/entities/provisioner-token.js +3 -0
- package/dist/core/entities/provisioner-token.js.map +1 -0
- package/dist/core/entities/reservation.d.ts +10 -0
- package/dist/core/entities/reservation.d.ts.map +1 -0
- package/dist/core/entities/reservation.js +3 -0
- package/dist/core/entities/reservation.js.map +1 -0
- package/dist/core/entities/runner-session.d.ts +18 -0
- package/dist/core/entities/runner-session.d.ts.map +1 -0
- package/dist/core/entities/runner-session.js +3 -0
- package/dist/core/entities/runner-session.js.map +1 -0
- package/dist/core/ephemeral-registration-tokens.d.ts +31 -0
- package/dist/core/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/core/ephemeral-registration-tokens.js +61 -0
- package/dist/core/ephemeral-registration-tokens.js.map +1 -0
- package/dist/core/errors.d.ts +62 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +92 -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 +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/job-executions.d.ts +14 -0
- package/dist/core/job-executions.d.ts.map +1 -0
- package/dist/core/job-executions.js +37 -0
- package/dist/core/job-executions.js.map +1 -0
- package/dist/core/maintenance-policy.d.ts +2 -0
- package/dist/core/maintenance-policy.d.ts.map +1 -0
- package/dist/core/maintenance-policy.js +3 -0
- package/dist/core/maintenance-policy.js.map +1 -0
- package/dist/core/maintenance.d.ts +33 -0
- package/dist/core/maintenance.d.ts.map +1 -0
- package/dist/core/maintenance.js +55 -0
- package/dist/core/maintenance.js.map +1 -0
- package/dist/core/manual-registration-tokens.d.ts +17 -0
- package/dist/core/manual-registration-tokens.d.ts.map +1 -0
- package/dist/core/manual-registration-tokens.js +28 -0
- package/dist/core/manual-registration-tokens.js.map +1 -0
- package/dist/core/provisioned-runners.d.ts +67 -0
- package/dist/core/provisioned-runners.d.ts.map +1 -0
- package/dist/core/provisioned-runners.js +162 -0
- package/dist/core/provisioned-runners.js.map +1 -0
- package/dist/core/provisioner-tokens.d.ts +20 -0
- package/dist/core/provisioner-tokens.d.ts.map +1 -0
- package/dist/core/provisioner-tokens.js +36 -0
- package/dist/core/provisioner-tokens.js.map +1 -0
- package/dist/core/rate-limit.d.ts +35 -0
- package/dist/core/rate-limit.d.ts.map +1 -0
- package/dist/core/rate-limit.js +74 -0
- package/dist/core/rate-limit.js.map +1 -0
- package/dist/core/runner-sessions.d.ts +26 -0
- package/dist/core/runner-sessions.d.ts.map +1 -0
- package/dist/core/runner-sessions.js +41 -0
- package/dist/core/runner-sessions.js.map +1 -0
- package/dist/core/runner-tool-capabilities.d.ts +24 -0
- package/dist/core/runner-tool-capabilities.d.ts.map +1 -0
- package/dist/core/runner-tool-capabilities.js +43 -0
- package/dist/core/runner-tool-capabilities.js.map +1 -0
- package/dist/db/db.d.ts +4478 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +36 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/ephemeral-registration-tokens.d.ts +47 -0
- package/dist/db/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/db/ephemeral-registration-tokens.js +170 -0
- package/dist/db/ephemeral-registration-tokens.js.map +1 -0
- package/dist/db/index.d.ts +19 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +15 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/job-executions.d.ts +128 -0
- package/dist/db/job-executions.d.ts.map +1 -0
- package/dist/db/job-executions.js +354 -0
- package/dist/db/job-executions.js.map +1 -0
- package/dist/db/manual-registration-tokens.d.ts +16 -0
- package/dist/db/manual-registration-tokens.d.ts.map +1 -0
- package/dist/db/manual-registration-tokens.js +37 -0
- package/dist/db/manual-registration-tokens.js.map +1 -0
- package/dist/db/provisioned-runners.d.ts +79 -0
- package/dist/db/provisioned-runners.d.ts.map +1 -0
- package/dist/db/provisioned-runners.js +466 -0
- package/dist/db/provisioned-runners.js.map +1 -0
- package/dist/db/provisioner-tokens.d.ts +26 -0
- package/dist/db/provisioner-tokens.d.ts.map +1 -0
- package/dist/db/provisioner-tokens.js +54 -0
- package/dist/db/provisioner-tokens.js.map +1 -0
- package/dist/db/rate-limits.d.ts +18 -0
- package/dist/db/rate-limits.d.ts.map +1 -0
- package/dist/db/rate-limits.js +44 -0
- package/dist/db/rate-limits.js.map +1 -0
- package/dist/db/reservations.d.ts +48 -0
- package/dist/db/reservations.d.ts.map +1 -0
- package/dist/db/reservations.js +162 -0
- package/dist/db/reservations.js.map +1 -0
- package/dist/db/runner-sessions.d.ts +18 -0
- package/dist/db/runner-sessions.d.ts.map +1 -0
- package/dist/db/runner-sessions.js +38 -0
- package/dist/db/runner-sessions.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/ephemeral-registration-tokens.d.ts +199 -0
- package/dist/db/schema/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/db/schema/ephemeral-registration-tokens.js +45 -0
- package/dist/db/schema/ephemeral-registration-tokens.js.map +1 -0
- package/dist/db/schema/manual-registration-tokens.d.ts +165 -0
- package/dist/db/schema/manual-registration-tokens.d.ts.map +1 -0
- package/dist/db/schema/manual-registration-tokens.js +40 -0
- package/dist/db/schema/manual-registration-tokens.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/pending-job-executions.d.ts +189 -0
- package/dist/db/schema/pending-job-executions.d.ts.map +1 -0
- package/dist/db/schema/pending-job-executions.js +21 -0
- package/dist/db/schema/pending-job-executions.js.map +1 -0
- package/dist/db/schema/provisioned-runners.d.ts +379 -0
- package/dist/db/schema/provisioned-runners.d.ts.map +1 -0
- package/dist/db/schema/provisioned-runners.js +83 -0
- package/dist/db/schema/provisioned-runners.js.map +1 -0
- package/dist/db/schema/provisioner-tokens.d.ts +216 -0
- package/dist/db/schema/provisioner-tokens.d.ts.map +1 -0
- package/dist/db/schema/provisioner-tokens.js +48 -0
- package/dist/db/schema/provisioner-tokens.js.map +1 -0
- package/dist/db/schema/rate-limits.d.ts +145 -0
- package/dist/db/schema/rate-limits.d.ts.map +1 -0
- package/dist/db/schema/rate-limits.js +25 -0
- package/dist/db/schema/rate-limits.js.map +1 -0
- package/dist/db/schema/reservations.d.ts +157 -0
- package/dist/db/schema/reservations.d.ts.map +1 -0
- package/dist/db/schema/reservations.js +34 -0
- package/dist/db/schema/reservations.js.map +1 -0
- package/dist/db/schema/runner-sessions.d.ts +298 -0
- package/dist/db/schema/runner-sessions.d.ts.map +1 -0
- package/dist/db/schema/runner-sessions.js +61 -0
- package/dist/db/schema/runner-sessions.js.map +1 -0
- package/dist/db/schema/running-job-executions.d.ts +334 -0
- package/dist/db/schema/running-job-executions.d.ts.map +1 -0
- package/dist/db/schema/running-job-executions.js +41 -0
- package/dist/db/schema/running-job-executions.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +3 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +4 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +34 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +60 -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 +21 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/auth/index.d.ts +3 -0
- package/dist/presentation/auth/index.d.ts.map +1 -0
- package/dist/presentation/auth/index.js +4 -0
- package/dist/presentation/auth/index.js.map +1 -0
- package/dist/presentation/auth/provisioner-token-auth.d.ts +3 -0
- package/dist/presentation/auth/provisioner-token-auth.d.ts.map +1 -0
- package/dist/presentation/auth/provisioner-token-auth.js +81 -0
- package/dist/presentation/auth/provisioner-token-auth.js.map +1 -0
- package/dist/presentation/auth/runner-registration-token-auth.d.ts +17 -0
- package/dist/presentation/auth/runner-registration-token-auth.d.ts.map +1 -0
- package/dist/presentation/auth/runner-registration-token-auth.js +77 -0
- package/dist/presentation/auth/runner-registration-token-auth.js.map +1 -0
- package/dist/presentation/dto/active-provisioner.d.ts +8 -0
- package/dist/presentation/dto/active-provisioner.d.ts.map +1 -0
- package/dist/presentation/dto/active-provisioner.js +10 -0
- package/dist/presentation/dto/active-provisioner.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +7 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +8 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/dto/manual-registration-token.d.ts +12 -0
- package/dist/presentation/dto/manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/dto/manual-registration-token.js +14 -0
- package/dist/presentation/dto/manual-registration-token.js.map +1 -0
- package/dist/presentation/dto/mint-registration-tokens.d.ts +5 -0
- package/dist/presentation/dto/mint-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/dto/mint-registration-tokens.js +19 -0
- package/dist/presentation/dto/mint-registration-tokens.js.map +1 -0
- package/dist/presentation/dto/poll-demand.d.ts +4 -0
- package/dist/presentation/dto/poll-demand.d.ts.map +1 -0
- package/dist/presentation/dto/poll-demand.js +19 -0
- package/dist/presentation/dto/poll-demand.js.map +1 -0
- package/dist/presentation/dto/provisioned-runners.d.ts +38 -0
- package/dist/presentation/dto/provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/dto/provisioned-runners.js +44 -0
- package/dist/presentation/dto/provisioned-runners.js.map +1 -0
- package/dist/presentation/dto/provisioner-token.d.ts +15 -0
- package/dist/presentation/dto/provisioner-token.d.ts.map +1 -0
- package/dist/presentation/dto/provisioner-token.js +17 -0
- package/dist/presentation/dto/provisioner-token.js.map +1 -0
- package/dist/presentation/index.d.ts +4 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +5 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/create-manual-registration-token.d.ts +2 -0
- package/dist/presentation/routes/create-manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/routes/create-manual-registration-token.js +44 -0
- package/dist/presentation/routes/create-manual-registration-token.js.map +1 -0
- package/dist/presentation/routes/create-provisioner-token.d.ts +2 -0
- package/dist/presentation/routes/create-provisioner-token.d.ts.map +1 -0
- package/dist/presentation/routes/create-provisioner-token.js +42 -0
- package/dist/presentation/routes/create-provisioner-token.js.map +1 -0
- package/dist/presentation/routes/get-provisioner-me.d.ts +2 -0
- package/dist/presentation/routes/get-provisioner-me.d.ts.map +1 -0
- package/dist/presentation/routes/get-provisioner-me.js +22 -0
- package/dist/presentation/routes/get-provisioner-me.js.map +1 -0
- package/dist/presentation/routes/heartbeat.d.ts +2 -0
- package/dist/presentation/routes/heartbeat.d.ts.map +1 -0
- package/dist/presentation/routes/heartbeat.js +64 -0
- package/dist/presentation/routes/heartbeat.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 +97 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-active-provisioners.d.ts +2 -0
- package/dist/presentation/routes/list-active-provisioners.d.ts.map +1 -0
- package/dist/presentation/routes/list-active-provisioners.js +32 -0
- package/dist/presentation/routes/list-active-provisioners.js.map +1 -0
- package/dist/presentation/routes/list-active-runners.d.ts +2 -0
- package/dist/presentation/routes/list-active-runners.d.ts.map +1 -0
- package/dist/presentation/routes/list-active-runners.js +32 -0
- package/dist/presentation/routes/list-active-runners.js.map +1 -0
- package/dist/presentation/routes/list-manual-registration-tokens.d.ts +2 -0
- package/dist/presentation/routes/list-manual-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/list-manual-registration-tokens.js +32 -0
- package/dist/presentation/routes/list-manual-registration-tokens.js.map +1 -0
- package/dist/presentation/routes/list-provisioner-tokens.d.ts +2 -0
- package/dist/presentation/routes/list-provisioner-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/list-provisioner-tokens.js +32 -0
- package/dist/presentation/routes/list-provisioner-tokens.js.map +1 -0
- package/dist/presentation/routes/mint-registration-tokens.d.ts +2 -0
- package/dist/presentation/routes/mint-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/mint-registration-tokens.js +74 -0
- package/dist/presentation/routes/mint-registration-tokens.js.map +1 -0
- package/dist/presentation/routes/poll-demand.d.ts +2 -0
- package/dist/presentation/routes/poll-demand.d.ts.map +1 -0
- package/dist/presentation/routes/poll-demand.js +53 -0
- package/dist/presentation/routes/poll-demand.js.map +1 -0
- package/dist/presentation/routes/rate-limit.d.ts +4 -0
- package/dist/presentation/routes/rate-limit.d.ts.map +1 -0
- package/dist/presentation/routes/rate-limit.js +94 -0
- package/dist/presentation/routes/rate-limit.js.map +1 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.d.ts +2 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.js +27 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.js.map +1 -0
- package/dist/presentation/routes/register.d.ts +2 -0
- package/dist/presentation/routes/register.d.ts.map +1 -0
- package/dist/presentation/routes/register.js +63 -0
- package/dist/presentation/routes/register.js.map +1 -0
- package/dist/presentation/routes/report-provisioned-runners.d.ts +2 -0
- package/dist/presentation/routes/report-provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/routes/report-provisioned-runners.js +37 -0
- package/dist/presentation/routes/report-provisioned-runners.js.map +1 -0
- package/dist/presentation/routes/request-job.d.ts +2 -0
- package/dist/presentation/routes/request-job.d.ts.map +1 -0
- package/dist/presentation/routes/request-job.js +45 -0
- package/dist/presentation/routes/request-job.js.map +1 -0
- package/dist/presentation/routes/revoke-manual-registration-token.d.ts +2 -0
- package/dist/presentation/routes/revoke-manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/routes/revoke-manual-registration-token.js +42 -0
- package/dist/presentation/routes/revoke-manual-registration-token.js.map +1 -0
- package/dist/presentation/routes/revoke-provisioner-token.d.ts +2 -0
- package/dist/presentation/routes/revoke-provisioner-token.d.ts.map +1 -0
- package/dist/presentation/routes/revoke-provisioner-token.js +44 -0
- package/dist/presentation/routes/revoke-provisioner-token.js.map +1 -0
- package/dist/presentation/routes/workspace-membership.d.ts +6 -0
- package/dist/presentation/routes/workspace-membership.d.ts.map +1 -0
- package/dist/presentation/routes/workspace-membership.js +6 -0
- package/dist/presentation/routes/workspace-membership.js.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.js +14 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +9 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +12 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/maintenance-activities.d.ts +31 -0
- package/dist/temporal/activities/maintenance-activities.d.ts.map +1 -0
- package/dist/temporal/activities/maintenance-activities.js +18 -0
- package/dist/temporal/activities/maintenance-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +2 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +3 -0
- package/dist/temporal/constants.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/temporal/workflows/stuck-job-detector.d.ts +2 -0
- package/dist/temporal/workflows/stuck-job-detector.d.ts.map +1 -0
- package/dist/temporal/workflows/stuck-job-detector.js +61 -0
- package/dist/temporal/workflows/stuck-job-detector.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +185 -0
- package/drizzle/meta/0000_snapshot.json +1582 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +82 -0
- package/src/config.test.ts +374 -0
- package/src/config.ts +330 -0
- package/src/core/demand.test.ts +301 -0
- package/src/core/demand.ts +239 -0
- package/src/core/entities/ephemeral-registration-token.ts +13 -0
- package/src/core/entities/manual-registration-token.ts +11 -0
- package/src/core/entities/provisioned-runner.ts +30 -0
- package/src/core/entities/provisioner-token.ts +16 -0
- package/src/core/entities/reservation.ts +9 -0
- package/src/core/entities/runner-session.ts +18 -0
- package/src/core/ephemeral-registration-tokens.test.ts +108 -0
- package/src/core/ephemeral-registration-tokens.ts +112 -0
- package/src/core/errors.ts +128 -0
- package/src/core/index.ts +56 -0
- package/src/core/job-executions.ts +47 -0
- package/src/core/maintenance-policy.ts +1 -0
- package/src/core/maintenance.test.ts +251 -0
- package/src/core/maintenance.ts +74 -0
- package/src/core/manual-registration-tokens.test.ts +44 -0
- package/src/core/manual-registration-tokens.ts +51 -0
- package/src/core/provisioned-runners.test.ts +101 -0
- package/src/core/provisioned-runners.ts +301 -0
- package/src/core/provisioner-tokens.test.ts +61 -0
- package/src/core/provisioner-tokens.ts +61 -0
- package/src/core/rate-limit.test.ts +158 -0
- package/src/core/rate-limit.ts +121 -0
- package/src/core/runner-sessions.test.ts +209 -0
- package/src/core/runner-sessions.ts +66 -0
- package/src/core/runner-tool-capabilities.test.ts +141 -0
- package/src/core/runner-tool-capabilities.ts +75 -0
- package/src/db/db.ts +38 -0
- package/src/db/ephemeral-registration-tokens.test.ts +332 -0
- package/src/db/ephemeral-registration-tokens.ts +348 -0
- package/src/db/index.ts +90 -0
- package/src/db/job-executions.test.ts +1500 -0
- package/src/db/job-executions.ts +647 -0
- package/src/db/manual-registration-tokens.test.ts +99 -0
- package/src/db/manual-registration-tokens.ts +87 -0
- package/src/db/provisioned-runners.test.ts +1812 -0
- package/src/db/provisioned-runners.ts +886 -0
- package/src/db/provisioner-tokens.test.ts +133 -0
- package/src/db/provisioner-tokens.ts +142 -0
- package/src/db/rate-limits.test.ts +74 -0
- package/src/db/rate-limits.ts +69 -0
- package/src/db/reservations.test.ts +399 -0
- package/src/db/reservations.ts +296 -0
- package/src/db/runner-sessions.test.ts +153 -0
- package/src/db/runner-sessions.ts +97 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/ephemeral-registration-tokens.ts +58 -0
- package/src/db/schema/manual-registration-tokens.ts +40 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/pending-job-executions.ts +25 -0
- package/src/db/schema/provisioned-runners.ts +89 -0
- package/src/db/schema/provisioner-tokens.ts +50 -0
- package/src/db/schema/rate-limits.ts +27 -0
- package/src/db/schema/reservations.ts +38 -0
- package/src/db/schema/runner-sessions.ts +77 -0
- package/src/db/schema/running-job-executions.ts +50 -0
- package/src/index.ts +63 -0
- package/src/metrics/index.ts +13 -0
- package/src/metrics/instance.ts +115 -0
- package/src/metrics/service.ts +22 -0
- package/src/presentation/auth/index.ts +6 -0
- package/src/presentation/auth/provisioner-token-auth.ts +76 -0
- package/src/presentation/auth/runner-registration-token-auth.ts +105 -0
- package/src/presentation/dto/active-provisioner.ts +15 -0
- package/src/presentation/dto/index.ts +13 -0
- package/src/presentation/dto/manual-registration-token.ts +23 -0
- package/src/presentation/dto/mint-registration-tokens.ts +35 -0
- package/src/presentation/dto/poll-demand.ts +20 -0
- package/src/presentation/dto/provisioned-runners.ts +88 -0
- package/src/presentation/dto/provisioner-token.ts +29 -0
- package/src/presentation/index.ts +6 -0
- package/src/presentation/routes/create-manual-registration-token.ts +43 -0
- package/src/presentation/routes/create-provisioner-token.ts +41 -0
- package/src/presentation/routes/get-provisioner-me.ts +22 -0
- package/src/presentation/routes/heartbeat.test.ts +325 -0
- package/src/presentation/routes/heartbeat.ts +80 -0
- package/src/presentation/routes/index.ts +86 -0
- package/src/presentation/routes/list-active-provisioners.ts +25 -0
- package/src/presentation/routes/list-active-runners.test.ts +366 -0
- package/src/presentation/routes/list-active-runners.ts +25 -0
- package/src/presentation/routes/list-manual-registration-tokens.ts +25 -0
- package/src/presentation/routes/list-provisioner-tokens.ts +25 -0
- package/src/presentation/routes/manual-registration-tokens.test.ts +213 -0
- package/src/presentation/routes/mint-registration-tokens.test.ts +453 -0
- package/src/presentation/routes/mint-registration-tokens.ts +82 -0
- package/src/presentation/routes/poll-demand-release.test.ts +80 -0
- package/src/presentation/routes/poll-demand.test.ts +323 -0
- package/src/presentation/routes/poll-demand.ts +56 -0
- package/src/presentation/routes/provisioner-me.test.ts +172 -0
- package/src/presentation/routes/provisioner-tokens.test.ts +219 -0
- package/src/presentation/routes/rate-limit.ts +115 -0
- package/src/presentation/routes/reconcile-provisioned-runners.test.ts +380 -0
- package/src/presentation/routes/reconcile-provisioned-runners.ts +30 -0
- package/src/presentation/routes/register.test.ts +453 -0
- package/src/presentation/routes/register.ts +75 -0
- package/src/presentation/routes/report-provisioned-runners.test.ts +249 -0
- package/src/presentation/routes/report-provisioned-runners.ts +40 -0
- package/src/presentation/routes/request-job.test.ts +222 -0
- package/src/presentation/routes/request-job.ts +47 -0
- package/src/presentation/routes/revoke-manual-registration-token.ts +35 -0
- package/src/presentation/routes/revoke-provisioner-token.ts +37 -0
- package/src/presentation/routes/workspace-membership.ts +9 -0
- package/src/presentation/subscribers/on-workflows-job-execution-timed-out.test.ts +147 -0
- package/src/presentation/subscribers/on-workflows-job-execution-timed-out.ts +17 -0
- package/src/temporal/activities/index.ts +17 -0
- package/src/temporal/activities/maintenance-activities.test.ts +104 -0
- package/src/temporal/activities/maintenance-activities.ts +41 -0
- package/src/temporal/constants.ts +1 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/src/temporal/workflows/stuck-job-detector.test.ts +93 -0
- package/src/temporal/workflows/stuck-job-detector.ts +67 -0
- package/test/env.ts +11 -0
- package/test/factories/ephemeral-registration-token.ts +41 -0
- package/test/factories/manual-registration-token.ts +37 -0
- package/test/factories/pending-job.ts +44 -0
- package/test/factories/provisioned-runner.ts +78 -0
- package/test/factories/provisioner-token.ts +41 -0
- package/test/factories/reservation.ts +33 -0
- package/test/factories/runner-session.ts +32 -0
- package/test/globalSetup.ts +23 -0
- package/test/index.ts +16 -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 +14 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUTH_LEASED_JOB,
|
|
3
|
+
AUTH_PROVISIONER_TOKEN,
|
|
4
|
+
AUTH_RUNNER_REGISTRATION_TOKEN,
|
|
5
|
+
AUTH_RUNNER_SESSION,
|
|
6
|
+
AUTH_USER,
|
|
7
|
+
setProvisionerContext,
|
|
8
|
+
} from '@shipfox/api-auth-context';
|
|
9
|
+
import {
|
|
10
|
+
type AuthMethod,
|
|
11
|
+
ClientError,
|
|
12
|
+
closeApp,
|
|
13
|
+
createApp,
|
|
14
|
+
extractBearerToken,
|
|
15
|
+
} from '@shipfox/node-fastify';
|
|
16
|
+
import {vi} from '@shipfox/vitest/vi';
|
|
17
|
+
import {and, eq} from 'drizzle-orm';
|
|
18
|
+
import type {FastifyInstance, FastifyRequest} from 'fastify';
|
|
19
|
+
import {db} from '#db/db.js';
|
|
20
|
+
import {provisionedRunners} from '#db/schema/provisioned-runners.js';
|
|
21
|
+
import {runningJobExecutions} from '#db/schema/running-job-executions.js';
|
|
22
|
+
import {provisionedRunnerTerminateIntentHonoredCount} from '#metrics/instance.js';
|
|
23
|
+
import {provisionedRunnerFactory, runnerSessionFactory} from '#test/index.js';
|
|
24
|
+
import {runnerRoutes} from './index.js';
|
|
25
|
+
|
|
26
|
+
const VALID_PROVISIONER_TOKEN = 'valid-provisioner-token';
|
|
27
|
+
|
|
28
|
+
const passthroughAuth = (name: string): AuthMethod => ({
|
|
29
|
+
name,
|
|
30
|
+
authenticate: () => Promise.resolve(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('POST /provisioners/provisioned-runners/report', () => {
|
|
34
|
+
let app: FastifyInstance;
|
|
35
|
+
let workspaceId: string;
|
|
36
|
+
let provisionerTokenId: string;
|
|
37
|
+
|
|
38
|
+
const fakeProvisionerAuth: AuthMethod = {
|
|
39
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
40
|
+
authenticate: (request: FastifyRequest) => {
|
|
41
|
+
const rawToken = extractBearerToken(request.headers.authorization);
|
|
42
|
+
if (rawToken !== VALID_PROVISIONER_TOKEN) {
|
|
43
|
+
throw new ClientError('Invalid provisioner token', 'unauthorized', {status: 401});
|
|
44
|
+
}
|
|
45
|
+
setProvisionerContext(request, {workspaceId, provisionerTokenId});
|
|
46
|
+
return Promise.resolve();
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
beforeAll(async () => {
|
|
51
|
+
app = await createApp({
|
|
52
|
+
auth: [
|
|
53
|
+
passthroughAuth(AUTH_USER),
|
|
54
|
+
passthroughAuth(AUTH_RUNNER_REGISTRATION_TOKEN),
|
|
55
|
+
passthroughAuth(AUTH_RUNNER_SESSION),
|
|
56
|
+
passthroughAuth(AUTH_LEASED_JOB),
|
|
57
|
+
fakeProvisionerAuth,
|
|
58
|
+
],
|
|
59
|
+
routes: runnerRoutes,
|
|
60
|
+
swagger: false,
|
|
61
|
+
});
|
|
62
|
+
await app.ready();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterAll(async () => {
|
|
66
|
+
await closeApp();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
beforeEach(() => {
|
|
70
|
+
workspaceId = crypto.randomUUID();
|
|
71
|
+
provisionerTokenId = crypto.randomUUID();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('accepts provisioned runner lifecycle reports from provisioner auth', async () => {
|
|
75
|
+
const reportedAt = '2025-01-01T00:00:00.000Z';
|
|
76
|
+
|
|
77
|
+
const res = await app.inject({
|
|
78
|
+
method: 'POST',
|
|
79
|
+
url: '/provisioners/provisioned-runners/report',
|
|
80
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
81
|
+
payload: {
|
|
82
|
+
events: [
|
|
83
|
+
{
|
|
84
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
85
|
+
labels: ['linux'],
|
|
86
|
+
state: 'starting',
|
|
87
|
+
reported_at: reportedAt,
|
|
88
|
+
provider_kind: 'docker',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const rows = await db()
|
|
95
|
+
.select()
|
|
96
|
+
.from(provisionedRunners)
|
|
97
|
+
.where(
|
|
98
|
+
and(
|
|
99
|
+
eq(provisionedRunners.workspaceId, workspaceId),
|
|
100
|
+
eq(provisionedRunners.provisionerId, provisionerTokenId),
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
expect(res.statusCode).toBe(200);
|
|
104
|
+
expect(res.json()).toEqual({accepted: 1, reservations_released: 0});
|
|
105
|
+
expect(rows[0]).toMatchObject({
|
|
106
|
+
workspaceId,
|
|
107
|
+
provisionerId: provisionerTokenId,
|
|
108
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
109
|
+
state: 'starting',
|
|
110
|
+
labels: ['linux'],
|
|
111
|
+
providerKind: 'docker',
|
|
112
|
+
});
|
|
113
|
+
expect(rows[0]?.reportedAt.toISOString()).toBe(reportedAt);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('returns 400 when the batch exceeds the DTO limit', async () => {
|
|
117
|
+
const event = {
|
|
118
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
119
|
+
labels: ['linux'],
|
|
120
|
+
state: 'running',
|
|
121
|
+
reported_at: new Date().toISOString(),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const res = await app.inject({
|
|
125
|
+
method: 'POST',
|
|
126
|
+
url: '/provisioners/provisioned-runners/report',
|
|
127
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
128
|
+
payload: {
|
|
129
|
+
events: Array.from({length: 1001}, (_, index) => ({
|
|
130
|
+
...event,
|
|
131
|
+
provisioned_runner_id: `provisioned-runner-${index}`,
|
|
132
|
+
})),
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(res.statusCode).toBe(400);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('increments the honored terminate-intent metric once for a terminated report', async () => {
|
|
140
|
+
const honoredSpy = vi.spyOn(provisionedRunnerTerminateIntentHonoredCount, 'add');
|
|
141
|
+
const runnerSession = await runnerSessionFactory.create({workspaceId});
|
|
142
|
+
await provisionedRunnerFactory.create({
|
|
143
|
+
workspaceId,
|
|
144
|
+
provisionerId: provisionerTokenId,
|
|
145
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
146
|
+
state: 'running',
|
|
147
|
+
});
|
|
148
|
+
await db()
|
|
149
|
+
.insert(runningJobExecutions)
|
|
150
|
+
.values({
|
|
151
|
+
workspaceId,
|
|
152
|
+
workflowRunId: crypto.randomUUID(),
|
|
153
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
154
|
+
jobId: crypto.randomUUID(),
|
|
155
|
+
jobExecutionId: crypto.randomUUID(),
|
|
156
|
+
projectId: crypto.randomUUID(),
|
|
157
|
+
runnerSessionId: runnerSession.id,
|
|
158
|
+
provisionerId: provisionerTokenId,
|
|
159
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
160
|
+
requiredLabels: ['linux'],
|
|
161
|
+
runnerLabels: ['linux'],
|
|
162
|
+
startedAt: new Date('2025-01-01T00:00:00.000Z'),
|
|
163
|
+
lastHeartbeatAt: new Date('2025-01-01T00:00:00.000Z'),
|
|
164
|
+
cancellationRequestedAt: new Date('2025-01-01T00:01:00.000Z'),
|
|
165
|
+
});
|
|
166
|
+
const honoredCallsBefore = honoredSpy.mock.calls.length;
|
|
167
|
+
|
|
168
|
+
const first = await app.inject({
|
|
169
|
+
method: 'POST',
|
|
170
|
+
url: '/provisioners/provisioned-runners/report',
|
|
171
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
172
|
+
payload: {
|
|
173
|
+
events: [
|
|
174
|
+
{
|
|
175
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
176
|
+
labels: ['linux'],
|
|
177
|
+
state: 'terminated',
|
|
178
|
+
reported_at: new Date().toISOString(),
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
const second = await app.inject({
|
|
184
|
+
method: 'POST',
|
|
185
|
+
url: '/provisioners/provisioned-runners/report',
|
|
186
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
187
|
+
payload: {
|
|
188
|
+
events: [
|
|
189
|
+
{
|
|
190
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
191
|
+
labels: ['linux'],
|
|
192
|
+
state: 'terminated',
|
|
193
|
+
reported_at: new Date().toISOString(),
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
expect(first.statusCode).toBe(200);
|
|
200
|
+
expect(second.statusCode).toBe(200);
|
|
201
|
+
const honoredCalls = honoredSpy.mock.calls
|
|
202
|
+
.slice(honoredCallsBefore)
|
|
203
|
+
.filter(
|
|
204
|
+
([value, attributes]) =>
|
|
205
|
+
value === 1 && JSON.stringify(attributes) === JSON.stringify({reason: 'job-cancelled'}),
|
|
206
|
+
);
|
|
207
|
+
expect(honoredCalls).toHaveLength(1);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('returns 400 for provider-sensitive extra fields', async () => {
|
|
211
|
+
const res = await app.inject({
|
|
212
|
+
method: 'POST',
|
|
213
|
+
url: '/provisioners/provisioned-runners/report',
|
|
214
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
215
|
+
payload: {
|
|
216
|
+
events: [
|
|
217
|
+
{
|
|
218
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
219
|
+
labels: ['linux'],
|
|
220
|
+
state: 'running',
|
|
221
|
+
reported_at: new Date().toISOString(),
|
|
222
|
+
hostname: 'worker-1',
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
expect(res.statusCode).toBe(400);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('returns 401 without provisioner auth', async () => {
|
|
232
|
+
const res = await app.inject({
|
|
233
|
+
method: 'POST',
|
|
234
|
+
url: '/provisioners/provisioned-runners/report',
|
|
235
|
+
payload: {
|
|
236
|
+
events: [
|
|
237
|
+
{
|
|
238
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
239
|
+
labels: ['linux'],
|
|
240
|
+
state: 'running',
|
|
241
|
+
reported_at: new Date().toISOString(),
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(res.statusCode).toBe(401);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {requireProvisionerContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {
|
|
3
|
+
reportProvisionedRunnersBodySchema,
|
|
4
|
+
reportProvisionedRunnersResponseSchema,
|
|
5
|
+
} from '@shipfox/api-runners-dto';
|
|
6
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
7
|
+
import {reportProvisionedRunners} from '#core/index.js';
|
|
8
|
+
import {toReportProvisionedRunnersResponseDto} from '#presentation/dto/index.js';
|
|
9
|
+
|
|
10
|
+
export const reportProvisionedRunnersRoute = defineRoute({
|
|
11
|
+
method: 'POST',
|
|
12
|
+
path: '/provisioned-runners/report',
|
|
13
|
+
description: 'Report provisioned runner lifecycle state',
|
|
14
|
+
schema: {
|
|
15
|
+
body: reportProvisionedRunnersBodySchema,
|
|
16
|
+
response: {
|
|
17
|
+
200: reportProvisionedRunnersResponseSchema,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
handler: async (request) => {
|
|
21
|
+
const {provisionerTokenId, workspaceId} = requireProvisionerContext(request);
|
|
22
|
+
const result = await reportProvisionedRunners({
|
|
23
|
+
workspaceId,
|
|
24
|
+
provisionerId: provisionerTokenId,
|
|
25
|
+
events: request.body.events.map((event) => ({
|
|
26
|
+
provisionedRunnerId: event.provisioned_runner_id,
|
|
27
|
+
reservationId: event.reservation_id ?? null,
|
|
28
|
+
templateKey: event.template_key ?? null,
|
|
29
|
+
labels: event.labels,
|
|
30
|
+
state: event.state,
|
|
31
|
+
reason: event.reason ?? null,
|
|
32
|
+
runnerSessionId: event.runner_session_id ?? null,
|
|
33
|
+
providerKind: event.provider_kind ?? null,
|
|
34
|
+
reportedAt: new Date(event.reported_at),
|
|
35
|
+
})),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return toReportProvisionedRunnersResponseDto(result);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLeaseTokenAuthMethod,
|
|
3
|
+
createRunnerSessionAuthMethod,
|
|
4
|
+
verifyJobLeaseToken,
|
|
5
|
+
} from '@shipfox/api-auth';
|
|
6
|
+
import {AUTH_PROVISIONER_TOKEN, AUTH_USER} from '@shipfox/api-auth-context';
|
|
7
|
+
import {RUNNER_SESSION_TOKEN_AUDIENCE} from '@shipfox/api-auth-dto';
|
|
8
|
+
import type {AuthMethod} from '@shipfox/node-fastify';
|
|
9
|
+
import {closeApp, createApp} from '@shipfox/node-fastify';
|
|
10
|
+
import {signHs256} from '@shipfox/node-jwt';
|
|
11
|
+
import {generateOpaqueToken} from '@shipfox/node-tokens';
|
|
12
|
+
import type {FastifyInstance} from 'fastify';
|
|
13
|
+
import {createRunnerRegistrationTokenAuthMethod} from '#presentation/auth/index.js';
|
|
14
|
+
import {
|
|
15
|
+
ephemeralRegistrationTokenFactory,
|
|
16
|
+
manualRegistrationTokenFactory,
|
|
17
|
+
pendingJobFactory,
|
|
18
|
+
} from '#test/index.js';
|
|
19
|
+
import {runnerRoutes} from './index.js';
|
|
20
|
+
|
|
21
|
+
const fakeUserAuth: AuthMethod = {
|
|
22
|
+
name: AUTH_USER,
|
|
23
|
+
authenticate: () => Promise.resolve(),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const fakeProvisionerAuth: AuthMethod = {
|
|
27
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
28
|
+
authenticate: () => Promise.resolve(),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
describe('POST /runners/jobs/request', () => {
|
|
32
|
+
let app: FastifyInstance;
|
|
33
|
+
let rawToken: string;
|
|
34
|
+
let workspaceId: string;
|
|
35
|
+
let sessionToken: string;
|
|
36
|
+
let runnerSessionId: string;
|
|
37
|
+
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
app = await createApp({
|
|
40
|
+
auth: [
|
|
41
|
+
fakeUserAuth,
|
|
42
|
+
createRunnerRegistrationTokenAuthMethod(),
|
|
43
|
+
createRunnerSessionAuthMethod(),
|
|
44
|
+
createLeaseTokenAuthMethod(),
|
|
45
|
+
fakeProvisionerAuth,
|
|
46
|
+
],
|
|
47
|
+
routes: runnerRoutes,
|
|
48
|
+
swagger: false,
|
|
49
|
+
});
|
|
50
|
+
await app.ready();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterAll(async () => {
|
|
54
|
+
await closeApp();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
beforeEach(async () => {
|
|
58
|
+
rawToken = `sf_mrt_${crypto.randomUUID()}`;
|
|
59
|
+
workspaceId = crypto.randomUUID();
|
|
60
|
+
await manualRegistrationTokenFactory.create({workspaceId}, {transient: {rawToken}});
|
|
61
|
+
const registered = await registerSession(rawToken);
|
|
62
|
+
sessionToken = registered.sessionToken;
|
|
63
|
+
runnerSessionId = registered.runnerSessionId;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
async function registerSession(
|
|
67
|
+
token: string,
|
|
68
|
+
): Promise<{sessionToken: string; runnerSessionId: string}> {
|
|
69
|
+
const res = await app.inject({
|
|
70
|
+
method: 'POST',
|
|
71
|
+
url: '/runners/register',
|
|
72
|
+
headers: {authorization: `Bearer ${token}`},
|
|
73
|
+
payload: {labels: ['Linux', 'x64']},
|
|
74
|
+
});
|
|
75
|
+
expect(res.statusCode).toBe(200);
|
|
76
|
+
const body = res.json();
|
|
77
|
+
return {sessionToken: body.session_token, runnerSessionId: body.session_id};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
it('returns 401 without authorization', async () => {
|
|
81
|
+
const res = await app.inject({
|
|
82
|
+
method: 'POST',
|
|
83
|
+
url: '/runners/jobs/request',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(res.statusCode).toBe(401);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('returns 401 with an invalid runner session token', async () => {
|
|
90
|
+
const res = await app.inject({
|
|
91
|
+
method: 'POST',
|
|
92
|
+
url: '/runners/jobs/request',
|
|
93
|
+
headers: {authorization: 'Bearer invalid'},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(res.statusCode).toBe(401);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('returns 200 with the job ids and a verifiable lease token when a job is available', async () => {
|
|
100
|
+
const created = await pendingJobFactory.create({workspaceId});
|
|
101
|
+
|
|
102
|
+
const res = await app.inject({
|
|
103
|
+
method: 'POST',
|
|
104
|
+
url: '/runners/jobs/request',
|
|
105
|
+
headers: {authorization: `Bearer ${sessionToken}`},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(res.statusCode).toBe(200);
|
|
109
|
+
const body = res.json();
|
|
110
|
+
expect(body.job_id).toBe(created.jobId);
|
|
111
|
+
expect(body.workflow_run_id).toBe(created.workflowRunId);
|
|
112
|
+
expect(body.workflow_run_attempt_id).toBe(created.workflowRunAttemptId);
|
|
113
|
+
expect(typeof body.lease_token).toBe('string');
|
|
114
|
+
expect(body.job_name).toBeUndefined();
|
|
115
|
+
expect(body.steps).toBeUndefined();
|
|
116
|
+
|
|
117
|
+
const claims = await verifyJobLeaseToken(body.lease_token);
|
|
118
|
+
expect(claims).toMatchObject({
|
|
119
|
+
jobId: created.jobId,
|
|
120
|
+
workflowRunId: created.workflowRunId,
|
|
121
|
+
workflowRunAttemptId: created.workflowRunAttemptId,
|
|
122
|
+
projectId: created.projectId,
|
|
123
|
+
workspaceId,
|
|
124
|
+
runnerSessionId,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('returns 204 when no jobs are available for the session workspace', async () => {
|
|
129
|
+
await pendingJobFactory.create({workspaceId: crypto.randomUUID()});
|
|
130
|
+
|
|
131
|
+
const res = await app.inject({
|
|
132
|
+
method: 'POST',
|
|
133
|
+
url: '/runners/jobs/request',
|
|
134
|
+
headers: {authorization: `Bearer ${sessionToken}`},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(res.statusCode).toBe(204);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('returns 204 when no pending job matches the session labels', async () => {
|
|
141
|
+
await pendingJobFactory.create({workspaceId, requiredLabels: ['macos']});
|
|
142
|
+
|
|
143
|
+
const res = await app.inject({
|
|
144
|
+
method: 'POST',
|
|
145
|
+
url: '/runners/jobs/request',
|
|
146
|
+
headers: {authorization: `Bearer ${sessionToken}`},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(res.statusCode).toBe(204);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('claims multiple jobs from one manual session', async () => {
|
|
153
|
+
const first = await pendingJobFactory.create({workspaceId});
|
|
154
|
+
const second = await pendingJobFactory.create({workspaceId});
|
|
155
|
+
|
|
156
|
+
const firstRes = await app.inject({
|
|
157
|
+
method: 'POST',
|
|
158
|
+
url: '/runners/jobs/request',
|
|
159
|
+
headers: {authorization: `Bearer ${sessionToken}`},
|
|
160
|
+
});
|
|
161
|
+
const secondRes = await app.inject({
|
|
162
|
+
method: 'POST',
|
|
163
|
+
url: '/runners/jobs/request',
|
|
164
|
+
headers: {authorization: `Bearer ${sessionToken}`},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
expect(firstRes.statusCode).toBe(200);
|
|
168
|
+
expect(firstRes.json().job_id).toBe(first.jobId);
|
|
169
|
+
expect(secondRes.statusCode).toBe(200);
|
|
170
|
+
expect(secondRes.json().job_id).toBe(second.jobId);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('returns 409 after an ephemeral session claims one job', async () => {
|
|
174
|
+
const ephemeralRawToken = generateOpaqueToken('ephemeralRegistrationToken');
|
|
175
|
+
await ephemeralRegistrationTokenFactory.create(
|
|
176
|
+
{workspaceId},
|
|
177
|
+
{transient: {rawToken: ephemeralRawToken}},
|
|
178
|
+
);
|
|
179
|
+
const registered = await registerSession(ephemeralRawToken);
|
|
180
|
+
const created = await pendingJobFactory.create({workspaceId});
|
|
181
|
+
await pendingJobFactory.create({workspaceId});
|
|
182
|
+
|
|
183
|
+
const firstRes = await app.inject({
|
|
184
|
+
method: 'POST',
|
|
185
|
+
url: '/runners/jobs/request',
|
|
186
|
+
headers: {authorization: `Bearer ${registered.sessionToken}`},
|
|
187
|
+
});
|
|
188
|
+
const secondRes = await app.inject({
|
|
189
|
+
method: 'POST',
|
|
190
|
+
url: '/runners/jobs/request',
|
|
191
|
+
headers: {authorization: `Bearer ${registered.sessionToken}`},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(firstRes.statusCode).toBe(200);
|
|
195
|
+
expect(firstRes.json().job_id).toBe(created.jobId);
|
|
196
|
+
expect(secondRes.statusCode).toBe(409);
|
|
197
|
+
expect(secondRes.json().code).toBe('runner-session-exhausted');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('returns 401 when the runner session token is expired', async () => {
|
|
201
|
+
const expiredSessionToken = await signHs256({
|
|
202
|
+
payload: {
|
|
203
|
+
runnerSessionId,
|
|
204
|
+
workspaceId,
|
|
205
|
+
scope: 'workspace',
|
|
206
|
+
labels: ['linux', 'x64'],
|
|
207
|
+
maxClaims: null,
|
|
208
|
+
},
|
|
209
|
+
secret: process.env.AUTH_RUNNER_SESSION_TOKEN_SECRET ?? 'test-runner-session-secret',
|
|
210
|
+
expiresIn: '-1s',
|
|
211
|
+
audience: RUNNER_SESSION_TOKEN_AUDIENCE,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const res = await app.inject({
|
|
215
|
+
method: 'POST',
|
|
216
|
+
url: '/runners/jobs/request',
|
|
217
|
+
headers: {authorization: `Bearer ${expiredSessionToken}`},
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
expect(res.statusCode).toBe(401);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {requireRunnerSessionContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {claimedJobResponseSchema} from '@shipfox/api-runners-dto';
|
|
3
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
4
|
+
import {RunnerSessionExhaustedError} from '#core/errors.js';
|
|
5
|
+
import {claimJobExecution} from '#core/job-executions.js';
|
|
6
|
+
|
|
7
|
+
export const requestJobRoute = defineRoute({
|
|
8
|
+
method: 'POST',
|
|
9
|
+
path: '/request',
|
|
10
|
+
description: 'Claim the next available job execution and receive its lease token',
|
|
11
|
+
schema: {
|
|
12
|
+
response: {
|
|
13
|
+
200: claimedJobResponseSchema,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
errorHandler: (error) => {
|
|
17
|
+
if (error instanceof RunnerSessionExhaustedError) {
|
|
18
|
+
throw new ClientError('Runner session claim limit exhausted', 'runner-session-exhausted', {
|
|
19
|
+
status: 409,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
},
|
|
24
|
+
handler: async (_request, reply) => {
|
|
25
|
+
const runner = requireRunnerSessionContext(_request);
|
|
26
|
+
|
|
27
|
+
const jobExecution = await claimJobExecution({
|
|
28
|
+
workspaceId: runner.workspaceId,
|
|
29
|
+
runnerSessionId: runner.runnerSessionId,
|
|
30
|
+
sessionLabels: runner.labels,
|
|
31
|
+
maxClaims: runner.maxClaims,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!jobExecution) {
|
|
35
|
+
reply.status(204);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
workflow_run_id: jobExecution.workflowRunId,
|
|
41
|
+
workflow_run_attempt_id: jobExecution.workflowRunAttemptId,
|
|
42
|
+
job_id: jobExecution.jobId,
|
|
43
|
+
job_execution_id: jobExecution.jobExecutionId,
|
|
44
|
+
lease_token: jobExecution.leaseToken,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {revokeManualRegistrationTokenResponseSchema} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
3
|
+
import {z} from 'zod';
|
|
4
|
+
import {
|
|
5
|
+
ManualRegistrationTokenNotFoundError,
|
|
6
|
+
revokeWorkspaceManualRegistrationToken,
|
|
7
|
+
} from '#core/index.js';
|
|
8
|
+
import {toManualRegistrationTokenDto} from '#presentation/dto/index.js';
|
|
9
|
+
import {requireManualRegistrationTokenWorkspaceMembership} from './workspace-membership.js';
|
|
10
|
+
|
|
11
|
+
export const revokeManualRegistrationTokenRoute = defineRoute({
|
|
12
|
+
method: 'POST',
|
|
13
|
+
path: '/:tokenId/revoke',
|
|
14
|
+
description: 'Stop a manual registration token from being used to connect to your account',
|
|
15
|
+
schema: {
|
|
16
|
+
params: z.object({workspaceId: z.string().uuid(), tokenId: z.string().uuid()}),
|
|
17
|
+
response: {
|
|
18
|
+
200: revokeManualRegistrationTokenResponseSchema,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
errorHandler: (error) => {
|
|
22
|
+
if (error instanceof ManualRegistrationTokenNotFoundError) {
|
|
23
|
+
throw new ClientError('Manual registration token not found', 'not-found', {status: 404});
|
|
24
|
+
}
|
|
25
|
+
throw error;
|
|
26
|
+
},
|
|
27
|
+
handler: async (request) => {
|
|
28
|
+
const {workspaceId, tokenId} = request.params;
|
|
29
|
+
requireManualRegistrationTokenWorkspaceMembership({request, workspaceId});
|
|
30
|
+
|
|
31
|
+
const revoked = await revokeWorkspaceManualRegistrationToken({tokenId, workspaceId});
|
|
32
|
+
|
|
33
|
+
return toManualRegistrationTokenDto(revoked);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {requireUserContext, requireWorkspaceAccess} from '@shipfox/api-auth-context';
|
|
2
|
+
import {revokeProvisionerTokenResponseSchema} from '@shipfox/api-runners-dto';
|
|
3
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
4
|
+
import {z} from 'zod';
|
|
5
|
+
import {ProvisionerTokenNotFoundError, revokeWorkspaceProvisionerToken} from '#core/index.js';
|
|
6
|
+
import {toProvisionerTokenDto} from '#presentation/dto/index.js';
|
|
7
|
+
|
|
8
|
+
export const revokeProvisionerTokenRoute = defineRoute({
|
|
9
|
+
method: 'POST',
|
|
10
|
+
path: '/:tokenId/revoke',
|
|
11
|
+
description: 'Stop a provisioner token from being used to connect to your account',
|
|
12
|
+
schema: {
|
|
13
|
+
params: z.object({workspaceId: z.string().uuid(), tokenId: z.string().uuid()}),
|
|
14
|
+
response: {
|
|
15
|
+
200: revokeProvisionerTokenResponseSchema,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
errorHandler: (error) => {
|
|
19
|
+
if (error instanceof ProvisionerTokenNotFoundError) {
|
|
20
|
+
throw new ClientError('Provisioner token not found', 'not-found', {status: 404});
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
},
|
|
24
|
+
handler: async (request) => {
|
|
25
|
+
const {workspaceId, tokenId} = request.params;
|
|
26
|
+
requireWorkspaceAccess({request, workspaceId});
|
|
27
|
+
const user = requireUserContext(request);
|
|
28
|
+
|
|
29
|
+
const revoked = await revokeWorkspaceProvisionerToken({
|
|
30
|
+
tokenId,
|
|
31
|
+
workspaceId,
|
|
32
|
+
revokedByUserId: user.userId,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return toProvisionerTokenDto(revoked);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {requireWorkspaceAccess} from '@shipfox/api-auth-context';
|
|
2
|
+
import type {FastifyRequest} from 'fastify';
|
|
3
|
+
|
|
4
|
+
export function requireManualRegistrationTokenWorkspaceMembership(params: {
|
|
5
|
+
request: FastifyRequest;
|
|
6
|
+
workspaceId: string;
|
|
7
|
+
}): void {
|
|
8
|
+
requireWorkspaceAccess(params);
|
|
9
|
+
}
|