fix: 修复 Windows trans 编码与参数传递

This commit is contained in:
Codex
2026-07-10 13:31:26 +02:00
parent ad93490f4a
commit b6ac6f71f6
6 changed files with 108 additions and 4 deletions
+20
View File
@@ -46,6 +46,7 @@ describe("ssh windows PowerShell safety prelude", () => {
expect(prelude).toContain("function ConvertTo-Json");
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'");
});
});
@@ -114,6 +115,25 @@ describe("ssh windows fs read-only operations", () => {
expect(decodedWindowsPowerShellCommand(cmd.parsed.remoteCommand)).toContain('python tool.py "71-FILTER 高频输出精度与频率跳变改进"');
});
test("supports GNU head/tail counts and preserves PowerShell native argv", () => {
const headScript = windowsFsReadOnlyScript("F:\\Work\\demo", "head", ["-35", "docs/read me.md"]);
const tailScript = windowsFsReadOnlyScript("F:\\Work\\demo", "tail", ["-20", "docs/read me.md"]);
const pythonCode = 'import pathlib; print({"utf8": pathlib.Path(r"docs/报告.md").read_text(encoding="utf-8") != ""})';
const python = parseSshInvocation("D601:win/F/Work/demo", ["ps", "python", "-c", pythonCode]);
const launcher = decodedWindowsPowerShellCommand(python.parsed.remoteCommand);
const encodedPayload = launcher.match(/\$payloadJsonB64 = ''([A-Za-z0-9+/=]+)'';/u)?.[1];
expect(headScript).toContain("$arg -match '^-(\\d+)$'");
expect(tailScript).toContain("$arg -match '^-(\\d+)$'");
expect(python.parsed.invocationKind).toBe("argv");
expect(encodedPayload).toBeDefined();
expect(JSON.parse(Buffer.from(encodedPayload ?? "", "base64").toString("utf8"))).toEqual({
command: "python",
args: ["-c", pythonCode],
nativeArguments: `"-c" "${pythonCode.replaceAll('"', '\\"')}"`,
});
});
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");
});