harn-vm 0.10.153

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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
//! Anthropic and Anthropic-wire route rows: thinking style, effort
//! controls, tool-search gating, and the OpenRouter/Bedrock mirrors that must
//! track the direct rows.

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

fn assert_openrouter_anthropic_runtime_parity(model: &str) {
    let direct = lookup("anthropic", model);
    let routed = lookup("openrouter", model);

    assert_eq!(
        routed.native_tools, direct.native_tools,
        "{model}: native tool support should match direct Anthropic"
    );
    assert_eq!(
        routed.preferred_tool_format, direct.preferred_tool_format,
        "{model}: preferred tool format should match direct Anthropic"
    );
    // Structured-output lowering is deliberately route-specific. Direct
    // Anthropic uses output_config.format; OpenRouter's OpenAI-compatible
    // transport retains its synthetic-tool strategy.
    assert_eq!(
        routed.thinking_modes,
        Vec::<String>::new(),
        "{model}: OpenRouter Claude routes must not advertise direct Anthropic thinking controls"
    );
    assert!(
        !routed.reasoning_effort_supported,
        "{model}: OpenRouter Claude routes must not advertise direct Anthropic effort controls"
    );
    assert!(
        !routed.interleaved_thinking_supported,
        "{model}: OpenRouter Claude routes must not advertise interleaved thinking"
    );
    assert_eq!(
        routed.supports_assistant_prefill, direct.supports_assistant_prefill,
        "{model}: assistant prefill support should match direct Anthropic"
    );
    assert_eq!(
        routed.prompt_caching, direct.prompt_caching,
        "{model}: prompt cache support should match direct Anthropic"
    );
    assert_eq!(
        routed.prefers_xml_scaffolding, direct.prefers_xml_scaffolding,
        "{model}: XML scaffolding preference should match direct Anthropic"
    );
    assert_eq!(
        routed.prefers_markdown_scaffolding, direct.prefers_markdown_scaffolding,
        "{model}: Markdown scaffolding preference should match direct Anthropic"
    );
    assert_eq!(
        routed.prefers_role_developer, direct.prefers_role_developer,
        "{model}: developer role preference should match direct Anthropic"
    );
    assert_eq!(
        routed.prefers_xml_tools, direct.prefers_xml_tools,
        "{model}: XML tool preference should match direct Anthropic"
    );
    assert_eq!(
        routed.thinking_block_style, direct.thinking_block_style,
        "{model}: thinking block style should match direct Anthropic"
    );
    assert_eq!(
        routed.text_tool_wire_format_supported, direct.text_tool_wire_format_supported,
        "{model}: text-tool fallback support should match direct Anthropic"
    );
}

#[test]
fn anthropic_opus_47_gets_full_capabilities() {
    reset();
    let caps = lookup("anthropic", "claude-opus-4-7");
    assert!(caps.native_tools);
    assert!(caps.defer_loading);
    assert_eq!(caps.tool_search, vec!["bm25", "regex"]);
    assert!(caps.prompt_caching);
    assert_eq!(caps.thinking_modes, vec!["adaptive", "effort"]);
    assert!(caps.reasoning_effort_supported);
    assert_eq!(
        caps.reasoning_effort_levels,
        vec!["low", "medium", "high", "xhigh", "max"]
    );
    assert!(caps.interleaved_thinking_supported);
    assert!(caps.vision_supported);
    assert!(caps.audio);
    assert!(caps.pdf);
    assert!(caps.files_api_supported);
    assert_eq!(caps.max_tools, Some(10000));
    assert!(caps.prefers_xml_scaffolding);
    assert!(!caps.prefers_markdown_scaffolding);
    assert_eq!(caps.structured_output.as_deref(), Some("native"));
    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, "thinking_blocks");
}

#[test]
fn anthropic_sonnet_5_gets_adaptive_effort_capabilities() {
    reset();
    let caps = lookup("anthropic", "claude-sonnet-5");
    assert!(caps.native_tools);
    assert!(caps.defer_loading);
    assert_eq!(caps.tool_search, vec!["bm25", "regex"]);
    assert!(caps.prompt_caching);
    assert_eq!(caps.thinking_modes, vec!["adaptive", "effort"]);
    assert!(caps.reasoning_effort_supported);
    assert_eq!(
        caps.reasoning_effort_levels,
        vec!["low", "medium", "high", "xhigh", "max"]
    );
    assert!(caps.reasoning_disable_supported);
    assert!(!caps.reasoning_none_supported);
    assert!(caps.interleaved_thinking_supported);
    assert!(!caps.supports_assistant_prefill);
    assert_eq!(caps.thinking_block_style, "thinking_blocks");
}

