mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
## Why
User deletion must remove uploads by the user and their owned agents
while preserving files uploaded by anyone else. Attribution can span
communities and survive only in storage, so cleanup must combine
database and storage evidence.
## What
Add one media handler used by both the direct `user-deletions
media-batches` command and the persisted user-deletion workflow. Preview
is read-only by default; deletion requires `--delete`.
The workflow now always runs `gate_user` → `purge_media` → community
stages. The gate and community handlers remain placeholders. Media
failure stays on the same stage for retry; a saved completed media stage
is not executed again on restart.
## How
- Resolve the human and directly owned agents once across communities.
Sharing within that target set does not protect a file.
- Combine candidate discovery from `media_uploaders` and upload audit
history with a sharing check for those hashes. Check outside uploaders
across all communities. Storage-only candidates receive the same
database check in batches.
- Add four nonunique indexes for uploader and hash lookups. Current
membership cannot safely filter historical discovery: departed members
may have no remaining membership row.
- Scan `_uploads/` for candidates, then candidate claims for outside
ownership. List blob and thumbnail versions by each selected `{hash}.`
prefix. A separate `_meta/` listing preserves sidecar coverage when no
matching claim or current membership remains. There is no whole-bucket
listing.
- Finish all discovery before deletion. Read historical claims using
exact `versionId` values. Delete exclusive file versions and markers,
with upload-attribution objects last. Remove target uploader rows after
storage processing succeeds. Shared storage versions and outside
uploader rows remain.
- Stream one JSON document with file identity, keep/delete status,
versions, and outcome counts. Remove per-file owner queries and owner
arrays. Workflow stdout remains inspection JSON; media reporting goes to
stderr.
Database/inventory pages hold at most 500 rows. Storage listings use at
most 1,000 entries per page and 100,000 pages per listing. A disposable
in-memory inventory has a 128 MiB accounting budget and a 250,000-entry
cap, including candidates, filenames, versions, and listing markers.
Accounting includes string bytes, inline data, and a conservative
allowance for tree/allocator overhead; it is not a process RSS limit.
This removes the SQLite dependency without a security-policy exception.
Large jobs may reach capacity sooner than with the former 1 GiB disk
inventory. Exceeding a discovery limit aborts before mutation; no
truncated inventory is used for deletion.
Migration 0092 and the desired schema add the same indexes. The
migration builds missing indexes under short lock/statement budgets and
verifies existing definitions. Large deployments can prebuild
concurrently using the procedure in [the executor
guide](docs/operator-user-deletion-executor.md). Existing relay writes
remain compatible. A stale workflow test call from the merged main
branch also receives its required run-cause argument.
## Risk
This performs real storage deletion. Writers must remain stopped; the
placeholder gate does not prevent uploads. Immutable version IDs are
required for exclusive objects. All results report
`account_erasure_complete: false`. Existing synthetic progress saved
under the older gate-to-community sequence is not migrated into the new
sequence.
Shared storage claims and audit history remain. They can continue
protecting a blob after both uploaders leave; claim retirement is
separate work. Metadata namespace scans remain proportional to their
sizes. Bare blobs with no surviving attribution cannot be assigned to a
user.
## Testing
Before committing the replacement as
`38c60be7f6c3ee3f6942ab89858ce42e2a536c5d`, exercised the actual
`buzz-admin user-deletions media-batches` command against a fresh local
PostgreSQL database and versioned MinIO bucket. Preview preserved all 23
versions and all database rows. Deletion removed 14 exclusive versions,
preserved nine shared/unrelated versions, and removed only five target
uploader rows. Retry removed no further versions; events and
publications remained unchanged.
A standalone probe of the production inventory reached the default byte
budget after 243,148 short-key versions or 90,933 versions with 1 KiB
keys. Peak process RSS was approximately 108 MiB and 124 MiB on macOS;
these measurements describe the probe, not total command memory.
Manually removed `versionId` from the production adapter's request and
ran `cargo test -p buzz-deletion --lib
historical_claim_protects_shared_file_and_bad_claim_aborts_before_deletion`.
The regression failed because the historical outside uploader no longer
protected the file. Restored the adapter before final validation.
Earlier live-lab evidence used the direct command at
`633fdb2a48dce64f904c0077689704f136c722c1`, before this query/storage
update: 38 exclusive files and 300 versions were deleted; 24 shared
files and 10 unrelated files remained. Authenticated downloads returned
404 for all deleted originals and matching hashes for all preserved
originals. That live deletion was not repeated for this update, and does
not attest concurrent-upload safety or complete account erasure.
## Bigger picture
Media tracking:
[BUZZ-415](https://linear.app/squareup/issue/BUZZ-415/delete-user-and-owned-agent-media-and-storage-objects).
Deleted-image UI is separate work:
[BUZZ-727](https://linear.app/squareup/issue/BUZZ-727/show-a-clear-unavailable-state-for-deleted-images-in-chat-and-image).
Related: #9353. This replaces the media portion of #9329 and #9355;
those branches remain intact.
Generated with Codex
---------
Signed-off-by: Ravneet Arora <rarora@squareup.com>
Signed-off-by: dessert <7d616e7e143e5d408159614dccff1371350a1c1bd36c8de838a45ece5aca0aca@buzz.block.builderlab.xyz>
Co-authored-by: dessert <7d616e7e143e5d408159614dccff1371350a1c1bd36c8de838a45ece5aca0aca@buzz.block.builderlab.xyz>
Co-authored-by: salad <7be12d8db721c3c6d5feccf11f8389e39c6b4b717dc6aa7ce30fc80e45e8788f@buzz.block.builderlab.xyz>
509 lines
18 KiB
Rust
509 lines
18 KiB
Rust
//! Exercise the real CLI with SELECT-only access and no workflow tables.
|
|
|
|
use nostr::ToBech32;
|
|
use serde_json::Value;
|
|
use sqlx::PgPool;
|
|
use tokio::process::Command;
|
|
use url::Url;
|
|
use uuid::Uuid;
|
|
|
|
fn admin_binary() -> std::ffi::OsString {
|
|
// Nextest relocates binaries when extracting an archive. Cargo's build-time
|
|
// path remains the fallback for local cargo test runs.
|
|
std::env::var_os("NEXTEST_BIN_EXE_buzz_admin")
|
|
.unwrap_or_else(|| env!("CARGO_BIN_EXE_buzz-admin").into())
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[ignore = "requires Postgres"]
|
|
async fn cluster_global_inventory_cli_uses_only_existing_membership_tables() {
|
|
let database_url = std::env::var("BUZZ_TEST_DATABASE_URL")
|
|
.or_else(|_| std::env::var("DATABASE_URL"))
|
|
.unwrap();
|
|
let pool = PgPool::connect(&database_url).await.unwrap();
|
|
// All interpolated identifiers are this fixed prefix plus generated hex.
|
|
let name = format!("inventory_{}", Uuid::new_v4().simple());
|
|
let mut tx = pool.begin().await.unwrap();
|
|
sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
|
|
"CREATE SCHEMA {name}; SET LOCAL search_path TO {name}, public;"
|
|
)))
|
|
.execute(&mut *tx)
|
|
.await
|
|
.unwrap();
|
|
// These are existing deployed tables. No entity_deletion_* schema is needed.
|
|
sqlx::raw_sql(include_str!(
|
|
"../../../schema/tables/public/communities.sql"
|
|
))
|
|
.execute(&mut *tx)
|
|
.await
|
|
.unwrap();
|
|
sqlx::raw_sql(include_str!(
|
|
"../../../schema/tables/public/relay_members.sql"
|
|
))
|
|
.execute(&mut *tx)
|
|
.await
|
|
.unwrap();
|
|
for schema in [
|
|
include_str!("../../../schema/tables/public/channels.sql"),
|
|
include_str!("../../../schema/tables/public/channel_members.sql"),
|
|
] {
|
|
sqlx::raw_sql(schema).execute(&mut *tx).await.unwrap();
|
|
}
|
|
let pubkey = "5e4083a7a793d02575876eaf47932b4835999f5af2653d26250a909b450da7c9";
|
|
let community = Uuid::new_v4();
|
|
sqlx::query("INSERT INTO communities (id, host) VALUES ($1, 'inventory-cli.example')")
|
|
.bind(community)
|
|
.execute(&mut *tx)
|
|
.await
|
|
.unwrap();
|
|
sqlx::query("INSERT INTO relay_members (community_id, pubkey, role) VALUES ($1, $2, 'member')")
|
|
.bind(community)
|
|
.bind(pubkey)
|
|
.execute(&mut *tx)
|
|
.await
|
|
.unwrap();
|
|
let participant_community = Uuid::new_v4();
|
|
sqlx::query("INSERT INTO communities (id, host) VALUES ($1, 'channel-only-cli.example')")
|
|
.bind(participant_community)
|
|
.execute(&mut *tx)
|
|
.await
|
|
.unwrap();
|
|
for target in [community, participant_community] {
|
|
for _ in 0..2 {
|
|
let channel = Uuid::new_v4();
|
|
sqlx::query("INSERT INTO channels (community_id, id, name, created_by) VALUES ($1, $2, 'inventory-test-' || $2::uuid::text, decode($3, 'hex'))")
|
|
.bind(target).bind(channel).bind(pubkey).execute(&mut *tx).await.unwrap();
|
|
sqlx::query("INSERT INTO channel_members (community_id, channel_id, pubkey) VALUES ($1, $2, decode($3, 'hex'))")
|
|
.bind(target).bind(channel).bind(pubkey).execute(&mut *tx).await.unwrap();
|
|
}
|
|
}
|
|
sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
|
|
"CREATE ROLE {name} LOGIN PASSWORD 'inventory-local-fixture'; \
|
|
GRANT USAGE ON SCHEMA {name} TO {name}; \
|
|
GRANT SELECT ON ALL TABLES IN SCHEMA {name} TO {name};"
|
|
)))
|
|
.execute(&mut *tx)
|
|
.await
|
|
.unwrap();
|
|
tx.commit().await.unwrap();
|
|
|
|
let mut reader_url = Url::parse(&database_url).unwrap();
|
|
reader_url.set_username(&name).unwrap();
|
|
reader_url
|
|
.set_password(Some("inventory-local-fixture"))
|
|
.unwrap();
|
|
reader_url
|
|
.query_pairs_mut()
|
|
.append_pair("options", &format!("-csearch_path={name}"));
|
|
let npub = nostr::PublicKey::parse(pubkey)
|
|
.unwrap()
|
|
.to_bech32()
|
|
.unwrap();
|
|
let mut outputs = Vec::new();
|
|
for input in [pubkey, npub.as_str()] {
|
|
outputs.push(
|
|
tokio::time::timeout(
|
|
std::time::Duration::from_secs(15),
|
|
Command::new(admin_binary())
|
|
.args(["user-deletions", "inventory", "--pubkey", input])
|
|
.env("DATABASE_URL", reader_url.as_str())
|
|
.kill_on_drop(true)
|
|
.output(),
|
|
)
|
|
.await
|
|
.unwrap()
|
|
.unwrap(),
|
|
);
|
|
}
|
|
let demo = Command::new(admin_binary())
|
|
.args(["user-deletions", "inventory"])
|
|
.env("DATABASE_URL", reader_url.as_str())
|
|
.kill_on_drop(true)
|
|
.output()
|
|
.await
|
|
.unwrap();
|
|
// Clean cluster-wide role state before asserting the subprocess results.
|
|
sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
|
|
"DROP SCHEMA {name} CASCADE; DROP OWNED BY {name}; DROP ROLE {name};"
|
|
)))
|
|
.execute(&pool)
|
|
.await
|
|
.unwrap();
|
|
let inventories: Vec<Value> = outputs
|
|
.into_iter()
|
|
.map(|output| {
|
|
assert!(
|
|
output.status.success(),
|
|
"{}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
serde_json::from_slice(&output.stdout).unwrap()
|
|
})
|
|
.collect();
|
|
assert_eq!(inventories[0], inventories[1]);
|
|
assert!(
|
|
demo.status.success(),
|
|
"{}",
|
|
String::from_utf8_lossy(&demo.stderr)
|
|
);
|
|
let demo: Value = serde_json::from_slice(&demo.stdout).unwrap();
|
|
assert_eq!(
|
|
demo,
|
|
serde_json::json!({
|
|
"communities": [
|
|
{"community_id": "00000000-0000-0000-0000-00000000000b", "label": "demo:community-b", "relationship": "participant"},
|
|
{"community_id": "00000000-0000-0000-0000-00000000000c", "label": "demo:community-c", "relationship": "former_participant"}
|
|
]
|
|
})
|
|
);
|
|
let inventory = &inventories[0];
|
|
assert_eq!(inventory.as_object().unwrap().len(), 1);
|
|
assert_eq!(demo.as_object().unwrap().len(), 1);
|
|
let communities = inventory["communities"].as_array().unwrap();
|
|
assert_eq!(communities.len(), 2);
|
|
let explicit_member = communities
|
|
.iter()
|
|
.find(|item| item["community_id"] == community.to_string())
|
|
.unwrap();
|
|
assert_eq!(explicit_member["label"], "inventory-cli.example");
|
|
assert_eq!(explicit_member["relationship"], "participant");
|
|
let participant = communities
|
|
.iter()
|
|
.find(|item| item["community_id"] == participant_community.to_string())
|
|
.unwrap();
|
|
assert_eq!(participant["label"], "channel-only-cli.example");
|
|
assert_eq!(participant["relationship"], "participant");
|
|
for output in [&demo, inventory] {
|
|
for row in output["communities"].as_array().unwrap() {
|
|
assert_eq!(row.as_object().unwrap().len(), 3);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_inventory_key_fails_before_database_connection() {
|
|
let output = std::process::Command::new(admin_binary())
|
|
.args(["user-deletions", "inventory", "--pubkey", "invalid-npub"])
|
|
.env_remove("DATABASE_URL")
|
|
.output()
|
|
.unwrap();
|
|
assert_eq!(output.status.code(), Some(2));
|
|
assert!(output.stdout.is_empty());
|
|
assert!(String::from_utf8_lossy(&output.stderr)
|
|
.contains("expected a 64-character hex public key or an npub"));
|
|
}
|
|
|
|
async fn workflow_cli(url: &str, args: &[&str], success: bool) -> Value {
|
|
workflow_cli_at(url, args, success, "http://127.0.0.1:1").await
|
|
}
|
|
|
|
async fn workflow_cli_at(url: &str, args: &[&str], success: bool, endpoint: &str) -> Value {
|
|
let output = tokio::time::timeout(
|
|
std::time::Duration::from_secs(20),
|
|
Command::new(admin_binary())
|
|
.arg("user-deletions")
|
|
.args(args)
|
|
.env("DATABASE_URL", url)
|
|
.env("BUZZ_DB_POOL_SIZE", "1")
|
|
.env("BUZZ_S3_ENDPOINT", endpoint)
|
|
.env("BUZZ_S3_BUCKET", "test")
|
|
.env("BUZZ_S3_ACCESS_KEY", "test")
|
|
.env("BUZZ_S3_SECRET_KEY", "test")
|
|
.env("BUZZ_S3_ADDRESSING_STYLE", "path")
|
|
.kill_on_drop(true)
|
|
.output(),
|
|
)
|
|
.await
|
|
.unwrap()
|
|
.unwrap();
|
|
assert_eq!(
|
|
output.status.success(),
|
|
success,
|
|
"{args:?}: {}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
if success {
|
|
serde_json::from_slice(&output.stdout).unwrap()
|
|
} else {
|
|
Value::String(String::from_utf8(output.stderr).unwrap())
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[ignore = "requires Postgres"]
|
|
async fn inventory_submission_routes_all_targets_through_gate_then_real_media() {
|
|
let url = std::env::var("BUZZ_TEST_DATABASE_URL").unwrap();
|
|
let pool = PgPool::connect(&url).await.unwrap();
|
|
let key = "ab".repeat(32);
|
|
let npub = nostr::PublicKey::parse(&key).unwrap().to_bech32().unwrap();
|
|
let community = Uuid::new_v4();
|
|
let channel = Uuid::new_v4();
|
|
sqlx::query("INSERT INTO communities (id, host) VALUES ($1, 'workflow-fixture.example')")
|
|
.bind(community)
|
|
.execute(&pool)
|
|
.await
|
|
.unwrap();
|
|
sqlx::query("INSERT INTO channels (community_id, id, name, created_by) VALUES ($1, $2, 'fixture', decode($3, 'hex'))")
|
|
.bind(community).bind(channel).bind(&key).execute(&pool).await.unwrap();
|
|
sqlx::query("INSERT INTO channel_members (community_id, channel_id, pubkey) VALUES ($1, $2, decode($3, 'hex'))")
|
|
.bind(community).bind(channel).bind(&key).execute(&pool).await.unwrap();
|
|
|
|
for subject in ["demo", npub.as_str()] {
|
|
let preview = workflow_cli(&url, &["inventory", "--pubkey", subject], true).await;
|
|
let saved = workflow_cli(
|
|
&url,
|
|
&[
|
|
"submit",
|
|
"--pubkey",
|
|
subject,
|
|
"--requested-by",
|
|
"operator-a",
|
|
],
|
|
true,
|
|
)
|
|
.await;
|
|
assert_eq!(saved["inventory_manifest"], preview);
|
|
assert_eq!(
|
|
saved["target"],
|
|
if subject == "demo" {
|
|
"demo:default"
|
|
} else {
|
|
&key
|
|
}
|
|
);
|
|
assert_eq!(saved["status"], "inventoried");
|
|
let id = saved["id"].as_str().unwrap();
|
|
workflow_cli(&url, &["run", id], false).await;
|
|
workflow_cli(
|
|
&url,
|
|
&[
|
|
"approve",
|
|
id,
|
|
"--approved-by",
|
|
"operator-b",
|
|
"--inventory-digest",
|
|
"wrong",
|
|
],
|
|
false,
|
|
)
|
|
.await;
|
|
let approved = workflow_cli(
|
|
&url,
|
|
&[
|
|
"approve",
|
|
id,
|
|
"--approved-by",
|
|
"operator-b",
|
|
"--inventory-digest",
|
|
saved["inventory_digest"].as_str().unwrap(),
|
|
],
|
|
true,
|
|
)
|
|
.await;
|
|
assert!(approved["stage_history"].as_array().unwrap().is_empty());
|
|
let stepped = workflow_cli(&url, &["run", id, "--next-step"], true).await;
|
|
assert_eq!(stepped["stage_history"][0]["stage"], "gate_user");
|
|
assert_eq!(stepped["stage_history"][0]["status"], "completed");
|
|
assert_eq!(
|
|
stepped["stage_history"][0]["metadata_json"]["result"]["dummy"],
|
|
true
|
|
);
|
|
assert_eq!(stepped["stage_history"][1]["stage"], "purge_media");
|
|
assert_eq!(stepped["stage_history"][1]["status"], "pending");
|
|
let gate = stepped["stage_history"][0].clone();
|
|
let error = workflow_cli(&url, &["run", id], false).await;
|
|
assert!(error
|
|
.as_str()
|
|
.unwrap()
|
|
.contains("media deletion requires --delete"));
|
|
let done = if subject == "demo" {
|
|
let error = workflow_cli(&url, &["run", id, "--delete"], false).await;
|
|
assert!(
|
|
error
|
|
.as_str()
|
|
.unwrap()
|
|
.contains("expected a 64-character hex public key or an npub"),
|
|
"{error}"
|
|
);
|
|
let blocked = workflow_cli(&url, &["inspect", id], true).await;
|
|
assert_eq!(blocked["status"], "retry_wait");
|
|
assert_eq!(blocked["stage_history"].as_array().unwrap().len(), 2);
|
|
assert_eq!(blocked["stage_history"][1]["status"], "failed");
|
|
blocked
|
|
} else {
|
|
let storage = EmptyStorage::start().await;
|
|
let done =
|
|
workflow_cli_at(&url, &["run", id, "--delete"], true, &storage.endpoint).await;
|
|
assert_eq!(done["status"], "completed");
|
|
let stages = done["stage_history"].as_array().unwrap();
|
|
assert_eq!(stages.len(), 4);
|
|
assert_eq!(stages[1]["metadata_json"]["result"]["deleted_versions"], 0);
|
|
assert_eq!(
|
|
stages[1]["metadata_json"]["result"]["account_erasure_complete"],
|
|
false
|
|
);
|
|
assert!(stages
|
|
.iter()
|
|
.all(|s| s["status"] == "completed" && s["is_current"] == false));
|
|
let repeated =
|
|
workflow_cli_at(&url, &["run", id, "--delete"], true, &storage.endpoint).await;
|
|
assert_eq!(repeated, done);
|
|
assert_eq!(
|
|
storage.requests.load(std::sync::atomic::Ordering::SeqCst),
|
|
1 // Empty discovery needs no subsequent version listings.
|
|
);
|
|
done
|
|
};
|
|
assert_eq!(done["stage_history"][0], gate);
|
|
let inspected = workflow_cli(&url, &["inspect", id], true).await;
|
|
assert_eq!(inspected, done);
|
|
// Hex and npub converge on the same saved request without rediscovery.
|
|
let repeat = workflow_cli(
|
|
&url,
|
|
&[
|
|
"submit",
|
|
"--pubkey",
|
|
if subject == "demo" { "demo" } else { &key },
|
|
"--requested-by",
|
|
"operator-a",
|
|
],
|
|
true,
|
|
)
|
|
.await;
|
|
for (field, value) in repeat.as_object().unwrap() {
|
|
assert_eq!(value, &done[field]);
|
|
}
|
|
workflow_cli(
|
|
&url,
|
|
&[
|
|
"submit",
|
|
"--pubkey",
|
|
subject,
|
|
"--requested-by",
|
|
"someone-else",
|
|
],
|
|
false,
|
|
)
|
|
.await;
|
|
}
|
|
// Community handlers remain placeholders; real membership is unchanged.
|
|
let count: i64 = sqlx::query_scalar("SELECT count(*) FROM channel_members WHERE community_id = $1 AND pubkey = decode($2, 'hex')")
|
|
.bind(community).bind(&key).fetch_one(&pool).await.unwrap();
|
|
assert_eq!(count, 1);
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[ignore = "requires Postgres"]
|
|
async fn inventory_approval_and_resume_use_saved_account_identity_without_resolution() {
|
|
let url = std::env::var("BUZZ_TEST_DATABASE_URL").unwrap();
|
|
let pool = PgPool::connect(&url).await.unwrap();
|
|
let saved = workflow_cli(
|
|
&url,
|
|
&[
|
|
"submit",
|
|
"--target",
|
|
"demo:resolved-account",
|
|
"--requested-by",
|
|
"operator-a",
|
|
],
|
|
true,
|
|
)
|
|
.await;
|
|
let id = saved["id"].as_str().unwrap();
|
|
// Model the output of a future account resolver. This is not CLI support
|
|
// for resolving account IDs: the inventory is already saved and complete.
|
|
let account = "builderlab:account-123";
|
|
sqlx::query("UPDATE entity_deletion_requests SET target = $2 WHERE id = $1")
|
|
.bind(Uuid::parse_str(id).unwrap())
|
|
.bind(account)
|
|
.execute(&pool)
|
|
.await
|
|
.unwrap();
|
|
workflow_cli(
|
|
&url,
|
|
&[
|
|
"approve",
|
|
id,
|
|
"--approved-by",
|
|
"operator-b",
|
|
"--inventory-digest",
|
|
saved["inventory_digest"].as_str().unwrap(),
|
|
],
|
|
true,
|
|
)
|
|
.await;
|
|
let stepped = workflow_cli(&url, &["run", id, "--next-step"], true).await;
|
|
let gate = stepped["stage_history"][0].clone();
|
|
assert_eq!(gate["status"], "completed");
|
|
assert_eq!(stepped["stage_history"][1]["stage"], "purge_media");
|
|
let error = workflow_cli(&url, &["run", id, "--delete"], false).await;
|
|
assert!(
|
|
error
|
|
.as_str()
|
|
.unwrap()
|
|
.contains("expected a 64-character hex public key or an npub"),
|
|
"{error}"
|
|
);
|
|
let blocked = workflow_cli(&url, &["inspect", id], true).await;
|
|
assert_eq!(blocked["target"], account);
|
|
assert_eq!(blocked["inventory_manifest"], saved["inventory_manifest"]);
|
|
assert_eq!(blocked["status"], "retry_wait");
|
|
assert_eq!(blocked["stage_history"][0], gate);
|
|
assert_eq!(blocked["stage_history"].as_array().unwrap().len(), 2);
|
|
assert_eq!(blocked["stage_history"][1]["status"], "failed");
|
|
for stage in blocked["stage_history"].as_array().unwrap() {
|
|
assert_eq!(stage["metadata_json"]["inputs"]["target"], account);
|
|
}
|
|
}
|
|
|
|
struct EmptyStorage {
|
|
endpoint: String,
|
|
requests: std::sync::Arc<std::sync::atomic::AtomicUsize>,
|
|
server: tokio::task::JoinHandle<()>,
|
|
}
|
|
impl Drop for EmptyStorage {
|
|
fn drop(&mut self) {
|
|
self.server.abort();
|
|
}
|
|
}
|
|
impl EmptyStorage {
|
|
async fn start() -> Self {
|
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
|
let endpoint = format!("http://{}", listener.local_addr().unwrap());
|
|
let requests = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
|
|
let calls = requests.clone();
|
|
let server = tokio::spawn(async move {
|
|
loop {
|
|
let (mut socket, _) = listener.accept().await.unwrap();
|
|
tokio::time::timeout(std::time::Duration::from_secs(5), async {
|
|
let mut request = Vec::new();
|
|
while !request.windows(4).any(|b| b == b"\r\n\r\n") {
|
|
let mut chunk = [0; 4096];
|
|
let n = socket.read(&mut chunk).await.unwrap();
|
|
assert_ne!(n, 0);
|
|
request.extend_from_slice(&chunk[..n]);
|
|
assert!(request.len() < 65536);
|
|
}
|
|
assert!(request.starts_with(b"GET "));
|
|
calls.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
|
let body =
|
|
"<ListVersionsResult><IsTruncated>false</IsTruncated></ListVersionsResult>";
|
|
let response = format!(
|
|
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
|
body.len()
|
|
);
|
|
socket.write_all(response.as_bytes()).await.unwrap();
|
|
})
|
|
.await
|
|
.unwrap();
|
|
}
|
|
});
|
|
Self {
|
|
endpoint,
|
|
requests,
|
|
server,
|
|
}
|
|
}
|
|
}
|