#![forbid(unsafe_code)]
const REQUIRED_LINES: &[&str] = &[
"kcode-k1-access = \"0.6.2\"",
"kcode-k1-access-audio-classifier = \"0.1.0\"",
"kcode-k1-access-full-audio = \"0.10.0\"",
"kcode-k1-access-launch-nodes = \"0.2.2\"",
"kcode-k1-access-persons = \"0.3.0\"",
"kcode-k1-access-profiles = \"0.6.2\"",
"kcode-k1-audio-classification = \"0.6.0\"",
"kcode-k1-audio-classifier = \"0.1.1\"",
"kcode-k1-authority-filters = \"0.2.0\"",
"kcode-k1-chat-service = \"0.10.3\"",
"kcode-k1-codex-adapter = \"0.5.3\"",
"kcode-k1-codex-websearch = \"0.2.0\"",
"kcode-k1-daemon-http-boundary = \"0.1.1\"",
"kcode-k1-daemon-provider-config = \"0.1.6\"",
"kcode-k1-daemon-web-startup = \"0.1.0\"",
"kcode-k1-full-audio = \"0.4.0\"",
"kcode-k1-http-access-context = \"0.2.0\"",
"kcode-k1-http-access-profile-presentation = \"0.1.0\"",
"kcode-k1-http-audio = \"0.4.0\"",
"kcode-k1-http-chat = \"0.7.2\"",
"kcode-k1-http-kmap = \"0.1.0\"",
"kcode-k1-http-launch-nodes = \"0.3.0\"",
"kcode-k1-http-people = \"0.9.0\"",
"kcode-k1-http-persons = \"0.3.0\"",
"kcode-k1-ktool-social = \"0.1.1\"",
"kcode-k1-launch-nodes = \"0.4.0\"",
"kcode-k1-peering = \"0.3.1\"",
"kcode-k1-txn-ordering = \"0.5.1\"",
"kcode-speaker-v3-analysis = \"0.3.5\"",
];
const OBSOLETE_LINES: &[&str] = &[
"kcode-k1-access = \"0.6.1\"",
"kcode-k1-access-full-audio = \"0.9.1\"",
"kcode-k1-access-full-audio = \"0.9.4\"",
"kcode-k1-access-launch-nodes = \"0.2.0\"",
"kcode-k1-audio-classification = \"0.5.9\"",
"kcode-k1-audio-classification = \"0.5.10\"",
"kcode-k1-chat-service = \"0.3.0\"",
"kcode-k1-chat-service = \"0.6.0\"",
"kcode-k1-chat-service = \"0.7.0\"",
"kcode-k1-chat-service = \"0.8.0\"",
"kcode-k1-chat-service = \"0.9.0\"",
"kcode-k1-chat-service = \"0.10.0\"",
"kcode-k1-chat-service = \"0.10.1\"",
"kcode-k1-chat-service = \"0.10.2\"",
"kcode-k1-codex-adapter = \"0.5.0\"",
"kcode-k1-codex-adapter = \"0.5.1\"",
"kcode-k1-codex-websearch = \"0.1.0\"",
"kcode-k1-daemon-http-boundary = \"0.1.0\"",
"kcode-k1-daemon-provider-config = \"0.1.4\"",
"kcode-k1-daemon-provider-config = \"0.1.5\"",
"kcode-k1-full-audio = \"0.3.7\"",
"kcode-k1-http-audio = \"0.3.0\"",
"kcode-k1-http-audio = \"0.3.1\"",
"kcode-k1-http-chat = \"0.2.0\"",
"kcode-k1-http-chat = \"0.5.0\"",
"kcode-k1-http-chat = \"0.6.0\"",
"kcode-k1-http-chat = \"0.6.1\"",
"kcode-k1-http-chat = \"0.7.0\"",
"kcode-k1-http-chat = \"0.7.1\"",
"kcode-k1-http-launch-nodes = \"0.2.0\"",
"kcode-k1-ktool-social = \"0.1.0\"",
"kcode-k1-launch-nodes = \"0.3.0\"",
"kcode-k1-peering = \"0.3.0\"",
"kcode-k1-web-http = \"0.1.0\"",
];
const REQUIRED_SOURCE: &[&str] = &[
"AudioClassification::open(",
".shutdown()",
"kcode_k1_http_audio::authenticated_routes",
"SocialKtools::new(",
"K1ChatService::open_with_social(",
];
const PROHIBITED_SOURCE: &[&str] = &[
"audio-classification-v2",
"http_audio_artifacts",
"retry_fragment",
"artifact_route",
"let chat = K1ChatService::open(",
];
pub fn verify_manifest(manifest: &str) {
for required in REQUIRED_LINES {
assert!(
manifest.lines().any(|line| line == *required),
"missing required manifest line: {required}"
);
}
for obsolete in OBSOLETE_LINES {
assert!(
!manifest.lines().any(|line| line == *obsolete),
"obsolete manifest line: {obsolete}"
);
}
assert!(
!manifest.lines().any(|line| line
.trim_start()
.starts_with("kcode-k1-http-audio-artifacts")),
"artifact manifest selection"
);
assert!(
!manifest.lines().any(|line| line.contains(" = \"=")),
"manifest contains an exact internal pin"
);
}
pub fn verify_source(source: &str) {
for required in REQUIRED_SOURCE {
assert!(
source.contains(required),
"missing required source evidence: {required}"
);
}
for prohibited in PROHIBITED_SOURCE {
assert!(
!source.contains(prohibited),
"prohibited source token: {prohibited}"
);
}
}
#[cfg(test)]
mod tests {
use super::*;
fn good_manifest() -> String {
REQUIRED_LINES.join("\n")
}
fn good_source() -> &'static str {
"AudioClassification::open(\nservice.shutdown()\nkcode_k1_http_audio::authenticated_routes\nSocialKtools::new(\nK1ChatService::open_with_social("
}
#[test]
fn accepts_current_inputs() {
verify_manifest(&good_manifest());
verify_source(good_source());
}
#[test]
fn rejects_missing_audio_requirements() {
for line in [
"kcode-k1-access-full-audio = \"0.10.0\"",
"kcode-k1-audio-classification = \"0.6.0\"",
"kcode-k1-full-audio = \"0.4.0\"",
"kcode-k1-http-audio = \"0.4.0\"",
"kcode-k1-peering = \"0.3.1\"",
"kcode-speaker-v3-analysis = \"0.3.5\"",
] {
assert!(
std::panic::catch_unwind(|| verify_manifest(&good_manifest().replace(line, "")))
.is_err()
);
}
}
#[test]
fn rejects_missing_social_manifest_requirements() {
for line in [
"kcode-k1-chat-service = \"0.10.3\"",
"kcode-k1-ktool-social = \"0.1.1\"",
] {
assert!(
std::panic::catch_unwind(|| verify_manifest(&good_manifest().replace(line, "")))
.is_err()
);
}
}
#[test]
fn rejects_missing_source_evidence() {
for evidence in REQUIRED_SOURCE {
assert!(
std::panic::catch_unwind(|| verify_source(&good_source().replace(evidence, "")))
.is_err()
);
}
}
#[test]
fn rejects_prohibited_source_tokens() {
for token in PROHIBITED_SOURCE {
assert!(
std::panic::catch_unwind(|| verify_source(&format!("{} {token}", good_source())))
.is_err()
);
}
}
#[test]
fn rejects_artifact_package_selection() {
assert!(
std::panic::catch_unwind(|| verify_manifest(&format!(
"{}\n kcode-k1-http-audio-artifacts = \"0.4.0\"",
good_manifest()
)))
.is_err()
);
}
#[test]
fn rejects_old_audio_and_displaced_social_lines() {
for line in [
"kcode-k1-audio-classification = \"0.5.10\"",
"kcode-k1-full-audio = \"0.3.7\"",
"kcode-k1-access-full-audio = \"0.9.4\"",
"kcode-k1-http-audio = \"0.3.1\"",
"kcode-k1-peering = \"0.3.0\"",
"kcode-k1-chat-service = \"0.10.2\"",
"kcode-k1-ktool-social = \"0.1.0\"",
] {
assert!(
std::panic::catch_unwind(|| verify_manifest(&format!(
"{}\n{line}",
good_manifest()
)))
.is_err()
);
}
}
#[test]
fn rejects_exact_internal_pin() {
assert!(
std::panic::catch_unwind(|| verify_manifest(&format!(
"{}\nkcode-k1-peering = \"=0.3.1\"",
good_manifest()
)))
.is_err()
);
}
#[test]
fn rejects_unrelated_obsolete_line() {
assert!(
std::panic::catch_unwind(|| verify_manifest(&format!(
"{}\nkcode-k1-http-chat = \"0.7.1\"",
good_manifest()
)))
.is_err()
);
}
}