#![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-bootstrap-state = \"0.1.0\"",
"kcode-k1-chat-service = \"0.11.0\"",
"kcode-k1-codex-adapter = \"0.5.3\"",
"kcode-k1-codex-websearch = \"0.2.0\"",
"kcode-k1-daemon-code-services = \"0.1.9\"",
"kcode-k1-daemon-http-boundary = \"0.1.1\"",
"kcode-k1-daemon-provider-config = \"0.2.0\"",
"kcode-k1-daemon-startup-error = \"0.1.1\"",
"kcode-k1-daemon-web-startup = \"0.1.1\"",
"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.3\"",
"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-set-launch-node = \"0.1.1\"",
"kcode-k1-ktool-social = \"0.1.1\"",
"kcode-k1-launch-nodes = \"0.4.0\"",
"kcode-k1-loom-bootstrap = \"0.1.0\"",
"kcode-k1-objects = \"0.2.2\"",
"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-chat-service = \"0.10.9\"",
"kcode-k1-codex-adapter = \"0.5.1\"",
"kcode-k1-daemon-code-services = \"0.1.8\"",
"kcode-k1-daemon-provider-config = \"0.1.6\"",
"kcode-k1-daemon-startup-error = \"0.1.0\"",
"kcode-k1-daemon-web-startup = \"0.1.0\"",
"kcode-k1-http-chat = \"0.7.2\"",
"kcode-k1-launch-nodes = \"0.3.0\"",
"kcode-k1-objects = \"0.2.1\"",
"kcode-k1-peering = \"0.3.0\"",
];
const REQUIRED_SOURCE: &[&str] = &[
"AudioClassification::open(",
".shutdown()",
"kcode_k1_http_audio::authenticated_routes",
"SocialKtools::new(",
"SetLaunchNodeKtool::new(",
"let web = open(",
"web.router()",
"web.projection()",
"CodeServices::open(",
"let rust_projection = code_services.rust_projection();",
".into_parts()",
"K1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(",
"K1BootstrapState::open(",
"ensure_loom_bootstrap(",
"BootstrapServices {",
"state: &bootstrap_state",
"rust_projection: &rust_projection",
"with_cause(\"Loom bootstrap\")",
"with_cause(\"daemon files\")",
"with_cause(\"Code services\")",
"redacted_stage(\"Vault\")",
"redacted_stage(\"Gemini API key\")",
"redacted_stage(\"Gemini client\")",
];
const PROHIBITED_SOURCE: &[&str] = &[
"audio-classification-v2",
"http_audio_artifacts",
"retry_fragment",
"artifact_route",
"open_router(",
"RustCodeKtoolService::new(",
"K1WebCodeKtoolService::new(",
"let chat = K1ChatService::open(",
"K1ChatService::open_with_social(",
"K1ChatService::open_with_social_and_set_launch_node(",
".map_err(stage(",
"StartupError::Stage(",
];
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}"
);
}
let bootstrap = source.find("ensure_loom_bootstrap(").unwrap();
let invites = source
.find("kcode_k1_daemon_invite_stock::reconcile(")
.expect("invite-stock call is required");
let listener = source
.find("Boundary::bind_with_public(")
.expect("listener binding is required");
assert!(
bootstrap < invites && invites < listener,
"Loom bootstrap must precede invite stock and listener binding"
);
}
#[cfg(test)]
mod tests {
use super::*;
fn good_manifest() -> String {
REQUIRED_LINES.join("\n")
}
fn good_source() -> &'static str {
"AudioClassification::open(
service.shutdown()
kcode_k1_http_audio::authenticated_routes
SocialKtools::new(
SetLaunchNodeKtool::new(
let web = open(
web.router()
web.projection()
CodeServices::open(
let rust_projection = code_services.rust_projection();
code_services.into_parts()
K1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(
K1BootstrapState::open(
ensure_loom_bootstrap(
BootstrapServices {
state: &bootstrap_state
rust_projection: &rust_projection
with_cause(\"Loom bootstrap\")
kcode_k1_daemon_invite_stock::reconcile(
Boundary::bind_with_public(
with_cause(\"daemon files\")
with_cause(\"Code services\")
redacted_stage(\"Vault\")
redacted_stage(\"Gemini API key\")
redacted_stage(\"Gemini client\")"
}
#[test]
fn accepts_current_inputs() {
verify_manifest(&good_manifest());
verify_source(good_source());
}
#[test]
fn rejects_missing_current_selections() {
for line in [
"kcode-k1-bootstrap-state = \"0.1.0\"",
"kcode-k1-chat-service = \"0.11.0\"",
"kcode-k1-daemon-code-services = \"0.1.9\"",
"kcode-k1-loom-bootstrap = \"0.1.0\"",
"kcode-k1-objects = \"0.2.2\"",
] {
assert!(
std::panic::catch_unwind(|| verify_manifest(&good_manifest().replace(line, "")))
.is_err()
);
}
}
#[test]
fn rejects_missing_prohibited_or_misordered_source_evidence() {
for evidence in REQUIRED_SOURCE {
assert!(
std::panic::catch_unwind(|| verify_source(&good_source().replace(evidence, "")))
.is_err()
);
}
for token in PROHIBITED_SOURCE {
assert!(
std::panic::catch_unwind(|| verify_source(&format!("{} {token}", good_source())))
.is_err()
);
}
let misordered = good_source()
.replace("ensure_loom_bootstrap(", "BOOTSTRAP(")
.replace(
"Boundary::bind_with_public(",
"ensure_loom_bootstrap(\nBoundary::bind_with_public(",
);
assert!(std::panic::catch_unwind(|| verify_source(&misordered)).is_err());
}
#[test]
fn rejects_obsolete_artifact_and_exact_pin_inputs() {
for line in OBSOLETE_LINES {
assert!(
std::panic::catch_unwind(|| verify_manifest(&format!(
"{}\n{line}",
good_manifest()
)))
.is_err()
);
}
assert!(
std::panic::catch_unwind(|| verify_manifest(&format!(
"{}\nkcode-k1-http-audio-artifacts = \"0.4.0\"",
good_manifest()
)))
.is_err()
);
assert!(
std::panic::catch_unwind(|| verify_manifest(&format!(
"{}\nkcode-k1-peering = \"=0.3.1\"",
good_manifest()
)))
.is_err()
);
}
#[test]
fn full_chat_constructor_does_not_match_former_names() {
let current =
"K1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(";
assert!(!current.contains("K1ChatService::open_with_social("));
assert!(!current.contains("K1ChatService::open_with_social_and_set_launch_node("));
}
}