mirror of
https://github.com/storytold/craft-launcher.git
synced 2026-12-02 20:22:35 -05:00
Fix warm nightly replay and typed admission refusals
Keep a recovered signed listing visible but stale when an older persisted absence disagrees. Capture the eligible install candidate once before reservations and report capture failures through the typed Nightly refusal path; retain worker revalidation at use.
This commit is contained in:
1 parent
7de2394a11
commit
8084fe64d8
3 files changed
+114
-7
No files matched your search
@@ -1180,7 +1180,7 @@ impl NativeBackend {
|
||||
if !self.options().nightly_enabled {
|
||||
return Err("Developer build installs and updates are off. Retained copies and data are kept.".into());
|
||||
}
|
||||
selected_nightly(app, &self.shared, platform)?;
|
||||
// prepare_job captures the exact candidate once, before any reservation.
|
||||
Ok(())
|
||||
}
|
||||
Work::Uninstall | Work::Launch(_) => {
|
||||
@@ -1229,7 +1229,7 @@ impl NativeBackend {
|
||||
match selected_nightly(CraftApp::by_id(app_id)?, &self.shared, self.platform?) {
|
||||
Ok(selected) => Some(selected),
|
||||
Err(error) => {
|
||||
self.shared.emit(Event::JobFinished { app: app_id.into(), result: Err(error) });
|
||||
self.shared.emit(Event::NightlyJobRefused { app: app_id.into(), operation: work.nightly_operation(), error });
|
||||
return None;
|
||||
}
|
||||
}
|
||||
@@ -2536,9 +2536,10 @@ fn nightly_status_with_state(
|
||||
.lock()
|
||||
.unwrap_or_else(PoisonError::into_inner)
|
||||
.get(app.id)
|
||||
.filter(|listing| record.tag.as_deref() == Some(listing.release.tag.as_str()))
|
||||
.map(|listing| (listing.fresh(now), listing.valid_until()));
|
||||
let mut status = record.status(enabled && state.fresh(&key, now) && (record.no_compatible_build() || listing.is_some_and(|(fresh, _)| fresh)));
|
||||
.map(|listing| (record.tag.as_deref() == Some(listing.release.tag.as_str()) && listing.fresh(now), listing.valid_until()));
|
||||
// A recovered listing contradicts an older absence until its persisted result is reconciled.
|
||||
let source_fresh = listing.map_or(record.no_compatible_build(), |(fresh, _)| fresh);
|
||||
let mut status = record.status(enabled && state.fresh(&key, now) && source_fresh);
|
||||
if let Some((_, until)) = listing {
|
||||
status.valid_until = Some(status.valid_until.map_or(until, |record_until| record_until.min(until)));
|
||||
}
|
||||
|
||||
@@ -774,3 +774,110 @@ fn review_cached_catalog_status_and_admission_share_the_source_expiry_without_an
|
||||
assert!(backend.shared.nightly_verified.lock().unwrap().is_empty(), "a cached listing is not an eager GitHub install token");
|
||||
assert!(requests.lock().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_integration_activation_replay_keeps_a_conflicting_cached_listing_visible_until_reconciled() {
|
||||
for has_listing in [false, true] {
|
||||
let (_temp, mut backend, requests) = setup();
|
||||
let platform = backend.platform.unwrap();
|
||||
let now = crate::now();
|
||||
let key = nightly_lookup::key(app(), platform);
|
||||
finish_nightly_result(
|
||||
app(),
|
||||
platform,
|
||||
0,
|
||||
Outcome::NotListed { published_at: now - 60 },
|
||||
Origin::ArtCraftApi,
|
||||
&backend.shared,
|
||||
&backend.paths,
|
||||
);
|
||||
*backend.shared.nightly_state.lock().unwrap() = nightly_lookup::State::load(&backend.paths);
|
||||
let mut catalog = test_catalog(20).0;
|
||||
let expected_tag = nightly_lookup::catalog_listing(&catalog, app(), None).unwrap().release.tag;
|
||||
if !has_listing {
|
||||
catalog.apps.get_mut(app().id).unwrap().nightly = None;
|
||||
}
|
||||
backend.poll();
|
||||
// The production activation order: signed cache first, persisted scheduling status next.
|
||||
backend.replay_nightly_feed(&catalog);
|
||||
backend.replay_nightly_status(|| now);
|
||||
let events = backend.poll();
|
||||
let latest = events
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|event| match event {
|
||||
Event::Latest { app: id, latest, .. } if id == app().id => Some(latest),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
let status = events
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|event| match event {
|
||||
Event::NightlyStatus { app: id, status } if id == app().id => Some(status),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
if has_listing {
|
||||
assert!(
|
||||
matches!(latest, LatestRelease::Found(release) if release.tag == expected_tag),
|
||||
"status replay must retain the signed cached card as Last seen, not overwrite it with an older absence: {events:?}"
|
||||
);
|
||||
assert!(status.stale && status.current_verified_at(now).is_none());
|
||||
assert!(!events.iter().any(|event| matches!(event, Event::Latest { app: id, latest: LatestRelease::None, .. } if id == app().id)));
|
||||
} else {
|
||||
assert!(matches!(latest, LatestRelease::None), "an authoritative matching absence must still replay");
|
||||
assert!(!status.stale && status.current_verified_at(now).is_some());
|
||||
}
|
||||
assert!(!events.iter().any(|event| matches!(event, Event::Installable { app: id, installable: true } if id == app().id)));
|
||||
assert!(!nightly_offer_ready(app(), &backend.shared, platform, &backend.shared.nightly_state.lock().unwrap(), now));
|
||||
assert_eq!(backend.shared.nightly_state.lock().unwrap().record(&key).verified_at, Some(now - 60));
|
||||
if has_listing {
|
||||
let listing = backend.shared.nightly_listings.lock().unwrap()[app().id].clone();
|
||||
finish_nightly_result(app(), platform, 0, Outcome::Listed(Box::new(listing)), Origin::ArtCraftApi, &backend.shared, &backend.paths);
|
||||
backend.replay_nightly_status(crate::now);
|
||||
let reconciled = backend.poll();
|
||||
assert!(reconciled.iter().any(|event| matches!(event, Event::Installable { app: id, installable: true } if id == app().id)));
|
||||
assert!(
|
||||
reconciled
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|event| match event {
|
||||
Event::NightlyStatus { app: id, status } if id == app().id => Some(!status.stale),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap()
|
||||
);
|
||||
assert!(nightly_offer_ready(app(), &backend.shared, platform, &backend.shared.nightly_state.lock().unwrap(), crate::now()));
|
||||
}
|
||||
assert!(backend.shared.nightly_verified.lock().unwrap().is_empty(), "reconciliation must not mint an eager GitHub token");
|
||||
assert!(requests.lock().unwrap().is_empty(), "activation replay never fetches a descriptor or payload");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_integration_refused_install_click_is_typed_and_starts_no_download() {
|
||||
let (_temp, mut backend, requests) = setup();
|
||||
selection(&backend, 20);
|
||||
backend.shared.nightly_listings.lock().unwrap().clear();
|
||||
backend.poll();
|
||||
let spawned = Arc::new(AtomicUsize::new(0));
|
||||
let spawned_jobs = spawned.clone();
|
||||
backend.spawn = Arc::new(move |_| {
|
||||
spawned_jobs.fetch_add(1, Ordering::SeqCst);
|
||||
});
|
||||
backend.http = Some(Http::new().unwrap().without_token().with_test_transport(requests.clone(), |url, _| panic!("refused click fetched {url}")));
|
||||
backend.send(Command::Install { app: app().id.into() });
|
||||
let events = backend.poll();
|
||||
assert!(
|
||||
events.iter().any(|event| matches!(event,
|
||||
Event::NightlyJobRefused { app: id, operation: artcraft_launcher_core::protocol::NightlyOperation::Install, error }
|
||||
if id == app().id && error.contains("Refresh")
|
||||
)),
|
||||
"a refused click must reach the Nightly UI's visible feedback path: {events:?}"
|
||||
);
|
||||
assert!(!events.iter().any(|event| matches!(event, Event::JobFinished { .. })), "the Nightly UI ignores generic completion");
|
||||
assert_eq!(spawned.load(Ordering::SeqCst), 0);
|
||||
assert!(!backend.has_active_jobs());
|
||||
assert!(requests.lock().unwrap().is_empty());
|
||||
}
|
||||
@@ -690,8 +690,7 @@ fn deferred_sweep_restores_installability_without_bypassing_signed_source_or_for
|
||||
shared.nightly_listings.lock().unwrap().clear();
|
||||
}
|
||||
"no build" => {
|
||||
shared.nightly_state.lock().unwrap().outcome(&key, crate::now(), &Outcome::NoCompatibleBuild);
|
||||
shared.nightly_verified.lock().unwrap().clear();
|
||||
finish_nightly_result(app(), platform, 0, Outcome::NotListed { published_at: crate::now() }, Origin::ArtCraftApi, &shared, &paths);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user