Skip to main content

harn_parser/
harness_methods.rs

1//! Canonical mappings between typed `harness.<sub>.*` methods and the
2//! ambient builtin names that still back capability classification,
3//! lint migrations, and runtime dispatch.
4
5pub fn harness_stdio_ambient(method: &str) -> Option<&'static str> {
6    match method {
7        "print" => Some("print"),
8        "println" => Some("println"),
9        "eprint" => Some("eprint"),
10        "eprintln" => Some("eprintln"),
11        "read_line" => Some("read_line"),
12        "prompt" => Some("prompt_user"),
13        _ => None,
14    }
15}
16
17pub fn harness_term_ambient(method: &str) -> Option<&'static str> {
18    match method {
19        "width" => Some("term_width"),
20        "height" => Some("term_height"),
21        "read_password" => Some("read_password"),
22        _ => None,
23    }
24}
25
26pub fn harness_clock_ambient(method: &str) -> Option<&'static str> {
27    match method {
28        "now_ms" => Some("now_ms"),
29        "monotonic_ms" | "elapsed" => Some("monotonic_ms"),
30        "sleep_ms" => Some("sleep_ms"),
31        "timestamp" => Some("timestamp"),
32        _ => None,
33    }
34}
35
36pub fn harness_fs_ambient(method: &str) -> Option<&'static str> {
37    match method {
38        "read_text" | "read" | "read_file" => Some("read_file"),
39        "read_text_result" | "read_result" => Some("read_file_result"),
40        "read_bytes" | "read_file_bytes" => Some("read_file_bytes"),
41        "write_text" | "write" | "write_file" => Some("write_file"),
42        "write_bytes" | "write_file_bytes" => Some("write_file_bytes"),
43        "replace_text" => Some("replace_file"),
44        "replace_text_result" => Some("replace_file_result"),
45        "replace_bytes" => Some("replace_file_bytes"),
46        "replace_bytes_result" => Some("replace_file_bytes_result"),
47        "exists" | "file_exists" => Some("file_exists"),
48        "status" | "path_status" => Some("path_status"),
49        "delete" | "delete_file" | "remove" => Some("delete_file"),
50        "append" | "append_file" => Some("append_file"),
51        "append_locked" | "append_file_locked" => Some("append_file_locked"),
52        "list_dir" | "list" => Some("list_dir"),
53        "mkdir" | "create_dir" => Some("mkdir"),
54        "path_join" => Some("path_join"),
55        "copy" | "copy_file" => Some("copy_file"),
56        "temp_dir" => Some("temp_dir"),
57        "workspace_temp_dir" => Some("workspace_temp_dir"),
58        "mkdtemp" => Some("mkdtemp"),
59        "mkdtemp_in_workspace" => Some("mkdtemp_in_workspace"),
60        "stat" => Some("stat"),
61        "rename" | "move" | "move_file" => Some("move_file"),
62        "read_lines" => Some("read_lines"),
63        "walk" | "walk_dir" => Some("walk_dir"),
64        "glob" => Some("glob"),
65        "find_text" => Some("find_text"),
66        "find_evidence" => Some("find_evidence"),
67        _ => None,
68    }
69}
70
71pub fn harness_env_ambient(method: &str) -> Option<&'static str> {
72    match method {
73        "get" => Some("env"),
74        "get_or" => Some("env_or"),
75        _ => None,
76    }
77}
78
79pub fn harness_random_ambient(method: &str) -> Option<&'static str> {
80    match method {
81        "gen_f64" | "f64" | "random" => Some("random"),
82        "gen_u64" | "u64" => Some("random_int"),
83        "gen_range" | "range" | "random_int" | "int" => Some("random_int"),
84        "choice" | "random_choice" => Some("random_choice"),
85        "shuffle" | "random_shuffle" => Some("random_shuffle"),
86        _ => None,
87    }
88}
89
90pub fn harness_net_ambient(method: &str) -> Option<&'static str> {
91    match method {
92        "get" | "http_get" => Some("http_get"),
93        "post" | "http_post" => Some("http_post"),
94        "put" | "http_put" => Some("http_put"),
95        "patch" | "http_patch" => Some("http_patch"),
96        "delete" | "http_delete" => Some("http_delete"),
97        "request" | "http_request" => Some("http_request"),
98        "download" | "http_download" => Some("http_download"),
99        _ => None,
100    }
101}
102
103pub fn harness_process_ambient(method: &str) -> Option<&'static str> {
104    match method {
105        "spawn_captured" => Some("spawn_captured"),
106        _ => None,
107    }
108}
109
110pub fn harness_crypto_ambient(method: &str) -> Option<&'static str> {
111    match method {
112        "sha256" => Some("sha256_hex"),
113        _ => None,
114    }
115}
116
117pub fn harness_system_ambient(method: &str) -> Option<&'static str> {
118    match method {
119        "platform" => Some("system_platform"),
120        "cpu" => Some("system_cpu"),
121        "memory" => Some("system_memory"),
122        "gpus" => Some("system_gpus"),
123        "temperature" => Some("system_temperature"),
124        "processes" => Some("system_processes"),
125        _ => None,
126    }
127}
128
129pub fn harness_llm_ambient(method: &str) -> Option<&'static str> {
130    match method {
131        "catalog" => Some("llm_catalog"),
132        "catalog_refresh" => Some("llm_catalog_refresh"),
133        "providers" => Some("llm_provider_status"),
134        _ => None,
135    }
136}
137
138pub fn harness_secrets_ambient(method: &str) -> Option<&'static str> {
139    match method {
140        "read" | "read_bytes" | "write" | "rotate" | "lease" | "lease_bytes" => None,
141        _ => None,
142    }
143}
144
145pub fn harness_tenant_ambient(method: &str) -> Option<&'static str> {
146    match method {
147        "id" => Some("harness_tenant_id"),
148        "try_id" => Some("harness_tenant_try_id"),
149        _ => None,
150    }
151}
152
153pub fn harness_auth_ambient(method: &str) -> Option<&'static str> {
154    match method {
155        "is_authenticated" => Some("harness_auth_is_authenticated"),
156        "subject" => Some("harness_auth_subject"),
157        "try_subject" => Some("harness_auth_try_subject"),
158        "scheme" => Some("harness_auth_scheme"),
159        "try_scheme" => Some("harness_auth_try_scheme"),
160        "kind" => Some("harness_auth_kind"),
161        "scopes" => Some("harness_auth_scopes"),
162        "has_scope" => Some("harness_auth_has_scope"),
163        _ => None,
164    }
165}
166
167pub fn harness_obs_ambient(method: &str) -> Option<&'static str> {
168    match method {
169        "span" | "start_span" => Some("__obs_start_span"),
170        "end_span" => Some("__obs_end_span"),
171        "log" => Some("__obs_emit"),
172        "counter" => Some("__obs_counter"),
173        "histogram" => Some("__obs_histogram"),
174        "gauge" => Some("__obs_gauge"),
175        "request_id" => Some("__obs_request_id"),
176        _ => None,
177    }
178}
179
180/// `harness.verdict.*` — the verdict issuance authority. `issue(result_handle)`
181/// resolves the host-owned record of a real `run_test` execution and mints an
182/// opaque proof-of-execution receipt; there is no caller-constructible positive
183/// path and no caller-authored evidence can earn one.
184pub fn harness_verdict_ambient(method: &str) -> Option<&'static str> {
185    match method {
186        "issue" => Some("__harness_verdict_issue"),
187        // Handled VM-side (operates on the opaque receipt, which cannot cross the
188        // hostlib boundary); the mapped name is never dispatched to a builtin,
189        // it only marks the method as known to the typechecker.
190        "same_run" => Some("__harness_verdict_same_run"),
191        _ => None,
192    }
193}
194
195pub fn harness_sub_handle_ambient(sub_handle: &str, method: &str) -> Option<&'static str> {
196    match sub_handle {
197        "stdio" => harness_stdio_ambient(method),
198        "term" => harness_term_ambient(method),
199        "clock" => harness_clock_ambient(method),
200        "fs" => harness_fs_ambient(method),
201        "env" => harness_env_ambient(method),
202        "random" => harness_random_ambient(method),
203        "net" => harness_net_ambient(method),
204        "process" => harness_process_ambient(method),
205        "crypto" => harness_crypto_ambient(method),
206        "system" => harness_system_ambient(method),
207        "secrets" => harness_secrets_ambient(method),
208        "llm" => harness_llm_ambient(method),
209        "tenant" => harness_tenant_ambient(method),
210        "auth" => harness_auth_ambient(method),
211        "obs" => harness_obs_ambient(method),
212        "verdict" => harness_verdict_ambient(method),
213        _ => None,
214    }
215}
216
217pub fn harness_type_sub_handle(type_name: &str) -> Option<&'static str> {
218    match type_name {
219        "HarnessStdio" => Some("stdio"),
220        "HarnessTerm" => Some("term"),
221        "HarnessClock" => Some("clock"),
222        "HarnessFs" => Some("fs"),
223        "HarnessEnv" => Some("env"),
224        "HarnessRandom" => Some("random"),
225        "HarnessNet" => Some("net"),
226        "HarnessProcess" => Some("process"),
227        "HarnessCrypto" => Some("crypto"),
228        "HarnessSystem" => Some("system"),
229        "HarnessSecrets" => Some("secrets"),
230        "HarnessLlm" => Some("llm"),
231        "HarnessTenant" => Some("tenant"),
232        "HarnessAuth" => Some("auth"),
233        "HarnessObs" => Some("obs"),
234        "HarnessVerdict" => Some("verdict"),
235        _ => None,
236    }
237}
238
239pub fn harness_fs_replacement(name: &str) -> Option<&'static str> {
240    match name {
241        "read_file" => Some("harness.fs.read_text"),
242        "read_file_result" => Some("harness.fs.read_text_result"),
243        "read_file_bytes" => Some("harness.fs.read_bytes"),
244        "write_file" => Some("harness.fs.write_text"),
245        "write_file_bytes" => Some("harness.fs.write_bytes"),
246        "replace_file" => Some("harness.fs.replace_text"),
247        "replace_file_result" => Some("harness.fs.replace_text_result"),
248        "replace_file_bytes" => Some("harness.fs.replace_bytes"),
249        "replace_file_bytes_result" => Some("harness.fs.replace_bytes_result"),
250        "file_exists" => Some("harness.fs.exists"),
251        "path_status" => Some("harness.fs.status"),
252        "delete_file" => Some("harness.fs.delete"),
253        "append_file" => Some("harness.fs.append"),
254        "append_file_locked" => Some("harness.fs.append_locked"),
255        "list_dir" => Some("harness.fs.list_dir"),
256        "mkdir" => Some("harness.fs.mkdir"),
257        "copy_file" => Some("harness.fs.copy"),
258        "temp_dir" => Some("harness.fs.temp_dir"),
259        "workspace_temp_dir" => Some("harness.fs.workspace_temp_dir"),
260        "mkdtemp" => Some("harness.fs.mkdtemp"),
261        "mkdtemp_in_workspace" => Some("harness.fs.mkdtemp_in_workspace"),
262        "stat" => Some("harness.fs.stat"),
263        "move_file" => Some("harness.fs.rename"),
264        "read_lines" => Some("harness.fs.read_lines"),
265        "walk_dir" => Some("harness.fs.walk"),
266        "glob" => Some("harness.fs.glob"),
267        "find_text" => Some("harness.fs.find_text"),
268        "find_evidence" => Some("harness.fs.find_evidence"),
269        _ => None,
270    }
271}