Skip to content

Commit 50f8ecf

Browse files
committed
test:Add test demonstrating non-actionable error messages during workspace publish rate limiting
1 parent 12fa1da commit 50f8ecf

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

tests/testsuite/publish.rs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,3 +4402,124 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
44024402
"#]])
44034403
.run();
44044404
}
4405+
4406+
#[cargo_test]
4407+
fn workspace_publish_rate_limit_error() {
4408+
// This test demonstrates the current behavior when workspace publishing
4409+
// fails due to rate limiting. The error message doesn't indicate which
4410+
// package failed or what packages remain to be published.
4411+
4412+
let registry = registry::RegistryBuilder::new()
4413+
.http_api()
4414+
.http_index()
4415+
.add_responder("/api/v1/crates/new", |_req, _| {
4416+
// For simplicity, let's just return rate limit error for all requests
4417+
// This simulates hitting rate limit during workspace publish
4418+
Response {
4419+
code: 429,
4420+
headers: vec!["Retry-After: 3600".to_string()],
4421+
body: format!(
4422+
"You have published too many new crates in a short period of time. Please try again after Fri, 18 Jul 2025 20:00:34 GMT or email help@crates.io to have your limit increased."
4423+
).into_bytes(),
4424+
}
4425+
})
4426+
.build();
4427+
4428+
let p = project()
4429+
.file(
4430+
"Cargo.toml",
4431+
r#"
4432+
[workspace]
4433+
members = ["package_a", "package_b", "package_c"]
4434+
4435+
[package]
4436+
name = "workspace_root"
4437+
version = "0.0.0"
4438+
edition = "2015"
4439+
license = "MIT"
4440+
description = "workspace root"
4441+
repository = "https://github.com/test/workspace"
4442+
publish = false
4443+
"#,
4444+
)
4445+
.file("src/lib.rs", "")
4446+
.file(
4447+
"package_a/Cargo.toml",
4448+
r#"
4449+
[package]
4450+
name = "package_a"
4451+
version = "0.1.0"
4452+
edition = "2015"
4453+
license = "MIT"
4454+
description = "package a"
4455+
repository = "https://github.com/test/package_a"
4456+
"#,
4457+
)
4458+
.file("package_a/src/lib.rs", "")
4459+
.file(
4460+
"package_b/Cargo.toml",
4461+
r#"
4462+
[package]
4463+
name = "package_b"
4464+
version = "0.1.0"
4465+
edition = "2015"
4466+
license = "MIT"
4467+
description = "package b"
4468+
repository = "https://github.com/test/package_b"
4469+
"#,
4470+
)
4471+
.file("package_b/src/lib.rs", "")
4472+
.file(
4473+
"package_c/Cargo.toml",
4474+
r#"
4475+
[package]
4476+
name = "package_c"
4477+
version = "0.1.0"
4478+
edition = "2015"
4479+
license = "MIT"
4480+
description = "package c"
4481+
repository = "https://github.com/test/package_c"
4482+
"#,
4483+
)
4484+
.file("package_c/src/lib.rs", "")
4485+
.build();
4486+
4487+
// This demonstrates the current non-actionable error message
4488+
// The user doesn't know which package failed or what packages remain to be published
4489+
p.cargo("publish --workspace")
4490+
.replace_crates_io(registry.index_url())
4491+
.with_status(101)
4492+
.with_stderr_data(str![[r#"
4493+
[UPDATING] crates.io index
4494+
[PACKAGING] package_a v0.1.0 ([ROOT]/foo/package_a)
4495+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4496+
[PACKAGING] package_b v0.1.0 ([ROOT]/foo/package_b)
4497+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4498+
[PACKAGING] package_c v0.1.0 ([ROOT]/foo/package_c)
4499+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4500+
[VERIFYING] package_a v0.1.0 ([ROOT]/foo/package_a)
4501+
[COMPILING] package_a v0.1.0 ([ROOT]/foo/target/package/package_a-0.1.0)
4502+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4503+
[VERIFYING] package_b v0.1.0 ([ROOT]/foo/package_b)
4504+
[COMPILING] package_b v0.1.0 ([ROOT]/foo/target/package/package_b-0.1.0)
4505+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4506+
[VERIFYING] package_c v0.1.0 ([ROOT]/foo/package_c)
4507+
[COMPILING] package_c v0.1.0 ([ROOT]/foo/target/package/package_c-0.1.0)
4508+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4509+
[UPLOADING] package_a v0.1.0 ([ROOT]/foo/package_a)
4510+
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
4511+
4512+
Caused by:
4513+
failed to get a 200 OK response, got 429
4514+
headers:
4515+
HTTP/1.1 429
4516+
Content-Length: 172
4517+
Connection: close
4518+
Retry-After: 3600
4519+
4520+
body:
4521+
You have published too many new crates in a short period of time. Please try again after Fri, 18 Jul 2025 20:00:34 GMT or email help@crates.io to have your limit increased.
4522+
4523+
"#]])
4524+
.run();
4525+
}

0 commit comments

Comments
 (0)