"use strict"; // chj.disks against an isolated Windows test VM: the platform is detected, no Linux disk tool is ever started and // every disk operation is refused cleanly. Read-only. Environment: CHJ_DISKS_WINDOWS_HOST, CHJ_DISKS_WINDOWS_FINGERPRINT // (SHA256:...), CHJ_DISKS_WINDOWS_KEY (private key path), CHJ_DISKS_WINDOWS_USER (default ai). const test = require("node:test"); const assert = require("node:assert/strict"); const { SessionManager } = require("../src/main/sessions/sessionManager"); const { PrivilegedExecutor } = require("../src/main/sessions/privilegedExec"); const { DiskService } = require("../src/main/disks/diskService"); const env = process.env; const skip = env.CHJ_DISKS_WINDOWS_HOST && env.CHJ_DISKS_WINDOWS_FINGERPRINT && env.CHJ_DISKS_WINDOWS_KEY ? false : "Set CHJ_DISKS_WINDOWS_* to run against an isolated Windows test VM."; test("chj.disks on an isolated Windows test VM is refused without running Linux tools", { skip, timeout: 180000 }, async (t) => { const hostKeys = new Map(); const profileService = { get: () => ({ id: "win", label: "win", host: env.CHJ_DISKS_WINDOWS_HOST, port: 22, username: env.CHJ_DISKS_WINDOWS_USER || "ai", authMethod: "privateKey", privateKeyPath: env.CHJ_DISKS_WINDOWS_KEY }), getHostKey: (h, p) => hostKeys.get(`${h}:${p}`) || null, trustHostKey: (h, p, fp) => hostKeys.set(`${h}:${p}`, fp), getStoredPassword: () => "", markUsed() {} }; const manager = new SessionManager({ profileService }); try { await manager.connect({ sessionId: "win", profileId: "win" }); } catch (error) { if (error.code !== "HOST_KEY_UNKNOWN") throw error; assert.equal(`SHA256:${Buffer.from(error.fingerprint, "hex").toString("base64").replace(/=+$/, "")}`, env.CHJ_DISKS_WINDOWS_FINGERPRINT, "documented host key"); manager.trustPending({ sessionId: "win", profileId: "win", fingerprint: error.fingerprint }); await manager.connect({ sessionId: "win", profileId: "win" }); } t.after(() => manager.disconnectAll("test")); const executor = new PrivilegedExecutor({ sessionManager: manager }); const runs = []; const original = executor.run.bind(executor); executor.run = (...args) => { runs.push(args[1]?.args?.[0]); return original(...args); }; const disks = new DiskService({ sessionManager: manager, privilegedExecutor: executor }); const inventory = await disks.inspect("win"); t.diagnostic(`${inventory.os} -> supported=${inventory.supported} reason=${inventory.reason}`); assert.equal(inventory.supported, false); assert.equal(inventory.platform, "windows"); assert.equal(inventory.reason, "WINDOWS"); assert.match(inventory.os, /Windows/); await assert.rejects(() => disks.plan("win", { operations: [{ type: "grow-fs", device: "/dev/sda1" }] }), { code: "DISKS_PLATFORM_UNSUPPORTED" }); await assert.rejects(() => disks.smart("win", { device: "/dev/sda" }), { code: "DISKS_PLATFORM_UNSUPPORTED" }); await assert.rejects(() => disks.autoExpand("win", { suggestionId: "partition:sda:1" }), { code: "DISKS_PLATFORM_UNSUPPORTED" }); assert.deepEqual(await disks.jobs("win"), { jobs: [] }); assert.deepEqual(runs, [], "the Linux helper was never started on Windows"); // The shared SSH layer stays usable for the other plugins. const metrics = await manager.readSystemMetrics("win"); assert.equal(metrics.os, "windows"); });