met 1.0.0-beta-preview

Metrale Engine: pure Rust LLM inference server (HTTP API, scheduler, TUI, CLI).
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
// SPDX-License-Identifier: MIT OR Apache-2.0

//! 2026-09-26: Render tests for the Library's three panes: the model list, the
//! recipe cards and the config form.
//!
//! Owner: server tui.
//! Invariants: none beyond the types.

use crate::recipe::Recipe;
use crate::recipe::fetch::Index;
use crate::tui::app::{App, Section};
use crate::tui::data::library::LibraryEntry;
use crate::tui::lib_state::View;
use crate::tui::render::harness::{has, screen};

pub(super) fn recipe(stem: &str) -> Recipe {
    let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests/fixtures/recipes/qwen3.6")
        .join(format!("{stem}.yaml"));
    Recipe::parse(
        format!("qwen3.6/{stem}"),
        &std::fs::read_to_string(path).expect("fixture"),
    )
    .expect("parses")
}

pub(super) fn local(id: &str, has_weights: bool) -> LibraryEntry {
    LibraryEntry {
        id: id.to_string(),
        snapshot_dir: Default::default(),
        size_bytes: 34_900_000_000,
        has_weights,
        model_type: "qwen3_6_moe".into(),
        quant: "fp8".into(),
        layers: 40,
        hidden: 4096,
        heads: 32,
        experts: 128,
        context: 65536,
        optimized: true,
    }
}

/// 2026-09-26: An `App` on the Library section, built from `recipes` and
/// `locals`.
pub(super) fn lib(recipes: Vec<Recipe>, locals: Vec<LibraryEntry>) -> App {
    let mut a = crate::tui::render::tests::app();
    a.section = Section::Library;
    a.library = locals;
    a.lib.index = Index {
        recipes,
        ..Default::default()
    };
    a.lib.rebuild(&a.library);
    a
}

fn flagship() -> App {
    let r = recipe("qwen3.6-35b-a3b-fp8-mtp");
    let model = r.model.clone();
    lib(vec![r], vec![local(&model, true)])
}

/// 2026-09-26: A library of one model with a download job, so the per-row
/// progress line is drawn. The repo id does not exist, because `start` launches
/// a real download worker (`model_download::start`).
fn downloading(done: u64, total: u64) -> App {
    const REPO: &str = "metrale-render-tests/no-such-model";
    let mut a = lib(Vec::new(), vec![local(REPO, false)]);
    let root = std::env::temp_dir().join("metrale-library-render-tests");
    std::fs::create_dir_all(&root).ok();
    a.download.start(REPO, root);
    let job = a.download.job.as_mut().expect("a job");
    job.done = done;
    job.total = total;
    job.rate_bps = 96_000_000.0;
    job.file = Some((3, 85, "model-00003-of-00085.safetensors".into()));
    a
}

/// 2026-09-26: The rows cut down to the list pane's columns, so the detail
/// pane to its right cannot satisfy an assertion about the row.
fn list_pane(rows: &[String], screen_w: u16) -> Vec<String> {
    let chrome = crate::tui::render::Chrome::of(ratatui::layout::Size::new(screen_w, 40));
    // 2026-09-26: Sidebar, then the 1-cell ring, then 46% of the content is
    // the list (`library/list.rs`).
    let content_w = screen_w - chrome.sidebar_w - 2;
    let end = (chrome.sidebar_w + 1 + content_w * 46 / 100) as usize;
    rows.iter().map(|r| r.chars().take(end).collect()).collect()
}

#[test]
fn the_progress_line_sheds_fields_from_the_right_as_the_pane_narrows() {
    let a = downloading(4_000_000_000, 34_900_000_000);

    let cramped = list_pane(&screen(&a, 120, 40), 120);
    assert!(
        has(&cramped, " 11%"),
        "the percentage survives:\n{cramped:#?}"
    );
    assert!(has(&cramped, "▓"), "and so does the bar");
    assert!(!has(&cramped, "MB/s"), "{cramped:#?}");
    assert!(!has(&cramped, "file 3/85"), "{cramped:#?}");

    let roomy = screen(&a, 200, 40);
    // 2026-09-26: `format::bytes` divides by 1024³.
    assert!(has(&roomy, "3.7 GB / 32.5 GB"), "{roomy:#?}");
    assert!(has(&roomy, "92 MB/s"), "{roomy:#?}");

    let wide = list_pane(&screen(&a, 280, 40), 280);
    assert!(has(&wide, "file 3/85"), "{wide:#?}");
}

/// 2026-09-26: The first screen row containing `id`. The header's status pill
/// also draws a "●", so a whole-screen scan cannot tell the two apart.
fn model_row(rows: &[String], id: &str) -> String {
    rows.iter()
        .find(|r| r.contains(id))
        .cloned()
        .unwrap_or_default()
}

