Skip to main content

kcode_k1_daemon_lib_testkit/
lib.rs

1#![forbid(unsafe_code)]
2
3const REQUIRED_LINES: &[&str] = &[
4    "kcode-k1-access = \"0.6.2\"",
5    "kcode-k1-access-audio-classifier = \"0.1.0\"",
6    "kcode-k1-access-full-audio = \"0.9.4\"",
7    "kcode-k1-access-launch-nodes = \"0.2.0\"",
8    "kcode-k1-access-persons = \"0.3.0\"",
9    "kcode-k1-access-profiles = \"0.6.2\"",
10    "kcode-k1-audio-classification = \"0.5.10\"",
11    "kcode-k1-audio-classifier = \"0.1.1\"",
12    "kcode-k1-authority-filters = \"0.2.0\"",
13    "kcode-k1-chat-service = \"0.10.0\"",
14    "kcode-k1-codex-adapter = \"0.5.1\"",
15    "kcode-k1-codex-websearch = \"0.1.0\"",
16    "kcode-k1-daemon-provider-config = \"0.1.6\"",
17    "kcode-k1-full-audio = \"0.3.7\"",
18    "kcode-k1-http-access-context = \"0.2.0\"",
19    "kcode-k1-http-access-profile-presentation = \"0.1.0\"",
20    "kcode-k1-http-audio = \"0.3.1\"",
21    "kcode-k1-http-audio-artifacts = \"0.4.0\"",
22    "kcode-k1-http-chat = \"0.7.1\"",
23    "kcode-k1-http-launch-nodes = \"0.3.0\"",
24    "kcode-k1-http-people = \"0.9.0\"",
25    "kcode-k1-http-persons = \"0.3.0\"",
26    "kcode-k1-launch-nodes = \"0.3.0\"",
27    "kcode-k1-peering = \"0.3.0\"",
28    "kcode-k1-txn-ordering = \"0.5.1\"",
29];
30
31const OBSOLETE_LINES: &[&str] = &[
32    "kcode-k1-access = \"0.6.1\"",
33    "kcode-k1-access-full-audio = \"0.9.1\"",
34    "kcode-k1-audio-classification = \"0.5.9\"",
35    "kcode-k1-chat-service = \"0.3.0\"",
36    "kcode-k1-chat-service = \"0.6.0\"",
37    "kcode-k1-chat-service = \"0.7.0\"",
38    "kcode-k1-chat-service = \"0.8.0\"",
39    "kcode-k1-chat-service = \"0.9.0\"",
40    "kcode-k1-codex-adapter = \"0.5.0\"",
41    "kcode-k1-daemon-provider-config = \"0.1.4\"",
42    "kcode-k1-daemon-provider-config = \"0.1.5\"",
43    "kcode-k1-http-audio = \"0.3.0\"",
44    "kcode-k1-http-chat = \"0.2.0\"",
45    "kcode-k1-http-chat = \"0.5.0\"",
46    "kcode-k1-http-chat = \"0.6.0\"",
47    "kcode-k1-http-chat = \"0.6.1\"",
48    "kcode-k1-http-chat = \"0.7.0\"",
49    "kcode-k1-http-launch-nodes = \"0.2.0\"",
50    "kcode-k1-http-audio-artifacts = \"0.3.0\"",
51];
52
53pub fn verify_manifest(manifest: &str) {
54    for required in REQUIRED_LINES {
55        assert!(
56            manifest.lines().any(|line| line == *required),
57            "missing required manifest line: {required}"
58        );
59    }
60    for obsolete in OBSOLETE_LINES {
61        assert!(
62            !manifest.lines().any(|line| line == *obsolete),
63            "obsolete manifest line: {obsolete}"
64        );
65    }
66    assert!(
67        !manifest.lines().any(|line| line.contains(" = \"=")),
68        "manifest contains an exact internal pin"
69    );
70}
71
72#[cfg(test)]
73mod tests {
74    use super::*;
75
76    fn good_manifest() -> String {
77        REQUIRED_LINES.join("\n")
78    }
79
80    #[test]
81    fn accepts_current_manifest() {
82        verify_manifest(&good_manifest());
83    }
84
85    #[test]
86    #[should_panic(expected = "missing required manifest line")]
87    fn rejects_missing_required_line() {
88        verify_manifest(&good_manifest().replacen(
89            "kcode-k1-http-audio-artifacts = \"0.4.0\"\n",
90            "",
91            1,
92        ));
93    }
94
95    #[test]
96    #[should_panic(expected = "obsolete manifest line")]
97    fn rejects_obsolete_line() {
98        verify_manifest(&format!(
99            "{}\nkcode-k1-http-chat = \"0.7.0\"",
100            good_manifest()
101        ));
102    }
103
104    #[test]
105    #[should_panic(expected = "exact internal pin")]
106    fn rejects_exact_internal_pin() {
107        verify_manifest(&format!(
108            "{}\nkcode-k1-peering = \"=0.3.1\"",
109            good_manifest()
110        ));
111    }
112}