@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,453 @@
|
|
|
1
|
+
import {createLeaseTokenAuthMethod, createRunnerSessionAuthMethod} from '@shipfox/api-auth';
|
|
2
|
+
import {
|
|
3
|
+
AUTH_LEASED_JOB,
|
|
4
|
+
AUTH_PROVISIONER_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 {hashOpaqueToken, tokenTypeParts} from '@shipfox/node-tokens';
|
|
17
|
+
import {and, count, eq, sql} from 'drizzle-orm';
|
|
18
|
+
import type {FastifyInstance, FastifyRequest} from 'fastify';
|
|
19
|
+
import {config} from '#config.js';
|
|
20
|
+
import {hashRunnersRateLimitIdentifier} from '#core/rate-limit.js';
|
|
21
|
+
import {db} from '#db/db.js';
|
|
22
|
+
import {resolveEphemeralRegistrationTokenByHash} from '#db/ephemeral-registration-tokens.js';
|
|
23
|
+
import {ephemeralRegistrationTokens} from '#db/schema/ephemeral-registration-tokens.js';
|
|
24
|
+
import {runnersRateLimits} from '#db/schema/rate-limits.js';
|
|
25
|
+
import {reservations} from '#db/schema/reservations.js';
|
|
26
|
+
import {createRunnerRegistrationTokenAuthMethod} from '#presentation/auth/index.js';
|
|
27
|
+
import {ephemeralRegistrationTokenFactory} from '#test/index.js';
|
|
28
|
+
import {runnerRoutes} from './index.js';
|
|
29
|
+
|
|
30
|
+
const VALID_PROVISIONER_TOKEN = 'valid-provisioner-token';
|
|
31
|
+
|
|
32
|
+
const fakeUserAuth: AuthMethod = {
|
|
33
|
+
name: AUTH_USER,
|
|
34
|
+
authenticate: () => Promise.resolve(),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const passthroughAuth = (name: string): AuthMethod => ({
|
|
38
|
+
name,
|
|
39
|
+
authenticate: () => Promise.resolve(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('POST /provisioners/runner-registration-tokens/batch', () => {
|
|
43
|
+
let app: FastifyInstance;
|
|
44
|
+
let workspaceId: string;
|
|
45
|
+
let provisionerTokenId: string;
|
|
46
|
+
|
|
47
|
+
const fakeProvisionerAuth: AuthMethod = {
|
|
48
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
49
|
+
authenticate: (request: FastifyRequest) => {
|
|
50
|
+
const rawToken = extractBearerToken(request.headers.authorization);
|
|
51
|
+
if (rawToken !== VALID_PROVISIONER_TOKEN) {
|
|
52
|
+
throw new ClientError('Invalid provisioner token', 'unauthorized', {status: 401});
|
|
53
|
+
}
|
|
54
|
+
setProvisionerContext(request, {workspaceId, provisionerTokenId});
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
beforeAll(async () => {
|
|
60
|
+
app = await createApp({
|
|
61
|
+
auth: [
|
|
62
|
+
fakeUserAuth,
|
|
63
|
+
createRunnerRegistrationTokenAuthMethod(),
|
|
64
|
+
createRunnerSessionAuthMethod(),
|
|
65
|
+
createLeaseTokenAuthMethod(),
|
|
66
|
+
passthroughAuth(AUTH_RUNNER_SESSION),
|
|
67
|
+
passthroughAuth(AUTH_LEASED_JOB),
|
|
68
|
+
fakeProvisionerAuth,
|
|
69
|
+
],
|
|
70
|
+
routes: runnerRoutes,
|
|
71
|
+
swagger: false,
|
|
72
|
+
});
|
|
73
|
+
await app.ready();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
afterAll(async () => {
|
|
77
|
+
await closeApp();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
workspaceId = crypto.randomUUID();
|
|
82
|
+
provisionerTokenId = crypto.randomUUID();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('mints one registration token per provisioned runner for a valid reservation', async () => {
|
|
86
|
+
const reservationId = await createReservation({count: 2});
|
|
87
|
+
const before = Date.now();
|
|
88
|
+
|
|
89
|
+
const res = await app.inject({
|
|
90
|
+
method: 'POST',
|
|
91
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
92
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
93
|
+
payload: body(reservationId, ['provisioned-runner-a', 'provisioned-runner-b']),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const after = Date.now();
|
|
97
|
+
expect(res.statusCode).toBe(200);
|
|
98
|
+
const tokens = res.json().tokens as {
|
|
99
|
+
provisioned_runner_id: string;
|
|
100
|
+
registration_token: string;
|
|
101
|
+
expires_at: string;
|
|
102
|
+
}[];
|
|
103
|
+
expect(tokens).toHaveLength(2);
|
|
104
|
+
expect(tokens.map((token) => token.provisioned_runner_id).sort()).toEqual([
|
|
105
|
+
'provisioned-runner-a',
|
|
106
|
+
'provisioned-runner-b',
|
|
107
|
+
]);
|
|
108
|
+
for (const minted of tokens) {
|
|
109
|
+
expect(
|
|
110
|
+
minted.registration_token.startsWith(`sf_${tokenTypeParts.ephemeralRegistrationToken}_`),
|
|
111
|
+
).toBe(true);
|
|
112
|
+
const persisted = await resolveEphemeralRegistrationTokenByHash(
|
|
113
|
+
hashOpaqueToken(minted.registration_token),
|
|
114
|
+
);
|
|
115
|
+
expect(persisted).toMatchObject({
|
|
116
|
+
workspaceId,
|
|
117
|
+
provisionerId: provisionerTokenId,
|
|
118
|
+
reservationId,
|
|
119
|
+
provisionedRunnerId: minted.provisioned_runner_id,
|
|
120
|
+
});
|
|
121
|
+
const expiresMs = new Date(minted.expires_at).getTime();
|
|
122
|
+
expect(expiresMs).toBeGreaterThanOrEqual(
|
|
123
|
+
before + config.EPHEMERAL_REGISTRATION_TOKEN_TTL_SECONDS * 1000,
|
|
124
|
+
);
|
|
125
|
+
expect(expiresMs).toBeLessThanOrEqual(
|
|
126
|
+
after + config.EPHEMERAL_REGISTRATION_TOKEN_TTL_SECONDS * 1000,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('returns 404 when the reservation is unknown', async () => {
|
|
132
|
+
const res = await app.inject({
|
|
133
|
+
method: 'POST',
|
|
134
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
135
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
136
|
+
payload: body(crypto.randomUUID(), ['provisioned-runner-a']),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
expect(res.statusCode).toBe(404);
|
|
140
|
+
expect(res.json().code).toBe('reservation-not-found');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('returns 404 when the reservation belongs to another provisioner', async () => {
|
|
144
|
+
const reservationId = await createReservation({
|
|
145
|
+
count: 1,
|
|
146
|
+
provisionerId: crypto.randomUUID(),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const res = await app.inject({
|
|
150
|
+
method: 'POST',
|
|
151
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
152
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
153
|
+
payload: body(reservationId, ['provisioned-runner-a']),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(res.statusCode).toBe(404);
|
|
157
|
+
expect(res.json().code).toBe('reservation-not-found');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('returns 404 when the reservation belongs to another workspace', async () => {
|
|
161
|
+
const reservationId = await createReservation({
|
|
162
|
+
count: 1,
|
|
163
|
+
workspaceId: crypto.randomUUID(),
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const res = await app.inject({
|
|
167
|
+
method: 'POST',
|
|
168
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
169
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
170
|
+
payload: body(reservationId, ['provisioned-runner-a']),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(res.statusCode).toBe(404);
|
|
174
|
+
expect(res.json().code).toBe('reservation-not-found');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('returns 409 when the reservation is expired', async () => {
|
|
178
|
+
const reservationId = await createReservation({
|
|
179
|
+
count: 1,
|
|
180
|
+
expiresAt: new Date(Date.now() - 1000),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const res = await app.inject({
|
|
184
|
+
method: 'POST',
|
|
185
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
186
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
187
|
+
payload: body(reservationId, ['provisioned-runner-a']),
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
expect(res.statusCode).toBe(409);
|
|
191
|
+
expect(res.json().code).toBe('reservation-expired');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('allows a batch equal to the reservation count', async () => {
|
|
195
|
+
const reservationId = await createReservation({count: 2});
|
|
196
|
+
|
|
197
|
+
const res = await app.inject({
|
|
198
|
+
method: 'POST',
|
|
199
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
200
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
201
|
+
payload: body(reservationId, ['provisioned-runner-a', 'provisioned-runner-b']),
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
expect(res.statusCode).toBe(200);
|
|
205
|
+
expect(res.json().tokens).toHaveLength(2);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('returns 409 when the batch exceeds the reservation count', async () => {
|
|
209
|
+
const reservationId = await createReservation({count: 1});
|
|
210
|
+
|
|
211
|
+
const res = await app.inject({
|
|
212
|
+
method: 'POST',
|
|
213
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
214
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
215
|
+
payload: body(reservationId, ['provisioned-runner-a', 'provisioned-runner-b']),
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(res.statusCode).toBe(409);
|
|
219
|
+
expect(res.json()).toMatchObject({
|
|
220
|
+
code: 'batch-exceeds-reservation',
|
|
221
|
+
details: {requested: 2, reservation_count: 1},
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('rejects the whole batch when a requested provisioned runner has an active token', async () => {
|
|
226
|
+
const reservationId = await createReservation({count: 2});
|
|
227
|
+
await ephemeralRegistrationTokenFactory.create({
|
|
228
|
+
workspaceId,
|
|
229
|
+
provisionerId: provisionerTokenId,
|
|
230
|
+
provisionedRunnerId: 'provisioned-runner-a',
|
|
231
|
+
expiresAt: new Date(Date.now() + 60_000),
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const res = await app.inject({
|
|
235
|
+
method: 'POST',
|
|
236
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
237
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
238
|
+
payload: body(reservationId, ['provisioned-runner-a', 'provisioned-runner-b']),
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
const persistedCount = await countEphemeralTokens();
|
|
242
|
+
expect(res.statusCode).toBe(409);
|
|
243
|
+
expect(res.json()).toMatchObject({
|
|
244
|
+
code: 'registration-token-active',
|
|
245
|
+
details: {provisioned_runner_ids: ['provisioned-runner-a']},
|
|
246
|
+
});
|
|
247
|
+
expect(persistedCount).toBe(1);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('returns 400 for duplicate provisioned runner ids', async () => {
|
|
251
|
+
const reservationId = await createReservation({count: 2});
|
|
252
|
+
|
|
253
|
+
const res = await app.inject({
|
|
254
|
+
method: 'POST',
|
|
255
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
256
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
257
|
+
payload: body(reservationId, ['provisioned-runner-a', 'provisioned-runner-a']),
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
expect(res.statusCode).toBe(400);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('returns 400 when the request exceeds the runtime batch max', async () => {
|
|
264
|
+
const reservationId = await createReservation({count: config.REGISTRATION_TOKEN_BATCH_MAX + 1});
|
|
265
|
+
|
|
266
|
+
const res = await app.inject({
|
|
267
|
+
method: 'POST',
|
|
268
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
269
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
270
|
+
payload: body(
|
|
271
|
+
reservationId,
|
|
272
|
+
Array.from(
|
|
273
|
+
{length: config.REGISTRATION_TOKEN_BATCH_MAX + 1},
|
|
274
|
+
(_, index) => `provisioned-runner-${index}`,
|
|
275
|
+
),
|
|
276
|
+
),
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
expect(res.statusCode).toBe(400);
|
|
280
|
+
expect(res.json()).toMatchObject({
|
|
281
|
+
code: 'batch-too-large',
|
|
282
|
+
details: {requested: config.REGISTRATION_TOKEN_BATCH_MAX + 1},
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('returns 400 when the request exceeds the DTO hard ceiling', async () => {
|
|
287
|
+
const reservationId = await createReservation({count: 1001});
|
|
288
|
+
|
|
289
|
+
const res = await app.inject({
|
|
290
|
+
method: 'POST',
|
|
291
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
292
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
293
|
+
payload: body(
|
|
294
|
+
reservationId,
|
|
295
|
+
Array.from({length: 1001}, (_, index) => `provisioned-runner-${index}`),
|
|
296
|
+
),
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
expect(res.statusCode).toBe(400);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('returns 429 when the provisioner mint rate limit is exceeded', async () => {
|
|
303
|
+
const reservationId = await createReservation({count: 1});
|
|
304
|
+
await seedProvisionerMintRateLimit(config.PROVISIONER_MINT_RATE_LIMIT_MAX_REQUESTS);
|
|
305
|
+
|
|
306
|
+
const res = await app.inject({
|
|
307
|
+
method: 'POST',
|
|
308
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
309
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
310
|
+
payload: body(reservationId, ['provisioned-runner-a']),
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const persistedCount = await countEphemeralTokens();
|
|
314
|
+
expect(res.statusCode).toBe(429);
|
|
315
|
+
expect(res.headers['retry-after']).toEqual(expect.any(String));
|
|
316
|
+
expect(res.json()).toMatchObject({
|
|
317
|
+
code: 'rate-limited',
|
|
318
|
+
details: {retry_after_seconds: expect.any(Number)},
|
|
319
|
+
});
|
|
320
|
+
expect(persistedCount).toBe(0);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('returns 503 when the provisioner mint rate limiter is unavailable', async () => {
|
|
324
|
+
const reservationId = await createReservation({count: 1});
|
|
325
|
+
const identifierHmac = await seedProvisionerMintRateLimit(1);
|
|
326
|
+
|
|
327
|
+
await db().transaction(async (tx) => {
|
|
328
|
+
await tx.execute(sql`
|
|
329
|
+
SELECT 1
|
|
330
|
+
FROM runners_rate_limits
|
|
331
|
+
WHERE identifier_hmac = ${identifierHmac}
|
|
332
|
+
FOR UPDATE
|
|
333
|
+
`);
|
|
334
|
+
|
|
335
|
+
const res = await app.inject({
|
|
336
|
+
method: 'POST',
|
|
337
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
338
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
339
|
+
payload: body(reservationId, ['provisioned-runner-a']),
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
expect(res.statusCode).toBe(503);
|
|
343
|
+
expect(res.json().code).toBe('runners-rate-limit-unavailable');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const persistedCount = await countEphemeralTokens();
|
|
347
|
+
expect(persistedCount).toBe(0);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('mints tokens that can register exactly once', async () => {
|
|
351
|
+
const reservationId = await createReservation({count: 1});
|
|
352
|
+
const mint = await app.inject({
|
|
353
|
+
method: 'POST',
|
|
354
|
+
url: '/provisioners/runner-registration-tokens/batch',
|
|
355
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
356
|
+
payload: body(reservationId, ['provisioned-runner-a']),
|
|
357
|
+
});
|
|
358
|
+
const registrationToken = mint.json().tokens[0].registration_token as string;
|
|
359
|
+
|
|
360
|
+
const first = await app.inject({
|
|
361
|
+
method: 'POST',
|
|
362
|
+
url: '/runners/register',
|
|
363
|
+
headers: {authorization: `Bearer ${registrationToken}`},
|
|
364
|
+
payload: {labels: ['linux']},
|
|
365
|
+
});
|
|
366
|
+
const second = await app.inject({
|
|
367
|
+
method: 'POST',
|
|
368
|
+
url: '/runners/register',
|
|
369
|
+
headers: {authorization: `Bearer ${registrationToken}`},
|
|
370
|
+
payload: {labels: ['linux']},
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
expect(mint.statusCode).toBe(200);
|
|
374
|
+
expect(first.statusCode).toBe(200);
|
|
375
|
+
expect(first.json()).toMatchObject({mode: 'ephemeral', max_claims: 1});
|
|
376
|
+
expect(second.statusCode).toBe(409);
|
|
377
|
+
expect(second.json().code).toBe('registration-token-consumed');
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
async function createReservation(params: {
|
|
381
|
+
count: number;
|
|
382
|
+
workspaceId?: string;
|
|
383
|
+
provisionerId?: string;
|
|
384
|
+
expiresAt?: Date;
|
|
385
|
+
}): Promise<string> {
|
|
386
|
+
const [reservation] = await db()
|
|
387
|
+
.insert(reservations)
|
|
388
|
+
.values({
|
|
389
|
+
workspaceId: params.workspaceId ?? workspaceId,
|
|
390
|
+
provisionerId: params.provisionerId ?? provisionerTokenId,
|
|
391
|
+
requiredLabels: ['linux'],
|
|
392
|
+
count: params.count,
|
|
393
|
+
expiresAt: params.expiresAt ?? new Date(Date.now() + 60_000),
|
|
394
|
+
})
|
|
395
|
+
.returning({id: reservations.id});
|
|
396
|
+
if (!reservation) throw new Error('Insert returned no rows');
|
|
397
|
+
return reservation.id;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async function countEphemeralTokens(): Promise<number> {
|
|
401
|
+
const [row] = await db()
|
|
402
|
+
.select({value: count()})
|
|
403
|
+
.from(ephemeralRegistrationTokens)
|
|
404
|
+
.where(
|
|
405
|
+
and(
|
|
406
|
+
eq(ephemeralRegistrationTokens.workspaceId, workspaceId),
|
|
407
|
+
eq(ephemeralRegistrationTokens.provisionerId, provisionerTokenId),
|
|
408
|
+
),
|
|
409
|
+
);
|
|
410
|
+
return row?.value ?? 0;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function body(reservationId: string, provisionedRunnerIds: string[]) {
|
|
414
|
+
return {
|
|
415
|
+
reservation_id: reservationId,
|
|
416
|
+
provisioned_runners: provisionedRunnerIds.map((provisionedRunnerId) => ({
|
|
417
|
+
provisioned_runner_id: provisionedRunnerId,
|
|
418
|
+
})),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async function seedProvisionerMintRateLimit(seedCount: number): Promise<string> {
|
|
423
|
+
const identifierHmac = hashRunnersRateLimitIdentifier({
|
|
424
|
+
action: 'provisioner-mint',
|
|
425
|
+
scope: 'provisioner',
|
|
426
|
+
identifier: provisionerTokenId,
|
|
427
|
+
});
|
|
428
|
+
const windows = rateLimitWindows(config.PROVISIONER_MINT_RATE_LIMIT_WINDOW_SECONDS);
|
|
429
|
+
|
|
430
|
+
await db()
|
|
431
|
+
.insert(runnersRateLimits)
|
|
432
|
+
.values(
|
|
433
|
+
windows.map((windowStart) => ({
|
|
434
|
+
action: 'provisioner-mint',
|
|
435
|
+
scope: 'provisioner',
|
|
436
|
+
identifierHmac,
|
|
437
|
+
windowStart,
|
|
438
|
+
count: seedCount,
|
|
439
|
+
expiresAt: new Date(
|
|
440
|
+
windowStart.getTime() + config.PROVISIONER_MINT_RATE_LIMIT_WINDOW_SECONDS * 1000,
|
|
441
|
+
),
|
|
442
|
+
})),
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
return identifierHmac;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function rateLimitWindows(windowSeconds: number): [Date, Date] {
|
|
449
|
+
const windowMs = windowSeconds * 1000;
|
|
450
|
+
const currentWindowStart = Math.floor(Date.now() / windowMs) * windowMs;
|
|
451
|
+
return [new Date(currentWindowStart), new Date(currentWindowStart + windowMs)];
|
|
452
|
+
}
|
|
453
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {requireProvisionerContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {
|
|
3
|
+
mintRegistrationTokensBatchBodySchema,
|
|
4
|
+
mintRegistrationTokensBatchResponseSchema,
|
|
5
|
+
} from '@shipfox/api-runners-dto';
|
|
6
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
7
|
+
import {config} from '#config.js';
|
|
8
|
+
import {mintEphemeralRegistrationTokensBatch} from '#core/ephemeral-registration-tokens.js';
|
|
9
|
+
import {
|
|
10
|
+
ActiveEphemeralRegistrationTokensExistError,
|
|
11
|
+
RegistrationTokenBatchExceedsReservationError,
|
|
12
|
+
RegistrationTokenBatchTooLargeError,
|
|
13
|
+
ReservationExpiredError,
|
|
14
|
+
ReservationNotFoundError,
|
|
15
|
+
} from '#core/errors.js';
|
|
16
|
+
import {
|
|
17
|
+
toMintRegistrationTokensProvisionedRunners,
|
|
18
|
+
toMintRegistrationTokensResponseDto,
|
|
19
|
+
} from '#presentation/dto/index.js';
|
|
20
|
+
import {createProvisionerMintRateLimitPreHandler} from './rate-limit.js';
|
|
21
|
+
|
|
22
|
+
export const mintRegistrationTokensRoute = defineRoute({
|
|
23
|
+
method: 'POST',
|
|
24
|
+
path: '/runner-registration-tokens/batch',
|
|
25
|
+
description: 'Mint ephemeral runner registration tokens for reserved provisioned runners',
|
|
26
|
+
schema: {
|
|
27
|
+
body: mintRegistrationTokensBatchBodySchema,
|
|
28
|
+
response: {
|
|
29
|
+
200: mintRegistrationTokensBatchResponseSchema,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
preHandler: createProvisionerMintRateLimitPreHandler(),
|
|
33
|
+
errorHandler: (error) => {
|
|
34
|
+
if (error instanceof ReservationNotFoundError) {
|
|
35
|
+
throw new ClientError('Reservation not found', 'reservation-not-found', {status: 404});
|
|
36
|
+
}
|
|
37
|
+
if (error instanceof ReservationExpiredError) {
|
|
38
|
+
throw new ClientError('Reservation has expired', 'reservation-expired', {status: 409});
|
|
39
|
+
}
|
|
40
|
+
if (error instanceof RegistrationTokenBatchExceedsReservationError) {
|
|
41
|
+
throw new ClientError('Batch exceeds reservation count', 'batch-exceeds-reservation', {
|
|
42
|
+
status: 409,
|
|
43
|
+
details: {
|
|
44
|
+
requested: error.requested,
|
|
45
|
+
reservation_count: error.reservationCount,
|
|
46
|
+
already_minted: error.alreadyMinted,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (error instanceof ActiveEphemeralRegistrationTokensExistError) {
|
|
51
|
+
throw new ClientError('Registration token already active', 'registration-token-active', {
|
|
52
|
+
status: 409,
|
|
53
|
+
details: {provisioned_runner_ids: error.provisionedRunnerIds},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (error instanceof RegistrationTokenBatchTooLargeError) {
|
|
57
|
+
throw new ClientError('Registration token batch is too large', 'batch-too-large', {
|
|
58
|
+
status: 400,
|
|
59
|
+
details: {
|
|
60
|
+
requested: error.requested,
|
|
61
|
+
max: error.max,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
},
|
|
67
|
+
handler: async (request) => {
|
|
68
|
+
const {provisionerTokenId, workspaceId} = requireProvisionerContext(request);
|
|
69
|
+
const result = await mintEphemeralRegistrationTokensBatch({
|
|
70
|
+
workspaceId,
|
|
71
|
+
provisionerId: provisionerTokenId,
|
|
72
|
+
reservationId: request.body.reservation_id,
|
|
73
|
+
provisionedRunners: toMintRegistrationTokensProvisionedRunners(
|
|
74
|
+
request.body.provisioned_runners,
|
|
75
|
+
),
|
|
76
|
+
ttlSeconds: config.EPHEMERAL_REGISTRATION_TOKEN_TTL_SECONDS,
|
|
77
|
+
maxBatchSize: config.REGISTRATION_TOKEN_BATCH_MAX,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return toMintRegistrationTokensResponseDto(result);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {AUTH_PROVISIONER_TOKEN, setProvisionerContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {type AuthMethod, closeApp, createApp, extractBearerToken} from '@shipfox/node-fastify';
|
|
3
|
+
import {vi} from '@shipfox/vitest/vi';
|
|
4
|
+
import {and, eq} from 'drizzle-orm';
|
|
5
|
+
import type {FastifyRequest} from 'fastify';
|
|
6
|
+
import {db} from '#db/db.js';
|
|
7
|
+
import {reservations} from '#db/schema/reservations.js';
|
|
8
|
+
import {pendingJobFactory} from '#test/index.js';
|
|
9
|
+
|
|
10
|
+
const VALID_PROVISIONER_TOKEN = 'valid-provisioner-token';
|
|
11
|
+
|
|
12
|
+
describe('POST /provisioners/demand/poll reservation cleanup', () => {
|
|
13
|
+
it('rolls back granted reservations if loading terminate intents throws', async () => {
|
|
14
|
+
vi.resetModules();
|
|
15
|
+
const listProvisionerTerminateIntentRowsTx = vi
|
|
16
|
+
.fn()
|
|
17
|
+
.mockRejectedValueOnce(new Error('db unavailable'));
|
|
18
|
+
vi.doMock('#db/provisioned-runners.js', async (importOriginal) => ({
|
|
19
|
+
...(await importOriginal<typeof import('#db/provisioned-runners.js')>()),
|
|
20
|
+
listProvisionerTerminateIntentRowsTx,
|
|
21
|
+
}));
|
|
22
|
+
const {pollDemandRoute} = await import('./poll-demand.js');
|
|
23
|
+
const workspaceId = crypto.randomUUID();
|
|
24
|
+
const provisionerTokenId = crypto.randomUUID();
|
|
25
|
+
const provisionerAuth: AuthMethod = {
|
|
26
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
27
|
+
authenticate: (request: FastifyRequest) => {
|
|
28
|
+
if (extractBearerToken(request.headers.authorization) !== VALID_PROVISIONER_TOKEN) {
|
|
29
|
+
throw new Error('unauthorized');
|
|
30
|
+
}
|
|
31
|
+
setProvisionerContext(request, {workspaceId, provisionerTokenId});
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const app = await createApp({
|
|
36
|
+
auth: [provisionerAuth],
|
|
37
|
+
routes: [{prefix: '/provisioners', auth: AUTH_PROVISIONER_TOKEN, routes: [pollDemandRoute]}],
|
|
38
|
+
swagger: false,
|
|
39
|
+
});
|
|
40
|
+
await app.ready();
|
|
41
|
+
await pendingJobFactory.create({workspaceId, requiredLabels: ['linux']});
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const res = await app.inject({
|
|
45
|
+
method: 'POST',
|
|
46
|
+
url: '/provisioners/demand/poll',
|
|
47
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
48
|
+
payload: {
|
|
49
|
+
wait_seconds: 0,
|
|
50
|
+
max_reservations: 1,
|
|
51
|
+
templates: [
|
|
52
|
+
{
|
|
53
|
+
template_key: 'linux',
|
|
54
|
+
labels: ['linux'],
|
|
55
|
+
available_slots: 1,
|
|
56
|
+
starting: 0,
|
|
57
|
+
running: 0,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const reservationRows = await db()
|
|
64
|
+
.select()
|
|
65
|
+
.from(reservations)
|
|
66
|
+
.where(
|
|
67
|
+
and(
|
|
68
|
+
eq(reservations.workspaceId, workspaceId),
|
|
69
|
+
eq(reservations.provisionerId, provisionerTokenId),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
expect(res.statusCode).toBe(500);
|
|
73
|
+
expect(reservationRows).toHaveLength(0);
|
|
74
|
+
} finally {
|
|
75
|
+
vi.doUnmock('#db/provisioned-runners.js');
|
|
76
|
+
vi.resetModules();
|
|
77
|
+
await closeApp();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|