Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions crates/twigpine-node/src/api/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3247,9 +3247,12 @@ mod tests {
.to_string()
}

/// Walk-counting shim that runs the REAL walk (`state.git_bin`): each `rev-list`
/// appends one line to `log`, then every invocation execs the real `git`, so the
/// allowed-set a walk produces is the repo's genuine one.
/// Walk-counting shim that runs the REAL walk (`state.git_bin`): each `log` (the
/// withheld walk's `git log --all --raw`) appends one line to `log`, then every
/// invocation execs the real `git`, so the allowed-set a walk produces is the
/// repo's genuine one. The `rev-list` arm stays for the commit/tag reachability
/// walk, which still enumerates with `git rev-list --all`; a walk is one or the
/// other, never both, so the tally stays one line per walk.
///
/// `walk_logging_fake_git` below answers every subcommand with nothing, so under it
/// EVERY walked repo yields an empty allowed set and no repo can ever authorize. The
Expand All @@ -3261,8 +3264,10 @@ mod tests {
"#!/bin/sh\n\
case \"$1\" in\n\
rev-list) echo walk >> \"{}\" ;;\n\
log) echo walk >> \"{}\" ;;\n\
esac\n\
exec git \"$@\"\n",
log.display(),
log.display()
);
let git_path = dir.join("walkgit");
Expand All @@ -3285,9 +3290,11 @@ mod tests {
}

