fix: honor trans backend config for ssh
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import type { UniDeskConfig } from "./config";
|
||||
import {
|
||||
createPosixApplyPatchFileSystem,
|
||||
createSshStdoutForwarder,
|
||||
formatSshStdoutTruncationHint,
|
||||
parseSshInvocation,
|
||||
sshCaptureBackendPlan,
|
||||
sshStdoutStreamMaxBytes,
|
||||
sshStdoutTruncationHint,
|
||||
windowsFsReadOnlyScript,
|
||||
@@ -15,6 +20,12 @@ function sha256Hex(text: string): string {
|
||||
return createHash("sha256").update(text, "utf8").digest("hex");
|
||||
}
|
||||
|
||||
function minimalConfig(publicHost = "203.0.113.10"): UniDeskConfig {
|
||||
return {
|
||||
network: { publicHost },
|
||||
} as UniDeskConfig;
|
||||
}
|
||||
|
||||
describe("ssh windows PowerShell safety prelude", () => {
|
||||
test("shadows ConvertTo-Json and strips filesystem ETS metadata", () => {
|
||||
const prelude = windowsPowerShellScriptPrelude("C:\\test");
|
||||
@@ -193,6 +204,52 @@ describe("ssh stdout bounded streaming", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("ssh backend selection", () => {
|
||||
test("uses trans YAML backend-core preference without runtime docker detection", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "unidesk-trans-config-"));
|
||||
const configPath = join(dir, "trans.ymal");
|
||||
writeFileSync(configPath, [
|
||||
"version: 1",
|
||||
"kind: UniDeskTransConfig",
|
||||
"ssh:",
|
||||
" backend: backend-core",
|
||||
"",
|
||||
].join("\n"));
|
||||
try {
|
||||
const plan = sshCaptureBackendPlan(minimalConfig(), { UNIDESK_TRANS_CONFIG_PATH: configPath } as NodeJS.ProcessEnv);
|
||||
|
||||
expect(plan.backend).toBe("local-backend-core-broker");
|
||||
expect(plan.remoteHost).toBeNull();
|
||||
expect(plan.reason).toBe(`configured:${configPath}#ssh.backend`);
|
||||
expect(plan.localBackendCore.backendCoreContainer).toBe(true);
|
||||
expect(plan.localBackendCore.source).toBe(`${configPath}#ssh.backend`);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("uses trans YAML frontend websocket preference when configured", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "unidesk-trans-config-"));
|
||||
const configPath = join(dir, "trans.ymal");
|
||||
writeFileSync(configPath, [
|
||||
"version: 1",
|
||||
"kind: UniDeskTransConfig",
|
||||
"ssh:",
|
||||
" backend: frontend-websocket",
|
||||
"",
|
||||
].join("\n"));
|
||||
try {
|
||||
const plan = sshCaptureBackendPlan(minimalConfig("198.51.100.4"), { UNIDESK_TRANS_CONFIG_PATH: configPath } as NodeJS.ProcessEnv);
|
||||
|
||||
expect(plan.backend).toBe("remote-frontend-websocket");
|
||||
expect(plan.remoteHost).toBe("198.51.100.4");
|
||||
expect(plan.reason).toBe(`configured:${configPath}#ssh.backend`);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("ssh removed shell aliases", () => {
|
||||
test("reports route-aware replacement examples for trans script", () => {
|
||||
const previousEntrypoint = process.env.UNIDESK_SSH_ENTRYPOINT;
|
||||
|
||||
Reference in New Issue
Block a user