Files
Netcatty/domain/vaultJumpGraph.test.ts
T
Netcatty-Bot 7ed7250f34 fix(vault): clean deleted jump host references across deletion flows
Deleting saved hosts now removes their jump references from surviving hosts and group defaults in all ordinary deletion flows. Host-only bulk deletion uses the existing vault mutation boundary, and explicit empty chains retain their original group-override meaning.

Validation: 282 focused checks, lint/build, two independent full-diff reviews, latest-head Codex review, current GitHub checks, and actual isolated Electron deletion/restart/native SSH reconnection.

Fixes #3691
2026-10-16 10:38:15 +08:00

85 lines
2.7 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import type { GroupConfig, Host } from "./models.ts";
import { pruneVaultJumpHostReferences } from "./vaultJumpGraph.ts";
import { applyGroupDefaults, resolveGroupDefaults } from "./groupConfig.ts";
const host = (id: string, hostIds?: string[]): Host => ({
id,
label: id,
hostname: `${id}.example.com`,
port: 22,
username: "root",
protocol: "ssh",
tags: [],
os: "linux",
group: "",
...(hostIds ? { hostChain: { hostIds } } : {}),
});
test("pruning removes deleted hosts from other hosts' jump chains", () => {
const hosts = [
host("target", ["jump-a", "jump-b"]),
host("other"),
];
const result = pruneVaultJumpHostReferences({
hosts,
groupConfigs: [],
removedHostIds: ["jump-a"],
});
assert.equal(result.changed, true);
assert.deepEqual(result.hosts[0].hostChain, { hostIds: ["jump-b"] });
assert.equal(result.hosts[1], hosts[1]);
});
test("pruning clears an empty chain and prunes group config chains", () => {
const groupConfigs: GroupConfig[] = [
{ path: "A", hostChain: { hostIds: ["gone"] } },
{ path: "B" },
];
const result = pruneVaultJumpHostReferences({
hosts: [host("target", ["gone"])],
groupConfigs,
removedHostIds: ["gone"],
});
assert.equal(result.changed, true);
assert.deepEqual(result.hosts[0].hostChain, { hostIds: [] });
assert.deepEqual(result.groupConfigs[0].hostChain, { hostIds: [] });
assert.equal(result.groupConfigs[1], groupConfigs[1]);
});
test("pruning keeps collections untouched when no chains reference removed hosts", () => {
const hosts = [host("target", ["kept"]), host("chain-free")];
const groupConfigs: GroupConfig[] = [{ path: "B" }];
const result = pruneVaultJumpHostReferences({
hosts,
groupConfigs,
removedHostIds: ["gone"],
});
assert.equal(result.changed, false);
assert.equal(result.hosts, hosts);
assert.equal(result.groupConfigs, groupConfigs);
});
test("removing a final explicit hop does not activate another inherited chain", () => {
const result = pruneVaultJumpHostReferences({
hosts: [{ ...host("target", ["gone"]), group: "Parent" },
{ ...host("inherited"), group: "Parent/Child" }],
groupConfigs: [
{ path: "Parent", hostChain: { hostIds: ["kept"] } },
{ path: "Parent/Child", hostChain: { hostIds: ["gone"] } },
],
removedHostIds: ["gone"],
});
for (const target of result.hosts) {
const effective = applyGroupDefaults(target,
resolveGroupDefaults(target.group!, result.groupConfigs));
assert.deepEqual(effective.hostChain, { hostIds: [] });
}
assert.deepEqual(result.groupConfigs[0].hostChain, { hostIds: ["kept"] });
});