Repository navigation
Description
Related: #740 (fly wrapper reuses this) · epic #736 · the floci additions (#706/#707/#734)
Problem
The per-cloud emulator-lifecycle wrappers are near-duplicates:
lexicons/aws/src/op/activities/floci.ts (149 lines), .../azure/.../floci-az.ts (123),
.../gcp/.../floci-gcp.ts (123). Identical structure — idempotent up (reuse running
container → docker run → poll health → return endpoint) and down (docker rm -f). Only three
things differ. The fly lexicon's flapsUp/Down (#740) would be the 4th copy, so extract a
shared helper now and have fly build against it from day one.
What varies (the only parameters needed)
- image / container port / health path — e.g.
floci/floci:4566:/_localstack/health,
floci-gcp:4588:/_floci-gcp/health,mudflaps:4280:/_mudflaps/health. - ready predicate — aws gates on a service name in the body
(isFlociReady→body.includes('"cloudformation"')); az/gcp/mudflaps: any 200 is ready. - extra
docker runargs — aws mounts the docker socket
(-v /var/run/docker.sock:...); the others don't.
What to build
emulatorLifecycle(spec) in packages/core/src/op/emulator-lifecycle.ts, exported from
@intentius/chant/op (the module the floci files already import safeHeartbeat/sleep from):
interface EmulatorSpec {
name: string; // default container name, e.g. "chant-mudflaps"
image: string; // default image (pin a tag)
containerPort: number; // internal port (4566 / 4588 / 4280 / …)
healthPath: string; // "/_localstack/health" | "/_mudflaps/health" | …
ready?: (body: string) => boolean; // default: any 200 → ready
runArgs?: string[]; // extra `docker run` args (e.g. docker-sock mount)
}
interface EmulatorLifecycle {
up(opts?: { name?: string; port?: number; image?: string; timeoutMs?: number; intervalMs?: number }, signal?: AbortSignal): Promise<{ endpoint: string }>;
down(opts?: { name?: string }, signal?: AbortSignal): Promise<void>;
// exposed for pure command tests (mirror the current floci.test.ts):
runCommand(o): string; existsCommand(name): string; rmCommand(name): string; healthUrl(port): string;
}
function emulatorLifecycle(spec: EmulatorSpec): EmulatorLifecycleup keeps today's behavior: docker ps -q -f name=<name> for idempotent reuse, docker run -d --rm --name <name> -p <port>:<containerPort> <runArgs> <image>, poll healthUrl(port) on the
injected interval until ready(body), return { endpoint: "http://localhost:<port>" }.
Migration (keep public names, no caller breakage)
Rewrite each floci*.ts as a thin adapter over the helper, preserving exported function names
(flociUp/flociGcpUp/…) so ops and tests don't change:
const gcp = emulatorLifecycle({ name: "chant-floci-gcp", image: "floci/floci-gcp:latest", containerPort: 4588, healthPath: "/_floci-gcp/health" });
export const flociGcpUp = gcp.up; export const flociGcpDown = gcp.down;aws passes ready: (b) => b.includes('"cloudformation"') and runArgs for the docker socket.
Fly reuse (#740)
The fly wrapper is a 3-line spec — no 4th near-dup:
const flaps = emulatorLifecycle({ name: "chant-mudflaps", image: "ghcr.io/intentius/mudflaps:0.3.0", containerPort: 4280, healthPath: "/_mudflaps/health" });
export const flapsUp = flaps.up; export const flapsDown = flaps.down;Acceptance criteria
-
emulatorLifecyclein@intentius/chant/opwith unit tests for the pure command builders
(mirroringlexicons/aws/src/op/activities/floci.test.ts). -
#740's fly wrapper is built on it (spec only, no bespoke lifecycle code). - The 3 existing
floci*.tsare migrated to thin adapters with their exported names
unchanged; existing floci tests pass (aws keeps its service-gate ready predicate + docker-sock arg).
References
- The three current wrappers +
floci.test.ts. Module:packages/core/src/op/(@intentius/chant/op). - Lineage context (why aws's health differs):
examples/local-cloud-trio/README.md(PR docs: floci lineage + xmlField assumption + shell-free scope #745).
Activity
core: shared emulatorLifecycle helper; migrate floci*.ts to adapters (#…
fly lexicon: scaffold chant-lexicon-fly + flaps wrapper (#737 groundw…