Skip to content

fly: App + Machine serializer emitting flaps create bodies (#738) - #751

Merged
lex00 merged 2 commits into
mainfrom
fly-serializer-738
Jul 11, 2026
Merged

lex00 merged 2 commits into
mainfrom
fly-serializer-738

Conversation

@lex00

@lex00 lex00 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Closes #738 (Phase 1 spine). Turns declared App/Machine resources — built on #737's generated types (D6) — into the JSON create bodies flaps accepts, so #739's applier can POST them verbatim and mudflaps round-trips them.

Output shape

A JSON object keyed by entity name; each value is one flaps request:

{
  "web": { "endpoint": "/v1/apps", "method": "POST", "body": { "app_name": "my-app", "org_slug": "acme" } },
  "api": { "endpoint": "/v1/apps/my-app/machines", "method": "POST",
    "body": { "name": "api-1", "region": "iad",
      "config": { "image": "flyio/hellofly:latest", "guest": { "cpu_kind": "shared", "cpus": 1, "memory_mb": 256 },
        "metadata": { "managed-by": "chant", "chant-stack": "billing", "chant-env": "prod" } } } }
}

Wire fidelity

Field names come from mudflaps' Go structs (the oracle), which win over the OpenAPI-generated TS names:

  • App create body is { app_name, org_slug } — not the generated name.
  • Machine body is { name?, region?, config }; the owning app is a URL path segment, not a body field.

D2 ownership

Every serialized Machine carries managed-by: chant (plus stack/env from context.ownership) merged into config.metadata, even with no user metadata — the marker wins over colliding keys so ownership can't be silently unset. Key naming lives in a new src/ownership.ts, mirroring aws/azure.

Tests

16 fly package tests pass (serializer 8, incl. bare-machine marker + ownership stack/env + app_name fidelity). generate + validate green; check-lexicon no regression.

Deferred to #739: actually POSTing to mudflaps, leases/nonce, /wait, owned-only prune. Volume/IP/cert/secret are recognized-but-skipped (out of scope → #741).

🤖 Generated with Claude Code

lex00 and others added 2 commits July 11, 2026 10:27
Replace the scaffold serializer stub with the real flySerializer: it turns
declared App and Machine resources (over #737's generated types) into the
JSON create bodies flaps accepts, keyed by entity name as
{ endpoint, method, body } so #739's applier can POST them verbatim and
mudflaps round-trips them.

Field names follow mudflaps' Go structs (the wire oracle), which win over
the OpenAPI-generated TS names: App create body is { app_name, org_slug }
(not `name`); Machine body is { name?, region?, config } with the owning
app as a URL path segment, not a body field.

D2: every serialized Machine carries the managed-by: chant ownership
marker (plus stack/env from context.ownership) merged into config.metadata,
even when the user set no metadata — the marker wins over colliding keys so
ownership can't be silently unset. Ownership key naming lives in a new
src/ownership.ts (FLY_METADATA_OWNERSHIP_KEYS), mirroring aws/azure.

16 fly package tests pass; generate + validate green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…hant

fly's src/generated is gitignored (regenerated in prepack), but the CI
"Generate lexicon artifacts" step enumerated lexicons explicitly and omitted
fly — so the generated types were absent at test time and serializer.test.ts
(which imports ./generated/index) failed with ERR_MODULE_NOT_FOUND. #750
passed only because no test imported generated yet.

Add `npm run --prefix lexicons/fly prepack` to both generate steps, and move
fly's spec cache to ~/.chant (matching k8s) so CI's schema cache covers it and
a docs.machines.dev hiccup falls back to cache instead of failing generate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lex00
lex00 merged commit a00fba8 into main Jul 11, 2026
5 checks passed
@lex00
lex00 deleted the fly-serializer-738 branch July 11, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fly lexicon: App + Machine typed resources + serializer (machine-config / fly.toml)

1 participant