/// Sonnet 5.5 narrows Sonnet 5 three ways (live API, 2026-09-29): thinking
/// turns off with `between_tools`, forced tool choice is a 400, and the cache
/// floor drops to 512. The `claude-sonnet-5*` glob also matches
/// `claude-sonnet-5-5`, so Sonnet 5 is the control that proves the 5.5 row
/// decided each value; before that row existed every default Harn call to
/// Sonnet 5.5 sent `disabled` and failed.
#[test]
fn anthropic_sonnet_55_turns_thinking_off_between_tools() {
    reset();
    for model in ["claude-sonnet-5-5", "anthropic/claude-sonnet-5.5"] {
        let caps = lookup("anthropic", model);
        assert_eq!(
            caps.thinking_off_type,
            ThinkingOffType::BetweenTools,
            "{model}"
        );
        assert!(caps.reasoning_disable_supported, "{model}");
        assert_eq!(
            caps.allowed_tool_choice_modes,
            vec!["auto", "none"],
            "{model}"
        );
        assert_eq!(caps.prompt_cache_min_prefix_tokens, Some(512), "{model}");
        // The rest layers on from the Sonnet 5 row through `extends`.
        assert_eq!(caps.thinking_modes, vec!["adaptive", "effort"], "{model}");
        assert!(!caps.temperature_supported, "{model}");
        assert!(caps.native_tools, "{model}");
    }
    for model in ["claude-sonnet-5", "anthropic/claude-sonnet-5"] {
        let caps = lookup("anthropic", model);
        assert_eq!(caps.thinking_off_type, ThinkingOffType::Disabled, "{model}");
        assert!(caps.allowed_tool_choice_modes.is_empty(), "{model}");
        assert_eq!(caps.prompt_cache_min_prefix_tokens, Some(1024), "{model}");
    }
}

/// Through OpenRouter, Sonnet 5.5's reasoning cannot be disabled at all and a
/// forced tool choice returns Anthropic's 400 (probed 2026-09-29). Sonnet 5
/// on the same route keeps both.
#[test]
fn openrouter_sonnet_55_keeps_reasoning_on_and_tool_choice_unforced() {
    reset();
    let caps = lookup("openrouter", "anthropic/claude-sonnet-5.5");
    assert!(!caps.reasoning_disable_supported);
    assert_eq!(caps.allowed_tool_choice_modes, vec!["auto", "none"]);
    assert!(caps.native_tools);

    let sonnet5 = lookup("openrouter", "anthropic/claude-sonnet-5");
    assert!(sonnet5.reasoning_disable_supported);
    assert!(sonnet5.allowed_tool_choice_modes.is_empty());
}

#[test]
fn anthropic_fable_effort_cannot_be_disabled() {
    reset();
    for model in ["claude-fable-5", "anthropic/claude-fable-5"] {
        let caps = lookup("anthropic", model);
        assert_eq!(caps.thinking_modes, vec!["adaptive", "effort"]);
        assert!(caps.reasoning_effort_supported);
        assert_eq!(
            caps.reasoning_effort_levels,
            vec!["low", "medium", "high", "xhigh", "max"]
        );
        assert!(!caps.reasoning_disable_supported);
        assert!(!caps.supports_assistant_prefill);
    }
}

/// Fable 5.1 keeps the whole Fable/Mythos surface and narrows exactly one
/// thing: forced tool choice is gone. `tool_choice` `any` / `tool` are a 400
/// on this model, so only `auto` and `none` may reach the wire. The Fable 5
/// control below is what makes this assertion mean something — an empty
/// `allowed_tool_choice_modes` is "unrestricted", so without the control a
/// silently-unmatched 5.1 rule would still read as a pass on every other line.
#[test]
fn anthropic_fable_51_forbids_forced_tool_choice() {
    reset();
    let caps = lookup("anthropic", "claude-fable-5-1");
    assert_eq!(caps.allowed_tool_choice_modes, vec!["auto", "none"]);

    // Inherited-by-restatement: 5.1 is a full rule, not an `extends` merge,
    // so every field the catch-all sets has to survive the copy.
    assert_eq!(caps.thinking_modes, vec!["adaptive", "effort"]);
    assert_eq!(
        caps.reasoning_effort_levels,
        vec!["low", "medium", "high", "xhigh", "max"]
    );
    assert!(!caps.reasoning_disable_supported);
    assert!(!caps.supports_assistant_prefill);
    assert!(!caps.temperature_supported);
    assert!(caps.native_tools);
    assert!(caps.prompt_caching);
    assert_eq!(caps.prompt_cache_min_prefix_tokens, Some(512));

    // Control: Fable 5 must stay unrestricted, or the 5.1 row is matching
    // more than it should.
    let fable5 = lookup("anthropic", "claude-fable-5");
    assert!(fable5.allowed_tool_choice_modes.is_empty());
}

