| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814 |
- import { describe, expect, it } from "vitest";
- import type { RemoteTarget, RemoteWorkspaceSessionEntry } from "@zcode/shared";
- import {
- buildRemoteWorkspaceIdentity,
- buildRemoteWorkspaceSessionMutation,
- buildPersistedWorkspaceSessionEntries,
- buildRemoteWorkspaceSessionEntryMap,
- createRemoteTargetFromSnapshot,
- createRemoteTargetSnapshot,
- findMatchingRemoteWorkspaceSessionEntry,
- formatRemoteWorkspaceHeaderHostLabel,
- formatRemoteWorkspaceTargetSubtitle,
- hasRemoteWorkspaceIdentity,
- readPersistedWorkspaceSessionEntries,
- removeRemoteWorkspaceSessionEntries,
- upsertRemoteWorkspaceSessionEntries,
- } from "@/lib/remoteWorkspaceHistory.js";
- describe("remoteWorkspaceHistory helpers", () => {
- it("reads combined session snapshots directly", () => {
- expect(
- readPersistedWorkspaceSessionEntries({
- lastWorkspaceSession: [
- {
- kind: "local",
- workspacePath: "/tmp/local-a",
- },
- {
- kind: "remote",
- workspacePath: "/workspace/demo",
- target: {
- kind: "docker",
- container: "demo",
- },
- lastOpenedAt: 1,
- lastConnectionStatus: "failed",
- },
- ],
- }),
- ).toHaveLength(2);
- });
- it("restores a rollback conversation identity from its bound Source profile", () => {
- const workspacePath = "/home/dev/.zcode/workspace/default";
- const legacyIdentity = `remote:ssh:localhost:2222:dev:${workspacePath}`;
- const stableIdentity = `remote:server:source-1:${workspacePath}`;
- expect(
- readPersistedWorkspaceSessionEntries({
- lastWorkspaceSession: [
- {
- kind: "remote",
- workspacePath,
- workspaceIdentity: legacyIdentity,
- workspacePurpose: "conversation",
- target: {
- kind: "ssh",
- host: "localhost",
- port: 2222,
- username: "dev",
- },
- lastOpenedAt: 1,
- lastConnectionStatus: "connected",
- },
- ],
- sourceServerWorkspaceHistory: [],
- connectionProfiles: [
- {
- profileId: "profile-1",
- sourceServerId: "source-1",
- transport: "ssh",
- target: {
- kind: "ssh",
- host: "localhost",
- port: 2222,
- username: "dev",
- },
- createdAt: 1,
- },
- ],
- remoteConversationWorkspaceBySourceServerId: {
- "source-1": { workspacePath, lastResolvedAt: 1 },
- },
- }),
- ).toEqual([
- expect.objectContaining({
- workspaceIdentity: stableIdentity,
- workspacePurpose: "conversation",
- }),
- ]);
- });
- it("keeps an ambiguous rollback conversation identity fail-closed", () => {
- const workspacePath = "/home/dev/.zcode/workspace/default";
- const legacyIdentity = `remote:ssh:localhost:2222:dev:${workspacePath}`;
- const target = {
- kind: "ssh" as const,
- host: "localhost",
- port: 2222,
- username: "dev",
- };
- expect(
- readPersistedWorkspaceSessionEntries({
- lastWorkspaceSession: [
- {
- kind: "remote",
- workspacePath,
- workspaceIdentity: legacyIdentity,
- workspacePurpose: "conversation",
- target,
- lastOpenedAt: 1,
- lastConnectionStatus: "connected",
- },
- ],
- connectionProfiles: [
- {
- profileId: "profile-1",
- sourceServerId: "source-1",
- transport: "ssh",
- target,
- createdAt: 1,
- },
- {
- profileId: "profile-2",
- sourceServerId: "source-2",
- transport: "ssh",
- target,
- createdAt: 2,
- },
- ],
- remoteConversationWorkspaceBySourceServerId: {
- "source-1": { workspacePath, lastResolvedAt: 1 },
- "source-2": { workspacePath, lastResolvedAt: 2 },
- },
- }),
- ).toEqual([expect.objectContaining({ workspaceIdentity: legacyIdentity })]);
- });
- it("serializes local and remote tabs into a combined session snapshot", () => {
- const remoteEntryMap = buildRemoteWorkspaceSessionEntryMap([
- {
- kind: "remote",
- workspacePath: "/workspace/demo",
- workspaceIdentity: "remote:docker:demo:/workspace/demo",
- target: {
- kind: "docker",
- container: "demo",
- },
- lastOpenedAt: 1,
- lastConnectionStatus: "failed",
- },
- ]);
- expect(
- buildPersistedWorkspaceSessionEntries(
- [
- {
- id: "local-1",
- kind: "workspace",
- workspacePath: "/tmp/local-a",
- label: "local-a",
- workspacePurpose: "conversation",
- },
- {
- id: "remote-1",
- kind: "workspace",
- workspacePath: "/workspace/demo",
- label: "demo",
- remoteTarget: {
- kind: "docker",
- container: "demo",
- },
- workspaceIdentity: "remote:docker:demo:/workspace/demo",
- },
- ],
- remoteEntryMap,
- ),
- ).toEqual([
- {
- kind: "local",
- workspacePath: "/tmp/local-a",
- workspacePurpose: "conversation",
- },
- {
- kind: "remote",
- workspacePath: "/workspace/demo",
- workspaceIdentity: "remote:docker:demo:/workspace/demo",
- target: {
- kind: "docker",
- container: "demo",
- },
- lastOpenedAt: 1,
- lastConnectionStatus: "failed",
- },
- ]);
- });
- it("reuses the existing SSH password credential key when updating a remote session", () => {
- const snapshot = createRemoteTargetSnapshot(
- "remote:ssh:demo.internal:22:root:/workspace/demo",
- {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- password: "secret",
- },
- {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- passwordCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:password",
- },
- );
- expect(snapshot).toMatchObject({
- kind: "ssh",
- passwordCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:password",
- });
- });
- it("hydrates an SSH target from a persisted snapshot", () => {
- const target = createRemoteTargetFromSnapshot(
- {
- kind: "ssh",
- host: "demo.internal",
- port: 2222,
- username: "root",
- privateKeyPath: "~/.ssh/id_ed25519",
- passwordCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:password",
- privateKeyPassphraseCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:private-key-passphrase",
- },
- {
- password: "secret",
- privateKeyPassphrase: "key-secret",
- },
- );
- expect(target).toEqual({
- kind: "ssh",
- host: "demo.internal",
- port: 2222,
- username: "root",
- privateKeyPath: "~/.ssh/id_ed25519",
- password: "secret",
- privateKeyPassphrase: "key-secret",
- });
- });
- it("persists SSH asset install mode and drops historical resource packages", () => {
- const snapshot = createRemoteTargetSnapshot(
- "remote:ssh:demo.internal:22:root:/workspace/demo",
- {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- assetInstallMode: "remote-download",
- resourcePackages: {
- selectedPackageIds: ["server-bundle", "node-runtime", "glm"],
- },
- },
- );
- expect(snapshot).toMatchObject({
- kind: "ssh",
- assetInstallMode: "remote-download",
- });
- expect(snapshot).not.toHaveProperty("resourcePackages");
- expect(
- createRemoteTargetFromSnapshot(snapshot, {
- password: null,
- privateKeyPassphrase: null,
- }),
- ).toMatchObject({
- kind: "ssh",
- assetInstallMode: "remote-download",
- });
- expect(
- createRemoteTargetFromSnapshot(snapshot, {
- password: null,
- privateKeyPassphrase: null,
- }),
- ).not.toHaveProperty("resourcePackages");
- });
- it("persists and hydrates SSH config alias metadata", () => {
- const snapshot = createRemoteTargetSnapshot("remote:ssh:localhost:2223:root:/root", {
- kind: "ssh",
- host: "localhost",
- port: 2223,
- username: "root",
- password: "secret",
- sshConfigAlias: "linux-arm64",
- });
- expect(snapshot).toMatchObject({
- kind: "ssh",
- sshConfigAlias: "linux-arm64",
- });
- expect(
- createRemoteTargetFromSnapshot(snapshot, {
- password: "secret",
- privateKeyPassphrase: null,
- }),
- ).toMatchObject({
- kind: "ssh",
- sshConfigAlias: "linux-arm64",
- });
- });
- it("stores a separate credential key for SSH private key passphrase", () => {
- const snapshot = createRemoteTargetSnapshot(
- "remote:ssh:demo.internal:22:root:/workspace/demo",
- {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- privateKeyPath: "~/.ssh/id_ed25519",
- privateKeyPassphrase: "key-secret",
- },
- {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- privateKeyPath: "~/.ssh/id_ed25519",
- privateKeyPassphraseCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:private-key-passphrase",
- },
- );
- expect(snapshot).toMatchObject({
- kind: "ssh",
- privateKeyPassphraseCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:private-key-passphrase",
- });
- });
- it("matches an existing remote session by workspace path and target identity", () => {
- const target: RemoteTarget = {
- kind: "docker",
- container: "demo-container",
- };
- const sessions = [
- {
- kind: "remote" as const,
- workspacePath: "/workspace/demo",
- target: {
- kind: "docker" as const,
- container: "demo-container",
- },
- lastOpenedAt: 10,
- lastConnectionStatus: "connected" as const,
- },
- ];
- expect(
- findMatchingRemoteWorkspaceSessionEntry(sessions, "/workspace/demo", target)?.workspacePath,
- ).toBe("/workspace/demo");
- });
- it("keeps the newest remote session at the top when upserting", () => {
- const updated = upsertRemoteWorkspaceSessionEntries(
- [
- {
- kind: "remote",
- workspacePath: "/workspace/older",
- target: {
- kind: "wsl",
- distro: "Ubuntu",
- },
- lastOpenedAt: 1,
- lastConnectionStatus: "connected",
- },
- ],
- {
- kind: "remote",
- workspacePath: "/workspace/newer",
- target: {
- kind: "docker",
- container: "demo",
- },
- lastOpenedAt: 2,
- lastConnectionStatus: "failed",
- lastConnectionError: "refused",
- },
- );
- expect(updated.map((entry) => entry.workspacePath)).toEqual([
- "/workspace/newer",
- "/workspace/older",
- ]);
- });
- it("formats a readable remote target subtitle", () => {
- expect(
- formatRemoteWorkspaceTargetSubtitle({
- kind: "wsl",
- distro: "Ubuntu-24.04",
- }),
- ).toBe("WSL · Ubuntu-24.04");
- expect(
- formatRemoteWorkspaceTargetSubtitle({
- kind: "wsl",
- distro: "Ubuntu-24.04",
- user: "root",
- }),
- ).toBe("WSL · Ubuntu-24.04 · root");
- });
- it("uses explicit WSL user in workspace identity and snapshot roundtrip", () => {
- const target: RemoteTarget = {
- kind: "wsl",
- distro: "Ubuntu-24.04",
- user: " root ",
- };
- const snapshot = createRemoteTargetSnapshot(
- "remote:wsl:Ubuntu-24.04:root:/workspace/demo",
- target,
- );
- expect(buildRemoteWorkspaceIdentity("/workspace/demo", target)).toBe(
- "remote:wsl:Ubuntu-24.04:root:/workspace/demo",
- );
- expect(snapshot).toEqual({
- kind: "wsl",
- distro: "Ubuntu-24.04",
- user: "root",
- });
- expect(
- createRemoteTargetFromSnapshot(snapshot, {
- password: null,
- privateKeyPassphrase: null,
- }),
- ).toEqual({
- kind: "wsl",
- distro: "Ubuntu-24.04",
- user: "root",
- });
- expect(formatRemoteWorkspaceHeaderHostLabel(snapshot)).toBe("wsl:Ubuntu-24.04:root");
- });
- it("persists and hydrates server remote target credentials", () => {
- const workspaceKey = "remote:server:studio-server-01:/srv/project";
- const target: RemoteTarget = {
- kind: "server",
- url: "https://studio.example.com/zcode/",
- name: "Studio Server",
- serverId: "Studio Server 01",
- workspacePath: "/srv/project",
- token: "server-secret",
- };
- const snapshot = createRemoteTargetSnapshot(workspaceKey, target);
- expect(buildRemoteWorkspaceIdentity("\\srv\\project\\", target)).toBe(workspaceKey);
- expect(snapshot).toEqual({
- kind: "server",
- url: "https://studio.example.com/zcode/",
- name: "Studio Server",
- serverId: "Studio Server 01",
- workspacePath: "/srv/project",
- tokenCredentialKey:
- "remote-workspace:remote:server:studio-server-01:/srv/project:server-token",
- });
- expect(
- createRemoteTargetFromSnapshot(snapshot, {
- password: null,
- privateKeyPassphrase: null,
- token: "server-secret",
- }),
- ).toEqual(target);
- expect(formatRemoteWorkspaceTargetSubtitle(snapshot)).toBe("Server · Studio Server");
- expect(formatRemoteWorkspaceHeaderHostLabel(snapshot)).toBe("studio.example.com");
- });
- it("keeps the legacy WSL identity when no user is specified", () => {
- expect(
- buildRemoteWorkspaceIdentity("/workspace/demo", {
- kind: "wsl",
- distro: "Ubuntu-24.04",
- }),
- ).toBe("remote:wsl:Ubuntu-24.04:/workspace/demo");
- });
- it("keeps omitted WSL user compatible with legacy history while separating root", () => {
- const sessions = [
- {
- kind: "remote" as const,
- workspacePath: "/workspace/demo",
- workspaceIdentity: "remote:wsl:Ubuntu-24.04:/workspace/demo",
- target: {
- kind: "wsl" as const,
- distro: "Ubuntu-24.04",
- },
- lastOpenedAt: 10,
- lastConnectionStatus: "connected" as const,
- },
- ];
- expect(
- findMatchingRemoteWorkspaceSessionEntry(sessions, "/workspace/demo", {
- kind: "wsl",
- distro: "Ubuntu-24.04",
- user: " ",
- })?.workspaceIdentity,
- ).toBe("remote:wsl:Ubuntu-24.04:/workspace/demo");
- expect(
- findMatchingRemoteWorkspaceSessionEntry(sessions, "/workspace/demo", {
- kind: "wsl",
- distro: "Ubuntu-24.04",
- user: "root",
- }),
- ).toBeNull();
- });
- it("formats a compact remote host label for workspace header", () => {
- expect(
- formatRemoteWorkspaceHeaderHostLabel({
- kind: "ssh",
- host: "10.0.0.8",
- port: 22,
- username: "dev",
- }),
- ).toBe("10.0.0.8");
- expect(
- formatRemoteWorkspaceHeaderHostLabel({
- kind: "ssh",
- host: "dev.internal",
- port: 2222,
- username: "dev",
- }),
- ).toBe("dev.internal:2222");
- });
- it("treats disconnected remote tabs as remote identities", () => {
- expect(
- hasRemoteWorkspaceIdentity({
- workspaceIdentity: "remote:docker:demo:/workspace/demo",
- }),
- ).toBe(true);
- expect(
- hasRemoteWorkspaceIdentity({
- workspacePath: "/tmp/demo",
- } as never),
- ).toBe(false);
- });
- it("keeps the previous SSH credential key when a reconnect failure is recorded", () => {
- const mutation = buildRemoteWorkspaceSessionMutation({
- remoteSessions: [
- {
- kind: "remote",
- workspacePath: "/workspace/demo",
- target: {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- passwordCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:password",
- },
- lastOpenedAt: 10,
- lastConnectionStatus: "connected",
- },
- ],
- workspacePath: "/workspace/demo",
- target: {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- },
- lastConnectionStatus: "failed",
- lastConnectionError: "connection refused",
- touchOpenedAt: false,
- });
- expect(mutation.entry.target).toMatchObject({
- kind: "ssh",
- passwordCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:password",
- });
- expect(mutation.credentialKeysToDelete).toEqual([]);
- });
- it("does not create workspace-scoped SSH credentials for a Source Server identity", () => {
- const mutation = buildRemoteWorkspaceSessionMutation({
- remoteSessions: [],
- workspacePath: "/srv/project",
- workspaceIdentity: "remote:server:3cd4f9da-cd79-426c-9d70-75f36e9f6a87:/srv/project",
- target: {
- kind: "ssh",
- host: "dev.example.com",
- username: "alice",
- password: "profile-owned-password",
- },
- lastConnectionStatus: "connected",
- touchOpenedAt: true,
- });
- expect(mutation.entry.target).toEqual({
- kind: "ssh",
- host: "dev.example.com",
- port: undefined,
- username: "alice",
- assetInstallMode: undefined,
- privateKeyPath: undefined,
- passwordCredentialKey: undefined,
- privateKeyPassphraseCredentialKey: undefined,
- });
- expect(mutation.credentialsToSave).toEqual([]);
- });
- it("rekeys a legacy route entry to the Host stable identity without duplicating history or deleting rollback credentials", () => {
- const legacyIdentity = "remote:ssh:dev.example.com:22:alice:/srv/project";
- const stableIdentity = "remote:server:3cd4f9da-cd79-426c-9d70-75f36e9f6a87:/srv/project";
- const mutation = buildRemoteWorkspaceSessionMutation({
- remoteSessions: [
- {
- kind: "remote",
- workspacePath: "/srv/project",
- localWorkspacePath: "/Users/alice/project",
- workspaceIdentity: legacyIdentity,
- target: {
- kind: "ssh",
- host: "dev.example.com",
- port: 22,
- username: "alice",
- passwordCredentialKey: `remote-workspace:${legacyIdentity}:password`,
- },
- lastOpenedAt: 123,
- lastConnectionStatus: "connected",
- },
- ],
- workspacePath: "/srv/project",
- workspaceIdentity: stableIdentity,
- target: {
- kind: "ssh",
- host: "dev.example.com",
- port: 22,
- username: "alice",
- },
- lastConnectionStatus: "failed",
- lastConnectionError: "offline",
- touchOpenedAt: false,
- });
- expect(mutation.nextRemoteSessions).toHaveLength(1);
- expect(mutation.entry).toMatchObject({
- workspaceIdentity: stableIdentity,
- localWorkspacePath: "/Users/alice/project",
- lastOpenedAt: 123,
- });
- expect(mutation.credentialKeysToDelete).toEqual([]);
- });
- describe("credential ownership during history cleanup", () => {
- const profileEntry: RemoteWorkspaceSessionEntry = {
- kind: "remote",
- workspacePath: "/srv/project",
- workspaceIdentity: "remote:ssh:dev.example.com:22:dev:/srv/project",
- target: {
- kind: "ssh",
- host: "dev.example.com",
- username: "dev",
- passwordCredentialKey: "connection-profile:profile-1:password",
- privateKeyPassphraseCredentialKey: "connection-profile:profile-1:private-key-passphrase",
- },
- lastOpenedAt: 1,
- lastConnectionStatus: "connected",
- };
- it.each(["connected", "failed"] as const)(
- "preserves Profile secrets when rekeying a %s workspace",
- (lastConnectionStatus) => {
- const mutation = buildRemoteWorkspaceSessionMutation({
- remoteSessions: [profileEntry],
- workspacePath: profileEntry.workspacePath,
- workspaceIdentity: "remote:server:source-1:/srv/project",
- target: { kind: "ssh", host: "dev.example.com", username: "dev" },
- lastConnectionStatus,
- touchOpenedAt: false,
- });
- expect(mutation.nextRemoteSessions).toHaveLength(1);
- expect(mutation.entry.workspaceIdentity).toBe("remote:server:source-1:/srv/project");
- expect(mutation.credentialKeysToDelete).toEqual([]);
- expect(mutation.credentialsToSave).toEqual([]);
- if (lastConnectionStatus === "connected") {
- expect(mutation.entry.target).not.toHaveProperty(
- "passwordCredentialKey",
- "connection-profile:profile-1:password",
- );
- expect(mutation.entry.target).not.toHaveProperty(
- "privateKeyPassphraseCredentialKey",
- "connection-profile:profile-1:private-key-passphrase",
- );
- }
- },
- );
- it("does not delete Profile secrets when their history entry is evicted", () => {
- const mutation = buildRemoteWorkspaceSessionMutation({
- remoteSessions: [
- profileEntry,
- ...Array.from(
- { length: 19 },
- (_, index): RemoteWorkspaceSessionEntry => ({
- kind: "remote",
- workspacePath: `/srv/other-${index}`,
- target: { kind: "docker", container: "fixture" },
- lastOpenedAt: index + 2,
- lastConnectionStatus: "connected",
- }),
- ),
- ],
- workspacePath: "/srv/new",
- target: { kind: "docker", container: "fixture" },
- lastConnectionStatus: "connected",
- touchOpenedAt: true,
- });
- expect(mutation.nextRemoteSessions).toHaveLength(20);
- expect(mutation.nextRemoteSessions).not.toContain(profileEntry);
- expect(mutation.credentialKeysToDelete).toEqual([]);
- });
- it("removes history without deleting secrets owned by its connection Profile", () => {
- const result = removeRemoteWorkspaceSessionEntries(
- [profileEntry],
- [profileEntry.workspaceIdentity!],
- );
- expect(result.nextRemoteSessions).toEqual([]);
- expect(result.credentialKeysToDelete).toEqual([]);
- });
- });
- it("stores the local workspace path used for remote MCP path rewriting", () => {
- const mutation = buildRemoteWorkspaceSessionMutation({
- remoteSessions: [],
- workspacePath: "/srv/project",
- workspaceIdentity: "remote:ssh:dev.example.com:22:alice:/srv/project",
- target: {
- kind: "ssh",
- host: "dev.example.com",
- username: "alice",
- },
- lastConnectionStatus: "connected",
- touchOpenedAt: true,
- localWorkspacePath: "/Users/alice/project",
- } as Parameters<typeof buildRemoteWorkspaceSessionMutation>[0] & {
- localWorkspacePath: string;
- });
- expect((mutation.entry as { localWorkspacePath?: string }).localWorkspacePath).toBe(
- "/Users/alice/project",
- );
- });
- it("removes remote workspace history entries and returns their SSH credential keys", () => {
- const result = removeRemoteWorkspaceSessionEntries(
- [
- {
- kind: "remote",
- workspacePath: "/workspace/demo",
- workspaceIdentity: "remote:ssh:demo.internal:22:root:/workspace/demo",
- target: {
- kind: "ssh",
- host: "demo.internal",
- username: "root",
- passwordCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:password",
- privateKeyPassphraseCredentialKey:
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:private-key-passphrase",
- },
- lastOpenedAt: 10,
- lastConnectionStatus: "connected",
- },
- {
- kind: "remote",
- workspacePath: "/workspace/other",
- workspaceIdentity: "remote:docker:demo:/workspace/other",
- target: {
- kind: "docker",
- container: "demo",
- },
- lastOpenedAt: 9,
- lastConnectionStatus: "failed",
- },
- ],
- ["remote:ssh:demo.internal:22:root:/workspace/demo"],
- );
- expect(result.nextRemoteSessions).toEqual([
- {
- kind: "remote",
- workspacePath: "/workspace/other",
- workspaceIdentity: "remote:docker:demo:/workspace/other",
- target: {
- kind: "docker",
- container: "demo",
- },
- lastOpenedAt: 9,
- lastConnectionStatus: "failed",
- },
- ]);
- expect(result.credentialKeysToDelete).toEqual([
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:password",
- "remote-workspace:remote:ssh:demo.internal:22:root:/workspace/demo:private-key-passphrase",
- ]);
- });
- });
|