From fb9b1fc15f831108b966d306af69c761a519c27d Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Wed, 11 Nov 2026 06:32:42 +0000 Subject: [PATCH] Persist Fly execution configurations --- packages/api-client/src/schema.d.ts | 280 ++++++++++++ .../0035_fly_execution_configurations.sql | 12 + packages/api/src/api-contract.ts | 18 + packages/api/src/flow-service.ts | 15 +- .../api/src/fly-execution-configurations.ts | 39 ++ .../fly-execution-configuration-repository.ts | 22 + ...-execution-configurations.postgres.test.ts | 48 ++ packages/docs/openapi.yaml | 415 ++++++++++++++++++ 8 files changed, 848 insertions(+), 1 deletion(-) create mode 100644 packages/api/migrations/0035_fly_execution_configurations.sql create mode 100644 packages/api/src/fly-execution-configurations.ts create mode 100644 packages/api/src/postgres/fly-execution-configuration-repository.ts create mode 100644 packages/api/test/fly-execution-configurations.postgres.test.ts diff --git a/packages/api-client/src/schema.d.ts b/packages/api-client/src/schema.d.ts index 96c05149..608423b5 100644 --- a/packages/api-client/src/schema.d.ts +++ b/packages/api-client/src/schema.d.ts @@ -608,6 +608,72 @@ export interface paths { patch?: never; trace?: never; }; + "/api/v1/fly/execution-configurations": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** + * List Fly execution configurations + * @description Returns tenant-owned image, region, and VM size selections without connection credentials. + * + * Requires the integrations:read scope. + * + * An interactive owner session is required; bearer tokens cannot call this operation. + */ + get: operations["get_api_v1_fly_execution_configurations"]; + put?: never; + /** + * Create a Fly execution configuration + * @description Requires a saved Fly connection and validates region and VM size against bounded provider metadata. + * + * Requires the integrations:write scope. + * + * An interactive owner session is required; bearer tokens cannot call this operation. + */ + post: operations["post_api_v1_fly_execution_configurations"]; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + "/api/v1/fly/execution-configurations/{id}": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** + * Read a Fly execution configuration + * @description Requires the integrations:read scope. + * + * An interactive owner session is required; bearer tokens cannot call this operation. + */ + get: operations["get_api_v1_fly_execution_configurations_id"]; + /** + * Update a Fly execution configuration + * @description Requires the integrations:write scope. + * + * An interactive owner session is required; bearer tokens cannot call this operation. + */ + put: operations["put_api_v1_fly_execution_configurations_id"]; + post?: never; + /** + * Delete a Fly execution configuration + * @description Requires the integrations:write scope. + * + * An interactive owner session is required; bearer tokens cannot call this operation. + */ + delete: operations["delete_api_v1_fly_execution_configurations_id"]; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/v1/integrations/exe": { parameters: { query?: never; @@ -4034,6 +4100,220 @@ export interface operations { 503: components["responses"]["Error503"]; }; }; + get_api_v1_fly_execution_configurations: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Configurations */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + configurations: { + /** Format: uuid */ + id: string; + name: string; + image: string; + region: string; + size: string; + createdAt: string; + updatedAt: string; + }[]; + }; + }; + }; + 400: components["responses"]["Error400"]; + 401: components["responses"]["Error401"]; + 403: components["responses"]["Error403"]; + 404: components["responses"]["Error404"]; + 409: components["responses"]["Error409"]; + 429: components["responses"]["Error429"]; + 500: components["responses"]["Error500"]; + 503: components["responses"]["Error503"]; + }; + }; + post_api_v1_fly_execution_configurations: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + name: string; + image: string; + region: string; + size: string; + }; + }; + }; + responses: { + /** @description Created configuration */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + configuration: { + /** Format: uuid */ + id: string; + name: string; + image: string; + region: string; + size: string; + createdAt: string; + updatedAt: string; + }; + }; + }; + }; + 400: components["responses"]["Error400"]; + 401: components["responses"]["Error401"]; + 403: components["responses"]["Error403"]; + 404: components["responses"]["Error404"]; + 409: components["responses"]["Error409"]; + 415: components["responses"]["Error415"]; + 429: components["responses"]["Error429"]; + 500: components["responses"]["Error500"]; + 503: components["responses"]["Error503"]; + }; + }; + get_api_v1_fly_execution_configurations_id: { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Configuration */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + configuration: { + /** Format: uuid */ + id: string; + name: string; + image: string; + region: string; + size: string; + createdAt: string; + updatedAt: string; + }; + }; + }; + }; + 400: components["responses"]["Error400"]; + 401: components["responses"]["Error401"]; + 403: components["responses"]["Error403"]; + 404: components["responses"]["Error404"]; + 409: components["responses"]["Error409"]; + 429: components["responses"]["Error429"]; + 500: components["responses"]["Error500"]; + 503: components["responses"]["Error503"]; + }; + }; + put_api_v1_fly_execution_configurations_id: { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + name: string; + image: string; + region: string; + size: string; + }; + }; + }; + responses: { + /** @description Updated configuration */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + configuration: { + /** Format: uuid */ + id: string; + name: string; + image: string; + region: string; + size: string; + createdAt: string; + updatedAt: string; + }; + }; + }; + }; + 400: components["responses"]["Error400"]; + 401: components["responses"]["Error401"]; + 403: components["responses"]["Error403"]; + 404: components["responses"]["Error404"]; + 409: components["responses"]["Error409"]; + 415: components["responses"]["Error415"]; + 429: components["responses"]["Error429"]; + 500: components["responses"]["Error500"]; + 503: components["responses"]["Error503"]; + }; + }; + delete_api_v1_fly_execution_configurations_id: { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Deletion result */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + id: string; + /** @constant */ + deleted: true; + }; + }; + }; + 400: components["responses"]["Error400"]; + 401: components["responses"]["Error401"]; + 403: components["responses"]["Error403"]; + 404: components["responses"]["Error404"]; + 409: components["responses"]["Error409"]; + 429: components["responses"]["Error429"]; + 500: components["responses"]["Error500"]; + 503: components["responses"]["Error503"]; + }; + }; put_api_v1_integrations_exe: { parameters: { query?: never; diff --git a/packages/api/migrations/0035_fly_execution_configurations.sql b/packages/api/migrations/0035_fly_execution_configurations.sql new file mode 100644 index 00000000..665c366f --- /dev/null +++ b/packages/api/migrations/0035_fly_execution_configurations.sql @@ -0,0 +1,12 @@ +CREATE TABLE app.fly_execution_configurations ( + tenant_id uuid NOT NULL REFERENCES app.fly_connections(tenant_id) ON DELETE CASCADE, + id uuid NOT NULL, + name text NOT NULL CHECK (length(name) BETWEEN 1 AND 120), + image text NOT NULL CHECK (length(image) BETWEEN 1 AND 512), + region text NOT NULL CHECK (region ~ '^[a-z0-9]{3}$'), + size text NOT NULL CHECK (size ~ '^[a-z0-9-]{1,64}$'), + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (tenant_id, id), + UNIQUE (tenant_id, name) +); diff --git a/packages/api/src/api-contract.ts b/packages/api/src/api-contract.ts index 42861c26..aab9e1ef 100644 --- a/packages/api/src/api-contract.ts +++ b/packages/api/src/api-contract.ts @@ -28,6 +28,7 @@ import document from "./api-document.json"; import { authInputs, authSuccess, continuationSuccess, connectionStartInput, connectionStartSuccess, connectionResumeInput, loginSuccess, sessionResponse, type AuthAction } from "./auth-api"; import { skillInput, skillUpdateInput, skillPage, skillResponse, skillJobsResponse, previewSkillInput } from "./skills"; import { flyConnectionInput, flyConnectionMetadata } from "./fly-account-client"; +import { flyExecutionConfiguration, flyExecutionConfigurationInput } from "./fly-execution-configurations"; type JsonSchema = Record; export interface RouteContract { @@ -379,6 +380,23 @@ export const API_ROUTES: RouteContract[] = [ description: "Owner browser session only. Deletes the tenant's encrypted provisioning token.", responses: { "200": { description: "Deletion result", content: { "application/json": { schema: jsonSchema(z.object({ deleted: z.boolean() }), "output") } } } }, }, service => service.removeFlyConnection(), { ownerSession: true }), + route("GET", "/api/v1/fly/execution-configurations", "integrations:read", { + summary: "List Fly execution configurations", description: "Returns tenant-owned image, region, and VM size selections without connection credentials.", + responses: { "200": { description: "Configurations", content: { "application/json": { schema: jsonSchema(z.object({ configurations: z.array(flyExecutionConfiguration) }), "output") } } } }, + }, service => service.listFlyExecutionConfigurations(), { ownerSession: true }), + route("POST", "/api/v1/fly/execution-configurations", "integrations:write", { + summary: "Create a Fly execution configuration", description: "Requires a saved Fly connection and validates region and VM size against bounded provider metadata.", + responses: { "200": { description: "Created configuration", content: { "application/json": { schema: jsonSchema(z.object({ configuration: flyExecutionConfiguration }), "output") } } } }, + }, (service, { body }) => service.saveFlyExecutionConfiguration(body), { body: flyExecutionConfigurationInput, ownerSession: true }), + route("GET", "/api/v1/fly/execution-configurations/{id}", "integrations:read", { + summary: "Read a Fly execution configuration", responses: { "200": { description: "Configuration", content: { "application/json": { schema: jsonSchema(z.object({ configuration: flyExecutionConfiguration }), "output") } } } }, + }, (service, { params }) => service.getFlyExecutionConfiguration(params.id!), { ownerSession: true, parameters: z.object({ id: z.uuid() }) }), + route("PUT", "/api/v1/fly/execution-configurations/{id}", "integrations:write", { + summary: "Update a Fly execution configuration", responses: { "200": { description: "Updated configuration", content: { "application/json": { schema: jsonSchema(z.object({ configuration: flyExecutionConfiguration }), "output") } } } }, + }, (service, { params, body }) => service.saveFlyExecutionConfiguration(body, params.id), { body: flyExecutionConfigurationInput, ownerSession: true, parameters: z.object({ id: z.uuid() }) }), + route("DELETE", "/api/v1/fly/execution-configurations/{id}", "integrations:write", { + summary: "Delete a Fly execution configuration", responses: { "200": { description: "Deletion result", content: { "application/json": { schema: jsonSchema(z.object({ id: z.string(), deleted: z.literal(true) }), "output") } } } }, + }, (service, { params }) => service.removeFlyExecutionConfiguration(params.id!), { ownerSession: true, parameters: z.object({ id: z.uuid() }) }), route( "PUT", "/api/v1/integrations/exe", diff --git a/packages/api/src/flow-service.ts b/packages/api/src/flow-service.ts index c1739a36..a44f620f 100644 --- a/packages/api/src/flow-service.ts +++ b/packages/api/src/flow-service.ts @@ -42,6 +42,8 @@ import { safeDiagnosticText } from "./harness-diagnostics"; import { skillInput, skillUpdateInput, skillPage, skillResponse, skillJobsResponse, previewSkillInput, composePrompt } from "./skills"; import { createFlyAccountClient, FlyAccountError, flyConnectionInput } from "./fly-account-client"; import { FlyConnectionRepository } from "./postgres/fly-connection-repository"; +import { FlyExecutionConfigurationRepository } from "./postgres/fly-execution-configuration-repository"; +import { flyExecutionConfigurationInput, getFlyExecutionMetadata, type FlyExecutionMetadataLoader } from "./fly-execution-configurations"; const PROJECT_GRAPH_LABEL_MAX_CHARS = 24; @@ -63,7 +65,7 @@ type Scope = "projects:read" | "projects:write" | "jobs:read" | "jobs:write" | " export class ApiService { authorizationDuration = 0; - constructor(private env: Env, private auth: OAuthProps, private ctx?: ExecutionContext) {} + constructor(private env: Env, private auth: OAuthProps, private ctx?: ExecutionContext, private flyMetadata: FlyExecutionMetadataLoader = getFlyExecutionMetadata) {} private jobs() { return new PostgresJobRepository(databaseFor(this.env), this.auth.tenantId, value => encrypt(value, this.env.CREDENTIAL_ENCRYPTION_KEY), value => decrypt(value, this.env.CREDENTIAL_ENCRYPTION_KEY)); } private connections() { return new ConnectionRepository(databaseFor(this.env), this.auth.tenantId, this.env.CREDENTIAL_ENCRYPTION_KEY); } @@ -187,6 +189,17 @@ export class ApiService { } catch (error) { this.throwFlyAccountError(error); } } async removeFlyConnection() { await this.authorizeOwnerSession("integrations:write"); return { deleted: await this.flyConnections().remove() }; } + private flyExecutionConfigs() { return new FlyExecutionConfigurationRepository(databaseFor(this.env), this.auth.tenantId); } + async listFlyExecutionConfigurations() { await this.authorizeOwnerSession("integrations:read"); return { configurations: await this.flyExecutionConfigs().list() }; } + async getFlyExecutionConfiguration(id: string) { await this.authorizeOwnerSession("integrations:read"); const value = await this.flyExecutionConfigs().get(id); if (!value) throw new ServiceError(404, "not_found", "Fly execution configuration not found"); return { configuration: value }; } + async saveFlyExecutionConfiguration(input: unknown, id?: string) { + await this.authorizeOwnerSession("integrations:write"); + if (!await this.flyConnections().get()) throw new ServiceError(409, "fly_connection_required", "Connect a Fly account before saving execution configurations."); + const parsed = flyExecutionConfigurationInput.parse(input), metadata = await this.flyMetadata(); + if (!metadata.regions.includes(parsed.region) || !metadata.sizes.includes(parsed.size)) throw new ServiceError(400, "invalid_fly_configuration", "The selected Fly region or VM size is unavailable."); + return { configuration: await this.flyExecutionConfigs().save(parsed, id) }; + } + async removeFlyExecutionConfiguration(id: string) { await this.authorizeOwnerSession("integrations:write"); const deleted = await this.flyExecutionConfigs().remove(id); if (!deleted) throw new ServiceError(404, "not_found", "Fly execution configuration not found"); return { id, deleted: true }; } private throwFlyAccountError(error: unknown): never { if (error instanceof FlyAccountError) throw new ServiceError(error.kind === "auth" ? 401 : error.kind === "organization" ? 400 : 502, error.kind === "auth" ? "fly_auth_failed" : error.kind === "organization" ? "fly_organization_unavailable" : "fly_validation_failed", error.message); throw error; diff --git a/packages/api/src/fly-execution-configurations.ts b/packages/api/src/fly-execution-configurations.ts new file mode 100644 index 00000000..d44926ad --- /dev/null +++ b/packages/api/src/fly-execution-configurations.ts @@ -0,0 +1,39 @@ +import { z } from "zod"; + +export const flyExecutionConfigurationInput = z.object({ + name: z.string().trim().min(1).max(120), + image: z.string().trim().min(1).max(512).regex(/^[A-Za-z0-9][A-Za-z0-9._/:@-]*$/, "Image must be a public image reference."), + region: z.string().trim().toLowerCase().regex(/^[a-z0-9]{3}$/), + size: z.string().trim().toLowerCase().regex(/^[a-z0-9-]{1,64}$/), +}).strict(); + +export const flyExecutionConfiguration = z.object({ + id: z.guid(), name: z.string(), image: z.string(), region: z.string(), size: z.string(), createdAt: z.string(), updatedAt: z.string(), +}); + +export type FlyExecutionConfigurationInput = z.infer; +export interface FlyExecutionMetadata { regions: readonly string[]; sizes: readonly string[] } +export type FlyExecutionMetadataLoader = () => Promise; + +/** Keeps provider metadata injected and bounded; stale reads fall back to the last good snapshot. */ +export class CachedFlyExecutionMetadata { + private value?: FlyExecutionMetadata; + private expiresAt = 0; + private pending?: Promise; + constructor(private readonly loader: FlyExecutionMetadataLoader, private readonly ttlMs = 60_000, private readonly timeoutMs = 2_000, private readonly now = Date.now) {} + async get(): Promise { + if (this.value && this.now() < this.expiresAt) return this.value; + if (!this.pending) this.pending = Promise.race([ + this.loader(), new Promise((_, reject) => setTimeout(() => reject(new Error("Fly metadata timeout")), this.timeoutMs)), + ]).then(value => { + const parsed = z.object({ regions: z.array(z.string().regex(/^[a-z0-9]{3}$/)).max(200), sizes: z.array(z.string().regex(/^[a-z0-9-]{1,64}$/)).max(100) }).parse(value); + if (!parsed.regions.length || !parsed.sizes.length) throw new Error("Fly metadata is empty"); + this.value = parsed; this.expiresAt = this.now() + this.ttlMs; return parsed; + }).catch(error => { if (this.value) return this.value; throw error; }).finally(() => { this.pending = undefined; }); + return this.pending; + } +} + +// Static bounded metadata is the safe default; deployments can inject a refreshed provider snapshot. +const defaultMetadata = new CachedFlyExecutionMetadata(async () => ({ regions: ["iad", "ord", "sjc", "lax", "ams", "fra", "lhr", "nrt", "sin"], sizes: ["shared-cpu-1x", "shared-cpu-2x", "shared-cpu-4x", "performance-1x", "performance-2x", "performance-4x"] })); +export const getFlyExecutionMetadata = () => defaultMetadata.get(); diff --git a/packages/api/src/postgres/fly-execution-configuration-repository.ts b/packages/api/src/postgres/fly-execution-configuration-repository.ts new file mode 100644 index 00000000..d31c18f0 --- /dev/null +++ b/packages/api/src/postgres/fly-execution-configuration-repository.ts @@ -0,0 +1,22 @@ +import type { Database } from "./database"; +import type { FlyExecutionConfigurationInput } from "../fly-execution-configurations"; + +export class FlyExecutionConfigurationRepository { + constructor(private database: Database, private tenantId: string) { if (!tenantId) throw new Error("tenantId is required"); } + async list() { + const { rows } = await this.database.pool.query("SELECT id,name,image,region,size,created_at,updated_at FROM app.fly_execution_configurations WHERE tenant_id=$1 ORDER BY created_at,id", [this.tenantId]); + return rows.map(row => this.map(row)); + } + async get(id: string) { + const { rows } = await this.database.pool.query("SELECT id,name,image,region,size,created_at,updated_at FROM app.fly_execution_configurations WHERE tenant_id=$1 AND id=$2", [this.tenantId,id]); + return rows[0] ? this.map(rows[0]) : null; + } + async save(input: FlyExecutionConfigurationInput, id: string = crypto.randomUUID()) { + const { rows } = await this.database.pool.query(`INSERT INTO app.fly_execution_configurations(tenant_id,id,name,image,region,size) VALUES($1,$2,$3,$4,$5,$6) + ON CONFLICT (tenant_id,id) DO UPDATE SET name=excluded.name,image=excluded.image,region=excluded.region,size=excluded.size,updated_at=now() + RETURNING id,name,image,region,size,created_at,updated_at`, [this.tenantId,id,input.name,input.image,input.region,input.size]); + return this.map(rows[0]); + } + async remove(id: string) { const r=await this.database.pool.query("DELETE FROM app.fly_execution_configurations WHERE tenant_id=$1 AND id=$2",[this.tenantId,id]); return (r.rowCount??0)>0; } + private map(row: any) { return { id: row.id, name: row.name, image: row.image, region: row.region, size: row.size, createdAt: new Date(row.created_at).toISOString(), updatedAt: new Date(row.updated_at).toISOString() }; } +} diff --git a/packages/api/test/fly-execution-configurations.postgres.test.ts b/packages/api/test/fly-execution-configurations.postgres.test.ts new file mode 100644 index 00000000..c7b2cb98 --- /dev/null +++ b/packages/api/test/fly-execution-configurations.postgres.test.ts @@ -0,0 +1,48 @@ +import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { ApiService } from "../src/flow-service"; +import { flyExecutionConfigurationInput } from "../src/fly-execution-configurations"; +import { exeConnection, integrationStatus } from "../src/settings-contracts"; +import { FlyConnectionRepository } from "../src/postgres/fly-connection-repository"; +import { FlyExecutionConfigurationRepository } from "../src/postgres/fly-execution-configuration-repository"; +import { protectedApiFetch } from "../src/protected-api"; +import { loadingFixture } from "./helpers/loading-fixture"; + +vi.mock("cloudflare:workers", () => ({ WorkerEntrypoint: class {}, DurableObject: class {} })); +vi.mock("@cloudflare/workers-oauth-provider", () => ({ OAuthProvider: class {}, AuthorizationError: class extends Error {}, getOAuthApi: vi.fn() })); + +const url = process.env.AUTH_TEST_DATABASE_URL; +describe.skipIf(!url)("Fly execution configurations (PostgreSQL/API)", () => { + let fixture: Awaited>; + beforeAll(async () => { fixture = await loadingFixture(url!); }); + beforeEach(async () => { if (fixture) await fixture.db.pool.query("DELETE FROM app.fly_connections WHERE tenant_id=$1", [fixture.tenantId]); }); + afterAll(async () => { await fixture?.cleanup(); }); + + const metadata = async () => ({ regions: ["iad", "ord"], sizes: ["shared-cpu-1x", "performance-2x"] }); + const service = (tenantId = fixture.tenantId) => new ApiService(fixture.env, { ...fixture.auth, tenantId, authMethod: "session", scopes: ["integrations:read", "integrations:write"] }, undefined, metadata); + const apiRequest = (method: string, path: string, body?: unknown) => protectedApiFetch(new Request(fixture.env.APP_ORIGIN + path, { method, headers: { Origin: fixture.env.APP_ORIGIN, "Content-Type": "application/json" }, ...(body === undefined ? {} : { body: JSON.stringify(body) }) }), fixture.env, { ...fixture.auth, authMethod: "session", scopes: ["integrations:read", "integrations:write"] }, { waitUntil() {} } as any); + + it("stores multiple tenant-scoped configurations, validates provider selections, and omits credentials", async () => { + const fly = new FlyConnectionRepository(fixture.db, fixture.tenantId, fixture.env.CREDENTIAL_ENCRYPTION_KEY); + await fly.save({ organizationSlug: "alpha", organizationName: "Alpha" }, "synthetic-fly-token"); + const api = service(); + const firstResponse = await apiRequest("POST", "/api/v1/fly/execution-configurations", { name: "Codex east", image: "ghcr.io/acme/runner:v1", region: "iad", size: "shared-cpu-1x" }); + const secondResponse = await apiRequest("POST", "/api/v1/fly/execution-configurations", { name: "Code west", image: "ghcr.io/acme/code:v2", region: "ord", size: "performance-2x" }); + expect(firstResponse.status).toBe(200); expect(secondResponse.status).toBe(200); + const first = await firstResponse.json() as any, second = await secondResponse.json() as any; + expect((await (await apiRequest("GET", "/api/v1/fly/execution-configurations")).json() as any).configurations).toHaveLength(2); + expect((await api.getFlyExecutionConfiguration(first.configuration.id)).configuration).toEqual(first.configuration); + expect(JSON.stringify(await (await apiRequest("GET", "/api/v1/fly/execution-configurations")).json())).not.toContain("synthetic-fly-token"); + await expect(new FlyExecutionConfigurationRepository(fixture.db, fixture.otherTenant).list()).resolves.toEqual([]); + await expect(api.saveFlyExecutionConfiguration({ name: "Bad region", image: "ghcr.io/acme/runner:v1", region: "xyz", size: "shared-cpu-1x" })).rejects.toMatchObject({ code: "invalid_fly_configuration" }); + await expect(api.saveFlyExecutionConfiguration({ name: "Bad size", image: "ghcr.io/acme/runner:v1", region: "iad", size: "custom" })).rejects.toMatchObject({ code: "invalid_fly_configuration" }); + expect(await api.removeFlyExecutionConfiguration(second.configuration.id)).toEqual({ id: second.configuration.id, deleted: true }); + }); + + it("requires a Fly connection and preserves old exe payload omission compatibility", async () => { + const api = service(); + await expect(api.saveFlyExecutionConfiguration({ name: "x", image: "ghcr.io/a/b:v1", region: "iad", size: "shared-cpu-1x" })).rejects.toMatchObject({ code: "fly_connection_required" }); + expect(flyExecutionConfigurationInput.safeParse({ name: "x", image: "bad image", region: "iad", size: "shared-cpu-1x" }).success).toBe(false); + expect(exeConnection.parse({ connectionId: "old", credentialStatus: "connected" })).toEqual({ connectionId: "old", credentialStatus: "connected", accountTags: [], models: [], efforts: [] }); + expect(integrationStatus.parse({ linear: null, clickup: null, exe: null, exeConnections: [], ampConnections: [], cloudflareTail: { count: 0, installations: [] } }).exeConnections).toEqual([]); + }); +}); diff --git a/packages/docs/openapi.yaml b/packages/docs/openapi.yaml index b6d5c57d..e34e8235 100644 --- a/packages/docs/openapi.yaml +++ b/packages/docs/openapi.yaml @@ -4378,6 +4378,421 @@ paths: - token - organizationSlug additionalProperties: false + /api/v1/fly/execution-configurations: + get: + summary: List Fly execution configurations + description: |- + Returns tenant-owned image, region, and VM size selections without connection credentials. + + Requires the integrations:read scope. + + An interactive owner session is required; bearer tokens cannot call this operation. + responses: + "200": + description: Configurations + content: + application/json: + schema: + type: object + properties: + configurations: + type: array + items: + type: object + properties: + id: + type: string + format: uuid + pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$ + name: + type: string + image: + type: string + region: + type: string + size: + type: string + createdAt: + type: string + updatedAt: + type: string + required: + - id + - name + - image + - region + - size + - createdAt + - updatedAt + additionalProperties: false + required: + - configurations + additionalProperties: false + "400": + $ref: "#/components/responses/Error400" + "401": + $ref: "#/components/responses/Error401" + "403": + $ref: "#/components/responses/Error403" + "404": + $ref: "#/components/responses/Error404" + "409": + $ref: "#/components/responses/Error409" + "429": + $ref: "#/components/responses/Error429" + "500": + $ref: "#/components/responses/Error500" + "503": + $ref: "#/components/responses/Error503" + operationId: get_api_v1_fly_execution_configurations + tags: + - fly + security: + - bearerAuth: [] + - cookieAuth: [] + x-required-scope: integrations:read + x-owner-session-required: true + post: + summary: Create a Fly execution configuration + description: |- + Requires a saved Fly connection and validates region and VM size against bounded provider metadata. + + Requires the integrations:write scope. + + An interactive owner session is required; bearer tokens cannot call this operation. + responses: + "200": + description: Created configuration + content: + application/json: + schema: + type: object + properties: + configuration: + type: object + properties: + id: + type: string + format: uuid + pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$ + name: + type: string + image: + type: string + region: + type: string + size: + type: string + createdAt: + type: string + updatedAt: + type: string + required: + - id + - name + - image + - region + - size + - createdAt + - updatedAt + additionalProperties: false + required: + - configuration + additionalProperties: false + "400": + $ref: "#/components/responses/Error400" + "401": + $ref: "#/components/responses/Error401" + "403": + $ref: "#/components/responses/Error403" + "404": + $ref: "#/components/responses/Error404" + "409": + $ref: "#/components/responses/Error409" + "415": + $ref: "#/components/responses/Error415" + "429": + $ref: "#/components/responses/Error429" + "500": + $ref: "#/components/responses/Error500" + "503": + $ref: "#/components/responses/Error503" + operationId: post_api_v1_fly_execution_configurations + tags: + - fly + security: + - bearerAuth: [] + - cookieAuth: [] + x-required-scope: integrations:write + x-owner-session-required: true + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + type: string + minLength: 1 + maxLength: 120 + image: + type: string + minLength: 1 + maxLength: 512 + pattern: ^[A-Za-z0-9][A-Za-z0-9._/:@-]*$ + region: + type: string + pattern: ^[a-z0-9]{3}$ + size: + type: string + pattern: ^[a-z0-9-]{1,64}$ + required: + - name + - image + - region + - size + additionalProperties: false + /api/v1/fly/execution-configurations/{id}: + get: + summary: Read a Fly execution configuration + responses: + "200": + description: Configuration + content: + application/json: + schema: + type: object + properties: + configuration: + type: object + properties: + id: + type: string + format: uuid + pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$ + name: + type: string + image: + type: string + region: + type: string + size: + type: string + createdAt: + type: string + updatedAt: + type: string + required: + - id + - name + - image + - region + - size + - createdAt + - updatedAt + additionalProperties: false + required: + - configuration + additionalProperties: false + "400": + $ref: "#/components/responses/Error400" + "401": + $ref: "#/components/responses/Error401" + "403": + $ref: "#/components/responses/Error403" + "404": + $ref: "#/components/responses/Error404" + "409": + $ref: "#/components/responses/Error409" + "429": + $ref: "#/components/responses/Error429" + "500": + $ref: "#/components/responses/Error500" + "503": + $ref: "#/components/responses/Error503" + description: |- + Requires the integrations:read scope. + + An interactive owner session is required; bearer tokens cannot call this operation. + operationId: get_api_v1_fly_execution_configurations_id + tags: + - fly + security: + - bearerAuth: [] + - cookieAuth: [] + x-required-scope: integrations:read + x-owner-session-required: true + parameters: + - name: id + in: path + required: true + schema: + type: string + format: uuid + pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$ + put: + summary: Update a Fly execution configuration + responses: + "200": + description: Updated configuration + content: + application/json: + schema: + type: object + properties: + configuration: + type: object + properties: + id: + type: string + format: uuid + pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$ + name: + type: string + image: + type: string + region: + type: string + size: + type: string + createdAt: + type: string + updatedAt: + type: string + required: + - id + - name + - image + - region + - size + - createdAt + - updatedAt + additionalProperties: false + required: + - configuration + additionalProperties: false + "400": + $ref: "#/components/responses/Error400" + "401": + $ref: "#/components/responses/Error401" + "403": + $ref: "#/components/responses/Error403" + "404": + $ref: "#/components/responses/Error404" + "409": + $ref: "#/components/responses/Error409" + "415": + $ref: "#/components/responses/Error415" + "429": + $ref: "#/components/responses/Error429" + "500": + $ref: "#/components/responses/Error500" + "503": + $ref: "#/components/responses/Error503" + description: |- + Requires the integrations:write scope. + + An interactive owner session is required; bearer tokens cannot call this operation. + operationId: put_api_v1_fly_execution_configurations_id + tags: + - fly + security: + - bearerAuth: [] + - cookieAuth: [] + x-required-scope: integrations:write + x-owner-session-required: true + parameters: + - name: id + in: path + required: true + schema: + type: string + format: uuid + pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$ + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + type: string + minLength: 1 + maxLength: 120 + image: + type: string + minLength: 1 + maxLength: 512 + pattern: ^[A-Za-z0-9][A-Za-z0-9._/:@-]*$ + region: + type: string + pattern: ^[a-z0-9]{3}$ + size: + type: string + pattern: ^[a-z0-9-]{1,64}$ + required: + - name + - image + - region + - size + additionalProperties: false + delete: + summary: Delete a Fly execution configuration + responses: + "200": + description: Deletion result + content: + application/json: + schema: + type: object + properties: + id: + type: string + deleted: + type: boolean + const: true + required: + - id + - deleted + additionalProperties: false + "400": + $ref: "#/components/responses/Error400" + "401": + $ref: "#/components/responses/Error401" + "403": + $ref: "#/components/responses/Error403" + "404": + $ref: "#/components/responses/Error404" + "409": + $ref: "#/components/responses/Error409" + "429": + $ref: "#/components/responses/Error429" + "500": + $ref: "#/components/responses/Error500" + "503": + $ref: "#/components/responses/Error503" + description: |- + Requires the integrations:write scope. + + An interactive owner session is required; bearer tokens cannot call this operation. + operationId: delete_api_v1_fly_execution_configurations_id + tags: + - fly + security: + - bearerAuth: [] + - cookieAuth: [] + x-required-scope: integrations:write + x-owner-session-required: true + parameters: + - name: id + in: path + required: true + schema: + type: string + format: uuid + pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$ /api/v1/integrations/exe: put: summary: Create an exe.dev integration