#[test]
fn a_running_download_owns_the_detail_pane_and_marks_its_row_with_a_dot() {
    let a = downloading(4_000_000_000, 34_900_000_000);
    let rows = screen(&a, 120, 40);
    // 2026-09-26: The detail pane's download section, which the row's line
    // does not show at this width.
    assert!(has(&rows, "DOWNLOADING"), "{rows:#?}");
    assert!(has(&rows, "3.7 GB / 32.5 GB"), "{rows:#?}");
    assert!(has(&rows, "92 MB/s"), "{rows:#?}");
    assert!(has(&rows, "file 3/85"), "{rows:#?}");
    let row = model_row(&rows, "metrale-render-tests/no-such-model");
    assert!(
        row.contains("●"),
        "the row glows while its download runs: {row:?}"
    );
}

#[test]
fn a_model_not_downloading_draws_no_dot_and_no_download_section() {
    let a = flagship();
    let rows = screen(&a, 200, 40);
    assert!(!has(&rows, "DOWNLOADING"), "{rows:#?}");
    let id = a.lib.visible()[0].model.clone();
    let row = model_row(&rows, &id);
    assert!(!row.contains("●"), "{row:?}");
}

#[test]
fn a_download_the_hub_gave_no_size_for_says_fetching_rather_than_nought_percent() {
    let a = downloading(900_000_000, 0);
    let rows = screen(&a, 200, 40);
    assert!(has(&rows, "fetching"), "{rows:#?}");
    assert!(!has(&rows, "0.0%"), "no fraction was knowable:\n{rows:#?}");
}

#[test]
fn a_cancelling_download_says_stopping_instead_of_a_bar_that_keeps_moving() {
    let mut a = downloading(4_000_000_000, 34_900_000_000);
    a.download.job.as_mut().expect("a job").cancelling = true;
    let rows = screen(&a, 200, 40);
    assert!(has(&rows, "stopping…"), "{rows:#?}");
    assert!(
        !has(&rows, "MB/s"),
        "and drops the fields that imply progress:\n{rows:#?}"
    );
    assert!(has(&rows, "x stop the download"), "{rows:#?}");
}

#[test]
fn an_update_badge_appears_only_for_a_mismatch_that_was_actually_confirmed() {
    use crate::model_download::stale::Freshness;
    let mut a = flagship();
    let model = a.lib.visible()[0].model.clone();

    // 2026-09-26: An unreachable Hub is `Unknown`, which draws no badge.
    a.download
        .freshness
        .insert(model.clone(), Freshness::Unknown);
    assert!(!has(&screen(&a, 200, 40), " update "));

    a.download.freshness.insert(
        model.clone(),
        Freshness::Stale {
            local: "abc".into(),
            remote: "def".into(),
        },
    );
    let stale = screen(&a, 200, 40);
    assert!(has(&stale, " update "), "{stale:#?}");
    assert!(has(&stale, "d update"), "and the key that fixes it");
}

#[test]
fn a_freshness_check_in_flight_holds_the_badges_place_so_the_row_cannot_reflow() {
    let mut a = flagship();
    let model = a.lib.visible()[0].model.clone();
    a.download.checking = Some(model);
    assert!(has(&screen(&a, 200, 40), "░░░░░░"));
}

#[test]
fn a_search_that_matches_nothing_says_so_rather_than_looking_empty() {
    let mut a = flagship();
    a.lib.filter = "llama".into();
    a.lib.rebuild(&a.library.clone());
    let rows = screen(&a, 200, 40);
    assert!(has(&rows, "nothing matches this search"), "{rows:#?}");
    assert!(
        !has(&rows, "press r to fetch recipes"),
        "an empty SEARCH is not an empty library:\n{rows:#?}"
    );
}

#[test]
fn the_search_field_is_visible_before_anyone_knows_the_key_for_it() {
    let a = flagship();
    let rows = screen(&a, 200, 40);
    assert!(
        has(&rows, "⌕ search models — / or click"),
        "the idle field must name both ways in:\n{rows:#?}"
    );
}

#[test]
fn the_search_field_echoes_what_is_being_typed_and_keeps_it_after() {
    let mut a = flagship();
    a.lib.filter = "qwen".into();
    a.lib.filter_editing = true;
    assert!(has(&screen(&a, 200, 40), "⌕ qwen▏"));

    a.lib.filter_editing = false;
    let rows = screen(&a, 200, 40);
    // 2026-09-26: A kept filter shows how many rows of how many it keeps.
    assert!(has(&rows, "⌕ qwen  — 1 of 1 · / edits"), "{rows:#?}");
    assert!(!has(&rows, "qwen▏"));
}

