mod common;
use std::collections::BTreeSet;
use coremlit::{
ComputeUnits, DataType, Model,
embeddings::clap::{
audio::{AudioEncoder, AudioEncoderOptions, N_MELS, T_FRAMES},
embedding::EMBEDDING_DIM,
},
};
#[test]
fn collect_files_rel_skips_sidecars_but_surfaces_real_extras() {
let tmp = tempfile::tempdir().expect("create temp dir");
let bundle = tmp.path().join("clap_audio.mlmodelc");
std::fs::create_dir_all(bundle.join("weights")).expect("mkdir bundle weights/");
std::fs::write(bundle.join("model.mil"), b"mil").expect("write model.mil");
std::fs::write(bundle.join("weights/weight.bin"), b"w").expect("write weight.bin");
std::fs::write(bundle.join("._model.mil"), b"ad").expect("write ._model.mil");
std::fs::write(bundle.join(".DS_Store"), b"ds").expect("write .DS_Store");
std::fs::write(bundle.join("weights/._weight.bin"), b"ad").expect("write nested ._");
std::fs::write(bundle.join("rogue.bin"), b"x").expect("write rogue.bin");
let mut found = Vec::new();
common::collect_files_rel(&bundle, "", &mut found);
let discovered: BTreeSet<String> = found.into_iter().collect();
assert_eq!(
discovered,
BTreeSet::from([
"model.mil".to_string(),
"rogue.bin".to_string(),
"weights/weight.bin".to_string(),
]),
"discovery must exclude `._*`/.DS_Store sidecars and keep every real file"
);
let pinned: BTreeSet<String> =
BTreeSet::from(["model.mil".to_string(), "weights/weight.bin".to_string()]);
assert_ne!(
discovered, pinned,
"a real unpinned extra must still break the exact-set equality"
);
let extras: Vec<String> = discovered.difference(&pinned).cloned().collect();
assert_eq!(
extras,
vec!["rogue.bin".to_string()],
"the surviving extra must be exactly the real unpinned file, not a sidecar"
);
}
#[test]
#[ignore = "requires local clapkit models (CLAPKIT_TEST_MODELS)"]
fn clap_audio_io_matches_spec() {
let model = Model::load(common::audio_model_path(), ComputeUnits::CpuOnly).unwrap();
let description = model.description();
let input = description
.input("input_features")
.expect("input_features input");
assert_eq!(input.shape(), &[1, 1, T_FRAMES, N_MELS]);
assert_eq!(input.data_type(), Some(DataType::F32));
let output = description
.output("audio_embeds")
.expect("audio_embeds output");
assert_eq!(output.shape(), &[1, EMBEDDING_DIM]);
assert_eq!(output.data_type(), Some(DataType::F32));
AudioEncoder::from_file_with(
common::audio_model_path(),
AudioEncoderOptions::new().with_compute(ComputeUnits::CpuOnly),
)
.expect("the staged artifact must satisfy this door's load contract");
}
#[test]
#[ignore = "requires local clapkit models (CLAPKIT_TEST_MODELS)"]
fn clap_audio_artifacts_match_pinned_sha256() {
let dir = common::audio_model_path();
let cases = common::artifact_sha256("clap_audio.mlmodelc");
common::assert_exact_sha_manifest(&dir, &cases);
}
#[test]
#[ignore = "requires local clapkit int8 models (CLAPKIT_TEST_MODELS)"]
fn clap_audio_int8_io_matches_spec() {
let model = Model::load(common::audio_model_int8_path(), ComputeUnits::CpuOnly).unwrap();
let description = model.description();
let input = description
.input("input_features")
.expect("input_features input");
assert_eq!(input.shape(), &[1, 1, T_FRAMES, N_MELS]);
assert_eq!(input.data_type(), Some(DataType::F32));
let output = description
.output("audio_embeds")
.expect("audio_embeds output");
assert_eq!(output.shape(), &[1, EMBEDDING_DIM]);
assert_eq!(output.data_type(), Some(DataType::F32));
AudioEncoder::from_file_with(
common::audio_model_int8_path(),
AudioEncoderOptions::new().with_compute(ComputeUnits::CpuOnly),
)
.expect("the staged artifact must satisfy this door's load contract");
}
#[test]
#[ignore = "requires local clapkit int8 models (CLAPKIT_TEST_MODELS)"]
fn clap_audio_int8_artifacts_match_pinned_sha256() {
let dir = common::audio_model_int8_path();
let cases = common::artifact_sha256("clap_audio_int8.mlmodelc");
common::assert_exact_sha_manifest(&dir, &cases);
}