fix(perf): unify SFTP lifecycles and bound runtime resources

This commit is contained in:
bincxz committed 2026-07-29 03:33:00 +08:00
1 parent 49918fd54a
commit fe737ec555
240 files changed
+23968 -4865

No files matched your search

@@ -0,0 +1,34 @@
"use strict";
const assert = require("node:assert/strict");
const test = require("node:test");
const {
MAX_SSH_AUTH_METHOD_CACHE_ENTRIES,
createSshAuthMethodCache,
} = require("./sshAuthMethodCache.cjs");
test("auth method cache stays hard-bounded across thousands of endpoints", () => {
const cache = createSshAuthMethodCache();
for (let index = 0; index < 4_000; index += 1) {
cache.set(`root@host-${index}:22`, { method: "publickey" });
}
assert.equal(cache.size, MAX_SSH_AUTH_METHOD_CACHE_ENTRIES);
assert.equal(cache.get("root@host-0:22"), undefined);
assert.deepEqual(cache.get("root@host-3999:22"), { method: "publickey" });
});
test("auth method cache refreshes recency on successful lookup", () => {
const cache = createSshAuthMethodCache({ maxEntries: 3 });
cache.set("a", { method: "password" });
cache.set("b", { method: "publickey" });
cache.set("c", { method: "publickey-default" });
assert.equal(cache.get("a")?.method, "password");
cache.set("d", { method: "password" });
assert.equal(cache.get("b"), undefined, "least-recently-used endpoint should be evicted");
assert.equal(cache.get("a")?.method, "password", "cache hit must protect the refreshed endpoint");
assert.equal(cache.size, 3);
});