BlueGit

ict rusty-teams

Files

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

layout_guard.rs

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