[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:
134
infrastructure/services/vaultImportWorkerClient.test.ts
Normal file
134
infrastructure/services/vaultImportWorkerClient.test.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import type { VaultImportResult } from "../../domain/vaultImport.ts";
|
||||
import {
|
||||
importVaultHostsInWorker,
|
||||
type VaultImportWorkerLike,
|
||||
} from "./vaultImportWorkerClient.ts";
|
||||
|
||||
const parsedResult: VaultImportResult = {
|
||||
hosts: [{
|
||||
id: "host-1",
|
||||
label: "Production",
|
||||
hostname: "10.0.0.1",
|
||||
port: 22,
|
||||
username: "root",
|
||||
protocol: "ssh",
|
||||
tags: [],
|
||||
os: "linux",
|
||||
}],
|
||||
groups: [],
|
||||
issues: [],
|
||||
stats: { parsed: 1, imported: 1, skipped: 0, duplicates: 0 },
|
||||
};
|
||||
|
||||
class FakeVaultImportWorker implements VaultImportWorkerLike {
|
||||
listeners = new Map<string, Set<(event: MessageEvent | ErrorEvent) => void>>();
|
||||
postedMessage: unknown;
|
||||
terminated = false;
|
||||
|
||||
addEventListener(type: "message" | "error", listener: (event: MessageEvent | ErrorEvent) => void) {
|
||||
const listeners = this.listeners.get(type) ?? new Set();
|
||||
listeners.add(listener);
|
||||
this.listeners.set(type, listeners);
|
||||
}
|
||||
|
||||
removeEventListener(type: "message" | "error", listener: (event: MessageEvent | ErrorEvent) => void) {
|
||||
this.listeners.get(type)?.delete(listener);
|
||||
}
|
||||
|
||||
postMessage(message: unknown) {
|
||||
this.postedMessage = message;
|
||||
}
|
||||
|
||||
terminate() {
|
||||
this.terminated = true;
|
||||
}
|
||||
|
||||
emit(type: "message" | "error", data: unknown) {
|
||||
const event = type === "message"
|
||||
? ({ data } as MessageEvent)
|
||||
: ({ message: String(data) } as ErrorEvent);
|
||||
for (const listener of this.listeners.get(type) ?? []) {
|
||||
listener(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("vault import stays pending while a worker parses and forwards real stage progress", async () => {
|
||||
const worker = new FakeVaultImportWorker();
|
||||
const progress: Array<{ stage: string; percent: number }> = [];
|
||||
let settled = false;
|
||||
const file = new File(["Label,Hostname\nProduction,10.0.0.1"], "hosts.csv");
|
||||
Object.defineProperty(file, "webkitRelativePath", {
|
||||
value: "Sessions/Production/hosts.csv",
|
||||
});
|
||||
|
||||
const promise = importVaultHostsInWorker({
|
||||
format: "csv",
|
||||
files: [file],
|
||||
createWorker: () => worker,
|
||||
onProgress: (update) => progress.push(update),
|
||||
}).finally(() => {
|
||||
settled = true;
|
||||
});
|
||||
|
||||
assert.deepEqual(worker.postedMessage, {
|
||||
type: "import",
|
||||
format: "csv",
|
||||
files: [file],
|
||||
relativePaths: ["Sessions/Production/hosts.csv"],
|
||||
encoding: undefined,
|
||||
});
|
||||
assert.equal(settled, false);
|
||||
|
||||
worker.emit("message", {
|
||||
type: "progress",
|
||||
progress: { stage: "reading", percent: 10 },
|
||||
});
|
||||
worker.emit("message", {
|
||||
type: "progress",
|
||||
progress: { stage: "parsing", percent: 55 },
|
||||
});
|
||||
worker.emit("message", { type: "result", result: parsedResult });
|
||||
|
||||
assert.deepEqual(await promise, parsedResult);
|
||||
assert.deepEqual(progress, [
|
||||
{ stage: "reading", percent: 10 },
|
||||
{ stage: "parsing", percent: 55 },
|
||||
]);
|
||||
assert.equal(worker.terminated, true);
|
||||
});
|
||||
|
||||
test("vault import surfaces worker failures and always stops the worker", async () => {
|
||||
const worker = new FakeVaultImportWorker();
|
||||
const promise = importVaultHostsInWorker({
|
||||
format: "csv",
|
||||
files: [new File(["bad input"], "hosts.csv")],
|
||||
createWorker: () => worker,
|
||||
});
|
||||
|
||||
worker.emit("message", { type: "error", message: "Unable to parse CSV" });
|
||||
|
||||
await assert.rejects(promise, /Unable to parse CSV/);
|
||||
assert.equal(worker.terminated, true);
|
||||
});
|
||||
|
||||
test("vault import cancellation stops the worker and rejects before applying a result", async () => {
|
||||
const worker = new FakeVaultImportWorker();
|
||||
const controller = new AbortController();
|
||||
const promise = importVaultHostsInWorker({
|
||||
format: "csv",
|
||||
files: [new File(["Label,Hostname\nA,a.example.com"], "hosts.csv")],
|
||||
signal: controller.signal,
|
||||
createWorker: () => worker,
|
||||
});
|
||||
|
||||
controller.abort();
|
||||
|
||||
await assert.rejects(promise, (error: unknown) => (
|
||||
error instanceof DOMException && error.name === "AbortError"
|
||||
));
|
||||
assert.equal(worker.terminated, true);
|
||||
});
|
||||
Reference in New Issue
Block a user