feat(workspace): real-stack avatar e2e, compose worker service, STORAGE.md contract

packages/supabase/tests/e2e/avatar-flow.e2e.ts (pnpm e2e:avatar through
scripts/avatar-e2e.sh: worker container on the Supabase network, 5 s sweep,
no quarantine grace; a fresh account per run): clean upload and owner-only
download (Bob, anon, quarantine key, direct final-key write refused),
replacement purged after the grace (queue clock shifted through psql), late
bytes through a still-valid signed upload URL swept, hostile and corrupted
uploads rejected with closed codes, removal with the purge queue drained.
Worker: the Storage API answers a missing object with HTTP 400 and
statusCode 404; normalised to 404 so a purge of a never-written key is acked.
docker-compose.yml: service worker under the worker profile (read-only,
cap_drop ALL, no-new-privileges, 512m, 1 cpu, 64 pids, .env.worker, external
Supabase network). docs/development/STORAGE.md: the implementation contract.
This commit is contained in:
bchanot committed 2026-10-13 19:39:51 +02:00
1 parent 0410af0c35
commit 0c6053c174
7 files changed
+798 -7

No files matched your search

+32 -6
View File
@@ -153,10 +153,12 @@ impl Backend for HttpBackend {
.header("Authorization", &format!("Bearer {}", self.key))
.call()
.map_err(network)?;
if response.status().as_u16() == 404 {
return Ok(());
// A missing object is a purge already done (HTTP 404, or this Storage API's
// HTTP 400 body with statusCode 404, normalised by `classify`).
match expect_success(&mut response) {
Err(BackendError::Status(404)) => Ok(()),
other => other,
}
expect_success(&mut response)
}
fn mark_quarantine_purged(&self, asset_id: &str) -> BackendResult<()> {
@@ -224,15 +226,24 @@ fn expect_success(response: &mut Response<ureq::Body>) -> BackendResult<()> {
Err(classify(status, &text))
}
/// A PostgREST `P0001` body names a closed refusal; any other status is reported as such.
/// A PostgREST `P0001` body names a closed refusal; a Storage API "not found" (HTTP 400
/// with `statusCode` 404 on this image family) is reported as 404; any other status as such.
pub fn classify(status: u16, body: &str) -> BackendError {
if let Ok(value) = serde_json::from_str::<Value>(body)
&& value.get("code").and_then(Value::as_str) == Some("P0001")
let Ok(value) = serde_json::from_str::<Value>(body) else {
return BackendError::Status(status);
};
if value.get("code").and_then(Value::as_str) == Some("P0001")
&& let Some(message) = value.get("message").and_then(Value::as_str)
&& is_closed_code(message)
{
return BackendError::Refused(message.to_owned());
}
if status == 400
&& (value.get("statusCode").and_then(Value::as_str) == Some("404")
|| value.get("error").and_then(Value::as_str) == Some("not_found"))
{
return BackendError::Status(404);
}
BackendError::Status(status)
}
@@ -265,6 +276,21 @@ mod tests {
BackendError::Status(400)
);
assert_eq!(classify(500, "not json"), BackendError::Status(500));
// storage-api v1.79 answers a missing object with HTTP 400 and statusCode "404".
assert_eq!(
classify(
400,
r#"{"statusCode":"404","error":"not_found","message":"Object not found"}"#
),
BackendError::Status(404)
);
assert_eq!(
classify(
400,
r#"{"statusCode":"400","error":"InvalidRequest","message":"x"}"#
),
BackendError::Status(400)
);
}
#[test]