/// Opus 5.5 narrows the Opus 5 surface: thinking cannot be disabled and
/// forced tool choice is a 400 (live API, 2026-09-22). Opus 5 is the control
/// that keeps both, so an Opus 5.5 row that matched too broadly would fail
/// here instead of silently tightening the previous generation.
#[test]
fn anthropic_opus_55_is_always_on_and_forbids_forced_tool_choice() {
    reset();
    for model in [
        "claude-opus-5-5",
        "anthropic/claude-opus-5-5",
        "anthropic/claude-opus-5.5",
    ] {
        let caps = lookup("anthropic", model);
        assert!(!caps.reasoning_disable_supported, "{model}");
        assert_eq!(
            caps.allowed_tool_choice_modes,
            vec!["auto", "none"],
            "{model}"
        );
        assert_eq!(caps.prompt_cache_min_prefix_tokens, Some(512), "{model}");
        assert_eq!(
            caps.reasoning_effort_levels,
            vec!["low", "medium", "high", "xhigh", "max"],
            "{model}"
        );
        assert!(!caps.temperature_supported, "{model}");
        assert!(!caps.supports_assistant_prefill, "{model}");
    }
    assert_eq!(
        lookup("anthropic", "claude-opus-5-5").system_message_placement,
        lookup("anthropic", "claude-opus-5").system_message_placement,
        "Opus 5.5 keeps native mid-conversation system messages"
    );

    for model in ["claude-opus-5", "anthropic/claude-opus-5"] {
        let caps = lookup("anthropic", model);
        assert!(caps.reasoning_disable_supported, "{model}");
        assert!(caps.allowed_tool_choice_modes.is_empty(), "{model}");
        assert_eq!(caps.prompt_cache_min_prefix_tokens, Some(512), "{model}");
    }

    // OpenRouter passes tool_choice through verbatim, so the restriction
    // follows the model onto that route; Opus 5 there stays unrestricted.
    assert_eq!(
        lookup("openrouter", "anthropic/claude-opus-5.5").allowed_tool_choice_modes,
        vec!["auto", "none"]
    );
    assert_eq!(
        lookup("openrouter", "anthropic/claude-fable-5.1").allowed_tool_choice_modes,
        vec!["auto", "none"]
    );
    assert!(lookup("openrouter", "anthropic/claude-opus-5")
        .allowed_tool_choice_modes
        .is_empty());
    assert!(lookup("openrouter", "anthropic/claude-fable-5")
        .allowed_tool_choice_modes
        .is_empty());
}

#[test]
fn anthropic_47_and_newer_sampling_is_denied_by_the_catalog() {
    reset();
    for model in [
        "claude-fable-5",
        "anthropic/claude-fable-5",
        "claude-mythos-5-preview",
        "anthropic/claude-mythos-5-preview",
        "claude-opus-4-7",
        "anthropic/claude-opus-4-7",
        "claude-opus-5",
        "anthropic/claude-opus-5",
        "claude-opus-5-5",
        "anthropic/claude-opus-5.5",
        "claude-sonnet-5",
        "anthropic/claude-sonnet-5",
    ] {
        let caps = lookup("anthropic", model);
        assert!(!caps.temperature_supported, "{model}: temperature");
        assert!(!caps.top_p_supported, "{model}: top_p");
        assert!(!caps.top_k_supported, "{model}: top_k");
    }

    let pre_47 = lookup("anthropic", "claude-sonnet-4-6");
    assert!(pre_47.temperature_supported);
    assert!(pre_47.top_p_supported);
    assert!(pre_47.top_k_supported);
}

#[test]
fn anthropic_opus_46_uses_budgeted_thinking() {
    reset();
    let caps = lookup("anthropic", "claude-opus-4-6");
    assert_eq!(caps.thinking_modes, vec!["enabled"]);
    assert!(caps.interleaved_thinking_supported);
    assert!(!caps.supports_assistant_prefill);
}

#[test]
fn anthropic_opus_45_does_not_support_interleaved_thinking() {
    reset();
    let caps = lookup("anthropic", "claude-opus-4-5");
    assert_eq!(caps.thinking_modes, vec!["enabled"]);
    assert!(!caps.interleaved_thinking_supported);
    assert!(caps.supports_assistant_prefill);
}

#[test]
fn native_schema_output_tracks_supported_direct_anthropic_generations() {
    reset();
    for model in [
        "claude-fable-5",
        "claude-mythos-preview",
        "claude-mythos-5",
        "claude-haiku-4-5",
        "claude-opus-4-5",
        "claude-opus-4-6",
        "claude-sonnet-4-5",
        "claude-sonnet-4-6",
        "claude-sonnet-5",
        "anthropic/claude-haiku-4-5",
        "anthropic/claude-opus-4-5",
        "anthropic/claude-sonnet-4-5",
    ] {
        let caps = lookup("anthropic", model);
        assert_eq!(
            caps.structured_output.as_deref(),
            Some("native"),
            "{model}: supported direct Anthropic models use output_config.format",
        );
        assert_eq!(caps.structured_output_mode, "native_json", "{model}");
    }
}

