+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
182 lines
5.9 KiB
TypeScript
182 lines
5.9 KiB
TypeScript
import {
|
|
BearerConnectionTarget,
|
|
PrimaryConnectionTarget,
|
|
} from "@t3tools/client-runtime/connection";
|
|
import {
|
|
type DesktopEnvironmentBootstrap,
|
|
EnvironmentId,
|
|
PRIMARY_LOCAL_ENVIRONMENT_ID,
|
|
} from "@t3tools/contracts";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import {
|
|
createDesktopSecondaryBootstrapsReader,
|
|
desktopLocalBackendId,
|
|
desktopLocalConnectionId,
|
|
isDesktopLocalConnectionTarget,
|
|
isWslConnectionTarget,
|
|
} from "./desktopLocal";
|
|
|
|
describe("desktop local connection identity", () => {
|
|
it("preserves the desktop backend instance id", () => {
|
|
const target = new BearerConnectionTarget({
|
|
connectionId: desktopLocalConnectionId("wsl:Ubuntu"),
|
|
environmentId: EnvironmentId.make("environment-wsl"),
|
|
label: "WSL (Ubuntu)",
|
|
});
|
|
|
|
expect(isDesktopLocalConnectionTarget(target)).toBe(true);
|
|
expect(desktopLocalBackendId(target)).toBe("wsl:Ubuntu");
|
|
expect(isWslConnectionTarget(target)).toBe(true);
|
|
});
|
|
|
|
it("does not infer WSL for another desktop-local backend", () => {
|
|
const target = new BearerConnectionTarget({
|
|
connectionId: desktopLocalConnectionId("native-linux"),
|
|
environmentId: EnvironmentId.make("environment-native-linux"),
|
|
label: "Linux",
|
|
});
|
|
|
|
expect(isDesktopLocalConnectionTarget(target)).toBe(true);
|
|
expect(isWslConnectionTarget(target)).toBe(false);
|
|
});
|
|
|
|
it("does not classify the primary environment as desktop-local", () => {
|
|
const target = new PrimaryConnectionTarget({
|
|
environmentId: EnvironmentId.make("environment-primary"),
|
|
httpBaseUrl: "http://127.0.0.1:3773",
|
|
label: "This device",
|
|
wsBaseUrl: "ws://127.0.0.1:3773",
|
|
});
|
|
|
|
expect(isDesktopLocalConnectionTarget(target)).toBe(false);
|
|
expect(desktopLocalBackendId(target)).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("desktop local topology reads", () => {
|
|
it("reuses snapshots when polling returns fresh objects for the same topology", () => {
|
|
const secondary: DesktopEnvironmentBootstrap = {
|
|
id: "wsl:default",
|
|
label: "WSL",
|
|
runningDistro: "Ubuntu",
|
|
httpBaseUrl: "http://127.0.0.1:4000",
|
|
wsBaseUrl: "ws://127.0.0.1:4000",
|
|
bootstrapToken: "bootstrap-1",
|
|
};
|
|
let entries = [secondary];
|
|
const reader = createDesktopSecondaryBootstrapsReader(() => ({
|
|
getLocalEnvironmentBootstraps: () => entries.map((entry) => ({ ...entry })),
|
|
}));
|
|
|
|
const connected = reader.readSnapshot();
|
|
expect(reader.readSnapshot()).toBe(connected);
|
|
expect(reader.readResult()).toEqual({ _tag: "Success", bootstraps: connected });
|
|
expect(reader.readSnapshot()).toBe(connected);
|
|
|
|
entries = [];
|
|
const empty = reader.readSnapshot();
|
|
expect(empty).toEqual([]);
|
|
expect(reader.readSnapshot()).toBe(empty);
|
|
});
|
|
|
|
it.each<Partial<DesktopEnvironmentBootstrap>>([
|
|
{ id: "wsl:Debian" },
|
|
{ label: "Renamed backend" },
|
|
{ runningDistro: "Debian" },
|
|
{ httpBaseUrl: "http://127.0.0.1:4001" },
|
|
{ wsBaseUrl: "ws://127.0.0.1:4001" },
|
|
{ bootstrapToken: "bootstrap-2" },
|
|
])("publishes bootstrap changes: %j", (change) => {
|
|
let secondary: DesktopEnvironmentBootstrap = {
|
|
id: "wsl:default",
|
|
label: "WSL",
|
|
runningDistro: "Ubuntu",
|
|
httpBaseUrl: "http://127.0.0.1:4000",
|
|
wsBaseUrl: "ws://127.0.0.1:4000",
|
|
bootstrapToken: "bootstrap-1",
|
|
};
|
|
const reader = createDesktopSecondaryBootstrapsReader(() => ({
|
|
getLocalEnvironmentBootstraps: () => [{ ...secondary }],
|
|
}));
|
|
const before = reader.readSnapshot();
|
|
secondary = { ...secondary, ...change };
|
|
const after = reader.readSnapshot();
|
|
expect(after).not.toBe(before);
|
|
expect(after).toEqual([secondary]);
|
|
expect(reader.readSnapshot()).toBe(after);
|
|
});
|
|
|
|
it("keeps the empty snapshot stable without a desktop bridge", () => {
|
|
const reader = createDesktopSecondaryBootstrapsReader(() => undefined);
|
|
expect(reader.readSnapshot()).toBe(reader.readSnapshot());
|
|
});
|
|
|
|
it("distinguishes a successful empty topology from a read failure", () => {
|
|
let readBootstraps = () => [];
|
|
const reader = createDesktopSecondaryBootstrapsReader(() => ({
|
|
getLocalEnvironmentBootstraps: () => readBootstraps(),
|
|
}));
|
|
|
|
expect(reader.readResult()).toEqual({ _tag: "Success", bootstraps: [] });
|
|
|
|
const cause = new Error("IPC unavailable");
|
|
readBootstraps = () => {
|
|
throw cause;
|
|
};
|
|
expect(reader.readResult()).toEqual({ _tag: "Failure", cause });
|
|
});
|
|
|
|
it("filters the primary bootstrap from successful topology reads", () => {
|
|
const secondary = {
|
|
id: "wsl:Ubuntu",
|
|
label: "WSL: Ubuntu",
|
|
httpBaseUrl: "http://127.0.0.1:4000",
|
|
wsBaseUrl: "ws://127.0.0.1:4000",
|
|
};
|
|
|
|
const reader = createDesktopSecondaryBootstrapsReader(() => ({
|
|
getLocalEnvironmentBootstraps: () => [
|
|
{
|
|
...secondary,
|
|
id: PRIMARY_LOCAL_ENVIRONMENT_ID,
|
|
label: "Windows",
|
|
},
|
|
secondary,
|
|
],
|
|
}));
|
|
|
|
expect(reader.readResult()).toEqual({ _tag: "Success", bootstraps: [secondary] });
|
|
});
|
|
|
|
it("retains the last successful snapshot only until another read succeeds", () => {
|
|
const secondary = {
|
|
id: "wsl:Ubuntu",
|
|
label: "WSL: Ubuntu",
|
|
httpBaseUrl: "http://127.0.0.1:4000",
|
|
wsBaseUrl: "ws://127.0.0.1:4000",
|
|
};
|
|
let readBootstraps = () => [secondary];
|
|
const reader = createDesktopSecondaryBootstrapsReader(() => ({
|
|
getLocalEnvironmentBootstraps: () => readBootstraps(),
|
|
}));
|
|
|
|
const connectedSnapshot = reader.readSnapshot();
|
|
expect(connectedSnapshot).toEqual([secondary]);
|
|
|
|
readBootstraps = () => {
|
|
throw new Error("IPC unavailable");
|
|
};
|
|
expect(reader.readSnapshot()).toBe(connectedSnapshot);
|
|
|
|
readBootstraps = () => [];
|
|
const removedSnapshot = reader.readSnapshot();
|
|
expect(removedSnapshot).toEqual([]);
|
|
|
|
readBootstraps = () => {
|
|
throw new Error("IPC unavailable again");
|
|
};
|
|
expect(reader.readSnapshot()).toBe(removedSnapshot);
|
|
});
|
|
});
|