harn-vm 0.10.166

Async bytecode virtual machine for the Harn programming language
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
//! OpenAI-family route rows: reasoning effort surfaces, tool-search
//! gating, token-parameter quirks, and the hosts that inherit the family.

use super::lookup_tests_support::reset;
use super::model::WireDialect;
use super::*;

#[test]
fn gpt6_sampling_condition_is_direct_and_not_inherited_by_unforwarded_routes() {
    reset();
    let none = crate::llm::api::ThinkingConfig::Effort {
        level: ReasoningEffort::None,
    };
    let low = crate::llm::api::ThinkingConfig::Effort {
        level: ReasoningEffort::Low,
    };
    for (provider, model) in [("openai", "gpt-6-luna"), ("openai", "gpt-6-sol")] {
        for thinking in [&crate::llm::api::ThinkingConfig::Disabled, &low] {
            assert!(
                admit_portable_option_for_thinking(
                    provider,
                    model,
                    thinking,
                    PortableOption::Temperature,
                    None
                )
                .is_err(),
                "{provider}:{model}"
            );
        }
        admit_portable_option_for_thinking(
            provider,
            model,
            &none,
            PortableOption::Temperature,
            None,
        )
        .expect("explicit none admits temperature");
        assert!(!lookup(provider, model).temperature_supported);
    }
    for model in ["openai/gpt-6-luna", "openai/gpt-6-sol"] {
        let caps = lookup("openrouter", model);
        assert!(caps.portable_option_effort_support.is_empty());
        admit_portable_option_for_thinking(
            "openrouter",
            model,
            &none,
            PortableOption::Temperature,
            None,
        )
        .expect_err("an unforwarded option must not inherit direct conditional support");
    }
    admit_portable_option_for_thinking(
        "openai",
        "gpt-6-astra",
        &none,
        PortableOption::Temperature,
        None,
    )
    .expect_err("Astra must not inherit a condition for Sol and Luna");
}

#[test]
fn openai_gpt_54_supports_tool_search() {
    reset();
    let caps = lookup("openai", "gpt-5.4");
    assert!(caps.defer_loading);
    assert_eq!(caps.tool_search, vec!["hosted", "client"]);
    assert_eq!(caps.json_schema.as_deref(), Some("native"));
    assert_eq!(caps.thinking_modes, vec!["effort"]);
    assert!(caps.reasoning_effort_supported);
    assert!(caps.reasoning_none_supported);
    assert!(!caps.prefers_xml_scaffolding);
    assert!(caps.prefers_markdown_scaffolding);
    assert_eq!(caps.structured_output_mode, "native_json");
    assert!(!caps.supports_assistant_prefill);
    assert!(!caps.prefers_role_developer);
    assert!(!caps.prefers_xml_tools);
    assert_eq!(caps.thinking_block_style, "reasoning_summary");
    assert_eq!(
        caps.reasoning_excluded_portable_options,
        vec![PortableOption::Temperature],
        "GPT-5.4 only fixes temperature while reasoning is active"
    );
}

#[test]
fn openai_gpt_53_has_reasoning_none_without_tool_search() {
    reset();
    let caps = lookup("openai", "gpt-5.3");
    assert!(caps.native_tools);
    assert!(!caps.defer_loading);
    assert!(caps.vision_supported);
    assert!(caps.tool_search.is_empty());
    assert_eq!(caps.thinking_modes, vec!["effort"]);
    assert!(caps.reasoning_effort_supported);
    assert!(caps.reasoning_none_supported);
}

#[test]
fn openai_original_gpt_5_has_reasoning_floor_without_none() {
    reset();
    let caps = lookup("openai", "gpt-5");
    assert!(caps.native_tools);
    assert!(!caps.defer_loading);
    assert_eq!(caps.thinking_modes, vec!["effort"]);
    assert!(caps.reasoning_effort_supported);
    assert!(!caps.reasoning_none_supported);
}

#[test]
fn openai_gpt_4o_matrix_fields_include_multimodal_support() {
    reset();
    let caps = lookup("openai", "gpt-4o");
    assert!(caps.native_tools);
    assert!(caps.vision);
    assert!(caps.audio);
    assert!(!caps.pdf);
    assert_eq!(caps.json_schema.as_deref(), Some("native"));
}

