BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / layout_guard.rs

layout_guard.rs

layout_guard.rs 31.9 KiB Download Raw
1use std::collections::HashSet;
2use std::fs;
3use std::path::{Path, PathBuf};
4
5use regex::Regex;
6
7const WIDGETS_FILE: &str = "views/widgets.rs";
8const SCAN_ALLOWLIST: &[(&str, &str)] = &[
9 ("views/toolbar_placement.rs", ".top(px(-SLOT_HEIGHT))"),
10 ("views/conversation.rs", ".bottom(px(-1.))"),
11];
12
13fn source_files(directory: &Path, files: &mut Vec<PathBuf>) {
14 for entry in fs::read_dir(directory).expect("read source directory") {
15 let path = entry.expect("directory entry").path();
16 if path.is_dir() {
17 source_files(&path, files);
18 } else if path.extension().is_some_and(|extension| extension == "rs") {
19 files.push(path);
20 }
21 }
22}
23
24fn negative_offsets(
25 pattern: &Regex,
26 source: &str,
27 relative: &str,
28) -> Vec<(usize, Option<usize>, String)> {
29 pattern
30 .find_iter(source)
31 .map(|found| {
32 let line_number = source[..found.start()].matches('\n').count() + 1;
33 let from_match = &source[found.start()..];
34 let allowed = SCAN_ALLOWLIST.iter().position(|(allowed_file, snippet)| {
35 *allowed_file == relative && from_match.starts_with(snippet)
36 });
37 let line_end = from_match.find('\n').unwrap_or(from_match.len());
38 (
39 line_number,
40 allowed,
41 from_match[..line_end].trim().to_owned(),
42 )
43 })
44 .collect()
45}
46
47fn offset_pattern() -> Regex {
48 Regex::new(r"\.(top|right|bottom|left|inset)\(\s*(px\(\s*)?-").expect("pattern")
49}
50
51#[test]
52fn matcher_catches_wrapped_offsets() {
53 let source = "let a = 1;\nlet b = div()\n .top(\n px(-4.))\n .left(px(2.));\n";
54 let found = negative_offsets(&offset_pattern(), source, "views/other.rs");
55 assert_eq!(found, [(3, None, ".top(".to_owned())]);
56}
57
58#[test]
59fn matcher_matches_allowlist_from_match_start() {
60 let source = "x\n .bottom(px(-1.))\n";
61 let found = negative_offsets(&offset_pattern(), source, "views/conversation.rs");
62 assert_eq!(found, [(2, Some(1), ".bottom(px(-1.))".to_owned())]);
63}
64
65#[test]
66fn negative_offsets_go_through_corner_badge() {
67 let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
68 let pattern = offset_pattern();
69 let mut files = Vec::new();
70 source_files(&root, &mut files);
71 let mut matched_allowlist = HashSet::new();
72 let mut violations = Vec::new();
73 for file in files {
74 let relative = file
75 .strip_prefix(&root)
76 .expect("inside src")
77 .to_string_lossy()
78 .replace('\\', "/");
79 if relative == WIDGETS_FILE || relative == "layout_guard.rs" {
80 continue;
81 }
82 let source = fs::read_to_string(&file).expect("read source file");
83 for (line_number, position, text) in negative_offsets(&pattern, &source, &relative) {
84 match position {
85 Some(position) => {
86 matched_allowlist.insert(position);
87 }
88 None => violations.push(format!(
89 "{relative}:{line_number}: negative absolute offset, use widgets::corner_badge: {text}"
90 )),
91 }
92 }
93 }
94 let stale: Vec<String> = SCAN_ALLOWLIST
95 .iter()
96 .enumerate()
97 .filter(|(position, _)| !matched_allowlist.contains(position))
98 .map(|(_, (file, snippet))| format!("stale allowlist entry, remove it: {file} {snippet}"))
99 .collect();
100 assert!(
101 violations.is_empty() && stale.is_empty(),
102 "{}",
103 violations
104 .into_iter()
105 .chain(stale)
106 .collect::<Vec<_>>()
107 .join("\n")
108 );
109}
110
111mod frames {
112 use std::collections::HashSet;
113 use std::sync::Arc;
114 use std::time::Duration;
115
116 use gpui_kit::test::TestWindowExt as _;
117 use gpui_kit::{
118 AppContext as _, Bounds, Pixels, TestAppContext, VisualTestContext, WindowOptions, point,
119 px, size,
120 };
121 use store::Store;
122
123 use std::time::Instant;
124
125 use calling::{CallState, CallUpdate, CaptionEntry, CaptionState, RosterEntry, call_channel};
126 use gpui_kit::Entity;
127
128 use crate::app_state::{AppHandle, AppState, Mode, Selection};
129 use crate::call::{ActiveCall, CallModel, ConsultCall};
130 use crate::demo;
131 use crate::user_activity::UserInput;
132 use crate::views::call_transcript::TranscriptPanel;
133 use crate::views::call_view::CHAT_PANEL_TAG;
134 use crate::views::message_row::BUBBLE_TAGS;
135 use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};
136 use crate::views::reaction_proposal_pill::REACTION_PILL;
137 use crate::views::recap_tab::RECAP_REGION;
138 use crate::views::shell::{AppShell, Startup, bind_keys, install_globals, sidebar_hidden_in_call};
139 use crate::views::shortcuts::{OpenActivity, OpenCallsTab, OpenChannelsTab, OpenSaved};
140
141 const GUARDED: &[&str] = &[
142 "shell",
143 "shell/title-bar",
144 "shell/title-bar/search",
145 "shell/title-bar/own-status",
146 "shell/title-bar/own-status/avatar",
147 "shell/islands",
148 "shell/islands/rail",
149 "shell/islands/sidebar",
150 "shell/islands/main",
151 "shell/status-bar",
152 ];
153 const CALL_GUARDED: &[&str] = &[
154 "shell/islands/main/call-header",
155 "shell/islands/main/call-stage",
156 "shell/islands/main/call-controls",
157 "shell/islands/main/call-controls/mic",
158 "shell/islands/main/call-controls/leave",
159 ];
160 const CALLS_TAGS: &[&str] = &[
161 "shell/islands/sidebar/calls-actions",
162 "shell/islands/sidebar/calls-actions/meet-now",
163 "shell/islands/sidebar/calls-actions/new-meeting",
164 ];
165 const PREJOIN_TAGS: &[&str] = &[
166 "shell/islands/main/prejoin",
167 "shell/islands/main/prejoin/preview",
168 "shell/islands/main/prejoin/controls",
169 "shell/islands/main/prejoin/devices",
170 "shell/islands/main/prejoin/audio",
171 "shell/islands/main/prejoin/actions",
172 ];
173 const PREJOIN_LINK: &str = "https://teams.microsoft.com/l/meetup-join/19%3ameeting_guard%40thread.v2/0?context=%7b%22Tid%22%3a%22t%22%2c%22Oid%22%3a%22o%22%7d";
174 const CONSULT_GUARDED: &[&str] = &[
175 "shell/islands/main/call-header/call-consult",
176 "shell/islands/main/call-header/call-consult/transfer",
177 "shell/islands/main/call-header/call-consult/resume",
178 ];
179 const CALL_TRANSCRIPT: &str = "shell/islands/main/call-transcript";
180 const PEOPLE_PANEL: &str = "shell/islands/main/call-people";
181 const SHARE_GUARDED: &[&str] = &[
182 "shell/islands/main/call-stage/share-content",
183 "shell/islands/main/call-stage/share-content/zoom-chip",
184 "shell/islands/main/call-stage/share-divider",
185 "shell/islands/main/call-stage/share-strip",
186 ];
187 const OVERLAY_PANELS: &[&str] = &[CALL_TRANSCRIPT, PEOPLE_PANEL];
188 const OVERLAY_CHROME: &[&str] = &[
189 "shell/islands/main/call-header",
190 "shell/islands/main/call-stage",
191 ];
192 const MENU: &str = "popup-menu";
193 const OWN_STATUS: &str = "shell/title-bar/own-status";
194 const RECAP_TAB: &str = "shell/islands/main/recap-tab";
195 const RECAP_MEETING_CHAT: &str = "demo-chat-meeting-standup";
196 const PROPOSAL_CHAT: &str = "demo-chat-release";
197 const REACTION_CHAT: &str = "demo-chat-mara";
198 const AGENT_TAGS: [&str; 4] = [
199 PROPOSAL_CARD,
200 PROPOSAL_THUMBNAILS,
201 PROPOSAL_BUTTONS,
202 REACTION_PILL,
203 ];
204 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
205 const TOLERANCE: f32 = 0.5;
206 const KNOWN_VIOLATIONS: &[&str] = &[];
207
208 type Tag = (&'static str, Bounds<Pixels>);
209
210 enum Screen {
211 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
212 StatusMenu,
213 Call,
214 Prejoin,
215 CallTranscript,
216 CallPeople,
217 CallShare,
218 CallConsult,
219 }
220
221 fn parent_of(path: &str) -> Option<&str> {
222 path.rsplit_once('/').map(|(parent, _)| parent)
223 }
224
225 fn contains(outer: Bounds<Pixels>, inner: Bounds<Pixels>) -> bool {
226 let tolerance = px(TOLERANCE);
227 inner.left() >= outer.left() - tolerance
228 && inner.top() >= outer.top() - tolerance
229 && inner.right() <= outer.right() + tolerance
230 && inner.bottom() <= outer.bottom() + tolerance
231 }
232
233 fn overlaps(first: Bounds<Pixels>, second: Bounds<Pixels>) -> bool {
234 let tolerance = px(TOLERANCE);
235 first.left() < second.right() - tolerance
236 && second.left() < first.right() - tolerance
237 && first.top() < second.bottom() - tolerance
238 && second.top() < first.bottom() - tolerance
239 }
240
241 fn describe(bounds: Bounds<Pixels>) -> String {
242 format!(
243 "[{:.1},{:.1} {:.1}x{:.1}]",
244 f32::from(bounds.origin.x),
245 f32::from(bounds.origin.y),
246 f32::from(bounds.size.width),
247 f32::from(bounds.size.height)
248 )
249 }
250
251 fn violations(
252 tags: &[Tag],
253 window: Bounds<Pixels>,
254 expected: &[&str],
255 ) -> Vec<(String, String)> {
256 let mut found = Vec::new();
257 let bounds_of = |path: &str| {
258 tags.iter()
259 .find(|(tag, _)| *tag == path)
260 .map(|(_, bounds)| *bounds)
261 };
262 for path in expected {
263 if bounds_of(path).is_none() {
264 found.push((
265 format!("{path}:missing"),
266 format!("{path} was not rendered"),
267 ));
268 }
269 }
270 for (path, bounds) in tags {
271 if !contains(window, *bounds) {
272 found.push((
273 format!("{path}:outside-window"),
274 format!(
275 "{path} {} leaves the window {}",
276 describe(*bounds),
277 describe(window)
278 ),
279 ));
280 }
281 if let Some(parent) =
282 parent_of(path).and_then(|parent| bounds_of(parent).map(|bounds| (parent, bounds)))
283 {
284 if !contains(parent.1, *bounds) {
285 found.push((
286 format!("{path}:outside-parent"),
287 format!(
288 "{path} {} leaves {} {}",
289 describe(*bounds),
290 parent.0,
291 describe(parent.1)
292 ),
293 ));
294 }
295 }
296 for (other, other_bounds) in tags {
297 let overlays = |first: &str, second: &str| {
298 OVERLAY_PANELS.contains(&first) && OVERLAY_CHROME.contains(&second)
299 };
300 let siblings = path < other
301 && parent_of(path).is_some()
302 && parent_of(path) == parent_of(other)
303 && !overlays(path, other)
304 && !overlays(other, path);
305 if siblings && overlaps(*bounds, *other_bounds) {
306 found.push((
307 format!("{path}:overlaps:{other}"),
308 format!(
309 "{path} {} overlaps {other} {}",
310 describe(*bounds),
311 describe(*other_bounds)
312 ),
313 ));
314 }
315 }
316 }
317 found
318 }
319
320 const SETTLE_FRAMES: usize = 2;
321 const SETTLE_LIMIT: usize = 60;
322 const SETTLE_STEP: Duration = Duration::from_millis(50);
323
324 fn collect(visual: &mut VisualTestContext, awaited: Option<&'static str>) -> Vec<Tag> {
325 let mut frames = 0;
326 while frames < SETTLE_FRAMES
327 || awaited.is_some_and(|path| visual.debug_bounds(path).is_none())
328 {
329 assert!(frames < SETTLE_LIMIT, "{awaited:?} never rendered");
330 visual.executor().advance_clock(SETTLE_STEP);
331 std::thread::sleep(SETTLE_STEP);
332 visual.run_until_parked();
333 visual.update(|window, cx| window.render_frame(cx));
334 frames += 1;
335 }
336 GUARDED
337 .iter()
338 .chain(CALL_GUARDED)
339 .chain(CALLS_TAGS)
340 .chain(PREJOIN_TAGS)
341 .chain(SHARE_GUARDED)
342 .chain(CONSULT_GUARDED)
343 .chain([
344 &CALL_TRANSCRIPT,
345 &MENU,
346 &RECAP_TAB,
347 &RECAP_REGION,
348 &PEOPLE_PANEL,
349 ])
350 .chain(&AGENT_TAGS)
351 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
352 .collect()
353 }
354
355 fn sharing_call() -> ActiveCall {
356 let mut call = gallery_call();
357 call.model.apply(CallUpdate::ScreenShare(Some("8:orgid:guard-1".to_owned())));
358 call.share_stage.view.step_in((800., 450.));
359 call
360 }
361
362 fn gallery_call() -> ActiveCall {
363 let (handle, _control) = call_channel();
364 let mut model = CallModel::meeting("Standup", false);
365 model.apply(CallUpdate::State(CallState::Connected {
366 since: Instant::now(),
367 }));
368 model.apply(CallUpdate::Roster(
369 (0..11)
370 .map(|index| RosterEntry {
371 mri: format!("8:orgid:guard-{index}"),
372 display_name: format!("Guest {index}"),
373 muted: false,
374 in_lobby: false,
375 has_video: false,
376 sharing: false,
377 hand: None,
378 spotlight: None,
379 organizer: false,
380 ..Default::default()
381 })
382 .collect(),
383 ));
384 ActiveCall::new(1, model, handle.commands, None, handle.video)
385 }
386
387 fn consult_calls() -> (ActiveCall, ActiveCall) {
388 let connected = |id: u64, name: &str, mri: &str| {
389 let (handle, _control) = call_channel();
390 let mut model = CallModel::people(name, &[(mri.to_owned(), name.to_owned())]);
391 model.apply(CallUpdate::State(CallState::Connected {
392 since: Instant::now(),
393 }));
394 ActiveCall::new(id, model, handle.commands, None, handle.video)
395 };
396 let held = connected(1, "Christopher Montgomery-Lindqvist", "8:orgid:guard-held");
397 let mut consult = connected(2, "Jonas Ortega", "8:orgid:guard-consult");
398 consult.consult = Some(ConsultCall::new(
399 ("8:orgid:guard-consult".to_owned(), "Jonas Ortega".to_owned()),
400 held.model.peer_name.clone(),
401 ));
402 (consult, held)
403 }
404
405 fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
406 mount_with(cx, false)
407 }
408
409 fn mount_with(
410 cx: &mut TestAppContext,
411 agent_api: bool,
412 ) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
413 cx.update(gpui_kit::init);
414 cx.update(|cx| {
415 crate::theme::apply(cx);
416 bind_keys(cx);
417 let store = Store::open_in_memory().expect("in-memory store");
418 demo::seed(&store);
419 let store = Arc::new(store);
420 if agent_api {
421 crate::agent_api::init(store.clone(), true, cx);
422 }
423 let mode = Mode {
424 demo: true,
425 read_only: false,
426 demo_sync: None,
427 };
428 let state = cx.new(|_| AppState::new(store, mode));
429 install_globals(&state, UserInput::new(), cx);
430 demo::start_session(&state, cx);
431 let shared_state = state.clone();
432 let startup = Startup {
433 switcher_query: None,
434 composer_text: None,
435 reply_to_last: false,
436 };
437 let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
438 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
439 })
440 .expect("open test window")
441 .0;
442 (window, shared_state)
443 })
444 }
445
446 fn rectangle(left: f32, top: f32, width: f32, height: f32) -> Bounds<Pixels> {
447 Bounds {
448 origin: point(px(left), px(top)),
449 size: size(px(width), px(height)),
450 }
451 }
452
453 #[test]
454 fn rules_flag_overlap_and_overflow() {
455 let window = rectangle(0., 0., 100., 100.);
456 let tags: Vec<Tag> = vec![
457 ("shell", rectangle(0., 0., 100., 100.)),
458 ("shell/islands", rectangle(0., 0., 100., 50.)),
459 ("shell/islands/rail", rectangle(0., 0., 60., 50.)),
460 ("shell/islands/sidebar", rectangle(50., 0., 60., 50.)),
461 ];
462 let keys: Vec<String> = violations(&tags, window, &["shell/status-bar"])
463 .into_iter()
464 .map(|(key, _)| key)
465 .collect();
466 assert_eq!(
467 keys,
468 [
469 "shell/status-bar:missing",
470 "shell/islands/rail:overlaps:shell/islands/sidebar",
471 "shell/islands/sidebar:outside-window",
472 "shell/islands/sidebar:outside-parent",
473 ]
474 );
475 }
476
477 #[gpui_kit::test]
478 fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {
479 let (handle, app) = mount(cx);
480 let mut visual = VisualTestContext::from_window(handle, cx);
481 let mut seen_known = HashSet::new();
482 let mut unexpected = Vec::new();
483 for (width, height) in SIZES {
484 visual.simulate_resize(size(px(width), px(height)));
485 let window = Bounds {
486 origin: point(px(0.), px(0.)),
487 size: size(px(width), px(height)),
488 };
489 let screens = [
490 Screen::Tab("chats", None),
491 Screen::Tab(
492 "activity",
493 Some(|visual| visual.dispatch_action(OpenActivity)),
494 ),
495 Screen::Tab(
496 "channels",
497 Some(|visual| visual.dispatch_action(OpenChannelsTab)),
498 ),
499 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
500 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
501 Screen::Prejoin,
502 Screen::StatusMenu,
503 Screen::Call,
504 Screen::CallTranscript,
505 Screen::CallPeople,
506 Screen::CallShare,
507 Screen::CallConsult,
508 ];
509 for screen in screens {
510 let (screen_name, status_menu) = match screen {
511 Screen::Tab(name, open) => {
512 if let Some(open) = open {
513 open(&mut visual);
514 }
515 (name, false)
516 }
517 Screen::Call | Screen::CallPeople => {
518 let people_open = matches!(screen, Screen::CallPeople);
519 visual.update(|_, cx| {
520 app.update(cx, |state, cx| {
521 let mut call = gallery_call();
522 call.people_open = people_open;
523 state.call = Some(call);
524 cx.notify();
525 })
526 });
527 (if people_open { "call-people" } else { "call" }, false)
528 }
529 Screen::Prejoin => {
530 let state = visual.update(|_, cx| cx.global::<AppHandle>().0.clone());
531 visual.update(|_, cx| {
532 state.update(cx, |state, cx| state.join_meeting_link(PREJOIN_LINK, cx))
533 });
534 ("prejoin", false)
535 }
536 Screen::CallTranscript => {
537 visual.update(|window, cx| {
538 app.update(cx, |state, cx| {
539 let mut call = gallery_call();
540 call.model.apply(CallUpdate::Captions(CaptionState::On));
541 for index in 0..40 {
542 call.model.note_caption(
543 CaptionEntry {
544 id: format!("guard-{index}"),
545 user_id: "8:orgid:guard-0".into(),
546 display_name: "Guest 0".into(),
547 text: "A long guarded sentence that has to wrap inside the panel".into(),
548 is_final: true,
549 },
550 Instant::now(),
551 );
552 }
553 call.transcript_open = true;
554 state.call = Some(call);
555 let app_entity = cx.entity();
556 state.transcript_panel = Some(cx.new(|cx| TranscriptPanel::new(app_entity, window, cx)));
557 cx.notify();
558 })
559 });
560 ("call-transcript", false)
561 }
562 Screen::CallShare => {
563 visual.update(|_, cx| {
564 app.update(cx, |state, cx| {
565 state.call = Some(sharing_call());
566 cx.notify();
567 })
568 });
569 ("call-share", false)
570 }
571 Screen::CallConsult => {
572 visual.update(|_, cx| {
573 app.update(cx, |state, cx| {
574 let (consult, held) = consult_calls();
575 state.call = Some(consult);
576 state.held_call = Some(held);
577 cx.notify();
578 })
579 });
580 ("call-consult", false)
581 }
582 Screen::StatusMenu => {
583 let tags = collect(&mut visual, None);
584 let button = tags
585 .iter()
586 .find(|(path, _)| *path == OWN_STATUS)
587 .map(|(_, bounds)| *bounds)
588 .expect("own status button rendered");
589 visual.simulate_click(button.center(), Default::default());
590 ("status-menu", true)
591 }
592 };
593 let is_call = matches!(
594 screen_name,
595 "call" | "call-people" | "call-transcript" | "call-share" | "call-consult"
596 );
597 let tags = collect(&mut visual, status_menu.then_some(MENU));
598 let mut expected = GUARDED.to_vec();
599 if is_call {
600 expected.extend(CALL_GUARDED);
601 let panel_open = matches!(screen_name, "call-people" | "call-transcript");
602 if sidebar_hidden_in_call(width, panel_open) {
603 expected.retain(|path| *path != "shell/islands/sidebar");
604 }
605 }
606 if screen_name == "call-transcript" {
607 expected.push(CALL_TRANSCRIPT);
608 }
609 if screen_name == "call-people" {
610 expected.push(PEOPLE_PANEL);
611 }
612 if screen_name == "call-share" {
613 expected.extend(SHARE_GUARDED);
614 }
615 if screen_name == "call-consult" {
616 expected.extend(CONSULT_GUARDED);
617 }
618 if status_menu {
619 expected.push(MENU);
620 }
621 match screen_name {
622 "calls" => expected.extend(CALLS_TAGS),
623 "prejoin" => expected.extend(PREJOIN_TAGS),
624 _ => {}
625 }
626 let mut found = violations(&tags, window, &expected);
627 if status_menu {
628 let menu = tags
629 .iter()
630 .find(|(path, _)| *path == MENU)
631 .map(|(_, bounds)| *bounds);
632 let button = tags
633 .iter()
634 .find(|(path, _)| *path == OWN_STATUS)
635 .map(|(_, bounds)| *bounds);
636 if let (Some(menu), Some(button)) = (menu, button) {
637 if overlaps(menu, button) {
638 found.push((
639 format!("{MENU}:covers:{OWN_STATUS}"),
640 format!(
641 "{MENU} {} covers {OWN_STATUS} {}",
642 describe(menu),
643 describe(button)
644 ),
645 ));
646 }
647 }
648 visual.simulate_keystrokes("escape");
649 visual.run_until_parked();
650 }
651 if is_call {
652 visual.update(|_, cx| {
653 app.update(cx, |state, cx| {
654 state.call = None;
655 state.held_call = None;
656 cx.notify();
657 })
658 });
659 }
660 if screen_name == "prejoin" {
661 let state = visual.update(|_, cx| cx.global::<AppHandle>().0.clone());
662 visual.update(|_, cx| state.update(cx, |state, cx| state.cancel_prejoin(cx)));
663 }
664 for (key, message) in found {
665 let full_key = format!("{screen_name}@{width}x{height}:{key}");
666 if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {
667 seen_known.insert(full_key);
668 } else {
669 unexpected.push(format!("{full_key}: {message}"));
670 }
671 }
672 }
673 }
674 let stale: Vec<String> = KNOWN_VIOLATIONS
675 .iter()
676 .filter(|key| !seen_known.contains(**key))
677 .map(|key| format!("stale known violation, remove it: {key}"))
678 .collect();
679 assert!(
680 unexpected.is_empty() && stale.is_empty(),
681 "{}",
682 unexpected
683 .into_iter()
684 .chain(stale)
685 .collect::<Vec<_>>()
686 .join("\n")
687 );
688 }
689 #[gpui_kit::test]
690 fn call_chat_bubbles_stay_inside_the_panel(cx: &mut TestAppContext) {
691 let (handle, app) = mount(cx);
692 let mut visual = VisualTestContext::from_window(handle, cx);
693 for (width, height) in SIZES {
694 visual.simulate_resize(size(px(width), px(height)));
695 visual.update(|_, cx| {
696 app.update(cx, |state, cx| {
697 let mut call = gallery_call();
698 call.conversation_id = Some(RECAP_MEETING_CHAT.to_owned());
699 call.chat_open = true;
700 state.call = Some(call);
701 cx.notify();
702 })
703 });
704 collect(&mut visual, Some(CHAT_PANEL_TAG));
705 let panel = visual
706 .debug_bounds(CHAT_PANEL_TAG)
707 .expect("chat panel rendered");
708 let bubbles: Vec<(usize, Bounds<Pixels>)> = BUBBLE_TAGS
709 .iter()
710 .enumerate()
711 .filter_map(|(index, tag)| visual.debug_bounds(tag).map(|bounds| (index, bounds)))
712 .collect();
713 assert!(!bubbles.is_empty(), "no bubbles rendered in the call chat");
714 let found: Vec<String> = bubbles
715 .into_iter()
716 .filter(|(_, bounds)| !contains(panel, *bounds))
717 .map(|(index, bounds)| {
718 format!(
719 "call-chat@{width}x{height}: bubble {index} {} leaves the chat panel {}",
720 describe(bounds),
721 describe(panel)
722 )
723 })
724 .collect();
725 visual.update(|_, cx| {
726 app.update(cx, |state, cx| {
727 state.call = None;
728 cx.notify();
729 })
730 });
731 assert!(found.is_empty(), "{}", found.join("\n"));
732 }
733 }
734
735 #[gpui_kit::test]
736 fn recap_tab_stays_inside_the_main_island(cx: &mut TestAppContext) {
737 let (handle, state) = mount(cx);
738 let mut visual = VisualTestContext::from_window(handle, cx);
739 for (width, height) in SIZES {
740 visual.simulate_resize(size(px(width), px(height)));
741 let window = Bounds {
742 origin: point(px(0.), px(0.)),
743 size: size(px(width), px(height)),
744 };
745 visual.update(|_, cx| {
746 state.update(cx, |state, cx| {
747 state.select(Selection::Chat(RECAP_MEETING_CHAT.to_owned()), cx)
748 })
749 });
750 collect(&mut visual, Some(RECAP_TAB));
751 let tab = visual.debug_bounds(RECAP_TAB).expect("recap tab rendered");
752 visual.simulate_click(tab.center(), Default::default());
753 let tags = collect(&mut visual, Some(RECAP_REGION));
754 let mut expected = GUARDED.to_vec();
755 expected.extend([RECAP_TAB, RECAP_REGION]);
756 let found: Vec<String> = violations(&tags, window, &expected)
757 .into_iter()
758 .map(|(key, message)| format!("recap@{width}x{height}:{key}: {message}"))
759 .collect();
760 assert!(found.is_empty(), "{}", found.join("\n"));
761 }
762 }
763
764 #[gpui_kit::test]
765 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
766 let (handle, state) = mount_with(cx, true);
767 let mut visual = VisualTestContext::from_window(handle, cx);
768 for (width, height) in SIZES {
769 visual.simulate_resize(size(px(width), px(height)));
770 let window = Bounds {
771 origin: point(px(0.), px(0.)),
772 size: size(px(width), px(height)),
773 };
774 for (chat, expected_tags) in [
775 (PROPOSAL_CHAT, &AGENT_TAGS[..3]),
776 (REACTION_CHAT, &AGENT_TAGS[3..]),
777 ] {
778 visual.update(|_, cx| {
779 state.update(cx, |state, cx| {
780 state.select(Selection::Chat(chat.to_owned()), cx)
781 })
782 });
783 let tags = collect(&mut visual, Some(expected_tags[0]));
784 let mut expected = GUARDED.to_vec();
785 expected.extend(expected_tags);
786 let found: Vec<String> = violations(&tags, window, &expected)
787 .into_iter()
788 .map(|(key, message)| format!("{chat}@{width}x{height}:{key}: {message}"))
789 .collect();
790 assert!(found.is_empty(), "{}", found.join("\n"));
791 }
792 }
793 }
794}
795
796#[test]
797fn lines_are_solid() {
798 let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
799 let mut files = Vec::new();
800 source_files(&root, &mut files);
801 let violations: Vec<String> = files
802 .iter()
803 .filter(|file| !file.ends_with("layout_guard.rs"))
804 .flat_map(|file| {
805 let source = fs::read_to_string(file).expect("read source file");
806 source
807 .lines()
808 .enumerate()
809 .filter(|(_, line)| {
810 line.contains(".border_dashed(") || line.contains(".border_dotted(")
811 })
812 .map(|(index, line)| {
813 format!(
814 "{}:{}: lines are always solid: {}",
815 file.display(),
816 index + 1,
817 line.trim()
818 )
819 })
820 .collect::<Vec<_>>()
821 })
822 .collect();
823 assert!(violations.is_empty(), "{}", violations.join("\n"));
824}