Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions e2e/team-session-states.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect, test, type Page } from "@playwright/test";
import { TEAM_REFUSALS } from "../src/shared/api/teamRefusals";
import { TEAM_WARNINGS } from "../src/shared/api/backendWarnings";
import { openApp, row, waitForIdle } from "./support/app";
import { ADMIN_INVITE, MEMBER_INVITE, joinTeam, menu, space, toast } from "./support/team";

Expand Down Expand Up @@ -121,6 +123,66 @@ test("a session kept here for the next start says so in its own words", async ({
await expect(toast(page, "wasn’t saved to the team")).toHaveCount(0);
});

test("a legacy team session defers Start while its data is kept on this computer", async ({ page }) => {
await inAdsTeam(page);
await page.evaluate((why) => {
const { __TAURI_INTERNALS__: internals } = window as unknown as M;
const invoke = internals.invoke.bind(internals);
let recovering = false;
let first = true;
internals.invoke = async (cmd, args) => {
if (cmd === "launch" && args?.profileId === "tp-ads-1") {
recovering = first;
first = false;
if (recovering) throw why;
}
const reply = await invoke(cmd, args);
if (cmd === "team_sessions" && recovering && Array.isArray(reply)) {
return [...reply, { team_id: "", profile_id: "", name: "", mine: false, local_only: true }];
}
return reply;
};
}, TEAM_REFUSALS.localRecovery);

const fb = row(page, "FB Ads 01");
await fb.hover();
await fb.getByRole("button", { name: "Start" }).click();
await expect(toast(page, "Preserving older session data"))
.toContainText("Try again in a moment.");
await expect(status(page, "FB Ads 01")).not.toContainText(/Failed|Saving/);

await requestQuit(page);
await expect(question(page).locator("[data-confirm-items] li"))
.toHaveText(["Older team sessionKeeping its browser data on this computer."]);
await question(page).getByRole("button", { name: "Cancel" }).click();
await warn(page, TEAM_WARNINGS.localSessionKept);
await expect(toast(page, "Older team session kept on this computer"))
.toContainText("ShardBrowser couldn’t verify the original team membership.");

await fb.hover();
await fb.getByRole("button", { name: "Start" }).click();
await expect(status(page, "FB Ads 01")).toContainText("Running");
});

test("bulk Start counts a configuration kept on this computer as deferred", async ({ page }) => {
await inAdsTeam(page);
await page.evaluate((why) => {
const { __TAURI_INTERNALS__: internals } = window as unknown as M;
const invoke = internals.invoke.bind(internals);
internals.invoke = (cmd, args) => cmd === "launch" && args?.profileId === "tp-ads-1"
? Promise.reject(why)
: invoke(cmd, args);
}, TEAM_REFUSALS.localRecovery);
for (const name of ["FB Ads 01", "FB Ads 02"]) {
await status(page, name).click({ modifiers: ["ControlOrMeta"] });
}
await page.getByRole("toolbar", { name: "2 selected" }).getByRole("button", { name: "Start", exact: true }).click();
await expect(toast(page, "Started 1 of 2 profiles")).not.toContainText("failed");
await expect(toast(page, "Preserving older session data")).toBeVisible();
await expect(status(page, "FB Ads 01")).not.toContainText("Failed");
await expect(status(page, "FB Ads 02")).toContainText("Running");
});

test("the clock and missing extensions warnings are said in words", async ({ page }) => {
await inAdsTeam(page);
await warn(page, "This computer's clock is 7 min ahead of the team server's, so the team's permission runs short: set the clock right, or FB Ads 01 may close when the permission runs out.");
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,7 @@ async fn team_leave(app: tauri::AppHandle, team_id: String) -> Result<team::Spac
// Its profiles open here go back first: once it is left, nothing reaches it.
space::open::close_team_and_wait(&team_id, space::open::QUIT_WAIT).await;
team::leave(&team_id).map_err(|e| e.to_string())?;
space::open::discard_unowned_team(&team_id);
space::perm::forget(&team_id);
space::cache::forget(&team_id);
space::secrets::forget(&team_id);
Expand Down
14 changes: 11 additions & 3 deletions src-tauri/src/space/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,20 @@ impl TeamClient {

/// The client for a team this launcher has joined, held to the key kept for it.
pub fn for_team(team_id: &str) -> anyhow::Result<Self> {
let reach = crate::team::reach(team_id)?;
Ok(Self::for_saved_team(team_id, crate::team::reach(team_id)?))
}

/// A shared session can use only the membership that opened it.
pub fn for_team_session(team_id: &str, owner: &str) -> anyhow::Result<Self> {
Ok(Self::for_saved_team(team_id, crate::team::session_reach(team_id, owner)?))
}

fn for_saved_team(team_id: &str, reach: crate::team::Reach) -> Self {
let mut c = TeamClient::reaching(&reach.server, &reach.token, &reach.device_id, team_wire::key_from_text(&reach.key));
c.team_id = Some(team_id.to_string());
// A reaper leaves a lost token to the launcher: it writes nothing of the team's.
c.report_lost = !super::reap::in_reaper();
Ok(c)
c
}

/// The client for the server holding the person's own space for sync. A
Expand Down Expand Up @@ -1543,7 +1551,7 @@ mod tests {
}
}
// The team token, and sync's, are handed out only to the client.
let hands_out = line.contains("team::reach(") || line.contains("sync_reach(");
let hands_out = line.contains("team::reach(") || line.contains("session_reach(") || line.contains("sync_reach(");
if (hands_out && rel != "team.rs") || (rel != "team.rs" && line.contains("fn reach(")) {
bad.push(format!("{rel}:{}: {}", n + 1, line.trim()));
}
Expand Down
14 changes: 10 additions & 4 deletions src-tauri/src/space/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,20 @@ fn close_team_profile(team_id: &str, id: &str) {
fn revoke(team_id: &str, lost: impl Fn(&str, &str) -> bool, tell: &Tell) {
let name = crate::team::link(team_id).ok().flatten().map(|t| t.name);
let Some(saved) = crate::team::revoke(team_id, lost).transpose() else { return };
close_and_wipe_open_team_profiles(team_id);
perm::forget(team_id);
super::cache::forget(team_id);
super::secrets::forget(team_id);
match saved {
Ok(st) => {
super::open::discard_unowned_team(team_id);
tell("space-changed", serde_json::to_value(&st.space).unwrap_or_default());
let name = name.unwrap_or_else(|| "A team".into());
crate::notify_warning(format!("{name} withdrew this launcher's access."));
}
Err(e) => eprintln!("[launcher] team {team_id} withdrew access, and saving that failed: {e:#}"),
Err(e) => {
close_and_wipe_open_team_profiles(team_id);
eprintln!("[launcher] team {team_id} withdrew access, and saving that failed: {e:#}");
}
}
}

Expand All @@ -448,16 +451,19 @@ fn close_and_wipe_open_team_profiles(team_id: &str) {
fn replaced(team_id: &str, lost: impl Fn(&str, &str) -> bool, tell: &Tell) {
let name = crate::team::link(team_id).ok().flatten().map(|t| t.name);
let Some(saved) = crate::team::token_replaced(team_id, lost).transpose() else { return };
close_open_team_profiles(team_id);
perm::forget(team_id);
super::cache::forget(team_id);
match saved {
Ok(st) => {
super::open::close_team_sessions_with_end(team_id, super::open::End::Keep);
tell("space-changed", serde_json::to_value(&st.space).unwrap_or_default());
let name = name.unwrap_or_else(|| "A team".into());
crate::notify_warning(format!("{name} replaced this launcher's invite: paste the new one from the team's admin."));
}
Err(e) => eprintln!("[launcher] team {team_id} replaced this token, and saving that failed: {e:#}"),
Err(e) => {
close_open_team_profiles(team_id);
eprintln!("[launcher] team {team_id} replaced this token, and saving that failed: {e:#}");
}
}
}

Expand Down
Loading