@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 {
|
|
2
|
+
createLeaseTokenAuthMethod,
|
|
3
|
+
createRunnerSessionAuthMethod,
|
|
4
|
+
verifyRunnerSessionToken,
|
|
5
|
+
} from '@shipfox/api-auth';
|
|
6
|
+
import {AUTH_PROVISIONER_TOKEN, AUTH_USER} from '@shipfox/api-auth-context';
|
|
7
|
+
import type {RunnerToolCapabilitiesDto} from '@shipfox/api-runners-dto';
|
|
8
|
+
import type {AuthMethod} from '@shipfox/node-fastify';
|
|
9
|
+
import {closeApp, createApp} from '@shipfox/node-fastify';
|
|
10
|
+
import {generateOpaqueToken} from '@shipfox/node-tokens';
|
|
11
|
+
import {eq, sql} from 'drizzle-orm';
|
|
12
|
+
import type {FastifyInstance} from 'fastify';
|
|
13
|
+
import {config} from '#config.js';
|
|
14
|
+
import {hashRunnersRateLimitIdentifier} from '#core/rate-limit.js';
|
|
15
|
+
import {db} from '#db/db.js';
|
|
16
|
+
import {revokeManualRegistrationToken} from '#db/manual-registration-tokens.js';
|
|
17
|
+
import {ephemeralRegistrationTokens} from '#db/schema/ephemeral-registration-tokens.js';
|
|
18
|
+
import {runnersRateLimits} from '#db/schema/rate-limits.js';
|
|
19
|
+
import {runnerSessions} from '#db/schema/runner-sessions.js';
|
|
20
|
+
import {createRunnerRegistrationTokenAuthMethod} from '#presentation/auth/index.js';
|
|
21
|
+
import {ephemeralRegistrationTokenFactory, manualRegistrationTokenFactory} from '#test/index.js';
|
|
22
|
+
import {runnerRoutes} from './index.js';
|
|
23
|
+
|
|
24
|
+
const fakeUserAuth: AuthMethod = {
|
|
25
|
+
name: AUTH_USER,
|
|
26
|
+
authenticate: () => Promise.resolve(),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const fakeProvisionerAuth: AuthMethod = {
|
|
30
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
31
|
+
authenticate: () => Promise.resolve(),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const fullCapabilities: RunnerToolCapabilitiesDto = {
|
|
35
|
+
harnesses: {
|
|
36
|
+
pi: {tools: ['read', 'bash', 'web_search']},
|
|
37
|
+
claude: {tools: ['Read', 'Bash', 'WebSearch']},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe('POST /runners/register', () => {
|
|
42
|
+
let app: FastifyInstance;
|
|
43
|
+
let rawToken: string;
|
|
44
|
+
let workspaceId: string;
|
|
45
|
+
|
|
46
|
+
beforeAll(async () => {
|
|
47
|
+
app = await createApp({
|
|
48
|
+
auth: [
|
|
49
|
+
fakeUserAuth,
|
|
50
|
+
createRunnerRegistrationTokenAuthMethod(),
|
|
51
|
+
createRunnerSessionAuthMethod(),
|
|
52
|
+
createLeaseTokenAuthMethod(),
|
|
53
|
+
fakeProvisionerAuth,
|
|
54
|
+
],
|
|
55
|
+
routes: runnerRoutes,
|
|
56
|
+
swagger: false,
|
|
57
|
+
});
|
|
58
|
+
await app.ready();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterAll(async () => {
|
|
62
|
+
await closeApp();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
beforeEach(async () => {
|
|
66
|
+
rawToken = generateOpaqueToken('manualRegistrationToken');
|
|
67
|
+
workspaceId = crypto.randomUUID();
|
|
68
|
+
await manualRegistrationTokenFactory.create({workspaceId}, {transient: {rawToken}});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('exchanges a registration token for a manual runner session', async () => {
|
|
72
|
+
const res = await app.inject({
|
|
73
|
+
method: 'POST',
|
|
74
|
+
url: '/runners/register',
|
|
75
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
76
|
+
payload: {labels: ['Linux', 'x64', 'linux']},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(res.statusCode).toBe(200);
|
|
80
|
+
const body = res.json();
|
|
81
|
+
expect(typeof body.session_token).toBe('string');
|
|
82
|
+
expect(body.session_id).toEqual(expect.any(String));
|
|
83
|
+
expect(body.mode).toBe('manual');
|
|
84
|
+
expect(body.max_claims).toBeNull();
|
|
85
|
+
|
|
86
|
+
const claims = await verifyRunnerSessionToken(body.session_token);
|
|
87
|
+
expect(claims).toMatchObject({
|
|
88
|
+
runnerSessionId: body.session_id,
|
|
89
|
+
workspaceId,
|
|
90
|
+
scope: 'workspace',
|
|
91
|
+
labels: ['linux', 'x64'],
|
|
92
|
+
maxClaims: null,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const rows = await db()
|
|
96
|
+
.select()
|
|
97
|
+
.from(runnerSessions)
|
|
98
|
+
.where(eq(runnerSessions.id, body.session_id));
|
|
99
|
+
expect(rows[0]?.labels).toEqual(['linux', 'x64']);
|
|
100
|
+
expect(rows[0]?.registrationTokenKind).toBe('manual');
|
|
101
|
+
expect(rows[0]?.provisionerId).toBeNull();
|
|
102
|
+
expect(rows[0]?.provisionedRunnerId).toBeNull();
|
|
103
|
+
expect(rows[0]?.toolCapabilities).toBeNull();
|
|
104
|
+
expect(rows[0]?.toolCapabilitiesReportedAt).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('persists a full capability report for a manual runner session', async () => {
|
|
108
|
+
const res = await app.inject({
|
|
109
|
+
method: 'POST',
|
|
110
|
+
url: '/runners/register',
|
|
111
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
112
|
+
payload: {labels: ['linux'], capabilities: fullCapabilities},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(res.statusCode).toBe(200);
|
|
116
|
+
const [session] = await db()
|
|
117
|
+
.select()
|
|
118
|
+
.from(runnerSessions)
|
|
119
|
+
.where(eq(runnerSessions.id, res.json().session_id));
|
|
120
|
+
expect(session?.toolCapabilities).toEqual(fullCapabilities);
|
|
121
|
+
expect(session?.toolCapabilitiesReportedAt).toBeInstanceOf(Date);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('exchanges an ephemeral registration token for a one-claim runner session', async () => {
|
|
125
|
+
const ephemeralRawToken = generateOpaqueToken('ephemeralRegistrationToken');
|
|
126
|
+
const token = await ephemeralRegistrationTokenFactory.create(
|
|
127
|
+
{workspaceId},
|
|
128
|
+
{transient: {rawToken: ephemeralRawToken}},
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const res = await app.inject({
|
|
132
|
+
method: 'POST',
|
|
133
|
+
url: '/runners/register',
|
|
134
|
+
headers: {authorization: `Bearer ${ephemeralRawToken}`},
|
|
135
|
+
payload: {labels: ['Linux', 'x64'], capabilities: {harnesses: {pi: {tools: ['read']}}}},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(res.statusCode).toBe(200);
|
|
139
|
+
const body = res.json();
|
|
140
|
+
expect(body.mode).toBe('ephemeral');
|
|
141
|
+
expect(body.max_claims).toBe(1);
|
|
142
|
+
|
|
143
|
+
const claims = await verifyRunnerSessionToken(body.session_token);
|
|
144
|
+
expect(claims?.maxClaims).toBe(1);
|
|
145
|
+
|
|
146
|
+
const [session] = await db()
|
|
147
|
+
.select()
|
|
148
|
+
.from(runnerSessions)
|
|
149
|
+
.where(eq(runnerSessions.id, body.session_id));
|
|
150
|
+
expect(session?.registrationTokenKind).toBe('ephemeral');
|
|
151
|
+
expect(session?.provisionerId).toBe(token.provisionerId);
|
|
152
|
+
expect(session?.provisionedRunnerId).toBe(token.provisionedRunnerId);
|
|
153
|
+
expect(session?.maxClaims).toBe(1);
|
|
154
|
+
expect(session?.claimsUsed).toBe(0);
|
|
155
|
+
expect(session?.toolCapabilities).toEqual({harnesses: {pi: {tools: ['read']}}});
|
|
156
|
+
expect(session?.toolCapabilitiesReportedAt).toBeInstanceOf(Date);
|
|
157
|
+
|
|
158
|
+
const [consumed] = await db()
|
|
159
|
+
.select()
|
|
160
|
+
.from(ephemeralRegistrationTokens)
|
|
161
|
+
.where(eq(ephemeralRegistrationTokens.id, token.id));
|
|
162
|
+
expect(consumed?.consumedAt).toBeInstanceOf(Date);
|
|
163
|
+
expect(consumed?.consumedSessionId).toBe(body.session_id);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('rejects malformed capability reports without creating a runner session', async () => {
|
|
167
|
+
const res = await app.inject({
|
|
168
|
+
method: 'POST',
|
|
169
|
+
url: '/runners/register',
|
|
170
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
171
|
+
payload: {labels: ['linux'], capabilities: {harnesses: {pi: {tools: ['read', 'read']}}}},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
expect(res.statusCode).toBe(400);
|
|
175
|
+
const rows = await db()
|
|
176
|
+
.select()
|
|
177
|
+
.from(runnerSessions)
|
|
178
|
+
.where(eq(runnerSessions.workspaceId, workspaceId));
|
|
179
|
+
expect(rows).toHaveLength(0);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('creates independent sessions from the same registration token', async () => {
|
|
183
|
+
const first = await app.inject({
|
|
184
|
+
method: 'POST',
|
|
185
|
+
url: '/runners/register',
|
|
186
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
187
|
+
payload: {labels: ['linux']},
|
|
188
|
+
});
|
|
189
|
+
const second = await app.inject({
|
|
190
|
+
method: 'POST',
|
|
191
|
+
url: '/runners/register',
|
|
192
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
193
|
+
payload: {labels: ['macos']},
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(first.statusCode).toBe(200);
|
|
197
|
+
expect(second.statusCode).toBe(200);
|
|
198
|
+
expect(first.json().session_id).not.toBe(second.json().session_id);
|
|
199
|
+
|
|
200
|
+
const rows = await db()
|
|
201
|
+
.select()
|
|
202
|
+
.from(runnerSessions)
|
|
203
|
+
.where(eq(runnerSessions.workspaceId, workspaceId));
|
|
204
|
+
expect(rows.map((row) => row.labels).sort()).toEqual([['linux'], ['macos']]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('returns 401 when the registration token is expired', async () => {
|
|
208
|
+
const expiredRawToken = generateOpaqueToken('manualRegistrationToken');
|
|
209
|
+
await manualRegistrationTokenFactory.create(
|
|
210
|
+
{workspaceId, expiresAt: new Date(Date.now() - 1000)},
|
|
211
|
+
{transient: {rawToken: expiredRawToken}},
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
const res = await app.inject({
|
|
215
|
+
method: 'POST',
|
|
216
|
+
url: '/runners/register',
|
|
217
|
+
headers: {authorization: `Bearer ${expiredRawToken}`},
|
|
218
|
+
payload: {labels: ['linux']},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(res.statusCode).toBe(401);
|
|
222
|
+
expect(res.json().code).toBe('registration-token-expired');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('returns 409 when an ephemeral registration token is reused', async () => {
|
|
226
|
+
const ephemeralRawToken = generateOpaqueToken('ephemeralRegistrationToken');
|
|
227
|
+
await ephemeralRegistrationTokenFactory.create(
|
|
228
|
+
{workspaceId},
|
|
229
|
+
{transient: {rawToken: ephemeralRawToken}},
|
|
230
|
+
);
|
|
231
|
+
const request = {
|
|
232
|
+
method: 'POST',
|
|
233
|
+
url: '/runners/register',
|
|
234
|
+
headers: {authorization: `Bearer ${ephemeralRawToken}`},
|
|
235
|
+
payload: {labels: ['linux']},
|
|
236
|
+
} as const;
|
|
237
|
+
|
|
238
|
+
const first = await app.inject(request);
|
|
239
|
+
const second = await app.inject(request);
|
|
240
|
+
|
|
241
|
+
expect(first.statusCode).toBe(200);
|
|
242
|
+
expect(second.statusCode).toBe(409);
|
|
243
|
+
expect(second.json().code).toBe('registration-token-consumed');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('returns 429 when the ephemeral registration rate limit is exceeded', async () => {
|
|
247
|
+
const ephemeralRawToken = generateOpaqueToken('ephemeralRegistrationToken');
|
|
248
|
+
const token = await ephemeralRegistrationTokenFactory.create(
|
|
249
|
+
{workspaceId},
|
|
250
|
+
{transient: {rawToken: ephemeralRawToken}},
|
|
251
|
+
);
|
|
252
|
+
await seedEphemeralRegisterRateLimit(
|
|
253
|
+
token.id,
|
|
254
|
+
config.EPHEMERAL_REGISTER_RATE_LIMIT_MAX_REQUESTS,
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const res = await app.inject({
|
|
258
|
+
method: 'POST',
|
|
259
|
+
url: '/runners/register',
|
|
260
|
+
headers: {authorization: `Bearer ${ephemeralRawToken}`},
|
|
261
|
+
payload: {labels: ['linux']},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const [persistedToken] = await db()
|
|
265
|
+
.select()
|
|
266
|
+
.from(ephemeralRegistrationTokens)
|
|
267
|
+
.where(eq(ephemeralRegistrationTokens.id, token.id));
|
|
268
|
+
expect(res.statusCode).toBe(429);
|
|
269
|
+
expect(res.headers['retry-after']).toEqual(expect.any(String));
|
|
270
|
+
expect(res.json()).toMatchObject({
|
|
271
|
+
code: 'rate-limited',
|
|
272
|
+
details: {retry_after_seconds: expect.any(Number)},
|
|
273
|
+
});
|
|
274
|
+
expect(persistedToken?.consumedAt).toBeNull();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('returns 503 when the ephemeral registration rate limiter is unavailable', async () => {
|
|
278
|
+
const ephemeralRawToken = generateOpaqueToken('ephemeralRegistrationToken');
|
|
279
|
+
const token = await ephemeralRegistrationTokenFactory.create(
|
|
280
|
+
{workspaceId},
|
|
281
|
+
{transient: {rawToken: ephemeralRawToken}},
|
|
282
|
+
);
|
|
283
|
+
const identifierHmac = await seedEphemeralRegisterRateLimit(token.id, 1);
|
|
284
|
+
|
|
285
|
+
await db().transaction(async (tx) => {
|
|
286
|
+
await tx.execute(sql`
|
|
287
|
+
SELECT 1
|
|
288
|
+
FROM runners_rate_limits
|
|
289
|
+
WHERE identifier_hmac = ${identifierHmac}
|
|
290
|
+
FOR UPDATE
|
|
291
|
+
`);
|
|
292
|
+
|
|
293
|
+
const res = await app.inject({
|
|
294
|
+
method: 'POST',
|
|
295
|
+
url: '/runners/register',
|
|
296
|
+
headers: {authorization: `Bearer ${ephemeralRawToken}`},
|
|
297
|
+
payload: {labels: ['linux']},
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
expect(res.statusCode).toBe(503);
|
|
301
|
+
expect(res.json().code).toBe('runners-rate-limit-unavailable');
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const [persistedToken] = await db()
|
|
305
|
+
.select()
|
|
306
|
+
.from(ephemeralRegistrationTokens)
|
|
307
|
+
.where(eq(ephemeralRegistrationTokens.id, token.id));
|
|
308
|
+
expect(persistedToken?.consumedAt).toBeNull();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('does not apply the ephemeral registration rate limit to manual registration', async () => {
|
|
312
|
+
const statusCodes: number[] = [];
|
|
313
|
+
|
|
314
|
+
for (let index = 0; index <= config.EPHEMERAL_REGISTER_RATE_LIMIT_MAX_REQUESTS; index += 1) {
|
|
315
|
+
const res = await app.inject({
|
|
316
|
+
method: 'POST',
|
|
317
|
+
url: '/runners/register',
|
|
318
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
319
|
+
payload: {labels: [`linux-${index}`]},
|
|
320
|
+
});
|
|
321
|
+
statusCodes.push(res.statusCode);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
expect(statusCodes).toEqual(
|
|
325
|
+
Array.from({length: config.EPHEMERAL_REGISTER_RATE_LIMIT_MAX_REQUESTS + 1}, () => 200),
|
|
326
|
+
);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('returns 401 when an ephemeral registration token is expired', async () => {
|
|
330
|
+
const ephemeralRawToken = generateOpaqueToken('ephemeralRegistrationToken');
|
|
331
|
+
await ephemeralRegistrationTokenFactory.create(
|
|
332
|
+
{workspaceId, expiresAt: new Date(Date.now() - 1000)},
|
|
333
|
+
{transient: {rawToken: ephemeralRawToken}},
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
const res = await app.inject({
|
|
337
|
+
method: 'POST',
|
|
338
|
+
url: '/runners/register',
|
|
339
|
+
headers: {authorization: `Bearer ${ephemeralRawToken}`},
|
|
340
|
+
payload: {labels: ['linux']},
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
expect(res.statusCode).toBe(401);
|
|
344
|
+
expect(res.json().code).toBe('registration-token-expired');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('returns 401 when an ephemeral registration token is not found', async () => {
|
|
348
|
+
const res = await app.inject({
|
|
349
|
+
method: 'POST',
|
|
350
|
+
url: '/runners/register',
|
|
351
|
+
headers: {authorization: `Bearer ${generateOpaqueToken('ephemeralRegistrationToken')}`},
|
|
352
|
+
payload: {labels: ['linux']},
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
expect(res.statusCode).toBe(401);
|
|
356
|
+
expect(res.json().code).toBe('unauthorized');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('returns 401 when the registration token is revoked', async () => {
|
|
360
|
+
const revokedRawToken = generateOpaqueToken('manualRegistrationToken');
|
|
361
|
+
const token = await manualRegistrationTokenFactory.create(
|
|
362
|
+
{workspaceId},
|
|
363
|
+
{transient: {rawToken: revokedRawToken}},
|
|
364
|
+
);
|
|
365
|
+
await revokeManualRegistrationToken({tokenId: token.id, workspaceId});
|
|
366
|
+
|
|
367
|
+
const res = await app.inject({
|
|
368
|
+
method: 'POST',
|
|
369
|
+
url: '/runners/register',
|
|
370
|
+
headers: {authorization: `Bearer ${revokedRawToken}`},
|
|
371
|
+
payload: {labels: ['linux']},
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
expect(res.statusCode).toBe(401);
|
|
375
|
+
expect(res.json().code).toBe('manual-registration-token-revoked');
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('returns 401 when the registration token prefix is unknown', async () => {
|
|
379
|
+
const res = await app.inject({
|
|
380
|
+
method: 'POST',
|
|
381
|
+
url: '/runners/register',
|
|
382
|
+
headers: {authorization: 'Bearer sf_unknown_token'},
|
|
383
|
+
payload: {labels: ['linux']},
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
expect(res.statusCode).toBe(401);
|
|
387
|
+
expect(res.json().code).toBe('unauthorized');
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it.each([
|
|
391
|
+
['too many labels', {labels: Array.from({length: 21}, (_, index) => `label-${index}`)}],
|
|
392
|
+
['too long label', {labels: ['a'.repeat(129)]}],
|
|
393
|
+
['bad charset', {labels: ['linux/amd64']}],
|
|
394
|
+
])('returns 400 for %s', async (_case, payload) => {
|
|
395
|
+
const res = await app.inject({
|
|
396
|
+
method: 'POST',
|
|
397
|
+
url: '/runners/register',
|
|
398
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
399
|
+
payload,
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
expect(res.statusCode).toBe(400);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it.each([
|
|
406
|
+
['20 labels', {labels: Array.from({length: 20}, (_, index) => `label-${index}`)}],
|
|
407
|
+
['128-character label', {labels: ['a'.repeat(128)]}],
|
|
408
|
+
])('accepts %s', async (_case, payload) => {
|
|
409
|
+
const res = await app.inject({
|
|
410
|
+
method: 'POST',
|
|
411
|
+
url: '/runners/register',
|
|
412
|
+
headers: {authorization: `Bearer ${rawToken}`},
|
|
413
|
+
payload,
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
expect(res.statusCode).toBe(200);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
async function seedEphemeralRegisterRateLimit(
|
|
420
|
+
tokenId: string,
|
|
421
|
+
seedCount: number,
|
|
422
|
+
): Promise<string> {
|
|
423
|
+
const identifierHmac = hashRunnersRateLimitIdentifier({
|
|
424
|
+
action: 'ephemeral-register',
|
|
425
|
+
scope: 'ephemeral-token',
|
|
426
|
+
identifier: tokenId,
|
|
427
|
+
});
|
|
428
|
+
const windows = rateLimitWindows(config.EPHEMERAL_REGISTER_RATE_LIMIT_WINDOW_SECONDS);
|
|
429
|
+
|
|
430
|
+
await db()
|
|
431
|
+
.insert(runnersRateLimits)
|
|
432
|
+
.values(
|
|
433
|
+
windows.map((windowStart) => ({
|
|
434
|
+
action: 'ephemeral-register',
|
|
435
|
+
scope: 'ephemeral-token',
|
|
436
|
+
identifierHmac,
|
|
437
|
+
windowStart,
|
|
438
|
+
count: seedCount,
|
|
439
|
+
expiresAt: new Date(
|
|
440
|
+
windowStart.getTime() + config.EPHEMERAL_REGISTER_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,75 @@
|
|
|
1
|
+
import {registerRunnerBodySchema, registerRunnerResponseSchema} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
3
|
+
import {
|
|
4
|
+
EmptyRunnerLabelsError,
|
|
5
|
+
RegistrationTokenConsumedError,
|
|
6
|
+
RegistrationTokenExpiredError,
|
|
7
|
+
} from '#core/errors.js';
|
|
8
|
+
import {registerRunnerSession} from '#core/runner-sessions.js';
|
|
9
|
+
import {getRunnerContext} from '#presentation/auth/index.js';
|
|
10
|
+
import {createEphemeralRegisterRateLimitPreHandler} from './rate-limit.js';
|
|
11
|
+
|
|
12
|
+
export const registerRoute = defineRoute({
|
|
13
|
+
method: 'POST',
|
|
14
|
+
path: '/register',
|
|
15
|
+
description: 'Exchange a runner registration token for a runner session token',
|
|
16
|
+
schema: {
|
|
17
|
+
body: registerRunnerBodySchema,
|
|
18
|
+
response: {
|
|
19
|
+
200: registerRunnerResponseSchema,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
preHandler: createEphemeralRegisterRateLimitPreHandler(),
|
|
23
|
+
errorHandler: (error, request) => {
|
|
24
|
+
if (error instanceof EmptyRunnerLabelsError) {
|
|
25
|
+
throw new ClientError(error.message, 'empty-runner-labels', {status: 400});
|
|
26
|
+
}
|
|
27
|
+
if (error instanceof RegistrationTokenConsumedError) {
|
|
28
|
+
const runner = getRunnerContext(request);
|
|
29
|
+
if (runner.kind === 'ephemeral') {
|
|
30
|
+
request.log.warn(
|
|
31
|
+
{
|
|
32
|
+
ephemeralTokenId: error.ephemeralTokenId,
|
|
33
|
+
provisionerId: runner.provisionerId,
|
|
34
|
+
},
|
|
35
|
+
'Ephemeral registration token reuse rejected',
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
throw new ClientError(
|
|
39
|
+
'Registration token has already been consumed',
|
|
40
|
+
'registration-token-consumed',
|
|
41
|
+
{
|
|
42
|
+
status: 409,
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (error instanceof RegistrationTokenExpiredError) {
|
|
47
|
+
throw new ClientError('Registration token has expired', 'registration-token-expired', {
|
|
48
|
+
status: 401,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
52
|
+
},
|
|
53
|
+
handler: async (request) => {
|
|
54
|
+
const runner = getRunnerContext(request);
|
|
55
|
+
const result = await registerRunnerSession({
|
|
56
|
+
credential:
|
|
57
|
+
runner.kind === 'manual'
|
|
58
|
+
? {
|
|
59
|
+
kind: 'manual',
|
|
60
|
+
registrationTokenId: runner.registrationTokenId,
|
|
61
|
+
workspaceId: runner.workspaceId,
|
|
62
|
+
}
|
|
63
|
+
: runner,
|
|
64
|
+
labels: request.body.labels,
|
|
65
|
+
toolCapabilities: request.body.capabilities ?? null,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
session_token: result.sessionToken,
|
|
70
|
+
session_id: result.session.id,
|
|
71
|
+
mode: result.mode,
|
|
72
|
+
max_claims: result.maxClaims,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
});
|