Files
clawmates/crates/cm-files/tests/s3_store.rs
T
Omar SobhandClaude Opus 5 5d9edd636d
deploy / test (push) Successful in 4m57s
deploy / build (push) Successful in 5m49s
test(cm-files): pull MinIO from quay.io — Docker Hub no longer has the repository
`cargo test --workspace` fails on any fresh machine: hub.docker.com's
minio/minio returned 404 for the whole repository on 2026-09-19, and
testcontainers cannot pull it. CI on gw-04 kept passing because a year-old
copy is cached there and testcontainers pulls only when the local create
returns 404 — one image prune away from failing forever, and already failing
here. MinIO publishes the same image on quay.io; the manifest answers 200.

Found while reproducing a red CI run that turned out to be environmental.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WZb5A2kfVfjpdwSochkuHz
2026-09-18 23:39:40 -05:00

96 lines
3.3 KiB
Rust

//! The cloud-target blob store against a REAL S3-compatible server
//! (MinIO in a container) — same contract the local store satisfies.
use testcontainers_modules::testcontainers::core::{ExecCommand, IntoContainerPort, WaitFor};
use testcontainers_modules::testcontainers::runners::AsyncRunner;
use testcontainers_modules::testcontainers::{GenericImage, ImageExt};
use cm_files::{BlobError, BlobStore, S3BlobStore};
async fn minio_store() -> (
S3BlobStore,
testcontainers_modules::testcontainers::ContainerAsync<GenericImage>,
) {
// quay.io, not Docker Hub: hub.docker.com/r/minio/minio returned 404 for
// the whole repository on 2026-09-19. CI kept passing only because gw-04
// had a year-old copy cached and testcontainers pulls only on a local
// miss; every fresh machine failed here with "pull access denied".
let container = GenericImage::new("quay.io/minio/minio", "latest")
.with_exposed_port(9000.tcp())
.with_wait_for(WaitFor::message_on_either_std("API:"))
.with_env_var("MINIO_ROOT_USER", "tc-access")
.with_env_var("MINIO_ROOT_PASSWORD", "tc-secret-key")
.with_cmd(["server", "/data"])
.start()
.await
.expect("minio starts");
// Create the bucket with the bundled mc client.
container
.exec(ExecCommand::new([
"sh",
"-c",
"mc alias set local http://127.0.0.1:9000 tc-access tc-secret-key && mc mb local/clawmates",
]))
.await
.expect("bucket created");
let port = container.get_host_port_ipv4(9000).await.unwrap();
// The bucket is created asynchronously after boot; retry connect+probe.
let store = S3BlobStore::connect(
&format!("http://127.0.0.1:{port}"),
"clawmates",
"tc-access",
"tc-secret-key",
)
.expect("client builds");
for _ in 0..50 {
if store.put("probe", b"x").await.is_ok() {
store.delete("probe").await.ok();
return (store, container);
}
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
}
panic!("minio bucket never became writable");
}
#[tokio::test]
async fn s3_round_trip_overwrite_and_missing_keys() {
let (store, _container) = minio_store().await;
store
.put("ws1/documents/agent1/report.md", b"# Q2 Report")
.await
.unwrap();
assert_eq!(
store.get("ws1/documents/agent1/report.md").await.unwrap(),
b"# Q2 Report"
);
// Overwrite replaces.
store
.put("ws1/documents/agent1/report.md", b"# Q3 Report")
.await
.unwrap();
assert_eq!(
store.get("ws1/documents/agent1/report.md").await.unwrap(),
b"# Q3 Report"
);
// Delete then NotFound on both get and delete.
store
.delete("ws1/documents/agent1/report.md")
.await
.unwrap();
assert!(matches!(
store.get("ws1/documents/agent1/report.md").await,
Err(BlobError::NotFound)
));
assert!(matches!(
store.delete("ws1/documents/agent1/report.md").await,
Err(BlobError::NotFound)
));
// Nested keys work without directory semantics.
store.put("a/b/c/deep.txt", b"deep").await.unwrap();
assert_eq!(store.get("a/b/c/deep.txt").await.unwrap(), b"deep");
}