fix: 改进 Windows SSH PowerShell 错误提示

This commit is contained in:
Codex
2026-07-11 06:23:13 +02:00
parent d810e854f0
commit ecd6764931
4 changed files with 59 additions and 8 deletions
+16
View File
@@ -18,6 +18,7 @@ import {
sshStdoutStreamMaxBytes,
sshStdoutTruncationHint,
sshWindowsPlaneHint,
sshWindowsPowerShellPipelineHint,
windowsFsReadOnlyScript,
windowsPowerShellScriptPrelude,
} from "./ssh";
@@ -95,10 +96,25 @@ describe("ssh windows fs read-only operations", () => {
expect(decoded).toContain("update-ref");
expect(decoded).toContain("unselected worktree/index fingerprint");
expect(decoded).toContain("old-value CAS");
expect(decoded).toContain("$ErrorActionPreference='Continue'");
expect(decoded).toContain("2>&1");
expect(decoded).toContain("Management.Automation.ErrorRecord");
expect(decoded).toContain("warnings=@($gitWarnings)");
expect(decoded.trimEnd()).toEndWith("exit 0");
expect(() => parseSshInvocation("D601:win/F/Work/ConStart", ["git", "exact-commit", "run", "--path", "src/main.c", "--message", "fix: exact"])).toThrow("requires --confirm");
expect(() => parseSshInvocation("D601:win/F/Work/ConStart", ["git", "exact-commit", "plan", "--path", "../secret"])).toThrow("must stay inside");
});
test("adds a bounded hint for the PowerShell statement-to-pipeline parser boundary", () => {
const invocation = parseSshInvocation("D601:win/c/test", ["ps", "foreach ($x in $xs) { $x } | Format-List"]);
const hint = sshWindowsPowerShellPipelineHint(invocation, 1, "An empty pipe element is not allowed");
expect(hint).toContain("windows-powershell-statement-pipeline-boundary");
expect(hint).toContain("@(foreach (...) { ... }) | Format-List");
expect(hint).not.toContain("$x in $xs");
expect(sshWindowsPowerShellPipelineHint(invocation, 0, "An empty pipe element is not allowed")).toBe("");
});
test("builds bounded UTF-8 scripts for cat, ls, and rg", () => {
const catScript = windowsFsReadOnlyScript("F:\\Work\\demo", "cat", ["--max-bytes", "4096", "中文.md"]);
const lsScript = windowsFsReadOnlyScript("F:\\Work\\demo", "ls", ["-la", "--limit=5"]);