Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
78 lines
3.0 KiB
TypeScript
78 lines
3.0 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { applyEphemeralHostDistroUpdate, applyEphemeralHostsUpdate, isSavedVaultHost, splitHostsUpdateByEphemeral } from "./ephemeralHosts";
|
|
import type { Host } from "./models";
|
|
|
|
const makeHost = (id: string, overrides: Partial<Host> = {}): Host => ({
|
|
id,
|
|
label: id,
|
|
hostname: `${id}.example.com`,
|
|
username: "root",
|
|
group: "",
|
|
tags: [],
|
|
os: "linux",
|
|
...overrides,
|
|
});
|
|
|
|
test("splitHostsUpdateByEphemeral separates ephemeral hosts from vault hosts", () => {
|
|
const vaultHost = makeHost("vault-1");
|
|
const ephemeralHost = makeHost("ephemeral-1", { password: "secret" });
|
|
|
|
const { vaultHosts, ephemeralHosts } = splitHostsUpdateByEphemeral(
|
|
[vaultHost, ephemeralHost],
|
|
new Set(["ephemeral-1"]),
|
|
);
|
|
|
|
assert.deepEqual(vaultHosts, [vaultHost]);
|
|
assert.deepEqual(ephemeralHosts, [ephemeralHost]);
|
|
});
|
|
|
|
test("splitHostsUpdateByEphemeral passes everything through when no ephemeral ids", () => {
|
|
const hosts = [makeHost("a"), makeHost("b")];
|
|
const { vaultHosts, ephemeralHosts } = splitHostsUpdateByEphemeral(hosts, new Set());
|
|
assert.deepEqual(vaultHosts, hosts);
|
|
assert.deepEqual(ephemeralHosts, []);
|
|
});
|
|
|
|
test("applyEphemeralHostsUpdate replaces matching hosts and keeps the rest", () => {
|
|
const original = [
|
|
makeHost("a", { password: "one-time" }),
|
|
makeHost("b", { password: "other" }),
|
|
];
|
|
const updated = makeHost("a", { password: "one-time", sftpFollowTerminalCwd: true });
|
|
|
|
const next = applyEphemeralHostsUpdate(original, [updated]);
|
|
|
|
assert.equal(next.length, 2);
|
|
assert.equal(next[0], updated);
|
|
assert.equal(next[1], original[1]);
|
|
});
|
|
|
|
test("applyEphemeralHostsUpdate returns previous array when nothing updated", () => {
|
|
const original = [makeHost("a")];
|
|
assert.equal(applyEphemeralHostsUpdate(original, []), original);
|
|
});
|
|
|
|
test("isSavedVaultHost is false for missing or ephemeral hosts", () => {
|
|
assert.equal(isSavedVaultHost(makeHost("a")), true);
|
|
assert.equal(isSavedVaultHost(makeHost("a", { ephemeral: true })), false);
|
|
assert.equal(isSavedVaultHost(null), false);
|
|
assert.equal(isSavedVaultHost(undefined), false);
|
|
});
|
|
|
|
test("temporary host detection reaches AI without changing other hosts or reviving closed sessions", async () => {
|
|
const { buildAITerminalSessionInfo } = await import('./buildAITerminalSessionInfo');
|
|
const other = makeHost('other');
|
|
for (const [distro, os] of [['ubuntu', 'linux'], ['darwin', 'macos'], ['windows', 'windows']]) {
|
|
const target = makeHost('quick-connect', { ephemeral: true });
|
|
const next = applyEphemeralHostDistroUpdate([target, other], target.id, distro);
|
|
assert.equal(buildAITerminalSessionInfo(undefined, next[0], 'macos').os, os);
|
|
assert.equal(next[0].ephemeral, true);
|
|
assert.equal(next[1], other);
|
|
assert.equal(applyEphemeralHostDistroUpdate(next, target.id, distro), next);
|
|
const closed = [other];
|
|
assert.equal(applyEphemeralHostDistroUpdate(closed, target.id, distro), closed);
|
|
}
|
|
});
|