#[test]
fn an_offline_recipe_index_says_why_and_what_to_do_about_it() {
    let mut a = flagship();
    a.lib.index.offline = Some("no route to host".into());
    let rows = screen(&a, 200, 40);
    assert!(has(&rows, "offline"), "the title admits it:\n{rows:#?}");
    assert!(
        has(&rows, "HTTPS_PROXY"),
        "and the body names the fix for THIS cause:\n{rows:#?}"
    );
}

#[test]
fn a_checkpoint_with_no_recipe_is_still_listed_and_says_the_flags_are_yours() {
    let a = lib(Vec::new(), vec![local("org/unknown-checkpoint", true)]);
    let rows = screen(&a, 200, 40);
    assert!(has(&rows, "org/unknown-checkpoint"), "{rows:#?}");
    assert!(has(&rows, "no recipe"), "{rows:#?}");
    assert!(has(&rows, "No recipe covers this checkpoint"), "{rows:#?}");
    assert!(has(&rows, "ON DISK"), "what IS known is still shown");
    assert!(has(&rows, "qwen3_6_moe"));
}

#[test]
fn the_row_glyph_distinguishes_present_partial_and_absent_weights() {
    let r = recipe("qwen3.6-35b-a3b-fp8-mtp");
    let model = r.model.clone();

    let present = lib(vec![r.clone()], vec![local(&model, true)]);
    assert!(has(&screen(&present, 200, 40), "✓ "));

    let partial = lib(vec![r.clone()], vec![local(&model, false)]);
    let partial_rows = screen(&partial, 200, 40);
    assert!(has(&partial_rows, "◐ "), "{partial_rows:#?}");
    assert!(
        has(&partial_rows, "d resume the download"),
        "a half-downloaded model is resumed, not restarted:\n{partial_rows:#?}"
    );

    let absent = lib(vec![r], Vec::new());
    let absent_rows = screen(&absent, 200, 40);
    assert!(has(&absent_rows, "· "), "{absent_rows:#?}");
    assert!(has(&absent_rows, "weights are not in the local cache"));
    assert!(has(&absent_rows, "d download the weights"));
}

#[test]
fn the_settings_form_marks_the_rows_that_were_changed_and_previews_the_command() {
    let mut a = flagship();
    a.lib.open_cards().expect("opens");
    a.lib.open_config().expect("opens");
    assert_eq!(a.lib.view, View::Config);
    let key = a.lib.config_rows()[0].key.clone();
    a.lib.overrides.insert(key.clone(), "4242".into());

    let rows = screen(&a, 200, 50);
    assert!(has(&rows, "SETTINGS ─ 1 changed"), "{rows:#?}");
    assert!(has(&rows, "•"), "the gutter marks the changed row");
    assert!(has(&rows, "4242"), "{rows:#?}");
    assert!(has(&rows, "COMMAND"), "{rows:#?}");
    assert!(
        has(&rows, "met serve"),
        "a form that hides its output makes the user guess:\n{rows:#?}"
    );
}

#[test]
fn a_field_being_edited_shows_its_buffer_and_a_cursor_not_the_stored_value() {
    let mut a = flagship();
    a.lib.open_cards().expect("opens");
    a.lib.open_config().expect("opens");
    a.lib.editing = true;
    a.lib.edit_buffer = "99991".into();
    let rows = screen(&a, 200, 50);
    assert!(has(&rows, "99991▏"), "{rows:#?}");
}

#[test]
fn a_validation_error_attaches_to_the_row_that_caused_it() {
    let mut a = flagship();
    a.lib.open_cards().expect("opens");
    a.lib.open_config().expect("opens");
    a.lib.error = Some("must be a positive integer".into());
    assert!(has(&screen(&a, 200, 50), "must be a positive integer"));
}

#[test]
fn a_card_says_on_its_face_when_enter_will_refuse_it() {
    let mut r = recipe("qwen3.6-35b-a3b-fp8-mtp");
    r.min_nodes = 2;
    let model = r.model.clone();
    let mut a = lib(vec![r], vec![local(&model, true)]);
    a.lib.open_cards().expect("opens");
    let rows = screen(&a, 200, 50);
    assert!(
        has(
            &rows,
            "needs 2 nodes — the dashboard starts single-node runs only"
        ),
        "{rows:#?}"
    );
    assert!(!has(&rows, "⏎ configure and start"), "{rows:#?}");
    assert!(has(&rows, "EP=2"), "the topology chip says why:\n{rows:#?}");
}

