test(v1.1.9): fix invoke_e2e + retry_e2e — admin bypass + rhai shape

Running the E2E suites against real Postgres surfaced three shape bugs
in the test scripts that caused false failures:

invoke_e2e:
- invoke_cross_app_rejects used two TestServer instances (one per app),
  but the second server's Owner admin isn't a member of the first
  server's app. Replaced with a single server that creates both apps
  via the same Owner admin (which has implicit access to every app).
- invoke_depth_limit_exceeds_cleanly: the recurser script had its own
  try/catch, so when the depth limit fired inside the deepest call the
  caught error became the BODY of a 200 response (which invoke()
  returns to the caller). The outer caller's try/catch never saw a
  throw → assertion failed. Rewrote so the recurser propagates throws
  (no inner try-catch); the outer caller's try-catch surfaces the
  depth error all the way up.

retry_e2e:
- All three tests used HTTP routes which need a domain claim the test
  apps don't have (`no app claims host ""` 404s). Switched to the
  admin bypass POST /api/v1/execute/{id} — same pattern dispatcher_e2e
  uses. Sidesteps the per-app domain matcher entirely.
- retry_run_surfaces_last_error_after_max_attempts: try-catch is a
  statement in Rhai, not an expression, so the block didn't evaluate
  to the catch arm's map. Refactored to bind to `let out` inside the
  catch arm, then return `#{ statusCode: 200, body: out }` as the
  final expression.

All 11 v1.1.9 E2E tests now pass against Postgres:
  queue_e2e: 4 passed (33s — exercises retry + dead-letter)
  invoke_e2e: 4 passed (2s)
  retry_e2e: 3 passed (2.5s)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-06-07 10:54:52 +02:00
parent 106394bef2
commit c38c46b8bc
2 changed files with 95 additions and 101 deletions

View File

@@ -1,7 +1,8 @@
//! v1.1.9 retry::* end-to-end test against a real engine inside the
//! all-in-one binary. Smaller surface than queue/invoke (no async
//! plumbing) — covers policy clamping, success-on-Nth-attempt, and
//! on_codes filtering through a real HTTP route.
//! on_codes filtering through the admin bypass POST /api/v1/execute/{id}
//! (sidesteps the per-app domain matcher).
//!
//! Skips when DATABASE_URL is unset.
@@ -72,30 +73,22 @@ async fn server_for(pool: PgPool, suffix: &str) -> (TestServer, String) {
(server, app_id)
}
async fn create_route_for(
server: &TestServer,
app_id: &str,
name: &str,
source: &str,
path: &str,
) {
async fn create_script(server: &TestServer, app_id: &str, name: &str, source: &str) -> String {
let created: Value = server
.post("/api/v1/admin/scripts")
.json(&json!({ "app_id": app_id, "name": name, "source": source }))
.await
.json();
let script_id = created["id"].as_str().expect("script id");
let resp = server
.post(&format!("/api/v1/admin/apps/{app_id}/routes"))
.json(&json!({
"script_id": script_id,
"method": "GET",
"path": path,
"host": null,
"dispatch_mode": "sync"
}))
.await;
resp.assert_status(axum::http::StatusCode::CREATED);
created["id"].as_str().expect("script id").to_string()
}
/// Execute via the admin bypass (same pattern as dispatcher_e2e).
async fn execute(server: &TestServer, script_id: &str) -> Value {
server
.post(&format!("/api/v1/execute/{script_id}"))
.json(&json!({}))
.await
.json()
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -114,11 +107,8 @@ async fn retry_run_eventually_succeeds_inside_http_handler() {
});
#{ statusCode: 200, body: v }
"#;
create_route_for(&server, &app_id, "succ", src, "/r/succ").await;
let resp = server.get("/r/succ").await;
resp.assert_status_ok();
let body: Value = resp.json();
let script_id = create_script(&server, &app_id, "succ", src).await;
let body = execute(&server, &script_id).await;
assert_eq!(body, json!(3));
}
@@ -129,18 +119,16 @@ async fn retry_run_surfaces_last_error_after_max_attempts() {
let src = r#"
let p = retry::policy(#{ max_attempts: 2, base_ms: 1, jitter_pct: 0 });
let out = "did not throw";
try {
retry::run(p, || { throw "boom" });
#{ statusCode: 200, body: "did not throw" }
} catch(e) {
#{ statusCode: 200, body: e }
out = e;
}
#{ statusCode: 200, body: out }
"#;
create_route_for(&server, &app_id, "surf", src, "/r/surf").await;
let resp = server.get("/r/surf").await;
resp.assert_status_ok();
let body: Value = resp.json();
let script_id = create_script(&server, &app_id, "surf", src).await;
let body = execute(&server, &script_id).await;
let s = body.as_str().unwrap_or_default();
assert!(s.contains("boom"), "expected 'boom' in error, got: {s}");
}
@@ -166,10 +154,7 @@ async fn retry_on_codes_filters_unmatched_errors() {
}
#{ statusCode: 200, body: attempts }
"#;
create_route_for(&server, &app_id, "codes", src, "/r/codes").await;
let resp = server.get("/r/codes").await;
resp.assert_status_ok();
let body: Value = resp.json();
let script_id = create_script(&server, &app_id, "codes", src).await;
let body = execute(&server, &script_id).await;
assert_eq!(body, json!(1), "non-matching error should surface immediately");
}