Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/emulator-freshness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
id: freshness
env:
GITHUB_TOKEN: ${{ github.token }}
run: npx tsx lexicons/fly/src/emulator-freshness-cli.ts
run: npx tsx scripts/check-emulator-freshness.ts

# Open or refresh a single tracking issue when a pin is behind. Advisory —
# a human reviews and bumps the pin per the #808 policy.
Expand Down
1 change: 1 addition & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export default defineConfig({
{ label: 'Create a Serializer', slug: 'lexicon-authoring/serializer' },
{ label: 'Implementing Observation', slug: 'lexicon-authoring/observation' },
{ label: 'Implementing Live Export', slug: 'lexicon-authoring/live-export' },
{ label: 'Declaring a Local Emulator', slug: 'lexicon-authoring/emulator' },
{ label: 'Write Lint Rules', slug: 'lexicon-authoring/lint-rules' },
{ label: 'LSP & MCP Providers', slug: 'lexicon-authoring/lsp-mcp' },
{ label: 'Skills', slug: 'lexicon-authoring/skills' },
Expand Down
37 changes: 27 additions & 10 deletions docs/src/content/docs/cli/emulator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Every action is idempotent. `up` on an already-running emulator reports the
existing endpoint rather than starting a second container.

<Aside type="note" title="Which lexicons have one">
An emulator is a lexicon capability, and today **aws** is the only lexicon that
declares one — [Floci](https://github.com/floci-io/floci). Running the command
in a project without it is not an error: it warns and exits 0, so a script that
An emulator is a lexicon capability. Four lexicons declare five between them —
a lexicon can ship more than one (chant #1345). Running the command in a project
whose lexicons have none is not an error: it warns and exits 0, so a script that
calls `chant emulator up` unconditionally still works.
</Aside>

Expand All @@ -49,8 +49,15 @@ chant emulator up

```
✓ aws: chant-floci up on http://localhost:4566
✓ azure: chant-floci-az up on http://localhost:4577
✓ gcp: chant-floci-gcp up on http://localhost:4588
✓ fly: chant-mudflaps up on http://localhost:4280
✓ fly: chant-spritzer up on http://localhost:4290
```

One line per emulator, not per lexicon: fly ships two, and `--lexicon fly` acts
on both.

### `emulator down`

Stops and removes the containers.
Expand Down Expand Up @@ -129,14 +136,24 @@ command is for the ad-hoc case, and for tools that need the endpoint
programmatically.
</Aside>

## The aws emulator
## The emulators

| Lexicon | Container | Image | Port | Health check | Endpoint var |
|---|---|---|---|---|---|
| aws | `chant-floci` | `floci/floci:1.5.34` | `4566` | `/_localstack/health`, waiting on `cloudformation` | `AWS_ENDPOINT_URL` |
| azure | `chant-floci-az` | `floci/floci-az:0.10.0` | `4577` | `/_floci/health` | `AZURE_ENDPOINT_URL` |
| gcp | `chant-floci-gcp` | `floci/floci-gcp:0.5.0` | `4588` | `/_floci-gcp/health` | — |
| fly | `chant-mudflaps` | `ghcr.io/intentius/mudflaps:0.4.1` | `4280` | `/_mudflaps/health` | `FLY_FLAPS_BASE_URL` |
| fly | `chant-spritzer` | `ghcr.io/intentius/spritzer:0.4.1` | `4290` | `/_spritzer/health` | `SPRITES_BASE_URL` |

gcp has no endpoint variable because `gcpApply` takes the endpoint as an
explicit argument rather than reading one — `chant emulator up --json` still
reports the endpoint, there is just nothing to export.

| | |
|---|---|
| Container | `chant-floci` |
| Image | `floci/floci:latest` |
| Port | `4566` |
| Health check | `/_localstack/health`, waiting on `cloudformation` |
Every image is pinned rather than tracking `:latest`, so a local suite that
passes today does not fail tomorrow because an image moved. A weekly workflow
reports how far behind each pin is; the bump is a human decision, made when a
consuming test needs the newer emulator.

Requires Docker. If Docker is missing or not running, `status` reports the
emulator as down rather than failing.
Expand Down
89 changes: 89 additions & 0 deletions docs/src/content/docs/lexicon-authoring/emulator.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Declaring a Local Emulator
description: How a lexicon declares the emulator chant emulator boots, and why declaring it is separate from having one
---

A lexicon that can be exercised without a cloud account declares an
**emulator capability**: enough for chant to boot the container, wait for it to
be healthy, and tell tooling where it is. `chant emulator up|down|status` and
`behold serve --local` both drive it.

## The declaration

```typescript
// src/op/activities/my-emulator.ts
import { emulatorLifecycle, type EmulatorCapability, type EmulatorSpec } from "@intentius/chant/op";

export const MY_EMULATOR_SPEC: EmulatorSpec = {
name: "chant-myfake", // container name
image: "org/myfake:1.2.0", // pinned, not :latest
containerPort: 4599,
healthPath: "/_myfake/health",
upstream: { repo: "org/myfake" }, // where releases are published
};

export const MY_EMULATOR: EmulatorCapability = {
spec: MY_EMULATOR_SPEC,
env: (endpoint) => ({ MYFAKE_ENDPOINT_URL: endpoint }),
};

// src/plugin.ts
emulator: MY_EMULATOR,
```

The same spec drives `emulatorLifecycle()`, so the wrapper your Ops already use
and the capability chant boots are one object rather than two that can drift.

## Having one is not declaring one

This distinction cost the repo three of its four emulators. azure and gcp both
built the exact spec above in `src/op/activities/` and used it from their Ops,
and neither set `plugin.emulator` — so `chant emulator up --all` booted Floci
and nothing else, while the local-testing docs presented all three clouds as
equal local targets (chant #1345). The wrapper is not the declaration.

## More than one

`emulator` takes a capability or an array of them. fly declares two:

```typescript
emulator: [MUDFLAPS_EMULATOR, SPRITZER_EMULATOR],
```

`chant emulator` reports one line per emulator rather than per lexicon, and
`--lexicon fly` acts on both.

## `env` names the endpoint variable

`env(endpoint)` returns what points tooling at the running emulator. Two things
depend on getting it right:

- **`chant emulator up --json`** hands it to a consumer verbatim, so credentials
and a region belong here too — Floci returns `AWS_ACCESS_KEY_ID: "test"`
alongside the endpoint.
- **`--live --env <name>` endpoint injection** picks out only the variables whose
*value is the endpoint* and sets those, leaving the credentials alone. That
derivation replaced a hand-maintained map in core which listed two of the four
lexicons that have an endpoint variable — and asserted azure had none, while
azure's own `describe-resources.ts` read `AZURE_ENDPOINT_URL` on every call.

Return `{}` when the emulator is reached only through an explicit argument, as
gcp's is. That is a real answer, and a better one than naming a variable nothing
reads.

## Pin the image

`image` should carry a version tag. An emulator on `:latest` cannot be behind,
which sounds fine until a local suite that passed yesterday fails today and
nothing in the repo records what moved.

Declaring `upstream.repo` puts the pin in the weekly freshness check
(`scripts/check-emulator-freshness.ts`), which compares each pin against the
latest GitHub release and opens a single advisory notice. It never bumps
anything: per the chant #808 policy a pin moves when a consuming test needs the
newer emulator, not because a release happened.

## See also

- [`chant emulator`](/chant/cli/emulator/) — the command this drives
- [Local Testing](/chant/local-testing/overview/) — the per-cloud loops
1 change: 1 addition & 0 deletions docs/src/content/docs/lexicon-authoring/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Every lexicon must implement these 4 methods to support the full generation and
| `completionProvider()` | `CompletionItem[]` | LSP completions for resource/property names |
| `hoverProvider()` | `HoverInfo` | LSP hover information for resource types |
| `docs()` | `Promise<void>` | Generate documentation pages |
| `emulator` | `EmulatorCapability` or a list of them | Local emulator(s) `chant emulator` boots — see [Declaring a Local Emulator](/chant/lexicon-authoring/emulator/) |
| `mcpTools()` | `McpToolContribution[]` | MCP tool contributions |
| `mcpResources()` | `McpResourceContribution[]` | MCP resource contributions |
| `commands()` | `CommandGroup` | A CLI verb group mounted under `chant <name> <verb>` — core dispatches to it wholesale and knows nothing about what's inside |
Expand Down
4 changes: 2 additions & 2 deletions lexicons/aws/src/op/activities/floci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
describe("flociRunCommand (#704)", () => {
test("minimal — defaults name/port/image, no docker socket", () => {
expect(flociRunCommand({})).toBe(
"docker run -d --rm --name chant-floci -p 4566:4566 floci/floci:latest",
"docker run -d --rm --name chant-floci -p 4566:4566 floci/floci:1.5.34",
);
});

Expand Down Expand Up @@ -60,7 +60,7 @@ describe("flociHealthUrl / flociEnv (#704)", () => {
describe("FLOCI_SPEC / FLOCI_EMULATOR — the aws plugin's emulator capability (#920)", () => {
test("spec pins the Floci container identity the shared lifecycle boots", () => {
expect(FLOCI_SPEC.name).toBe("chant-floci");
expect(FLOCI_SPEC.image).toBe("floci/floci:latest");
expect(FLOCI_SPEC.image).toBe("floci/floci:1.5.34");
expect(FLOCI_SPEC.containerPort).toBe(4566);
expect(FLOCI_SPEC.healthPath).toBe("/_localstack/health");
});
Expand Down
7 changes: 6 additions & 1 deletion lexicons/aws/src/op/activities/floci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { emulatorLifecycle, type EmulatorSpec, type EmulatorCapability } from "@

const DEFAULT_NAME = "chant-floci";
const DEFAULT_PORT = 4566;
const DEFAULT_IMAGE = "floci/floci:latest";
// Pinned, not `:latest` (#1345). An image that moves underneath a passing
// local suite is the drift a pin exists to stop, and the freshness check in
// core reports how far behind this is rather than bumping it — the tag moves
// when a consuming test needs the newer emulator (#808).
const DEFAULT_IMAGE = "floci/floci:1.5.34";
const DEFAULT_REGION = "us-east-1";
const DEFAULT_READY_SERVICE = "cloudformation";
const DOCKER_SOCK = ["-v", "/var/run/docker.sock:/var/run/docker.sock"] as const;
Expand Down Expand Up @@ -55,6 +59,7 @@ const flociSpecFor = (readyService: string): EmulatorSpec => ({
containerPort: DEFAULT_PORT,
healthPath: "/_localstack/health",
ready: (body) => isFlociReady(body, readyService),
upstream: { repo: "floci-io/floci" },
});

/** The Floci emulator spec — the aws plugin's `emulator` capability (#920). */
Expand Down
2 changes: 1 addition & 1 deletion lexicons/azure/src/op/activities/floci-az.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
describe("floci-az lifecycle commands (typed emulator, not shell)", () => {
test("run command uses defaults and maps the port", () => {
expect(flociAzRunCommand({})).toBe(
"docker run -d --rm --name chant-floci-az -p 4577:4577 floci/floci-az:latest",
"docker run -d --rm --name chant-floci-az -p 4577:4577 floci/floci-az:0.10.0",
);
});

Expand Down
30 changes: 25 additions & 5 deletions lexicons/azure/src/op/activities/floci-az.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { emulatorLifecycle } from "@intentius/chant/op";
import { emulatorLifecycle, type EmulatorCapability, type EmulatorSpec } from "@intentius/chant/op";

export interface FlociAzUpArgs {
/** Container name. Default: `chant-floci-az`. */
name?: string;
/** Host port mapped to the emulator's `:4577`. Default: `4577`. */
port?: number;
/** Image. Default: `floci/floci-az:latest`. */
/** Image. Default: the pinned `floci/floci-az` tag. */
image?: string;
/** Readiness timeout in ms. Default: `60000`. */
timeoutMs?: number;
Expand All @@ -20,12 +20,32 @@ export interface FlociAzDownArgs {

// floci-az is a bespoke ARM fake (not LocalStack) — a plain 200 on its health
// endpoint means ready. Shared lifecycle: emulatorLifecycle (#746).
const az = emulatorLifecycle({
// Pinned rather than `:latest` (#1345): an image that moves underneath a
// passing local suite is exactly the drift a pin exists to stop.
export const FLOCI_AZ_SPEC: EmulatorSpec = {
name: "chant-floci-az",
image: "floci/floci-az:latest",
image: "floci/floci-az:0.10.0",
containerPort: 4577,
healthPath: "/_floci/health",
});
upstream: { repo: "floci-io/floci-az" },
};

/**
* The azure plugin's emulator capability (#1345).
*
* The spec below has existed since #746; what was missing was declaring it, so
* `chant emulator up --all` booted Floci and nothing else even though floci-az
* was one line away. `AZURE_ENDPOINT_URL` is the var azure's own
* `describe-resources.ts` and `deep-observe.ts` already read on every live
* call, which is also what makes `--live --env <local>` reach the emulator
* instead of real Azure.
*/
export const FLOCI_AZ_EMULATOR: EmulatorCapability = {
spec: FLOCI_AZ_SPEC,
env: (endpoint) => ({ AZURE_ENDPOINT_URL: endpoint }),
};

const az = emulatorLifecycle(FLOCI_AZ_SPEC);

export const flociAzExistsCommand = az.existsCommand;
export const flociAzRmCommand = az.rmCommand;
Expand Down
2 changes: 2 additions & 0 deletions lexicons/azure/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { CompletionContext, CompletionItem, HoverContext, HoverInfo } from
import type { McpToolContribution, McpResourceContribution } from "@intentius/chant/mcp/types";
import { postSynthChecks as postSynthCheckList } from "./lint/post-synth";
import { azureAuditCatalog } from "./lint/audit-catalog";
import { FLOCI_AZ_EMULATOR } from "./op/activities/floci-az";
import { createSkillsLoader } from "@intentius/chant/lexicon-plugin-helpers";
import { readFileSync, readdirSync, existsSync } from "fs";
import { join, dirname } from "path";
Expand All @@ -29,6 +30,7 @@ import { azureDeepNormalizationHooks, observeResourcesDeepAzure } from "./deep-o
*/
export const azurePlugin: LexiconPlugin = {
name: "azure",
emulator: FLOCI_AZ_EMULATOR,
auditCatalog: () => azureAuditCatalog,
serializer: azureSerializer,

Expand Down
49 changes: 0 additions & 49 deletions lexicons/fly/src/emulator-freshness-cli.ts

This file was deleted.

Loading
Loading