Skip to content

Commit

Permalink
fix regression when showing search results with a failed crate
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Jun 24, 2024
1 parent bbf1c3f commit bb8cd48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,8 @@ mod tests {
use crate::db::types::BuildStatus;
use crate::registry_api::{CrateOwner, OwnerKind};
use crate::test::{
assert_cache_control, assert_redirect, assert_redirect_unchecked, assert_success, wrapper,
FakeBuild, TestFrontend,
assert_cache_control, assert_redirect, assert_redirect_unchecked, assert_success,
fake_release_that_failed_before_build, wrapper, FakeBuild, TestFrontend,
};
use anyhow::Error;
use chrono::{Duration, TimeZone};
Expand Down Expand Up @@ -1298,6 +1298,18 @@ mod tests {
.docsrs_version("docs.rs 4.0.0")])
.create()?;

// release that failed in the fetch-step, will miss some details
env.runtime().block_on(async {
let mut conn = env.async_db().await.async_conn().await;
fake_release_that_failed_before_build(
&mut conn,
"failed_hard",
"0.1.0",
"some random error",
)
.await
})?;

let _m = crates_io
.mock("GET", "/api/v1/crates")
.match_query(Matcher::AllOf(vec![
Expand All @@ -1313,7 +1325,8 @@ mod tests {
{ "name": "some_other_crate" },
{ "name": "and_another_one" },
{ "name": "yet_another_crate" },
{ "name": "in_progress" }
{ "name": "in_progress" },
{ "name": "failed_hard" }
],
"meta": {
"next_page": null,
Expand All @@ -1327,14 +1340,15 @@ mod tests {
let links = get_release_links("/releases/search?query=some_random_crate", web)?;

// `some_other_crate` won't be shown since we don't have it yet
assert_eq!(links.len(), 3);
assert_eq!(links.len(), 4);
// * `max_version` from the crates.io search result will be ignored since we
// might not have it yet, or the doc-build might be in progress.
// * ranking/order from crates.io result is preserved
// * version used is the highest semver following our own "latest version" logic
assert_eq!(links[0], "/some_random_crate/latest/some_random_crate/");
assert_eq!(links[1], "/and_another_one/latest/and_another_one/");
assert_eq!(links[2], "/yet_another_crate/0.1.0/yet_another_crate/");
assert_eq!(links[3], "/crate/failed_hard/0.1.0");
Ok(())
})
}
Expand Down
6 changes: 5 additions & 1 deletion templates/releases/releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@
{{ release.stars }}
{{ "star" | fas }}
</div>
{%- else -%}
{%- elif release.build_time -%}
<div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date"
title="{{ release.build_time | date(format='%FT%TZ') }}">
{{ release.build_time | timeformat(relative=true) }}
</div>
{%- else -%}
<div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date">
&mdash;
</div>
{%- endif %}
</div>
</a>
Expand Down

0 comments on commit bb8cd48

Please sign in to comment.