#[test]
fn openai_reasoning_models_support_effort() {
    reset();
    let caps = lookup("openai", "o3");
    assert_eq!(caps.thinking_modes, vec!["effort"]);
    assert!(caps.requires_completion_tokens);
    assert!(caps.reasoning_effort_supported);
    assert!(caps.prefers_role_developer);
    assert_eq!(caps.thinking_block_style, "reasoning_summary");
    let prefixed = lookup("openrouter", "openai/o4-mini");
    assert!(prefixed.requires_completion_tokens);
    assert!(prefixed.reasoning_effort_supported);
}

#[test]
fn openai_gpt5_requires_completion_tokens() {
    reset();
    // gpt-5.x reasoning models reject legacy `max_tokens` on
    // /v1/chat/completions and require `max_completion_tokens`.
    for model in [
        "gpt-5.5",
        "gpt-5.4",
        "gpt-5.2",
        "gpt-5.1",
        "gpt-5",
        "gpt-5-mini",
    ] {
        assert!(
            lookup("openai", model).requires_completion_tokens,
            "{model} must require max_completion_tokens"
        );
    }
    // Prefixed OpenRouter ids resolve the same way.
    assert!(lookup("openrouter", "openai/gpt-5.5").requires_completion_tokens);
}

#[test]
fn openai_gpt_5_6_exposes_exact_reasoning_efforts() {
    reset();
    for model in ["gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"] {
        let caps = lookup("openai", model);
        assert_eq!(
            caps.reasoning_effort_levels,
            vec!["none", "low", "medium", "high", "xhigh", "max"],
            "{model} reasoning effort contract"
        );
        assert!(caps.responses_api);
        assert!(caps.vision_supported);
        assert!(caps.reasoning_tools_require_responses);
        assert!(!caps.temperature_supported);
    }
}

/// GPT-6 Astra narrows the ladder again, and the generic `gpt-*`
/// `version_min = [5, 4]` row would otherwise claim `none` is available and
/// leave sampling unconstrained. Both facts were probed against the live API
/// on 2026-09-04; a wrong row here costs a provider 400 per agent turn, and
/// nothing else in the suite would catch it.
#[test]
fn openai_gpt_6_astra_narrows_effort_and_forbids_sampling() {
    reset();
    for model in ["gpt-6-astra", "gpt-6"] {
        let caps = lookup("openai", model);
        assert_eq!(
            caps.reasoning_effort_levels,
            vec!["low", "medium", "high", "xhigh"],
            "{model} reasoning effort contract"
        );
        assert!(
            !caps.reasoning_none_supported,
            "{model} rejects reasoning_effort=none"
        );
        assert!(
            !caps.temperature_supported,
            "{model} accepts only the default temperature"
        );
        assert!(!caps.top_p_supported, "{model} rejects top_p");
        assert!(caps.responses_api);
        assert!(caps.vision_supported);
        assert!(
            caps.reasoning_tools_require_responses,
            "{model} cannot carry function tools on /v1/chat/completions"
        );
    }
    // Gateway-prefixed ids resolve to the same contract.
    let routed = lookup("openrouter", "openai/gpt-6-astra");
    assert_eq!(
        routed.reasoning_effort_levels,
        vec!["low", "medium", "high", "xhigh"]
    );
    assert!(!routed.temperature_supported);
}

/// GPT-6 Sol and Luna accept effort `none`; Astra does not. All three reject
/// `max` and a non-default temperature while reasoning (live API,
/// 2026-09-22). Astra is the control: if the Sol/Luna wildcard captured it,
/// the Astra assertions would flip.
#[test]
fn openai_gpt_6_sol_and_luna_accept_effort_none() {
    reset();
    for (provider, model) in [
        ("openai", "gpt-6-sol"),
        ("openai", "gpt-6-luna"),
        ("openrouter", "openai/gpt-6-sol"),
        ("openrouter", "openai/gpt-6-luna-pro"),
    ] {
        let caps = lookup(provider, model);
        assert!(caps.reasoning_none_supported, "{model}");
        assert_eq!(
            caps.reasoning_effort_levels,
            vec!["none", "low", "medium", "high", "xhigh"],
            "{model}"
        );
        assert!(!caps.temperature_supported, "{model}");
        assert!(!caps.top_p_supported, "{model}");
    }
    for model in ["gpt-6-sol", "gpt-6-luna"] {
        let caps = lookup("openai", model);
        assert!(caps.responses_api, "{model}");
        assert!(caps.prompt_caching, "{model}");
        assert!(
            caps.reasoning_tools_require_responses,
            "{model} cannot carry function tools on /v1/chat/completions while reasoning"
        );
    }
    for (provider, model) in [
        ("openai", "gpt-6-astra"),
        ("openrouter", "openai/gpt-6-astra-pro"),
    ] {
        assert!(!lookup(provider, model).reasoning_none_supported, "{model}");
    }
}