#[test]
fn a_recipe_for_another_runtime_is_listed_but_never_offered_as_launchable() {
    let mut r = recipe("qwen3.6-35b-a3b-fp8-mtp");
    r.runtime = Some("vllm".into());
    let model = r.model.clone();
    let mut a = lib(vec![r], vec![local(&model, true)]);
    let list = screen(&a, 200, 50);
    assert!(
        has(&list, " vllm "),
        "it is listed, never hidden:\n{list:#?}"
    );

    a.lib.open_cards().expect("opens");
    let cards = screen(&a, 200, 50);
    assert!(
        has(&cards, "this runtime cannot be launched from here"),
        "{cards:#?}"
    );
    assert!(has(&cards, "⊘ vllm"), "and the card is marked:\n{cards:#?}");
}

#[test]
fn every_library_pane_survives_narrow_and_short_terminals() {
    let mut a = flagship();
    for (w, h) in [(20u16, 4u16), (20, 8), (20, 40), (40, 12), (200, 3)] {
        assert_eq!(screen(&a, w, h).len(), h as usize, "list at {w}x{h}");
    }
    a.lib.open_cards().expect("opens");
    for (w, h) in [(20u16, 4u16), (20, 8), (40, 12), (200, 3)] {
        assert_eq!(screen(&a, w, h).len(), h as usize, "cards at {w}x{h}");
    }
    a.lib.open_config().expect("opens");
    for (w, h) in [(20u16, 4u16), (20, 8), (40, 12), (200, 3)] {
        assert_eq!(screen(&a, w, h).len(), h as usize, "config at {w}x{h}");
    }
}

/// 2026-09-26: Each weights state is a word on the row, not only the mark
/// glyph.
#[test]
fn every_weights_state_is_a_word_on_the_row_not_only_a_mark_glyph() {
    let r = recipe("qwen3.6-35b-a3b-fp8-mtp");
    let model = r.model.clone();

    let complete = lib(vec![r.clone()], vec![local(&model, true)]);
    let rows = screen(&complete, 200, 50);
    assert!(has(&rows, " on disk "), "{rows:#?}");

    let partial = lib(vec![r.clone()], vec![local(&model, false)]);
    let rows = screen(&partial, 200, 50);
    assert!(has(&rows, " partial "), "{rows:#?}");

    let absent = lib(vec![r], Vec::new());
    let rows = screen(&absent, 200, 50);
    assert!(has(&rows, " not downloaded "), "{rows:#?}");
    assert!(
        !has(&rows, " on disk "),
        "absence must not wear the presence badge:\n{rows:#?}"
    );

    let running = downloading(4_000_000_000, 34_900_000_000);
    let rows = screen(&running, 200, 50);
    assert!(has(&rows, " downloading "), "{rows:#?}");
}

/// 2026-09-26: In a mixed list each row shows its own state.
#[test]
fn a_mixed_list_shows_each_rows_own_state() {
    let mut here = recipe("qwen3.6-35b-a3b-fp8-mtp");
    here.model = "org/model-here".into();
    let mut gone = recipe("qwen3.6-35b-a3b-fp8-mtp");
    gone.model = "org/model-absent".into();
    let a = lib(vec![here, gone], vec![local("org/model-here", true)]);
    let rows = screen(&a, 200, 50);
    let here_row = rows
        .iter()
        .position(|r| r.contains("org/model-here"))
        .expect("row");
    let gone_row = rows
        .iter()
        .position(|r| r.contains("org/model-absent"))
        .expect("row");
    // 2026-09-26: The badge is on line 2 of each 3-line row.
    assert!(rows[here_row + 1].contains(" on disk "), "{rows:#?}");
    assert!(rows[gone_row + 1].contains(" not downloaded "), "{rows:#?}");
}

/// 2026-09-26: On a short terminal the form scrolls so the selected row stays
/// on screen, with the command preview kept at the bottom.
#[test]
fn the_settings_form_scrolls_to_keep_the_selected_row_on_screen() {
    let mut a = flagship();
    a.lib.open_cards().expect("opens");
    a.lib.open_config().expect("opens");
    let rows_in_form = a.lib.config_rows();
    let first_key = rows_in_form.first().expect("has rows").key.clone();
    let last_key = rows_in_form.last().expect("has rows").key.clone();
    a.lib.row = rows_in_form.len() - 1;

    // 2026-09-26: Too short for head, every row and preview together.
    let rows = screen(&a, 100, 16);
    assert!(
        has(&rows, &last_key),
        "the selected (last) row is on screen:\n{rows:#?}"
    );
    assert!(
        !has(&rows, &first_key),
        "the top scrolled away to make room:\n{rows:#?}"
    );
    assert!(
        has(&rows, "COMMAND") || has(&rows, "met "),
        "the preview stays pinned at the bottom:\n{rows:#?}"
    );

    a.lib.row = 0;
    let rows = screen(&a, 100, 16);
    assert!(has(&rows, &first_key), "{rows:#?}");
}