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.2\"",
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.1\"",
14    "kcode-k1-codex-adapter = \"0.5.3\"",
15    "kcode-k1-codex-websearch = \"0.2.0\"",
16    "kcode-k1-daemon-http-boundary = \"0.1.1\"",
17    "kcode-k1-daemon-provider-config = \"0.1.6\"",
18    "kcode-k1-daemon-web-startup = \"0.1.0\"",
19    "kcode-k1-full-audio = \"0.3.7\"",
20    "kcode-k1-http-access-context = \"0.2.0\"",
21    "kcode-k1-http-access-profile-presentation = \"0.1.0\"",
22    "kcode-k1-http-audio = \"0.3.1\"",
23    "kcode-k1-http-audio-artifacts = \"0.4.0\"",
24    "kcode-k1-http-chat = \"0.7.2\"",
25    "kcode-k1-http-kmap = \"0.1.0\"",
26    "kcode-k1-http-launch-nodes = \"0.3.0\"",
27    "kcode-k1-http-people = \"0.9.0\"",
28    "kcode-k1-http-persons = \"0.3.0\"",
29    "kcode-k1-launch-nodes = \"0.4.0\"",
30    "kcode-k1-peering = \"0.3.0\"",
31    "kcode-k1-txn-ordering = \"0.5.1\"",
32];
33
34const OBSOLETE_LINES: &[&str] = &[
35    "kcode-k1-access = \"0.6.1\"",
36    "kcode-k1-access-full-audio = \"0.9.1\"",
37    "kcode-k1-access-launch-nodes = \"0.2.0\"",
38    "kcode-k1-audio-classification = \"0.5.9\"",
39    "kcode-k1-chat-service = \"0.3.0\"",
40    "kcode-k1-chat-service = \"0.6.0\"",
41    "kcode-k1-chat-service = \"0.7.0\"",
42    "kcode-k1-chat-service = \"0.8.0\"",
43    "kcode-k1-chat-service = \"0.9.0\"",
44    "kcode-k1-chat-service = \"0.10.0\"",
45    "kcode-k1-codex-adapter = \"0.5.0\"",
46    "kcode-k1-codex-adapter = \"0.5.1\"",
47    "kcode-k1-codex-websearch = \"0.1.0\"",
48    "kcode-k1-daemon-http-boundary = \"0.1.0\"",
49    "kcode-k1-daemon-provider-config = \"0.1.4\"",
50    "kcode-k1-daemon-provider-config = \"0.1.5\"",
51    "kcode-k1-http-audio = \"0.3.0\"",
52    "kcode-k1-http-chat = \"0.2.0\"",
53    "kcode-k1-http-chat = \"0.5.0\"",
54    "kcode-k1-http-chat = \"0.6.0\"",
55    "kcode-k1-http-chat = \"0.6.1\"",
56    "kcode-k1-http-chat = \"0.7.0\"",
57    "kcode-k1-http-chat = \"0.7.1\"",
58    "kcode-k1-http-launch-nodes = \"0.2.0\"",
59    "kcode-k1-http-audio-artifacts = \"0.3.0\"",
60    "kcode-k1-launch-nodes = \"0.3.0\"",
61    "kcode-k1-web-http = \"0.1.0\"",
62];
63
64pub fn verify_manifest(manifest: &str) {
65    for required in REQUIRED_LINES {
66        assert!(
67            manifest.lines().any(|line| line == *required),
68            "missing required manifest line: {required}"
69        );
70    }
71    for obsolete in OBSOLETE_LINES {
72        assert!(
73            !manifest.lines().any(|line| line == *obsolete),
74            "obsolete manifest line: {obsolete}"
75        );
76    }
77    assert!(
78        !manifest.lines().any(|line| line.contains(" = \"=")),
79        "manifest contains an exact internal pin"
80    );
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86
87    fn good_manifest() -> String {
88        REQUIRED_LINES.join("\n")
89    }
90
91    #[test]
92    fn accepts_current_manifest() {
93        verify_manifest(&good_manifest());
94    }
95
96    #[test]
97    #[should_panic(expected = "missing required manifest line")]
98    fn rejects_missing_required_line() {
99        verify_manifest(&good_manifest().replacen(
100            "kcode-k1-http-audio-artifacts = \"0.4.0\"\n",
101            "",
102            1,
103        ));
104    }
105
106    #[test]
107    #[should_panic(expected = "missing required manifest line")]
108    fn rejects_missing_http_chat_0_7_2() {
109        verify_manifest(&good_manifest().replacen("kcode-k1-http-chat = \"0.7.2\"\n", "", 1));
110    }
111
112    #[test]
113    #[should_panic(expected = "missing required manifest line")]
114    fn rejects_missing_http_kmap() {
115        verify_manifest(&good_manifest().replacen("kcode-k1-http-kmap = \"0.1.0\"\n", "", 1));
116    }
117
118    #[test]
119    #[should_panic(expected = "missing required manifest line")]
120    fn rejects_missing_daemon_web_startup() {
121        verify_manifest(&good_manifest().replacen(
122            "kcode-k1-daemon-web-startup = \"0.1.0\"\n",
123            "",
124            1,
125        ));
126    }
127
128    #[test]
129    #[should_panic(expected = "obsolete manifest line")]
130    fn rejects_displaced_access_launch_nodes() {
131        verify_manifest(&format!(
132            "{}\nkcode-k1-access-launch-nodes = \"0.2.0\"",
133            good_manifest()
134        ));
135    }
136
137    #[test]
138    #[should_panic(expected = "obsolete manifest line")]
139    fn rejects_displaced_launch_nodes() {
140        verify_manifest(&format!(
141            "{}\nkcode-k1-launch-nodes = \"0.3.0\"",
142            good_manifest()
143        ));
144    }
145
146    #[test]
147    #[should_panic(expected = "obsolete manifest line")]
148    fn rejects_displaced_daemon_http_boundary() {
149        verify_manifest(&format!(
150            "{}\nkcode-k1-daemon-http-boundary = \"0.1.0\"",
151            good_manifest()
152        ));
153    }
154
155    #[test]
156    #[should_panic(expected = "obsolete manifest line")]
157    fn rejects_direct_web_http() {
158        verify_manifest(&format!(
159            "{}\nkcode-k1-web-http = \"0.1.0\"",
160            good_manifest()
161        ));
162    }
163
164    #[test]
165    #[should_panic(expected = "obsolete manifest line")]
166    fn rejects_obsolete_line() {
167        verify_manifest(&format!(
168            "{}\nkcode-k1-http-chat = \"0.7.1\"",
169            good_manifest()
170        ));
171    }
172
173    #[test]
174    #[should_panic(expected = "exact internal pin")]
175    fn rejects_exact_internal_pin() {
176        verify_manifest(&format!(
177            "{}\nkcode-k1-peering = \"=0.3.1\"",
178            good_manifest()
179        ));
180    }
181}