fix: 统一 Windows trans 工作目录

This commit is contained in:
Codex
2026-07-13 05:13:47 +02:00
parent 35b0048364
commit e91f228327
2 changed files with 82 additions and 17 deletions
+40 -5
View File
@@ -49,7 +49,11 @@ describe("ssh windows PowerShell safety prelude", () => {
expect(prelude).toContain("'PSPath','PSParentPath','PSChildName','PSDrive','PSProvider','ReadCount'");
expect(prelude).toContain("Microsoft.PowerShell.Utility\\ConvertTo-Json");
expect(prelude).toContain("$PSDefaultParameterValues['Get-Content:Encoding'] = 'utf8'");
expect(prelude).toContain("Set-Location -LiteralPath 'C:\\test'");
expect(prelude).toContain("[System.IO.Directory]::Exists($unideskRouteCwd)");
expect(prelude).toContain("Set-Location -LiteralPath $unideskRouteCwd -ErrorAction Stop");
expect(prelude).toContain("[Environment]::CurrentDirectory = (Get-Location).ProviderPath");
expect(prelude).toContain("UNIDESK_SSH_CWD_FAILED");
expect(prelude).toContain("trans-windows-route-cwd-invalid");
});
});
@@ -182,6 +186,37 @@ describe("ssh windows fs read-only operations", () => {
});
});
test("requires one route cwd for PowerShell, cmd, and their stdin launchers", () => {
for (const operation of ["ps", "cmd"] as const) {
try {
parseSshInvocation("D601:win", [operation]);
throw new Error(`expected ${operation} without a route cwd to fail`);
} catch (error) {
expect(error).toMatchObject({
code: "trans-windows-route-cwd-required",
argument: "D601:win",
});
expect((error as Error & { hint?: string }).hint).toContain("quoted heredoc");
}
}
const powerShell = parseSshInvocation("D601:win/d/work/研究资料归档-李昂", ["ps"]);
const cmd = parseSshInvocation("D601:win/d/work/研究资料归档-李昂", ["cmd"]);
const powerShellLauncher = decodedWindowsPowerShellCommand(powerShell.parsed.remoteCommand);
const cmdLauncher = decodedWindowsPowerShellCommand(cmd.parsed.remoteCommand);
expect(powerShell.parsed.requiresStdin).toBe(true);
expect(cmd.parsed.requiresStdin).toBe(true);
for (const launcher of [powerShellLauncher, cmdLauncher]) {
expect(launcher).toContain("D:\\work\\研究资料归档-李昂");
expect(launcher).toContain("UNIDESK_SSH_CWD_FAILED");
expect(launcher).toContain("trans-windows-route-cwd-invalid");
expect(launcher).toContain("[Environment]::CurrentDirectory = (Get-Location).ProviderPath");
expect(launcher).toContain("[Console]::In.ReadToEnd()");
}
expect(cmdLauncher).not.toContain("cd /d");
});
test("rejects unsupported Windows read operations instead of treating them as POSIX", () => {
expect(() => parseSshInvocation("D601:win/c/test", ["sed", "-n", "1p", "hello.md"])).toThrow("unsupported ssh win operation: sed");
});
@@ -355,7 +390,7 @@ describe("ssh stdout bounded streaming", () => {
});
test("formats truncation hint without echoing remote command", () => {
const invocation = parseSshInvocation("D601:win", ["ps"]);
const invocation = parseSshInvocation("D601:win/c/test", ["ps"]);
expect(invocation.parsed.remoteCommand).not.toBeNull();
const hint = sshStdoutTruncationHint({
invocation,
@@ -370,7 +405,7 @@ describe("ssh stdout bounded streaming", () => {
const payload = JSON.parse(formatted.slice("UNIDESK_SSH_STDOUT_TRUNCATED ".length)) as Record<string, unknown>;
expect(payload.code).toBe("ssh-stdout-truncated");
expect(payload.providerId).toBe("D601");
expect(payload.route).toBe("D601:win");
expect(payload.route).toBe("D601:win/c/test");
expect(payload.thresholdBytes).toBe(4096);
expect(payload.disclosurePolicy).toMatchObject({
name: "unified-cli-dump-preview",
@@ -380,7 +415,7 @@ describe("ssh stdout bounded streaming", () => {
});
test("forwarder bounds stdout and emits one truncation hint", () => {
const invocation = parseSshInvocation("D601:win", ["ps"]);
const invocation = parseSshInvocation("D601:win/c/test", ["ps"]);
const forwarded: Buffer[] = [];
const stdout = {
write(chunk: string | Buffer): boolean {
@@ -423,7 +458,7 @@ describe("ssh stdout bounded streaming", () => {
});
test("stderr forwarder uses the same dump guard and marker", () => {
const invocation = parseSshInvocation("D601:win", ["ps"]);
const invocation = parseSshInvocation("D601:win/c/test", ["ps"]);
const forwarded: Buffer[] = [];
const stderr = {
write(chunk: string | Buffer): boolean {