@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,323 @@
|
|
|
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 type {FastifyInstance, FastifyRequest} from 'fastify';
|
|
18
|
+
import {db} from '#db/db.js';
|
|
19
|
+
import {runningJobExecutions} from '#db/schema/running-job-executions.js';
|
|
20
|
+
import {
|
|
21
|
+
provisionedRunnerCountDivergenceCount,
|
|
22
|
+
provisionedRunnerTerminateIntentIssuedCount,
|
|
23
|
+
} from '#metrics/instance.js';
|
|
24
|
+
import {pendingJobFactory, provisionedRunnerFactory, runnerSessionFactory} from '#test/index.js';
|
|
25
|
+
import {runnerRoutes} from './index.js';
|
|
26
|
+
|
|
27
|
+
const VALID_PROVISIONER_TOKEN = 'valid-provisioner-token';
|
|
28
|
+
|
|
29
|
+
const passthroughAuth = (name: string): AuthMethod => ({
|
|
30
|
+
name,
|
|
31
|
+
authenticate: () => Promise.resolve(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('POST /provisioners/demand/poll', () => {
|
|
35
|
+
let app: FastifyInstance;
|
|
36
|
+
let workspaceId: string;
|
|
37
|
+
let provisionerTokenId: string;
|
|
38
|
+
|
|
39
|
+
const fakeProvisionerAuth: AuthMethod = {
|
|
40
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
41
|
+
authenticate: (request: FastifyRequest) => {
|
|
42
|
+
const rawToken = extractBearerToken(request.headers.authorization);
|
|
43
|
+
if (rawToken !== VALID_PROVISIONER_TOKEN) {
|
|
44
|
+
throw new ClientError('Invalid provisioner token', 'unauthorized', {status: 401});
|
|
45
|
+
}
|
|
46
|
+
setProvisionerContext(request, {workspaceId, provisionerTokenId});
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
beforeAll(async () => {
|
|
52
|
+
app = await createApp({
|
|
53
|
+
auth: [
|
|
54
|
+
passthroughAuth(AUTH_USER),
|
|
55
|
+
passthroughAuth(AUTH_RUNNER_REGISTRATION_TOKEN),
|
|
56
|
+
passthroughAuth(AUTH_RUNNER_SESSION),
|
|
57
|
+
passthroughAuth(AUTH_LEASED_JOB),
|
|
58
|
+
fakeProvisionerAuth,
|
|
59
|
+
],
|
|
60
|
+
routes: runnerRoutes,
|
|
61
|
+
swagger: false,
|
|
62
|
+
});
|
|
63
|
+
await app.ready();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterAll(async () => {
|
|
67
|
+
await closeApp();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
workspaceId = crypto.randomUUID();
|
|
72
|
+
provisionerTokenId = crypto.randomUUID();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('returns demand stats and reservations when matching demand exists', async () => {
|
|
76
|
+
await pendingJobFactory.create({workspaceId, requiredLabels: ['linux']});
|
|
77
|
+
|
|
78
|
+
const res = await app.inject({
|
|
79
|
+
method: 'POST',
|
|
80
|
+
url: '/provisioners/demand/poll',
|
|
81
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
82
|
+
payload: body({max_reservations: 1}),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(res.statusCode).toBe(200);
|
|
86
|
+
expect(res.json()).toMatchObject({
|
|
87
|
+
stats: [{labels: ['linux'], queued: 1, reserved: 1}],
|
|
88
|
+
reservations: [{labels: ['linux'], count: 1}],
|
|
89
|
+
terminate_provisioned_runner_ids: [],
|
|
90
|
+
});
|
|
91
|
+
expect(res.json().reservations[0].reservation_id).toEqual(expect.any(String));
|
|
92
|
+
expect(res.json().reservations[0].expires_at).toEqual(expect.any(String));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('returns stats without reservations in observe-only mode', async () => {
|
|
96
|
+
await pendingJobFactory.create({workspaceId, requiredLabels: ['linux']});
|
|
97
|
+
|
|
98
|
+
const res = await app.inject({
|
|
99
|
+
method: 'POST',
|
|
100
|
+
url: '/provisioners/demand/poll',
|
|
101
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
102
|
+
payload: {
|
|
103
|
+
wait_seconds: 0,
|
|
104
|
+
max_reservations: 0,
|
|
105
|
+
templates: [
|
|
106
|
+
{
|
|
107
|
+
template_key: 'linux',
|
|
108
|
+
labels: ['linux'],
|
|
109
|
+
available_slots: 1,
|
|
110
|
+
starting: 0,
|
|
111
|
+
running: 1,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
expect(res.statusCode).toBe(200);
|
|
118
|
+
expect(res.json()).toMatchObject({
|
|
119
|
+
stats: [{labels: ['linux'], queued: 1, reserved: 0}],
|
|
120
|
+
reservations: [],
|
|
121
|
+
terminate_provisioned_runner_ids: [],
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('returns terminate intent ids for active provisioned runners with cancelled latest jobs', async () => {
|
|
126
|
+
await provisionedRunnerFactory.create({
|
|
127
|
+
workspaceId,
|
|
128
|
+
provisionerId: provisionerTokenId,
|
|
129
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
130
|
+
state: 'running',
|
|
131
|
+
});
|
|
132
|
+
await insertRunningJob({
|
|
133
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
134
|
+
cancellationRequestedAt: new Date('2025-01-01T00:01:00.000Z'),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const res = await app.inject({
|
|
138
|
+
method: 'POST',
|
|
139
|
+
url: '/provisioners/demand/poll',
|
|
140
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
141
|
+
payload: {
|
|
142
|
+
wait_seconds: 0,
|
|
143
|
+
max_reservations: 0,
|
|
144
|
+
templates: [
|
|
145
|
+
{
|
|
146
|
+
template_key: 'linux',
|
|
147
|
+
labels: ['linux'],
|
|
148
|
+
available_slots: 1,
|
|
149
|
+
starting: 0,
|
|
150
|
+
running: 1,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(res.statusCode).toBe(200);
|
|
157
|
+
expect(res.json()).toMatchObject({
|
|
158
|
+
reservations: [],
|
|
159
|
+
terminate_provisioned_runner_ids: ['provisioned-runner-1'],
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('records count divergence and terminate-intent metrics for the returned poll result', async () => {
|
|
164
|
+
const divergenceSpy = vi.spyOn(provisionedRunnerCountDivergenceCount, 'add');
|
|
165
|
+
const intentSpy = vi.spyOn(provisionedRunnerTerminateIntentIssuedCount, 'add');
|
|
166
|
+
await provisionedRunnerFactory.create({
|
|
167
|
+
workspaceId,
|
|
168
|
+
provisionerId: provisionerTokenId,
|
|
169
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
170
|
+
templateKey: 'linux',
|
|
171
|
+
state: 'running',
|
|
172
|
+
});
|
|
173
|
+
await provisionedRunnerFactory.create({
|
|
174
|
+
workspaceId,
|
|
175
|
+
provisionerId: provisionerTokenId,
|
|
176
|
+
provisionedRunnerId: 'provisioned-runner-2',
|
|
177
|
+
templateKey: 'linux',
|
|
178
|
+
state: 'running',
|
|
179
|
+
});
|
|
180
|
+
await insertRunningJob({
|
|
181
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
182
|
+
cancellationRequestedAt: new Date('2025-01-01T00:01:00.000Z'),
|
|
183
|
+
});
|
|
184
|
+
const divergenceCallsBefore = divergenceSpy.mock.calls.length;
|
|
185
|
+
const intentCallsBefore = intentSpy.mock.calls.length;
|
|
186
|
+
|
|
187
|
+
const res = await app.inject({
|
|
188
|
+
method: 'POST',
|
|
189
|
+
url: '/provisioners/demand/poll',
|
|
190
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
191
|
+
payload: {
|
|
192
|
+
wait_seconds: 0,
|
|
193
|
+
max_reservations: 0,
|
|
194
|
+
templates: [
|
|
195
|
+
{
|
|
196
|
+
template_key: 'linux',
|
|
197
|
+
labels: ['linux'],
|
|
198
|
+
available_slots: 1,
|
|
199
|
+
starting: 0,
|
|
200
|
+
running: 1,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(res.statusCode).toBe(200);
|
|
207
|
+
expect(res.json()).toMatchObject({
|
|
208
|
+
reservations: [],
|
|
209
|
+
terminate_provisioned_runner_ids: ['provisioned-runner-1'],
|
|
210
|
+
});
|
|
211
|
+
const divergenceCalls = divergenceSpy.mock.calls
|
|
212
|
+
.slice(divergenceCallsBefore)
|
|
213
|
+
.filter(
|
|
214
|
+
([value, attributes]) =>
|
|
215
|
+
value === 1 &&
|
|
216
|
+
JSON.stringify(attributes) ===
|
|
217
|
+
JSON.stringify({state: 'running', direction: 'backend-higher'}),
|
|
218
|
+
);
|
|
219
|
+
const intentCalls = intentSpy.mock.calls
|
|
220
|
+
.slice(intentCallsBefore)
|
|
221
|
+
.filter(
|
|
222
|
+
([value, attributes]) =>
|
|
223
|
+
value === 1 &&
|
|
224
|
+
JSON.stringify(attributes) ===
|
|
225
|
+
JSON.stringify({surface: 'poll-demand', reason: 'job-cancelled'}),
|
|
226
|
+
);
|
|
227
|
+
expect(divergenceCalls).toHaveLength(1);
|
|
228
|
+
expect(intentCalls).toHaveLength(1);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('returns 400 for max reservations above the request bound', async () => {
|
|
232
|
+
const res = await app.inject({
|
|
233
|
+
method: 'POST',
|
|
234
|
+
url: '/provisioners/demand/poll',
|
|
235
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
236
|
+
payload: body({max_reservations: 1001}),
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(res.statusCode).toBe(400);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('returns 400 for too many templates', async () => {
|
|
243
|
+
const templates = Array.from({length: 101}, (_, index) => ({
|
|
244
|
+
template_key: `linux-${index}`,
|
|
245
|
+
labels: ['linux'],
|
|
246
|
+
available_slots: 1,
|
|
247
|
+
starting: 0,
|
|
248
|
+
running: 0,
|
|
249
|
+
}));
|
|
250
|
+
|
|
251
|
+
const res = await app.inject({
|
|
252
|
+
method: 'POST',
|
|
253
|
+
url: '/provisioners/demand/poll',
|
|
254
|
+
headers: {authorization: `Bearer ${VALID_PROVISIONER_TOKEN}`},
|
|
255
|
+
payload: {wait_seconds: 0, max_reservations: 1, templates},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
expect(res.statusCode).toBe(400);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('returns 401 without authorization', async () => {
|
|
262
|
+
const res = await app.inject({
|
|
263
|
+
method: 'POST',
|
|
264
|
+
url: '/provisioners/demand/poll',
|
|
265
|
+
payload: body({max_reservations: 1}),
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(res.statusCode).toBe(401);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('returns 401 with invalid authorization', async () => {
|
|
272
|
+
const res = await app.inject({
|
|
273
|
+
method: 'POST',
|
|
274
|
+
url: '/provisioners/demand/poll',
|
|
275
|
+
headers: {authorization: 'Bearer invalid'},
|
|
276
|
+
payload: body({max_reservations: 1}),
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
expect(res.statusCode).toBe(401);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
function body(params: {max_reservations: number}) {
|
|
283
|
+
return {
|
|
284
|
+
wait_seconds: 0,
|
|
285
|
+
max_reservations: params.max_reservations,
|
|
286
|
+
templates: [
|
|
287
|
+
{
|
|
288
|
+
template_key: 'linux',
|
|
289
|
+
labels: ['linux'],
|
|
290
|
+
available_slots: 1,
|
|
291
|
+
starting: 0,
|
|
292
|
+
running: 0,
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function insertRunningJob(params: {
|
|
299
|
+
provisionedRunnerId: string;
|
|
300
|
+
cancellationRequestedAt?: Date | null;
|
|
301
|
+
}) {
|
|
302
|
+
const runnerSession = await runnerSessionFactory.create({workspaceId});
|
|
303
|
+
|
|
304
|
+
await db()
|
|
305
|
+
.insert(runningJobExecutions)
|
|
306
|
+
.values({
|
|
307
|
+
workspaceId,
|
|
308
|
+
workflowRunId: crypto.randomUUID(),
|
|
309
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
310
|
+
jobId: crypto.randomUUID(),
|
|
311
|
+
jobExecutionId: crypto.randomUUID(),
|
|
312
|
+
projectId: crypto.randomUUID(),
|
|
313
|
+
runnerSessionId: runnerSession.id,
|
|
314
|
+
provisionerId: provisionerTokenId,
|
|
315
|
+
provisionedRunnerId: params.provisionedRunnerId,
|
|
316
|
+
requiredLabels: ['linux'],
|
|
317
|
+
runnerLabels: ['linux'],
|
|
318
|
+
startedAt: new Date('2025-01-01T00:00:00.000Z'),
|
|
319
|
+
lastHeartbeatAt: new Date('2025-01-01T00:00:00.000Z'),
|
|
320
|
+
cancellationRequestedAt: params.cancellationRequestedAt ?? null,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {requireProvisionerContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {pollDemandBodySchema, pollDemandResponseSchema} from '@shipfox/api-runners-dto';
|
|
3
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
4
|
+
import {config} from '#config.js';
|
|
5
|
+
import {pollDemand, releaseReservationGrants} from '#core/demand.js';
|
|
6
|
+
import type {ReservationGrant} from '#db/reservations.js';
|
|
7
|
+
import {toPollDemandResponseDto} from '#presentation/dto/index.js';
|
|
8
|
+
|
|
9
|
+
const TERMINATE_INTENT_LIMIT = 1000;
|
|
10
|
+
|
|
11
|
+
export const pollDemandRoute = defineRoute({
|
|
12
|
+
method: 'POST',
|
|
13
|
+
path: '/demand/poll',
|
|
14
|
+
description: 'Poll aggregate runner demand and reserve capacity for a provisioner',
|
|
15
|
+
schema: {
|
|
16
|
+
body: pollDemandBodySchema,
|
|
17
|
+
response: {
|
|
18
|
+
200: pollDemandResponseSchema,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
handler: async (request, reply) => {
|
|
22
|
+
const {provisionerTokenId, workspaceId} = requireProvisionerContext(request);
|
|
23
|
+
const abortController = new AbortController();
|
|
24
|
+
let responseFinished = false;
|
|
25
|
+
let responseReservations: ReservationGrant[] = [];
|
|
26
|
+
reply.raw.on('finish', () => {
|
|
27
|
+
responseFinished = true;
|
|
28
|
+
});
|
|
29
|
+
reply.raw.on('close', () => {
|
|
30
|
+
if (!responseFinished) {
|
|
31
|
+
abortController.abort();
|
|
32
|
+
void releaseReservationGrants(responseReservations).catch(() => undefined);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const result = await pollDemand({
|
|
37
|
+
workspaceId,
|
|
38
|
+
provisionerId: provisionerTokenId,
|
|
39
|
+
maxReservations: request.body.max_reservations,
|
|
40
|
+
waitSeconds: request.body.wait_seconds,
|
|
41
|
+
ttlSeconds: config.RESERVATION_TTL_SECONDS,
|
|
42
|
+
terminateIntentLimit: TERMINATE_INTENT_LIMIT,
|
|
43
|
+
templates: request.body.templates.map((template) => ({
|
|
44
|
+
templateKey: template.template_key,
|
|
45
|
+
labels: template.labels,
|
|
46
|
+
availableSlots: template.available_slots,
|
|
47
|
+
starting: template.starting,
|
|
48
|
+
running: template.running,
|
|
49
|
+
})),
|
|
50
|
+
signal: abortController.signal,
|
|
51
|
+
});
|
|
52
|
+
responseReservations = result.reservations;
|
|
53
|
+
|
|
54
|
+
return toPollDemandResponseDto(result);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {AUTH_PROVISIONER_TOKEN, AUTH_USER} from '@shipfox/api-auth-context';
|
|
2
|
+
import type {AuthMethod} from '@shipfox/node-fastify';
|
|
3
|
+
import {closeApp, createApp} from '@shipfox/node-fastify';
|
|
4
|
+
import {generateOpaqueToken} from '@shipfox/node-tokens';
|
|
5
|
+
import type {FastifyInstance} from 'fastify';
|
|
6
|
+
import * as provisionerTokenDb from '#db/provisioner-tokens.js';
|
|
7
|
+
import {revokeProvisionerToken} from '#db/provisioner-tokens.js';
|
|
8
|
+
import {createProvisionerTokenAuthMethod} from '#presentation/auth/index.js';
|
|
9
|
+
import {provisionerTokenFactory} from '#test/index.js';
|
|
10
|
+
import {provisionerRoutes} from './index.js';
|
|
11
|
+
|
|
12
|
+
const fakeUserAuth: AuthMethod = {
|
|
13
|
+
name: AUTH_USER,
|
|
14
|
+
authenticate: () => Promise.resolve(),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('provisioner me route', () => {
|
|
18
|
+
let app: FastifyInstance;
|
|
19
|
+
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
await closeApp();
|
|
22
|
+
app = await createApp({
|
|
23
|
+
auth: [fakeUserAuth, createProvisionerTokenAuthMethod()],
|
|
24
|
+
routes: provisionerRoutes,
|
|
25
|
+
swagger: false,
|
|
26
|
+
});
|
|
27
|
+
await app.ready();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(async () => {
|
|
31
|
+
await closeApp();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('uses provisioner auth for provisioner routes', () => {
|
|
35
|
+
expect(provisionerRoutes[2]?.auth).toBe(AUTH_PROVISIONER_TOKEN);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns the authenticated provisioner identity', async () => {
|
|
39
|
+
const workspaceId = crypto.randomUUID();
|
|
40
|
+
const rawToken = generateOpaqueToken('provisionerToken');
|
|
41
|
+
const token = await provisionerTokenFactory.create({workspaceId}, {transient: {rawToken}});
|
|
42
|
+
|
|
43
|
+
const res = await app.inject({
|
|
44
|
+
method: 'GET',
|
|
45
|
+
url: '/provisioners/me',
|
|
46
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(res.statusCode).toBe(200);
|
|
50
|
+
expect(res.json()).toEqual({id: token.id, workspace_id: workspaceId});
|
|
51
|
+
const touched = await provisionerTokenDb.resolveProvisionerTokenByHash(token.hashedToken);
|
|
52
|
+
expect(touched?.lastSeenAt).toBeInstanceOf(Date);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('does not reject valid auth when the last-seen write fails', async () => {
|
|
56
|
+
await closeApp();
|
|
57
|
+
const workspaceId = crypto.randomUUID();
|
|
58
|
+
const rawToken = generateOpaqueToken('provisionerToken');
|
|
59
|
+
const token = await provisionerTokenFactory.create({workspaceId}, {transient: {rawToken}});
|
|
60
|
+
vi.spyOn(provisionerTokenDb, 'touchProvisionerLastSeen').mockRejectedValueOnce(
|
|
61
|
+
new Error('database unavailable'),
|
|
62
|
+
);
|
|
63
|
+
app = await createApp({
|
|
64
|
+
auth: [fakeUserAuth, createProvisionerTokenAuthMethod()],
|
|
65
|
+
routes: provisionerRoutes,
|
|
66
|
+
swagger: false,
|
|
67
|
+
});
|
|
68
|
+
await app.ready();
|
|
69
|
+
|
|
70
|
+
const res = await app.inject({
|
|
71
|
+
method: 'GET',
|
|
72
|
+
url: '/provisioners/me',
|
|
73
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(res.statusCode).toBe(200);
|
|
77
|
+
expect(res.json()).toEqual({id: token.id, workspace_id: workspaceId});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('returns 401 without an authorization header', async () => {
|
|
81
|
+
const res = await app.inject({
|
|
82
|
+
method: 'GET',
|
|
83
|
+
url: '/provisioners/me',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(res.statusCode).toBe(401);
|
|
87
|
+
expect(res.json().code).toBe('unauthorized');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns 401 for a non-provisioner token type before lookup', async () => {
|
|
91
|
+
const rawToken = generateOpaqueToken('manualRegistrationToken');
|
|
92
|
+
|
|
93
|
+
const res = await app.inject({
|
|
94
|
+
method: 'GET',
|
|
95
|
+
url: '/provisioners/me',
|
|
96
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(res.statusCode).toBe(401);
|
|
100
|
+
expect(res.json().code).toBe('unauthorized');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('returns 401 for an unknown provisioner token', async () => {
|
|
104
|
+
const rawToken = generateOpaqueToken('provisionerToken');
|
|
105
|
+
|
|
106
|
+
const res = await app.inject({
|
|
107
|
+
method: 'GET',
|
|
108
|
+
url: '/provisioners/me',
|
|
109
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(res.statusCode).toBe(401);
|
|
113
|
+
expect(res.json().code).toBe('unauthorized');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('returns 401 for a revoked provisioner token', async () => {
|
|
117
|
+
const workspaceId = crypto.randomUUID();
|
|
118
|
+
const rawToken = generateOpaqueToken('provisionerToken');
|
|
119
|
+
const token = await provisionerTokenFactory.create({workspaceId}, {transient: {rawToken}});
|
|
120
|
+
await revokeProvisionerToken({
|
|
121
|
+
tokenId: token.id,
|
|
122
|
+
workspaceId,
|
|
123
|
+
revokedByUserId: crypto.randomUUID(),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const res = await app.inject({
|
|
127
|
+
method: 'GET',
|
|
128
|
+
url: '/provisioners/me',
|
|
129
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
expect(res.statusCode).toBe(401);
|
|
133
|
+
expect(res.json().code).toBe('provisioner-token-revoked');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('returns 401 for an expired provisioner token', async () => {
|
|
137
|
+
const workspaceId = crypto.randomUUID();
|
|
138
|
+
const rawToken = generateOpaqueToken('provisionerToken');
|
|
139
|
+
await provisionerTokenFactory.create(
|
|
140
|
+
{workspaceId, expiresAt: new Date(Date.now() - 60_000)},
|
|
141
|
+
{transient: {rawToken}},
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const res = await app.inject({
|
|
145
|
+
method: 'GET',
|
|
146
|
+
url: '/provisioners/me',
|
|
147
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
expect(res.statusCode).toBe(401);
|
|
151
|
+
expect(res.json().code).toBe('provisioner-token-expired');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('returns 401 for a provisioner token expiring at the current instant', async () => {
|
|
155
|
+
const now = new Date('2026-01-01T00:00:00.000Z');
|
|
156
|
+
const workspaceId = crypto.randomUUID();
|
|
157
|
+
const rawToken = generateOpaqueToken('provisionerToken');
|
|
158
|
+
await provisionerTokenFactory.create({workspaceId, expiresAt: now}, {transient: {rawToken}});
|
|
159
|
+
|
|
160
|
+
vi.useFakeTimers();
|
|
161
|
+
vi.setSystemTime(now);
|
|
162
|
+
const res = await app.inject({
|
|
163
|
+
method: 'GET',
|
|
164
|
+
url: '/provisioners/me',
|
|
165
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
166
|
+
});
|
|
167
|
+
vi.useRealTimers();
|
|
168
|
+
|
|
169
|
+
expect(res.statusCode).toBe(401);
|
|
170
|
+
expect(res.json().code).toBe('provisioner-token-expired');
|
|
171
|
+
});
|
|
172
|
+
});
|