Skip to content

harness(phase-0): sudo-free Host-header path + chat_history + envelope replays - #2492

Merged
HongmingWang-Rabbit merged 1 commit into
stagingfrom
harness/phase-0-sudo-free-plus-replays
May 2, 2026
Merged

HongmingWang-Rabbit merged 1 commit into
stagingfrom
harness/phase-0-sudo-free-plus-replays

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Summary

Phase 0 of the long-term harness roadmap — three changes that bring the local harness from "covers what staging covers minus the SaaS topology" to "exercises every surface we shipped this session against the prod-shape `Dockerfile.tenant` image."

1. Drop the `/etc/hosts` requirement

Replays previously needed `127.0.0.1 harness-tenant.localhost` in `/etc/hosts` to resolve the cf-proxy. That gated the harness behind a sudo step on every fresh dev box and CI runner. cf-proxy nginx already routes by Host header (matches production CF tunnel), so the no-sudo path is to target loopback `:8080` with `Host: harness-tenant.localhost` set as a header.

New `tests/harness/_curl.sh` centralises this — `curl_anon`, `curl_admin`, `curl_workspace`, and `psql_exec` wrappers all set the right Host + auth headers automatically. `seed.sh`, `peer-discovery-404.sh`, `buildinfo-stale-image.sh` updated to source it. Legacy `/etc/hosts` users still work via env-var override.

2. Fix the `seed.sh` FK regression that blocked DB-side replays

`POST /workspaces` ignores any `id` in the request body and generates one server-side. `seed.sh` was minting client-side UUIDs that never reached the workspaces table, so any replay that INSERTed into `activity_logs` (FK-constrained on `workspace_id`) failed with `workspace not found`. Capture the returned id from the response instead.

3. Two new replays cover the surfaces shipped this session

`replays/chat-history.sh` — exercises the full SaaS-shape wire that PR #2472 (peer_id filter), #2474 (chat_history client tool), and #2476 (before_ts paging) ride on. 8 phases / 16 assertions:

  • Basic peer_id filter (DESC ordering, oldest/newest)
  • Limit clamp
  • before_ts paging (strict less-than, cursor walk-back)
  • OR clause covering both source_id and target_id
  • Malformed peer_id → 400
  • Malformed before_ts → 400 + RFC3339 example
  • URL-encoded SQLi-shape peer_id → 400 (UUID validation rejects pre-SQL)

`replays/channel-envelope-trust-boundary.sh` — exercises PR #2471 + #2481 by importing from `molecule_runtime.*` (the wheel-rewritten path) so it catches "wheel build dropped a fix that unit tests still pass." 5 phases / 11 assertions:

  • Malicious peer_id scrubbed from envelope
  • `agent_card_url` omitted on validation failure
  • XML-injection bytes scrubbed
  • Valid UUID preserved + URL builds canonically
  • `_agent_card_url_for` direct gate

`run-all-replays.sh` auto-discovers `replays/*.sh` — no registration needed.

Verification

```
$ ./run-all-replays.sh
[run-all] booting harness...
[run-all] seeding workspaces...
[run-all] ━━━ buildinfo-stale-image ━━━ PASS
[run-all] ━━━ channel-envelope-trust-boundary ━━━ PASS (11/11 against wheel 0.1.79)
[run-all] ━━━ chat-history ━━━ PASS (16/16)
[run-all] ━━━ peer-discovery-404 ━━━ PASS
[run-all] Replay summary: 4 passed, 0 failed (of 4 total)
```

Test plan

  • `./up.sh` works without /etc/hosts edit
  • `./seed.sh` writes UUIDs that match the workspaces table
  • `./run-all-replays.sh` 4/4 PASS end-to-end
  • Legacy /etc/hosts users still work via env-var override
  • CI on this branch
  • Roadmap follow-ups: Phase 2 (multi-tenant + CI gate), Phase 3 (real CP), Phase 4 (Miniflare + LocalStack)

🤖 Generated with Claude Code

…e replays

Three changes that bring the local harness from "covers what staging
covers minus the SaaS topology" to "exercises every surface we shipped
this session against the prod-shape Dockerfile.tenant image."

1. Drop the /etc/hosts requirement.

   Replays previously needed `127.0.0.1 harness-tenant.localhost` in
   /etc/hosts to resolve the cf-proxy. That gated the harness behind a
   sudo step on every fresh dev box and CI runner. The cf-proxy nginx
   already routes by Host header (matches production CF tunnel: URL is
   public, Host carries tenant identity), so the no-sudo path is to
   target loopback :8080 with `Host: harness-tenant.localhost` set as
   a header.

   New `tests/harness/_curl.sh` centralises this — curl_anon /
   curl_admin / curl_workspace / psql_exec wrappers all set the Host
   + auth headers automatically. seed.sh, peer-discovery-404.sh,
   buildinfo-stale-image.sh updated to source it. Legacy /etc/hosts
   users still work via env-var override.

2. Fix the seed.sh FK regression that blocked DB-side replays.

   POST /workspaces ignores any `id` in the request body and generates
   one server-side. seed.sh was minting client-side UUIDs that never
   reached the workspaces table, so any replay that INSERTed into
   activity_logs (FK-constrained on workspace_id) failed with the
   workspace-not-found error. Capture the returned id from the
   response instead.

3. Two new replays cover the surfaces shipped this session.

   chat-history.sh — exercises the full SaaS-shape wire that PR #2472
   (peer_id filter), #2474 (chat_history client tool), and #2476
   (before_ts paging) ride on. 8 phases / 16 assertions: peer_id filter,
   limit cap, before_ts paging, OR-clause covering both source_id and
   target_id, malformed peer_id 400, malformed before_ts 400, URL-encoded
   SQLi-shape rejection. Verified PASS against the live harness.

   channel-envelope-trust-boundary.sh — exercises PR #2471 + #2481 by
   importing from `molecule_runtime.*` (the wheel-rewritten path) so
   it catches "wheel build dropped a fix that unit tests still pass."
   5 phases / 11 assertions: malicious peer_id scrubbed from envelope,
   agent_card_url omitted on validation failure, XML-injection bytes
   scrubbed, valid UUID preserved, _agent_card_url_for direct gate.
   Verified PASS against published wheel 0.1.79.

run-all-replays.sh auto-discovers — no registration needed. Full
lifecycle (boot → seed → 4 replays → teardown) runs clean.

Roadmap section updated to reflect Phase 1 (this PR) → Phase 2
(multi-tenant + CI gate) → Phase 3 (real CP) → Phase 4 (Miniflare +
LocalStack + traffic replay).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@HongmingWang-Rabbit
HongmingWang-Rabbit added this pull request to the merge queue May 2, 2026
Merged via the queue into staging with commit 56a5427 May 2, 2026
21 of 22 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the harness/phase-0-sudo-free-plus-replays branch May 2, 2026 03:22
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