[Init] Initial commit - NetMesh terminal manager
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
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
This commit is contained in:
99
application/state/sessionRestoreStorage.test.ts
Normal file
99
application/state/sessionRestoreStorage.test.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { createSessionRestoreStorage } from "./sessionRestoreStorage.ts";
|
||||
import type { SessionRestorePayload } from "../../domain/sessionRestore.ts";
|
||||
|
||||
const payload: SessionRestorePayload = {
|
||||
version: 1,
|
||||
savedAt: 1,
|
||||
activeTabId: "vault",
|
||||
tabOrder: [],
|
||||
sessions: [],
|
||||
workspaces: [],
|
||||
};
|
||||
|
||||
test("session restore storage reads a valid payload", () => {
|
||||
const backing = new Map<string, unknown>();
|
||||
const storage = createSessionRestoreStorage({
|
||||
read: <T,>(key: string): T | null => (backing.get(key) as T) ?? null,
|
||||
write: <T,>(key: string, value: T): boolean => {
|
||||
backing.set(key, value);
|
||||
return true;
|
||||
},
|
||||
remove: (key: string) => {
|
||||
backing.delete(key);
|
||||
},
|
||||
});
|
||||
|
||||
storage.write(payload);
|
||||
assert.deepEqual(storage.read(), payload);
|
||||
});
|
||||
|
||||
test("session restore storage removes invalid payloads", () => {
|
||||
const backing = new Map<string, unknown>([["netcatty_session_restore_v1", { version: 999 }]]);
|
||||
const storage = createSessionRestoreStorage({
|
||||
read: <T,>(key: string): T | null => (backing.get(key) as T) ?? null,
|
||||
write: () => true,
|
||||
remove: (key: string) => {
|
||||
backing.delete(key);
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(storage.read(), null);
|
||||
assert.equal(backing.has("netcatty_session_restore_v1"), false);
|
||||
});
|
||||
|
||||
test("session restore storage removes malformed payloads that pass shallow checks", () => {
|
||||
const backing = new Map<string, unknown>([[
|
||||
"netcatty_session_restore_v1",
|
||||
{
|
||||
version: 1,
|
||||
savedAt: 1,
|
||||
activeTabId: "vault",
|
||||
tabOrder: [],
|
||||
sessions: [null],
|
||||
workspaces: [],
|
||||
},
|
||||
]]);
|
||||
const storage = createSessionRestoreStorage({
|
||||
read: <T,>(key: string): T | null => (backing.get(key) as T) ?? null,
|
||||
write: () => true,
|
||||
remove: (key: string) => {
|
||||
backing.delete(key);
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(storage.read(), null);
|
||||
assert.equal(backing.has("netcatty_session_restore_v1"), false);
|
||||
});
|
||||
|
||||
test("session restore storage sanitizes payloads before writing", () => {
|
||||
const backing = new Map<string, unknown>();
|
||||
const storage = createSessionRestoreStorage({
|
||||
read: <T,>(key: string): T | null => (backing.get(key) as T) ?? null,
|
||||
write: <T,>(key: string, value: T): boolean => {
|
||||
backing.set(key, value);
|
||||
return true;
|
||||
},
|
||||
remove: (key: string) => {
|
||||
backing.delete(key);
|
||||
},
|
||||
});
|
||||
|
||||
storage.write({
|
||||
...payload,
|
||||
sessions: [{
|
||||
id: "s1",
|
||||
hostId: "h1",
|
||||
hostLabel: "Host 1",
|
||||
hostname: "example.test",
|
||||
username: "root",
|
||||
status: "connected",
|
||||
}],
|
||||
tabOrder: ["s1"],
|
||||
activeTabId: "s1",
|
||||
} as unknown as SessionRestorePayload);
|
||||
|
||||
assert.equal(storage.read()?.sessions[0].status, "disconnected");
|
||||
});
|
||||
Reference in New Issue
Block a user