mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 04:35:16 +08:00
feat: harden official sync scheduling and integrity
This commit is contained in:
@@ -185,6 +185,58 @@ fn official_update_service_emits_human_progress_events() {
|
||||
.contains("pull plan contains 19 official URLs")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn official_update_first_run_pulls_without_pre_audit() {
|
||||
let harness = TestHarness::new();
|
||||
let config = harness.sync_config("first-run-output");
|
||||
let mut events = Vec::<OfficialUpdateProgress>::new();
|
||||
|
||||
let report = OfficialUpdateService::new()
|
||||
.run_with_progress(&config, |event| events.push(event))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(report.update_status, OfficialUpdateStatus::Downloaded);
|
||||
assert_eq!(report.resource_count, Some(19));
|
||||
assert_eq!(report.downloaded_count, 19);
|
||||
assert_eq!(report.skipped_count, 0);
|
||||
assert_eq!(report.local_manifest_repair_needed_count, 0);
|
||||
assert!(events.iter().any(|event| {
|
||||
event.stage == "local-state" && event.message.contains("has_local_resources=false")
|
||||
}));
|
||||
assert!(events
|
||||
.iter()
|
||||
.any(|event| { event.stage == "audit" && event.message.contains("skipping local audit") }));
|
||||
assert!(events.iter().any(|event| {
|
||||
event.stage == "decision" && event.message.contains("initial_pull_needed=true")
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn official_update_second_run_audits_existing_resources_before_reuse() {
|
||||
let harness = TestHarness::new();
|
||||
let config = harness.sync_config("second-run-output");
|
||||
OfficialUpdateService::new().run(&config).unwrap();
|
||||
|
||||
let mut events = Vec::<OfficialUpdateProgress>::new();
|
||||
let report = OfficialUpdateService::new()
|
||||
.run_with_progress(&config, |event| events.push(event))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(report.update_status, OfficialUpdateStatus::UpToDate);
|
||||
assert_eq!(report.downloaded_count, 0);
|
||||
assert_eq!(report.local_manifest_verified_count, 19);
|
||||
assert_eq!(report.local_manifest_repair_needed_count, 0);
|
||||
assert!(events.iter().any(|event| {
|
||||
event.stage == "local-state" && event.message.contains("has_local_resources=true")
|
||||
}));
|
||||
assert!(events.iter().any(|event| {
|
||||
event.stage == "audit" && event.message.contains("auditing local download manifest")
|
||||
}));
|
||||
assert!(events.iter().any(|event| {
|
||||
event.stage == "decision" && event.message.contains("initial_pull_needed=false")
|
||||
}));
|
||||
}
|
||||
|
||||
struct TestHarness {
|
||||
temp: TempDir,
|
||||
curl_script: std::path::PathBuf,
|
||||
@@ -259,6 +311,17 @@ impl TestHarness {
|
||||
&self.curl_script,
|
||||
)
|
||||
}
|
||||
|
||||
fn sync_config(&self, output_name: &str) -> OfficialUpdateConfig {
|
||||
OfficialUpdateConfig {
|
||||
auto_discover: true,
|
||||
launcher_version: TEST_LAUNCHER_VERSION.to_string(),
|
||||
output_root: self.temp.path().join(output_name),
|
||||
curl_command: self.curl_script.clone(),
|
||||
unzip_command: self.unzip_script.clone(),
|
||||
..OfficialUpdateConfig::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn write_executable(path: &Path, content: &str) {
|
||||
|
||||
Reference in New Issue
Block a user