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-bootstrap-state = \"0.1.0\"",
14 "kcode-k1-chat-service = \"0.11.0\"",
15 "kcode-k1-codex-adapter = \"0.5.3\"",
16 "kcode-k1-codex-websearch = \"0.2.0\"",
17 "kcode-k1-daemon-code-services = \"0.1.9\"",
18 "kcode-k1-daemon-http-boundary = \"0.1.1\"",
19 "kcode-k1-daemon-provider-config = \"0.2.0\"",
20 "kcode-k1-daemon-startup-error = \"0.1.1\"",
21 "kcode-k1-daemon-web-startup = \"0.1.1\"",
22 "kcode-k1-full-audio = \"0.4.0\"",
23 "kcode-k1-http-access-context = \"0.2.0\"",
24 "kcode-k1-http-access-profile-presentation = \"0.1.0\"",
25 "kcode-k1-http-audio = \"0.4.0\"",
26 "kcode-k1-http-chat = \"0.7.3\"",
27 "kcode-k1-http-kmap = \"0.1.0\"",
28 "kcode-k1-http-launch-nodes = \"0.3.0\"",
29 "kcode-k1-http-people = \"0.9.0\"",
30 "kcode-k1-http-persons = \"0.3.0\"",
31 "kcode-k1-ktool-set-launch-node = \"0.1.1\"",
32 "kcode-k1-ktool-social = \"0.1.1\"",
33 "kcode-k1-launch-nodes = \"0.4.0\"",
34 "kcode-k1-loom-bootstrap = \"0.1.0\"",
35 "kcode-k1-objects = \"0.2.2\"",
36 "kcode-k1-peering = \"0.3.1\"",
37 "kcode-k1-txn-ordering = \"0.5.1\"",
38 "kcode-speaker-v3-analysis = \"0.3.5\"",
39];
40
41const OBSOLETE_LINES: &[&str] = &[
42 "kcode-k1-chat-service = \"0.10.9\"",
43 "kcode-k1-codex-adapter = \"0.5.1\"",
44 "kcode-k1-daemon-code-services = \"0.1.8\"",
45 "kcode-k1-daemon-provider-config = \"0.1.6\"",
46 "kcode-k1-daemon-startup-error = \"0.1.0\"",
47 "kcode-k1-daemon-web-startup = \"0.1.0\"",
48 "kcode-k1-http-chat = \"0.7.2\"",
49 "kcode-k1-launch-nodes = \"0.3.0\"",
50 "kcode-k1-objects = \"0.2.1\"",
51 "kcode-k1-peering = \"0.3.0\"",
52];
53
54const REQUIRED_SOURCE: &[&str] = &[
55 "AudioClassification::open(",
56 ".shutdown()",
57 "kcode_k1_http_audio::authenticated_routes",
58 "SocialKtools::new(",
59 "SetLaunchNodeKtool::new(",
60 "let web = open(",
61 "web.router()",
62 "web.projection()",
63 "CodeServices::open(",
64 "let rust_projection = code_services.rust_projection();",
65 ".into_parts()",
66 "K1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(",
67 "K1BootstrapState::open(",
68 "ensure_loom_bootstrap(",
69 "BootstrapServices {",
70 "state: &bootstrap_state",
71 "rust_projection: &rust_projection",
72 "with_cause(\"Loom bootstrap\")",
73 "with_cause(\"daemon files\")",
74 "with_cause(\"Code services\")",
75 "redacted_stage(\"Vault\")",
76 "redacted_stage(\"Gemini API key\")",
77 "redacted_stage(\"Gemini client\")",
78];
79
80const PROHIBITED_SOURCE: &[&str] = &[
81 "audio-classification-v2",
82 "http_audio_artifacts",
83 "retry_fragment",
84 "artifact_route",
85 "open_router(",
86 "RustCodeKtoolService::new(",
87 "K1WebCodeKtoolService::new(",
88 "let chat = K1ChatService::open(",
89 "K1ChatService::open_with_social(",
90 "K1ChatService::open_with_social_and_set_launch_node(",
91 ".map_err(stage(",
92 "StartupError::Stage(",
93];
94
95pub fn verify_manifest(manifest: &str) {
96 for required in REQUIRED_LINES {
97 assert!(
98 manifest.lines().any(|line| line == *required),
99 "missing required manifest line: {required}"
100 );
101 }
102 for obsolete in OBSOLETE_LINES {
103 assert!(
104 !manifest.lines().any(|line| line == *obsolete),
105 "obsolete manifest line: {obsolete}"
106 );
107 }
108 assert!(
109 !manifest.lines().any(|line| line
110 .trim_start()
111 .starts_with("kcode-k1-http-audio-artifacts")),
112 "artifact manifest selection"
113 );
114 assert!(
115 !manifest.lines().any(|line| line.contains(" = \"=")),
116 "manifest contains an exact internal pin"
117 );
118}
119
120pub fn verify_source(source: &str) {
121 for required in REQUIRED_SOURCE {
122 assert!(
123 source.contains(required),
124 "missing required source evidence: {required}"
125 );
126 }
127 for prohibited in PROHIBITED_SOURCE {
128 assert!(
129 !source.contains(prohibited),
130 "prohibited source token: {prohibited}"
131 );
132 }
133 let bootstrap = source.find("ensure_loom_bootstrap(").unwrap();
134 let invites = source
135 .find("kcode_k1_daemon_invite_stock::reconcile(")
136 .expect("invite-stock call is required");
137 let listener = source
138 .find("Boundary::bind_with_public(")
139 .expect("listener binding is required");
140 assert!(
141 bootstrap < invites && invites < listener,
142 "Loom bootstrap must precede invite stock and listener binding"
143 );
144}
145
146#[cfg(test)]
147mod tests {
148 use super::*;
149
150 fn good_manifest() -> String {
151 REQUIRED_LINES.join("\n")
152 }
153
154 fn good_source() -> &'static str {
155 "AudioClassification::open(
156service.shutdown()
157kcode_k1_http_audio::authenticated_routes
158SocialKtools::new(
159SetLaunchNodeKtool::new(
160let web = open(
161web.router()
162web.projection()
163CodeServices::open(
164let rust_projection = code_services.rust_projection();
165code_services.into_parts()
166K1ChatService::open_with_social_and_set_launch_node_and_rust_code_and_web_code(
167K1BootstrapState::open(
168ensure_loom_bootstrap(
169BootstrapServices {
170state: &bootstrap_state
171rust_projection: &rust_projection
172with_cause(\"Loom bootstrap\")
173kcode_k1_daemon_invite_stock::reconcile(
174Boundary::bind_with_public(
175with_cause(\"daemon files\")
176with_cause(\"Code services\")
177redacted_stage(\"Vault\")
178redacted_stage(\"Gemini API key\")
179redacted_stage(\"Gemini client\")"
180 }
181
182 #[test]
183 fn accepts_current_inputs() {
184 verify_manifest(&good_manifest());
185 verify_source(good_source());
186 }
187
188 #[test]
189 fn rejects_missing_current_selections() {
190 for line in [
191 "kcode-k1-bootstrap-state = \"0.1.0\"",
192 "kcode-k1-chat-service = \"0.11.0\"",
193 "kcode-k1-daemon-code-services = \"0.1.9\"",
194 "kcode-k1-loom-bootstrap = \"0.1.0\"",
195 "kcode-k1-objects = \"0.2.2\"",
196 ] {
197 assert!(
198 std::panic::catch_unwind(|| verify_manifest(&good_manifest().replace(line, "")))
199 .is_err()
200 );
201 }
202 }
203
204 #[test]
205 fn rejects_missing_prohibited_or_misordered_source_evidence() {
206 for evidence in REQUIRED_SOURCE {
207 assert!(
208 std::panic::catch_unwind(|| verify_source(&good_source().replace(evidence, "")))
209 .is_err()
210 );
211 }
212 for token in PROHIBITED_SOURCE {
213 assert!(
214 std::panic::catch_unwind(|| verify_source(&format!("{} {token}", good_source())))
215 .is_err()
216 );
217 }
218 let misordered = good_source()
219 .replace("ensure_loom_bootstrap(", "BOOTSTRAP(")
220 .replace(
221 "Boundary::bind_with_public(",
222 "ensure_loom_bootstrap(\nBoundary::bind_with_public(",
223 );
224 assert!(std::panic::catch_unwind(|| verify_source(&misordered)).is_err());
225 }
226
227 #[test]
228 fn rejects_obsolete_artifact_and_exact_pin_inputs() {
229 for line in OBSOLETE_LINES {
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}