kcode_k1_daemon_lib_testkit/
lib.rs1#![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.10.0\"",
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.6.0\"",
11 "kcode-k1-audio-classifier = \"0.1.1\"",
12 "kcode-k1-authority-filters = \"0.2.0\"",
13 "kcode-k1-chat-service = \"0.11.0\"",
14 "kcode-k1-codex-adapter = \"0.5.3\"",
15 "kcode-k1-codex-websearch = \"0.2.0\"",
16 "kcode-k1-daemon-code-services = \"0.1.8\"",
17 "kcode-k1-daemon-http-boundary = \"0.1.1\"",
18 "kcode-k1-daemon-provider-config = \"0.2.0\"",
19 "kcode-k1-daemon-startup-error = \"0.1.1\"",
20 "kcode-k1-daemon-web-startup = \"0.1.1\"",
21 "kcode-k1-full-audio = \"0.4.0\"",
22 "kcode-k1-http-access-context = \"0.2.0\"",
23 "kcode-k1-http-access-profile-presentation = \"0.1.0\"",
24 "kcode-k1-http-audio = \"0.4.0\"",
25 "kcode-k1-http-chat = \"0.7.3\"",
26 "kcode-k1-http-kmap = \"0.1.0\"",
27 "kcode-k1-http-launch-nodes = \"0.3.0\"",
28 "kcode-k1-http-people = \"0.9.0\"",
29 "kcode-k1-http-persons = \"0.3.0\"",
30 "kcode-k1-ktool-set-launch-node = \"0.1.1\"",
31 "kcode-k1-ktool-social = \"0.1.1\"",
32 "kcode-k1-launch-nodes = \"0.4.0\"",
33 "kcode-k1-objects = \"0.2.2\"",
34 "kcode-k1-peering = \"0.3.1\"",
35 "kcode-k1-txn-ordering = \"0.5.1\"",
36 "kcode-speaker-v3-analysis = \"0.3.5\"",
37];
38
39const OBSOLETE_LINES: &[&str] = &[
40 "kcode-k1-access = \"0.6.1\"",
41 "kcode-k1-access-full-audio = \"0.9.1\"",
42 "kcode-k1-access-full-audio = \"0.9.4\"",
43 "kcode-k1-access-launch-nodes = \"0.2.0\"",
44 "kcode-k1-audio-classification = \"0.5.9\"",
45 "kcode-k1-audio-classification = \"0.5.10\"",
46 "kcode-k1-chat-service = \"0.3.0\"",
47 "kcode-k1-chat-service = \"0.6.0\"",
48 "kcode-k1-chat-service = \"0.7.0\"",
49 "kcode-k1-chat-service = \"0.8.0\"",
50 "kcode-k1-chat-service = \"0.9.0\"",
51 "kcode-k1-chat-service = \"0.10.0\"",
52 "kcode-k1-chat-service = \"0.10.1\"",
53 "kcode-k1-chat-service = \"0.10.2\"",
54 "kcode-k1-chat-service = \"0.10.3\"",
55 "kcode-k1-chat-service = \"0.10.4\"",
56 "kcode-k1-chat-service = \"0.10.5\"",
57 "kcode-k1-chat-service = \"0.10.6\"",
58 "kcode-k1-chat-service = \"0.10.7\"",
59 "kcode-k1-chat-service = \"0.10.8\"",
60 "kcode-k1-chat-service = \"0.10.9\"",
61 "kcode-k1-codex-adapter = \"0.5.0\"",
62 "kcode-k1-codex-adapter = \"0.5.1\"",
63 "kcode-k1-codex-websearch = \"0.1.0\"",
64 "kcode-k1-daemon-code-services = \"0.1.0\"",
65 "kcode-k1-daemon-code-services = \"0.1.1\"",
66 "kcode-k1-daemon-code-services = \"0.1.2\"",
67 "kcode-k1-daemon-code-services = \"0.1.3\"",
68 "kcode-k1-daemon-code-services = \"0.1.4\"",
69 "kcode-k1-daemon-code-services = \"0.1.5\"",
70 "kcode-k1-daemon-code-services = \"0.1.6\"",
71 "kcode-k1-daemon-code-services = \"0.1.7\"",
72 "kcode-k1-daemon-http-boundary = \"0.1.0\"",
73 "kcode-k1-daemon-provider-config = \"0.1.4\"",
74 "kcode-k1-daemon-provider-config = \"0.1.5\"",
75 "kcode-k1-daemon-provider-config = \"0.1.6\"",
76 "kcode-k1-daemon-startup-error = \"0.1.0\"",
77 "kcode-k1-daemon-web-startup = \"0.1.0\"",
78 "kcode-k1-full-audio = \"0.3.7\"",
79 "kcode-k1-http-audio = \"0.3.0\"",
80 "kcode-k1-http-audio = \"0.3.1\"",
81 "kcode-k1-http-chat = \"0.2.0\"",
82 "kcode-k1-http-chat = \"0.5.0\"",
83 "kcode-k1-http-chat = \"0.6.0\"",
84 "kcode-k1-http-chat = \"0.6.1\"",
85 "kcode-k1-http-chat = \"0.7.0\"",
86 "kcode-k1-http-chat = \"0.7.1\"",
87 "kcode-k1-http-chat = \"0.7.2\"",
88 "kcode-k1-http-launch-nodes = \"0.2.0\"",
89 "kcode-k1-ktool-set-launch-node = \"0.1.0\"",
90 "kcode-k1-ktool-social = \"0.1.0\"",
91 "kcode-k1-launch-nodes = \"0.3.0\"",
92 "kcode-k1-objects = \"0.2.1\"",
93 "kcode-k1-peering = \"0.3.0\"",
94 "kcode-k1-web-code-ktool-service = \"0.1.1\"",
95 "kcode-k1-web-http = \"0.1.0\"",
96];
97
98const REQUIRED_SOURCE: &[&str] = &[
99 "AudioClassification::open(",
100 ".shutdown()",
101 "kcode_k1_http_audio::authenticated_routes",
102 "SocialKtools::new(",
103 "SetLaunchNodeKtool::new(",
104 "let web = open(",
105 "web.router()",
106 "web.projection()",
107 "CodeServices::open(",
108 ".into_parts()",
109 "K1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(",
110 "with_cause(\"daemon files\")",
111 "with_cause(\"Code services\")",
112 "redacted_stage(\"Vault\")",
113 "redacted_stage(\"Gemini API key\")",
114 "redacted_stage(\"Gemini client\")",
115];
116
117const PROHIBITED_SOURCE: &[&str] = &[
118 "audio-classification-v2",
119 "http_audio_artifacts",
120 "retry_fragment",
121 "artifact_route",
122 "open_router(",
123 "RustCodeKtoolService::new(",
124 "K1WebCodeKtoolService::new(",
125 "let chat = K1ChatService::open(",
126 "K1ChatService::open_with_social(",
127 "K1ChatService::open_with_social_and_set_launch_node(",
128 ".map_err(stage(",
129 "StartupError::Stage(",
130];
131
132pub fn verify_manifest(manifest: &str) {
133 for required in REQUIRED_LINES {
134 assert!(
135 manifest.lines().any(|line| line == *required),
136 "missing required manifest line: {required}"
137 );
138 }
139 for obsolete in OBSOLETE_LINES {
140 assert!(
141 !manifest.lines().any(|line| line == *obsolete),
142 "obsolete manifest line: {obsolete}"
143 );
144 }
145 assert!(
146 !manifest.lines().any(|line| line
147 .trim_start()
148 .starts_with("kcode-k1-http-audio-artifacts")),
149 "artifact manifest selection"
150 );
151 assert!(
152 !manifest.lines().any(|line| line.contains(" = \"=")),
153 "manifest contains an exact internal pin"
154 );
155}
156
157pub fn verify_source(source: &str) {
158 for required in REQUIRED_SOURCE {
159 assert!(
160 source.contains(required),
161 "missing required source evidence: {required}"
162 );
163 }
164 for prohibited in PROHIBITED_SOURCE {
165 assert!(
166 !source.contains(prohibited),
167 "prohibited source token: {prohibited}"
168 );
169 }
170}
171
172#[cfg(test)]
173mod tests {
174 use super::*;
175
176 fn good_manifest() -> String {
177 REQUIRED_LINES.join("\n")
178 }
179 fn good_source() -> &'static str {
180 "AudioClassification::open(\nservice.shutdown()\nkcode_k1_http_audio::authenticated_routes\nSocialKtools::new(\nSetLaunchNodeKtool::new(\nlet web = open(\nweb.router()\nweb.projection()\nCodeServices::open(\ncode_services.into_parts()\nK1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(\nwith_cause(\"daemon files\")\nwith_cause(\"Code services\")\nredacted_stage(\"Vault\")\nredacted_stage(\"Gemini API key\")\nredacted_stage(\"Gemini client\")"
181 }
182
183 #[test]
184 fn accepts_current_inputs() {
185 verify_manifest(&good_manifest());
186 verify_source(good_source());
187 }
188
189 #[test]
190 fn rejects_missing_current_selections() {
191 for line in [
192 "kcode-k1-chat-service = \"0.11.0\"",
193 "kcode-k1-daemon-provider-config = \"0.2.0\"",
194 "kcode-k1-daemon-code-services = \"0.1.8\"",
195 "kcode-k1-daemon-startup-error = \"0.1.1\"",
196 "kcode-k1-daemon-web-startup = \"0.1.1\"",
197 "kcode-k1-objects = \"0.2.2\"",
198 "kcode-k1-http-chat = \"0.7.3\"",
199 ] {
200 assert!(
201 std::panic::catch_unwind(|| verify_manifest(&good_manifest().replace(line, "")))
202 .is_err()
203 );
204 }
205 }
206
207 #[test]
208 fn rejects_missing_or_prohibited_source_evidence() {
209 for evidence in REQUIRED_SOURCE {
210 assert!(
211 std::panic::catch_unwind(|| verify_source(&good_source().replace(evidence, "")))
212 .is_err()
213 );
214 }
215 for token in PROHIBITED_SOURCE {
216 assert!(
217 std::panic::catch_unwind(|| verify_source(&format!("{} {token}", good_source())))
218 .is_err()
219 );
220 }
221 }
222
223 #[test]
224 fn rejects_old_selections_artifact_package_and_exact_pins() {
225 for line in [
226 "kcode-k1-chat-service = \"0.10.9\"",
227 "kcode-k1-daemon-provider-config = \"0.1.6\"",
228 "kcode-k1-http-chat = \"0.7.2\"",
229 ] {
230 assert!(
231 std::panic::catch_unwind(|| verify_manifest(&format!(
232 "{}\n{line}",
233 good_manifest()
234 )))
235 .is_err()
236 );
237 }
238 assert!(
239 std::panic::catch_unwind(|| verify_manifest(&format!(
240 "{}\nkcode-k1-http-audio-artifacts = \"0.4.0\"",
241 good_manifest()
242 )))
243 .is_err()
244 );
245 assert!(
246 std::panic::catch_unwind(|| verify_manifest(&format!(
247 "{}\nkcode-k1-peering = \"=0.3.1\"",
248 good_manifest()
249 )))
250 .is_err()
251 );
252 }
253
254 #[test]
255 fn full_chat_constructor_does_not_match_former_names() {
256 let current =
257 "K1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(";
258 assert!(!current.contains("K1ChatService::open_with_social("));
259 assert!(!current.contains("K1ChatService::open_with_social_and_set_launch_node("));
260 }
261}