forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

layout.rs4842 lines, 204.1 KiBHistoryRawDownload
1//! What is drawn and where: the toolbar, the theme, the notices, the lanes
2//! and their marks, the tints, the subtitle rows and the sliders.
3
4use super::*;
5
6/// The class the user reported twice in one day ("some menus are belongs to
7/// old ui ... for example resolution picker", then "right click menu in
8/// library is old too"): a surface that paints a *role* token
9/// (`BG_HOVER`/`BG_SELECTED`/`BG_RAISED`) rather than a Darkroom token used
10/// to get the legacy tree's pale greys, because the Darkroom palette still
11/// carried them. Dozens of call sites read those three roles; the fix is the
12/// palette, and this pins it: the Darkroom surfaces are DESIGN §2.1's mock
13/// values (canvas, panel, raised, hover), they step up in that order so a
14/// hovered row is visible on a resting one, the picked-row fill sits between
15/// raised and hover (the real selection mark is the 1px ink1 ring, DESIGN §4),
16/// and the dim hover stays below raised.
17#[test]
18fn the_darkroom_palettes_interaction_greys_follow_design_2_1() {
19 use crate::ui::theme::darkroom;
20 let grey = |v: u32| (v >> 16 & 0xff, v >> 8 & 0xff, v & 0xff);
21 let lum = |v: u32| {
22 let (r, g, b) = grey(v);
23 r + g + b
24 };
25 // Pinned by value, so a palette sweep that drifts a surface fails here
26 // rather than in a screenshot.
27 assert_eq!(darkroom::BG_CANVAS, 0x0b0c0e, "canvas is DESIGN §2.1");
28 assert_eq!(darkroom::BG_PANEL, 0x131518, "panel is DESIGN §2.1");
29 assert_eq!(darkroom::BG_RAISED, 0x1b1e22, "raised is DESIGN §2.1");
30 assert_eq!(darkroom::BG_HOVER, 0x24282d, "hover is DESIGN §2.1");
31 assert!(
32 lum(darkroom::BG_CANVAS) < lum(darkroom::BG_PANEL)
33 && lum(darkroom::BG_PANEL) < lum(darkroom::BG_RAISED)
34 && lum(darkroom::BG_RAISED) < lum(darkroom::BG_HOVER),
35 "the surfaces must step up canvas < panel < raised < hover -- a \
36 button or menu that paints a lower step than its panel sinks into it"
37 );
38 assert!(
39 lum(darkroom::BG_RAISED) < lum(darkroom::BG_SELECTED)
40 && lum(darkroom::BG_SELECTED) <= lum(darkroom::BG_HOVER),
41 "the picked-row fill sits between raised and hover; past hover it \
42 would read as a hover, and at raised it would not read at all"
43 );
44 assert!(
45 lum(darkroom::BG_HOVER_DIM) < lum(darkroom::BG_RAISED),
46 "the dim hover is the step below, not above"
47 );
48}
49
50/// The whole reason `ui/theme.rs` exists: a colour written anywhere else is
51/// a colour the next palette sweep will miss, which is exactly how 186 grey
52/// calls survived every previous attempt at this.
53#[test]
54fn no_colour_is_written_outside_the_theme() {
55 let source = ui_source();
56 let stray: Vec<&str> = source
57 .lines()
58 .filter(|l| l.contains("rgb(0x") || l.contains("rgba(0x"))
59 .collect();
60 assert!(
61 stray.is_empty(),
62 "colour written outside the theme: {stray:?}"
63 );
64}
65
66/// The literal-grep above is blind to a hue arriving through a theme
67/// *constant*: `DARK_SEAM` carried `rgba(0,0,0,.7)` (`0xRRGGBBAA`) into
68/// `rgb()`, which reads the alpha byte as blue -- 2436 blue pixels in a
69/// darkroom screenshot, on a call site that never once wrote `0x` itself.
70/// So this scan reads the theme's own encoding: every constant whose low
71/// byte is not `ff` (i.e. `0xRRGGBBAA` with a real alpha) is alpha-carrying,
72/// and an alpha-carrying role may only ever be handed to `rgba(`, never
73/// `rgb(`.
74#[test]
75fn an_alpha_carrying_role_never_reaches_rgb() {
76 let theme = src_text("ui/theme.rs");
77 let alpha_roles: Vec<&str> = theme
78 .lines()
79 .filter_map(|l| {
80 let l = l.trim();
81 let l = l.strip_prefix("pub const ")?;
82 let (name, rest) = l.split_once(':')?;
83 let hex = rest.trim().strip_prefix("u32 = 0x")?;
84 let hex = hex.trim_end_matches(';');
85 (hex.len() == 8 && !hex.ends_with("ff")).then_some(name.trim())
86 })
87 .collect();
88 assert!(
89 alpha_roles.len() >= 8,
90 "the theme's alpha-carrying roles moved; this scan is blind"
91 );
92
93 let source = ui_source();
94 let mut misuses = Vec::new();
95 for role in &alpha_roles {
96 if source.contains(&format!("rgb({role}(")) {
97 misuses.push(*role);
98 }
99 }
100 assert!(
101 misuses.is_empty(),
102 "alpha-carrying role(s) reaching rgb() instead of rgba(): {misuses:?}"
103 );
104}
105
106/// "It scrolls" is not "it can be found": at the 640x360 floor the timeline
107/// takes its share and no more, so a third track is behind a scroll -- and
108/// the line that says so has to keep telling the truth *while* the column is
109/// being scrolled, or it is an instruction nobody can carry out.
110#[test]
111fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() {
112 // The timeline is a region and not the window: its chrome -- the
113 // scrollbar strip's row included, which is the larger of the two the
114 // zoom can leave in it -- and one whole lane fit the share it may take
115 // at the floor.
116 let floor = 360. * TIMELINE_SHARE;
117 assert!(
118 timeline_fixed_h(true) + LANE_H <= floor,
119 "{} px of chrome and a lane will not fit {floor} px",
120 timeline_fixed_h(true)
121 );
122 // The inspector's rows are not one height, so its own line is measured
123 // in pixels off the scroll instead: gpui keeps the offset negative going
124 // down, and at the bottom the two cancel out exactly.
125 assert_eq!(px_below(120., 0.), 120.);
126 assert_eq!(px_below(120., -40.), 80.);
127 assert_eq!(px_below(120., -120.), 0.);
128 assert_eq!(px_below(0., 0.), 0.);
129}
130
131/// One slot: a second message replaces the first on screen, so the newest
132/// line is always the one a person reads and an old failure never lingers
133/// under a newer line.
134#[test]
135fn a_second_message_replaces_the_first_on_screen() {
136 let mut q = std::collections::VecDeque::new();
137 push_notice(&mut q, "Nothing added: no video stream".into());
138 push_notice(&mut q, "Nothing added: the file is not there".into());
139 assert_eq!(q.len(), 1);
140 assert_eq!(
141 q.back().map(|n: &crate::notices::Toast| n.text.as_ref()),
142 Some("Nothing added: the file is not there")
143 );
144
145 // A held key that refuses says its one sentence once.
146 push_notice(&mut q, "Nothing added: the file is not there".into());
147 assert_eq!(q.len(), 1);
148
149 // However many messages arrive, the newest is the one kept.
150 for i in 0..NOTICES_MAX + 3 {
151 push_notice(&mut q, format!("Scan failed: {i}").into());
152 }
153 assert_eq!(q.len(), 1);
154 assert_eq!(
155 q.back().map(|n: &crate::notices::Toast| n.text.as_ref()),
156 Some(format!("Scan failed: {}", NOTICES_MAX + 2).as_str())
157 );
158}
159
160/// An export's own outcome is what a person started it to read, so it must
161/// never be drawn out of sight: it replaces whatever was on screen, and it is
162/// the newest, the one the status bar draws.
163#[test]
164fn an_export_outcome_is_the_newest_and_is_drawn() {
165 let mut q = std::collections::VecDeque::new();
166 push_notice(
167 &mut q,
168 "Editing copy ready for a.mp4: Editing copies on cuts on it".into(),
169 );
170 push_notice(&mut q, "Subtitles b.srt: 1 track(s) in the palette".into());
171 push_notice(&mut q, format!("{EXPORT_DONE}out.mp4").into());
172 assert_eq!(q.len(), 1);
173 assert_eq!(
174 q.back().map(|n: &crate::notices::Toast| n.text.as_ref()),
175 Some(format!("{EXPORT_DONE}out.mp4")).as_deref(),
176 "the export's result must be the newest notice, the one the stack draws"
177 );
178
179 // A failed export is the same class: the outcome, whichever it was.
180 let mut q = std::collections::VecDeque::new();
181 push_notice(
182 &mut q,
183 "Editing copy ready for a.mp4: Editing copies on cuts on it".into(),
184 );
185 push_notice(&mut q, "Export failed: disk full".into());
186 assert_eq!(
187 q.back().map(|n: &crate::notices::Toast| n.text.as_ref()),
188 Some("Export failed: disk full")
189 );
190}
191
192/// The cards are sections of the inspector, not sheets over the timeline:
193/// adjusting a clip must never hide the clip. Structural, because that is
194/// where the rule lives -- a card rendered from the root again would be an
195/// overlay again, whatever it looked like on the day it was written.
196#[test]
197fn an_inspector_section_occludes_no_timeline() {
198 // Whichever file the root render has come to live in, from the impl to the
199 // end of it -- found rather than named, so moving the root does not quietly
200 // leave this rule reading a file the render is no longer in.
201 let render = source_from("impl Render for Player");
202 let dock = src_text("ui/dock_stance.rs");
203 let stance = src_text("ui/stance.rs");
204 for card in [
205 "eq_card",
206 "color_card",
207 "speed_card",
208 "silence_card",
209 "mix_card",
210 "subtitle_style_card",
211 ] {
212 // Docked (unmaximized), the card is a section of the dock's own
213 // narrow column; maximized, it escapes to `stance-centre`'s window-
214 // space positioning context instead -- either way it is mounted
215 // through the darkroom's own structure, never straight off the
216 // root render.
217 assert!(
218 dock.contains(&format!("player.{card}("))
219 || stance.contains(&format!("player.{card}(")),
220 "{card} is not mounted anywhere in the darkroom"
221 );
222 assert!(
223 !render.contains(&format!("self.{card}(")),
224 "{card} is drawn from the root again -- it is an overlay over the timeline"
225 );
226 }
227 // The docked cards are placed against the dock's own box, and the
228 // maximized escape against `stance-centre` -- both positioning contexts,
229 // which is what turns `scrim()` (`absolute().inset_0()`) from a
230 // window-wide sheet into a contained one.
231 assert!(
232 stance.contains(".relative()"),
233 "the darkroom has no positioning context: its cards would cover the window"
234 );
235}
236
237#[test]
238fn a_stateful_button_keeps_its_rect() {
239 // A toggle's own state must never gate whether the button exists --
240 // only how it looks. Flip the state and the pointer's target (the
241 // element the hitmap id names, and the rect a click lands on) is
242 // unchanged; only the label and the `active` styling read the flag.
243 // "eq-spectrum" and "export-cancel" are the darkroom's own stateful
244 // toggles: the first flips `self.eq_spectrum`, the second reads
245 // `armed` (whether cancel is armed), and neither may gate its own
246 // button out of the tree.
247 let cards = src_text("ui/cards");
248 for (id, flag) in [
249 ("\"eq-spectrum\"", "self.eq_spectrum"),
250 ("\"export-cancel\"", "armed"),
251 ] {
252 let at = cards.find(id).unwrap_or_else(|| panic!("no {id} button"));
253 let before = &cards[at.saturating_sub(350)..at];
254 assert!(
255 !before.contains(&format!(".when({flag}"))
256 && !before.contains(&format!(".when(!{flag}")),
257 "{id} is gated on the very flag it flips -- its rect would move when the state does"
258 );
259 }
260}
261
262#[test]
263fn nothing_clickable_is_smaller_than_the_wcag_minimum() {
264 // Every hit target in the panel, including the scrub strip -- whose bar
265 // is 6 px to look at and whose click area must not be.
266 const {
267 assert!(CONTROL_H >= HIT_MIN);
268 }
269 const {
270 assert!(RULER_HIT_H >= HIT_MIN);
271 }
272 const {
273 assert!(LANE_H >= HIT_MIN);
274 }
275 // A clip box is a hit target too, and its two trim strips occlude it:
276 // on a box narrower than the pair there is no body left to press, so
277 // the clip cannot be selected, dragged or menued at all -- which is
278 // every clip a jumpcut leaves at a normal zoom. Below three handles
279 // there are no strips.
280 assert!(!trims(0.));
281 assert!(!trims(EDGE_W));
282 assert!(!trims(2. * EDGE_W), "a box that is all handle and no clip");
283 assert!(!trims(3. * EDGE_W - 0.1));
284 // And where they are drawn, what is left between them is a hit target
285 // in its own right -- a whole handle's width of clip.
286 for width in [3. * EDGE_W, 24., 100., 4000.] {
287 assert!(trims(width));
288 assert!(
289 width - 2. * EDGE_W >= EDGE_W,
290 "{width} px of box leaves no middle"
291 );
292 }
293}
294
295#[test]
296fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() {
297 // Two lanes, a ruler, a button row and the timecode line, inside the
298 // panel the window is sized for.
299 const {
300 assert!(
301 CONTROL_H + RULER_HIT_H + 2. * LANE_H + 17. + 4. * 8. + 16. <= PANEL_H,
302 "the second lane does not fit the panel"
303 );
304 }
305 // Headers and clip boxes are as tall as the lane, and the lane is a
306 // click target (WCAG 2.5.8).
307 const {
308 assert!(LANE_H >= HIT_MIN);
309 }
310 // A label row that ate the whole lane would leave no waveform.
311 const {
312 assert!(LABEL_H < LANE_H / 2.);
313 }
314 // An added track adds its own row to the panel, and the two a project
315 // starts with leave it exactly the height it has always been.
316 assert_eq!(panel_h(2), PANEL_H);
317 assert_eq!(panel_h(1), PANEL_H);
318 assert_eq!(panel_h(3), PANEL_H + LANE_H + 8.);
319 assert_eq!(
320 panel_h(LANES_MAX),
321 PANEL_H + lanes_h(LANES_MAX) - lanes_h(2)
322 );
323 // Past the cap the column scrolls instead: the panel stops growing, so
324 // no number of tracks can push the picture off the window.
325 assert_eq!(panel_h(LANES_MAX + 1), panel_h(LANES_MAX));
326 assert_eq!(panel_h(50), panel_h(LANES_MAX));
327 assert_eq!(lanes_h(0), 0.);
328 assert_eq!(lanes_h(1), LANE_H);
329 assert_eq!(lanes_h(2), 2. * LANE_H + 8.);
330}
331
332/// The strip's row is furniture only while there is somewhere to scroll to:
333/// zoomed out to the whole timeline the strip is not drawn and neither is its
334/// height -- out of every budget at once (the region, the box the lanes are
335/// laid out against, and the seam's floor), or the lanes would gain or lose a
336/// strip's row at the zoom boundary without the strip to show for it.
337#[test]
338fn the_scroll_strip_row_comes_and_goes_with_the_zoom() {
339 use crate::{SCROLL_ROW_H, Split, lanes_h, split_size, timeline_fixed_h, timeline_h};
340 use gpui::{px, size};
341
342 // The strip's row, and only the strip's row, is what the two faces differ
343 // by -- the bar is centred in it. The hit area is taller than the bar and
344 // overlays the lanes above it, so it costs no row.
345 assert_eq!(
346 timeline_fixed_h(true) - timeline_fixed_h(false),
347 SCROLL_ROW_H
348 );
349 let window = size(px(1280.), px(720.));
350 for scroll in [false, true] {
351 // Whatever the strip is doing, the lanes keep exactly the room they
352 // had: the region grows by the strip's row when it appears, by
353 // exactly the row the lanes would otherwise lose to it.
354 assert_eq!(timeline_h(2, scroll) - timeline_fixed_h(scroll), lanes_h(2));
355 assert_eq!(timeline_h(6, scroll) - timeline_fixed_h(scroll), lanes_h(6));
356 // ...and the floor keeps a whole lane standing under the line, on
357 // either face of the zoom boundary.
358 let floor = split_size(Split::Timeline, Some(0.), 2, window, scroll);
359 let box_h = floor - timeline_fixed_h(scroll);
360 assert!(box_h < lanes_h(2), "no line to pay for at the floor");
361 assert!(
362 box_h - LABEL_H - 8. >= LANE_H,
363 "the floor leaves {} px for a {LANE_H} px lane",
364 box_h - LABEL_H - 8.
365 );
366 // The two floors land the lanes in the same place: whichever face
367 // the zoom is on, a timeline held at its floor shows the same whole
368 // lane under the same line -- the strip's row comes and goes with
369 // the floor, not out of the lane. (A size dragged into the interior
370 // stays the hand's across the boundary, and the lanes are simply
371 // given the row back.)
372 assert_eq!(box_h, LANE_H + LABEL_H + 8.);
373 }
374 // The share covers the taller floor, strip in -- the one the clamp would
375 // otherwise overrule at the 640x360 floor, saying the panel takes less of
376 // a short window than it does.
377 assert!(
378 timeline_fixed_h(true) + LANE_H + LABEL_H + 8. <= 360. * TIMELINE_SHARE,
379 "the strip-bearing floor will not fit the share"
380 );
381}
382
383/// The lane stack's thumb: the visible share of the rows at their own place
384/// on the track, the time axis's own thumb turned through a right angle.
385#[test]
386fn the_lane_thumb_is_the_visible_share_of_the_stack() {
387 use crate::SCROLL_THUMB_MIN;
388 use crate::lanes_thumb;
389
390 // Whole stack on screen: the track fills and there is nothing to scroll.
391 assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.));
392 assert_eq!(lanes_thumb(200., 0., 0., 0.), (0., 200.));
393 // Half the stack visible, taken halfway down: a half-height thumb at the
394 // halfway mark.
395 assert_eq!(lanes_thumb(200., 400., 200., 100.), (50., 100.));
396 assert_eq!(lanes_thumb(200., 400., 200., 0.), (0., 100.));
397 // The floor height: however tall the stack, the thumb stays holdable --
398 // and the clamp keeps it on the track, not the caller.
399 let (y, h) = lanes_thumb(200., 2000., 200., 1800.);
400 assert_eq!(h, SCROLL_THUMB_MIN);
401 assert_eq!(y, 200. - SCROLL_THUMB_MIN);
402 assert_eq!(lanes_thumb(200., 2000., 200., 0.).0, 0.);
403 assert_eq!(lanes_thumb(200., 1_000_000., 200., 0.).0, 0.);
404}
405
406/// The selection itself: clicks in order, the anchor under the hand, the
407/// toggle that assembles a group, and the plain click that replaces it all.
408#[test]
409fn a_selection_holds_its_picks_in_click_order_and_anchors_the_last() {
410 use crate::Selection;
411
412 let mut sel = Selection::new();
413 assert!(sel.is_empty());
414 assert_eq!(sel.anchor(), None);
415
416 let (v, a, cap) = (
417 (Lane::V1, 0),
418 (Lane::A1, 1),
419 (Lane::new(LaneKind::Subtitle, 0), 0),
420 );
421 sel.set_one(v);
422 assert_eq!(sel.len(), 1);
423 assert_eq!(sel.anchor(), Some(v));
424
425 // Ctrl-clicks join, in the order they were made.
426 sel.toggle(a);
427 sel.toggle(cap);
428 assert_eq!(sel.picks(), &[v, a, cap]);
429 assert_eq!(sel.anchor(), Some(cap), "the last pick is the anchor");
430 assert!(sel.contains(a));
431
432 // ...and a ctrl-click on a pick already held takes it back out, leaving
433 // the others where they were.
434 sel.toggle(a);
435 assert_eq!(sel.picks(), &[v, cap]);
436 assert!(!sel.contains(a));
437
438 // A plain click is the whole selection, one pick: whatever was held gives
439 // way to the thing just named.
440 sel.set_one(a);
441 assert_eq!(sel.picks(), &[a]);
442
443 // `add` joins without disturbing -- Select All's builder.
444 let mut all = Selection::new();
445 all.add(v);
446 all.add(a);
447 all.add(v);
448 assert_eq!(all.picks(), &[v, a], "a pick is never held twice");
449
450 sel.clear();
451 assert!(sel.is_empty());
452 assert_eq!(sel.anchor(), None);
453}
454
455/// `Player::pick`'s own decision, mirrored here against `Selection` alone
456/// (`pick` itself needs a `Context<Player>` this module has no window to
457/// build): a plain press on a clip already in a multi-pick must leave the
458/// set alone, since the press is where a set-drag begins -- collapsing here
459/// would make dragging a member of a selection move only that one clip.
460/// Collapsing to the one pressed belongs to a plain click, once it is a
461/// click and not a drag (`ui/bench_stance.rs`/`ui/timeline.rs`'s `on_click`).
462#[test]
463fn a_plain_press_on_an_already_picked_clip_keeps_the_set() {
464 use crate::Selection;
465
466 let (v, a, cap) = (
467 (Lane::V1, 0),
468 (Lane::A1, 0),
469 (Lane::new(LaneKind::Subtitle, 0), 0),
470 );
471 let mut sel = Selection::new();
472 sel.toggle(v);
473 sel.toggle(a);
474 sel.toggle(cap);
475 assert_eq!(sel.picks(), &[v, a, cap]);
476
477 let press = |sel: &mut Selection, target, ctrl| match ctrl {
478 true => sel.toggle(target),
479 false if sel.contains(target) => {}
480 false => sel.set_one(target),
481 };
482
483 press(&mut sel, a, false);
484 assert_eq!(
485 sel.picks(),
486 &[v, a, cap],
487 "a plain press on a member of the set keeps it, for a set-drag to move"
488 );
489
490 // A plain press on something outside the set still collapses to it --
491 // the ordinary single-select case.
492 let outside = (Lane::V1, 1);
493 press(&mut sel, outside, false);
494 assert_eq!(sel.picks(), &[outside]);
495}
496
497#[test]
498fn a_click_marks_the_whole_group_and_nothing_else() {
499 let (v, a) = ((Lane::V1, 0), (Lane::A1, 0));
500 // Clicking the video half of group 1 marks the audio half with it -- the
501 // pick, and everything sharing its link.
502 assert!(marked(v, Some(1), &[v], &[Some(1)]));
503 assert!(marked(a, Some(1), &[v], &[Some(1)]));
504 // Another group's clips stay unmarked, in either lane.
505 assert!(!marked((Lane::V1, 1), Some(2), &[v], &[Some(1)]));
506 assert!(!marked((Lane::A1, 1), Some(2), &[v], &[Some(1)]));
507 // A half a lift left behind has no group: it marks itself only, which
508 // is what makes it separately deletable. Two ungrouped clips must not
509 // mark each other by both being ungrouped.
510 assert!(marked(a, None, &[a], &[None]));
511 assert!(!marked(v, None, &[a], &[None]));
512 // A caption ctrl-clicked into the selection marks the clip it was pinned
513 // to, and the caption is marked by the clip's pick just the same.
514 let cap = (Lane::new(LaneKind::Subtitle, 0), 0);
515 assert!(marked(cap, Some(1), &[cap, v], &[None, Some(1)]));
516 assert!(marked(a, Some(1), &[cap, v], &[None, Some(1)]));
517 // Nothing selected marks nothing.
518 assert!(!marked(v, Some(1), &[], &[]));
519}
520
521#[test]
522fn an_envelope_stays_inside_the_box_it_is_drawn_in() {
523 // A ramp: silence at the start, full scale at the end.
524 let peaks: Vec<(f32, f32)> = (0..40)
525 .map(|i| (-(i as f32) / 39., i as f32 / 39.))
526 .collect();
527 let (w, h) = (100., 30.);
528 let cols = envelope(&peaks, 0., 1., w, h);
529 assert_eq!(cols.len(), (w / WAVE_COL) as usize + 1);
530 for &(x, top, bottom) in &cols {
531 assert!((0. ..=w).contains(&x), "x {x} outside 0..{w}");
532 assert!((0. ..=h).contains(&top), "top {top} outside 0..{h}");
533 assert!(
534 (0. ..=h).contains(&bottom),
535 "bottom {bottom} outside 0..{h}"
536 );
537 // Never inverted, and never a polygon with no area: silence has to
538 // read as a line rather than as nothing at all.
539 assert!(
540 bottom - top >= 1.,
541 "column {top}..{bottom} is thinner than a pixel"
542 );
543 }
544 // The ramp is drawn as a ramp: the last column is taller than the first.
545 let height = |&(_, top, bottom): &(f32, f32, f32)| bottom - top;
546 assert!(height(cols.last().unwrap()) > height(cols.first().unwrap()) + 5.);
547 // Degenerate inputs draw nothing rather than panicking.
548 assert!(envelope(&[], 0., 1., w, h).is_empty());
549 assert!(envelope(&peaks, 0., 1., 0., h).is_empty());
550 // A clip whose range runs past the peaks clamps to the last bucket.
551 assert!(!envelope(&peaks, 0., 99., w, h).is_empty());
552}
553
554/// A box laid out wider than any screen -- a long clip at a deep zoom -- is
555/// still one screen's worth of columns: the path a repaint has to build is
556/// bounded by what can be seen, not by what the layout says the box is.
557/// Unbounded, a 5 s clip zoomed to the frame is a path of millions of points
558/// per frame, and the repaint that stalls on it is the waveform that
559/// "disappeared".
560#[test]
561fn an_envelope_never_costs_more_points_than_a_screen_can_show() {
562 let peaks: Vec<(f32, f32)> = (0..200).map(|i| (-(i as f32) / 199., 1.)).collect();
563 // The width a 5 s clip is laid out at when the bed shows 8 frames of it.
564 let huge = 5. * 30. / 8. * 1200.;
565 let cols = envelope(&peaks, 0., 5., huge, 30.);
566 assert!(
567 cols.len() <= WAVE_COLS_MAX + 1,
568 "{} columns for a {huge} px box",
569 cols.len()
570 );
571 // ...and the slice actually painted is the part of the box on the bed,
572 // which is where that width stops mattering: a column per two visible
573 // pixels, at every zoom.
574 assert_eq!(envelope(&peaks, 0., 5., 1200., 30.).len(), 601);
575}
576
577/// The box a trim draws is the box its release commits, at every speed. The
578/// preview used to hand the *timeline* frame count to a source-frame field:
579/// at 2x a tail moved twice as fast as the pointer and snapped back on
580/// release, and a head drag moved the clip's other edge.
581#[test]
582fn a_trim_preview_lands_where_the_release_commits() {
583 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
584 session.set_gain(0.0);
585 for permille in SPEED_PRESETS {
586 // Live, so the loop owes it no undo step: the speeds are the axis
587 // this walks, and the trims below are what is undone.
588 session
589 .set_speed_live(Lane::V1, 0, Speed::from_permille(permille))
590 .expect("a clip alone on its lane may be speeded");
591 for edge in [Edge::Start, Edge::End] {
592 let clip = session.lane_clips(Lane::V1)[0].clone();
593 let (lo, hi) = session
594 .trim_room(Lane::V1, 0, edge)
595 .expect("clip 0 is there");
596 // Both walls and the middle of the room: the whole range a
597 // pointer can be clamped to.
598 for to in [lo, (lo + hi) / 2, hi] {
599 let preview = trimmed_clip(clip.clone(), edge, to, false);
600 // The drag is one edit and one undo step, so the next `to`
601 // is measured from the same clip this one was.
602 if session.trim_clip(Lane::V1, 0, edge, to) {
603 assert_eq!(
604 preview,
605 session.lane_clips(Lane::V1)[0],
606 "{edge:?} to {to} at {permille} per mille"
607 );
608 assert!(session.undo(), "the trim is one undo step");
609 } else {
610 // An edge already where it was asked to go is not an
611 // edit, and the preview draws the clip unchanged.
612 assert_eq!(preview, clip, "{edge:?} to {to} at {permille} per mille");
613 }
614 assert_eq!(session.lane_clips(Lane::V1)[0], clip, "back where it was");
615 }
616 }
617 }
618}
619
620/// The caption a drag is showing lands where the release commits -- the
621/// subtitle twin of the trim preview above -- and the two contracts the boxes
622/// on the lanes rest on: `place_sub`'s `at` wins over the placement's own
623/// `start`, and a gesture that changed nothing is `Ok` and not a refusal, so a
624/// front-end that toasted every `Ok` would toast a pick-up-put-back.
625#[test]
626fn a_caption_trim_preview_lands_where_the_release_commits() {
627 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
628 session.set_gain(0.0);
629 let fps = session.meta().frame_rate;
630 let srt = Path::new(env!("CARGO_MANIFEST_DIR"))
631 .join("../engine/tests/data/test_subs.srt")
632 .canonicalize()
633 .expect("the subtitle fixture");
634 session.import_subtitles(&srt).expect("the .srt imports");
635 let lane = session.add_lane(LaneKind::Subtitle);
636 // The whole track as a placement, exactly as `Player::sub_of_track` builds
637 // one from a palette row.
638 let out_us = session.subtitles()[0]
639 .cues
640 .iter()
641 .map(|c| c.end_us)
642 .max()
643 .expect("the fixture has cues");
644 let whole = SubClip {
645 start: 0,
646 frames: frames_of_us(out_us, fps),
647 track: 0,
648 in_us: 0,
649 out_us,
650 link: None,
651 };
652 session
653 .place_sub(lane, 30, whole)
654 .expect("an empty subtitle lane takes it");
655 assert_eq!(
656 session.sub_lane(lane)[0].start,
657 30,
658 "the frame the hand let go on wins over the placement's own start"
659 );
660 for edge in [Edge::Start, Edge::End] {
661 let (lo, hi) = session
662 .trim_sub_room(lane, 0, edge)
663 .expect("placement 0 is there");
664 for to in [lo, (lo + hi) / 2, hi] {
665 let placed = session.sub_lane(lane)[0];
666 let preview = trimmed_sub(placed, edge, to);
667 session
668 .trim_sub(lane, 0, edge, to)
669 .expect("an edge inside its own room is never refused");
670 let now = session.sub_lane(lane)[0];
671 assert_eq!(
672 (preview.start, preview.frames),
673 (now.start, now.frames),
674 "{edge:?} to {to}"
675 );
676 // One edit, one undo step -- and none at all where the edge was
677 // already there, which is the `Ok` that must stay silent.
678 if (now.start, now.frames) != (placed.start, placed.frames) {
679 assert!(session.undo(), "the trim is one undo step");
680 }
681 }
682 }
683 // Picked up and put back down: `Ok`, nothing moved, nothing to say.
684 let before = session.sub_lane(lane)[0];
685 session
686 .move_sub(lane, 0, lane, before.start)
687 .expect("a drop that changes nothing is not a refusal");
688 assert_eq!(session.sub_lane(lane)[0], before);
689 // ...and two captions over one frame are refused in words, which is what
690 // the notice shows verbatim.
691 let over = session
692 .place_sub(lane, before.start, whole)
693 .expect_err("two captions may not cover one frame");
694 assert!(over.to_string().contains("already covers"), "{over}");
695}
696
697/// A still trims the same way, and the preview knows it: its head grows
698/// forward from source frame 0 -- every frame of it is the same picture --
699/// so the box stretches instead of sliding left.
700#[test]
701fn a_stills_trim_preview_grows_forward_like_the_commit() {
702 let mut session = PlaybackSession::open(asset("test_still.png")).expect("a picture opens");
703 for edge in [Edge::Start, Edge::End] {
704 let clip = session.lane_clips(Lane::V1)[0].clone();
705 let (lo, hi) = session
706 .trim_room(Lane::V1, 0, edge)
707 .expect("clip 0 is there");
708 for to in [lo, (lo + hi) / 2, hi] {
709 let preview = trimmed_clip(clip.clone(), edge, to, true);
710 match session.trim_clip(Lane::V1, 0, edge, to) {
711 true => {
712 assert_eq!(
713 preview,
714 session.lane_clips(Lane::V1)[0],
715 "a still {edge:?} to {to}"
716 );
717 assert!(session.undo(), "the trim is one undo step");
718 }
719 false => assert_eq!(preview, clip, "a still {edge:?} to {to}"),
720 }
721 assert_eq!(session.lane_clips(Lane::V1)[0], clip, "back where it was");
722 }
723 }
724}
725
726/// gpui freezes a drag's payload for the whole gesture, and nothing stops a
727/// stroke from editing the lane under it: the drop has to find the clip that
728/// was picked up, not whatever slid into its index.
729#[test]
730fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() {
731 let at = |start: u32| Clip {
732 speed_keys: Vec::new(),
733 reversed: false,
734 stabilise: None, deinterlace: Default::default(), mark: Default::default(),
735 angle: Default::default(),
736 fade_in: 0,
737 fade_out: 0,
738 transition_out: 0,
739 transition_kind: Default::default(),
740 visualizer: 0,
741 viz_paint: 0,
742 gain_db: 0.0,
743 gain_keys: Vec::new(),
744 pan: 0,
745 pitch: 0.0,
746 transform_keys: Vec::new(),
747 opacity_keys: Vec::new(),
748 color_keys: Vec::new(),
749 effects: Vec::new(),
750 start,
751 in_frame: 0,
752 out_frame: 30,
753 source: 0,
754 link: None,
755 eq: None,
756 color: None,
757 transform: None,
758 fit: FitPolicy::Fit,
759 speed: Speed::NORMAL,
760 };
761 let lane = [at(0), at(30), at(60)];
762 let dragged = lane[2].clone();
763 assert_eq!(live_idx(&lane, 2, &dragged), Some(2), "nothing moved");
764 // A delete in front of it: the clip is now index 1, and the index the
765 // drag froze names a clip nobody grabbed.
766 let after = [at(0), at(60)];
767 assert_eq!(live_idx(&after, 2, &dragged), Some(1));
768 assert_eq!(live_idx(&after, 1, &dragged), Some(1));
769 // Deleted mid-drag: there is nothing to move, and moving its neighbour
770 // instead is exactly the bug this exists for.
771 assert_eq!(live_idx(&[at(0)], 2, &dragged), None);
772 assert_eq!(live_idx(&[], 0, &dragged), None);
773}
774
775#[test]
776fn a_quiet_source_still_draws_as_a_shape() {
777 // An eighth of full scale, which is about where the fixtures sit.
778 let quiet: Vec<(f32, f32)> = vec![(-0.125, 0.125), (-0.0625, 0.0625)];
779 let loud = normalise(quiet.clone());
780 assert_eq!(loud[0], (-1., 1.));
781 assert_eq!(loud[1], (-0.5, 0.5));
782 // Digital silence has no loudest sample to scale to; it must not divide
783 // by zero and must stay flat.
784 assert_eq!(normalise(vec![(0., 0.)]), vec![(0., 0.)]);
785 assert!(normalise(Vec::new()).is_empty());
786}
787
788/// The whole waveform path, from the file on disk to the columns that get
789/// painted: what no screenshot can assert about the shape.
790#[test]
791fn the_fixtures_waveform_reaches_the_lane_as_a_shape() {
792 let asset = |name: &str| {
793 std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
794 .join("../../assets")
795 .join(name)
796 };
797 let peaks = normalise(
798 engine::waveform::peaks(asset("test_av.mp4"), 0, WAVE_BPS)
799 .expect("open the fixture")
800 .expect("test_av.mp4 has audio"),
801 );
802 // 5 s of source at the rate the lane asks for.
803 assert!(peaks.len().abs_diff(5 * WAVE_BPS as usize) <= WAVE_BPS as usize);
804 let cols = envelope(&peaks, 0., 5., 600., 30.);
805 let height = |&(_, top, bottom): &(f32, f32, f32)| bottom - top;
806 let tallest = cols.iter().map(height).fold(0., f32::max);
807 let flattest = cols.iter().map(height).fold(f32::MAX, f32::min);
808 // The fixture's 1 Hz pulse: a full-scale peak and a near-silent dip in
809 // every second, so the drawn envelope is a shape and not a bar.
810 assert!(tallest > 25., "loudest column only {tallest} px of 30");
811 assert!(
812 flattest < 8.,
813 "quietest column {flattest} px -- no dips drawn"
814 );
815 // A video-only source draws no waveform at all rather than a flat fake.
816 assert!(
817 engine::waveform::peaks(asset("test_baseline.mp4"), 0, WAVE_BPS)
818 .expect("open the fixture")
819 .is_none()
820 );
821}
822
823#[test]
824fn every_mark_on_a_clip_is_legible_on_it() {
825 // The body a name and a waveform are drawn on is the clip's kind
826 // ([`clip_kind`]); the source tint is the border and the library
827 // swatch, and is measured for telling itself apart rather than for
828 // carrying text.
829 // Every palette a person can pick, not merely the one in force.
830 for id in crate::ui::theme::PaletteId::ALL {
831 let p = id.palette();
832 for (i, tint) in [p.CLIP_VIDEO, p.CLIP_AUDIO, p.CLIP_IMAGE, p.CLIP_TEXT]
833 .iter()
834 .enumerate()
835 {
836 // WCAG 1.4.3: the clip's name is body text on its tint.
837 assert!(
838 contrast(p.FG_PRIMARY, *tint) >= 4.5,
839 "{id:?} source {i}: label contrast {:.2}",
840 contrast(p.FG_PRIMARY, *tint)
841 );
842 // WCAG 1.4.11: the waveform is a non-text graphic on it.
843 assert!(
844 contrast(p.FG_SECONDARY, *tint) >= 3.,
845 "{id:?} source {i}: waveform contrast {:.2}",
846 contrast(p.FG_SECONDARY, *tint)
847 );
848 }
849 // A selected clip's bed is the same two marks on a different colour.
850 assert!(contrast(p.FG_PRIMARY, p.BG_SELECTED) >= 4.5, "{id:?}");
851 assert!(contrast(p.FG_SECONDARY, p.BG_SELECTED) >= 3., "{id:?}");
852 // The bed a gap shows through has to read as a hole in the lane --
853 // the clip is the object, the bed is the hole -- and the playhead
854 // has to be findable on both.
855 assert!(contrast(p.CLIP_VIDEO, p.BG_TIMELINE) >= 1.5, "{id:?}");
856 assert!(contrast(p.ACCENT_PLAYHEAD, p.BG_TIMELINE) >= 3., "{id:?}");
857 assert!(contrast(p.ACCENT_PLAYHEAD, p.CLIP_VIDEO) >= 3., "{id:?}");
858 }
859 // The sanity check on the ratio itself: black on white is 21:1.
860 assert!((contrast(0xffffff, 0x000000) - 21.).abs() < 0.01);
861}
862
863#[test]
864fn source_tints_differ_per_source_and_cycle() {
865 // The bug: the first entry *was* `BG_RAISED`, so the first file imported
866 // -- the one every session has -- wore the panel's own background and
867 // had no visible swatch at all.
868 assert_ne!(source_tint(0), BG_RAISED());
869 // ...in every family, since the swatch is drawn on whichever panel is
870 // in force (`ui::theme`) and a tint that vanished into one of them is a
871 // file with no colour at all.
872 for id in crate::ui::theme::PaletteId::ALL {
873 let p = id.palette();
874 for (i, &tint) in p.SOURCE_TINTS.iter().enumerate() {
875 assert_ne!(tint, p.BG_RAISED, "{id:?} tint {i} is the panel");
876 }
877 }
878 // Neighbouring sources must not share one, or an import is invisible.
879 assert_ne!(source_tint(0), source_tint(1));
880 assert_ne!(source_tint(1), source_tint(2));
881 assert_ne!(source_tint(2), source_tint(3));
882 // Past the palette it wraps -- never an index panic. The cycle length is
883 // the palette's own length (12 hues, DESIGN §2.2), not a fixed 4.
884 let n = SOURCE_TINTS().len();
885 assert_eq!(source_tint(n), source_tint(0));
886 assert_eq!(source_tint(n + 5), source_tint(5));
887 assert_eq!(source_tint(usize::MAX), SOURCE_TINTS()[usize::MAX % n]);
888}
889
890/// Not "they are different numbers" -- different *enough to see*, against
891/// each other and against the surface a swatch is drawn on. The palette is
892/// deliberately dark and low-saturation, so the margin is thin and a new
893/// tint picked by eye can land inside it without anyone noticing.
894#[test]
895fn source_tints_are_all_discernible() {
896 // Summed channel distance: `BG_RAISED` to the warm tint is 18, and that
897 // step is the one already accepted as readable on a lane.
898 let apart = |a: u32, b: u32| {
899 (0..3)
900 .map(|i| {
901 let shift = i * 8;
902 ((a >> shift) & 0xff).abs_diff((b >> shift) & 0xff)
903 })
904 .sum::<u32>()
905 };
906 // Every family, not the one in force: a palette is picked at runtime
907 // now, and four tints tuned by eye on one ground are exactly where a
908 // pair lands inside the margin on another.
909 for id in crate::ui::theme::PaletteId::ALL {
910 let p = id.palette();
911 for (i, &tint) in p.SOURCE_TINTS.iter().enumerate() {
912 assert!(
913 apart(tint, p.BG_RAISED) >= 16,
914 "{id:?} tint {i} is {} from the panel it sits on",
915 apart(tint, p.BG_RAISED)
916 );
917 for (j, &other) in p.SOURCE_TINTS.iter().enumerate().skip(i + 1) {
918 // The eleven non-darkroom families still cycle four tuned
919 // tints through the 12-wide wheel (`source_tint`'s own `%
920 // len()` reads them back identically either way) -- a
921 // literal repeat there is the intended cycle, not a
922 // collision, so it is skipped rather than failed. Darkroom's
923 // own twelve (DESIGN §2) are twelve *different* hues and
924 // never repeat, so a real collision there still fails this.
925 if tint == other {
926 continue;
927 }
928 assert!(
929 apart(tint, other) >= 16,
930 "{id:?} tints {i} and {j} are only {} apart",
931 apart(tint, other)
932 );
933 }
934 }
935 // The two a person sees side by side first must be further apart
936 // than the floor: source 0 and source 1 are the first import and
937 // the second.
938 assert!(apart(p.SOURCE_TINTS[0], p.SOURCE_TINTS[1]) >= 32, "{id:?}");
939 }
940 // Darkroom's own 12-hue wheel (DESIGN §2/§12 step 5's hook): every one
941 // of the twelve is a genuinely different hue, not four repeated three
942 // times like the other families still cycle -- a hue accidentally
943 // reintroduced by a future edit here is the "four shades of grey" bug
944 // this task exists to fix, so it fails loudly rather than skip past the
945 // `tint == other` escape hatch above.
946 let dr = crate::ui::theme::PaletteId::Darkroom.palette();
947 for (i, &a) in dr.SOURCE_TINTS.iter().enumerate() {
948 for (j, &b) in dr.SOURCE_TINTS.iter().enumerate().skip(i + 1) {
949 assert_ne!(a, b, "darkroom tints {i} and {j} collide");
950 }
951 }
952}
953
954/// A `.srt` dropped on the window is nobody's stream: it has no source
955/// entry, and the lookup that used to fall back to index 0 painted it with
956/// the first file's colour -- a swatch saying it came out of a film it
957/// never touched.
958#[test]
959fn a_standalone_subtitle_wears_no_file_tint() {
960 let sources = [
961 Source {
962 path: PathBuf::from("/films/a.mkv"),
963 audio_stream: 0, ..Default::default()
964 },
965 Source {
966 path: PathBuf::from("/films/b.mp4"),
967 audio_stream: 0, ..Default::default()
968 },
969 // A second stream of the first file is a second source and the
970 // same colour.
971 Source {
972 path: PathBuf::from("/films/a.mkv"),
973 audio_stream: 1, ..Default::default()
974 },
975 ];
976 assert_eq!(
977 file_tint(&sources, Path::new("/films/a.mkv")),
978 Some(source_tint(0))
979 );
980 assert_eq!(
981 file_tint(&sources, Path::new("/films/b.mp4")),
982 Some(source_tint(1))
983 );
984 assert_eq!(file_tint(&sources, Path::new("/subs/a.eng.srt")), None);
985 assert_eq!(file_tint(&[], Path::new("/films/a.mkv")), None);
986 // The same file under two spellings is one file and one colour: a
987 // source is stored symlink-resolved, everything else as it was typed.
988 let here = std::fs::canonicalize(".").expect("the crate directory");
989 let sources = [Source {
990 path: here.join("Cargo.toml"),
991 audio_stream: 0, ..Default::default()
992 }];
993 assert_eq!(
994 file_tint(&sources, Path::new("Cargo.toml")),
995 Some(source_tint(0)),
996 "a relative spelling of the source file wears the source's colour"
997 );
998}
999
1000/// A film's two ASS tracks with the timeline trimmed to twenty seconds:
1001/// one of them still has cues there and one has none, and the card said
1002/// nothing whatever about the second while the Subtitles list went on
1003/// showing it with its eighty-three cues.
1004///
1005/// And the 25 GB remux's thirty-five: naming those wrapped the row to ten
1006/// lines and pushed Destination under the fold, so past the value box's
1007/// three lines the same line counts instead.
1008#[test]
1009fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() {
1010 let film = "/films/An Episode 01.mkv";
1011 let two = [
1012 sub(film, Some(1), "[ASS]"),
1013 sub(film, Some(2), "[ASS] [FOR DUB]"),
1014 ];
1015 // What the engine answers about the one pick that reached it, and what
1016 // this side knows about the row that did not.
1017 let named = subtitle_plan("[ASS] → embedded".to_string(), &two, &[0]);
1018 assert_eq!(
1019 named,
1020 "[ASS] → embedded; [ASS] [FOR DUB] — in the palette, on no track"
1021 );
1022 assert!(
1023 named.chars().count() <= SUB_PLAN_CHARS,
1024 "two tracks fit the value box: {named}"
1025 );
1026 // Thirty-five off one file: twenty-two carry cues here, nine are
1027 // pictures, one could not be read, three have nothing on this timeline.
1028 let many: Vec<_> = (0..35)
1029 .map(|i| {
1030 let mut track = sub("/films/A Remux.mkv", Some(i), "eng — Subtitles");
1031 track.bitmap = (22..31).contains(&i);
1032 track.refused = (i == 31).then(|| "VobSub is pictures".to_string());
1033 track
1034 })
1035 .collect();
1036 // The picks are every track with a cue on the timeline: the twenty-two
1037 // and the nine picture ones, which the engine drops itself.
1038 let picks: Vec<usize> = (0..31usize).collect();
1039 let counted = subtitle_plan("22 tracks → embedded (…)".to_string(), &many, &picks);
1040 assert_eq!(
1041 counted,
1042 "22 of 35 → embedded; 9 pictures; 1 unread; 3 in the palette, on no track"
1043 );
1044 assert!(
1045 counted.chars().count() <= SUB_PLAN_CHARS,
1046 "thirty-five tracks still fit the value box: {counted}"
1047 );
1048 // Nothing on the timeline at all is still the engine's word for it.
1049 assert_eq!(subtitle_plan("none".to_string(), &[], &[]), "none");
1050 // The lanes are what an export writes once anything is placed on one, and
1051 // the engine words that whole ([`engine::export::planned_subtitles`]) --
1052 // including the lanes it carries *nothing* of, which is a sentence with no
1053 // pick behind it at all. That used to be dropped on the floor: the card said
1054 // "[ASS] — no cues here" twice and never said what became of the lane.
1055 let placed = "S1 [ASS] — past the last picture".to_string();
1056 assert_eq!(
1057 subtitle_plan(placed.clone(), &two, &[]),
1058 "S1 [ASS] — past the last picture; [ASS] [FOR DUB] — in the palette, on no track"
1059 );
1060 // ...and the row that sentence speaks for gets no clause of its own: a line
1061 // that names a lane's track and then calls the same track unplaced is the
1062 // card contradicting itself in one breath.
1063 assert!(!subtitle_plan(placed, &two[..1], &[]).contains("in the palette"));
1064}
1065
1066/// The list is in the order tracks were added, which is not the order a
1067/// person reads it in: importing a second film puts its tracks after the
1068/// first film's, and importing a third `.srt` for the first film puts that
1069/// one last of all. The rows still read as three sources.
1070#[test]
1071fn subtitle_rows_group_a_source_however_they_were_added() {
1072 let tracks = [
1073 sub("/films/a.mkv", Some(1), "eng"),
1074 sub("/films/b.mkv", Some(1), "eng"),
1075 sub("/films/a.mkv", Some(2), "fre"),
1076 sub("/subs/late.srt", None, "late.srt"),
1077 sub("/films/b.mkv", Some(3), "ger"),
1078 ];
1079 let groups = subtitle_rows(&tracks);
1080 assert_eq!(
1081 groups.iter().map(|g| g.name.as_str()).collect::<Vec<_>>(),
1082 ["a", "b", "late"],
1083 "one group per file, in the order the files first appear"
1084 );
1085 assert_eq!(
1086 groups
1087 .iter()
1088 .map(|g| g.rows.iter().map(|r| r.label.as_str()).collect::<Vec<_>>())
1089 .collect::<Vec<_>>(),
1090 [vec!["eng", "fre"], vec!["eng", "ger"], vec!["late.srt"]],
1091 "a file's tracks are contiguous and in add order"
1092 );
1093 // Numbered within the file, the way `row_name` numbers audio streams:
1094 // two tracks that both say "eng" are told apart by nothing else.
1095 assert_eq!(
1096 groups
1097 .iter()
1098 .map(|g| g.rows.iter().map(|r| r.number).collect::<Vec<_>>())
1099 .collect::<Vec<_>>(),
1100 [vec![1, 2], vec![1, 2], vec![1]]
1101 );
1102 // The swatch key is the file, so a group and that file's media rows
1103 // wear one colour -- and the standalone one has none.
1104 let sources = [Source {
1105 path: PathBuf::from("/films/a.mkv"),
1106 audio_stream: 0, ..Default::default()
1107 }];
1108 assert_eq!(
1109 file_tint(&sources, &groups[0].path),
1110 Some(source_tint(0)),
1111 "the group carries the path the tint is asked by"
1112 );
1113 assert_eq!(file_tint(&sources, &groups[2].path), None);
1114 // What a header's "N tracks" says: the group's own row count, which is
1115 // 2, 2, 1 here -- a film that gave several tracks and a standalone
1116 // `.srt` that gave exactly one.
1117 assert_eq!(
1118 groups.iter().map(|g| g.rows.len()).collect::<Vec<_>>(),
1119 [2, 2, 1]
1120 );
1121 // A standalone `.srt` is already its own group, named after its own
1122 // file ("late", not lumped under some catch-all "External" bucket) --
1123 // there is no sourceless case for a header to special-case.
1124 assert_eq!(groups[2].name, "late");
1125 assert_eq!(groups[2].path, PathBuf::from("/subs/late.srt"));
1126}
1127
1128/// The fold a click on a header sets is keyed by [`SubGroup::path`]
1129/// (`Player::sub_folded`), so it has to survive the very thing regrouping
1130/// is for: a second track landing on a file already in the list, or one
1131/// being removed from it. The group's path is the fold's whole identity,
1132/// so it must not move under either.
1133#[test]
1134fn a_groups_fold_key_survives_a_track_arriving_or_leaving_its_file() {
1135 let before = [
1136 sub("/films/a.mkv", Some(1), "eng"),
1137 sub("/films/b.mkv", Some(1), "eng"),
1138 ];
1139 let after_add = [
1140 sub("/films/a.mkv", Some(1), "eng"),
1141 sub("/films/b.mkv", Some(1), "eng"),
1142 sub("/films/a.mkv", Some(2), "fre"),
1143 ];
1144 let (before_groups, after_groups) = (subtitle_rows(&before), subtitle_rows(&after_add));
1145 assert_eq!(before_groups[0].path, after_groups[0].path, "a's key held");
1146 assert_eq!(before_groups[1].path, after_groups[1].path, "b's key held");
1147 // The group a second track landed on grew; the other did not move.
1148 assert_eq!(after_groups[0].rows.len(), 2);
1149 assert_eq!(after_groups[1].rows.len(), 1);
1150 // Removing that same track back off leaves the original key and count.
1151 let after_remove = subtitle_rows(&before);
1152 assert_eq!(after_remove[0].path, before_groups[0].path);
1153 assert_eq!(after_remove[0].rows.len(), 1);
1154}
1155
1156/// What the strip header, the section heading and the toggle's notice all
1157/// say. Two films each carrying an "eng" track are one word apart until the
1158/// film is in the name; a film carrying two is one word apart from itself.
1159#[test]
1160fn the_picked_subtitle_is_named_with_the_film_it_came_out_of() {
1161 let tracks = [
1162 sub("/films/a.mkv", Some(1), "eng"),
1163 sub("/films/b.mkv", Some(1), "eng"),
1164 sub("/films/a.mkv", Some(2), "eng"),
1165 sub("/films/b.mkv", Some(2), "und"),
1166 sub("/subs/late.srt", None, "late.srt"),
1167 ];
1168 let name = |track| sub_pick_name(&tracks, track).expect("a track that is there");
1169 // The two "eng"s of two films: one file gave several so its tracks are
1170 // numbered, the other gave one so it is not.
1171 assert_eq!(name(0), "eng 1 — a");
1172 assert_eq!(name(2), "eng 2 — a");
1173 assert_eq!(name(1), "eng 1 — b");
1174 assert_ne!(name(0), name(1), "two films' eng tracks read apart");
1175 for picked in [name(0), name(1), name(2)] {
1176 assert!(picked.contains(" — a") || picked.contains(" — b"));
1177 }
1178 // "und" is the tag for "nobody said", humanised once by
1179 // `subtitle_rows` and not again here.
1180 assert_eq!(name(3), "unknown language 2 — b");
1181 // A standalone `.srt` is its own file and its label already says so:
1182 // one track, so no number, and no stem after it saying it again.
1183 assert_eq!(name(4), "late.srt");
1184 // The silence a row left over from a timeline that is gone gets.
1185 assert_eq!(sub_pick_name(&tracks, 5), None);
1186 assert_eq!(sub_pick_name(&[], 0), None);
1187}
1188
1189/// What the toggle covers is what is *placed*, so what it says is a lane fact:
1190/// naming the palette row the list happens to mark named a track the stroke
1191/// never touched ("SUBTITLES OFF — one.srt is still on the timeline" for a
1192/// one.srt nobody dragged anywhere).
1193#[test]
1194fn the_subtitles_toggle_says_what_is_placed_and_never_the_picked_row() {
1195 for on in [true, false] {
1196 let text = subtitle_toggle_notice(on, 2);
1197 assert!(text.contains('2'), "{text} counts the captions placed");
1198 assert!(
1199 !text.contains("track(s)") && !text.contains(" — a"),
1200 "{text} names no palette row"
1201 );
1202 }
1203 // Off leaves them on the lanes; that is the half a person needs told.
1204 assert!(subtitle_toggle_notice(false, 2).contains("still placed"));
1205 // An empty timeline says the state, not a count that reads as broken --
1206 // and DESIGN §8 (2026-08-27) keeps this a state report, not a "drag it"
1207 // instruction.
1208 let none = subtitle_toggle_notice(true, 0);
1209 assert!(!none.contains('0'), "{none} counts nothing at nothing");
1210 assert!(
1211 none.contains("nothing placed"),
1212 "{none} says the state, not the move"
1213 );
1214}
1215
1216/// The door this editor answers "don't make me import the film again" with:
1217/// it reads a file's subtitle tracks onto the open timeline -- a release's
1218/// `.mkv`, an `.srt` beside it -- while the file itself joins nothing.
1219///
1220/// Cleanse round 2 (2026-09-10) took its ghost row out of the dock's footer
1221/// along with the `IMPORT` head: one `Add` row is the dock's one door, and
1222/// `Add` itself forks a subtitle file to the same place. The verb keeps its
1223/// stroke, its KEYS row, and a pointer door of its own -- the dock's
1224/// right-click menu ([`DOCK_ITEMS`]), which an *empty* library carries too.
1225/// It is the action and not a second implementation of it, so the row, the
1226/// stroke and the actions card cannot drift apart, and the menu row is
1227/// oracle-gated like every other, so with no timeline open it dims and says
1228/// why instead of opening a chooser for nothing.
1229#[test]
1230fn the_dock_menu_carries_the_add_subtitles_door() {
1231 use crate::{ActionId, DOCK_ITEMS};
1232 assert!(
1233 DOCK_ITEMS.contains(&ActionId::ImportSubtitles)
1234 && DOCK_ITEMS.contains(&ActionId::PasteFilePath)
1235 && DOCK_ITEMS.contains(&ActionId::AddFiles),
1236 "the dock's right-click menu lost one of the three ways in"
1237 );
1238 // ...and that menu is actually opened from the Sources body.
1239 let dock = src_text("ui/dock_stance.rs");
1240 assert!(
1241 dock.contains("on: MenuOn::Dock,"),
1242 "nothing in the dock opens the menu that now carries the two imports"
1243 );
1244 // The rows are drawn from `DOCK_ITEMS` by the one menu render.
1245 let overlays = src_text("ui/overlays.rs");
1246 assert!(
1247 overlays.contains("MenuOn::Dock => DOCK_ITEMS.to_vec(),"),
1248 "the dock menu draws something other than the three import actions"
1249 );
1250 // `act(ActionId::ImportSubtitles, ...)` routes to `pick_and_add_subtitles`
1251 // -- the row names the action, not a second implementation of it.
1252 let actions = src_text("player/actions.rs");
1253 assert!(
1254 actions.contains("ActionId::ImportSubtitles => self.pick_and_add_subtitles(cx)"),
1255 "ImportSubtitles no longer opens the subtitle chooser"
1256 );
1257 // A subtitle file taken through the plain `Add files` door lands as
1258 // subtitles rather than as a source that cannot be read.
1259 let library = src_text("player/library.rs");
1260 assert!(
1261 library.contains("if is_subtitle(path) {"),
1262 "Add files no longer forks a .srt/.vtt to the subtitle list"
1263 );
1264}
1265
1266/// The Darkroom keeps imported subtitle tracks in the Text tab itself (moved
1267/// off the unconditional spot under the Sources list, user 2026-08-27), where
1268/// a row can be selected, folded with its source, removed, and dragged to the
1269/// bench's existing subtitle-lane target.
1270#[test]
1271fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() {
1272 let dock = src_text("ui/dock_stance.rs");
1273 let palette = &dock[dock
1274 .find("fn subtitle_tab_rows")
1275 .expect("no Darkroom subtitle rows")..];
1276 for required in [
1277 "subtitle_rows",
1278 "dock-subtitle-group",
1279 "sub_folded.remove",
1280 "sub_folded.insert",
1281 "this.sub_track = track",
1282 ".on_drag(SubPick(track)",
1283 "remove_subtitle_track(track",
1284 ] {
1285 assert!(palette.contains(required), "palette lost {required}");
1286 }
1287 let bench = src_text("ui/bench_stance");
1288 let drop_at = bench
1289 .find(".drag_over::<SubPick>")
1290 .expect("no subtitle-track lane target");
1291 let drop = &bench[drop_at..(drop_at + 500).min(bench.len())];
1292 assert!(
1293 drop.contains("this.place_sub(drag.0, lane"),
1294 "a dock subtitle drag does not place on the lane: {drop}"
1295 );
1296}
1297
1298/// A file's subtitle tracks are that file's subset and are listed as one:
1299/// directly under the row that names it, never after every unrelated file
1300/// (user 2026-09-10, screenshot -- two screen recordings sat between a film
1301/// and its own subtitle group). A `.srt` nobody carries stays top-level, in
1302/// arrival order, at the end.
1303#[test]
1304fn a_file_subtitle_group_follows_its_own_row() {
1305 use crate::ui::dock_stance::{Slot, source_list_order};
1306 let film = PathBuf::from("/films/a.mkv");
1307 let other = PathBuf::from("/rec/b.mp4");
1308 let loose = PathBuf::from("/subs/late.srt");
1309 assert_eq!(
1310 source_list_order(
1311 &[film.clone(), other.clone()],
1312 &[film.clone(), loose.clone()]
1313 ),
1314 [Slot::Media(0), Slot::Subs(0), Slot::Media(1), Slot::Subs(1)],
1315 "the film's own tracks must sit between it and the next file"
1316 );
1317 // A file with several audio streams has several rows; the tracks follow
1318 // the last of them, so the file's own rows stay together.
1319 assert_eq!(
1320 source_list_order(
1321 &[film.clone(), other.clone(), film.clone()],
1322 std::slice::from_ref(&film)
1323 ),
1324 [
1325 Slot::Media(0),
1326 Slot::Media(1),
1327 Slot::Media(2),
1328 Slot::Subs(0)
1329 ],
1330 );
1331 // Nobody's `.srt`: still a top-level row, still last.
1332 assert_eq!(
1333 source_list_order(&[other], &[loose]),
1334 [Slot::Media(0), Slot::Subs(0)],
1335 );
1336}
1337
1338/// ...and the Sources list is *built* through that ordering rather than by
1339/// appending the subtitle groups after the media rows, which is what put a
1340/// film's own tracks at the end of the list.
1341#[test]
1342fn the_sources_list_is_built_through_the_ordering() {
1343 let dock = src_text("ui/dock_stance.rs");
1344 let tab = &dock[dock.find("fn sources_tab").expect("no sources tab")..];
1345 assert!(
1346 tab.contains("source_list_order(&media, &subs)"),
1347 "the Sources list no longer goes through source_list_order"
1348 );
1349 assert!(
1350 !tab.contains("row_elements.extend(subtitles)"),
1351 "the subtitle groups are appended after every source again"
1352 );
1353 // A parent already in the list gets the tracks bare, under it.
1354 let palette = &dock[dock.find("fn subtitle_tab_rows").expect("no subtitle rows")..];
1355 assert!(
1356 palette.contains("let nested = parents.contains(&group.path)")
1357 && palette.contains("let has_header = !nested || track_count > 3"),
1358 "a group under its own parent still draws a group row"
1359 );
1360}
1361
1362/// Two files whose rows read the same word are told apart on the metadata
1363/// line -- the folder, or `#n` when the folder is shared too.
1364#[test]
1365fn same_named_files_are_told_apart_on_the_metadata_line() {
1366 let three: Vec<Source> = ["/a/rec.mp4", "/b/rec.mp4", "/a/solo.mp4"]
1367 .into_iter()
1368 .map(|path| Source {
1369 path: PathBuf::from(path),
1370 audio_stream: 0, ..Default::default()
1371 })
1372 .collect();
1373 let rows = library_rows(&three, &HashMap::new(), &HashMap::new(), None, |_| 90);
1374 assert_eq!(
1375 rows.iter()
1376 .map(|row| row.detail.as_str())
1377 .collect::<Vec<_>>(),
1378 ["a", "b", ""],
1379 "twins say which folder they came out of"
1380 );
1381 let twins: Vec<Source> = ["/a/rec.mp4", "/a/rec.mkv"]
1382 .into_iter()
1383 .map(|path| Source {
1384 path: PathBuf::from(path),
1385 audio_stream: 0, ..Default::default()
1386 })
1387 .collect();
1388 let rows = library_rows(&twins, &HashMap::new(), &HashMap::new(), None, |_| 90);
1389 assert_eq!(
1390 rows.iter()
1391 .map(|row| row.detail.as_str())
1392 .collect::<Vec<_>>(),
1393 ["#1", "#2"],
1394 "one folder, one stem: arrival order tells them apart"
1395 );
1396}
1397
1398/// A subtitle group's header in the Text tab must not vanish on a short
1399/// window: `subtitle_tab_rows` draws one per group unconditionally -- there
1400/// is no viewport-height gate on it at all any more, so the list under it
1401/// is what would scroll instead, never the header itself. And it has to be
1402/// a real fold, not the click-cycling pattern this codebase has already
1403/// thrown out once: one click toggles `sub_folded` shut or open, it never
1404/// steps through more than those two states.
1405#[test]
1406fn a_subtitle_group_header_is_never_gated_on_window_height() {
1407 let dock = src_text("ui/dock_stance.rs");
1408 assert!(
1409 !dock.contains("sub_headers_fit"),
1410 "the header is still gated on the viewport's height"
1411 );
1412 // The header is a click target that flips membership in a set --
1413 // `remove` else `insert` -- not a value stepped through several states.
1414 let head_at = dock
1415 .find("\"dock-subtitle-group\"")
1416 .expect("no id on the group header");
1417 // Wide enough to reach the count line past the header's styling and its
1418 // commentary -- a window that stops short reads as the line deleted
1419 // (the same fixed-window misfire the modal-guard scan had, 2026-08-27).
1420 let block = &dock[head_at..(head_at + 3600).min(dock.len())];
1421 assert!(
1422 block.contains("sub_folded.remove"),
1423 "no fold-open path: {block}"
1424 );
1425 assert!(
1426 block.contains("sub_folded.insert"),
1427 "no fold-shut path: {block}"
1428 );
1429 assert!(
1430 block.contains("{track_count} track"),
1431 "the header does not say how many tracks it holds: {block}"
1432 );
1433}
1434
1435/// The one thing regrouping must not break: `sub_track` is a flat index
1436/// into the add-order list, a click sets it and a save writes it into the
1437/// `.edith`. Every row must still name the track it was made from -- rows
1438/// for refused tracks included, because they take a number in that list
1439/// whether or not anyone can pick them.
1440#[test]
1441fn a_subtitle_row_names_the_flat_track_it_was_made_from() {
1442 let mut tracks = vec![
1443 sub("/films/a.mkv", Some(1), "eng"),
1444 sub("/films/b.mkv", Some(1), "eng"),
1445 sub("/films/a.mkv", Some(2), "fre"),
1446 ];
1447 // Track 1 of b is pictures: still a row, still index 1 of the list.
1448 tracks[1].bitmap = true;
1449 tracks[1].refused = Some("PGS subtitles are pictures".to_string());
1450 let groups = subtitle_rows(&tracks);
1451 let flat: Vec<(usize, &str)> = groups
1452 .iter()
1453 .flat_map(|g| g.rows.iter().map(|r| (r.track, r.label.as_str())))
1454 .collect();
1455 assert_eq!(flat, [(0, "eng"), (2, "fre"), (1, "eng")]);
1456 for (track, label) in flat {
1457 assert_eq!(
1458 tracks[track].label, label,
1459 "row {track} picks the track it names"
1460 );
1461 }
1462 // (c) The refused one is here, saying why, and greyable by that alone.
1463 let refused = &groups[1].rows[0];
1464 assert_eq!(
1465 refused.refused.as_deref(),
1466 Some("PGS subtitles are pictures")
1467 );
1468 assert_eq!(refused.detail, "PGS subtitles are pictures");
1469 assert!(refused.bitmap);
1470 // ...and it was counted: the row after it in add order is still 2.
1471 assert_eq!(groups[0].rows[1].track, 2);
1472}
1473
1474/// The × on a row shifts every track after it down one, and the pick is
1475/// what an export writes into the file -- so a pick that stayed put would
1476/// silently change which track the next export carries. Every relation
1477/// between the pick and the row that went, on a list of three.
1478#[test]
1479fn removing_a_subtitle_row_carries_the_pick_with_it() {
1480 // A row *before* the pick: the same track stays picked, one index down.
1481 assert_eq!(sub_pick_after_removal(2, 0, 2), 1);
1482 assert_eq!(sub_pick_after_removal(2, 1, 2), 1);
1483 // A row *after* it: the pick has not moved and neither has its index.
1484 assert_eq!(sub_pick_after_removal(0, 2, 2), 0);
1485 assert_eq!(sub_pick_after_removal(1, 2, 2), 1);
1486 // The picked row itself: the one that slid into its place...
1487 assert_eq!(sub_pick_after_removal(1, 1, 2), 1);
1488 // ...and the last row when the picked one was the last, since there is
1489 // nothing after it to slide.
1490 assert_eq!(sub_pick_after_removal(2, 2, 2), 1);
1491 // The last row of all: an emptied list is legal for subtitles, and the
1492 // section is not drawn at all at that point.
1493 assert_eq!(sub_pick_after_removal(0, 0, 0), 0);
1494}
1495
1496/// A `^z` moves rows without saying which one moved, so the pick is followed by
1497/// what it *names* ([`sub_pick_after_restore`]) rather than by its index: the
1498/// same three rows as the removal test above, restored instead of taken away,
1499/// where the index is the wrong answer in the first case and the right one in
1500/// the second.
1501#[test]
1502fn a_restored_palette_carries_the_pick_by_what_it_names() {
1503 let palette = [
1504 sub("/films/a.mkv", Some(1), "eng"),
1505 sub("/films/a.mkv", Some(2), "fre"),
1506 sub("/films/a.mkv", Some(3), "ger"),
1507 ];
1508 // The pick on "ger" at index 1 of the two rows a removal of the first left.
1509 let short = [palette[1].clone(), palette[2].clone()];
1510 let picked = SubPickKey::of(&short, 1).expect("a row the pick names");
1511 assert_eq!(
1512 sub_pick_after_restore(1, Some(&picked), &palette),
1513 2,
1514 "the row above it came back"
1515 );
1516 // The row that came back *below* the pick leaves it where it was.
1517 let short = [palette[0].clone(), palette[1].clone()];
1518 let picked = SubPickKey::of(&short, 1).expect("a row the pick names");
1519 assert_eq!(
1520 sub_pick_after_restore(1, Some(&picked), &palette),
1521 1,
1522 "a row after it is not its business"
1523 );
1524 // The picked row itself gone from the restored palette: the old index
1525 // clamped into it, which is the removal door's own fallback.
1526 let picked = SubPickKey::of(&palette, 2).expect("a row the pick names");
1527 assert_eq!(sub_pick_after_restore(2, Some(&picked), &palette[..2]), 1);
1528 assert_eq!(
1529 sub_pick_after_restore(0, None, &[]),
1530 0,
1531 "an emptied palette is a state, not a panic"
1532 );
1533}
1534
1535/// The same claim from the click's end, on the order imports actually
1536/// arrive in: two films opened one after the other and an `.srt` dropped
1537/// last interleave in the flat list, and the display reorders them. What a
1538/// click sets is the row's own `track`, so the *n*th row on screen has to
1539/// pick the track it shows and the echoes have to name that same file.
1540#[test]
1541fn a_click_on_a_regrouped_row_picks_the_track_that_row_shows() {
1542 let tracks = [
1543 sub("/films/a.mkv", Some(1), "eng"),
1544 sub("/films/b.mkv", Some(1), "eng"),
1545 sub("/films/a.mkv", Some(2), "fre"),
1546 sub("/subs/late.srt", None, "late.srt"),
1547 sub("/films/b.mkv", Some(3), "ger"),
1548 ];
1549 let rows: Vec<_> = subtitle_rows(&tracks)
1550 .into_iter()
1551 .flat_map(|group| {
1552 group
1553 .rows
1554 .into_iter()
1555 .map(move |row| (group.path.clone(), row))
1556 })
1557 .collect();
1558 // Read top to bottom, the rows are no longer in add order...
1559 assert_eq!(
1560 rows.iter().map(|(_, row)| row.track).collect::<Vec<_>>(),
1561 [0, 2, 1, 4, 3]
1562 );
1563 for (path, row) in &rows {
1564 // ...and what the click writes into `sub_track` -- and a save into
1565 // the `.edith` -- still lands on the track the row is showing.
1566 let picked = &tracks[row.track];
1567 assert_eq!(&picked.path, path, "row {} picks another file", row.track);
1568 assert_eq!(lang_human(&picked.label), row.label);
1569 // And the heading, the strip and the notice name that same file
1570 // back, so a click cannot leave the echoes pointing elsewhere.
1571 let echo = sub_pick_name(&tracks, row.track).expect("the row's own track");
1572 let stem = path.file_stem().expect("a fixture path").to_string_lossy();
1573 assert!(
1574 echo.contains(&*stem),
1575 "picked {}, echoed {echo}",
1576 path.display()
1577 );
1578 }
1579}
1580
1581/// "und" is what a muxer writes when nobody said what the language is. A
1582/// row showing it verbatim names a language nobody speaks.
1583#[test]
1584fn an_untagged_language_says_it_is_unknown() {
1585 assert_eq!(lang_human("und"), "unknown language");
1586 assert_eq!(lang_human("eng"), "eng");
1587 assert_eq!(lang_human("fre — Commentary"), "fre — Commentary");
1588 // Reaching the subtitle rows too: a track whose only name was the tag.
1589 let groups = subtitle_rows(&[sub("/films/a.mkv", Some(1), "und")]);
1590 assert_eq!(groups[0].rows[0].label, "unknown language");
1591 // The pair, read as the pair: the row title comes off `language` and
1592 // `name` and never out of the flattened label, which is what let an
1593 // "und" beside a title through as a language nobody speaks. A refused
1594 // track states neither and keeps its label.
1595 let titled = |language: &str, name: &str, label: &str| engine::subtitle::SubtitleTrack {
1596 path: PathBuf::from("/films/a.mkv"),
1597 track: Some(1),
1598 language: language.into(),
1599 name: name.into(),
1600 label: label.into(),
1601 cues: Vec::new(),
1602 bitmap: false,
1603 refused: None,
1604 };
1605 for (language, name, label, title) in [
1606 ("fra", "Signs", "fra — Signs", "fra — Signs"),
1607 ("und", "Signs", "Signs", "Signs"),
1608 ("und", "", "und", "unknown language"),
1609 ("", "late.srt", "late.srt", "late.srt"),
1610 ("", "", "eng", "eng"),
1611 ] {
1612 let rows = subtitle_rows(&[titled(language, name, label)]);
1613 assert_eq!(rows[0].rows[0].label, title, "{language:?} {name:?}");
1614 }
1615}
1616
1617/// The bug: an empty timeline is end-of-stream from its one black frame
1618/// onward, so the pump had `done` set before anything was ever pressed --
1619/// and the transport's restart branch read that as "played out, start from
1620/// the top". It started a clock against a zero-length timeline, which was
1621/// `done` again by the next repaint, so every further press restarted it
1622/// too: the button read "Pause" and no press of it ever paused.
1623///
1624/// What holds it now is one predicate, checked here against real sessions
1625/// on both sides -- the emptied one refuses, a timeline with clips on it
1626/// does not.
1627#[test]
1628fn an_empty_timeline_has_nothing_to_play() {
1629 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
1630 // Silent like the engine suite: this opens the real device.
1631 session.set_gain(0.0);
1632 // A timeline with clips on it plays, and always did: the guard must not
1633 // touch that side.
1634 assert!(!session.is_empty());
1635 assert!(!nothing_to_play(Some(&session)));
1636
1637 // Every clip taken off, which is a state and not a failure.
1638 while session.delete_clip(Lane::V1, 0) {}
1639 while session.delete_clip(Lane::A1, 0) {}
1640 assert!(session.is_empty(), "the timeline is empty");
1641 assert_eq!(session.timeline_duration(), 0.0);
1642
1643 // What the pump does every render, and what set `done` before the fix:
1644 // the black frame goes by and the session is at its end at once.
1645 for _ in 0..40 {
1646 while session.try_frame().is_some() {}
1647 std::thread::sleep(Duration::from_millis(10));
1648 }
1649 assert!(
1650 session.is_eos(),
1651 "an empty timeline is done before it starts"
1652 );
1653
1654 // So the press is refused rather than sent down the restart branch --
1655 // and with no session at all it is the same refusal.
1656 assert!(nothing_to_play(Some(&session)));
1657 assert!(nothing_to_play(None));
1658 assert!(!session.is_playing(), "and nothing was started");
1659}
1660
1661/// The slider writes the same numbers the keys do, and mute is not one of
1662/// them: dragging while muted picks the level unmuting comes back to.
1663#[test]
1664fn the_slider_lands_on_the_grid_the_keys_move_on() {
1665 let mut volume = Volume::default();
1666 // Both ends exactly, and clamped past them.
1667 volume.set_along(0.);
1668 assert_eq!(volume.gain(), 0.0);
1669 assert_eq!(volume.label(), "Vol 0%");
1670 volume.set_along(1.5);
1671 assert_eq!(volume.gain(), 1.0);
1672 assert_eq!(volume.along(), 1.0);
1673
1674 // Halfway is 50%, and a key press from there is 5% -- the same step
1675 // count as before, on a finer grid.
1676 volume.set_along(0.5);
1677 assert_eq!(volume.label(), "Vol 50%");
1678 volume.step(true);
1679 assert_eq!(volume.label(), "Vol 55%");
1680 volume.step(false);
1681 assert_eq!(volume.gain(), 0.5);
1682
1683 // A number no step lands on comes back as the nearest one, so the label
1684 // and the fill are the same value the device was handed.
1685 volume.set_along(0.333);
1686 assert_eq!(volume.label(), "Vol 33%");
1687 assert_eq!(volume.along(), 0.33);
1688
1689 // Muted, the drag moves the level and nothing comes out.
1690 volume.muted = true;
1691 volume.set_along(0.8);
1692 assert_eq!(volume.gain(), 0.0);
1693 assert_eq!(volume.label(), "Muted 80%");
1694 volume.muted = false;
1695 assert_eq!(volume.gain(), 0.8);
1696}
1697
1698/// The slider lands where it paints: the arithmetic `Player::drag_volume`
1699/// runs over the bar's own painted width, which is the one thing a test of
1700/// it can share without re-deriving it.
1701#[test]
1702fn the_volume_slider_lands_where_it_paints() {
1703 let bar = Bounds {
1704 origin: point(px(420.), px(508.)),
1705 size: size(px(VOLUME_W), px(CONTROL_H)),
1706 };
1707 let at = |x: f32| {
1708 let mut volume = Volume::default();
1709 volume.set_along(frac_along(px(x), bar));
1710 volume
1711 };
1712 assert_eq!(at(420.).gain(), 0.0, "the left end is silence");
1713 assert_eq!(at(420. + VOLUME_W).gain(), 1.0, "the right end is full");
1714 assert_eq!(at(-4000.).gain(), 0.0, "off the left clamps");
1715 assert_eq!(at(9999.).gain(), 1.0, "off the right clamps");
1716 // Every pixel along it: a level the keys could also reach, painted back
1717 // where the hand pressed to within the half step the rounding costs.
1718 for step in 0..=(VOLUME_W as u32) {
1719 let along = step as f32 / VOLUME_W;
1720 let volume = at(420. + along * VOLUME_W);
1721 let painted = volume.along();
1722 let slack = 0.5 / f32::from(Volume::MAX_STEPS) + 1e-4;
1723 assert!(
1724 (painted - along).abs() <= slack,
1725 "pressed at {along}, paints at {painted}"
1726 );
1727 }
1728}
1729
1730/// Darkroom lane heads dispatch only verbs that apply to the lane under the
1731/// pointer; source checks pin the visible pointer doors to that guarded path.
1732#[test]
1733fn darkroom_lane_header_verbs_are_targeted_and_visible() {
1734 let live = Ctx {
1735 timeline: true,
1736 ..Ctx::default()
1737 };
1738 assert_eq!(enable_lane(ActionId::Mix, Lane::A1, live.clone()), Enable::Yes);
1739 assert_eq!(
1740 enable_lane(ActionId::RemoveVideoLane, Lane::V1, live.clone()),
1741 Enable::Yes
1742 );
1743 assert_eq!(
1744 enable_lane(ActionId::RemoveAudioLane, Lane::A1, live.clone()),
1745 Enable::Yes
1746 );
1747 assert!(matches!(
1748 enable_lane(ActionId::Mix, Lane::V1, live),
1749 Enable::Hidden(_)
1750 ));
1751
1752 // The head itself carries a dot, a name and its switches, and nothing else
1753 // (cleanse round 2, DESIGN §7). Its mix and its remove are rows
1754 // in its own right-click menu instead, and they still reach the lane the
1755 // hand named rather than the last of the kind a bare stroke walks to:
1756 // `overlays.rs` routes those rows through the same `act_lane` door the
1757 // head's buttons used.
1758 let bench = src_text("ui/bench_stance");
1759 for gone in [
1760 "\"bench-mix-lane\"",
1761 "\"bench-remove-lane\"",
1762 "lane.{}.remove",
1763 ] {
1764 assert!(!bench.contains(gone), "the lane head still wears {gone}");
1765 }
1766 for door in ["\"bench-show-sub-lane\"", "this.show_sub_lane(lane, cx)"] {
1767 assert!(bench.contains(door), "lane header lost {door}");
1768 }
1769 assert!(
1770 lane_items(Lane::A1).contains(&ActionId::Mix)
1771 && lane_items(Lane::A1).contains(&ActionId::RemoveAudioLane)
1772 && lane_items(Lane::V1).contains(&ActionId::RemoveVideoLane)
1773 && !lane_items(Lane::V1).contains(&ActionId::Mix),
1774 "a head verb left the head with no row in the head's own menu"
1775 );
1776 assert!(
1777 src_text("ui/overlays.rs").contains("this.act_lane(action, menu.lane, cx)"),
1778 "the head menu lane verbs no longer act on the lane that was clicked"
1779 );
1780 // Cleanse round 2 (2026-09-10): the monitoring cluster left the band
1781 // (chord + KEYS row only). The export range's two grips moved from the
1782 // contact strip onto the overview above the ruler with the strip itself.
1783 let overview = src_text("ui/bench_stance/overview.rs");
1784 for door in [
1785 "fn mark_grip(",
1786 "\"stance-strip-mark-in\"",
1787 "\"stance-strip-mark-out\"",
1788 "MARK_DRAG.with(|m| m.set(Some(action)))",
1789 ] {
1790 assert!(overview.contains(door), "overview lost {door}");
1791 }
1792}
1793
1794/// The three seams a hand may move, and the two ends neither of them may be
1795/// dragged past: a panel dragged to nothing is a panel nobody can get back, and
1796/// a picture squeezed out by its two neighbours is that same loss from the
1797/// other side of the window.
1798#[test]
1799fn a_dragged_divider_stops_before_either_panel_disappears() {
1800 use crate::ui::theme::INSPECTOR_MIN_W;
1801 use crate::{
1802 SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w,
1803 split_drag_size, split_size, timeline_fixed_h, timeline_h,
1804 };
1805 use gpui::{point, px, size};
1806
1807 let window = size(px(1280.), px(720.));
1808 // Untouched, every region is still the share the window gives it. The
1809 // timeline's answer is stated for both of its faces: the timeline fits
1810 // the bed with nothing to scroll to, and zoomed in past that line the
1811 // strip's row joins the furniture.
1812 assert_eq!(
1813 split_size(Split::Library, None, 2, window, false),
1814 library_w(1280.)
1815 );
1816 assert_eq!(
1817 split_size(Split::Inspector, None, 2, window, false),
1818 inspector_w(1280.)
1819 );
1820 assert_eq!(
1821 split_size(Split::Timeline, None, 2, window, false),
1822 timeline_h(2, false).min(720. * TIMELINE_SHARE)
1823 );
1824 assert_eq!(
1825 split_size(Split::Timeline, None, 2, window, true),
1826 timeline_h(2, true).min(720. * TIMELINE_SHARE)
1827 );
1828 // Dragged, it is what the hand asked for...
1829 assert_eq!(
1830 split_size(Split::Library, Some(300.), 2, window, false),
1831 300.
1832 );
1833 assert_eq!(
1834 split_size(Split::Timeline, Some(300.), 2, window, false),
1835 300.
1836 );
1837 // ...and never past either end of it.
1838 assert_eq!(
1839 split_size(Split::Library, Some(0.), 2, window, false),
1840 LIBRARY_MIN_W
1841 );
1842 assert_eq!(
1843 split_size(Split::Library, Some(9000.), 2, window, false),
1844 1280. * SIDE_MAX_FRAC
1845 );
1846 assert_eq!(
1847 split_size(Split::Inspector, Some(-40.), 2, window, false),
1848 INSPECTOR_MIN_W
1849 );
1850 // The timeline's own floor is a floor with a whole lane *drawn* in it. At
1851 // that height the column shows one row of a two-track project, so the line
1852 // saying the rest are below is drawn too -- out of the region's pixels,
1853 // not out of the lane's. Left unbudgeted the header came out 27 px of its
1854 // 48 and the track's name, its subtitle dot and its × were cut in half.
1855 // Stated for the strip-bearing face, the taller of the two -- that is the
1856 // one the clamp has to hold at the 640x360 floor.
1857 let floor = split_size(Split::Timeline, Some(0.), 2, window, true);
1858 assert_eq!(floor, timeline_fixed_h(true) + LANE_H + LABEL_H + 8.);
1859 // The same arithmetic the timeline lays the column out with
1860 // ([`Player::timeline`]): what the affordance costs comes off the box, and
1861 // a whole lane is still standing under it.
1862 let lanes_box = floor - timeline_fixed_h(true);
1863 assert!(lanes_box < lanes_h(2), "no line to pay for at the floor");
1864 assert!(
1865 lanes_box - LABEL_H - 8. >= LANE_H,
1866 "the floor leaves {} px for a {LANE_H} px lane",
1867 lanes_box - LABEL_H - 8.
1868 );
1869 // A lone track has nothing below it and pays nothing for the line -- the
1870 // floor is a floor, not a reserved corridor.
1871 assert_eq!(
1872 split_size(Split::Timeline, Some(0.), 1, window, true),
1873 timeline_fixed_h(true) + LANE_H
1874 );
1875 // A size dragged with one track and kept while a second arrives is raised
1876 // to the new floor as it is read, not silently drawn under it.
1877 assert_eq!(
1878 split_size(Split::Timeline, Some(126.), 2, window, true),
1879 floor
1880 );
1881 // And the floor still fits the share the shortest window gives the region.
1882 assert!(floor <= 360. * TIMELINE_SHARE, "{floor} px will not fit");
1883 assert_eq!(
1884 split_size(Split::Timeline, Some(9000.), 2, window, true),
1885 720. * TIMELINE_MAX_SHARE
1886 );
1887 // A window too narrow to honour both ends keeps the floor rather than
1888 // panicking inside `clamp`, which is what a ceiling under its own floor
1889 // does.
1890 let narrow = size(px(600.), px(360.));
1891 assert_eq!(
1892 split_size(Split::Inspector, Some(9000.), 2, narrow, false),
1893 INSPECTOR_MIN_W
1894 );
1895
1896 // The pointer turned into a size: the panel follows the hand, and the two
1897 // that do not start at the window's own edge are measured from the far one.
1898 // Half a strip off each, because the strip is grabbed by its middle.
1899 assert_eq!(
1900 split_drag_size(Split::Library, point(px(300.), px(400.)), window),
1901 300. - SPLIT_W / 2.
1902 );
1903 assert_eq!(
1904 split_drag_size(Split::Inspector, point(px(1000.), px(400.)), window),
1905 280. - SPLIT_W / 2.
1906 );
1907 // The seam sits above the fixed toolbar, so what the pointer leaves under
1908 // it is that strip and the timeline together.
1909 assert_eq!(
1910 split_drag_size(Split::Timeline, point(px(300.), px(500.)), window),
1911 220. - TOOLBAR_H - SPLIT_W / 2.
1912 );
1913}
1914
1915/// The darkroom's own two seams (`Split::Dock`, `Split::Bench`): a hand may
1916/// not drag either past its floor or its ceiling, the same promise
1917/// [`a_dragged_divider_stops_before_either_panel_disappears`] makes for the
1918/// legacy three.
1919#[test]
1920fn the_darkroom_seams_stop_before_either_side_disappears() {
1921 use crate::{
1922 BENCH_MIN_H, BENCH_SHARE, DOCK_MIN_W, SIDE_MAX_FRAC, SPLIT_W, Split, split_bounds,
1923 split_drag_size, split_size,
1924 };
1925 use gpui::{point, px, size};
1926
1927 let window = size(px(1280.), px(720.));
1928 // Untouched, each answers its own default: the dock its stance width, the
1929 // bench a share of the window's height (DESIGN §5, about 42%).
1930 assert_eq!(
1931 split_size(Split::Dock, None, 2, window, false),
1932 crate::ui::stance::DOCK_W
1933 );
1934 assert_eq!(
1935 split_size(Split::Bench, None, 2, window, false),
1936 720. * crate::layout::bench_share(720.)
1937 );
1938 // The DESIGN §5 numbers themselves: a 320px dock, a 280px dock floor, a
1939 // 30px ledger and a timeline block at about 42% of the window.
1940 assert_eq!(crate::ui::stance::DOCK_W, 320.);
1941 assert_eq!(DOCK_MIN_W, 280.);
1942 assert_eq!(crate::ui::stance::LEDGER_H, 24.);
1943 assert!((BENCH_SHARE - 0.46).abs() < 1e-6);
1944 // Dragged, it is what the hand asked for...
1945 assert_eq!(split_size(Split::Dock, Some(400.), 2, window, false), 400.);
1946 assert_eq!(split_size(Split::Bench, Some(300.), 2, window, false), 300.);
1947 // ...and never past the floor...
1948 assert_eq!(
1949 split_size(Split::Dock, Some(0.), 2, window, false),
1950 DOCK_MIN_W
1951 );
1952 assert_eq!(
1953 split_size(Split::Bench, Some(0.), 2, window, false),
1954 BENCH_MIN_H
1955 );
1956 // ...nor the ceiling. The bench's is not a window-share one -- it leaves
1957 // the screen and time band a fixed 160px, [`split_bounds`]'s own reason.
1958 assert_eq!(
1959 split_size(Split::Dock, Some(9000.), 2, window, false),
1960 1280. * SIDE_MAX_FRAC
1961 );
1962 let (_, bench_max) = split_bounds(Split::Bench, 2, window, false);
1963 assert_eq!(
1964 split_size(Split::Bench, Some(9000.), 2, window, false),
1965 bench_max
1966 );
1967 assert!(bench_max < 720.);
1968 // The pointer turned into a size, half a strip off for the same reason
1969 // the legacy seams read it that way.
1970 assert_eq!(
1971 split_drag_size(Split::Dock, point(px(1000.), px(400.)), window),
1972 280. - SPLIT_W / 2.
1973 );
1974 assert_eq!(
1975 split_drag_size(Split::Bench, point(px(300.), px(500.)), window),
1976 220. - crate::ui::stance::LEDGER_H - SPLIT_W / 2.
1977 );
1978}
1979
1980/// At the bench's floor, both default lanes' rows actually fit inside the
1981/// `bench-lanes` column `bench_stance::render` gives them -- not just each
1982/// row's own clamped height, but their *sum plus the gap between them*,
1983/// since `bench-lanes` scrolls rather than clipping visibly and a sum that
1984/// overruns the column loses its bottom row's pixels off-screen, unscrolled
1985/// (this session's F1: the A1 lane's clip-bar border and status dot, cut by
1986/// ~2px at the old `BENCH_MIN_H = 80.`).
1987#[test]
1988fn both_default_lanes_fit_the_bench_at_its_floor() {
1989 use crate::BENCH_MIN_H;
1990 use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H};
1991 use crate::ui::stance::BENCH_CHROME_H;
1992
1993 let box_h = BENCH_MIN_H - BENCH_CHROME_H;
1994 let avail = box_h - RULER_H - ROW_GAP;
1995 // Lanes are no longer split evenly out of the box: each is drawn at its
1996 // own height, never below `LANE_MIN_H`, so the floor is the two default
1997 // lanes at that minimum plus their gap. `BENCH_MIN_H` carries one spare row
1998 // (`layout::LEDGER_SEAM_CLEARANCE`) so the last lane's own last pixel never
1999 // shares a row with the ledger's border.
2000 let content = 2. * LANE_MIN_H + ROW_GAP;
2001 assert!(
2002 content <= avail + 1e-4,
2003 "the two lane rows ({content}px) overrun the column ({avail}px) -- \
2004 the bottom lane's pixels get cut, unscrolled"
2005 );
2006}
2007
2008/// `BENCH_CHROME_H` on its own: the previous test's `box_h = BENCH_MIN_H -
2009/// BENCH_CHROME_H` line trusts `BENCH_CHROME_H` to already be correct, so it
2010/// cannot catch `BENCH_CHROME_H` itself drifting -- which is exactly how the
2011/// third clip (this session's) survived it: the constant undercounted the
2012/// section head's real line box by 1px and this test's predecessor never
2013/// looked. Recomputes what `ui::stance::bench` actually draws above
2014/// `bench_stance::render`'s content -- the div's own `.border_t_1()` (1px) plus
2015/// its `py(4.)` top padding + the section head's real line box at gpui's
2016/// golden-ratio line-height, not the label's bare font size (the same trap
2017/// `a_lane_row_fits_what_its_own_head_draws` already checks for the lane
2018/// heads) -- and then checks the *whole* stack -- chrome, ruler, both gaps,
2019/// both lanes, and the clear row the ledger's own fixed-position border
2020/// needs (`LEDGER_SEAM_CLEARANCE`, not exported, so this recomputes it as
2021/// `BENCH_MIN_H` minus every other named term) -- fits inside `BENCH_MIN_H`
2022/// with nothing left over uncounted. This binary carries no `TestAppContext`
2023/// to mount `ui::stance::bench` and `ui::stance::ledger` for real and read
2024/// painted bounds back, so it stays geometry-only, same as its neighbours.
2025#[test]
2026fn the_whole_bench_stack_fits_its_own_floor_with_the_ledger_seam_clear() {
2027 use crate::BENCH_MIN_H;
2028 use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H};
2029 use crate::ui::stance::BENCH_CHROME_H;
2030
2031 const BENCH_BORDER_T: f32 = 1.;
2032 const BENCH_PY_TOP: f32 = 4.;
2033 // No section head any more (cleanse round 2): the border and the padding
2034 // are the whole of what `stance::bench` draws above the ruler.
2035 let real_chrome = BENCH_BORDER_T + BENCH_PY_TOP;
2036 assert_eq!(
2037 BENCH_CHROME_H, real_chrome,
2038 "BENCH_CHROME_H ({BENCH_CHROME_H}) does not match what `stance::bench` \
2039 actually draws above the content ({real_chrome}px: {BENCH_BORDER_T}px \
2040 border + {BENCH_PY_TOP}px padding) -- bench_stance::render gets handed the wrong box_h and lays its \
2041 rows out past its own real space"
2042 );
2043
2044 // The ledger's own fixed-position border needs one more clear row below
2045 // the last lane, on top of chrome + ruler + both gaps + both lanes --
2046 // recomputed here rather than importing the private
2047 // `layout::LEDGER_SEAM_CLEARANCE`, so this test fails if that term is
2048 // ever silently dropped from `BENCH_MIN_H`'s own sum.
2049 let content_need = real_chrome + RULER_H + ROW_GAP + 2. * LANE_MIN_H + ROW_GAP;
2050 let ledger_seam_clearance = BENCH_MIN_H - content_need;
2051 assert!(
2052 ledger_seam_clearance >= 1. - 1e-4,
2053 "BENCH_MIN_H ({BENCH_MIN_H}) leaves only {ledger_seam_clearance}px \
2054 between the last lane row and the ledger's own top border -- driven \
2055 at exactly the content's need (0px clearance) the border still won \
2056 the shared pixel and clipped the last lane's status dot"
2057 );
2058}
2059
2060/// The previous test asserted lane ROWS fit the bench column -- not that a
2061/// lane's own CONTENT fits its row, which is how the defect it fixed
2062/// survived it: at the old `LANE_MIN_H` of `18.` both lanes fit the bench
2063/// exactly while V1's status dot silently overflowed into A1's row (masked)
2064/// and A1's overflowed into the ledger (visible, since A1 has no next row).
2065/// This binary carries no `TestAppContext` to mount a real `lane_row` and
2066/// read its painted bounds back, so this recomputes the label's own line
2067/// box from the constants `lane_row` actually draws with (gpui's default
2068/// `TextStyle::line_height` is the golden ratio, not 1x the font size --
2069/// see `LANE_MIN_H`'s own doc comment) rather than a literal, so a future
2070/// shrink of `LANE_MIN_H` or growth of the label size fails this instead of
2071/// silently clipping the last lane again.
2072#[test]
2073fn a_lane_row_fits_what_its_own_head_draws() {
2074 use crate::ui::bench_stance::{LANE_DOT_D, LANE_MIN_H};
2075 use crate::ui::type_scale::CHORD_METADATA_MIN_PX;
2076
2077 // gpui's line-height ratio, which happens to sit near the golden ratio; it
2078 // is not that constant, so the lint's suggestion would be wrong here.
2079 #[allow(
2080 clippy::approx_constant,
2081 reason = "gpui's default line-height ratio, not the golden ratio constant"
2082 )]
2083 let label_line_h = (CHORD_METADATA_MIN_PX * 1.618_034).round();
2084 // The head is one row -- dot, name, switches -- centred in the lane, so
2085 // what it needs is its tallest child: the 24px switch hit area (and the
2086 // subtitle name's own hit area), not a stack of label, gap and dot.
2087 let content = label_line_h.max(LANE_DOT_D).max(HIT_MIN);
2088 assert!(
2089 LANE_MIN_H >= content,
2090 "LANE_MIN_H ({LANE_MIN_H}) is shorter than what a lane head actually \
2091 draws ({content}px: the tallest of the {label_line_h}px label line \
2092 box, the {LANE_DOT_D}px dot and the {HIT_MIN}px switch hit areas) -- \
2093 the head would spill past its row"
2094 );
2095}
2096
2097/// A round trip through the file: what is saved is what the next load reads
2098/// back, all five seams touched -- a scratch path, not the real config, the
2099/// same isolation `keymap::tests`' own `load_from`/`save_to` already takes.
2100/// One of the five is written past its own ceiling (the library, past
2101/// `SIDE_MAX_FRAC` of the window it is loaded back into): a file written at
2102/// a wider window must not hand a narrower one an illegal layout, so the
2103/// load clamps it back down rather than reading it verbatim.
2104#[test]
2105fn a_saved_seam_survives_a_reload() {
2106 use crate::{
2107 BENCH_MIN_H, SIDE_MAX_FRAC, Split, Splits, load_stance_splits_from, save_stance_splits_to,
2108 };
2109 use gpui::{Pixels, Size, px, size};
2110
2111 let dir = engine::scratch::Scratch::dir("edith-stance-splits");
2112 let path = dir.join("stance-splits");
2113 let window: Size<Pixels> = size(px(1280.), px(720.));
2114
2115 let mut splits = Splits::default();
2116 splits.set(Split::Library, 9000.);
2117 splits.set(Split::Inspector, 200.);
2118 splits.set(Split::Timeline, 250.);
2119 splits.set(Split::Dock, 333.);
2120 splits.set(Split::Bench, 200.);
2121 save_stance_splits_to(&splits, &path);
2122 let loaded = load_stance_splits_from(&path, window);
2123 assert_eq!(
2124 loaded.get(Split::Library),
2125 Some(1280. * SIDE_MAX_FRAC),
2126 "a library past its own ceiling should clamp to it on load"
2127 );
2128 assert_eq!(loaded.get(Split::Inspector), Some(200.));
2129 assert_eq!(loaded.get(Split::Timeline), Some(250.));
2130 assert_eq!(loaded.get(Split::Dock), Some(333.));
2131 assert_eq!(loaded.get(Split::Bench), Some(200.));
2132
2133 // A bench saved below its own floor clamps up to it, the same ceiling
2134 // logic mirrored on the one seam whose bound is a minimum.
2135 let mut low_bench = Splits::default();
2136 low_bench.set(Split::Bench, 1.);
2137 save_stance_splits_to(&low_bench, &path);
2138 let loaded = load_stance_splits_from(&path, window);
2139 assert_eq!(loaded.get(Split::Bench), Some(BENCH_MIN_H));
2140}
2141
2142/// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends
2143/// with no further pointer event ever coming (`Player::drag_left_window`,
2144/// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary
2145/// cannot raise -- see `tests/media.rs`'s own note on the same limit, and
2146/// the harness drive `D2` in this session's report for the wiring itself).
2147/// What *is* checkable here without a window: exactly the persisted
2148/// seams owe that save, the same set `Split::PERSISTED` already names, and a
2149/// drag that never started (`None`) owes nothing.
2150#[test]
2151fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {
2152 use crate::{Split, player::timeline_edit::split_drag_owes_save};
2153
2154 assert!(split_drag_owes_save(Some(Split::Dock)));
2155 assert!(split_drag_owes_save(Some(Split::Bench)));
2156 assert!(split_drag_owes_save(Some(Split::Library)));
2157 assert!(split_drag_owes_save(Some(Split::Inspector)));
2158 assert!(split_drag_owes_save(Some(Split::Timeline)));
2159 assert!(!split_drag_owes_save(None));
2160}
2161
2162/// A missing file leaves every region at its default -- the silent fallback
2163/// `load_stance_splits`'s doc comment promises.
2164#[test]
2165fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {
2166 use crate::{Split, load_stance_splits_from};
2167 use gpui::{Pixels, Size, px, size};
2168
2169 let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing");
2170 let window: Size<Pixels> = size(px(1280.), px(720.));
2171 let splits = load_stance_splits_from(&dir.join("nothing-here"), window);
2172 assert_eq!(splits.get(Split::Library), None);
2173 assert_eq!(splits.get(Split::Inspector), None);
2174 assert_eq!(splits.get(Split::Timeline), None);
2175 assert_eq!(splits.get(Split::Dock), None);
2176 assert_eq!(splits.get(Split::Bench), None);
2177}
2178
2179/// Every seam in the main layout has a handle on it, and every region draws
2180/// itself at the size that handle sets: a region still measuring itself off the
2181/// window's own share is a panel whose divider moves nothing.
2182#[test]
2183fn every_seam_in_the_layout_has_a_divider_on_it() {
2184 // The darkroom collapsed Library/Inspector/Timeline into rooms with no
2185 // seam of their own; render.rs no longer draws any divider at all --
2186 // ui::stance::render is the whole root now -- so the only two seams a
2187 // hand can still drag are the ones the stance itself owns.
2188 // Whitespace-collapsed, so the call still matches however rustfmt wraps it.
2189 let stance = src_text("ui/stance.rs")
2190 .split_whitespace()
2191 .collect::<Vec<_>>()
2192 .join(" ");
2193 for split in ["Split::Dock", "Split::Bench"] {
2194 assert!(
2195 stance.contains(&format!("divider( {split},")),
2196 "{split} has no divider to drag"
2197 );
2198 }
2199 // The strip is drawn wide enough to hit and says which way it moves --
2200 // an invisible hairline is a feature nobody finds.
2201 let interact = src_text("interact.rs");
2202 assert!(
2203 interact.contains("cursor_col_resize") && interact.contains("cursor_row_resize"),
2204 "a divider with no resize cursor on it"
2205 );
2206 // ...and nothing lays a region out off the untouched share any more:
2207 // the legacy panels that read `library_w`/`inspector_w` (`ui/library.rs`,
2208 // `ui/inspector.rs`, `ui/toolbar.rs`) are gone or gone from the render
2209 // path, so what remains is layout.rs's own Split::Library/Inspector
2210 // arms -- kept for save-file compat, never drawn.
2211 assert!(
2212 !src_text("render.rs").contains("library_w("),
2213 "render.rs still measures a panel with library_w("
2214 );
2215}
2216
2217/// DESIGN.md §12 step 2 as amended 2026-09-09 (user decision "option C"):
2218/// the stance skeleton draws its five regions -- screen, time band, bench,
2219/// ledger, dock -- in the order §5's diagram lays them out, and
2220/// `Player::render` actually reaches it when the flag is on. The sixth, the
2221/// 56px rail, is deleted -- the room root is centre | dock.
2222#[test]
2223fn the_stance_renders_its_five_regions_in_the_documented_order() {
2224 let stance = src_text("ui/stance.rs");
2225 let order = [
2226 "stance-screen",
2227 "stance-time-band",
2228 "stance-bench",
2229 "stance-ledger",
2230 "stance-dock",
2231 ];
2232 let defined: Vec<usize> = order
2233 .iter()
2234 .map(|id| {
2235 stance
2236 .find(&format!("\"{id}\""))
2237 .unwrap_or_else(|| panic!("no {id} region in the stance"))
2238 })
2239 .collect();
2240 assert!(
2241 defined.windows(2).all(|w| w[0] < w[1]),
2242 "the five regions are not defined in DESIGN §5's order: {defined:?}"
2243 );
2244
2245 // Defined in order is not composed in order -- `render()` has to call
2246 // them in it too, or the geometry above is dead prose.
2247 let render_body = &stance[stance
2248 .find("pub(crate) fn render(")
2249 .expect("the stance's entry point")..];
2250 // Open paren only, no close: DESIGN §12 steps 3 and 4 hand most of the
2251 // regions player/window state to read, so their call sites carry
2252 // arguments now. Order is what this asserts, not arity.
2253 let calls = ["screen(", "time_band(", "bench(", "ledger(", "dock("];
2254 let composed: Vec<usize> = calls
2255 .iter()
2256 .map(|c| {
2257 render_body
2258 .find(c)
2259 .unwrap_or_else(|| panic!("render() never calls {c}"))
2260 })
2261 .collect();
2262 assert!(
2263 composed.windows(2).all(|w| w[0] < w[1]),
2264 "render() does not compose the six regions in DESIGN §5's order: {composed:?}"
2265 );
2266
2267 // The skeleton is reached unconditionally now -- the darkroom is the
2268 // only room, and `self.darkroom`'s branch is gone with the legacy tree
2269 // it used to choose between.
2270 let render_rs = src_text("render.rs");
2271 assert!(
2272 render_rs.contains("ui::stance::render("),
2273 "render.rs no longer reaches ui::stance::render"
2274 );
2275 assert!(
2276 !render_rs.contains("self.darkroom"),
2277 "render.rs still branches on self.darkroom after the legacy tree was removed"
2278 );
2279}
2280
2281/// The picture is letterboxed, never stretched: both the picture region and
2282/// the subtitle picture overlay paint through [`letterboxed_image`] (the
2283/// `canvas()` element that hands `ObjectFit::Contain::get_bounds` a real
2284/// resolved size) rather than a plain `img().object_fit(...)`, which reads
2285/// right by hand but never gets a fitted box from taffy in this pin -- see
2286/// `render.rs`'s own doc comment on the function for the measured dead end.
2287/// A regression back to `img(...).object_fit(` in either caller is the
2288/// stretch-to-fill bug returning silently.
2289#[test]
2290fn the_picture_letterboxes_through_a_canvas_never_a_plain_img_object_fit() {
2291 let render_rs = src_text("render.rs");
2292 assert!(
2293 render_rs.contains("pub(crate) fn letterboxed_image"),
2294 "the letterbox helper moved or was renamed"
2295 );
2296 assert!(
2297 render_rs.contains("ObjectFit::Contain.get_bounds(bounds, image.size(0))"),
2298 "letterboxed_image no longer computes the Contain rect by hand"
2299 );
2300 for (file, needle) in [
2301 ("render.rs", "viewer_picture("),
2302 ("ui/preview.rs", "letterboxed_image(image)"),
2303 ] {
2304 let text = src_text(file);
2305 assert!(
2306 text.contains(needle),
2307 "{file} no longer paints through letterboxed_image"
2308 );
2309 assert!(
2310 !text.contains(".object_fit(gpui::ObjectFit::Contain)"),
2311 "{file} reintroduced the stretched img().object_fit(Contain) dead end"
2312 );
2313 }
2314}
2315
2316/// DESIGN §6.2: the picture sits 12px in from the viewer's edges, the corner
2317/// plate is the only thing drawn over it, and the OUT|IN strip floats over the
2318/// bottom edge only while it is shown. Its layout box must never reach the
2319/// picture, or the picture's box moves on every cut walk again.
2320#[test]
2321fn the_viewer_pads_the_picture_and_floats_its_overlays() {
2322 let stance = src_text("ui/stance.rs");
2323 assert!(
2324 stance.contains("const VIEWER_PAD: f32 = 12.;"),
2325 "the viewer padding is no longer the DESIGN §6.2 12px"
2326 );
2327 let screen = &stance[stance.find("fn screen(").expect("the Darkroom screen")..];
2328 assert!(
2329 screen.contains(".p(px(VIEWER_PAD))") && !screen.contains("corner_plate"),
2330 "the screen no longer pads the picture, or a boxed chip is back over it"
2331 );
2332 assert!(
2333 screen.contains("player.trim_two_up()") && !screen.contains("player.two_up()"),
2334 "the OUT|IN split is mounted only through trim_two_up, never as a flow sibling"
2335 );
2336
2337 let preview = src_text("ui/preview.rs");
2338 let two = &preview[preview.find("fn trim_two_up(").expect("the trim two-up")..];
2339 assert!(
2340 two.contains(".absolute()") && preview.contains("fn editing_cut("),
2341 "the trim two-up must be absolute (no layout box) and only while an edit point is worked"
2342 );
2343 assert!(
2344 !preview.contains("viewer-plate") && !preview.contains("fn corner_plate") && !preview.contains("fn two_up("),
2345 "nothing boxed is drawn over the picture: the timecode is the transport's, the name the status bar's"
2346 );
2347}
2348
2349/// DESIGN §8: "No full-width bars, no covering the picture, ever." The
2350/// darkroom stance (`ui::stance::screen`) draws
2351/// [`Player::picture_area`](crate::Player::picture_area) directly, so a
2352/// notice surface that reaches into that method unconditionally reaches the
2353/// picture on the darkroom path too -- measured live covering the bottom 10%
2354/// of the frame (rows 300-333 of 335). The legacy full-width `notice_bar`
2355/// and its non-darkroom caller are gone with the rest of the old tree, and
2356/// the floating notice plate went after them (user 2026-08-27: the ledger's
2357/// own "last action" strip is the one notice channel now), so this pins
2358/// `picture_area` itself never growing a notice surface back.
2359#[test]
2360fn the_darkroom_path_never_lets_a_notice_surface_reach_the_picture() {
2361 // The ledger strip (`ui::stance::ledger` reading `notices.back()`) is
2362 // the only notice channel left, and the invariant is that
2363 // picture_area's body never draws one over the picture.
2364 let body = fn_body("picture_area");
2365 assert!(
2366 !body.contains("notice_bar"),
2367 "picture_area draws a notice surface over the picture again (the old occlusion defect)"
2368 );
2369}
2370
2371/// DESIGN §5/§11 check 6, the fourth occlusion defect (notice bar, export
2372/// card, preview badge, now menus): every floating menu that can open above
2373/// the picture -- the clip context menu, the picker -- must size its
2374/// scrolling list against `stance::menu_floor`'s room, not the raw window.
2375/// Sizing against the whole viewport is exactly the bug that shipped: a menu
2376/// taller than the bench/ledger/dock footprint got clamped by `menu_at`'s
2377/// own bottom-edge fit back up over the picture, because nothing had told
2378/// the list it only had the footprint to grow into. This pins the general
2379/// rule so the next surface someone floats -- a fourth menu, a fifth
2380/// occlusion -- cannot silently reintroduce `menu_rows_h(rows.len(),
2381/// viewport)` in its place.
2382///
2383/// The library menu is the deliberate exception (user 2026-08-27, "right
2384/// clicking a library media opens a menu in somewhere nonsense"): it anchors
2385/// to a pointer that is always inside the dock, where no picture exists to
2386/// protect, and `menu_floor`'s clamp teleported it down to the picture floor
2387/// -- so `ui/library.rs` must open at the pointer through `menu_at` alone,
2388/// and this guard pins that it never routes back through `menu_floor`.
2389#[test]
2390fn every_darkroom_menu_sizes_its_list_against_the_floor_room_not_the_raw_viewport() {
2391 let file = "ui/overlays.rs";
2392 let text = src_text(file);
2393 assert!(
2394 !text.contains("menu_rows_h(rows.len(), viewport)"),
2395 "{file} sizes a menu's list against the raw viewport again -- \
2396 route it through stance::menu_floor's room instead, or a tall \
2397 menu will climb back over the picture"
2398 );
2399 let floors = text.matches("menu_floor(").count();
2400 let sizings = text.matches("menu_rows_h(rows.len(),").count();
2401 assert_eq!(
2402 floors, sizings,
2403 "{file} has a menu list-sizing call not paired with a menu_floor \
2404 call -- every darkroom menu must clamp both its anchor and its \
2405 list room together"
2406 );
2407 assert!(
2408 sizings > 0,
2409 "{file} no longer opens any menu -- update this guard"
2410 );
2411 let library = src_text("ui/library.rs");
2412 assert!(
2413 !library.contains("menu_floor("),
2414 "ui/library.rs routes its menu through menu_floor's picture-floor \
2415 clamp again -- a right-click high in the dock teleports back down \
2416 to the picture floor (the 'menu in somewhere nonsense' defect)"
2417 );
2418 assert!(
2419 library.contains("menu_at_w(at, viewport, pw, h)") && !library.contains("ROW_CLEAR"),
2420 "ui/library.rs no longer anchors its menu on the pointer through \
2421 menu_at_w; update this guard"
2422 );
2423}
2424
2425/// The settings page's own organising rule: PROJECT rows open only the
2426/// doors that write into the `.edith` file ([`Player::open_picker`],
2427/// [`Player::open_mix`]), and EDITOR rows open only the doors that do not
2428/// ([`Player::toggle_proxies`], [`Player::toggle_auto_proxies`],
2429/// [`Player::open_subtitle_style`]) -- never the config-file writers
2430/// (`ui::dock_stance::config_path`/`ui::theme::config_path`/
2431/// `keymap::Keymap::config_path`) directly, which every editor-side row
2432/// already routes around through its own opener. A row wired to the wrong
2433/// section's opener is exactly the regression a page organised around named
2434/// sections invites -- and the tab strip did not loosen it: a tab decides
2435/// which section is *shown*, never which door a row opens. This pins each
2436/// half to its own doors so the two lists cannot cross.
2437#[test]
2438fn settings_project_and_editor_sections_open_disjoint_doors() {
2439 let source = src_text("ui/settings_stance.rs");
2440 let project_start = source
2441 .find("fn project_section(")
2442 .expect("the project section");
2443 let editor_start = source
2444 .find("fn editor_section(")
2445 .expect("the editor section");
2446 let render_start = source
2447 .find("pub(crate) fn render(")
2448 .expect("the page's render fn");
2449 assert!(
2450 project_start < editor_start && editor_start < render_start,
2451 "the three fns moved; this scan is blind"
2452 );
2453 let project_body = &source[project_start..editor_start];
2454 let editor_body = &source[editor_start..render_start];
2455
2456 // `Pick::Theme` is the one list that is nobody's project -- the palette
2457 // lives in ~/.config/edith like the subtitle font beside it (see
2458 // `menus.rs`'s own note on the variant), so its row is EDITOR's by the
2459 // same rule every other row here follows. The scan below is on the door
2460 // *string*, so the palette row is subtracted from the EDITOR body before
2461 // the project-door check runs rather than the check being loosened for
2462 // every picker.
2463 // `Pick::Autosave` is the same kind of thing: how often this machine writes
2464 // the recovery copy beside the project, kept in ~/.config/edith/autosave.
2465 let editor_no_theme = editor_body
2466 .replace("open_picker(Pick::Theme", "")
2467 .replace("open_picker(Pick::Autosave", "");
2468 {
2469 let door = "open_picker(";
2470 assert!(
2471 project_body.contains(door),
2472 "PROJECT section no longer opens {door} -- update this guard"
2473 );
2474 assert!(
2475 !editor_no_theme.contains(door),
2476 "EDITOR section opens {door}, a project-file door -- that value belongs in PROJECT, not here"
2477 );
2478 }
2479 assert!(
2480 editor_body.contains("open_picker(Pick::Theme"),
2481 "the palette row left EDITOR -- it is a ~/.config preference, not a project value"
2482 );
2483 // The proxy switches are the project's (DESIGN §9.2: written into the
2484 // .edith once one is open), so they moved from EDITOR to PROJECT; the
2485 // subtitle font stays this machine's.
2486 for door in ["toggle_proxies(", "toggle_auto_proxies("] {
2487 assert!(
2488 project_body.contains(door),
2489 "PROJECT section no longer opens {door} -- the proxy switches are the project's"
2490 );
2491 assert!(
2492 !editor_no_theme.contains(door),
2493 "EDITOR section opens {door}, a project-file door -- that value belongs in PROJECT, not here"
2494 );
2495 }
2496 assert!(
2497 editor_body.contains("open_subtitle_style("),
2498 "EDITOR section no longer opens the subtitle font -- update this guard"
2499 );
2500 assert!(
2501 !project_body.contains("open_subtitle_style("),
2502 "PROJECT section opens the subtitle font, an editor-only door -- that value belongs in EDITOR, not here"
2503 );
2504 // Neither section writes a config file straight from a row: both go
2505 // through an opener, which is the one place a config-file write (the
2506 // subtitle style card's Save, this window's next project load) is
2507 // allowed to live.
2508 // The file helpers after the EXPORT section (the export pick's path, the
2509 // keys' save) are the openers' own home, so the rows' scan stops short of
2510 // them; the export pick's path is then checked where it is defined.
2511 let rows_body = &editor_body[..editor_body
2512 .find("/// Every format the page can pick")
2513 .unwrap_or(editor_body.len())];
2514 for path_fn in [
2515 "dock_stance::config_path",
2516 "theme::config_path",
2517 "Keymap::config_path",
2518 ] {
2519 assert!(
2520 !project_body.contains(path_fn),
2521 "PROJECT section touches {path_fn} directly"
2522 );
2523 assert!(
2524 !rows_body.contains(path_fn),
2525 "EDITOR section touches {path_fn} directly"
2526 );
2527 }
2528 let export_ui = src_text("export_ui.rs");
2529 assert!(
2530 export_ui.contains(
2531 "fn export_defaults_path() -> PathBuf {\n crate::keymap::Keymap::config_path()"
2532 ),
2533 "the export pick's file moved out of its one helper"
2534 );
2535}
2536
2537/// D1's own class, pinned per row rather than per section: a row's hint can
2538/// claim a `~/.config/edith` default (the section header claims nothing on
2539/// its own since [`settings_project_and_editor_sections_open_disjoint_doors`]'s
2540/// commit, so a lying section head no longer slips past a reviewer -- but a
2541/// lying *row* hint did, on Proxies, because nothing scanned row text at all).
2542/// For every row whose own hint text names that file, this requires the
2543/// matching `save_*_pref`/`load_*_pref` pair to actually exist in
2544/// `player/library.rs` -- the exact gap Proxies shipped with: a hint promising
2545/// a default the row's own door never wrote.
2546#[test]
2547fn settings_row_hints_naming_config_edith_have_a_matching_pref_pair() {
2548 let source = src_text("ui/settings_stance.rs");
2549 let library = src_text("player/library.rs");
2550 // (row id, the stem its pref functions are named after)
2551 for (row_id, stem) in [
2552 ("settings-proxies", "proxies"),
2553 ("settings-auto-proxies", "auto_proxies"),
2554 ] {
2555 let row_start = source
2556 .find(&format!("\"{row_id}\""))
2557 .unwrap_or_else(|| panic!("{row_id} row moved or renamed -- update this guard"));
2558 let row_end = source[row_start..]
2559 .find(",\n ))")
2560 .map_or(source.len(), |i| row_start + i);
2561 let row_text = &source[row_start..row_end];
2562 if !row_text.contains("~/.config/edith") {
2563 continue;
2564 }
2565 for prefix in ["save_", "load_"] {
2566 let fn_name = format!("{prefix}{stem}_pref");
2567 assert!(
2568 library.contains(&format!("fn {fn_name}(")),
2569 "{row_id}'s hint claims a ~/.config/edith default but \
2570 player/library.rs has no `{fn_name}` -- the hint promises \
2571 storage the row does not have"
2572 );
2573 }
2574 }
2575}
2576
2577/// With no project open, a PROJECT row must not fall back to a bare noun
2578/// ("Size"/"Rate"/"HDR") standing in the value slot -- it reads as a value
2579/// while carrying none. This binary has no `TestAppContext` to actually
2580/// render the page with `player.session` empty, so this is a source scan
2581/// for the fallback strings the bug shipped as, same as the guard above it.
2582#[test]
2583fn settings_project_rows_have_no_bare_noun_placeholder() {
2584 let source = src_text("ui/settings_stance.rs");
2585 let project_start = source
2586 .find("fn project_section(")
2587 .expect("the project section");
2588 let editor_start = source
2589 .find("fn editor_section(")
2590 .expect("the editor section");
2591 let project_body = &source[project_start..editor_start];
2592 for placeholder in [
2593 "\"Size\".to_string()",
2594 "\"Rate\".to_string()",
2595 "\"HDR\".to_string()",
2596 ] {
2597 assert!(
2598 !project_body.contains(placeholder),
2599 "a PROJECT row fell back to the bare noun {placeholder} -- it reads as a value with no project open"
2600 );
2601 }
2602}
2603
2604/// The HDR group (the look HDR gets on a normal screen) shows only when the
2605/// project has an HDR source, and the read-only reference rows are gone from
2606/// Settings: nothing there is a fact about one file.
2607#[test]
2608fn the_hdr_group_shows_only_with_hdr_and_the_reference_rows_are_gone() {
2609 let source = src_text("ui/settings_stance.rs");
2610 let project_start = source.find("fn project_section(").expect("the project section");
2611 let editor_start = source.find("fn editor_section(").expect("the editor section");
2612 let project_body = &source[project_start..editor_start];
2613 assert!(project_body.contains("has_hdr.then("), "the HDR group is no longer conditional");
2614 assert!(project_body.contains("\"When HDR plays on a normal screen\""));
2615 for gone in ["settings-hdr-reference", "settings-content-light", "settings-mix", "\"Mix\""] {
2616 assert!(!project_body.contains(gone), "Settings still has {gone}");
2617 }
2618}
2619/// The parity class this user has reported four separate times: "some
2620/// options are only reachable via keyboard shortcut". A source scan (this
2621/// binary has no `TestAppContext` to click through) over every darkroom
2622/// surface -- the dock, the bench/timeband transport, the
2623/// settings page, the maximized cards and the clip context menu
2624/// (`menus.rs`'s `MENU_ITEMS`, rendered mouse-and-chord-visible by
2625/// `overlays.rs`) -- for a literal `ActionId::<variant>` mention. An
2626/// [`ActionId`] reachable by chord ([`Keymap::defaults`]) but absent from
2627/// every one of those texts has no mouse door into the darkroom at all,
2628/// which is exactly this bug's shape (`Fit` and `Redo` shipped that way
2629/// until this commit).
2630///
2631/// [`ActionId::Resolution`] and [`ActionId::SubtitleStyle`] are the two
2632/// deliberate exceptions: their settings-page rows open them through
2633/// `Pick::Resolution` and `open_subtitle_style(cx)` respectively, never
2634/// spelling the action name itself, so each is matched on its own door
2635/// string instead.
2636///
2637/// Every action gets a persistent regional control or the context-menu row for
2638/// the thing it acts on. Any exemption is independently-owned lane parity work,
2639/// named with its owner so a future removal cannot silently turn any unrelated
2640/// action back into keyboard-only.
2641#[test]
2642fn every_action_has_a_darkroom_widget_home_or_explicit_owner() {
2643 use crate::ActionId;
2644 // Empty: every action now has a row on the menu bar (DESIGN §4.4), so no
2645 // action is exempt. The entries this list held (the selection walk, the
2646 // shuttle, the sync walk, the trims at the playhead and the rest) each
2647 // became a menu row. An exemption added later needs an owner, and it goes
2648 // back here.
2649 const EXPLICITLY_OWNED_ELSEWHERE: &[(ActionId, &str)] = &[];
2650 /// `ActionId::Loop` is a prefix of `ActionId::LoopTrim`, and the keys
2651 /// menu's own label arm (`ActionId::ToggleMute | ActionId::Paste =>
2652 /// format!("{full} (global)")`) shapes a string rather than opening a
2653 /// door -- neither is a widget home, so neither counts as a mention.
2654 fn mentions(text: &str, name: &str) -> bool {
2655 text.lines()
2656 .filter(|l| !l.contains("=> format!(\"{full} (global)\")"))
2657 .any(|line| {
2658 line.match_indices(&format!("ActionId::{name}"))
2659 .any(|(i, m)| {
2660 !line[i + m.len()..]
2661 .chars()
2662 .next()
2663 .is_some_and(|c| c.is_alphanumeric() || c == '_')
2664 })
2665 })
2666 }
2667 let darkroom = [
2668 "ui/bench_stance",
2669 "ui/cards",
2670 "ui/dock_stance.rs",
2671 "ui/menubar.rs",
2672 "ui/overlays.rs",
2673 "ui/settings_stance.rs",
2674 "ui/stance.rs",
2675 "ui/timeband_stance.rs",
2676 "ui/toolbar.rs",
2677 "menus.rs",
2678 ]
2679 .map(src_text)
2680 .join("\n");
2681 for action in ActionId::ALL {
2682 if let Some((_, owner)) = EXPLICITLY_OWNED_ELSEWHERE
2683 .iter()
2684 .find(|(owned, _)| *owned == action)
2685 {
2686 assert!(!owner.is_empty(), "ActionId::{action:?} needs an owner");
2687 // An exemption is a debt, not a licence: once the owning lane
2688 // has mounted the action, the entry has to go, or the sweep
2689 // goes blind on an action that is covered.
2690 assert!(
2691 !mentions(&darkroom, &format!("{action:?}")),
2692 "ActionId::{action:?} has a darkroom home now -- delete its \
2693 EXPLICITLY_OWNED_ELSEWHERE entry ({owner})"
2694 );
2695 continue;
2696 }
2697 let name = format!("{action:?}");
2698 let mentioned = mentions(&darkroom, &name)
2699 || (action == ActionId::Resolution && darkroom.contains("Pick::Resolution"))
2700 || (action == ActionId::SubtitleStyle && darkroom.contains("open_subtitle_style(cx)"));
2701 let hitmap_id = crate::ui::hitmap::action_id(action);
2702 assert_eq!(
2703 hitmap_id,
2704 format!("action.{name}"),
2705 "ActionId::{name} has a Darkroom widget home but no stable hitmap id"
2706 );
2707 assert!(
2708 mentioned,
2709 "ActionId::{name} is bound to a chord but has no visible affordance \
2710 anywhere in the darkroom tree -- either mount it or name the owning parity lane"
2711 );
2712 }
2713}
2714
2715/// Transition affordances must be painted and use the existing edit state:
2716/// fades own their drag handles, an active dissolve remains a mouse toggle,
2717/// and a carried lane names the exact slot `reorder_lane` will use.
2718#[test]
2719fn darkroom_bench_wires_transition_controls_and_lane_drop_cue() {
2720 let clip_src = src_text("ui/bench_stance/clip.rs");
2721 let clip = &clip_src[clip_src.find("fn clip_box(").expect("the clip renderer")..];
2722 for needle in [
2723 "fade_wedge(true)",
2724 "fade_wedge(false)",
2725 "dissolve_glyph()",
2726 "this.start_fade_drag(lane, idx, is_in, event.position.x, cx)",
2727 "this.dissolve_selected(cx)",
2728 ] {
2729 assert!(
2730 clip.contains(needle),
2731 "the Darkroom clip lost its transition affordance: {needle}"
2732 );
2733 }
2734 let dissolve = &clip[clip
2735 .find(".when(dissolves, |d| {")
2736 .expect("the dissolve affordance")
2737 ..clip.find(".when(trims(span),").expect("the fade handles")];
2738 assert!(
2739 dissolve.contains(".w(px(FADE_HANDLE_W))"),
2740 "dissolve click target no longer matches fade-handle width"
2741 );
2742 assert!(
2743 dissolve.contains(".h(px(FADE_HANDLE_H))"),
2744 "dissolve click target no longer matches fade-handle height"
2745 );
2746 assert!(
2747 !dissolve.contains("h_full()"),
2748 "dissolve click target still covers the clip body"
2749 );
2750 assert!(
2751 !dissolve.contains(".w(px(scale"),
2752 "dissolve hit test still tracks transition width"
2753 );
2754
2755 let lane_src = src_text("ui/bench_stance/lane.rs");
2756 let from = lane_src.find("fn lane_row(").expect("the lane renderer");
2757 let lane = &lane_src[from..from + lane_src[from..].find("\n}\n").expect("its end")];
2758 for needle in [
2759 "this.preview_lane_drop(event.drag(cx).0, lane, cx)",
2760 "this.forget_lane_drop(lane, cx)",
2761 ".lane_drop",
2762 "if drop.above",
2763 ] {
2764 assert!(
2765 lane.contains(needle),
2766 "the Darkroom lane lost its reorder feedback: {needle}"
2767 );
2768 }
2769}
2770
2771/// DESIGN §7: the head's switches are text glyphs at a 24px hit area, the head
2772/// is 140px wide, and a hidden or muted lane's clips sit at 40%. The
2773/// subtitle lane's show toggle is its name now, so the eye glyph is the hide.
2774#[test]
2775fn the_lane_head_is_140_wide_with_glyph_switches_and_dims_hidden_lanes() {
2776 let bench = src_text("ui/bench_stance");
2777 assert!(
2778 bench.contains("const HEAD_W: f32 = 156."),
2779 "the lane head is no longer 140px wide"
2780 );
2781 for glyph in ["◉", "♪", "▣"] {
2782 assert!(bench.contains(glyph), "the head lost its {glyph} switch");
2783 }
2784 let lane = src_text("ui/bench_stance/lane.rs");
2785 assert!(
2786 lane.contains("const DIMMED_OPACITY: f32 = 0.4;") && lane.contains(".opacity(dim)"),
2787 "a hidden or muted lane's clips are not dimmed to 40%"
2788 );
2789 let name = source_from("fn lane_name(");
2790 let name = &name[..name.find("\n}\n").expect("the name's end")];
2791 assert!(
2792 !name.contains("◉") && name.contains("show_sub_lane(lane, cx)"),
2793 "the subtitle show toggle still wears the eye glyph, or is not the name"
2794 );
2795}
2796
2797/// The pointer harness can only drive controls that report the bounds of the
2798/// element that owns the gesture. Keep every dynamic Darkroom entry surface
2799/// named, so UI verification never falls back to guessed pixels.
2800#[test]
2801fn hitmap_names_every_darkroom_pointer_entry_surface() {
2802 let bench = src_text("ui/bench_stance");
2803 for needle in [
2804 "clip.{}.{}.{}.fade-{}",
2805 "clip.{}.{}.{}.trim-{}",
2806 "clip.{}.{}.{}.dissolve",
2807 "lane.{}.reorder",
2808 "lane.{}.eye",
2809 "lane.{}.mute",
2810 "lane.{}.lock",
2811 ] {
2812 assert!(
2813 bench.contains(needle),
2814 "bench control missing hitmap id: {needle}"
2815 );
2816 }
2817 assert!(
2818 bench.contains(".when(trims(span), |d| {"),
2819 "fade handles must cover video clips as well as audio clips"
2820 );
2821
2822 let dock = src_text("ui/dock_stance.rs");
2823 for needle in [
2824 "subtitle.{group_ord}.{track}.row",
2825 "subtitle.{group_ord}.{track}.select",
2826 "source.{i}.row",
2827 "source.{i}.add",
2828 "dock.filter",
2829 ] {
2830 assert!(
2831 dock.contains(needle),
2832 "dock control missing hitmap contract: {needle}"
2833 );
2834 }
2835
2836 for (path, needles) in [
2837 (
2838 "ui/bench_stance/overview.rs",
2839 &[
2840 "timeline.overview",
2841 "stance-overview-window",
2842 "stance-strip-mark-in",
2843 "stance-strip-mark-out",
2844 "timeline.scrollbar",
2845 "stance-scroll-thumb",
2846 ][..],
2847 ),
2848 ("ui/preview.rs", &["source.ruler"][..]),
2849 (
2850 "ui/overlays.rs",
2851 &[
2852 "menu.{action:?}",
2853 "menu.properties",
2854 "theme.{n}.row",
2855 "let enabled = refusal.yes()",
2856 "hitmap::dynamic(\n move || (format!(\"menu.{action:?}\"",
2857 ][..],
2858 ),
2859 (
2860 "ui/settings_stance.rs",
2861 &[".children(hitmap::control(id, label_text, !exporting))"][..],
2862 ),
2863 ] {
2864 let source = src_text(path);
2865 for needle in needles {
2866 assert!(
2867 source.contains(needle),
2868 "{path} missing hitmap contract: {needle}"
2869 );
2870 }
2871 }
2872}
2873
2874/// An external file drag (gpui `ExternalPaths`, Wayland `text/uri-list`) has
2875/// to be heard over the DOCK -- the Sources/library panel -- and not only
2876/// over the centre column: the dock is the centre's flex sibling, so the
2877/// handler `stance-centre` used to carry covered none of
2878/// the library panel, which is exactly the shipped "drag and drop file
2879/// import is not working on library panel" defect. The listener therefore
2880/// belongs to the room root (`stance-room`), above every region, and it must
2881/// route the dropped paths through `import` -- the same door the Import
2882/// action uses.
2883///
2884/// A scan, not a click: this crate has no gpui `VisualTestContext` harness
2885/// (nothing in `tests/` opens a window), and a drop cannot be simulated
2886/// without one -- the compositor half (`wl_data_device`) is out of reach of
2887/// the test process either way.
2888#[test]
2889fn an_external_file_drop_is_heard_by_the_whole_room_and_imports() {
2890 let stance = src_text("ui/stance.rs");
2891 let root_at = stance
2892 .find(".id(\"stance-room\")")
2893 .expect("no stance root div");
2894 let centre_at = stance
2895 .find(".id(\"stance-centre\")")
2896 .expect("no stance centre column");
2897 let drop_at = stance
2898 .find(".on_drop(cx.listener(|this, paths: &gpui::ExternalPaths")
2899 .expect("no external-file drop handler in the stance");
2900 assert!(
2901 drop_at > root_at && drop_at < centre_at,
2902 "the external drop handler is not on the room root -- \
2903 a drop over the dock's library panel is heard by nothing"
2904 );
2905 let body = &stance[drop_at..(drop_at + 700).min(stance.len())];
2906 assert!(
2907 body.contains("this.import(path, cx)"),
2908 "a dropped file does not go through the import door: {body}"
2909 );
2910 // ...and the library panel says so while the file is over it.
2911 let dock_at = stance.find(".id(\"stance-dock\")").expect("no dock div");
2912 let dock = &stance[dock_at..(dock_at + 700).min(stance.len())];
2913 assert!(
2914 dock.contains(".drag_over::<gpui::ExternalPaths>"),
2915 "the dock answers an external file drag with nothing: {dock}"
2916 );
2917}
2918
2919/// The wheel is the bench's, not a clip's: the user rolled it over the bench
2920/// and nothing moved unless the pointer happened to sit on a track, because
2921/// the only listeners were one per bed and one on the ruler strip. The row's
2922/// listener now sits on the whole row (head column included) and stops there,
2923/// and `bench-content` answers everything else -- the strip left of the ruler,
2924/// the ruler itself, the gaps between rows, the space below the last track.
2925/// Exactly two listeners, so no strip answers one notch twice.
2926#[test]
2927fn the_bench_answers_a_wheel_notch_anywhere_over_it() {
2928 let bench = src_text("ui/bench_stance");
2929 assert_eq!(
2930 bench.matches(".on_scroll_wheel(").count(),
2931 2,
2932 "the bench has a wheel listener per region again -- a notch would be answered twice"
2933 );
2934 let row = bench
2935 .find(".id((\"bench-lane\", lane.ord")
2936 .expect("no lane row");
2937 let bed = bench.find(".id((\"bench-bed\"").expect("no lane bed");
2938 let row_wheel = bench[row..bed]
2939 .find(".on_scroll_wheel(")
2940 .map(|at| &bench[row + at..bed])
2941 .expect("the lane row does not answer the wheel -- only its bed does");
2942 assert!(
2943 row_wheel[..200].contains("cx.stop_propagation();")
2944 && row_wheel[..200].contains("this.timeline_wheel(event, cx)"),
2945 "the row's wheel lost the mapping or its stop: {}",
2946 &row_wheel[..200]
2947 );
2948 let content = bench
2949 .find(".id(\"bench-content\")")
2950 .expect("no bench content");
2951 let content_wheel = bench[content..]
2952 .find(".on_scroll_wheel(")
2953 .expect("the bench container does not answer the wheel");
2954 assert!(
2955 content_wheel < 700 && bench[content..].contains("this.timeline_wheel(event, cx)"),
2956 "the container's wheel listener is not on the container itself"
2957 );
2958 // The ruler is its own file now; it is mounted in the content between the
2959 // container's listener and the lane column, and must add none of its own.
2960 let ruler = src_text("ui/bench_stance/ruler.rs");
2961 assert!(
2962 !ruler.contains(".on_scroll_wheel("),
2963 "the ruler answers the wheel on its own again -- one notch, two scrolls"
2964 );
2965 let content_src = src_text("ui/bench_stance/mod.rs");
2966 let mounted = content_src.find(".child(ruler(").expect("the ruler is not mounted");
2967 let lanes = content_src
2968 .find(".id(\"bench-lanes\")")
2969 .expect("no lane column");
2970 assert!(
2971 !content_src[mounted..lanes].contains(".on_scroll_wheel("),
2972 "the ruler answers the wheel on its own again -- one notch, two scrolls"
2973 );
2974}
2975
2976/// The way back from a layout dragged somewhere unusable: a double press on
2977/// the seam forgets the size, and the region is the window's own share again
2978/// -- the *same* share an untouched window gives it, not a second default
2979/// kept beside the first ([`Splits::clear`]).
2980#[test]
2981fn a_double_pressed_divider_forgets_the_size_it_was_dragged_to() {
2982 use crate::layout::{Split, Splits, split_size};
2983 use gpui::{px, size};
2984
2985 let window = size(px(1280.), px(720.));
2986 let mut splits = Splits::default();
2987 for split in Split::PERSISTED {
2988 let default = split_size(split, None, 2, window, false);
2989 // A hand takes the seam somewhere else...
2990 splits.set(split, split_size(split, Some(300.), 2, window, false));
2991 assert_ne!(
2992 splits.get(split),
2993 None,
2994 "{split:?} kept nothing of the drag"
2995 );
2996 // ...and the double press puts it back where an untouched window
2997 // would have drawn it.
2998 splits.clear(split);
2999 assert_eq!(splits.get(split), None, "{split:?} still holds a size");
3000 assert_eq!(
3001 split_size(split, splits.get(split), 2, window, false),
3002 default,
3003 "{split:?} came back to something other than its own share"
3004 );
3005 }
3006}
3007
3008/// The seam is a ghost (DESIGN §11.2): 6 px of hit area with *nothing* painted
3009/// at rest, one hairline of dim ink under the pointer, the same line one step
3010/// brighter while it is held. The scan is the guard because the failure it
3011/// catches -- a `bg` on the strip, which is what the divider shipped with --
3012/// draws a 6 px band of colour down the room at rest and reads as the chrome
3013/// the user called crowded.
3014#[test]
3015fn the_seam_paints_nothing_until_a_pointer_finds_it() {
3016 let src = src_text("interact.rs");
3017 let start = src.find("pub(crate) fn divider(").expect("the divider");
3018 let body = &src[start..start + src[start..].find("\n}\n").expect("its end")];
3019 assert!(
3020 !body.contains(".bg("),
3021 "the divider fills its strip at rest: {body}"
3022 );
3023 assert!(
3024 body.contains("gpui::transparent_black()"),
3025 "the divider's line is inked at rest: {body}"
3026 );
3027 for step in [
3028 ".group_hover(",
3029 "GRAB_W",
3030 "BENCH_GRAB_H",
3031 "STROKE_DIVIDER()",
3032 "INK3()",
3033 "border_t_1()",
3034 "border_l_1()",
3035 ] {
3036 assert!(body.contains(step), "the divider is missing {step}");
3037 }
3038 // The hairline is the *band's* child, not the strip's own border: a line
3039 // raised only by the 6 px that already grab the seam is feedback the hand
3040 // gets after it no longer needs it (a `bench=207` -- a press with no
3041 // drag in it -- beside a dragged `dock=277`).
3042 assert!(
3043 body.find(".group(group.clone())")
3044 .expect("the band's group")
3045 < body.find("border_t_1()").expect("the hairline"),
3046 "the hairline is painted outside the band: {body}"
3047 );
3048}
3049
3050/// The band the hand actually gets, in seam coordinates. It once reached 13px
3051/// past the line to cover the `BENCH` label row a hand aimed at; that row is
3052/// gone (cleanse round 2) and the ruler under the seam answers presses of its
3053/// own (it scrubs), so the bench seam takes every other seam's reach and no
3054/// more -- a deeper band would eat scrubs at the film's own top edge. Every
3055/// seam shares one 24 px band ([`HIT_MIN`], WCAG 2.5.8), hung one row above
3056/// the strip, so every seam reaches the same 17 px past its own line.
3057#[test]
3058fn the_bench_seam_reaches_no_further_than_every_other_seam() {
3059 let above = 1.;
3060 let reach = |grab: f32| grab - above - crate::layout::SPLIT_W;
3061 assert_eq!(crate::layout::GRAB_W, HIT_MIN, "a seam's band is 24 px");
3062 assert_eq!(reach(crate::layout::GRAB_W), 17.);
3063 assert_eq!(
3064 reach(crate::layout::BENCH_GRAB_H),
3065 reach(crate::layout::GRAB_W),
3066 "the bench band reaches past the ruler row, which answers presses itself"
3067 );
3068}
3069
3070/// The clamp table, driven: the seam refuses exactly two things, and neither
3071/// is anywhere near where a hand drags. Measured live at 2560x1440 --
3072/// `bench=105` at the floor, `bench=1164` at the ceiling.
3073#[test]
3074fn the_bench_seam_stops_at_its_floor_and_its_ceiling() {
3075 use crate::{BENCH_MIN_H, Split, split_bounds, split_size};
3076 use gpui::{px, size};
3077
3078 let window = size(px(2560.), px(1440.));
3079 let (min, max) = split_bounds(Split::Bench, 2, window, false);
3080 assert_eq!(min, BENCH_MIN_H);
3081 assert_eq!(
3082 max,
3083 1440. - crate::ui::stance::TIME_BAND_H - crate::ui::stance::LEDGER_H - 160.
3084 );
3085 for (asked, want) in [(0., min), (-942., min), (5000., max), (207., 207.)] {
3086 assert_eq!(
3087 split_size(Split::Bench, Some(asked), 2, window, false),
3088 want,
3089 "a bench dragged to {asked}"
3090 );
3091 }
3092}
3093
3094/// DESIGN §7: "lanes scroll behind the pinned ruler and track heads" -- pinned
3095/// means pinned. A clip that starts left of the view sits at a negative `left`
3096/// inside its bed, and with no clip mask gpui paints it (and its hitbox) over
3097/// the `HEAD_W` px head column, so V1/A1 and their verbs disappear under the first
3098/// take as soon as the bench is wheeled past frame 0. The mask belongs on the
3099/// bed itself so a half-scrolled clip still drags on the half that shows.
3100#[test]
3101fn the_lane_bed_clips_its_clips_at_the_pinned_heads() {
3102 let src = src_text("ui/bench_stance");
3103 let start = src.find(r#".id(("bench-bed""#).expect("the bed");
3104 let bed = &src[start
3105 ..start
3106 + src[start..]
3107 .find(".bg(rgb(DARK_CANVAS()))")
3108 .expect("its fill")];
3109 assert!(
3110 bed.contains(".overflow_hidden()"),
3111 "the bed lets its clips paint outside itself, straight over the \
3112 pinned lane heads: {bed}"
3113 );
3114}
3115
3116/// A source row is its name first (user 2026-09-09: "clunky, crowded and
3117/// problematic"). At DOCK_W 280 the name used to be the only flexible child
3118/// among six, so it measured 0px and the library showed
3119/// `● V1 A1 · 2 uses Preview Add ↵ ○` -- every part of a row except the one
3120/// thing the row is for. The fix is subtraction, not a hover gate (DESIGN §8):
3121/// the name keeps 60% of the row, usage joins the metadata line under it, and
3122/// the three verbs shrink to glyph ghosts at the right edge.
3123#[test]
3124fn a_source_row_shows_its_name_before_anything_else() {
3125 let dock = src_text("ui/dock_stance.rs");
3126 let start = dock.find("fn source_row(").expect("the source row");
3127 let row = &dock[start..dock.find("/// Imported subtitle tracks").expect("its end")];
3128 // REDESIGN §3.8: the name is the one flexible child beside a fixed poster
3129 // and a 28px `+`, and it ends in an ellipsis rather than collapsing.
3130 assert!(
3131 row.contains(".flex_1()\n .min_w(px(0.))\n .truncate()"),
3132 "the row name can no longer shrink to an ellipsis"
3133 );
3134 // Cleanse round 2: the name is what the editor calls the film, not what
3135 // the filesystem calls the bytes.
3136 assert!(
3137 row.contains("let name: SharedString = stem(&row.name).into();"),
3138 "the row name still wears its extension"
3139 );
3140 assert_eq!(
3141 crate::ui::dock_stance::stem("he_is_not_the_only_one.mp4"),
3142 "he_is_not_the_only_one"
3143 );
3144 // A file with several audio streams keeps the stream half of its name and
3145 // loses only the extension; a name that is all extension keeps it.
3146 assert_eq!(
3147 crate::ui::dock_stance::stem("A Film.mkv [audio 2]"),
3148 "A Film [audio 2]"
3149 );
3150 assert_eq!(crate::ui::dock_stance::stem(".srt"), ".srt");
3151 // One ghost on the right edge, and one only: preview and the stand-in
3152 // moved into the row's own menu (`RowItem::Preview`/`Proxy`).
3153 // REDESIGN §3.8: a 28px ghost `plus` icon button, always drawn; the key is
3154 // nowhere on the row (§5 rule 1).
3155 assert!(row.contains("Icon::Plus"), "the right-edge verb lost its plus");
3156 assert!(!row.contains(r#".child("↵")"#), "a key is back on the row");
3157 for gone in [r#".child("▷")"#, "dock-proxy-toggle", "dock-preview"] {
3158 assert!(!row.contains(gone), "the row still carries `{gone}`");
3159 }
3160 assert!(
3161 row.contains("source.{i}.add"),
3162 "the add ghost lost its hitmap entry"
3163 );
3164 // The metadata line is codec · length · lanes: no decoder seat, no use
3165 // count (`usage_line` and the `seats` filter above it).
3166 assert!(
3167 row.contains(".map(Backend::label);") && row.contains("fn row_facts("),
3168 "the metadata line no longer drops the decoder seat"
3169 );
3170 let usage = &dock[dock.find("fn usage_labels(").expect("the usage chips")..start];
3171 assert!(
3172 !usage.contains("use{}"),
3173 "the metadata line still counts uses"
3174 );
3175 // DESIGN §8: the permanent footer telling the editor how to use a list
3176 // ("drag · ↵ add · double-click plays") is instructional copy and is gone.
3177 assert!(
3178 !dock.contains("double-click plays"),
3179 "the dock still carries an instruction footer"
3180 );
3181 // ...an empty library says so in words, and a filter that matches
3182 // nothing keeps the one noun.
3183 assert!(
3184 dock.contains("EMPTY_LIBRARY_HINT") && dock.contains("Nothing matches"),
3185 "the empty dock lost its empty-library words or the no-match noun"
3186 );
3187}
3188
3189/// DESIGN §6.7: the Media tab is one list of rows at a fixed height, with
3190/// `+ Add` as a text button, and the footer's import button named for what
3191/// it does.
3192#[test]
3193fn the_media_tab_rows_are_fixed_and_the_footer_names_the_import() {
3194 assert_eq!(crate::ui::dock_stance::SOURCE_ROW_H, 64.0);
3195 let dock = src_text("ui/dock_stance.rs");
3196 let row = &dock[dock.find("fn source_row(").expect("the source row")..];
3197 assert!(
3198 row.contains(".h(px(source_row_h(usable)))"),
3199 "a media row is no longer fixed at 72px"
3200 );
3201 assert!(
3202 dock.contains(r#""Import media…""#),
3203 "the footer no longer names the import"
3204 );
3205 // The tab is found by its id, not by its label, so a rename cannot
3206 // silently break which surface a click opens.
3207 assert!(
3208 dock.contains(r#"match id == "dock-tab-src""#)
3209 && dock.contains(r#"this.dock_src_active = id == "dock-tab-src";"#),
3210 "the tab still compares its label to pick its surface"
3211 );
3212}
3213
3214/// The dock's metadata line drops the decoder *seat* and nothing else. A file
3215/// the decoder refused has no seat to drop: its detail is the refusal, and it
3216/// is the only thing the line has to say.
3217#[test]
3218fn the_dock_keeps_a_refusal_where_it_drops_a_seat() {
3219 use crate::ui::dock_stance::without_seats;
3220 use engine::decode::Backend;
3221
3222 let seats = [
3223 Backend::Opening,
3224 Backend::Hardware,
3225 Backend::Software,
3226 Backend::Still,
3227 Backend::Gap,
3228 ]
3229 .map(Backend::label);
3230 assert_eq!(
3231 without_seats("h264 · HW", &seats),
3232 "h264",
3233 "the seat is how this machine reads it, and the row says what the file is"
3234 );
3235 let refusal = "no Segment element: not a Matroska file";
3236 assert_eq!(
3237 without_seats(refusal, &seats),
3238 refusal,
3239 "a refusal is not a seat, and reaches the row whole"
3240 );
3241 // The halves keep their separator either way: a stream detail beside a
3242 // refusal is still two things said in order.
3243 assert_eq!(
3244 without_seats(&format!("{refusal} · stereo · 48 kHz"), &seats),
3245 format!("{refusal} · stereo · 48 kHz")
3246 );
3247}
3248
3249/// A room key pressed while the ring sits in the dock has to reach the room.
3250/// Two ways it did not: the dock's own handler could stop a key it does not
3251/// answer, and the body the dock mounts could leave the focused
3252/// `FocusHandle` with no element -- gpui dispatches only along the rendered
3253/// focus node's ancestors (`gpui-0.2.2` `window.rs:3982`, falling back to the
3254/// *window* root, which is not the room's div), so an orphaned handle kills
3255/// every key until the next click. Measured 2026-09-09: with KEYS open, a
3256/// second `?` and `space` reached no listener at all.
3257#[test]
3258fn every_dock_body_mounts_the_ring_it_is_standing_in_for() {
3259 let dock = src_text("ui/dock_stance.rs");
3260 for (body, id) in [
3261 ("sources", "\"dock-sources\""),
3262 ("clip", "\"dock-clip\""),
3263 ] {
3264 let after = dock
3265 .split(id)
3266 .nth(1)
3267 .unwrap_or_else(|| panic!("the dock's {body} body is gone"));
3268 let head: String = after.lines().take(4).collect();
3269 assert!(
3270 head.contains(".track_focus(") && head.contains(".on_key_down("),
3271 "the dock's {body} body mounts no focus handle: a ring left on it dies"
3272 );
3273 }
3274 // ...and the shared handler answers exactly two keys, stopping the stroke
3275 // only there; anything else bubbles to `ui::stance::render`'s handler.
3276 let handler = dock
3277 .split("fn cycle_on_key_down(")
3278 .nth(1)
3279 .expect("the dock's shared key handler is gone");
3280 let body = handler.split("\n}\n").next().unwrap();
3281 assert_eq!(
3282 body.matches("cx.stop_propagation()").count(),
3283 2,
3284 "the dock's key handler stops a stroke outside its tab/escape branches"
3285 );
3286 for branch in ["is_focus_cycle_key(key)", "is_focus_exit_key(key)"] {
3287 assert!(
3288 body.contains(branch),
3289 "{branch} left the dock's key handler"
3290 );
3291 }
3292}
3293
3294/// Focus and selection rings are drawn, never inserted: a `when(focused,
3295/// border_1())` puts a pixel of box into the flow and every row in the dock
3296/// steps sideways the moment the surface takes focus (hunter: h-clip-tab.png
3297/// vs i-library-menu.png).
3298#[test]
3299fn a_dock_ring_never_moves_what_it_rings() {
3300 let dock = src_text("ui/dock_stance.rs");
3301 for gate in [
3302 ".when(picked, |d| d.border_1()",
3303 ".when(focused, |d| d.border_1()",
3304 ] {
3305 assert!(
3306 !dock.contains(gate),
3307 "a dock ring is still added on state ({gate}), shifting its content"
3308 );
3309 }
3310 assert_eq!(
3311 dock.matches("gpui::transparent_black()").count(),
3312 8,
3313 "a dock ring lost its at-rest transparent border"
3314 );
3315 // ...and the focus ring is not painted at all (user 2026-09-09:
3316 // "clicking through timeline draws a white overlay around the timeline,
3317 // same happens for library section too"). Keyboard focus is unchanged --
3318 // only the paint is gone -- so no dock surface may reach for the focus
3319 // stroke or for `ink1` on a focused border.
3320 assert!(
3321 !dock.contains("STROKE_FOCUS"),
3322 "a dock surface paints the focus ring again"
3323 );
3324 assert!(
3325 !dock.contains("is_focused(window)"),
3326 "a dock surface reads focus for paint again"
3327 );
3328 assert!(
3329 dock.contains(".track_focus(&player.focus_dock)")
3330 && dock.contains(".track_focus(&player.focus_inspector)"),
3331 "dropping the ring's paint took the surface's keyboard focus with it"
3332 );
3333}
3334
3335/// DESIGN §9 as amended 2026-09-09: the keys list lives in the dock BODY,
3336/// not a plate over the bench and not a tab of its own (user: "remove keys
3337/// section from here since we also have it next to ledger"). The strip is
3338/// the SOURCES/CLIP pair; the list rides `keys_open` under a KEYS section
3339/// head, and the rows still come off `keys_rows` with the refused ones
3340/// greyed rather than hidden (§8).
3341#[test]
3342fn the_keys_list_is_dock_body_state_not_a_tab() {
3343 let stance = src_text("ui/stance.rs");
3344 assert!(
3345 !stance.contains("keys_overlay") && !stance.contains("stance-keys-overlay"),
3346 "the keys plate is still mounted over the bench"
3347 );
3348 let dock = src_text("ui/dock_stance.rs");
3349 for (id, label) in [("dock-tab-src", "Media"), ("dock-tab-clip", "Clip"), ("dock-tab-transcript", "Transcript")] {
3350 assert!(
3351 dock.contains(&format!("dock_tab(\"{id}\", \"{label}\"")),
3352 "the dock's tab strip lost {label}"
3353 );
3354 }
3355 // The sheet is a dialog over the picture, not a dock tab (nothing in the strip moves).
3356 assert!(
3357 !dock.contains("dock_tab(\"dock-tab-keys\""),
3358 "the shortcuts sheet is a dock tab again"
3359 );
3360 assert!(
3361 dock[dock.find("fn keys_sheet(").unwrap()..].contains("\"Keyboard shortcuts\""),
3362 "the shortcuts sheet draws no title"
3363 );
3364 assert!(
3365 dock.contains("keys_rows_matching("),
3366 "the shortcuts sheet draws something other than the action registry"
3367 );
3368 // A reference sheet, not a state view: no row dims for what the room can do right now.
3369 assert!(
3370 !dock.contains("Enable::No(why) | Enable::Hidden(why) => Some(why)"),
3371 "the shortcuts sheet greys rows by state; it is a reference"
3372 );
3373 assert!(
3374 dock[dock.find("fn keys_sheet(").unwrap()..].contains(".overflow_y_scroll()"),
3375 "the keys list does not scroll like its neighbours"
3376 );
3377 // The Sources filter box belongs to Sources: it is built inside
3378 // `sources_tab`, never in the shared frame `render` draws.
3379 let frame = &dock[dock.find("pub(crate) fn render(").unwrap()..];
3380 assert!(
3381 !frame.contains("dock-filter"),
3382 "the Sources filter box leaked into the shared dock frame"
3383 );
3384}
3385
3386/// DESIGN §6.9: the status bar keeps the selected clip or gap and export
3387/// progress on the left, the picture's format and the two room verbs
3388/// (`commands`, `shortcuts`) on the right. Project identity, save state, the
3389/// CC/settings/full verbs and the position timecode are gone from it; the
3390/// menu bar carries identity and save state now.
3391#[test]
3392fn the_ledger_carries_the_two_room_verbs_and_no_rail_remains() {
3393 let src = src_text("ui/stance.rs");
3394 for gone in ["stance-spine", "spine_stance", "SPINE_W", "fn spine("] {
3395 assert!(
3396 !src.contains(gone),
3397 "the rail is still in the stance: {gone}"
3398 );
3399 }
3400 let ledger = &src[src.find("fn ledger(").expect("the ledger strip")
3401 ..src.find("/// The dock:").expect("the dock frame")];
3402 // REDESIGN §3.13: no key hints in the status bar. The palette is the menu bar's
3403 // search field and the shortcuts sheet is in the Help menu.
3404 for gone in ["\"commands\"", "\"shortcuts\"", "ActionId::ShowActions", "ActionId::ShowKeys", "fn ledger_verb("] {
3405 assert!(!src.contains(gone) || gone.starts_with("ActionId") && !ledger.contains(gone), "the status bar kept {gone}");
3406 }
3407 assert!(src_text("ui/menubar.rs").contains("\"menubar-search\""));
3408 for gone in [
3409 "\"CC\"",
3410 "\"settings\"",
3411 "\"full\"",
3412 "ActionId::ToggleSubtitles",
3413 "ActionId::Settings",
3414 "ActionId::Fullscreen",
3415 "ActionId::Save",
3416 "project_path",
3417 "timecode(position",
3418 ] {
3419 assert!(
3420 !ledger.contains(gone),
3421 "the status bar still carries {gone}"
3422 );
3423 }
3424 // The format readout lives in the viewer header alone; the status bar repeats none of it.
3425 assert!(
3426 !ledger.contains("s.resolution()") && !ledger.contains("fps_label(player.fps)"),
3427 "the status bar repeats the viewer header's format"
3428 );
3429 assert!(src.contains("size_label(w, h)"), "the viewer header lost the picture's format");
3430}
3431
3432/// The `all` control left the ruler (cleanse round 2, DESIGN §5): the ruler
3433/// row is the bench's own top edge and carries ticks and the playhead alone.
3434/// Every removed control keeps a door -- `^a` still fires it, and the ruler's
3435/// own right-click menu ([`BENCH_ITEMS`]) is where the pointer reaches it --
3436/// so this checks the control is gone AND that the row exists, not just the
3437/// deletion.
3438#[test]
3439fn select_all_left_the_ruler_for_the_rulers_own_menu() {
3440 use crate::ActionId;
3441 use crate::menus::BENCH_ITEMS;
3442 let bench = src_text("ui/bench_stance");
3443 for gone in ["bench-select-all", "select_all_band", "SELECT_ALL_PAD"] {
3444 assert!(!bench.contains(gone), "the ruler still carries {gone}");
3445 }
3446 assert!(
3447 BENCH_ITEMS.contains(&ActionId::SelectAll),
3448 "`all` left the ruler with no menu row behind it"
3449 );
3450 // And the band it reserved is the ticks' again: nothing subtracts a
3451 // control's width from the bed's right edge any more.
3452 assert!(
3453 bench.contains("if x >= plate_w && x + label_w <= bed_w && x >= label_end + LABEL_GAP_PX {"),
3454 "the tick loop still keeps a band clear for a control that is gone"
3455 );
3456}
3457
3458/// The rest of cleanse round 2's bench + ledger, which is all about *one*
3459/// saying per thing: the head is a dot and a name (its verbs left, checked
3460/// above), a source's name is drawn once per source -- the audio half of a
3461/// linked insert has no plate, because the picture plate directly above it
3462/// and the shared dot already say whose it is -- names lose their extension
3463/// through one helper, and the ledger's state word is Save's only door now
3464/// (the time band's parking-spot ghost, filed there because the ledger was a
3465/// concurrent builder's file, is deleted).
3466#[test]
3467fn one_name_per_source_one_stem_helper_and_one_save_door() {
3468 let bench = src_text("ui/bench_stance");
3469 assert!(
3470 !bench.contains(".filter(|_| !(audio && clip.link.is_some()))"),
3471 "the audio half of a linked insert lost its name again (P7: it is named like the picture half)"
3472 );
3473 assert!(
3474 bench.contains("stem(&s.path)") && !bench.contains("file_name(&s.path)"),
3475 "a name plate shows the file's extension again"
3476 );
3477 let stance = src_text("ui/stance.rs");
3478 // Project identity and the save state moved from the status bar to the
3479 // menu bar (DESIGN §6.9), which keeps the same one-stem, one-door rule.
3480 let menubar = src_text("ui/menubar.rs");
3481 assert!(
3482 menubar.contains("stem(&player.project_path)"),
3483 "the menu bar shows the project's extension again"
3484 );
3485 assert!(
3486 menubar.contains("ActionId::Save"),
3487 "the menu bar's unsaved state is no longer Save's door"
3488 );
3489 // The close request is intercepted and routed through the predicate, and
3490 // the plate it raises is answered: this repo can build no window in a
3491 // test ([`Player`] needs a `TestAppContext`), so the wiring itself is
3492 // what is guarded -- the hook, the rule it asks, and the three answers.
3493 let main = src_text("main.rs");
3494 assert!(
3495 main.contains("on_window_should_close") && main.contains("close_needs_answer()"),
3496 "alt+F4 closes the window without asking about unsaved work"
3497 );
3498 assert!(
3499 stance.contains("if this.quit_ask {")
3500 && stance.contains("if this.save_project(cx) {")
3501 && stance.contains("window.remove_window()"),
3502 "the unsaved plate is up with no key answering it"
3503 );
3504 let popup = src_text("ui/popup.rs");
3505 assert!(
3506 popup.contains("fn unsaved_dialog(") && popup.contains("Save changes to {name}?") && popup.contains("Don't save"),
3507 "the unsaved prompt is no longer a dialog"
3508 );
3509 // The overwrite guard (user 2026-09-11: saving over an existing file
3510 // must warn first, same pattern as the exit guard): Save no longer
3511 // writes through the action directly -- it routes through the guarded
3512 // door, which raises the plate with the target's own name, and the
3513 // plate is answered by its own key block beside the quit plate's.
3514 let actions = src_text("player/actions.rs");
3515 assert!(
3516 actions.contains("ActionId::Save => self.save_guarded(cx)")
3517 && !actions.contains("ActionId::Save => self.save_project(cx)"),
3518 "^s overwrites a foreign .edith without asking"
3519 );
3520 assert!(
3521 stance.contains("if this.save_ask {") && popup.contains("fn overwrite_dialog("),
3522 "the overwrite plate is up with no key answering it"
3523 );
3524 assert!(
3525 !src_text("ui/timeband_stance.rs").contains("ActionId::Save"),
3526 "Save has two doors: the ledger's state word and the time band's ghost"
3527 );
3528 // The helper itself, since three surfaces read one file's name through
3529 // it: a plain name loses its extension, a name with none is itself, and
3530 // a path with no name at all still reads as something.
3531 use crate::files::{file_name, stem};
3532 use std::path::Path;
3533 assert_eq!(
3534 stem(Path::new("/x/he_is_not_the_only_one.mp4")),
3535 "he_is_not_the_only_one"
3536 );
3537 assert_eq!(stem(Path::new("/x/untitled")), "untitled");
3538 assert_eq!(stem(Path::new("/x/a.b.edith")), "a.b");
3539 assert_eq!(stem(Path::new("/")), file_name(Path::new("/")));
3540}
3541
3542/// DESIGN §4/§5: the hero timecode leads the time band and the ledger carries
3543/// position. The ruler's left plate was a third resting copy of the same
3544/// reading -- it stays only for the state change it belongs to, a live scrub.
3545#[test]
3546fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() {
3547 let bench = src_text("ui/bench_stance");
3548 let at = bench
3549 .find(".child(playhead_tc)")
3550 .expect("no playhead timecode in the ruler");
3551 let before = &bench[..at];
3552 let guard = before
3553 .rfind(".when(player.scrubbing")
3554 .expect("the ruler plate draws its timecode at rest -- the third copy");
3555 assert!(
3556 before[guard..].matches(".child(").count() <= 2,
3557 "the scrubbing guard is not the plate's own: {}",
3558 &before[guard..guard + 200]
3559 );
3560 assert!(
3561 bench.contains("let plate_w = if player.scrubbing { PLATE_W } else { 0. };"),
3562 "the ticks still lose the plate's width at rest"
3563 );
3564}
3565
3566/// The band overflowed its own column at 1280x720 (`$EDITH_HITMAP`:
3567/// `action.Export x=1113 w=80` with the column ending at x=995, the contact
3568/// strip measured `w=0`), so the Export chip was invisible under the dock and
3569/// a click on blank dock space at (1130,435) opened the export card. Three
3570/// things hold that shut: the row clips itself, the strip keeps a floor, and
3571/// the ladder sheds groups above it.
3572#[test]
3573fn the_time_band_never_paints_outside_its_own_column() {
3574 let src = src_text("ui/timeband_stance.rs");
3575 let start = src
3576 .find(r#".id("stance-time-band-row")"#)
3577 .expect("the band row");
3578 let row = &src[start
3579 ..start
3580 + src[start..]
3581 .find(".child(timecode_cell)")
3582 .expect("the timecode")];
3583 assert!(
3584 row.contains(".overflow_hidden()"),
3585 "the band row lets its children paint (and be clicked) under the dock: {row}"
3586 );
3587 assert!(
3588 src.contains(".id(\"stance-transport\")") && src.contains(".id(\"stance-tail\")"),
3589 "the transport group is the flex_1 that centres the glyphs; Loop, volume and Mute close the row"
3590 );
3591}
3592
3593/// DESIGN §7's ladder, cleanse round 2 (2026-09-10): the band is five
3594/// things -- timecode, the three transport glyphs, the odometer, the contact
3595/// strip and Export -- and the only sheddable layer left is the chord row
3596/// under the glyphs. This pins the one threshold (measured in the harness:
3597/// 454px of fixed groups + the strip's old 120px floor, rounded up -- a 640x600 window
3598/// reads 539px of band and draws no chords, a 1280x720 one reads 982px and
3599/// draws them) and that it never comes back off.
3600#[test]
3601fn the_band_sheds_its_chords_and_nothing_else() {
3602 use crate::ui::timeband_stance::band_layers;
3603 assert_eq!(
3604 [2000., 982., 580., 579., 539., 0.].map(|w| band_layers(w).chords),
3605 [true, true, true, false, false, false],
3606 "the band's one rung is the chord row at 580px"
3607 );
3608 // Monotone: a wider band never shows less than a narrower one.
3609 let mut prev = band_layers(0.);
3610 for w in (0..2400).step_by(10).map(|w| w as f32) {
3611 let now = band_layers(w);
3612 assert!(now.chords || !prev.chords, "layer came back off at {w}px");
3613 prev = now;
3614 }
3615}
3616
3617/// Every door in this band is at least `HIT_MIN` wide and tall (WCAG 2.5.8).
3618/// The hitmap read `SetIn w=8`, `VolumeDown w=12`, `Loop w=13`, `SetOut w=15`,
3619/// `Prev/NextSyncPoint w=16` before this: padding on the shared `ghost`, not a
3620/// bigger glyph. Those five glyphs left the band in cleanse round 2; the
3621/// three that stayed are drawn by the same `ghost`, so the floor is still
3622/// checked where it is spent.
3623#[test]
3624fn every_ghost_in_the_time_band_carries_a_full_hit_area() {
3625 let src = src_text("ui/timeband_stance.rs");
3626 let start = src.find("fn icon_button(").expect("the band's icon button");
3627 let button = &src[start..start + src[start..].find("\n}\n").expect("its end")];
3628 // A Large button is 32px square: a full hit area.
3629 assert!(button.contains("ButtonSize::Large"), "the band's icon button shrank: {button}");
3630 const {
3631 assert!(HIT_MIN >= 24.);
3632 }
3633}
3634
3635/// Mute wore `"{volume}%"` as its glyph while the slider beside it drew the
3636/// same value: one number, two places. The slider is back on the band (DESIGN
3637/// §6.3) and the UX audit (U-12) asked for its value beside it: the band
3638/// writes the level exactly once, in its own `volume_value`, and never as
3639/// Mute's word again.
3640#[test]
3641fn the_band_writes_the_monitoring_level_once_beside_its_slider() {
3642 let src = src_text("ui/timeband_stance.rs");
3643 assert_eq!(
3644 src.matches("player.volume.percent()").count(),
3645 1,
3646 "the level is written once, in the slider's tooltip"
3647 );
3648 assert!(!src.contains("fn volume_value("), "the % number is back beside the slider");
3649 assert!(
3650 src.contains("if player.volume.muted { Icon::VolumeX } else { Icon::Volume2 }"),
3651 "Mute swaps its icon with its state"
3652 );
3653}
3654
3655/// `Play` and `StepForward` drew the same solid right-triangle: two verbs one
3656/// shape, told apart only by their chords. Step wears the frame-step pair.
3657#[test]
3658fn transport_verbs_differ_by_shape_not_only_by_chord() {
3659 let src = src_text("ui/timeband_stance.rs");
3660 let glyph = |action: &str| {
3661 let at = src.find(&format!("ActionId::{action},")).expect("the call");
3662 src[..at].rsplit('"').nth(1).expect("its glyph").to_string()
3663 };
3664 // Cleanse round 2: the shuttle pair left the band, so the three that
3665 // stayed are what must still differ by shape.
3666 let shapes = ["Play", "StepBack", "StepForward"].map(glyph);
3667 let mut seen = shapes.to_vec();
3668 seen.sort();
3669 seen.dedup();
3670 assert_eq!(
3671 seen.len(),
3672 shapes.len(),
3673 "two transport verbs share one glyph: {shapes:?}"
3674 );
3675}
3676
3677/// The band's odometer is gone (DESIGN §6.3: hero timecode, transport, then
3678/// Loop, volume and Mute). Its cut count stayed off the band only while the
3679/// trim readout is armed, so it must not sneak back into the source.
3680#[test]
3681fn the_band_has_no_cut_odometer() {
3682 let src = src_text("ui/timeband_stance.rs");
3683 for gone in ["odometer", "cut_readout", "stance-cut-readout"] {
3684 assert!(
3685 !src.contains(gone),
3686 "the odometer is back in the time band: {gone}"
3687 );
3688 }
3689}
3690
3691/// DESIGN §6.3: "Right: Loop, and a volume slider." Mute sits after the slider
3692/// (its glyph shows the state beside the level it returns to), and the trim
3693/// readout is the only thing that may join the group, and only while armed.
3694#[test]
3695fn the_transport_closes_with_loop_volume_and_mute() {
3696 let src = src_text("ui/timeband_stance.rs");
3697 let at = |needle: &str| {
3698 src.find(needle)
3699 .unwrap_or_else(|| panic!("the band lost {needle}"))
3700 };
3701 let (loop_at, tail, mute_at, volume_at) = (
3702 at(r#""stance-tb-loop""#),
3703 at(r#".id("stance-tail")"#),
3704 at(r#""stance-tb-mute""#),
3705 at(".child(volume_slider(player, cx))"),
3706 );
3707 assert!(
3708 loop_at < tail && tail < mute_at && mute_at < volume_at,
3709 "the transport closes with Loop, then the tail reads Mute, volume"
3710 );
3711 // The trim line is read by the status strip, not the band: the band never changes while a
3712 // trim is in hand.
3713 assert!(
3714 !src.contains("trim_readout(player)"),
3715 "the trim readout must not sit in the transport band"
3716 );
3717 let ledger = src_text("ui/stance.rs");
3718 assert!(
3719 ledger.contains("trim_text(player)") && ledger.contains("trim_in_flight(player)"),
3720 "the trim line must replace the status strip's readout while a trim is armed or in hand"
3721 );
3722}
3723
3724/// DESIGN §8's rejected pattern, swept over the source rather than argued
3725/// per message: "the room never explains itself in prose ... any new string
3726/// over ~4 words that instructs rather than reports state is a defect". The
3727/// notices are what the ledger strip paints, and a sentence there is what cut
3728/// mid-word in the user's own screenshot (`OPENED ... 1 subtitle track(s) in `).
3729///
3730/// The scan reads every literal handed to a notice constructor, found by its
3731/// *call site* and not by its shape: the head of a composed refusal is the
3732/// verb's own label ("Delete — click a clip first", seen live 2026-09-09), so
3733/// a caps-headed filter walked past every one of them. Any imperative tell in
3734/// such a literal is a defect at any length. A refusal *claim* may still be
3735/// long: those are the allowlist below, each one naming a genuine absent
3736/// capability, never a lesson in how to use the room.
3737#[test]
3738fn no_notice_teaches_the_room_in_prose() {
3739 // Long refusal claims that report a capability genuinely absent from this
3740 // machine (DESIGN §8, "a refusal string is a claim"), kept whole on
3741 // purpose: the remedy is not a chord in this room because the missing
3742 // thing is not in this room.
3743 // The source preview's one line says what it is and the one way to use it.
3744 const ALLOWED: &[&str] = &[
3745 "No file chooser",
3746 "No file dialog",
3747 "No folder dialog",
3748 "Previewing {}. Drag it onto the timeline to use it.",
3749 // The one wording the path sheet's empty paste is asked to use.
3750 "Copy a file's path first",
3751 // The reason Zoom to selection gives with nothing selected, as the feature asks for it.
3752 "Select a clip first",
3753 // The reason Mark the beats gives on a picture-only clip, as the feature asks for it.
3754 "Pick a clip with sound",
3755 ];
3756 const TELLS: &[&str] = &[
3757 "drag ",
3758 "press ",
3759 "pick ",
3760 "type ",
3761 "click ",
3762 "to show",
3763 "to use",
3764 "takes it back",
3765 "puts it back",
3766 " first",
3767 ];
3768 let mut offenders = Vec::new();
3769 for path in source_files() {
3770 let text = std::fs::read_to_string(&path).expect("a source file");
3771 for literal in notice_literals(&text) {
3772 if ALLOWED.iter().any(|allowed| literal.contains(allowed)) {
3773 continue;
3774 }
3775 let lower = literal.to_lowercase();
3776 if TELLS.iter().any(|tell| lower.contains(tell)) {
3777 offenders.push(format!("{}: {literal}", path.display()));
3778 }
3779 }
3780 }
3781 assert!(
3782 offenders.is_empty(),
3783 "a notice that instructs instead of reporting state (DESIGN §8):\n{}",
3784 offenders.join("\n")
3785 );
3786}
3787
3788/// Every string literal that reaches the user as a notice: the arguments of
3789/// the doors a message comes through -- the queue's own two, and the oracle's
3790/// refusal words, which the dispatch pastes behind an action label
3791/// ([`crate::player::actions`]). Reading the call site rather than the string
3792/// is the point: a message's case says nothing about whether it teaches.
3793fn notice_literals(text: &str) -> Vec<String> {
3794 const CALLS: &[&str] = &[
3795 "notify_user(",
3796 "push_notice(",
3797 "Enable::No(",
3798 "Enable::Hidden(",
3799 ];
3800 let code: String = text
3801 .lines()
3802 .filter(|line| !line.trim_start().starts_with("//"))
3803 .collect::<Vec<_>>()
3804 .join("\n");
3805 let mut out = Vec::new();
3806 for call in CALLS {
3807 for (at, _) in code.match_indices(call) {
3808 let open = at + call.len();
3809 // The call's own argument list, to its matching paren: a literal
3810 // written two lines below the opening one is still this call's.
3811 let mut depth = 1usize;
3812 let mut in_string = false;
3813 let mut escaped = false;
3814 let mut end = open;
3815 for (offset, c) in code[open..].char_indices() {
3816 end = open + offset;
3817 match (in_string, c) {
3818 (true, '\\') => escaped = !escaped,
3819 (true, '"') if !escaped => in_string = false,
3820 (true, _) => escaped = false,
3821 (false, '"') => in_string = true,
3822 (false, '(') => depth += 1,
3823 (false, ')') => {
3824 depth -= 1;
3825 if depth == 0 {
3826 break;
3827 }
3828 }
3829 _ => {}
3830 }
3831 }
3832 out.extend(string_literals(&code[open..end]));
3833 }
3834 }
3835 out
3836}
3837
3838/// Every string literal in `text`, comments dropped first so the prose about
3839/// a message is never read as the message.
3840fn string_literals(text: &str) -> Vec<String> {
3841 let code: String = text
3842 .lines()
3843 .filter(|line| !line.trim_start().starts_with("//"))
3844 .collect::<Vec<_>>()
3845 .join("\n");
3846 let mut out = Vec::new();
3847 let mut chars = code.chars().peekable();
3848 while let Some(c) = chars.next() {
3849 if c != '"' {
3850 continue;
3851 }
3852 let mut literal = String::new();
3853 while let Some(c) = chars.next() {
3854 match c {
3855 // A line continuation joins the halves of a wrapped message;
3856 // every other escape is not a word either way.
3857 '\\' => {
3858 if chars.next() == Some('\n') {
3859 while chars.peek() == Some(&' ') {
3860 chars.next();
3861 }
3862 }
3863 }
3864 '"' => break,
3865 _ => literal.push(c),
3866 }
3867 }
3868 out.push(literal);
3869 }
3870 out
3871}
3872
3873/// The Picture list holds the nine files in one order -- a codec's two boxes side by side,
3874/// the sound-only formats last.
3875#[test]
3876fn the_picture_list_pairs_codec_and_container() {
3877 use crate::ui::settings_stance::{PICTURE_CYCLE, picture_label};
3878 assert_eq!(
3879 PICTURE_CYCLE,
3880 [
3881 Format::Mp4,
3882 Format::Av1Mp4,
3883 Format::Av1,
3884 Format::Hevc,
3885 Format::HevcMp4,
3886 Format::Wav,
3887 Format::Flac,
3888 Format::Mp3,
3889 Format::Ogg,
3890 Format::Opus,
3891 ]
3892 );
3893 assert_eq!(picture_label(Format::Mp4), "H.264 · MP4");
3894 assert_eq!(picture_label(Format::Av1), "AV1 · MKV");
3895 assert_eq!(picture_label(Format::Av1Mp4), "AV1 · MP4");
3896 assert_eq!(picture_label(Format::Wav), "WAV");
3897}
3898
3899/// A refused codec is greyed with its reason, never hidden (DESIGN §8), and
3900/// the reason is short enough to sit beside a value: six words, the rest of
3901/// the sentence still said by the export moment's own banner. The sound row
3902/// wears a chord only where its codec has a rate to step.
3903#[test]
3904fn a_refusal_is_six_words_beside_the_value_and_soundless_codecs_wear_no_chord() {
3905 use crate::ui::settings_stance::short_reason;
3906 let long = "HEVC needs the VA-API plugin, which this machine has not built";
3907 assert_eq!(short_reason(long), "HEVC needs the VA-API plugin, which");
3908 assert!(short_reason(long).split_whitespace().count() <= 6);
3909 assert_eq!(short_reason("no encoder here"), "no encoder here");
3910}
3911
3912/// Every control the hitmap names wears a hover line (the user, 2026-09-09,
3913/// over a screenshot of the time band: "each and every button needs hover
3914/// over information ... I don't know some of them"). The hitmap already
3915/// carries the pair a plate needs -- an id and a label -- so the sweep walks
3916/// the same emitters: a builder chain that records a control and never calls
3917/// `.tooltip` is a glyph the user cannot name.
3918///
3919/// A scan and not a render: this crate has no gpui window in its tests, so
3920/// the text is the finest grain available. Each emitter must claim a
3921/// `.tooltip(` of *its own* within [`REACH`] lines -- one to one, nearest
3922/// first. Counting them per function instead let an unrelated plate (the
3923/// empty-dock hint) pay for a control that had none: `dock.sort.cycle` sat
3924/// bare under a green gate until this pairing was written.
3925///
3926/// Controls outside the hitmap are outside this gate by charter. Named for
3927/// the record, since each is a control the pointer can press: a card's own
3928/// picker rows (colour/transform/mix/subtitle/silence bands, the speed
3929/// chips) and the two menus' rows, all of which already read as
3930/// `<label> <value-or-chord>` on the row itself -- a plate would repeat the
3931/// row it hangs off, which is DESIGN §8's prose rule the other way round.
3932#[test]
3933fn every_hitmap_control_wears_a_hover_line() {
3934 /// How far from a control's `hitmap::` line its plate may be attached.
3935 /// A builder chain runs long here (the contact strip's tooltip sits 65
3936 /// lines above its emitter), so the reach is generous; what it buys is
3937 /// that a plate can be spent only once.
3938 const REACH: usize = 80;
3939 // Ids that name a control a *previous* emitter in the same chain already
3940 // plated -- the second id is the harness's aim point, not a second
3941 // control -- with the reason each is exempt.
3942 const DOUBLE_NAMED: &[&str] = &[
3943 // `subtitle.N.M.row` and `subtitle.N.M.select` are one row.
3944 ".select\")",
3945 ];
3946 let mut controls = 0;
3947 let mut naked = Vec::new();
3948 for path in source_files() {
3949 let text = std::fs::read_to_string(&path).expect("a source file");
3950 if !text.contains("hitmap::") {
3951 continue;
3952 }
3953 let file = path
3954 .file_name()
3955 .and_then(|n| n.to_str())
3956 .expect("a file name")
3957 .to_string();
3958 let lines: Vec<&str> = text.lines().collect();
3959 let mut tips: Vec<(usize, bool)> = lines
3960 .iter()
3961 .enumerate()
3962 .filter(|(_, l)| l.contains(".tooltip("))
3963 .map(|(i, _)| (i, false))
3964 .collect();
3965 for (i, line) in lines.iter().enumerate() {
3966 let emitter = ["hitmap::control(", "hitmap::dynamic(", "hitmap::action("]
3967 .iter()
3968 .any(|needle| line.contains(needle));
3969 if !emitter {
3970 continue;
3971 }
3972 // The id a `dynamic` builds sits a line or three below its call.
3973 let head = lines[i..(i + 6).min(lines.len())].join("\n");
3974 if DOUBLE_NAMED.iter().any(|id| head.contains(id)) {
3975 continue;
3976 }
3977 controls += 1;
3978 let mut free: Vec<usize> = (0..tips.len())
3979 .filter(|n| !tips[*n].1 && tips[*n].0.abs_diff(i) <= REACH)
3980 .collect();
3981 free.sort_by_key(|n| tips[*n].0.abs_diff(i));
3982 match free.first() {
3983 Some(n) => tips[*n].1 = true,
3984 // Clips and subtitles carry no tooltip on purpose: the status bar
3985 // reads the drag hint under the pointer instead. An empty lane bed
3986 // carries none either: its drop highlight is its feedback.
3987 None if file == "clip.rs" || file == "sub.rs" || head.contains(".bed\"") => {}
3988 None => naked.push(format!("{file}:{}: {}", i + 1, line.trim())),
3989 }
3990 }
3991 }
3992 // The floor moved 40 -> 34 with cleanse round 2 (2026-09-10): the band lost its
3993 // shuttle/marks/monitoring cluster, the bench its head verbs and `all`, and the dock
3994 // gave up five named controls in one diff (the three sub-tabs, the sort
3995 // cycle, the row's preview and stand-in ghosts, against one Add row kept)
3996 // and a floor above the true count is a red gate, not a blindness check.
3997 assert!(
3998 controls >= 34,
3999 "the hover sweep found only {controls} controls -- it has gone blind"
4000 );
4001 assert!(
4002 naked.is_empty(),
4003 "controls with no hover line of their own (attach \
4004 `widgets::tip_hover`/`action_hover` in the chain that emits the \
4005 hitmap id): {naked:#?}"
4006 );
4007}
4008
4009/// The one hover shape for the whole room: `<name> · <chord>`, and a control
4010/// the state refuses says why instead of naming a stroke that will not fire
4011/// (DESIGN §4/§8 -- a tooltip is not a sentence).
4012#[test]
4013fn a_hover_line_is_a_name_and_a_chord() {
4014 use crate::ui::widgets::tip_line;
4015 assert_eq!(
4016 tip_line("One frame forward", "right", None),
4017 "One frame forward · right"
4018 );
4019 assert_eq!(
4020 tip_line("Split", "s", Some("nothing selected")),
4021 "Split · nothing selected"
4022 );
4023 // `Keymap::chord`'s unbound badge is not a stroke.
4024 assert_eq!(tip_line("Add files", "--", None), "Add files");
4025 assert_eq!(tip_line("Source", "", None), "Source");
4026}
4027
4028/// A region is a place, not a control: none of the region roots paints a
4029/// border because it holds focus (user 2026-09-10, "clicking through
4030/// timeline draws a white overlay around the timeline"; DESIGN §4's ring
4031/// line is about the *selected thing*). Focus routing itself is untouched.
4032#[test]
4033fn no_region_root_wears_a_focus_ring() {
4034 let stance = src_text("ui/stance.rs");
4035 let bench = src_text("ui/bench_stance");
4036 let band = src_text("ui/timeband_stance.rs");
4037 for (name, text) in [
4038 ("stance.rs", &stance),
4039 ("bench_stance.rs", &bench),
4040 ("timeband_stance.rs", &band),
4041 ] {
4042 for line in text.lines() {
4043 let code = line.trim_start();
4044 if code.starts_with("//") {
4045 continue;
4046 }
4047 assert!(
4048 !(code.contains("is_focused(") || code.contains("when(focused"))
4049 || !code.contains("border"),
4050 "{name} still paints a focus-conditional border: {code}"
4051 );
4052 assert!(
4053 !code.contains("STROKE_FOCUS"),
4054 "{name} paints the focus stroke on a region: {code}"
4055 );
4056 }
4057 }
4058}
4059
4060/// The user could not find the three columns (2026-09-10: "I couldn't realize
4061/// them when I look at"), because their heads were 12px `ink3` -- the room's
4062/// quietest type -- with a prose tail running on after each one. The page's
4063/// answer has since become a tab strip (user 2026-09-19): three columns at
4064/// once asked the eye to find three anchors in one glance and then to read a
4065/// column that began mid-screen. The pin moved with the page: the sections are
4066/// tabs now, each tab wears the dock's own tab look -- [`crate::ui::dock_stance`]'s
4067/// `dock_tab`, reproduced here because that fn is private to its module -- and
4068/// each section's one-line explanation rides the tab's hover plate
4069/// (DESIGN §8), never running on after a head as ambient text.
4070#[test]
4071fn the_settings_sections_are_tabs_that_carry_their_own_explanation() {
4072 let source = src_text("ui/settings_stance.rs");
4073 let start = source.find("fn settings_tab(").expect("the tab builder");
4074 let body = &source[start..source[start..].find("\n}\n").unwrap() + start];
4075 // The dock's own tab look: no pill, no fill; a 1px `ink1` top rule and
4076 // `ink1` text mark the showing tab, the resting one is `ink3`. Every tab
4077 // is a `hitmap::control` wearing a plate of its own (the hover-line gate
4078 // below counts the plates one to one).
4079 for needle in [
4080 "type_scale::body()",
4081 "border_b_2()",
4082 "tokens().ink1",
4083 "tokens().ink2",
4084 ".cursor_pointer()",
4085 ".tooltip(",
4086 "hitmap::control(",
4087 ] {
4088 assert!(body.contains(needle), "a settings tab lost {needle}");
4089 }
4090 assert!(
4091 !body.contains("type_scale::head()"),
4092 "the settings tabs fell back to the 12px in-list section head"
4093 );
4094 // Three tabs, one per section, named the way the room names the section.
4095 for tab in ["project", "editor", "keys"] {
4096 assert!(
4097 source.contains(&format!("\"settings-tab-{tab}\"")),
4098 "the settings strip has no {tab} tab"
4099 );
4100 }
4101 // Each section's one-line explanation is the tab's plate now.
4102 for explanation in [
4103 "stored in the .edith file",
4104 "this machine, this window",
4105 "every shortcut, and how to rebind it",
4106 ] {
4107 assert!(
4108 source.contains(explanation),
4109 "a settings tab lost its explanation: {explanation}"
4110 );
4111 }
4112 // ...and none of them runs on after a head as ambient text.
4113 for run_on in ["Project \u{b7}", "Editor \u{b7}", "Export \u{b7}"] {
4114 assert!(
4115 !source.contains(run_on),
4116 "a settings head grew its prose tail back: {run_on}"
4117 );
4118 }
4119 // One section shows at a time: the plate mounts the showing tab's own
4120 // section and nothing else -- a page that drew all three under the strip
4121 // would be the three columns back with the strip doing nothing.
4122 for (tab, section) in [
4123 ("SettingsTab::Project", "project_section(player, cx)"),
4124 ("SettingsTab::Editor", "editor_section(player, cx)"),
4125 ] {
4126 assert!(
4127 source.contains(&format!("{tab} => {section}")),
4128 "the {tab} tab no longer shows {section}"
4129 );
4130 }
4131}
4132
4133/// The page's own geometry, after the user retired the below-picture sheet
4134/// (2026-09-19: "this settings section should be a modal instead of covering
4135/// the timeline"). The page is a centred modal now -- a centred scrim and a
4136/// plate of one tabbed column's own measure, never `w_full()`, which put a
4137/// `justify_between` row's value a window away from its label, and never the
4138/// [`crate::ui::stance::below_picture_floor`] anchor that laid the sheet over
4139/// the bench at the window's full width. The height is a viewport cap with
4140/// headroom, the rows scroll under the strip when a short window cannot hold
4141/// them, and the modal keeps the two things its callers read: the
4142/// `settings-card` id and the press-away exit (`this.close_card()`, the same
4143/// one every other card's scrim leads with). A source scan, like every other
4144/// guard on this page -- this binary renders no window of its own.
4145#[test]
4146fn the_settings_page_is_a_centred_modal_with_one_column_of_measure() {
4147 let source = src_text("ui/settings_stance.rs");
4148 let start = source
4149 .find("pub(crate) fn render(")
4150 .expect("the page's render fn");
4151 let body = &source[start..];
4152 let end = body.find("\n}\n").map_or(body.len(), |at| at + 2);
4153 let body = &body[..end];
4154
4155 // Centred on both axes, and the below-picture sheet gone with the rest
4156 // of it: no floor arithmetic, no bottom-edge alignment, no full-width
4157 // plate.
4158 // (The kit dialog shell centres it on both axes.)
4159 for needle in ["kit::dialog_layer(", "kit::dialog(\"settings-card\""] {
4160 assert!(body.contains(needle), "the settings modal lost {needle}");
4161 }
4162 for gone in ["below_picture_floor", "items_end()", "w_full()"] {
4163 assert!(
4164 !body.contains(gone),
4165 "the settings page drew {gone} again -- that is the below-picture sheet, \
4166 not the centred modal the user asked for"
4167 );
4168 }
4169 // The plate: one column's own measure with its yield for a narrow centre
4170 // column, a capped height, and the rows scrolled inside the cap.
4171 for needle in [
4172 "\"settings-card\"",
4173 "SETTINGS_W",
4174 ".max_w(relative(1.))",
4175 "\"settings-rows\"",
4176 "overflow_y_scroll()",
4177 "more_below(",
4178 ] {
4179 assert!(
4180 body.contains(needle),
4181 "the settings modal lost {needle} -- the plate is no longer one capped \
4182 column with its rows scrolling"
4183 );
4184 }
4185 // One measure for every tab (user 2026-09-20: "switching between them
4186 // feels weird" -- the plate hugged its rows, so PROJECT's seven and
4187 // EXPORT's four resized it under the hand). The rows area wears the
4188 // tallest section's fixed height, and that height is PROJECT's own
4189 // arithmetic: count the section's rows out of its body rather than
4190 // trusting the constant's comment.
4191 assert!(
4192 body.contains(".h(px(rows_h))"),
4193 "the settings rows lost their fixed measure -- a tab switch resizes the plate again"
4194 );
4195 let project = &source[source
4196 .find("fn project_section(")
4197 .expect("the PROJECT section")..];
4198 let project = &project[..project.find("\n}\n").map_or(project.len(), |at| at + 2)];
4199 assert_eq!(
4200 project.matches("saved_line(").count(),
4201 1,
4202 "the PROJECT section no longer ends on its storage line"
4203 );
4204 // PROJECT at its tallest: three list rows, the HDR row and its two-line
4205 // hint, both switches and the storage line.
4206 let tallest = 7. * CONTROL_H + 36. + 7. * 2.;
4207 assert!(
4208 crate::ui::settings_stance::SETTINGS_ROWS_H >= tallest,
4209 "SETTINGS_ROWS_H no longer holds the PROJECT section"
4210 );
4211 assert!(
4212 body.contains("this.settings_open = false"),
4213 "the settings scrim swallows the press without closing the modal"
4214 );
4215}
4216
4217/// The monitoring level is not a setting: it lives on the transport (slider and mute) and on
4218/// `m` / the volume keys. Settings -> Editor carries no Level row, and the footer note does not
4219/// mention one.
4220#[test]
4221fn the_editor_section_has_no_monitoring_level_row() {
4222 let source = src_text("ui/settings_stance.rs");
4223 let editor_start = source
4224 .find("fn editor_section(")
4225 .expect("the editor section");
4226 let render_start = source
4227 .find("pub(crate) fn render(")
4228 .expect("the page's render fn");
4229 let editor_body = &source[editor_start..render_start];
4230 for needle in ["\"settings-level\"", "\"Level\"", "Level is not saved"] {
4231 assert!(
4232 !editor_body.contains(needle),
4233 "the EDITOR section grew the monitoring level back ({needle})"
4234 );
4235 }
4236}
4237
4238/// The wheel's own arithmetic: one notch is one key press (5%), and the count
4239/// stops at both ends rather than wrapping silence into full volume -- the
4240/// saturating pair [`Volume::step`] is written for. Pure, so it runs without
4241/// a window.
4242#[test]
4243fn the_level_wheel_steps_five_percent_and_clamps_at_both_ends() {
4244 use crate::transport::Volume;
4245 let mut volume = Volume::default();
4246 assert_eq!(volume.percent(), 100);
4247 for expected in [95, 90, 85, 80] {
4248 volume.step(false);
4249 assert_eq!(volume.percent(), expected, "a notch down is 5%");
4250 }
4251 for _ in 0..40 {
4252 volume.step(false);
4253 }
4254 assert_eq!(volume.percent(), 0, "the level floors at silence");
4255 volume.step(false);
4256 assert_eq!(volume.percent(), 0, "a notch below silence is silence");
4257 for _ in 0..40 {
4258 volume.step(true);
4259 }
4260 assert_eq!(volume.percent(), 100, "the level ceilings at full");
4261 volume.step(true);
4262 assert_eq!(volume.percent(), 100, "a notch above full is full");
4263 // Turning it down while muted is not what makes sound come out.
4264 volume.muted = true;
4265 volume.step(false);
4266 assert!(volume.muted && volume.percent() == 95);
4267}
4268
4269/// The type twin of `no_colour_is_written_outside_the_theme`: DESIGN §2.4
4270/// sets 12px as the floor, and `ui::type_scale` is where that floor lives.
4271/// A literal size under it written at a call site is a size the next type
4272/// sweep will not see -- how 9px and 10.5px text reached the preview's
4273/// labels and 11px reached the menus. Every literal is read in both forms a
4274/// call site writes one: `text_size(px(N))`, and `label(N, ..)` / `mono(N, ..)`
4275/// taking it as the first argument.
4276#[test]
4277fn no_ui_text_is_set_literally_below_the_floor() {
4278 const FLOOR: f32 = 12.;
4279 let source = ui_source();
4280 assert!(
4281 source.matches("text_size(").count() >= 20,
4282 "the text-size call sites moved; this scan is blind"
4283 );
4284
4285 let mut stray = Vec::new();
4286 for needle in ["text_size(px(", "label(", "mono("] {
4287 for (at, _) in source.match_indices(needle) {
4288 let prev = source[..at].chars().next_back();
4289 let ident_before = prev.is_some_and(|c| c.is_alphanumeric() || c == '_');
4290 if needle != "text_size(px(" && ident_before {
4291 continue;
4292 }
4293 let literal: String = source[at + needle.len()..]
4294 .trim_start()
4295 .chars()
4296 .take_while(|c| c.is_ascii_digit() || *c == '.')
4297 .collect();
4298 if let Ok(size) = literal.parse::<f32>()
4299 && size < FLOOR
4300 {
4301 stray.push(format!("{needle}{literal}"));
4302 }
4303 }
4304 }
4305 assert!(
4306 stray.is_empty(),
4307 "literal text size(s) under DESIGN §2.4's {FLOOR}px floor: {stray:?}"
4308 );
4309}
4310
4311/// DESIGN §2.3 and §4: every family is held to the same floor on every surface
4312/// a line of text can sit on. INK3 is the tertiary tier -- labels, keys and
4313/// metadata -- so it has to be legible too, and it has to be its own colour:
4314/// a family whose INK3 aliased INK4 would put the disabled grey on information.
4315#[test]
4316fn every_palette_has_three_legible_inks_on_every_surface() {
4317 for id in crate::ui::theme::PaletteId::ALL {
4318 let p = id.palette();
4319 for (name, ink) in [("ink1", p.INK1), ("ink2", p.INK2), ("ink3", p.INK3)] {
4320 for (surface, bg) in [
4321 ("canvas", p.DARK_CANVAS),
4322 ("panel", p.DARK_PANEL),
4323 ("raised", p.DARK_RAISED),
4324 ] {
4325 assert!(
4326 contrast(ink, bg) >= 4.5,
4327 "{id:?} {name} on {surface}: {:.2}",
4328 contrast(ink, bg)
4329 );
4330 }
4331 }
4332 assert_ne!(p.INK3, p.INK4, "{id:?}: INK3 aliases the disabled ink");
4333 assert_ne!(p.INK3, p.INK2, "{id:?}: INK3 aliases the secondary ink");
4334 }
4335}
4336
4337/// DESIGN §2.1 is the mock's numbers, and the default is the mock's room: a
4338/// fresh install opens on it. A saved pick still wins, since `load` only falls
4339/// back to the default when there is nothing to read.
4340#[test]
4341fn darkroom_is_the_default_and_matches_design_2_1() {
4342 use crate::ui::theme::{PaletteId, darkroom};
4343 assert_eq!(PaletteId::DEFAULT, PaletteId::Darkroom);
4344 assert_eq!(darkroom::BG_CANVAS, 0x0b0c0e);
4345 assert_eq!(darkroom::BG_PANEL, 0x131518);
4346 assert_eq!(darkroom::BG_RAISED, 0x1b1e22);
4347 assert_eq!(darkroom::BG_HOVER, 0x24282d);
4348 assert_eq!(darkroom::STROKE_DIVIDER, 0x2a2e34);
4349 assert_eq!(darkroom::INK1, 0xe8eaed);
4350 assert_eq!(darkroom::INK2, 0xb4bac1);
4351 assert_eq!(darkroom::INK3, 0x8d959e);
4352 assert_eq!(darkroom::INK4, 0x777f88);
4353 assert_eq!(darkroom::NOTICE_LOOK, 0xd1b564);
4354 assert_eq!(darkroom::NOTICE_DECIDE, 0xe07a7a);
4355}
4356
4357/// DESIGN §4.3 and §4.10: the hit sizes a hand is given. A trim zone is 24 px
4358/// centred on its edge, shrinks inside a short clip so the middle of it stays
4359/// a move target, and gives its outside half to the clip under the pointer
4360/// where two clips meet.
4361#[test]
4362fn a_trim_zone_is_24px_centred_on_the_edge_and_yields_at_a_join() {
4363 use crate::{TRIM_HANDLE, TRIM_REACH, trim_zone};
4364
4365 assert_eq!(2. * TRIM_REACH, HIT_MIN, "24 px, centred on the edge");
4366 const { assert!(TRIM_HANDLE <= TRIM_REACH, "a drawn handle fits in its zone") };
4367 // A long clip with room on both sides: the full reach each way.
4368 assert_eq!(
4369 trim_zone(400., f32::INFINITY),
4370 (TRIM_REACH, TRIM_REACH),
4371 "12 px inside, 12 px outside"
4372 );
4373 // A short clip gives up inside reach, never the middle third of itself.
4374 for width in [18., 24., 36., 47.] {
4375 let (inside, outside) = trim_zone(width, f32::INFINITY);
4376 assert!(inside <= width / 4. + 1e-4, "{width} px: inside {inside}");
4377 assert!(
4378 width - 2. * inside >= width / 3.,
4379 "{width} px leaves no middle third"
4380 );
4381 assert!(inside + outside <= HIT_MIN);
4382 }
4383 assert_eq!(trim_zone(48., f32::INFINITY).0, TRIM_REACH);
4384 // Touching clips: the outside half is nothing, so the join belongs to the
4385 // clip the pointer is on, entirely.
4386 assert_eq!(trim_zone(400., 0.).1, 0.);
4387 // A gap: each side takes half of it, and the two halves meet exactly.
4388 let gap = 10.;
4389 assert_eq!(trim_zone(400., gap).1, gap / 2.);
4390 assert_eq!(trim_zone(400., -3.).1, 0., "an overlap reaches nothing");
4391}
4392
4393#[test]
4394fn a_clip_draws_its_trims_outside_its_clipped_box() {
4395 let src = src_text("ui/bench_stance/clip.rs");
4396 let start = src.find("fn clip_box(").expect("the clip box");
4397 let body = &src[start..start + src[start..].find("\n}\n").expect("its end")];
4398 // The box clips its own contents, so the zones must be siblings of it:
4399 // the body is built first, then the wrapper carries the zones after it.
4400 let boxed = body.find("let body = div()").expect("the box");
4401 assert!(body.find(".overflow_hidden()").expect("clipped") > boxed);
4402 assert!(
4403 body.find(".child(body)").expect("the wrapper") > boxed,
4404 "the zones hang off the wrapper, not the clipped box: {body}"
4405 );
4406 assert!(
4407 body.find("trim_zone(").expect("the zones") > body.find(".child(body)").expect("wrapper"),
4408 "a zone built inside the box would be clipped to its edges"
4409 );
4410 // A selected clip shows its two 12 px handles, and its outline is 2 px.
4411 // (REDESIGN §3.6: 8x20 pills, and the 2px accent outline is an overlay on the wrapper.)
4412 assert!(body.contains(".w(px(8.))") && body.contains(".h(px(20.))"));
4413 assert!(body.contains(".border_2()") && body.contains("tokens().accent"));
4414 // Fades and the dissolve are hit areas of the full 24 px, drawn at 10 px.
4415 assert!(body.matches(".w(px(HIT_MIN))").count() >= 2, "{body}");
4416 assert!(body.contains("FADE_HANDLE_W"));
4417 // Their own hit areas sit above the trim zones, which come first.
4418 assert!(
4419 body.find("trim_zone(").expect("zones") < body.find("bench-clip-fade").expect("fades"),
4420 "a fade must be painted above the trim strip under it"
4421 );
4422 // The subtitle cue's outline matches the clip's.
4423 let sub_src = src_text("ui/bench_stance/sub.rs");
4424 let sub = sub_src.find("fn sub_box(").expect("the subtitle cue");
4425 let sub = &sub_src[sub..sub + sub_src[sub..].find("\n}\n").expect("its end")];
4426 assert!(sub.contains(".border_2()") && sub.contains("tokens().accent"));
4427}
4428
4429/// DESIGN §8: a toast never covers the timeline or the picture. One at a time,
4430/// it lives in the status bar, whose height is fixed.
4431#[test]
4432fn a_toast_lives_in_the_status_bar_and_never_over_the_timeline() {
4433 let text = src_text("ui/stance.rs");
4434 assert!(
4435 !text.contains("fn toast_stack(") && !text.contains("stance-toasts"),
4436 "a floating toast stack is back over the timeline"
4437 );
4438 let at = text.find("fn ledger(").expect("the status bar");
4439 let ledger = &text[at..at + text[at..].find("\n}\n").expect("its end")];
4440 assert!(
4441 ledger.contains("current_toast(&player.notices)") && ledger.contains("toast_card("),
4442 "the status bar must show one toast: the open question, else the newest"
4443 );
4444 assert!(text.contains(".h(px(LEDGER_H - 2.))"), "the toast must fit the bar's height");
4445}
4446
4447#[test]
4448fn ink4_is_only_for_disabled_states() {
4449 // ink4 (`INK4()`, which is `FG_DISABLED`) is for disabled controls only
4450 // (DESIGN §2.1, §4.1). Every use counted here must be a disabled state: a
4451 // blocked export, a refused format's value, an action the room cannot take
4452 // right now. Labels, keys, metadata, hints and empty states are information
4453 // and take INK3(). A new use is a new information-or-disabled decision, so
4454 // check which it is, and only then change the count below.
4455 let mut uses = Vec::new();
4456 for path in source_files() {
4457 if path.file_name() == Some("theme.rs".as_ref()) {
4458 continue;
4459 }
4460 let text = std::fs::read_to_string(&path).expect("a source file");
4461 for (line, code) in text.lines().enumerate() {
4462 if code.contains("INK4()") || code.contains("FG_DISABLED") {
4463 let shown = path.strip_prefix(src_dir()).unwrap_or(&path);
4464 uses.push(format!("{}:{}", shown.display(), line + 1));
4465 }
4466 }
4467 }
4468 // (The bed's gap hatch was the ninth; REDESIGN §3.6 removed every hatch.)
4469 // None remain: P5 moved them to `tokens().ink4`, and the shortcuts sheet (which held the
4470 // last two) now dims a refused row with opacity and gives the reason on hover.
4471 assert_eq!(
4472 uses.len(),
4473 0,
4474 "a new INK4()/FG_DISABLED line must be a disabled control, not information: {uses:#?}"
4475 );
4476}
4477
4478/// A first media into an empty timeline lands and fits (DESIGN §7), by the
4479/// launch argument and by an import alike. The fit is worked out against the
4480/// bed the timeline was painted on, and a bed that has not been painted yet
4481/// has no width to fit into: the fit waits for the first frame that has one
4482/// rather than falling back to the default 60 px/s, which is the screenshot
4483/// that made a 12 s clip fill a third of a 1560 px bed.
4484#[test]
4485fn a_first_media_fits_the_bed_it_is_painted_on_and_waits_for_one_if_unpainted() {
4486 let fit = |bed: f32| {
4487 View {
4488 scale: Scale::default(),
4489 bed,
4490 duration: 12.,
4491 fps: 24.,
4492 }
4493 .fit()
4494 };
4495 let painted = fit(1560.);
4496 assert!(
4497 (painted.pps - 1560. / 12.).abs() < 1e-9 && painted.start == 0.,
4498 "a 12 s edit on a 1560 px bed is 130 px/s from the head, not {painted:?}"
4499 );
4500 assert_eq!(
4501 fit(0.).pps,
4502 PPS_DEFAULT,
4503 "an unpainted bed is the fallback this test exists to keep out of a fit"
4504 );
4505
4506 let view = src_text("player/view.rs");
4507 let zoom = &view[view.find("fn zoom_fit(").expect("zoom_fit")..];
4508 let zoom = &zoom[..zoom.find("\n }\n").expect("zoom_fit body")];
4509 assert!(
4510 zoom.contains("false => self.fit_pending = true"),
4511 "zoom_fit must defer when the bed is unpainted: {zoom}"
4512 );
4513 let render = src_text("render.rs");
4514 let frame = &render[render.find("if self.fit_pending {").expect("render consumes the fit")..];
4515 assert!(
4516 frame.contains("request_animation_frame") && frame.contains("self.fit_pending = false"),
4517 "the deferred fit must be taken on the first measured frame and keep the loop alive until then"
4518 );
4519 let library = src_text("player/library.rs");
4520 let launch = &library[library
4521 .find("Landed::Media(opened, place) => {")
4522 .expect("the launch arm of take_import")..];
4523 let launch = &launch[..launch.find("cx.notify();").expect("arm end")];
4524 assert!(
4525 launch.contains("if place") && launch.contains("self.zoom_fit(cx);"),
4526 "the file argv named must fit when it lands as the timeline: {launch}"
4527 );
4528}
4529
4530/// A fit spreads the whole edit across about 98% of the bed, and the rest is the
4531/// margin (DESIGN §7). The share is read off the source, so the test and the
4532/// fit cannot drift apart.
4533#[test]
4534fn a_fit_leaves_about_two_percent_of_the_bed_as_margin() {
4535 let view = src_text("player/view.rs");
4536 let share: f32 = view
4537 .lines()
4538 .find_map(|line| {
4539 line.strip_prefix("const FIT_SHARE: f32 = ")
4540 .and_then(|rest| rest.strip_suffix(';'))
4541 .and_then(|num| num.parse().ok())
4542 })
4543 .expect("FIT_SHARE is a plain f32 literal");
4544 assert!(
4545 (0.97..=0.99).contains(&share),
4546 "a fit is about 98% of the bed, not {share}"
4547 );
4548 let bed = 1560.;
4549 let fit = View {
4550 scale: Scale::default(),
4551 bed: bed * share,
4552 duration: 12.,
4553 fps: 24.,
4554 }
4555 .fit();
4556 assert!(
4557 (fit.width_px(12.) - bed * share).abs() < 0.5 && fit.start == 0.,
4558 "the whole 12 s edit must end at the margin, 98% of a 1560 px bed: {fit:?}"
4559 );
4560 let fit_to_bed = &view[view.find("fn fit_to_bed(").expect("fit_to_bed")..];
4561 let fit_to_bed = &fit_to_bed[..fit_to_bed.find("\n }\n").expect("fit_to_bed body")];
4562 assert!(
4563 fit_to_bed.contains("bed: view.bed * FIT_SHARE"),
4564 "fit_to_bed must fit into the share of the bed, not the whole bed: {fit_to_bed}"
4565 );
4566}
4567
4568/// A fit stays in force while the bed changes width: the first frame measures
4569/// the initial window size, the compositor then tiles the window, and the next
4570/// frame refits for the new width. A hand's zoom, scroll or thumb drag ends the
4571/// fit, so a resize after one keeps the view the hand chose (DESIGN §7).
4572#[test]
4573fn a_fit_follows_a_resized_bed_until_a_hand_zooms_or_scrolls() {
4574 fn body<'a>(text: &'a str, sig: &str) -> &'a str {
4575 let from = &text[text.find(sig).unwrap_or_else(|| panic!("{sig}"))..];
4576 &from[..from.find("\n }\n").unwrap_or_else(|| panic!("end of {sig}"))]
4577 }
4578 let player = src_text("main.rs");
4579 assert!(
4580 player.contains("fitted_bed: Option<f32>") && player.contains("fitted_bed: None,"),
4581 "Player must hold the bed width of the fit, and start with none"
4582 );
4583
4584 let view = src_text("player/view.rs");
4585 assert!(
4586 body(&view, "fn fit_to_bed(").contains("self.fitted_bed = Some(view.bed);"),
4587 "a fit must record the bed width it was worked out for"
4588 );
4589 let zoom_fit = body(&view, "fn zoom_fit(");
4590 assert!(
4591 zoom_fit.contains("self.fit_to_bed();"),
4592 "zoom_fit must fit through fit_to_bed, so the fit is the sticky one: {zoom_fit}"
4593 );
4594 for sig in ["fn zoom(", "fn scroll_view(", "fn pan_window_to("] {
4595 assert!(
4596 body(&view, sig).contains("self.fitted_bed = None;"),
4597 "{sig} is a hand's view and must end the sticky fit"
4598 );
4599 }
4600 // The thumb and the overview's window box both pan through pan_window_to,
4601 // and a drag holds against the follow the way a scroll does.
4602 assert!(
4603 body(&view, "fn pan_window_to(").contains("self.panned = true;"),
4604 "a window drag must hold the view against the playhead's follow"
4605 );
4606 assert!(
4607 body(&view, "fn scroll_drag_to(").contains("self.pan_window_to("),
4608 "the thumb's drag must pan through the shared door"
4609 );
4610
4611 let render = src_text("render.rs");
4612 let frame = &render[render
4613 .find("if let Some(fitted) = self.fitted_bed {")
4614 .expect("render refits a fit still in force")..];
4615 let frame = &frame[..frame.find("ui::stance::render").expect("render end")];
4616 assert!(
4617 frame.contains("bed != fitted")
4618 && frame.contains("bed > 0.")
4619 && frame.contains("self.fit_to_bed();"),
4620 "render must refit a sticky fit when the bed width differs, and never fit a zero width: \
4621 {frame}"
4622 );
4623}
4624
4625/// An action's hover plate reads its key off the keymap, not off a literal
4626/// written beside the action (DESIGN §4.5): the name, `Keymap::display` as the
4627/// key, and a refused action's reason on its own line.
4628#[test]
4629fn an_action_tooltip_reads_its_key_from_the_keymap() {
4630 use crate::oracle::Enable;
4631 use crate::ui::widgets::action_parts;
4632 let keymap = crate::keymap::Keymap::defaults();
4633 for action in crate::keymap::ActionId::ALL {
4634 let parts = action_parts(&keymap, action, Enable::Yes);
4635 assert_eq!(parts.name.to_string(), action.label());
4636 assert_eq!(
4637 parts.key.map(|k| k.to_string()),
4638 Some(keymap.display(action)),
4639 "{action:?}: the plate's key must be the keymap's own reading"
4640 );
4641 assert_eq!(parts.why, None, "{action:?}: an enabled action gives no reason");
4642 }
4643 let refused = action_parts(
4644 &keymap,
4645 crate::keymap::ActionId::Cut,
4646 Enable::No("Put the playhead over a clip"),
4647 );
4648 assert_eq!(
4649 refused.why.map(|w| w.to_string()),
4650 Some("Put the playhead over a clip".to_string()),
4651 "a refused action's reason is the oracle's, on its own line"
4652 );
4653 assert_eq!(
4654 refused.key.map(|k| k.to_string()),
4655 Some(keymap.display(crate::keymap::ActionId::Cut)),
4656 );
4657 // And the live helper takes its parts from that same keymap, not from a
4658 // second source of its own.
4659 let body = fn_body("action_hover");
4660 assert!(
4661 body.contains("action_parts(&player.keymap, action"),
4662 "action_hover must build its plate from the player's keymap: {body}"
4663 );
4664}
4665
4666/// The edit toolbar keeps DESIGN §6.4's group order, with a hairline rule
4667/// between the groups, and every labelled button reads its key from the
4668/// keymap rather than typing one. The commands must appear in the source in
4669/// that order (a sequential search, so a swap or a missing rule fails), and the
4670/// two helpers that draw a key must take it from `Keymap::display` or from
4671/// `action_hover`, which reads the keymap's chord.
4672#[test]
4673fn the_edit_toolbar_keeps_its_group_order_and_reads_every_key_from_the_keymap() {
4674 let src = src_text("ui/toolbar.rs");
4675 let render = &src[src
4676 .find("pub(crate) fn render(")
4677 .expect("the toolbar's render")..];
4678 let order = [
4679 "ActionId::Cut",
4680 "ActionId::Delete",
4681 "ActionId::Lift",
4682 "rule()",
4683 "ActionId::Undo",
4684 "ActionId::Redo",
4685 "rule()",
4686 "ActionId::ToggleSnap",
4687 "ActionId::SetIn",
4688 "ActionId::SetOut",
4689 "ActionId::ZoomOut",
4690 "zoom_slider(",
4691 "ActionId::ZoomIn",
4692 "ActionId::ZoomFit",
4693 ];
4694 let mut at = 0;
4695 for needle in order {
4696 let found = render[at..]
4697 .find(needle)
4698 .unwrap_or_else(|| panic!("{needle} must follow the groups before it: {render}"));
4699 at += found + needle.len();
4700 }
4701 let helper = |sig: &str| {
4702 let start = src.find(sig).unwrap_or_else(|| panic!("{sig} must exist"));
4703 let rest = &src[start + sig.len()..];
4704 let end = rest.find("\n}\n").expect("the helper's closing brace");
4705 &rest[..end]
4706 };
4707 assert!(
4708 helper("fn button(").contains("toolbar_tip(player, action)")
4709 && helper("fn toolbar_tip(").contains("player.keymap.display(action)"),
4710 "a toolbar button must name its key through the keymap's hover, not print it"
4711 );
4712 assert!(!src.contains("keymap.primary("), "the toolbar prints a key");
4713}
4714
4715/// REDESIGN §3.8: a refused row says why in one line and stays the row height.
4716#[test]
4717fn a_refused_media_row_keeps_the_row_height() {
4718 use crate::ui::dock_stance::{REFUSED_ROW_H, SOURCE_ROW_H, source_row_h};
4719 assert_eq!(source_row_h(true), SOURCE_ROW_H);
4720 assert_eq!(source_row_h(false), REFUSED_ROW_H);
4721 assert_eq!(source_row_h(false), source_row_h(true));
4722 let dock = src_text("ui/dock_stance.rs");
4723 assert!(
4724 !dock.contains(".when(usable, |d| d.truncate())"),
4725 "the meta line truncates a refusal again"
4726 );
4727}
4728
4729/// Plain words: a source on no lane says where it is, never "unused" or
4730/// "not placed".
4731#[test]
4732fn the_media_list_says_not_on_timeline_in_plain_words() {
4733 use crate::ui::dock_stance::NOT_ON_TIMELINE;
4734 assert_eq!(NOT_ON_TIMELINE, "not on timeline");
4735 let dock = src_text("ui/dock_stance.rs");
4736 let code: String = dock
4737 .lines()
4738 .filter(|l| !l.trim_start().starts_with("//"))
4739 .collect::<Vec<_>>()
4740 .join("\n");
4741 assert!(
4742 !code.contains("\"unused\"") && !code.contains("\"not placed\""),
4743 "jargon is back in the media list"
4744 );
4745}
4746
4747/// The search box is a bordered field with a placeholder, and the media
4748/// rows carry a 64x36 poster.
4749#[test]
4750fn the_search_field_is_bordered_and_rows_carry_a_poster() {
4751 use crate::ui::dock_stance::SEARCH_PLACEHOLDER;
4752 assert!(SEARCH_PLACEHOLDER.contains("Search media"));
4753 let dock = src_text("ui/dock_stance.rs");
4754 let field = &dock[dock.find(r#".id("dock-filter")"#).expect("the field")..];
4755 let field = &field[..field.find(".child(match").expect("its text")];
4756 assert!(
4757 field.contains(".border_1()") && field.contains("t.e2"),
4758 "the search field lost its border"
4759 );
4760 assert!(
4761 dock.contains("const POSTER_W: f32 = 88.;") && dock.contains("const POSTER_H: f32 = 50.;")
4762 );
4763 assert!(dock.contains("let poster = poster(player, &row.path"));
4764}
4765
4766/// The empty states each carry a call to action.
4767#[test]
4768fn the_empty_viewer_media_list_and_lanes_each_say_what_to_do() {
4769 use crate::ui::bench_stance::lane::{empty_lane_hint, wave_is_silent};
4770 assert_eq!(empty_lane_hint(LaneKind::Video), "Drop media here");
4771 assert_eq!(empty_lane_hint(LaneKind::Subtitle), "Drop captions here");
4772 let dock = src_text("ui/dock_stance.rs");
4773 assert!(dock.contains("EMPTY_LIBRARY_HINT") && dock.contains("pick_and_import"));
4774 let render = src_text("render.rs");
4775 assert!(
4776 render.contains("self.empty_viewer(cx)"),
4777 "the viewer lost its Import box"
4778 );
4779 assert!(!src_text("ui/widgets.rs").contains("No project"));
4780 // Silent is an answer; loading is not.
4781 assert!(wave_is_silent(&Wave::Silent));
4782 let flat = std::sync::Arc::new(vec![(0., 0.); 4]);
4783 let loud = std::sync::Arc::new(vec![(-0.5, 0.5)]);
4784 assert!(wave_is_silent(&Wave::Peaks(flat)));
4785 assert!(!wave_is_silent(&Wave::Peaks(loud)));
4786 assert!(!wave_is_silent(&Wave::Loading));
4787}
4788
4789/// No layout shift (Nielsen): a toggle whose word changes with its state keeps
4790/// the width of its widest spelling, so the row around it does not move. The
4791/// crate has no gpui harness, so this reads the sources the way its siblings do.
4792#[test]
4793fn a_toggle_whose_word_changes_keeps_one_width() {
4794 let band = src_text("ui/timeband_stance.rs");
4795 assert!(
4796 !band.contains("\"Muted\""),
4797 "the transport has icons, not words that change"
4798 );
4799 let bar = src_text("ui/toolbar.rs");
4800 assert!(
4801 bar.contains("\"Snap\"") && !bar.contains("Snap on") && !bar.contains("Snap off"),
4802 "Snap keeps one word; its state is the fill"
4803 );
4804 let stance = src_text("ui/stance.rs");
4805 assert!(
4806 stance.contains("// `Exporting 5%` to `Exporting 100%`: held at the widest."),
4807 "the status bar's export readout must hold its width"
4808 );
4809}
4810
4811/// 1280x720: the toolbar sheds its keys (kept in the tooltips) instead of
4812/// pushing the zoom group and Export off the window.
4813#[test]
4814fn the_toolbar_sheds_its_keys_rather_than_clip_at_a_narrow_column() {
4815 let bar = src_text("ui/toolbar.rs");
4816 assert!(
4817 bar.contains("const COMPACT_BELOW: f32 = 900.;") && bar.contains("words.then_some"),
4818 "the toolbar no longer sheds words at narrow widths"
4819 );
4820}
4821
4822/// P6: monospace is the transport timecode's face. The media list, the status bar, the lanes, the
4823/// viewer and its welcome hero speak in Inter roles (`ui::type_scale`), never `mono`.
4824#[test]
4825fn the_media_list_status_bar_lanes_and_viewer_use_no_mono() {
4826 for file in [
4827 "ui/dock_stance.rs",
4828 "ui/stance.rs",
4829 "ui/preview.rs",
4830 "ui/timeband_stance.rs",
4831 "ui/bench_stance/lane.rs",
4832 "ui/bench_stance/sub.rs",
4833 "ui/bench_stance/clip.rs",
4834 "ui/toolbar.rs",
4835 ] {
4836 let text = src_text(file);
4837 assert!(
4838 !text.contains("mono(") && !text.contains("SPLINE_SANS_MONO"),
4839 "{file} sets the mono face; use a type_scale role"
4840 );
4841 }
4842}