Skip to content

serve --adapter fastly should reconcile local provisioning and typed config before starting Viceroy #390

Open

Description

@ChristianPavilonis

Problem

A generated typed app CLI currently needs this manual sequence for Fastly local development:

ts config push --adapter fastly --local --yes
ts serve --adapter fastly

The first command is easy to miss. It also has to be repeated after trusted-server.toml changes. Without it, fastly.toml has missing or stale [local_server.config_stores.<store>.contents] data, so Viceroy starts without the current typed app config.

This makes serve unreliable on a fresh checkout and lets developers test stale configuration without realizing it.

The current code paths explain the gap:

  • run_serve dispatches AdapterAction::Serve immediately.
  • Fastly serve shells out to fastly compute serve.
  • config push --local is the code that writes the typed blob into Fastly's local-server config-store tables.
  • The typed push already compares the blob-envelope SHA and skips an equal value, so we do not need a second timestamp or cache file to detect changes.

Desired behavior

For a generated typed CLI, this should be enough:

ts serve --adapter fastly

Before starting Viceroy, serve should reconcile the local state needed by that adapter:

  1. Ensure local adapter resources and generated manifests exist and match edgezero.toml.
  2. Validate and push the typed app config to the local emulator state when its content differs.
  3. Start the adapter's local server only after reconciliation succeeds.

The operation must stay local. It must not create or update Fastly account resources or require Fastly authentication.

Suggested shape

  • Add a typed serve path such as run_serve_typed::<C>, since the bundled untyped edgezero binary cannot serialize an application's AppConfig<C>.
  • Update generated downstream CLIs to dispatch serve through that typed path.
  • Reuse the existing local config readback and envelope SHA comparison. Run reconciliation on every serve invocation and let the existing idempotency check decide whether a write is needed.
  • Compose with provision --local from feat: provision --local + gitignored adapter manifests + hardened path safety #287 once available, rather than adding separate Fastly-only bootstrap logic to serve.
  • Keep run_serve usable for untyped callers. If it cannot reconcile typed config, its behavior and limitation should be explicit.
  • Treat local reconciliation as a preflight. If validation, provisioning, or config writeback fails, do not start Viceroy.

This can start with Fastly, but the boundary should allow other adapters to declare local prerequisites without putting provider-specific branching into the generated CLI.

Acceptance criteria

  • On a freshly provisioned checkout, ts serve --adapter fastly does not require a separate ts config push --adapter fastly --local command.
  • Changing trusted-server.toml and restarting serve updates the Fastly local config-store entry before Viceroy starts.
  • Starting serve with unchanged config uses the existing SHA equality check and does not rewrite the entry unnecessarily.
  • The preflight performs no Fastly management API operations and needs no Fastly login.
  • A config validation or local writeback error exits before fastly compute serve runs.
  • Generated typed CLIs use the typed serve path.
  • Tests cover first run, changed config, unchanged config, and preflight failure.
  • Local-development docs show serve as the single command after initial project setup.

Related work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions