Visual Studio Code, rebuilt in Rust
Rust
//! testingContinuousRunService.ts: the tests, or the whole workspace, whose controllers rerun them as files change.
//! Each profile of a continuous run is one `$startContinuousRun` request (testServiceImpl.ts `startContinuousRun`)
//! that stays open until the run stops.
use std::collections::{HashMap, HashSet};
use gpui::{Context, Task, Window};
use serde_json::{Value, json};
use super::Workbench;
use crate::commands::Outcome;
use crate::notifications::{Notification, Severity};
use crate::menus::MenuAction;
use crate::quick_input::{Entry, Item, Kind, QuickInput};
use crate::main_thread_quick_open::Owner;
use crate::testing::{GROUP_COVERAGE, GROUP_DEBUG, GROUP_RUN, Profile, root_id};
const LAST_RUN_KEY: &str = "lastContinuousRunProfileIds";
/// A profile of a controller: `(controllerId, profileId)`.
type ProfileKey = (String, i64);
/// A `RunningRef` of the service's prefix tree.
pub struct ContinuousRun {
/// The test's id; empty for every test of the workspace (the tree's root).
test_id: String,
/// `autoSetDefault`: started for a group, the run follows that group's default profiles.
auto_group: Option<u64>,
/// The open request of each profile; dropping one drops its reply, which cancels its token.
requests: Vec<(ProfileKey, Task<()>)>,
}
pub enum ContinuousProfiles {
Profiles(Vec<ProfileKey>),
/// The group's default profiles that support continuous runs.
Group(u64),
}
/// `isEnabledForAParentOf`: the run covers the test.
fn covers(run_id: &str, test_id: &str) -> bool {
run_id.is_empty() || run_id == test_id || test_id.strip_prefix(run_id).is_some_and(|rest| rest.starts_with('\0'))
}
impl super::testing_service::TestingService {
/// `isSpecificallyEnabledFor`.
pub fn is_continuous_for(&self, test_id: &str) -> bool {
self.continuous.iter().any(|run| run.test_id == test_id)
}
pub fn is_continuous_for_a_parent_of(&self, test_id: &str) -> bool {
self.continuous.iter().any(|run| covers(&run.test_id, test_id))
}
pub fn is_continuous_for_a_child_of(&self, test_id: &str) -> bool {
self.continuous.iter().any(|run| run.test_id.is_empty() || covers(test_id, &run.test_id))
}
/// `isEnabled`.
pub fn is_continuous(&self) -> bool {
!self.continuous.is_empty()
}
/// `isEnabledForProfile`.
pub fn is_continuous_for_profile(&self, profile: &ProfileKey) -> bool {
self.continuous.iter().any(|run| run.requests.iter().any(|(running, _)| running == profile))
}
/// testingExplorerView.ts `getContinuousRunDropdown`: the continuous profiles of controllers with tests.
pub fn continuous_dropdown_profiles(&self) -> Vec<&Profile> {
self.profiles.iter().filter(|profile| profile.supports_continuous_run && !self.collection.children_of(&profile.controller_id).is_empty()).collect()
}
/// testProfileService.ts `getGroupDefaultProfiles`, filtered as `start` does for a group.
fn group_continuous_profiles(&self, group: u64, test_id: &str) -> Vec<ProfileKey> {
let in_group = || self.profiles.iter().filter(|profile| profile.group == group);
let mut defaults: Vec<&Profile> = in_group().filter(|profile| profile.is_default).collect();
if defaults.is_empty() {
defaults.extend(in_group().next());
}
defaults.into_iter().filter(|profile| profile.supports_continuous_run && (test_id.is_empty() || root_id(test_id) == profile.controller_id)).map(|profile| (profile.controller_id.clone(), profile.profile_id)).collect()
}
}
impl Workbench {
pub(super) fn register_testing_continuous_commands(&mut self) {
self.commands.register("testing.startContinuousRun", |workbench, _, window, cx| {
let last_run = workbench.last_continuous_run_profile_ids();
let profiles: Vec<ProfileKey> = workbench.testing.profiles.iter().filter(|profile| last_run.contains(&profile.profile_id)).map(|profile| (profile.controller_id.clone(), profile.profile_id)).collect();
if !profiles.is_empty() {
workbench.start_continuous_run(ContinuousProfiles::Profiles(profiles), "", window, cx);
return Outcome::done();
}
let picked = workbench.select_continuous_run_profiles(None, window, cx);
cx.spawn_in(window, async move |this, cx| {
let profiles = picked.await;
if !profiles.is_empty() {
let _ = this.update_in(cx, |workbench, window, cx| workbench.start_continuous_run(ContinuousProfiles::Profiles(profiles), "", window, cx));
}
})
.detach();
Outcome::done()
});
// `ContinuousRunUsingProfileTestAction`: a picker of the test's controller's profiles for each test.
self.commands.register("testing.continuousRunUsingForTest", |_, args, window, cx| {
let ids = super::testing_item_menu::test_ids(&args);
cx.spawn_in(window, async move |this, cx| {
for id in ids {
let Ok(picked) = this.update_in(cx, |workbench, window, cx| workbench.select_continuous_run_profiles(Some(root_id(&id)), window, cx)) else { return };
let profiles = picked.await;
if !profiles.is_empty() {
let _ = this.update_in(cx, |workbench, window, cx| workbench.start_continuous_run(ContinuousProfiles::Profiles(profiles), &id, window, cx));
}
}
})
.detach();
Outcome::done()
});
self.commands.register("testing.stopContinuousRun", |workbench, _, _, cx| {
workbench.stop_continuous_run("", cx);
Outcome::done()
});
self.commands.register("testing.toggleContinuousRunForTest", |workbench, args, window, cx| {
for id in super::testing_item_menu::test_ids(&args) {
match workbench.testing.is_continuous_for(&id) {
true => workbench.stop_continuous_run(&id, cx),
false => workbench.start_continuous_run(ContinuousProfiles::Group(GROUP_RUN), &id, window, cx),
}
}
Outcome::done()
});
// testing.contribution.ts: what the host's `TestRunProfile` continuous runs call.
self.commands.register("testing.startContinuousRunFromExtension", |workbench, args, window, cx| {
let (controller, profile_id) = (args[0]["controllerId"].as_str().unwrap_or_default(), args[0]["profileId"].as_i64());
let Some(profile) = workbench.testing.profiles.iter().find(|profile| profile.controller_id == controller && Some(profile.profile_id) == profile_id) else { return Outcome::done() };
if !profile.supports_continuous_run {
return Outcome::done();
}
let key = (profile.controller_id.clone(), profile.profile_id);
let tests: Vec<String> = args[1].as_array().into_iter().flatten().filter_map(|test| workbench.testing.collection.items.get(test["extId"].as_str()?)).filter(|test| profile.can_run(test)).map(|test| test.id.clone()).collect();
for test in tests {
workbench.start_continuous_run(ContinuousProfiles::Profiles(vec![key.clone()]), &test, window, cx);
}
Outcome::done()
});
self.commands.register("testing.stopContinuousRunFromExtension", |workbench, args, _, cx| {
for test in args[0].as_array().into_iter().flatten() {
workbench.stop_continuous_run(test["extId"].as_str().unwrap_or_default(), cx);
}
Outcome::done()
});
}
/// testingContextKeys.ts: `isContinuousModeOn` (a run for every test) and testProfileService.ts's
/// `supportsContinuousRun` capability of all profiles.
pub(super) fn testing_continuous_context(&self, context: &mut HashMap<String, Value>) {
context.insert("testing.isContinuousModeOn".into(), json!(self.testing.is_continuous_for("")));
context.insert("testing.supportsContinuousRun".into(), json!(self.testing.profiles.iter().any(|profile| profile.supports_continuous_run)));
}
/// `start`: a run for the test, or for every test with an empty id. A test that already runs continuously
/// adds the profiles and stops following its group's defaults.
pub(super) fn start_continuous_run(&mut self, profiles: ContinuousProfiles, test_id: &str, window: &mut Window, cx: &mut Context<Self>) {
let (profiles, auto_group) = match profiles {
ContinuousProfiles::Profiles(profiles) => (profiles, None),
ContinuousProfiles::Group(group) => (self.testing.group_continuous_profiles(group, test_id), Some(group)),
};
let index = match self.testing.continuous.iter().position(|run| run.test_id == test_id) {
Some(index) => index,
None => {
self.testing.continuous.push(ContinuousRun { test_id: test_id.to_owned(), auto_group, requests: Vec::new() });
self.set_continuous_profiles(self.testing.continuous.len() - 1, profiles, window, cx);
cx.notify();
return;
}
};
let existing = &mut self.testing.continuous[index];
existing.auto_group = None;
let mut merged = profiles;
for (profile, _) in &existing.requests {
if !merged.contains(profile) {
merged.push(profile.clone());
}
}
self.set_continuous_profiles(index, merged, window, cx);
cx.notify();
}
/// `stop`: the test's run and the runs of its children; every run with an empty id.
pub(super) fn stop_continuous_run(&mut self, test_id: &str, cx: &mut Context<Self>) {
self.testing.continuous.retain(|run| !covers(test_id, &run.test_id));
cx.notify();
}
/// `stopProfile`: the profile leaves every run; a run it was the last profile of stops.
pub(super) fn stop_continuous_profile(&mut self, profile: &ProfileKey, window: &mut Window, cx: &mut Context<Self>) {
let mut index = 0;
while index < self.testing.continuous.len() {
let profiles: Vec<ProfileKey> = self.testing.continuous[index].requests.iter().map(|(running, _)| running.clone()).collect();
if !profiles.contains(profile) {
index += 1;
} else if profiles.len() == 1 {
self.testing.continuous.remove(index);
} else {
self.set_continuous_profiles(index, profiles.into_iter().filter(|running| running != profile).collect(), window, cx);
index += 1;
}
}
cx.notify();
}
/// testingExplorerView.ts `getContinuousRunDropdown`'s menu: the profiles by group, a disabled group label when
/// there are several groups, each checked while it runs; a click stops or starts it for every test.
pub(super) fn show_continuous_run_dropdown(&mut self, anchor: gpui::Bounds<gpui::Pixels>, window: &mut Window, cx: &mut Context<Self>) {
let profiles: Vec<Profile> = self.testing.continuous_dropdown_profiles().into_iter().cloned().collect();
let groups = [GROUP_RUN, GROUP_DEBUG, GROUP_COVERAGE].into_iter().filter(|group| profiles.iter().any(|profile| profile.group == *group)).collect::<Vec<_>>();
let mut actions = Vec::new();
for &group in &groups {
if groups.len() > 1 {
actions.push(MenuAction::Command { id: String::new(), title: group_name(group).unwrap_or_default().into(), enabled: false, checked: false, alt: None });
}
for profile in profiles.iter().filter(|profile| profile.group == group) {
let key = (profile.controller_id.clone(), profile.profile_id);
// The menu runs commands: one per profile stands in for the dropdown's plain actions.
let id = format!("_testing.toggleContinuousRunProfile.{}.{}", key.0, key.1);
let checked = self.testing.is_continuous_for_profile(&key);
self.commands.unregister(&id);
self.commands.register(id.clone(), move |workbench, _, window, cx| {
match workbench.testing.is_continuous_for_profile(&key) {
true => workbench.stop_continuous_profile(&key, window, cx),
false => workbench.start_continuous_run(ContinuousProfiles::Profiles(vec![key.clone()]), "", window, cx),
}
Outcome::done()
});
actions.push(MenuAction::Command { id, title: profile.label.clone(), enabled: true, checked, alt: None });
}
}
let context = self.key_context(window);
self.show_context_menu_actions(actions, &context, anchor, Vec::new(), window, cx);
}
/// testProfileService.ts `onDidChange`: a run started for a group follows the group's new default profiles.
pub(super) fn continuous_profiles_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
for index in 0..self.testing.continuous.len() {
let run = &self.testing.continuous[index];
let Some(group) = run.auto_group else { continue };
let relevant = self.testing.group_continuous_profiles(group, &run.test_id);
if !relevant.iter().eq(run.requests.iter().map(|(profile, _)| profile)) {
self.set_continuous_profiles(index, relevant, window, cx);
}
}
}
/// The `autorunIterableDelta` of `start`: a request for each added profile, the removed ones cancelled, and
/// the run's profiles stored as the last ones.
fn set_continuous_profiles(&mut self, index: usize, profiles: Vec<ProfileKey>, window: &mut Window, cx: &mut Context<Self>) {
let test_id = self.testing.continuous[index].test_id.clone();
let mut requests = std::mem::take(&mut self.testing.continuous[index].requests);
requests.retain(|(profile, _)| profiles.contains(profile));
for profile in profiles {
if requests.iter().all(|(running, _)| *running != profile) {
let request = self.start_continuous_request(&test_id, &profile, window, cx);
requests.push((profile, request));
}
}
let ids: Vec<i64> = requests.iter().map(|((_, id), _)| *id).collect();
self.workspace_storage.lock().unwrap().set(LAST_RUN_KEY, json!(ids).to_string());
self.testing.continuous[index].requests = requests;
}
/// testServiceImpl.ts `startContinuousRun`: the workspace trust request, then the controller's
/// `$startContinuousRun`, whose errors show as a notification.
fn start_continuous_request(&mut self, test_id: &str, (controller, profile_id): &ProfileKey, window: &mut Window, cx: &mut Context<Self>) -> Task<()> {
let target = if test_id.is_empty() { controller.as_str() } else { test_id };
let exclude: Vec<&String> = self.testing.excluded.iter().filter(|id| *id != target).collect();
let request = json!([{ "excludeExtIds": exclude, "profileId": profile_id, "controllerId": controller, "testIds": [target] }]);
let trust = self.request_workspace_trust(&json!({ "message": "Running tests may execute code in your workspace." }), window, cx);
cx.spawn(async move |this, cx| {
let trusted = match trust {
Outcome::Ready(answer) => matches!(answer, Ok(Value::Bool(true))),
Outcome::Pending(answer) => matches!(answer.await, Ok(Ok(Value::Bool(true)))),
};
if !trusted {
return;
}
let Ok(reply) = this.update(cx, |workbench, _| workbench.host.call_cancellable("ExtHostTesting", "$startContinuousRun", vec![request])) else { return };
let Ok(Ok(answers)) = reply.await else { return };
let errors: Vec<&str> = answers.as_array().into_iter().flatten().filter_map(|answer| answer["error"].as_str()).collect();
if !errors.is_empty() {
let message = format!("An error occurred attempting to run tests: {}", errors.join(" "));
let _ = this.update(cx, |workbench, cx| {
workbench.notify_error(message);
cx.notify();
});
}
})
}
/// `lastRunProfileIds`.
fn last_continuous_run_profile_ids(&self) -> HashSet<i64> {
let storage = self.workspace_storage.lock().unwrap();
storage.get(LAST_RUN_KEY).and_then(|ids| serde_json::from_str(ids).ok()).unwrap_or_default()
}
/// testExplorerActions.ts `selectContinuousRunProfiles`: the profiles that support continuous runs, a single one
/// without asking, else a multi-select picker by group with the last run's profiles selected. Given a controller,
/// only its profiles, without the controller's label (`ContinuousRunUsingProfileTestAction`).
fn select_continuous_run_profiles(&mut self, controller: Option<&str>, window: &mut Window, cx: &mut Context<Self>) -> Task<Vec<ProfileKey>> {
let mut items: Vec<(Profile, String)> = Vec::new();
for profile in self.testing.profiles.iter().filter(|profile| profile.supports_continuous_run && controller.is_none_or(|controller| profile.controller_id == controller)) {
let controller = match controller {
Some(_) => String::new(),
None => self.testing.controllers.get(&profile.controller_id).map(|controller| controller.label.clone()).unwrap_or_default(),
};
items.push((profile.clone(), controller));
}
if items.is_empty() {
self.notify(Notification::new(Severity::Info, "No test continuous run-enabled profiles were found"));
return Task::ready(Vec::new());
}
let key = |profile: &Profile| (profile.controller_id.clone(), profile.profile_id);
if let [(profile, _)] = items.as_slice() {
return Task::ready(vec![key(profile)]);
}
let label = |(profile, controller): &(Profile, String)| if profile.label.is_empty() { controller.clone() } else { profile.label.clone() };
items.sort_by(|a, b| a.0.group.cmp(&b.0.group).then_with(|| a.0.controller_id.cmp(&b.0.controller_id)).then_with(|| label(a).cmp(&label(b))));
let last_run = self.last_continuous_run_profile_ids();
let mut entries = Vec::new();
for (index, item) in items.iter().enumerate() {
if index == 0 || items[index - 1].0.group != item.0.group {
entries.push(Entry::Separator(group_name(item.0.group).map(str::to_owned)));
}
let description = (!item.1.is_empty()).then(|| item.1.clone());
entries.push(Entry::Item(Item { handle: index as i64, label: label(item), description, picked: last_run.contains(&item.0.profile_id), ..Item::default() }));
}
let profiles: Vec<ProfileKey> = items.iter().map(|(profile, _)| key(profile)).collect();
let (sender, receiver) = futures::channel::oneshot::channel();
let mut input = QuickInput::new(0, Kind::QuickPick);
input.title = Some("Select profiles to run when files change:".into());
input.can_select_many = true;
input.set_items(entries);
input.select_picked_items();
let id = self.quick_inputs.add(input, Owner::Debug(Some(sender)));
self.show_quick_input(id, window, cx);
self.flush_quick_input_events(window, cx);
cx.spawn(async move |_, _| {
let handles = receiver.await.ok().flatten().unwrap_or_default();
handles.split(',').filter_map(|handle| handle.parse::<usize>().ok()).map(|index| profiles[index].clone()).collect()
})
}
}
/// constants.ts `testConfigurationGroupNames`.
pub(super) fn group_name(group: u64) -> Option<&'static str> {
match group {
GROUP_RUN => Some("Run"),
GROUP_DEBUG => Some("Debug"),
GROUP_COVERAGE => Some("Coverage"),
_ => None,
}
}
#[cfg(test)]
mod tests {
use std::path::Path;
use std::sync::{Arc, Mutex};
use gpui::TestAppContext;
use serde_json::json;
use crate::menus::MenuAction;
use crate::testing::{GROUP_DEBUG, GROUP_RUN, Profile};
use crate::workbench::Workbench;
use crate::workbench::activity::Badge;
use crate::workspace_trust::{Startup, WorkspaceTrust};
fn profile(controller: &str, profile_id: i64, label: &str, group: u64) -> Profile {
Profile { controller_id: controller.into(), profile_id, label: label.into(), group, is_default: true, tag: None, supports_continuous_run: true, has_configuration_handler: false }
}
/// A trusted workbench with the profiles and a test `<controller>\0t` under each controller.
fn workbench_with(profiles: Vec<Profile>, cx: &mut TestAppContext) -> (gpui::Entity<Workbench>, &mut gpui::VisualTestContext, std::sync::mpsc::Receiver<crate::host_sync::HostMessage>) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let theme = crate::theme::load_theme(&[exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap()], "Dark Modern").unwrap();
let (sender, host) = std::sync::mpsc::channel();
let (workbench, cx) = cx.add_window_view(|_, cx| {
let mut workbench = Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(sender), cx);
let mut storage = storage::Storage::in_memory();
let startup = Startup { enabled: false, workspace: None, empty_window_trusted: false, workspace_storage: &mut storage };
workbench.workspace_trust = WorkspaceTrust::new(Arc::new(Mutex::new(storage::Storage::in_memory())), startup);
for profile in &profiles {
let (root, test) = (profile.controller_id.clone(), format!("{}\0t", profile.controller_id));
workbench.testing.collection.apply(&[json!({ "op": 0, "item": { "expand": 0, "item": { "extId": root, "label": root, "tags": [] } } }), json!({ "op": 0, "item": { "expand": 0, "item": { "extId": test, "label": "t", "tags": [] } } })]);
}
workbench.testing.profiles = profiles;
workbench
});
(workbench, cx, host)
}
fn started(host: &std::sync::mpsc::Receiver<crate::host_sync::HostMessage>) -> Vec<crate::host_sync::HostMessage> {
host.try_iter().filter(|message| message.method == "$startContinuousRun").collect()
}
#[gpui::test]
fn the_view_title_dropdown_starts_and_stops_one_profile_of_several(cx: &mut TestAppContext) {
let (workbench, cx, host) = workbench_with(vec![profile("c", 1, "Run Tests", GROUP_RUN), profile("c", 2, "Debug Tests", GROUP_DEBUG)], cx);
let menu = |cx: &mut gpui::VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| {
workbench.show_continuous_run_dropdown(gpui::Bounds::default(), window, cx);
let actions = workbench.context_menu.as_ref().unwrap().levels[0].actions.clone();
workbench.hide_context_menu(window, cx);
actions.into_iter().map(|action| match action {
MenuAction::Command { id, title, enabled, checked, .. } => (id, title, enabled, checked),
_ => unreachable!(),
}).collect::<Vec<_>>()
})
};
let run = |cx: &mut gpui::VisualTestContext, id: &str| {
let id = id.to_owned();
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command(&id, Vec::new(), window, cx));
cx.run_until_parked();
};
let (run_id, debug_id) = ("_testing.toggleContinuousRunProfile.c.1", "_testing.toggleContinuousRunProfile.c.2");
let item = |id: &str, title: &str, enabled: bool, checked: bool| (id.to_owned(), title.to_owned(), enabled, checked);
assert_eq!(menu(cx), [item("", "Run", false, false), item(run_id, "Run Tests", true, false), item("", "Debug", false, false), item(debug_id, "Debug Tests", true, false)]);
run(cx, run_id);
run(cx, debug_id);
let requests = started(&host);
assert_eq!(requests.iter().map(|message| (message.args[0][0]["profileId"].clone(), message.args[0][0]["testIds"].clone())).collect::<Vec<_>>(), [(json!(1), json!(["c"])), (json!(2), json!(["c"]))]);
assert_eq!(menu(cx).iter().map(|(_, _, _, checked)| *checked).collect::<Vec<_>>(), [false, true, false, true]);
run(cx, run_id);
assert!(requests[0].reply.as_ref().unwrap().is_canceled(), "stopProfile cancels only that profile's request");
assert!(!requests[1].reply.as_ref().unwrap().is_canceled());
assert_eq!(menu(cx).iter().map(|(_, _, _, checked)| *checked).collect::<Vec<_>>(), [false, false, false, true]);
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.workspace_storage.lock().unwrap().get(super::LAST_RUN_KEY).map(str::to_owned)), Some("[2]".to_owned()));
run(cx, debug_id);
assert!(requests[1].reply.as_ref().unwrap().is_canceled());
assert!(workbench.read_with(cx, |workbench, _| !workbench.testing.is_continuous()), "a run without profiles left stops");
}
#[gpui::test]
fn continuous_run_using_picks_from_the_tests_controller_only(cx: &mut TestAppContext) {
let (workbench, cx, host) = workbench_with(vec![profile("c", 1, "Run", GROUP_RUN), profile("d", 2, "Run", GROUP_RUN)], cx);
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("testing.continuousRunUsingForTest", vec![json!("c\0t")], window, cx));
cx.run_until_parked();
let requests = started(&host);
assert_eq!(requests.iter().map(|message| message.args.clone()).collect::<Vec<_>>(), [vec![json!([{ "excludeExtIds": [], "profileId": 1, "controllerId": "c", "testIds": ["c\0t"] }])]], "the controller's only profile starts without a picker");
assert!(workbench.read_with(cx, |workbench, _| workbench.testing.is_continuous_for("c\0t")));
}
#[gpui::test]
fn a_continuous_run_holds_one_cancellable_request_per_profile_until_it_stops(cx: &mut TestAppContext) {
let (workbench, cx, host) = workbench_with(vec![profile("c", 1, "Run", GROUP_RUN)], cx);
let state = |cx: &mut gpui::VisualTestContext| {
workbench.read_with(cx, |workbench, _| {
let mut context = std::collections::HashMap::new();
workbench.testing_continuous_context(&mut context);
(workbench.testing_badge(), context["testing.isContinuousModeOn"] == true)
})
};
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("testing.toggleContinuousRunForTest", vec![json!("c\0t")], window, cx));
cx.run_until_parked();
let started: Vec<_> = host.try_iter().filter(|message| message.method == "$startContinuousRun").collect();
assert_eq!(started.iter().map(|message| (message.args.clone(), message.cancellable)).collect::<Vec<_>>(), [(vec![json!([{ "excludeExtIds": [], "profileId": 1, "controllerId": "c", "testIds": ["c\0t"] }])], true)]);
assert_eq!(state(cx), (Some(Badge::Icon("eye")), false), "a test's run shows the eye, but continuous mode is not on");
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("testing.toggleContinuousRunForTest", vec![json!("c\0t")], window, cx));
cx.run_until_parked();
assert!(started[0].reply.as_ref().unwrap().is_canceled(), "a stop cancels the request");
assert_eq!(state(cx), (None, false));
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("testing.startContinuousRun", Vec::new(), window, cx));
cx.run_until_parked();
let started: Vec<_> = host.try_iter().filter(|message| message.method == "$startContinuousRun").collect();
assert_eq!(started.iter().map(|message| message.args[0][0]["testIds"].clone()).collect::<Vec<_>>(), [json!(["c"])], "the only continuous profile runs every test of its controller");
assert_eq!(state(cx), (Some(Badge::Icon("eye")), true));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.workspace_storage.lock().unwrap().get(super::LAST_RUN_KEY).map(str::to_owned)), Some("[1]".to_owned()));
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("testing.stopContinuousRun", Vec::new(), window, cx));
cx.run_until_parked();
assert!(started[0].reply.as_ref().unwrap().is_canceled());
assert_eq!(state(cx), (None, false));
}
}