Skip to content

Commit 618e7e9

Browse files
author
ikeboy003
committed
pingdotgg#469: prove the thread-snapshot route is SERVED, not merely present in source
The route and handler are on main already — I restored both in a077b2e as pingdotgg#436, since the abandoned clau-031c-ui merge had taken them out by resolving server_main.rs to theirs wholesale. This adds the assertion that was missing. A route existing in source is not the same as the router serving it. A path registered under the wrong prefix, or shadowed by the capture_http fallback, greps identically to a working one — and the original symptom was precisely a fallthrough: WARN http: no route -> 404 GET /api/orchestration/threads/29e30a3f-... on the REAL thread id, so promotion never completed and the view stayed on /draft/<id> while the turn ran to completion somewhere it was not looking. So the test binds the REAL router with `build_app` and speaks HTTP to it over a socket, which is the only form that can tell a served route from a registered one. Raw TCP rather than a client crate: no new dependency for one GET. It asserts NOT-404, not 200. With no such thread the honest answer is a failure body from the handler — demanding 200 would push it to invent a snapshot for a thread that does not exist, which is what its own "the DURABLE record is the authority" comment refuses to do. Falsified on woodbine: with the `.route("/api/orchestration/threads/{thread_id}", ...)` line deleted the test FAILS; restored, it passes. It discriminates.
1 parent b78b109 commit 618e7e9

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

‎backend/src/contract_tests.rs‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,65 @@ async fn unimplemented_server_rpcs_refuse_explicitly_instead_of_faking_success()
12481248
);
12491249
}
12501250

1251+
/// #469/#436: `GET /api/orchestration/threads/:threadId` must ANSWER, not 404.
1252+
///
1253+
/// The contract defines it (contracts/src/environmentHttp.ts:516) and the client
1254+
/// calls it (client-runtime/src/state/threadSnapshotHttp.ts:50) the moment a
1255+
/// draft becomes a real thread. When the route was absent it fell through to the
1256+
/// capture_http fallback and 404'd ON THE REAL THREAD ID, so promotion never
1257+
/// completed and the view stayed on /draft/<id> while the turn ran to completion
1258+
/// somewhere it was not looking.
1259+
///
1260+
/// The route existing in source is not the same as the router serving it — a
1261+
/// path registered under the wrong prefix, or shadowed by the fallback, reads
1262+
/// identically in a grep. So this binds the REAL router with `build_app` and
1263+
/// speaks HTTP to it over a socket, which is the only form that can tell those
1264+
/// apart.
1265+
///
1266+
/// It asserts NOT-404 rather than 200: with no such thread the honest answer is
1267+
/// a failure body from the handler, and demanding 200 here would force the
1268+
/// handler to invent a snapshot for a thread that does not exist — which is
1269+
/// exactly what its "the DURABLE record is the authority" comment refuses to do.
1270+
#[tokio::test]
1271+
async fn the_thread_snapshot_route_is_served_and_does_not_fall_through_to_404() {
1272+
use tokio::io::{AsyncReadExt, AsyncWriteExt};
1273+
1274+
let (state, _d) = test_state().await;
1275+
let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
1276+
.await
1277+
.expect("bind an ephemeral port");
1278+
let addr = listener.local_addr().expect("local addr");
1279+
let app = crate::build_app(state);
1280+
let server = tokio::spawn(async move {
1281+
let _ = axum::serve(listener, app).await;
1282+
});
1283+
1284+
let mut sock = tokio::net::TcpStream::connect(addr).await.expect("connect");
1285+
sock.write_all(
1286+
b"GET /api/orchestration/threads/t-snapshot HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n",
1287+
)
1288+
.await
1289+
.expect("send the request");
1290+
1291+
let mut raw = Vec::new();
1292+
let _ = tokio::time::timeout(
1293+
std::time::Duration::from_secs(20),
1294+
sock.read_to_end(&mut raw),
1295+
)
1296+
.await
1297+
.expect("the server answered within 20s");
1298+
server.abort();
1299+
1300+
let response = String::from_utf8_lossy(&raw);
1301+
let status = response.lines().next().unwrap_or("").to_string();
1302+
assert!(
1303+
!status.contains("404"),
1304+
"#469: the router 404'd on GET /api/orchestration/threads/:threadId, so it is not \
1305+
served — the client's promotion fetch falls through to capture_http exactly as it did \
1306+
when the route was missing. Status line: {status:?}"
1307+
);
1308+
}
1309+
12511310
/// #462: DUPLICATE DECIDER AUTHORITY, made red instead of merely known.
12521311
///
12531312
/// There are two deciders for one command set.

0 commit comments

Comments
 (0)