This commit is contained in:
Daniel Pechersky 2025-09-23 22:12:16 +09:00 committed by GitHub
commit 258f24da5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 112 additions and 0 deletions

36
Cargo.lock generated
View file

@ -117,6 +117,7 @@ dependencies = [
"hyper 1.7.0",
"id_tree",
"inflections",
"insta",
"itertools 0.14.0",
"nom 8.0.0",
"num_cpus",
@ -1192,6 +1193,18 @@ dependencies = [
"ninja_gen",
]
[[package]]
name = "console"
version = "0.15.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
dependencies = [
"encode_unicode",
"libc",
"once_cell",
"windows-sys 0.59.0",
]
[[package]]
name = "constant_time_eq"
version = "0.3.1"
@ -1965,6 +1978,12 @@ dependencies = [
"winreg 0.55.0",
]
[[package]]
name = "encode_unicode"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]]
name = "encoding_rs"
version = "0.8.35"
@ -3369,6 +3388,17 @@ dependencies = [
"libc",
]
[[package]]
name = "insta"
version = "1.43.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46fdb647ebde000f43b5b53f773c30cf9b0cb4300453208713fa38b2c70935a0"
dependencies = [
"console",
"once_cell",
"similar",
]
[[package]]
name = "intl-memoizer"
version = "0.5.3"
@ -5948,6 +5978,12 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "similar"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa"
[[package]]
name = "siphasher"
version = "0.3.11"

View file

@ -87,6 +87,7 @@ htmlescape = "0.3.1"
hyper = "1"
id_tree = "1.8.0"
inflections = "1.1.1"
insta = "1.43.2"
intl-memoizer = "0.5.3"
itertools = "0.14.0"
junction = "1.2.0"

1
rslib/.gitignore vendored
View file

@ -1,3 +1,4 @@
Cargo.lock
.build
target
tests/support/large

View file

@ -35,6 +35,8 @@ syn.workspace = true
async-stream.workspace = true
reqwest = { workspace = true, features = ["native-tls"] }
wiremock.workspace = true
tempfile.workspace = true
insta.workspace = true
[dependencies]
criterion = { workspace = true, optional = true }

View file

@ -504,4 +504,76 @@ mod tests {
);
Ok(())
}
mod update_memory_state {
use std::{fs::File, io::BufReader};
use tempfile::{NamedTempFile, TempPath};
use zstd::stream::copy_decode;
use crate::{browser_table::Column, collection::CollectionBuilder, search::SortMode};
use super::*;
const TEST_COLLECTION_PATH: &str = "tests/support/large/collection.anki21b";
fn assert_file_size_hasnt_changed() {
insta::assert_snapshot!(std::fs::metadata(TEST_COLLECTION_PATH).unwrap().len(), @"50563219");
}
fn open_temp_collection() -> (Collection, TempPath) {
assert_file_size_hasnt_changed();
let mut test_collection = BufReader::new(File::open(TEST_COLLECTION_PATH).unwrap());
let mut temp_file = NamedTempFile::new().unwrap();
copy_decode(&mut test_collection, temp_file.as_file_mut()).unwrap();
let temp_path = temp_file.into_temp_path();
let collection = CollectionBuilder::new(temp_path.to_path_buf())
.build()
.unwrap();
(collection, temp_path)
}
pub static PARAMS: [f32; 21] = [
0.212, 1.2931, 2.3065, 8.2956, 6.4133, 0.8334, 3.0194, 0.001, 1.8722, 0.1666, 0.796,
1.4835, 0.0614, 0.2629, 1.6483, 0.6014, 1.8729, 0.5425, 0.0912, 0.0658, 0.1542,
];
#[test]
#[ignore = "the test collection isn't yet automatically downloaded."]
fn snapshot_req() {
let (mut collection, _temp) = open_temp_collection();
let deck_name = "Main::English";
let deck_id = collection.get_deck_id(deck_name).unwrap().unwrap();
let search = SearchNode::DeckIdWithChildren(deck_id);
collection
.update_memory_state(vec![UpdateMemoryStateEntry {
req: Some(UpdateMemoryStateRequest {
params: PARAMS.to_vec(),
preset_desired_retention: 0.9,
historical_retention: 0.9,
max_interval: 36_500,
reschedule: true,
deck_desired_retention: [(deck_id, 0.9)].into_iter().collect(),
}),
search: search.clone(),
ignore_before: TimestampMillis(0),
}])
.unwrap();
let cards_in_deck = collection
.all_cards_for_search_in_order(
search,
SortMode::Builtin {
column: Column::SortField,
reverse: false,
},
)
.unwrap();
insta::assert_debug_snapshot!(cards_in_deck);
}
}
}