@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,29 @@
|
|
|
1
|
+
import type {ProvisionerToken} from '#core/entities/provisioner-token.js';
|
|
2
|
+
|
|
3
|
+
export function toProvisionerTokenDto(token: ProvisionerToken): {
|
|
4
|
+
id: string;
|
|
5
|
+
workspace_id: string;
|
|
6
|
+
prefix: string;
|
|
7
|
+
name: string | null;
|
|
8
|
+
created_by_user_id: string;
|
|
9
|
+
revoked_by_user_id: string | null;
|
|
10
|
+
expires_at: string | null;
|
|
11
|
+
revoked_at: string | null;
|
|
12
|
+
last_seen_at: string | null;
|
|
13
|
+
created_at: string;
|
|
14
|
+
updated_at: string;
|
|
15
|
+
} {
|
|
16
|
+
return {
|
|
17
|
+
id: token.id,
|
|
18
|
+
workspace_id: token.workspaceId,
|
|
19
|
+
prefix: token.prefix,
|
|
20
|
+
name: token.name,
|
|
21
|
+
created_by_user_id: token.createdByUserId,
|
|
22
|
+
revoked_by_user_id: token.revokedByUserId,
|
|
23
|
+
expires_at: token.expiresAt?.toISOString() ?? null,
|
|
24
|
+
revoked_at: token.revokedAt?.toISOString() ?? null,
|
|
25
|
+
last_seen_at: token.lastSeenAt?.toISOString() ?? null,
|
|
26
|
+
created_at: token.createdAt.toISOString(),
|
|
27
|
+
updated_at: token.updatedAt.toISOString(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createProvisionerTokenAuthMethod,
|
|
3
|
+
createRunnerRegistrationTokenAuthMethod,
|
|
4
|
+
} from './auth/index.js';
|
|
5
|
+
export {runnerRoutes as routes} from './routes/index.js';
|
|
6
|
+
export {onWorkflowsJobExecutionTimedOut} from './subscribers/on-workflows-job-execution-timed-out.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createManualRegistrationTokenBodySchema,
|
|
3
|
+
createManualRegistrationTokenResponseSchema,
|
|
4
|
+
} from '@shipfox/api-runners-dto';
|
|
5
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
6
|
+
import {z} from 'zod';
|
|
7
|
+
import {createWorkspaceManualRegistrationToken} from '#core/index.js';
|
|
8
|
+
import {requireManualRegistrationTokenWorkspaceMembership} from './workspace-membership.js';
|
|
9
|
+
|
|
10
|
+
export const createManualRegistrationTokenRoute = defineRoute({
|
|
11
|
+
method: 'POST',
|
|
12
|
+
path: '/',
|
|
13
|
+
description: 'Create a token that lets a runner connect to your account',
|
|
14
|
+
schema: {
|
|
15
|
+
params: z.object({workspaceId: z.string().uuid()}),
|
|
16
|
+
body: createManualRegistrationTokenBodySchema,
|
|
17
|
+
response: {
|
|
18
|
+
201: createManualRegistrationTokenResponseSchema,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
handler: async (request, reply) => {
|
|
22
|
+
const {workspaceId} = request.params;
|
|
23
|
+
requireManualRegistrationTokenWorkspaceMembership({request, workspaceId});
|
|
24
|
+
const {name, ttl_seconds} = request.body;
|
|
25
|
+
|
|
26
|
+
const {token, rawToken} = await createWorkspaceManualRegistrationToken({
|
|
27
|
+
workspaceId,
|
|
28
|
+
name,
|
|
29
|
+
ttlSeconds: ttl_seconds,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
reply.code(201);
|
|
33
|
+
return {
|
|
34
|
+
id: token.id,
|
|
35
|
+
raw_token: rawToken,
|
|
36
|
+
prefix: token.prefix,
|
|
37
|
+
name: token.name,
|
|
38
|
+
workspace_id: token.workspaceId,
|
|
39
|
+
expires_at: token.expiresAt?.toISOString() ?? null,
|
|
40
|
+
created_at: token.createdAt.toISOString(),
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {requireUserContext, requireWorkspaceAccess} from '@shipfox/api-auth-context';
|
|
2
|
+
import {
|
|
3
|
+
createProvisionerTokenBodySchema,
|
|
4
|
+
createProvisionerTokenResponseSchema,
|
|
5
|
+
} from '@shipfox/api-runners-dto';
|
|
6
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
7
|
+
import {z} from 'zod';
|
|
8
|
+
import {createWorkspaceProvisionerToken} from '#core/index.js';
|
|
9
|
+
import {toProvisionerTokenDto} from '#presentation/dto/index.js';
|
|
10
|
+
|
|
11
|
+
export const createProvisionerTokenRoute = defineRoute({
|
|
12
|
+
method: 'POST',
|
|
13
|
+
path: '/',
|
|
14
|
+
description: 'Create a token that lets a provisioner connect to your account',
|
|
15
|
+
schema: {
|
|
16
|
+
params: z.object({workspaceId: z.string().uuid()}),
|
|
17
|
+
body: createProvisionerTokenBodySchema,
|
|
18
|
+
response: {
|
|
19
|
+
201: createProvisionerTokenResponseSchema,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
handler: async (request, reply) => {
|
|
23
|
+
const {workspaceId} = request.params;
|
|
24
|
+
requireWorkspaceAccess({request, workspaceId});
|
|
25
|
+
const user = requireUserContext(request);
|
|
26
|
+
const {name, ttl_seconds} = request.body;
|
|
27
|
+
|
|
28
|
+
const {token, rawToken} = await createWorkspaceProvisionerToken({
|
|
29
|
+
workspaceId,
|
|
30
|
+
createdByUserId: user.userId,
|
|
31
|
+
name,
|
|
32
|
+
ttlSeconds: ttl_seconds,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
reply.code(201);
|
|
36
|
+
return {
|
|
37
|
+
...toProvisionerTokenDto(token),
|
|
38
|
+
raw_token: rawToken,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {requireProvisionerContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {provisionerIdentityResponseSchema} from '@shipfox/api-runners-dto';
|
|
3
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
4
|
+
|
|
5
|
+
export const getProvisionerMeRoute = defineRoute({
|
|
6
|
+
method: 'GET',
|
|
7
|
+
path: '/me',
|
|
8
|
+
description: 'Return the authenticated provisioner token identity',
|
|
9
|
+
schema: {
|
|
10
|
+
response: {
|
|
11
|
+
200: provisionerIdentityResponseSchema,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
handler: (request) => {
|
|
15
|
+
const context = requireProvisionerContext(request);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
id: context.provisionerTokenId,
|
|
19
|
+
workspace_id: context.workspaceId,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLeaseTokenAuthMethod,
|
|
3
|
+
createRunnerSessionAuthMethod,
|
|
4
|
+
issueJobLeaseToken,
|
|
5
|
+
jobLeaseParamsFrom,
|
|
6
|
+
verifyJobLeaseToken,
|
|
7
|
+
} from '@shipfox/api-auth';
|
|
8
|
+
import {AUTH_PROVISIONER_TOKEN, AUTH_USER} from '@shipfox/api-auth-context';
|
|
9
|
+
import type {RunnerToolCapabilitiesDto} from '@shipfox/api-runners-dto';
|
|
10
|
+
import type {AuthMethod} from '@shipfox/node-fastify';
|
|
11
|
+
import {closeApp, createApp} from '@shipfox/node-fastify';
|
|
12
|
+
import {eq} from 'drizzle-orm';
|
|
13
|
+
import type {FastifyInstance} from 'fastify';
|
|
14
|
+
import {claimJobExecution} from '#core/job-executions.js';
|
|
15
|
+
import {db} from '#db/db.js';
|
|
16
|
+
import {requestJobExecutionCancellation} from '#db/job-executions.js';
|
|
17
|
+
import {runnerSessions} from '#db/schema/runner-sessions.js';
|
|
18
|
+
import {runningJobExecutions} from '#db/schema/running-job-executions.js';
|
|
19
|
+
import {createRunnerRegistrationTokenAuthMethod} from '#presentation/auth/index.js';
|
|
20
|
+
import {pendingJobFactory, runnerSessionFactory} from '#test/index.js';
|
|
21
|
+
import {runnerRoutes} from './index.js';
|
|
22
|
+
|
|
23
|
+
const fakeUserAuth: AuthMethod = {
|
|
24
|
+
name: AUTH_USER,
|
|
25
|
+
authenticate: () => Promise.resolve(),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const fakeProvisionerAuth: AuthMethod = {
|
|
29
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
30
|
+
authenticate: () => Promise.resolve(),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const fullCapabilities: RunnerToolCapabilitiesDto = {
|
|
34
|
+
harnesses: {
|
|
35
|
+
pi: {tools: ['read', 'bash', 'web_search']},
|
|
36
|
+
claude: {tools: ['Read', 'Bash', 'WebSearch']},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const partialCapabilities: RunnerToolCapabilitiesDto = {
|
|
41
|
+
harnesses: {
|
|
42
|
+
pi: {tools: ['read']},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
describe('POST /runners/jobs/:jobId/heartbeat', () => {
|
|
47
|
+
let app: FastifyInstance;
|
|
48
|
+
let workspaceId: string;
|
|
49
|
+
let runnerSessionId: string;
|
|
50
|
+
|
|
51
|
+
beforeAll(async () => {
|
|
52
|
+
app = await createApp({
|
|
53
|
+
auth: [
|
|
54
|
+
fakeUserAuth,
|
|
55
|
+
createRunnerRegistrationTokenAuthMethod(),
|
|
56
|
+
createRunnerSessionAuthMethod(),
|
|
57
|
+
createLeaseTokenAuthMethod(),
|
|
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(async () => {
|
|
71
|
+
workspaceId = crypto.randomUUID();
|
|
72
|
+
const session = await runnerSessionFactory.create({workspaceId});
|
|
73
|
+
runnerSessionId = session.id;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
async function claimAvailableJob(): Promise<{
|
|
77
|
+
jobId: string;
|
|
78
|
+
jobExecutionId: string;
|
|
79
|
+
workflowRunId: string;
|
|
80
|
+
workflowRunAttemptId: string;
|
|
81
|
+
leaseToken: string;
|
|
82
|
+
}> {
|
|
83
|
+
const pending = await pendingJobFactory.create({workspaceId});
|
|
84
|
+
const claimed = await claimJobExecution({
|
|
85
|
+
workspaceId,
|
|
86
|
+
runnerSessionId,
|
|
87
|
+
sessionLabels: ['linux', 'x64'],
|
|
88
|
+
maxClaims: null,
|
|
89
|
+
});
|
|
90
|
+
expect(claimed).not.toBeNull();
|
|
91
|
+
return {
|
|
92
|
+
jobId: pending.jobId,
|
|
93
|
+
jobExecutionId: claimed?.jobExecutionId as string,
|
|
94
|
+
workflowRunId: pending.workflowRunId,
|
|
95
|
+
workflowRunAttemptId: pending.workflowRunAttemptId,
|
|
96
|
+
leaseToken: claimed?.leaseToken as string,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
it('returns 401 without authorization', async () => {
|
|
101
|
+
const res = await app.inject({
|
|
102
|
+
method: 'POST',
|
|
103
|
+
url: `/runners/jobs/${crypto.randomUUID()}/heartbeat`,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(res.statusCode).toBe(401);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('returns 200 + cancel:false on a fresh row', async () => {
|
|
110
|
+
const {jobId, jobExecutionId, workflowRunId, workflowRunAttemptId, leaseToken} =
|
|
111
|
+
await claimAvailableJob();
|
|
112
|
+
|
|
113
|
+
const res = await app.inject({
|
|
114
|
+
method: 'POST',
|
|
115
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
116
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(res.statusCode).toBe(200);
|
|
120
|
+
const body = res.json<{cancel: boolean; lease_token: string}>();
|
|
121
|
+
expect(body).toEqual({cancel: false, lease_token: expect.any(String)});
|
|
122
|
+
const refreshedLease = await verifyJobLeaseToken(body.lease_token);
|
|
123
|
+
expect(refreshedLease).toMatchObject({
|
|
124
|
+
jobId,
|
|
125
|
+
jobExecutionId,
|
|
126
|
+
workflowRunId,
|
|
127
|
+
workflowRunAttemptId,
|
|
128
|
+
runnerSessionId,
|
|
129
|
+
});
|
|
130
|
+
expect(refreshedLease?.currentStepId).toBeUndefined();
|
|
131
|
+
expect(refreshedLease?.currentStepAttempt).toBeUndefined();
|
|
132
|
+
const [running] = await db()
|
|
133
|
+
.select()
|
|
134
|
+
.from(runningJobExecutions)
|
|
135
|
+
.where(eq(runningJobExecutions.jobExecutionId, jobExecutionId));
|
|
136
|
+
expect(running?.firstHeartbeatAt).toBeInstanceOf(Date);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('refreshes job heartbeat and runner capability report', async () => {
|
|
140
|
+
const {jobId, jobExecutionId, leaseToken} = await claimAvailableJob();
|
|
141
|
+
|
|
142
|
+
const res = await app.inject({
|
|
143
|
+
method: 'POST',
|
|
144
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
145
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
146
|
+
payload: {capabilities: fullCapabilities},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(res.statusCode).toBe(200);
|
|
150
|
+
const [running] = await db()
|
|
151
|
+
.select()
|
|
152
|
+
.from(runningJobExecutions)
|
|
153
|
+
.where(eq(runningJobExecutions.jobExecutionId, jobExecutionId));
|
|
154
|
+
const [session] = await db()
|
|
155
|
+
.select()
|
|
156
|
+
.from(runnerSessions)
|
|
157
|
+
.where(eq(runnerSessions.id, runnerSessionId));
|
|
158
|
+
expect(running?.firstHeartbeatAt).toBeInstanceOf(Date);
|
|
159
|
+
expect(session?.toolCapabilities).toEqual(fullCapabilities);
|
|
160
|
+
expect(session?.toolCapabilitiesReportedAt).toBeInstanceOf(Date);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('clears the stored capability report when heartbeat omits capabilities', async () => {
|
|
164
|
+
const {jobId, leaseToken} = await claimAvailableJob();
|
|
165
|
+
await db()
|
|
166
|
+
.update(runnerSessions)
|
|
167
|
+
.set({
|
|
168
|
+
toolCapabilities: partialCapabilities,
|
|
169
|
+
toolCapabilitiesReportedAt: new Date('2026-01-01T00:00:00.000Z'),
|
|
170
|
+
})
|
|
171
|
+
.where(eq(runnerSessions.id, runnerSessionId));
|
|
172
|
+
|
|
173
|
+
const res = await app.inject({
|
|
174
|
+
method: 'POST',
|
|
175
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
176
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(res.statusCode).toBe(200);
|
|
180
|
+
const [session] = await db()
|
|
181
|
+
.select()
|
|
182
|
+
.from(runnerSessions)
|
|
183
|
+
.where(eq(runnerSessions.id, runnerSessionId));
|
|
184
|
+
expect(session?.toolCapabilities).toBeNull();
|
|
185
|
+
expect(session?.toolCapabilitiesReportedAt).toBeNull();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('rejects malformed capability reports without liveness or capability side effects', async () => {
|
|
189
|
+
const {jobId, jobExecutionId, leaseToken} = await claimAvailableJob();
|
|
190
|
+
await db()
|
|
191
|
+
.update(runnerSessions)
|
|
192
|
+
.set({
|
|
193
|
+
toolCapabilities: partialCapabilities,
|
|
194
|
+
toolCapabilitiesReportedAt: new Date('2026-01-01T00:00:00.000Z'),
|
|
195
|
+
})
|
|
196
|
+
.where(eq(runnerSessions.id, runnerSessionId));
|
|
197
|
+
const [beforeRunning] = await db()
|
|
198
|
+
.select()
|
|
199
|
+
.from(runningJobExecutions)
|
|
200
|
+
.where(eq(runningJobExecutions.jobExecutionId, jobExecutionId));
|
|
201
|
+
|
|
202
|
+
const res = await app.inject({
|
|
203
|
+
method: 'POST',
|
|
204
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
205
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
206
|
+
payload: {capabilities: {harnesses: {pi: {tools: ['read', 'read']}}}},
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(res.statusCode).toBe(400);
|
|
210
|
+
const [afterRunning] = await db()
|
|
211
|
+
.select()
|
|
212
|
+
.from(runningJobExecutions)
|
|
213
|
+
.where(eq(runningJobExecutions.jobExecutionId, jobExecutionId));
|
|
214
|
+
const [session] = await db()
|
|
215
|
+
.select()
|
|
216
|
+
.from(runnerSessions)
|
|
217
|
+
.where(eq(runnerSessions.id, runnerSessionId));
|
|
218
|
+
expect(afterRunning?.firstHeartbeatAt).toEqual(beforeRunning?.firstHeartbeatAt);
|
|
219
|
+
expect(afterRunning?.lastHeartbeatAt).toEqual(beforeRunning?.lastHeartbeatAt);
|
|
220
|
+
expect(session?.toolCapabilities).toEqual(partialCapabilities);
|
|
221
|
+
expect(session?.toolCapabilitiesReportedAt).toEqual(new Date('2026-01-01T00:00:00.000Z'));
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('returns 200 + cancel:true after requestJobExecutionCancellation', async () => {
|
|
225
|
+
const {jobId, jobExecutionId, workflowRunId, workflowRunAttemptId, leaseToken} =
|
|
226
|
+
await claimAvailableJob();
|
|
227
|
+
await requestJobExecutionCancellation({jobExecutionId});
|
|
228
|
+
|
|
229
|
+
const res = await app.inject({
|
|
230
|
+
method: 'POST',
|
|
231
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
232
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
expect(res.statusCode).toBe(200);
|
|
236
|
+
const body = res.json<{cancel: boolean; lease_token: string}>();
|
|
237
|
+
expect(body).toEqual({cancel: true, lease_token: expect.any(String)});
|
|
238
|
+
const refreshedLease = await verifyJobLeaseToken(body.lease_token);
|
|
239
|
+
expect(refreshedLease).toMatchObject({
|
|
240
|
+
jobId,
|
|
241
|
+
jobExecutionId,
|
|
242
|
+
workflowRunId,
|
|
243
|
+
workflowRunAttemptId,
|
|
244
|
+
runnerSessionId,
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('preserves current step scope when renewing a step-scoped lease', async () => {
|
|
249
|
+
const {jobId, leaseToken} = await claimAvailableJob();
|
|
250
|
+
const lease = await verifyJobLeaseToken(leaseToken);
|
|
251
|
+
if (!lease) throw new Error('Expected valid lease token');
|
|
252
|
+
const stepScope = {currentStepId: crypto.randomUUID(), currentStepAttempt: 3};
|
|
253
|
+
const stepScopedLeaseToken = await issueJobLeaseToken(jobLeaseParamsFrom(lease, stepScope));
|
|
254
|
+
|
|
255
|
+
const res = await app.inject({
|
|
256
|
+
method: 'POST',
|
|
257
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
258
|
+
headers: {authorization: `Bearer ${stepScopedLeaseToken}`},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(res.statusCode).toBe(200);
|
|
262
|
+
const body = res.json<{cancel: boolean; lease_token: string}>();
|
|
263
|
+
const refreshedLease = await verifyJobLeaseToken(body.lease_token);
|
|
264
|
+
expect(refreshedLease).toMatchObject(stepScope);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('returns 404 when the jobId is unknown', async () => {
|
|
268
|
+
const jobId = crypto.randomUUID();
|
|
269
|
+
const jobExecutionId = crypto.randomUUID();
|
|
270
|
+
const leaseToken = await issueJobLeaseToken({
|
|
271
|
+
jobId,
|
|
272
|
+
jobExecutionId,
|
|
273
|
+
workflowRunId: crypto.randomUUID(),
|
|
274
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
275
|
+
projectId: crypto.randomUUID(),
|
|
276
|
+
workspaceId,
|
|
277
|
+
runnerSessionId,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const res = await app.inject({
|
|
281
|
+
method: 'POST',
|
|
282
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
283
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
expect(res.statusCode).toBe(404);
|
|
287
|
+
expect(res.json().code).toBe('running-job-execution-not-found');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('returns 404 when the job belongs to a different session', async () => {
|
|
291
|
+
const {jobId, jobExecutionId} = await claimAvailableJob();
|
|
292
|
+
const otherSession = await runnerSessionFactory.create({workspaceId});
|
|
293
|
+
const leaseToken = await issueJobLeaseToken({
|
|
294
|
+
jobId,
|
|
295
|
+
jobExecutionId,
|
|
296
|
+
workflowRunId: crypto.randomUUID(),
|
|
297
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
298
|
+
projectId: crypto.randomUUID(),
|
|
299
|
+
workspaceId,
|
|
300
|
+
runnerSessionId: otherSession.id,
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const res = await app.inject({
|
|
304
|
+
method: 'POST',
|
|
305
|
+
url: `/runners/jobs/${jobId}/heartbeat`,
|
|
306
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
expect(res.statusCode).toBe(404);
|
|
310
|
+
expect(res.json().code).toBe('running-job-execution-not-found');
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('returns 404 when the path job id does not match the lease token job id', async () => {
|
|
314
|
+
const {leaseToken} = await claimAvailableJob();
|
|
315
|
+
|
|
316
|
+
const res = await app.inject({
|
|
317
|
+
method: 'POST',
|
|
318
|
+
url: `/runners/jobs/${crypto.randomUUID()}/heartbeat`,
|
|
319
|
+
headers: {authorization: `Bearer ${leaseToken}`},
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
expect(res.statusCode).toBe(404);
|
|
323
|
+
expect(res.json().code).toBe('lease-job-mismatch');
|
|
324
|
+
});
|
|
325
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {issueJobLeaseToken, jobLeaseParamsFrom} from '@shipfox/api-auth';
|
|
2
|
+
import {requireLeasedJobContext} from '@shipfox/api-auth-context';
|
|
3
|
+
import {heartbeatBodySchema, heartbeatResponseSchema} from '@shipfox/api-runners-dto';
|
|
4
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
5
|
+
import {z} from 'zod';
|
|
6
|
+
import {RunningJobExecutionNotFoundError} from '#core/errors.js';
|
|
7
|
+
import {recordHeartbeat} from '#db/job-executions.js';
|
|
8
|
+
|
|
9
|
+
export const heartbeatRoute = defineRoute({
|
|
10
|
+
method: 'POST',
|
|
11
|
+
path: '/:jobId/heartbeat',
|
|
12
|
+
description:
|
|
13
|
+
'Keeps a running job execution alive while the runner is still working on it. Returns whether the server has asked the runner to cancel.',
|
|
14
|
+
schema: {
|
|
15
|
+
params: z.object({jobId: z.string().uuid()}),
|
|
16
|
+
body: heartbeatBodySchema.nullish(),
|
|
17
|
+
response: {
|
|
18
|
+
200: heartbeatResponseSchema,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
errorHandler: (error) => {
|
|
22
|
+
if (error instanceof RunningJobExecutionNotFoundError) {
|
|
23
|
+
throw new ClientError(error.message, 'running-job-execution-not-found', {status: 404});
|
|
24
|
+
}
|
|
25
|
+
throw error;
|
|
26
|
+
},
|
|
27
|
+
handler: async (request) => {
|
|
28
|
+
const {jobId} = request.params;
|
|
29
|
+
const lease = requireLeasedJobContext(request);
|
|
30
|
+
if (lease.jobId !== jobId) {
|
|
31
|
+
throw new ClientError('Lease token does not match job', 'lease-job-mismatch', {
|
|
32
|
+
status: 404,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const heartbeatResult = await recordHeartbeat({
|
|
37
|
+
jobExecutionId: lease.jobExecutionId,
|
|
38
|
+
runnerSessionId: lease.runnerSessionId,
|
|
39
|
+
toolCapabilities: request.body?.capabilities ?? null,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
heartbeatResult.previousToolCapabilities &&
|
|
44
|
+
!sameToolCapabilities(
|
|
45
|
+
heartbeatResult.previousToolCapabilities,
|
|
46
|
+
heartbeatResult.currentToolCapabilities,
|
|
47
|
+
)
|
|
48
|
+
) {
|
|
49
|
+
request.log.info(
|
|
50
|
+
{
|
|
51
|
+
runnerSessionId: lease.runnerSessionId,
|
|
52
|
+
jobExecutionId: lease.jobExecutionId,
|
|
53
|
+
previousHarnesses: Object.keys(heartbeatResult.previousToolCapabilities.harnesses),
|
|
54
|
+
currentHarnesses: heartbeatResult.currentToolCapabilities
|
|
55
|
+
? Object.keys(heartbeatResult.currentToolCapabilities.harnesses)
|
|
56
|
+
: [],
|
|
57
|
+
},
|
|
58
|
+
'Runner heartbeat changed advertised tool capabilities',
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const leaseToken = await issueJobLeaseToken(
|
|
63
|
+
jobLeaseParamsFrom(
|
|
64
|
+
heartbeatResult.runningJobExecution,
|
|
65
|
+
lease.currentStepId && lease.currentStepAttempt !== undefined
|
|
66
|
+
? {
|
|
67
|
+
currentStepId: lease.currentStepId,
|
|
68
|
+
currentStepAttempt: lease.currentStepAttempt,
|
|
69
|
+
}
|
|
70
|
+
: undefined,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return {cancel: heartbeatResult.cancellationRequested, lease_token: leaseToken};
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function sameToolCapabilities(left: unknown, right: unknown): boolean {
|
|
79
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
80
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUTH_LEASED_JOB,
|
|
3
|
+
AUTH_PROVISIONER_TOKEN,
|
|
4
|
+
AUTH_RUNNER_REGISTRATION_TOKEN,
|
|
5
|
+
AUTH_RUNNER_SESSION,
|
|
6
|
+
AUTH_USER,
|
|
7
|
+
} from '@shipfox/api-auth-context';
|
|
8
|
+
import type {RouteGroup} from '@shipfox/node-fastify';
|
|
9
|
+
import {createManualRegistrationTokenRoute} from './create-manual-registration-token.js';
|
|
10
|
+
import {createProvisionerTokenRoute} from './create-provisioner-token.js';
|
|
11
|
+
import {getProvisionerMeRoute} from './get-provisioner-me.js';
|
|
12
|
+
import {heartbeatRoute} from './heartbeat.js';
|
|
13
|
+
import {listActiveProvisionersRoute} from './list-active-provisioners.js';
|
|
14
|
+
import {listActiveRunnersRoute} from './list-active-runners.js';
|
|
15
|
+
import {listManualRegistrationTokensRoute} from './list-manual-registration-tokens.js';
|
|
16
|
+
import {listProvisionerTokensRoute} from './list-provisioner-tokens.js';
|
|
17
|
+
import {mintRegistrationTokensRoute} from './mint-registration-tokens.js';
|
|
18
|
+
import {pollDemandRoute} from './poll-demand.js';
|
|
19
|
+
import {reconcileProvisionedRunnersRoute} from './reconcile-provisioned-runners.js';
|
|
20
|
+
import {registerRoute} from './register.js';
|
|
21
|
+
import {reportProvisionedRunnersRoute} from './report-provisioned-runners.js';
|
|
22
|
+
import {requestJobRoute} from './request-job.js';
|
|
23
|
+
import {revokeManualRegistrationTokenRoute} from './revoke-manual-registration-token.js';
|
|
24
|
+
import {revokeProvisionerTokenRoute} from './revoke-provisioner-token.js';
|
|
25
|
+
|
|
26
|
+
const runnerOnlyRoutes: RouteGroup[] = [
|
|
27
|
+
{
|
|
28
|
+
prefix: '/workspaces/:workspaceId/runners/manual-registration-tokens',
|
|
29
|
+
auth: AUTH_USER,
|
|
30
|
+
routes: [
|
|
31
|
+
listManualRegistrationTokensRoute,
|
|
32
|
+
createManualRegistrationTokenRoute,
|
|
33
|
+
revokeManualRegistrationTokenRoute,
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
prefix: '/workspaces/:workspaceId/runners/active',
|
|
38
|
+
auth: AUTH_USER,
|
|
39
|
+
routes: [listActiveRunnersRoute],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
prefix: '/runners',
|
|
43
|
+
auth: AUTH_RUNNER_REGISTRATION_TOKEN,
|
|
44
|
+
routes: [registerRoute],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
prefix: '/runners/jobs',
|
|
48
|
+
auth: AUTH_RUNNER_SESSION,
|
|
49
|
+
routes: [requestJobRoute],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
prefix: '/runners/jobs',
|
|
53
|
+
auth: AUTH_LEASED_JOB,
|
|
54
|
+
routes: [heartbeatRoute],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
prefix: '/provisioners',
|
|
58
|
+
auth: AUTH_PROVISIONER_TOKEN,
|
|
59
|
+
routes: [
|
|
60
|
+
pollDemandRoute,
|
|
61
|
+
mintRegistrationTokensRoute,
|
|
62
|
+
reportProvisionedRunnersRoute,
|
|
63
|
+
reconcileProvisionedRunnersRoute,
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
export const provisionerRoutes: RouteGroup[] = [
|
|
69
|
+
{
|
|
70
|
+
prefix: '/workspaces/:workspaceId/provisioners/tokens',
|
|
71
|
+
auth: AUTH_USER,
|
|
72
|
+
routes: [listProvisionerTokensRoute, createProvisionerTokenRoute, revokeProvisionerTokenRoute],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
prefix: '/workspaces/:workspaceId/provisioners/active',
|
|
76
|
+
auth: AUTH_USER,
|
|
77
|
+
routes: [listActiveProvisionersRoute],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
prefix: '/provisioners',
|
|
81
|
+
auth: AUTH_PROVISIONER_TOKEN,
|
|
82
|
+
routes: [getProvisionerMeRoute],
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
export const runnerRoutes: RouteGroup[] = [...runnerOnlyRoutes, ...provisionerRoutes];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {requireWorkspaceAccess} from '@shipfox/api-auth-context';
|
|
2
|
+
import {listActiveProvisionersResponseSchema} from '@shipfox/api-runners-dto';
|
|
3
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
4
|
+
import {z} from 'zod';
|
|
5
|
+
import {listActiveProvisioners} from '#core/index.js';
|
|
6
|
+
import {toActiveProvisionerDto} from '#presentation/dto/index.js';
|
|
7
|
+
|
|
8
|
+
export const listActiveProvisionersRoute = defineRoute({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/',
|
|
11
|
+
description: 'List active provisioners for a workspace',
|
|
12
|
+
schema: {
|
|
13
|
+
params: z.object({workspaceId: z.string().uuid()}),
|
|
14
|
+
response: {
|
|
15
|
+
200: listActiveProvisionersResponseSchema,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
handler: async (request) => {
|
|
19
|
+
const {workspaceId} = request.params;
|
|
20
|
+
requireWorkspaceAccess({request, workspaceId});
|
|
21
|
+
|
|
22
|
+
const provisioners = await listActiveProvisioners(workspaceId);
|
|
23
|
+
return {provisioners: provisioners.map(toActiveProvisionerDto)};
|
|
24
|
+
},
|
|
25
|
+
});
|