Skip to content

Commit ae94cc4

Browse files
committed
test(traces): prove the ref budget answers 413 at the endpoint
MTR-13. Capacity was only asserted at the unit level, by calling `code_refs` directly. The budget is actually reached through the advertisement, so the endpoint is what has to be measured. The new case seeds a legacy traces ref plus 4098 branch refs (bulk SQL, because that many pushes would dominate the suite), requests `/third-party/mtr94-control.git/info/refs?service=git-upload-pack`, and requires **413**. Measured: `FIX13_ENDPOINT_413 status=413 Payload Too Large`. Three of my own errors were fixed getting here: the case had no `#[tokio::test]` wrapper so it silently did not run, my first INSERT used a non-existent `ref_tree_hash` column, and the second used `'Branch'` for an enum that stores `branch`. Verified: `code_clone_ref_budget_answers_413` passes (96.81s). Still open: the ref-race rejection control, an AC-8 oracle that can distinguish a traces-only object, and the full algorithm x transport x protocol x mode matrix. Signed-off-by: Eli Ma <eli@patch.sh>
1 parent 34874d3 commit ae94cc4

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

‎tests/integration_traces.rs‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5753,6 +5753,60 @@ mod disabled_http {
57535753
}
57545754
}
57555755

5756+
/// Capacity at the endpoint: a legacy view over its ref budget must answer 413
5757+
/// on the advertisement, not serve a truncated ref list. The budget lives in
5758+
/// `code_refs`, which the advertisement reaches before any pack is built.
5759+
pub async fn code_clone_ref_budget_answers_413() {
5760+
let (guard, db) = traces_db::TracesDb::migrated().await;
5761+
let mut fixture = Fixture::new(&db).await;
5762+
let result = AssertUnwindSafe(async {
5763+
fixture.prepare(&db).await;
5764+
// A legacy traces ref makes the budget apply at all; without it the code
5765+
// view is returned directly and an over-budget repo still serves.
5766+
let mut rows = vec![("refs/libra/traces".to_owned(), "b".repeat(40))];
5767+
for index in 0..4098 {
5768+
rows.push((format!("refs/heads/bulk{index}"), "a".repeat(40)));
5769+
}
5770+
for (index, (name, oid)) in rows.into_iter().enumerate() {
5771+
scalar(
5772+
&db,
5773+
&format!(
5774+
"INSERT INTO import_refs (id, repo_id, ref_name, ref_git_id, ref_type, default_branch, created_at, updated_at) \
5775+
SELECT (SELECT COALESCE(MAX(id), 0) + 1 + {index} FROM import_refs), repo_id, '{name}', '{oid}', 'branch', false, now(), now() \
5776+
FROM import_refs WHERE ref_name = 'refs/heads/main' LIMIT 1 RETURNING ref_name AS value"
5777+
),
5778+
)
5779+
.await;
5780+
}
5781+
let advertisement = reqwest::Client::new()
5782+
.get(git_cli::mega2_host_http_url(
5783+
fixture.port,
5784+
"/third-party/mtr94-control.git/info/refs?service=git-upload-pack",
5785+
))
5786+
.send()
5787+
.await
5788+
.expect("advertisement request");
5789+
let status = advertisement.status();
5790+
eprintln!("FIX13_ENDPOINT_413 status={status}");
5791+
assert_eq!(
5792+
status.as_u16(),
5793+
413,
5794+
"an over-budget legacy view must answer 413"
5795+
);
5796+
})
5797+
.catch_unwind()
5798+
.await;
5799+
fixture.stop();
5800+
let closed = db.close().await;
5801+
drop(guard);
5802+
if let Err(panic) = result {
5803+
let logs = fixture.temp.keep();
5804+
eprintln!("ref-budget fixture logs: {}", logs.display());
5805+
std::panic::resume_unwind(panic);
5806+
}
5807+
closed.expect("close ref-budget pool");
5808+
}
5809+
57565810
/// AC-7/AC-8 at the code-path view across the fetch modes the card names.
57575811
///
57585812
/// Every arm clones the same seeded code path and must (a) contain no
@@ -7835,6 +7889,11 @@ async fn code_clone_isolation_code_path_objects() {
78357889
disabled_http::code_clone_isolation_code_path_objects().await;
78367890
}
78377891

7892+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
7893+
async fn code_clone_ref_budget_answers_413() {
7894+
disabled_http::code_clone_ref_budget_answers_413().await;
7895+
}
7896+
78387897
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
78397898
async fn traces_disabled_http_discovery() {
78407899
disabled_http::run(disabled_http::Endpoint::Discovery).await;

0 commit comments

Comments
 (0)