metrale_bench/benchmarks/video/
provision.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-26: The committed video clips, and writing them to disk.
4//!
5//! The clips are `include_bytes!`d into the binary and written to
6//! `~/.metrale/artifacts/video` behind a content-derived stamp, so a changed
7//! clip re-provisions without a version bump. The vision fixtures use the
8//! same scheme.
9//!
10//! Owner: bench, video.
11//! Invariants:
12//! - `provision` commits the stamp only after every clip write succeeded.
13
14use anyhow::Result;
15
16use crate::artifacts::{ArtifactStore, Stamp, write_asset_bytes};
17
18/// 2026-09-26: A clip and what it shows.
19pub struct Clip {
20    pub name: &'static str,
21    pub bytes: &'static [u8],
22    /// 2026-09-26: The colors it shows, in order, one per second.
23    pub colors: &'static [&'static str],
24    /// 2026-09-26: Seconds of footage. Only `provision_tests.rs` reads it, to
25    /// pin the 1:2:4 durations the geometry leg relies on.
26    pub seconds: u32,
27    /// 2026-09-26: True for a container the server decodes with ffmpeg (every
28    /// one but GIF). Only `provision_tests.rs` reads it; the driver decides a
29    /// skip from the server's error (`request::is_decoder_unavailable`).
30    pub needs_ffmpeg: bool,
31    pub mime: &'static str,
32}
33
34/// 2026-09-26: Five clips, used in pairs and one triple:
35///
36/// * `01` vs `02`: temporal order. The same four colors reversed, same
37///   container and duration.
38/// * `01` vs `03`: backend parity. The same colors as an MP4 (ffmpeg) and a
39///   GIF (decoded in-process); both must cost the same prompt tokens.
40/// * `05`, `04`, `01`: geometry at 1 s, 2 s and 4 s
41///   (`geometry::check_proportional`).
42pub const CLIPS: &[Clip] = &[
43    Clip {
44        name: "01_colors_fwd.mp4",
45        bytes: include_bytes!("../../../assets/video/01_colors_fwd.mp4"),
46        colors: &["red", "green", "blue", "yellow"],
47        seconds: 4,
48        needs_ffmpeg: true,
49        mime: "video/mp4",
50    },
51    Clip {
52        name: "02_colors_rev.mp4",
53        bytes: include_bytes!("../../../assets/video/02_colors_rev.mp4"),
54        colors: &["yellow", "blue", "green", "red"],
55        seconds: 4,
56        needs_ffmpeg: true,
57        mime: "video/mp4",
58    },
59    Clip {
60        name: "03_colors_fwd.gif",
61        bytes: include_bytes!("../../../assets/video/03_colors_fwd.gif"),
62        colors: &["red", "green", "blue", "yellow"],
63        seconds: 4,
64        needs_ffmpeg: false,
65        mime: "image/gif",
66    },
67    Clip {
68        name: "05_colors_unit.mp4",
69        bytes: include_bytes!("../../../assets/video/05_colors_unit.mp4"),
70        colors: &["red"],
71        seconds: 1,
72        needs_ffmpeg: true,
73        mime: "video/mp4",
74    },
75    Clip {
76        name: "04_colors_half.mp4",
77        bytes: include_bytes!("../../../assets/video/04_colors_half.mp4"),
78        colors: &["red", "green"],
79        seconds: 2,
80        needs_ffmpeg: true,
81        mime: "video/mp4",
82    },
83];
84
85pub fn clip(name: &str) -> Option<&'static Clip> {
86    CLIPS.iter().find(|c| c.name == name)
87}
88
89/// 2026-09-26: Content-derived over every clip's name and bytes, so a changed
90/// clip re-provisions without a version bump.
91fn stamp_value() -> String {
92    crate::benchmarks::content_stamp("video-fixtures-v1", CLIPS.iter().map(|c| (c.name, c.bytes)))
93}
94
95pub const PLUGIN_ID: &str = "video";
96
97pub fn provision(store: &ArtifactStore) -> Result<std::path::PathBuf> {
98    let dir = store.plugin_dir(PLUGIN_ID)?;
99    let stamp = Stamp::new(&dir, ".provisioned", stamp_value());
100    if stamp.is_current() {
101        return Ok(dir);
102    }
103    for c in CLIPS {
104        write_asset_bytes(&dir, c.name, c.bytes)?;
105    }
106    // 2026-09-26: Last: a stamp written before the writes complete would mark
107    // a partial directory as current.
108    stamp.commit()?;
109    Ok(dir)
110}
111
112#[cfg(test)]
113#[path = "provision_tests.rs"]
114mod provision_tests;