#[test]
fn older_anthropic_generations_keep_synthetic_tool_fallback() {
    reset();
    for model in ["claude-opus-4-0", "claude-sonnet-4-0", "claude-opus-3-5"] {
        let caps = lookup("anthropic", model);
        assert_eq!(
            caps.structured_output.as_deref(),
            Some("tool_use"),
            "{model}: unsupported generations retain the compatibility fallback",
        );
        assert_eq!(caps.structured_output_mode, "xml_tagged", "{model}");
    }
}

#[test]
fn openrouter_claude_rows_track_direct_anthropic_runtime_quirks() {
    reset();
    for model in [
        "anthropic/claude-fable-5-0",
        "anthropic/claude-mythos-5-0",
        "anthropic/claude-haiku-4-5",
        "anthropic/claude-haiku-4-7",
        "anthropic/claude-sonnet-4-6",
        "anthropic/claude-sonnet-4-7",
        "anthropic/claude-sonnet-5",
        "anthropic/claude-opus-4-6",
        "anthropic/claude-opus-4-7",
        "anthropic/claude-opus-5.5",
    ] {
        assert_openrouter_anthropic_runtime_parity(model);
    }
}

#[test]
fn override_can_supply_anthropic_beta_features() {
    reset();
    let toml_src = r#"
[[provider.anthropic]]
model_match = "claude-custom-*"
native_tools = true
anthropic_beta_features = ["fine-grained-tool-streaming-2025-05-14"]
"#;
    set_user_overrides_toml(toml_src).unwrap();
    let caps = lookup("anthropic", "claude-custom-1");
    assert_eq!(
        caps.anthropic_beta_features,
        vec!["fine-grained-tool-streaming-2025-05-14"]
    );
    reset();
}

#[test]
fn anthropic_haiku_44_has_no_tool_search() {
    reset();
    let caps = lookup("anthropic", "claude-haiku-4-4");
    // Haiku 4.4 falls through to the `claude-*` catch-all row.
    assert!(caps.native_tools);
    assert!(caps.prompt_caching);
    assert!(!caps.defer_loading);
    assert!(caps.tool_search.is_empty());
}

#[test]
fn anthropic_haiku_45_supports_tool_search() {
    reset();
    let caps = lookup("anthropic", "claude-haiku-4-5");
    assert!(caps.defer_loading);
    assert_eq!(caps.tool_search, vec!["bm25", "regex"]);
}

#[test]
fn old_claude_gets_catchall() {
    reset();
    let caps = lookup("anthropic", "claude-opus-3-5");
    assert!(caps.native_tools);
    assert!(caps.prompt_caching);
    assert!(!caps.defer_loading);
    assert!(caps.tool_search.is_empty());
}

#[test]
fn openrouter_anthropic_claude_models_support_native_tools() {
    // Regression for #2319: OpenRouter Anthropic slugs must match the
    // Anthropic capability rules before the OpenRouter -> OpenAI family
    // chain, otherwise native-tool requests get rejected as unsupported.
    reset();
    for model in [
        "anthropic/claude-haiku-4-5",
        "anthropic/claude-haiku-4-5-20251001",
        "anthropic/claude-sonnet-4-6",
        "anthropic/claude-sonnet-4-7",
        "anthropic/claude-opus-4-7",
    ] {
        let caps = lookup("openrouter", model);
        assert!(
            caps.native_tools,
            "{model} via openrouter should report native_tools=true",
        );
        assert!(
            caps.prompt_caching,
            "{model} via openrouter should report prompt_caching=true",
        );
        assert_eq!(
            caps.cache_breakpoint_style,
            super::CacheBreakpointStyle::TopLevel,
            "{model} via openrouter should use top-level cache_control",
        );
        assert_eq!(
            caps.structured_output.as_deref(),
            Some("tool_use"),
            "{model} via OpenRouter retains the route-specific synthetic-tool strategy",
        );
    }
}

#[test]
fn bedrock_claude_uses_anthropic_wire_capabilities() {
    reset();
    let caps = lookup("bedrock", "anthropic.claude-3-5-sonnet-20240620-v1:0");
    assert!(caps.native_tools);
    assert_eq!(caps.message_wire_format, WireDialect::Anthropic);
    assert_eq!(caps.native_tool_wire_format, "anthropic");
}

#[test]
fn openrouter_namespaced_anthropic_model() {
    reset();
    let caps = lookup("anthropic", "anthropic/claude-opus-4-7");
    assert!(caps.defer_loading);
}