fix(coding-agent): preserved bash status while syncing cwd
Propagated the native shell working directory in ShellRunResult so AgentSession can refresh cwd without running a hidden pwd command in the persistent shell. Added regression coverage for cd plus a failing command followed by echo $?, proving cwd sync no longer overwrites the user's last shell status. Fixes #3958
This commit is contained in:
@@ -122,17 +122,21 @@ describe("executeBash", () => {
|
||||
expect(result.output.trim()).toBe(fs.realpathSync(tempDir));
|
||||
});
|
||||
|
||||
it("syncs persistent shell directory changes back to the session", async () => {
|
||||
it("syncs persistent shell directory changes back to the session without clobbering status", async () => {
|
||||
const childDir = path.join(tempDir, "child");
|
||||
fs.mkdirSync(childDir);
|
||||
const sessionKey = `cwd-sync-${Date.now()}`;
|
||||
await executeBash(`cd ${shellQuote(childDir)}`, { sessionKey, timeout: 5000, useUserShell: true });
|
||||
const result = await executeBash(`cd ${shellQuote(childDir)}; false`, {
|
||||
sessionKey,
|
||||
timeout: 5000,
|
||||
useUserShell: true,
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
|
||||
const applied: string[] = [];
|
||||
const synced = await syncBashSessionCwd({
|
||||
sessionKey,
|
||||
result,
|
||||
currentCwd: tempDir,
|
||||
useUserShell: true,
|
||||
applyCwd: async cwd => {
|
||||
applied.push(cwd);
|
||||
},
|
||||
@@ -140,6 +144,8 @@ describe("executeBash", () => {
|
||||
|
||||
expect(synced).toBe(childDir);
|
||||
expect(applied).toEqual([childDir]);
|
||||
const status = await executeBash("echo $?", { sessionKey, timeout: 5000, useUserShell: true });
|
||||
expect(status.output.trim()).toBe("1");
|
||||
});
|
||||
|
||||
it("canonicalizes symlinked cwd before execution", async () => {
|
||||
|
||||
Reference in New Issue
Block a user