Skip to content
Merged
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
6 changes: 6 additions & 0 deletions apps/web/src/spin/environments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ describe("what this client forgets of what it saved", () => {
expect(remove.mock.calls.map(([id]) => id)).toEqual(forgotten);
});

it("leaves an entry at an address the page does not give, whatever it tells", () => {
const { remove, forget } = forgetter();
forget(savedEach(["e1", w1], ["e3", "https://saved.example.com"]), listing());
expect(remove.mock.calls.map(([id]) => id)).toEqual(["e1"]);
});

it("forgets nothing before it has read what it saved", () => {
const { remove, forget } = forgetter();
forget({ isReady: false, entries: savedEach(["e1", w1]).entries }, listing());
Expand Down
16 changes: 14 additions & 2 deletions apps/web/src/spin/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,19 @@ export function savedEnvironmentId(
return undefined;
}

/** Whether an address is one the page gives a workspace: <workspace>.spinbox.invalid. */
function isPageAddress(httpBaseUrl: string): boolean {
try {
return new URL(httpBaseUrl).hostname.endsWith(".spinbox.invalid");
} catch {
return false;
}
}

/**
* Each environment saved at no address of a workspace the page told; undefined before it told a list.
* Each environment saved at a page address (<workspace>.spinbox.invalid) no workspace the page told
* has; undefined before it told a list. Only the page's own addresses: it can say a workspace of
* its own is gone, never that an entry it did not make is not wanted.
* By address, not T3's id: the id is kept in the agent's home, which another workspace may mount, so
* one saved for a deleted workspace would pass for that one and block its pairing.
*/
Expand All @@ -204,7 +215,8 @@ function unlistedEnvironmentIds(
for (const [id, entry] of catalog.entries) {
const profile = Option.getOrUndefined(entry.profile);
const at = profile?._tag === "BearerConnectionProfile" ? profile.httpBaseUrl : undefined;
if (at === undefined || !addresses.some((address) => sameBase(address, at))) unlisted.push(id);
if (at === undefined || !isPageAddress(at)) continue;
if (!addresses.some((address) => sameBase(address, at))) unlisted.push(id);
}
return unlisted;
}
Expand Down
Loading