@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,209 @@
|
|
|
1
|
+
import {verifyRunnerSessionToken} from '@shipfox/api-auth';
|
|
2
|
+
import {and, eq} from 'drizzle-orm';
|
|
3
|
+
import {db} from '#db/db.js';
|
|
4
|
+
import {ephemeralRegistrationTokens} from '#db/schema/ephemeral-registration-tokens.js';
|
|
5
|
+
import {provisionedRunners} from '#db/schema/provisioned-runners.js';
|
|
6
|
+
import {runnerSessions} from '#db/schema/runner-sessions.js';
|
|
7
|
+
import {
|
|
8
|
+
ephemeralRegistrationTokenFactory,
|
|
9
|
+
manualRegistrationTokenFactory,
|
|
10
|
+
provisionedRunnerFactory,
|
|
11
|
+
} from '#test/index.js';
|
|
12
|
+
import {
|
|
13
|
+
EmptyRunnerLabelsError,
|
|
14
|
+
RegistrationTokenConsumedError,
|
|
15
|
+
RegistrationTokenWorkspaceMismatchError,
|
|
16
|
+
} from './errors.js';
|
|
17
|
+
import {registerRunnerSession} from './runner-sessions.js';
|
|
18
|
+
|
|
19
|
+
describe('registerRunnerSession', () => {
|
|
20
|
+
let workspaceId: string;
|
|
21
|
+
let registrationTokenId: string;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
workspaceId = crypto.randomUUID();
|
|
25
|
+
const token = await manualRegistrationTokenFactory.create({workspaceId});
|
|
26
|
+
registrationTokenId = token.id;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('canonicalizes labels, stores them, and embeds them in the session token', async () => {
|
|
30
|
+
const result = await registerRunnerSession({
|
|
31
|
+
credential: {kind: 'manual', registrationTokenId, workspaceId},
|
|
32
|
+
labels: [' Linux ', 'x64', 'linux'],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(result.mode).toBe('manual');
|
|
36
|
+
expect(result.maxClaims).toBeNull();
|
|
37
|
+
expect(result.session.labels).toEqual(['linux', 'x64']);
|
|
38
|
+
expect(result.session.registrationTokenKind).toBe('manual');
|
|
39
|
+
expect(result.session.provisionerId).toBeNull();
|
|
40
|
+
expect(result.session.provisionedRunnerId).toBeNull();
|
|
41
|
+
expect(result.session.maxClaims).toBeNull();
|
|
42
|
+
expect(result.session.claimsUsed).toBe(0);
|
|
43
|
+
|
|
44
|
+
const rows = await db()
|
|
45
|
+
.select()
|
|
46
|
+
.from(runnerSessions)
|
|
47
|
+
.where(eq(runnerSessions.id, result.session.id));
|
|
48
|
+
expect(rows[0]?.labels).toEqual(['linux', 'x64']);
|
|
49
|
+
|
|
50
|
+
const claims = await verifyRunnerSessionToken(result.sessionToken);
|
|
51
|
+
expect(claims?.labels).toEqual(['linux', 'x64']);
|
|
52
|
+
expect(claims?.maxClaims).toBeNull();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('throws EmptyRunnerLabelsError when labels canonicalize to empty', async () => {
|
|
56
|
+
await expect(
|
|
57
|
+
registerRunnerSession({
|
|
58
|
+
credential: {kind: 'manual', registrationTokenId, workspaceId},
|
|
59
|
+
labels: [' ', '\t'],
|
|
60
|
+
}),
|
|
61
|
+
).rejects.toBeInstanceOf(EmptyRunnerLabelsError);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('consumes an ephemeral token and creates a one-claim session', async () => {
|
|
65
|
+
const token = await ephemeralRegistrationTokenFactory.create({workspaceId});
|
|
66
|
+
|
|
67
|
+
const result = await registerRunnerSession({
|
|
68
|
+
credential: {
|
|
69
|
+
kind: 'ephemeral',
|
|
70
|
+
ephemeralTokenId: token.id,
|
|
71
|
+
workspaceId,
|
|
72
|
+
provisionerId: token.provisionerId,
|
|
73
|
+
reservationId: token.reservationId,
|
|
74
|
+
provisionedRunnerId: token.provisionedRunnerId,
|
|
75
|
+
},
|
|
76
|
+
labels: [' Linux ', 'x64'],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(result.mode).toBe('ephemeral');
|
|
80
|
+
expect(result.maxClaims).toBe(1);
|
|
81
|
+
expect(result.session.registrationTokenKind).toBe('ephemeral');
|
|
82
|
+
expect(result.session.provisionerId).toBe(token.provisionerId);
|
|
83
|
+
expect(result.session.provisionedRunnerId).toBe(token.provisionedRunnerId);
|
|
84
|
+
expect(result.session.maxClaims).toBe(1);
|
|
85
|
+
expect(result.session.claimsUsed).toBe(0);
|
|
86
|
+
|
|
87
|
+
const [consumed] = await db()
|
|
88
|
+
.select()
|
|
89
|
+
.from(ephemeralRegistrationTokens)
|
|
90
|
+
.where(eq(ephemeralRegistrationTokens.id, token.id));
|
|
91
|
+
expect(consumed?.consumedAt).toBeInstanceOf(Date);
|
|
92
|
+
expect(consumed?.consumedSessionId).toBe(result.session.id);
|
|
93
|
+
|
|
94
|
+
const [session] = await db()
|
|
95
|
+
.select()
|
|
96
|
+
.from(runnerSessions)
|
|
97
|
+
.where(eq(runnerSessions.id, result.session.id));
|
|
98
|
+
expect(session?.provisionerId).toBe(token.provisionerId);
|
|
99
|
+
expect(session?.provisionedRunnerId).toBe(token.provisionedRunnerId);
|
|
100
|
+
|
|
101
|
+
const claims = await verifyRunnerSessionToken(result.sessionToken);
|
|
102
|
+
expect(claims?.maxClaims).toBe(1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('links an existing provisioned runner row when consuming an ephemeral token', async () => {
|
|
106
|
+
const token = await ephemeralRegistrationTokenFactory.create({workspaceId});
|
|
107
|
+
await provisionedRunnerFactory.create({
|
|
108
|
+
workspaceId,
|
|
109
|
+
provisionerId: token.provisionerId,
|
|
110
|
+
provisionedRunnerId: token.provisionedRunnerId,
|
|
111
|
+
runnerSessionId: null,
|
|
112
|
+
state: 'starting',
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const result = await registerRunnerSession({
|
|
116
|
+
credential: {
|
|
117
|
+
kind: 'ephemeral',
|
|
118
|
+
ephemeralTokenId: token.id,
|
|
119
|
+
workspaceId,
|
|
120
|
+
provisionerId: token.provisionerId,
|
|
121
|
+
reservationId: token.reservationId,
|
|
122
|
+
provisionedRunnerId: token.provisionedRunnerId,
|
|
123
|
+
},
|
|
124
|
+
labels: ['linux'],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const [provisionedRunner] = await db()
|
|
128
|
+
.select()
|
|
129
|
+
.from(provisionedRunners)
|
|
130
|
+
.where(
|
|
131
|
+
and(
|
|
132
|
+
eq(provisionedRunners.workspaceId, workspaceId),
|
|
133
|
+
eq(provisionedRunners.provisionerId, token.provisionerId),
|
|
134
|
+
eq(provisionedRunners.provisionedRunnerId, token.provisionedRunnerId),
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
expect(provisionedRunner?.runnerSessionId).toBe(result.session.id);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('rejects a second consume of the same ephemeral token', async () => {
|
|
141
|
+
const token = await ephemeralRegistrationTokenFactory.create({workspaceId});
|
|
142
|
+
const credential = {
|
|
143
|
+
kind: 'ephemeral' as const,
|
|
144
|
+
ephemeralTokenId: token.id,
|
|
145
|
+
workspaceId,
|
|
146
|
+
provisionerId: token.provisionerId,
|
|
147
|
+
reservationId: token.reservationId,
|
|
148
|
+
provisionedRunnerId: token.provisionedRunnerId,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
await registerRunnerSession({credential, labels: ['linux']});
|
|
152
|
+
|
|
153
|
+
await expect(registerRunnerSession({credential, labels: ['linux']})).rejects.toBeInstanceOf(
|
|
154
|
+
RegistrationTokenConsumedError,
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('rejects consuming an ephemeral token for a different workspace', async () => {
|
|
159
|
+
const token = await ephemeralRegistrationTokenFactory.create({workspaceId});
|
|
160
|
+
|
|
161
|
+
await expect(
|
|
162
|
+
registerRunnerSession({
|
|
163
|
+
credential: {
|
|
164
|
+
kind: 'ephemeral',
|
|
165
|
+
ephemeralTokenId: token.id,
|
|
166
|
+
workspaceId: crypto.randomUUID(),
|
|
167
|
+
provisionerId: token.provisionerId,
|
|
168
|
+
reservationId: token.reservationId,
|
|
169
|
+
provisionedRunnerId: token.provisionedRunnerId,
|
|
170
|
+
},
|
|
171
|
+
labels: ['linux'],
|
|
172
|
+
}),
|
|
173
|
+
).rejects.toBeInstanceOf(RegistrationTokenWorkspaceMismatchError);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('rejects an ephemeral session row without a positive max claim cap', async () => {
|
|
177
|
+
await expect(
|
|
178
|
+
db()
|
|
179
|
+
.insert(runnerSessions)
|
|
180
|
+
.values({
|
|
181
|
+
workspaceId,
|
|
182
|
+
scope: 'workspace',
|
|
183
|
+
registrationTokenId: crypto.randomUUID(),
|
|
184
|
+
registrationTokenKind: 'ephemeral',
|
|
185
|
+
provisionerId: crypto.randomUUID(),
|
|
186
|
+
provisionedRunnerId: `provisioned-runner-${crypto.randomUUID()}`,
|
|
187
|
+
labels: ['linux'],
|
|
188
|
+
maxClaims: null,
|
|
189
|
+
claimsUsed: 0,
|
|
190
|
+
}),
|
|
191
|
+
).rejects.toThrow();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('rejects an ephemeral session row without a provisioned-runner link', async () => {
|
|
195
|
+
await expect(
|
|
196
|
+
db()
|
|
197
|
+
.insert(runnerSessions)
|
|
198
|
+
.values({
|
|
199
|
+
workspaceId,
|
|
200
|
+
scope: 'workspace',
|
|
201
|
+
registrationTokenId: crypto.randomUUID(),
|
|
202
|
+
registrationTokenKind: 'ephemeral',
|
|
203
|
+
labels: ['linux'],
|
|
204
|
+
maxClaims: 1,
|
|
205
|
+
claimsUsed: 0,
|
|
206
|
+
}),
|
|
207
|
+
).rejects.toThrow();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {issueRunnerSessionToken} from '@shipfox/api-auth';
|
|
2
|
+
import type {RunnerToolCapabilitiesDto} from '@shipfox/api-runners-dto';
|
|
3
|
+
import {canonicalizeLabels} from '@shipfox/runner-labels';
|
|
4
|
+
import {createRunnerSessionConsumingEphemeralToken} from '#db/ephemeral-registration-tokens.js';
|
|
5
|
+
import {createRunnerSession} from '#db/runner-sessions.js';
|
|
6
|
+
import type {RunnerSession} from './entities/runner-session.js';
|
|
7
|
+
import {EmptyRunnerLabelsError} from './errors.js';
|
|
8
|
+
|
|
9
|
+
export interface RegisterRunnerSessionResult {
|
|
10
|
+
session: RunnerSession;
|
|
11
|
+
sessionToken: string;
|
|
12
|
+
mode: 'manual' | 'ephemeral';
|
|
13
|
+
maxClaims: number | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type RunnerRegistrationCredential =
|
|
17
|
+
| {
|
|
18
|
+
kind: 'manual';
|
|
19
|
+
registrationTokenId: string;
|
|
20
|
+
workspaceId: string;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
kind: 'ephemeral';
|
|
24
|
+
ephemeralTokenId: string;
|
|
25
|
+
workspaceId: string;
|
|
26
|
+
provisionerId: string;
|
|
27
|
+
reservationId: string | null;
|
|
28
|
+
provisionedRunnerId: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export async function registerRunnerSession(params: {
|
|
32
|
+
credential: RunnerRegistrationCredential;
|
|
33
|
+
labels: string[];
|
|
34
|
+
toolCapabilities?: RunnerToolCapabilitiesDto | null;
|
|
35
|
+
}): Promise<RegisterRunnerSessionResult> {
|
|
36
|
+
const labels = [...canonicalizeLabels(params.labels)];
|
|
37
|
+
if (labels.length === 0) throw new EmptyRunnerLabelsError();
|
|
38
|
+
|
|
39
|
+
const mode = params.credential.kind;
|
|
40
|
+
const maxClaims = params.credential.kind === 'ephemeral' ? 1 : null;
|
|
41
|
+
const session =
|
|
42
|
+
params.credential.kind === 'manual'
|
|
43
|
+
? await createRunnerSession({
|
|
44
|
+
workspaceId: params.credential.workspaceId,
|
|
45
|
+
scope: 'workspace',
|
|
46
|
+
registrationTokenId: params.credential.registrationTokenId,
|
|
47
|
+
labels,
|
|
48
|
+
toolCapabilities: params.toolCapabilities ?? null,
|
|
49
|
+
})
|
|
50
|
+
: await createRunnerSessionConsumingEphemeralToken({
|
|
51
|
+
ephemeralTokenId: params.credential.ephemeralTokenId,
|
|
52
|
+
workspaceId: params.credential.workspaceId,
|
|
53
|
+
labels,
|
|
54
|
+
toolCapabilities: params.toolCapabilities ?? null,
|
|
55
|
+
maxClaims: 1,
|
|
56
|
+
});
|
|
57
|
+
const sessionToken = await issueRunnerSessionToken({
|
|
58
|
+
runnerSessionId: session.id,
|
|
59
|
+
workspaceId: session.workspaceId,
|
|
60
|
+
scope: session.scope,
|
|
61
|
+
labels: session.labels,
|
|
62
|
+
maxClaims,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return {session, sessionToken, mode, maxClaims};
|
|
66
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type {RunnerToolCapabilitiesDto} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {eq, sql} from 'drizzle-orm';
|
|
3
|
+
import {db} from '#db/db.js';
|
|
4
|
+
import {runnerSessions} from '#db/schema/runner-sessions.js';
|
|
5
|
+
import {runnerSessionFactory} from '#test/index.js';
|
|
6
|
+
import {
|
|
7
|
+
effectiveRunnerToolCapabilities,
|
|
8
|
+
getEffectiveRunnerToolCapabilities,
|
|
9
|
+
unadvertisedRunnerTools,
|
|
10
|
+
} from './runner-tool-capabilities.js';
|
|
11
|
+
|
|
12
|
+
const capabilities: RunnerToolCapabilitiesDto = {
|
|
13
|
+
harnesses: {
|
|
14
|
+
pi: {tools: ['read', 'bash']},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe('effectiveRunnerToolCapabilities', () => {
|
|
19
|
+
it('returns an empty set when the report is missing', () => {
|
|
20
|
+
const effective = effectiveRunnerToolCapabilities({
|
|
21
|
+
toolCapabilities: null,
|
|
22
|
+
reportedAt: new Date('2026-01-01T00:00:00.000Z'),
|
|
23
|
+
staleAfterSeconds: 10,
|
|
24
|
+
now: new Date('2026-01-01T00:00:01.000Z'),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
expect(effective).toEqual({harnesses: {}});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('returns an empty set when the report timestamp is missing', () => {
|
|
31
|
+
const effective = effectiveRunnerToolCapabilities({
|
|
32
|
+
toolCapabilities: capabilities,
|
|
33
|
+
reportedAt: null,
|
|
34
|
+
staleAfterSeconds: 10,
|
|
35
|
+
now: new Date('2026-01-01T00:00:01.000Z'),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(effective).toEqual({harnesses: {}});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('returns an empty set when the report is stale', () => {
|
|
42
|
+
const effective = effectiveRunnerToolCapabilities({
|
|
43
|
+
toolCapabilities: capabilities,
|
|
44
|
+
reportedAt: new Date('2026-01-01T00:00:00.000Z'),
|
|
45
|
+
staleAfterSeconds: 10,
|
|
46
|
+
now: new Date('2026-01-01T00:00:11.000Z'),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(effective).toEqual({harnesses: {}});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('returns exact persisted tools when the report is fresh', () => {
|
|
53
|
+
const effective = effectiveRunnerToolCapabilities({
|
|
54
|
+
toolCapabilities: capabilities,
|
|
55
|
+
reportedAt: new Date('2026-01-01T00:00:00.000Z'),
|
|
56
|
+
staleAfterSeconds: 10,
|
|
57
|
+
now: new Date('2026-01-01T00:00:10.000Z'),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(effective).toBe(capabilities);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('unadvertisedRunnerTools', () => {
|
|
65
|
+
it('returns no tools when every requested tool is advertised', () => {
|
|
66
|
+
const missing = unadvertisedRunnerTools({
|
|
67
|
+
harness: 'pi',
|
|
68
|
+
requestedTools: ['read', 'bash'],
|
|
69
|
+
capabilities,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(missing).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('returns the missing subset in requested order', () => {
|
|
76
|
+
const missing = unadvertisedRunnerTools({
|
|
77
|
+
harness: 'pi',
|
|
78
|
+
requestedTools: ['read', 'web_search', 'bash', 'get_search_content'],
|
|
79
|
+
capabilities,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(missing).toEqual(['web_search', 'get_search_content']);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('returns every requested tool when the harness has no advertised tools', () => {
|
|
86
|
+
const missing = unadvertisedRunnerTools({
|
|
87
|
+
harness: 'claude',
|
|
88
|
+
requestedTools: ['read', 'bash'],
|
|
89
|
+
capabilities,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(missing).toEqual(['read', 'bash']);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('matches tool names exactly across harnesses', () => {
|
|
96
|
+
const missing = unadvertisedRunnerTools({
|
|
97
|
+
harness: 'claude',
|
|
98
|
+
requestedTools: ['read', 'Read'],
|
|
99
|
+
capabilities: {harnesses: {claude: {tools: ['read']}, pi: {tools: ['Read']}}},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(missing).toEqual(['Read']);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('getEffectiveRunnerToolCapabilities', () => {
|
|
107
|
+
it('returns fresh capabilities and reports the harness as known', async () => {
|
|
108
|
+
const runnerSession = await runnerSessionFactory.create({toolCapabilities: capabilities});
|
|
109
|
+
|
|
110
|
+
const result = await getEffectiveRunnerToolCapabilities({runnerSessionId: runnerSession.id});
|
|
111
|
+
|
|
112
|
+
expect(result.capabilities).toEqual(capabilities);
|
|
113
|
+
expect(result.reportFresh).toBe(true);
|
|
114
|
+
expect(result.harnessKnown('pi')).toBe(true);
|
|
115
|
+
expect(result.harnessKnown('claude')).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('treats missing capabilities as unknown', async () => {
|
|
119
|
+
const runnerSession = await runnerSessionFactory.create({toolCapabilities: null});
|
|
120
|
+
|
|
121
|
+
const result = await getEffectiveRunnerToolCapabilities({runnerSessionId: runnerSession.id});
|
|
122
|
+
|
|
123
|
+
expect(result.capabilities).toEqual({harnesses: {}});
|
|
124
|
+
expect(result.reportFresh).toBe(false);
|
|
125
|
+
expect(result.harnessKnown('pi')).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('treats stale capabilities as unknown', async () => {
|
|
129
|
+
const runnerSession = await runnerSessionFactory.create({toolCapabilities: capabilities});
|
|
130
|
+
await db()
|
|
131
|
+
.update(runnerSessions)
|
|
132
|
+
.set({toolCapabilitiesReportedAt: sql`now() - interval '1 hour'`})
|
|
133
|
+
.where(eq(runnerSessions.id, runnerSession.id));
|
|
134
|
+
|
|
135
|
+
const result = await getEffectiveRunnerToolCapabilities({runnerSessionId: runnerSession.id});
|
|
136
|
+
|
|
137
|
+
expect(result.capabilities).toEqual({harnesses: {}});
|
|
138
|
+
expect(result.reportFresh).toBe(false);
|
|
139
|
+
expect(result.harnessKnown('pi')).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type {RunnerToolCapabilitiesDto} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {config} from '#config.js';
|
|
3
|
+
import {getRunnerSessionById} from '#db/runner-sessions.js';
|
|
4
|
+
|
|
5
|
+
type RunnerToolHarness = keyof RunnerToolCapabilitiesDto['harnesses'];
|
|
6
|
+
|
|
7
|
+
export const EMPTY_RUNNER_TOOL_CAPABILITIES: RunnerToolCapabilitiesDto = {
|
|
8
|
+
harnesses: {},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function effectiveRunnerToolCapabilities(params: {
|
|
12
|
+
toolCapabilities: RunnerToolCapabilitiesDto | null;
|
|
13
|
+
reportedAt: Date | null;
|
|
14
|
+
staleAfterSeconds: number;
|
|
15
|
+
now?: Date;
|
|
16
|
+
}): RunnerToolCapabilitiesDto {
|
|
17
|
+
if (!params.toolCapabilities || !params.reportedAt) return EMPTY_RUNNER_TOOL_CAPABILITIES;
|
|
18
|
+
|
|
19
|
+
const now = params.now ?? new Date();
|
|
20
|
+
const ageMs = now.getTime() - params.reportedAt.getTime();
|
|
21
|
+
if (ageMs > params.staleAfterSeconds * 1000) return EMPTY_RUNNER_TOOL_CAPABILITIES;
|
|
22
|
+
|
|
23
|
+
return params.toolCapabilities;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function runnerToolCapabilityReportIsFresh(params: {
|
|
27
|
+
toolCapabilities: RunnerToolCapabilitiesDto | null | undefined;
|
|
28
|
+
reportedAt: Date | null | undefined;
|
|
29
|
+
staleAfterSeconds: number;
|
|
30
|
+
now?: Date;
|
|
31
|
+
}): boolean {
|
|
32
|
+
if (!params.toolCapabilities || !params.reportedAt) return false;
|
|
33
|
+
|
|
34
|
+
const now = params.now ?? new Date();
|
|
35
|
+
const ageMs = now.getTime() - params.reportedAt.getTime();
|
|
36
|
+
return ageMs <= params.staleAfterSeconds * 1000;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function unadvertisedRunnerTools(params: {
|
|
40
|
+
harness: RunnerToolHarness;
|
|
41
|
+
requestedTools: readonly string[];
|
|
42
|
+
capabilities: RunnerToolCapabilitiesDto;
|
|
43
|
+
}): string[] {
|
|
44
|
+
const advertised = new Set(params.capabilities.harnesses[params.harness]?.tools ?? []);
|
|
45
|
+
return params.requestedTools.filter((tool) => !advertised.has(tool));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface EffectiveRunnerToolCapabilitiesResult {
|
|
49
|
+
capabilities: RunnerToolCapabilitiesDto;
|
|
50
|
+
reportFresh: boolean;
|
|
51
|
+
harnessKnown(harness: RunnerToolHarness): boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function getEffectiveRunnerToolCapabilities(params: {
|
|
55
|
+
runnerSessionId: string;
|
|
56
|
+
}): Promise<EffectiveRunnerToolCapabilitiesResult> {
|
|
57
|
+
const runnerSession = await getRunnerSessionById(params.runnerSessionId);
|
|
58
|
+
const staleAfterSeconds = config.RUNNER_TOOL_CAPABILITIES_STALE_AFTER_SECONDS;
|
|
59
|
+
const capabilities = effectiveRunnerToolCapabilities({
|
|
60
|
+
toolCapabilities: runnerSession?.toolCapabilities ?? null,
|
|
61
|
+
reportedAt: runnerSession?.toolCapabilitiesReportedAt ?? null,
|
|
62
|
+
staleAfterSeconds,
|
|
63
|
+
});
|
|
64
|
+
const reportFresh = runnerToolCapabilityReportIsFresh({
|
|
65
|
+
toolCapabilities: runnerSession?.toolCapabilities,
|
|
66
|
+
reportedAt: runnerSession?.toolCapabilitiesReportedAt,
|
|
67
|
+
staleAfterSeconds,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
capabilities,
|
|
72
|
+
reportFresh,
|
|
73
|
+
harnessKnown: (harness) => capabilities.harnesses[harness] !== undefined,
|
|
74
|
+
};
|
|
75
|
+
}
|
package/src/db/db.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {drizzle, type NodePgDatabase} from '@shipfox/node-drizzle';
|
|
2
|
+
import {pgClient} from '@shipfox/node-postgres';
|
|
3
|
+
import {ephemeralRegistrationTokens} from './schema/ephemeral-registration-tokens.js';
|
|
4
|
+
import {manualRegistrationTokens} from './schema/manual-registration-tokens.js';
|
|
5
|
+
import {runnersOutbox} from './schema/outbox.js';
|
|
6
|
+
import {pendingJobExecutions} from './schema/pending-job-executions.js';
|
|
7
|
+
import {provisionedRunners} from './schema/provisioned-runners.js';
|
|
8
|
+
import {provisionerTokens} from './schema/provisioner-tokens.js';
|
|
9
|
+
import {runnersRateLimits} from './schema/rate-limits.js';
|
|
10
|
+
import {reservations} from './schema/reservations.js';
|
|
11
|
+
import {runnerSessions} from './schema/runner-sessions.js';
|
|
12
|
+
import {runningJobExecutions} from './schema/running-job-executions.js';
|
|
13
|
+
|
|
14
|
+
export const schema = {
|
|
15
|
+
ephemeralRegistrationTokens,
|
|
16
|
+
pendingJobExecutions,
|
|
17
|
+
provisionedRunners,
|
|
18
|
+
provisionerTokens,
|
|
19
|
+
runnersRateLimits,
|
|
20
|
+
reservations,
|
|
21
|
+
runnerSessions,
|
|
22
|
+
manualRegistrationTokens,
|
|
23
|
+
runningJobExecutions,
|
|
24
|
+
runnersOutbox,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
let _db: NodePgDatabase<typeof schema> | undefined;
|
|
28
|
+
|
|
29
|
+
export function db() {
|
|
30
|
+
if (!_db) _db = drizzle(pgClient(), {schema});
|
|
31
|
+
return _db;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function closeDb(): void {
|
|
35
|
+
_db = undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Tx = Parameters<Parameters<NodePgDatabase<typeof schema>['transaction']>[0]>[0];
|