/// GPT-6.1 Sol has Astra's surface, not GPT-6 Sol's: effort `none` is a 400
/// on it, directly and through OpenRouter (live API, 2026-09-29). The
/// `gpt-6*` wildcard would grant it `none`, so the GPT-6 Sol control proves
/// the Astra row, not the wildcard, decided these values.
#[test]
fn openai_gpt_6_1_sol_rejects_effort_none() {
    reset();
    for (provider, model) in [
        ("openai", "gpt-6.1-sol"),
        ("openrouter", "openai/gpt-6.1-sol"),
        ("openrouter", "openai/gpt-6.1-sol-pro"),
    ] {
        let caps = lookup(provider, model);
        assert!(!caps.reasoning_none_supported, "{model}");
        assert_eq!(
            caps.reasoning_effort_levels,
            vec!["low", "medium", "high", "xhigh"],
            "{model}"
        );
        assert!(!caps.temperature_supported, "{model}");
    }
    // Only the direct route must move tool calls to Responses; OpenRouter
    // does that routing itself (a chat-completions tool call returned 200).
    assert!(lookup("openai", "gpt-6.1-sol").reasoning_tools_require_responses);
    assert!(lookup("openai", "gpt-6-sol").reasoning_none_supported);

    // OpenRouter 400s `reasoning: {enabled: false}` on Astra and 6.1 Sol, so
    // Harn must omit it there; GPT-6 Sol on the same route accepts it.
    for model in [
        "openai/gpt-6.1-sol",
        "openai/gpt-6.1-sol-pro",
        "openai/gpt-6-astra",
    ] {
        assert!(
            !lookup("openrouter", model).reasoning_disable_supported,
            "{model}"
        );
    }
    assert!(lookup("openrouter", "openai/gpt-6-sol").reasoning_disable_supported);
    // The direct route keeps its effort-floor lowering.
    assert!(lookup("openai", "gpt-6.1-sol").reasoning_disable_supported);
}

/// Direction control for the row above: the sibling family it sits next to
/// must keep its own, wider ladder. A row that accidentally widened Astra's
/// match glob would pass the assertions above by making every GPT model look
/// like Astra, and this is what would fail.
#[test]
fn openai_gpt_6_row_does_not_capture_gpt_5_6() {
    reset();
    let five_six = lookup("openai", "gpt-5.6-sol");
    assert!(
        five_six.reasoning_none_supported,
        "GPT-5.6 still accepts effort=none"
    );
    assert_eq!(
        five_six.reasoning_effort_levels,
        vec!["none", "low", "medium", "high", "xhigh", "max"]
    );
}

/// Every OpenAI route that caches must say so, because the catalog projects
/// `model.prompt_cache` from this rule field and NOT from the `capabilities`
/// list on the model row. Before 2026-09-04 no OpenAI rule set it, so rows that
/// listed "prompt_caching" in `capabilities` still exported
/// `prompt_cache: false` and downstream cost models could not see a cache hit
/// they were already being billed for. Each id below was probed against the
/// live API: an identical ~1578-token prefix sent twice returned a cache hit on
/// the second call.
#[test]
fn openai_routes_that_cache_declare_prompt_caching() {
    reset();
    for model in [
        "gpt-6-astra",
        "gpt-5.6-luna",
        "gpt-5.6-sol",
        "gpt-5.4",
        "gpt-5.4-mini",
        "gpt-4o-mini",
        "o4-mini",
    ] {
        assert!(
            lookup("openai", model).prompt_caching,
            "{model} caches prompts and must declare prompt_caching"
        );
    }
    // Gateway-prefixed ids resolve to the same contract.
    assert!(lookup("openrouter", "openai/gpt-5.6-luna").prompt_caching);
}

