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