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