/// Declaring `prompt_caching` must NOT start emitting a request marker on
/// OpenAI routes. `PromptCacheBreakpoint::resolve` is gated on
/// `caps.prompt_caching`, so before this flag was set the OpenAI branch was
/// unreachable and the breakpoint style never mattered. It matters now.
///
/// OpenAI caches automatically and accepts no marker: a top-level
/// `cache_control` on `/v1/chat/completions` is rejected with
/// `Unknown parameter: 'cache_control'.` (probed 2026-09-04). Anthropic's
/// provider defaults set `top_level`; OpenAI's set nothing and fall back to
/// `CacheBreakpointStyle::None`, which is what keeps the marker out of the
/// request. If someone gives OpenAI a breakpoint style, every cache-requesting
/// OpenAI call starts failing with that 400, and this is the test that says so.
#[test]
fn openai_prompt_caching_emits_no_request_marker() {
    reset();
    for model in ["gpt-6-astra", "gpt-5.6-luna", "gpt-4o-mini", "o4-mini"] {
        let caps = lookup("openai", model);
        assert!(caps.prompt_caching, "{model} caches");
        assert_eq!(
            caps.cache_breakpoint_style,
            CacheBreakpointStyle::None,
            "{model} caches automatically and rejects a cache_control marker"
        );
    }
}

/// Direction control for the row above. The two catch-all rules carry no
/// `version_min` and exist to backstop pre-4o models that predate automatic
/// caching, so they must NOT claim the capability. Without this, widening the
/// flag to every rule in the file would still pass the assertions above.
#[test]
fn openai_legacy_catch_all_does_not_claim_prompt_caching() {
    reset();
    assert!(
        !lookup("openai", "gpt-3.5-turbo").prompt_caching,
        "the pre-4o catch-all must not claim prompt caching"
    );
}

#[test]
fn openrouter_inherits_openai() {
    reset();
    let caps = lookup("openrouter", "gpt-5.4");
    assert!(caps.defer_loading);
    assert_eq!(caps.tool_search, vec!["hosted", "client"]);
    assert_eq!(caps.reasoning_wire_format.as_deref(), Some("openrouter"));
    assert!(!caps.top_k_supported);
}

#[test]
fn groq_inherits_openai_family_only() {
    reset();
    let caps = lookup("groq", "gpt-5.5-preview");
    assert!(caps.defer_loading);
}

#[test]
fn cerebras_inherits_openai_family() {
    reset();
    let caps = lookup("cerebras", "gpt-oss-120b");
    assert_eq!(caps.message_wire_format, WireDialect::OpenAiCompat);
    assert_eq!(caps.native_tool_wire_format, "openai");
    // gpt-oss uses NATIVE tool calls across cerebras/groq/together. Under
    // json/text it emits a bare {"tool","arguments"} dialect the
    // fenced-JSON parser rejects (zero parsed calls), so native is the only
    // working channel.
    assert!(caps.native_tools);
    assert_eq!(caps.preferred_tool_format.as_deref(), Some("native"));
}

/// harn#9338: OpenRouter has no Responses skin for OpenAI's `tool_search`
/// meta-tool and 400s it, so its OpenAI routes must not claim native search.
/// Direct OpenAI is the control: it keeps the claim the overlay withdraws.
#[test]
fn openrouter_openai_routes_do_not_claim_native_tool_search() {
    reset();
    for model in ["openai/gpt-5.4", "openai/gpt-6-sol", "openai/gpt-6.1-sol"] {
        let caps = lookup("openrouter", model);
        assert!(
            !caps.defer_loading,
            "{model} claims defer_loading on OpenRouter"
        );
        assert!(
            caps.tool_search.is_empty(),
            "{model} claims native tool search on OpenRouter"
        );
    }
    let direct = lookup("openai", "gpt-6-sol");
    assert!(direct.defer_loading);
    assert_eq!(direct.tool_search, vec!["hosted", "client"]);
}