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
93 lines
2.6 KiB
TypeScript
93 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import type { GroupConfig, Host, ManagedSource } from "./models.ts";
|
|
import { buildVaultGroupDeletion } from "./vaultGroupDeletion.ts";
|
|
|
|
const host = (id: string, group: string, managedSourceId?: string): Host => ({
|
|
id,
|
|
label: id,
|
|
hostname: `${id}.example.com`,
|
|
port: 22,
|
|
username: "root",
|
|
protocol: "ssh",
|
|
tags: [],
|
|
os: "linux",
|
|
group,
|
|
managedSourceId,
|
|
});
|
|
|
|
test("bulk group deletion collapses nested choices and updates related vault data once", () => {
|
|
const managedSources: ManagedSource[] = [{
|
|
id: "managed-a",
|
|
type: "ssh_config",
|
|
filePath: "/tmp/config",
|
|
groupName: "A/Managed",
|
|
lastSyncedAt: 1,
|
|
}];
|
|
const groupConfigs: GroupConfig[] = [
|
|
{ path: "A" },
|
|
{ path: "A/Sub" },
|
|
{ path: "B" },
|
|
{ path: "C" },
|
|
];
|
|
|
|
const result = buildVaultGroupDeletion({
|
|
selectedPaths: ["A/Sub", "B", "A"],
|
|
deleteHosts: false,
|
|
customGroups: ["A", "A/Sub", "A/Managed", "B", "C"],
|
|
hosts: [
|
|
host("a", "A"),
|
|
host("managed", "A/Managed", "managed-a"),
|
|
host("b", "B"),
|
|
host("c", "C"),
|
|
],
|
|
groupConfigs,
|
|
managedSources,
|
|
});
|
|
|
|
assert.deepEqual(result.selectedRoots, ["A", "B"]);
|
|
assert.deepEqual(result.customGroups, ["C"]);
|
|
assert.deepEqual(result.hosts.map(({ id, group }) => ({ id, group })), [
|
|
{ id: "a", group: "" },
|
|
{ id: "b", group: "" },
|
|
{ id: "c", group: "C" },
|
|
]);
|
|
assert.deepEqual(result.groupConfigs, [{ path: "C" }]);
|
|
assert.deepEqual(result.sourcesToRemove, managedSources);
|
|
});
|
|
|
|
test("bulk group deletion can remove every host below the selected groups", () => {
|
|
const result = buildVaultGroupDeletion({
|
|
selectedPaths: ["A", "B"],
|
|
deleteHosts: true,
|
|
customGroups: ["A", "B", "C"],
|
|
hosts: [host("a", "A/Sub"), host("b", "B"), host("c", "C")],
|
|
groupConfigs: [],
|
|
managedSources: [],
|
|
});
|
|
|
|
assert.deepEqual(result.hosts.map(({ id }) => id), ["c"]);
|
|
});
|
|
|
|
test("deleting a subgroup of a retained managed source keeps its source identity", () => {
|
|
const result = buildVaultGroupDeletion({
|
|
selectedPaths: ["Managed/Sub"],
|
|
deleteHosts: false,
|
|
customGroups: ["Managed", "Managed/Sub"],
|
|
hosts: [host("managed-child", "Managed/Sub", "managed-root")],
|
|
groupConfigs: [],
|
|
managedSources: [{
|
|
id: "managed-root",
|
|
type: "ssh_config",
|
|
filePath: "/tmp/config",
|
|
groupName: "Managed",
|
|
lastSyncedAt: 1,
|
|
}],
|
|
});
|
|
|
|
assert.equal(result.hosts[0]?.group, "");
|
|
assert.equal(result.hosts[0]?.managedSourceId, "managed-root");
|
|
assert.deepEqual(result.sourcesToRemove, []);
|
|
});
|