/// Fake git for the WALK only (`state.git_bin`): empty refs, `rev-parse`
/// resolves, and each `rev-list` appends one line to `log` and prints nothing —
/// every walked repo yields an EMPTY allowed-set (path-gate deny verdict) and
/// the log's line count == the number of expensive walks run. The probe and the
/// resolves, and each `log` (the withheld walk's `git log --all --raw`) appends
/// one line to `log` and prints nothing — every walked repo yields an EMPTY
/// allowed-set (path-gate deny verdict) and the log's line count == the number of
/// expensive walks run. The `rev-list` arm stays for the commit/tag reachability
/// walk, which still enumerates with `git rev-list --all`. The probe and the
/// content read shell to the real `git`, so seeded objects must genuinely exist.
#[cfg(unix)]
fn walk_logging_fake_git(dir: &std::path::Path, log: &std::path::Path) -> String {
Expand All @@ -3297,9 +3304,11 @@ mod tests {
for-each-ref) : ;;\n\
rev-parse) echo deadbeef ;;\n\
rev-list) echo walk >> \"{}\" ;;\n\
log) echo walk >> \"{}\" ;;\n\
*) : ;;\n\
esac\n\
exit 0\n",
log.display(),
log.display()
);
let git_path = dir.join("fakegit");
Expand Down Expand Up @@ -8447,16 +8456,17 @@ mod tests {
let tmp = tempfile::TempDir::new().unwrap();
let walk_log = tmp.path().join("walks.log");
let revlist_pid = tmp.path().join("revlist.pid");
// Fake git for the WALK only: `rev-list` records its pid and a start
// marker, sleeps far past the budget, then records a done marker. Under
// the clamped walk deadline the whole process group is torn down mid
// sleep, so "done" never appears. The 8s sleep also bounds a RED run.
// Fake git for the WALK only: the walk's `git log --all --raw` records its
// pid and a start marker, sleeps far past the budget, then records a done
// marker. Under the clamped walk deadline the whole process group is torn
// down mid sleep, so "done" never appears. The 8s sleep also bounds a RED run.
let body = format!(
"#!/bin/sh\n\
case \"$1\" in\n\
for-each-ref) : ;;\n\
rev-parse) echo deadbeef ;;\n\
rev-list) echo $$ > \"{pid}\"; echo start >> \"{log}\"; sleep 8; echo done >> \"{log}\" ;;\n\
log) echo $$ > \"{pid}\"; echo start >> \"{log}\"; sleep 8; echo done >> \"{log}\" ;;\n\
*) : ;;\n\
esac\n\
exit 0\n",
Expand Down Expand Up @@ -8514,7 +8524,7 @@ mod tests {
let peer: SocketAddr = "203.0.113.71:5000".parse().unwrap();
let mut fut = Box::pin(router.oneshot(get_cid(&cid, Some(peer))));

// Drive until the fake git's rev-list records its pid: the walk is now in
// Drive until the fake git's log records its pid: the walk is now in
// the blocking pool and the request future is `.await`ing its join. Stop
// polling the instant the future completes (re-polling would panic).
let mut walk_pid: Option<i32> = None;
Expand Down Expand Up @@ -8880,14 +8890,15 @@ mod tests {
drop(held);
}

/// Build the shared `/ipfs` TREE-walk fixture. A fake `git` whose `rev-list` records
/// its pid then sleeps ~6s (so the tree walk blocks deterministically inside
/// Build the shared `/ipfs` TREE-walk fixture. A fake `git` whose `log` (the
/// tree walk's `git log --all --raw`) records its pid then sleeps ~6s (so the
/// tree walk blocks deterministically inside
/// `run_bounded_git`) and whose `cat-file -t` answers "tree" (so the bounded
/// object-type probe, `object_type_bounded` on `state.git_bin`, routes into the
/// tree-gate arm); a real SHA-256 bare repo with a committed `src/` tree pinned WITH
/// provenance; and a path-scoped rule so the gate takes the tree-walk branch. Returns
/// the tempdir (keep it alive for the whole test), the state (the caller sets the walk
/// semaphores), the requested CID, and the rev-list pidfile path.
/// semaphores), the requested CID, and the pidfile path.
#[cfg(unix)]
async fn seed_tree_walk_fixture(
pool: sqlx::PgPool,
Expand All @@ -8908,9 +8919,11 @@ mod tests {
rev-parse) echo deadbeef ;;\n\
cat-file) if [ \"$2\" = \"-t\" ]; then echo tree; fi ;;\n\
rev-list) echo $$ > \"{}\"; sleep 6 ;;\n\
log) echo $$ > \"{}\"; sleep 6 ;;\n\
*) : ;;\n\
esac\n\
exit 0\n",
revlist_pid.display(),
revlist_pid.display()
);
let git_path = tmp.path().join("fakegit");
Expand Down Expand Up @@ -9028,7 +9041,7 @@ mod tests {
/// `allowed_tree_set_for_caller_bounded` — the walk this integration converts to
/// `run_bounded_git` — rather than the blob walk #174 already proved. With the
/// global pool at size 1, drive a request until its walk (a fake git that hangs on
/// `rev-list`) is in flight; the slot must stay held (`available_permits() == 0`)
/// `log`) is in flight; the slot must stay held (`available_permits() == 0`)
/// and a replacement from a DIFFERENT source must shed 503 for as long as the
/// blocking walk runs — even though the request future is only `.await`ing the
/// blocking join. When the blocking walk ends the permit frees and a replacement
Expand Down Expand Up @@ -9066,7 +9079,7 @@ mod tests {

let peer: SocketAddr = "203.0.113.81:5000".parse().unwrap();
let mut fut = Box::pin(router.clone().oneshot(make_req(peer)));
// Drive until the fake git's rev-list records its pid — the TREE walk is now in
// Drive until the fake git's log records its pid — the TREE walk is now in
// the blocking pool and the request future is `.await`ing its join, holding the
// walk permit. Stop polling the instant the future completes (re-polling a
// completed oneshot panics).
Expand All @@ -9087,7 +9100,7 @@ mod tests {
}
}
let pid = walk_pid
.unwrap_or_else(|| panic!("the fake git rev-list must have spawned; early: {early:?}"));
.unwrap_or_else(|| panic!("the fake git log must have spawned; early: {early:?}"));
// Reap the sleeping child on drop so a RED run leaks no orphan.
struct ReapOnDrop(i32);
impl Drop for ReapOnDrop {
Expand Down Expand Up @@ -9213,7 +9226,7 @@ mod tests {
break;
}
}
let pid = walk_pid.expect("the fake git rev-list must have spawned");
let pid = walk_pid.expect("the fake git log must have spawned");
struct ReapOnDrop(i32);
impl Drop for ReapOnDrop {
fn drop(&mut self) {
Expand Down Expand Up @@ -9272,7 +9285,7 @@ mod tests {
/// the object absent. With `ipfs_max_repos_walked = 1` and TWO public, path-scoped
/// repos both carrying the blob, the first candidate is walked (empty allowed-set →
/// a deny VERDICT) and the second is cut by the cap (no verdict), so the fake git's
/// `rev-list` runs exactly once and the request sheds a retryable 503 + Retry-After
/// `log` runs exactly once and the request sheds a retryable 503 + Retry-After
/// — never the old false 404 (the blob genuinely sits in the second repo).
/// This drives the TWIGPINE_IPFS_MAX_REPOS_WALKED knob specifically. The merge left
/// two walk caps in play, this one and the branch's own history-walk ceiling, and
Expand All @@ -9289,8 +9302,9 @@ mod tests {

let tmp = tempfile::TempDir::new().unwrap();
let walk_log = tmp.path().join("walks.log");
// Fake git for the WALK: empty refs, `rev-parse` resolves, and each `rev-list`
// appends one line to a log (so the number of walks == the line count) and exits
// Fake git for the WALK: empty refs, `rev-parse` resolves, and each `log`
// (the withheld walk's `git log --all --raw`) appends one line to a log (so
// the number of walks == the line count) and exits
// with EMPTY output (the allowed-set is empty, so every repo path-gates to a
// `continue` and the request 404s after walking). object_type uses the REAL git,
// so the seeded blob below must genuinely exist.
Expand All @@ -9300,9 +9314,11 @@ mod tests {
for-each-ref) : ;;\n\
rev-parse) echo deadbeef ;;\n\
rev-list) echo walk >> \"{}\" ;;\n\
log) echo walk >> \"{}\" ;;\n\
*) : ;;\n\
esac\n\
exit 0\n",
walk_log.display(),
walk_log.display()
);
let git_path = tmp.path().join("fakegit");
Expand Down Expand Up @@ -9864,8 +9880,9 @@ mod tests {
/// in an admitted visibility walk is PROGRESSING, and shedding it would convert a
/// slow-but-correct retrieval into a 503 on a box that is merely loaded.
///
/// The resolve budget is 1s while the walk sleeps ~2s per `rev-list`, so any
/// deadline that reaches past `oids_for_cid` ends this request before it can serve.
/// The resolve budget is 1s while the walk sleeps ~2s on its `git log --all --raw`,
/// so any deadline that reaches past `oids_for_cid` ends this request before it
/// can serve.
/// The shim execs the REAL git after sleeping, so the allowed-set the walk produces
/// is the repo's genuine one and the 200 is a real serve, not an artifact.
///
Expand Down Expand Up @@ -9911,6 +9928,7 @@ mod tests {
"#!/bin/sh\n\
case \"$1\" in\n\
rev-list) sleep 2 ;;\n\
log) sleep 2 ;;\n\
esac\n\
exec git \"$@\"\n",
)
Expand Down
Loading
Loading