Skip to content

Add context-aware connection tests, spec events, and workbench env config - #815

Merged
flarco merged 1 commit into
v1.6.4from
flarco/sling-workbench
Sep 23, 2026
Merged

flarco merged 1 commit into
v1.6.4from
flarco/sling-workbench

Conversation

@flarco

@flarco flarco commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

sling conns test can only be configured through process-wide SLING_TEST_* env vars, and spec test events go to a package-global channel (api.SpecEventChn). Two tests running at once share one channel, a test cannot be cancelled, and a server (the workbench) has no way to pass per-run options, receive structured events, or stop a run. There is also no way to test a connection against an edited spec without saving it, and no place in env.yaml to configure sling serve workbench.

Solution

ELI5: instead of settings shouted through global env vars and one global megaphone, every test run now carries its own settings and its own private callback, handed over through the context. Runs can overlap, each can be stopped, and each reports its own progress. A run can also point at a draft spec just for that run, and env.yaml can hold workbench settings.

Details:

  • api.SpecEvent and typed event constants (endpoint-start, request-complete, records, endpoint-done, error) replace the map[string]any global channel. WithSpecEventHandler/fireSpecEvent carry the handler on the request context, so events are per-run and cancellation propagates. Legacy JSON fields (req_id, timestamp, iter_id, iter_sequence, size_bytes, record_count) are kept for released spec inspectors.
  • request-complete events now include request_index, state_before and state_after (iteration state read under iter.context), plus each request's records.
  • Connection.TestWithOptions(ctx, TestOptions) and ConnEntries.TestWithOptions(ctx, name, opts) add endpoints, limit, max requests, context, spec file, trace and OnEvent. Test() keeps its signature and builds its options from SLING_TEST_*, so the CLI is unchanged.
  • TestOptions.SpecFile overlays a spec on a copy of the connection entry for one run; the original entries stay untouched.
  • A cancelled test returns context.Canceled instead of success, and stops before the next endpoint.
  • env.yaml gains a managed workbench: block (WorkbenchConfig: host, port, token, projects_root, shell, worker_idle, path_extra, env); command-line flags win over the file.
  • The goreleaser mac formula installs a launchd service running sling serve workbench --no-browser.

Testing

  • core/dbio/connection/connection_test.go: event sequence and payloads (request index, state before/after, legacy wire fields), error event, env-driven test, spec-file overlay, and cancellation via context.
  • tests/suite.cli.yaml cases 620 and 621: workbench --help output, plus a smoke test that starts the server on a free port, checks /healthz returns ok, and stops it.

- Replace the global SpecEventChn with a typed SpecEvent sent through the
  request context, so each spec test run is isolated, cancellable, and reports
  the request index plus iteration state before and after each request. Legacy
  wire fields stay for released spec inspectors.
- Add Connection.TestWithOptions and ConnEntries.TestWithOptions (endpoints,
  limit, max requests, context, trace, OnEvent) plus a spec-file overlay that
  tests a draft spec without mutating the connection entry. Test() still reads
  the SLING_TEST_* env vars, so the CLI is unchanged.
- Emit error events and return context.Canceled promptly on cancellation
  instead of reporting success.
- Add the workbench block to env.yaml, run `sling serve workbench
  --no-browser` as a brew service, and cover the command with CLI smoke tests.
@flarco
flarco merged commit 242cff1 into v1.6.4 Sep 23, 2026
1 check passed
@flarco
flarco deleted the flarco/sling-workbench branch September 29, 2026 21:03
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