Skip to content

feat(sandbox): Phase 0 MVP — local HTTP mock server from OpenAPI spec#73

Merged
yuchou87 merged 18 commits into
mainfrom
feat/sandbox-phase0
May 9, 2026
Merged

feat(sandbox): Phase 0 MVP — local HTTP mock server from OpenAPI spec#73
yuchou87 merged 18 commits into
mainfrom
feat/sandbox-phase0

Conversation

@yuchou87

@yuchou87 yuchou87 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds internal/sandbox/ package: stateful in-memory mock HTTP server driven by an OpenAPI spec
  • Adds caseforge sandbox --spec <path> command for interactive dev/debug use
  • Adds caseforge gen --with-sandbox flag for CI one-shot validate-without-a-real-backend

What's included

internal/sandbox/

File Responsibility
sandbox.go Options struct + defaults
state.go StateStore interface + memStateStore (RWMutex-guarded, concurrent-safe)
strategies.go ExampleStrategy → SchemaStrategy → FakerStrategy chain
generator.go ResponseGenerator: tries strategies, guarantees non-empty id on write ops
logging.go multiHandler fanning slog records to stderr (text) + file (JSON); buildLogger
handler.go makeHandler: per-operation http.HandlerFunc (DELETE/GET/POST-PUT-PATCH)
server.go SandboxServer: Start (random port via net.Listen), Shutdown, Addr
*_test.go Unit tests for StateStore, strategies, generator; integration tests via httptest

cmd/sandbox.go

caseforge sandbox --spec api.yaml [--port N] [--host H] [--log-level info|warn|error|silent] [--log-file path] [--format auto|schema|faker]

Prints caseforge sandbox listening on http://127.0.0.1:<port> on startup; SIGINT/SIGTERM → graceful shutdown.

cmd/gen.go

--with-sandbox: starts sandbox in-process on a random port, injects --variable base_url=… into hurl runner, runs generated cases, returns non-zero exit if any test fails.

Test plan

  • go test -race ./... — 256 unit + integration tests pass, no data races
  • ./scripts/acceptance.sh — 256/256 pass, including:
    • AT-301: caseforge sandboxGET /pets returns 200
    • AT-302: full CRUD flow: POST→201, GET/{id}→200, DELETE/{id}→204
    • AT-303: gen --with-sandbox flag is registered

Out of scope (Phase 1)

  • Response schema strict validation
  • Multi-spec hot-reload, HTTPS/TLS, auth middleware, persistent state

yuchou87 added 18 commits May 8, 2026 20:52
Fix ResponseGenerator to guarantee a non-empty UUID id for write ops
when the schema strategy returns an empty string for the id field.
… in cleanup

runWithSandbox now returns a non-nil error when any test fails so CI exits
non-zero. resetGenGlobals in the e2e test helper now resets genWithSandbox.
AT-301: sandbox GET /pets returns 200
AT-302: full CRUD flow POST→GET/{id}→DELETE returns 201/200/204
AT-303: gen --with-sandbox flag is registered
- cmd/gen.go: fix BASE_URL → base_url to match hurl renderer's {{base_url}}
  placeholder; the mismatch caused --with-sandbox to send requests to an
  unresolved literal URL, making every run fail.
- scripts/acceptance.sh: promote AT-303 from --help grep to a real end-to-end
  gen+sandbox+hurl run using a success-only spec and --technique
  equivalence_partitioning so only happy-path cases are exercised.
  Add skip/random_port helpers; replace Linux-only shuf with portable $RANDOM.
…tion

caseforge run --target and caseforge conformance --target both injected
BASE_URL into hurl's --variable flag. Hurl is case-sensitive and its
renderer emits {{base_url}} (lowercase), so the variable was never
substituted and every request hit a literal unresolved URL.

- cmd/run.go: inject base_url for hurl runner, BASE_URL for k6 runner
- cmd/conformance.go: inject base_url (always uses hurl runner)
- Update help text to clarify the per-format convention
…ADME

- Add caseforge sandbox to Workflow commands table
- Add --with-sandbox to gen Command Reference flags
- Add caseforge sandbox Command Reference section with flags, startup
  message, stateful CRUD behaviour, and CI vs interactive guidance
…ails, CI tip

- Document auto strategy chain (example → schema → faker)
- Add sandbox vs gen --with-sandbox use-case guidance
- Document X-Sandbox-ID response header and LIST behaviour
- Add Ctrl-C / graceful shutdown note
- Add CI one-shot recipe: --technique equivalence_partitioning + success-only spec
@yuchou87 yuchou87 merged commit f9921ed into main May 9, 2026
1 check passed
@yuchou87 yuchou87 deleted the feat/sandbox-phase0 branch May 9, 2026 23: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.

1 participant