Fix Fish shell PATH detection and clean up lint warnings (#323)
* Fix Fish shell PATH detection for Codex * refactor(provider): resolve lint warnings in provider layers * refactor(terminal): simplify thread lock release initialization * test(git): simplify fetch release callback initialization
This commit is contained in:
1 parent
0a902790ca
commit
e1c33dcd33
9 files changed
+114
-20
No files matched your search
@@ -1,14 +1,11 @@
|
||||
import * as ChildProcess from "node:child_process";
|
||||
import { readPathFromLoginShell } from "@t3tools/shared/shell";
|
||||
|
||||
export function fixPath(): void {
|
||||
if (process.platform !== "darwin") return;
|
||||
|
||||
try {
|
||||
const shell = process.env.SHELL ?? "/bin/zsh";
|
||||
const result = ChildProcess.execFileSync(shell, ["-ilc", "echo -n $PATH"], {
|
||||
encoding: "utf8",
|
||||
timeout: 5000,
|
||||
});
|
||||
const result = readPathFromLoginShell(shell);
|
||||
if (result) {
|
||||
process.env.PATH = result;
|
||||
}
|
||||
|
||||
@@ -654,7 +654,7 @@ it.layer(TestLayer)("git integration", (it) => {
|
||||
|
||||
const realGitService = yield* GitService;
|
||||
let fetchStarted = false;
|
||||
let releaseFetch: () => void = () => undefined;
|
||||
let releaseFetch!: () => void;
|
||||
const waitForReleasePromise = new Promise<void>((resolve) => {
|
||||
releaseFetch = resolve;
|
||||
});
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import * as OS from "node:os";
|
||||
import { Effect, Path } from "effect";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { readPathFromLoginShell } from "@t3tools/shared/shell";
|
||||
|
||||
export function fixPath(): void {
|
||||
if (process.platform !== "darwin") return;
|
||||
|
||||
try {
|
||||
const shell = process.env.SHELL ?? "/bin/zsh";
|
||||
const result = execFileSync(shell, ["-ilc", "echo -n $PATH"], {
|
||||
encoding: "utf8",
|
||||
timeout: 5000,
|
||||
});
|
||||
const result = readPathFromLoginShell(shell);
|
||||
if (result) {
|
||||
process.env.PATH = result;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
type CodexAppServerSendTurnInput,
|
||||
} from "../../codexAppServerManager.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { ProviderAdapterValidationError } from "../Errors.ts";
|
||||
import { CodexAdapter } from "../Services/CodexAdapter.ts";
|
||||
import { ProviderSessionDirectory } from "../Services/ProviderSessionDirectory.ts";
|
||||
import { makeCodexAdapterLive } from "./CodexAdapter.ts";
|
||||
|
||||
@@ -436,13 +436,17 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
return session;
|
||||
}
|
||||
|
||||
return {
|
||||
...session,
|
||||
...(session.resumeCursor === undefined && binding.resumeCursor !== undefined
|
||||
? { resumeCursor: binding.resumeCursor }
|
||||
: {}),
|
||||
...(binding.runtimeMode !== undefined ? { runtimeMode: binding.runtimeMode } : {}),
|
||||
};
|
||||
const overrides: {
|
||||
resumeCursor?: ProviderSession["resumeCursor"];
|
||||
runtimeMode?: ProviderSession["runtimeMode"];
|
||||
} = {};
|
||||
if (session.resumeCursor === undefined && binding.resumeCursor !== undefined) {
|
||||
overrides.resumeCursor = binding.resumeCursor;
|
||||
}
|
||||
if (binding.runtimeMode !== undefined) {
|
||||
overrides.runtimeMode = binding.runtimeMode;
|
||||
}
|
||||
return Object.assign({}, session, overrides);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1150,7 +1150,7 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
|
||||
private async runWithThreadLock<T>(threadId: string, task: () => Promise<T>): Promise<T> {
|
||||
const previous = this.threadLocks.get(threadId) ?? Promise.resolve();
|
||||
let release: () => void = () => {};
|
||||
let release!: () => void;
|
||||
const current = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
"types": "./src/logging.ts",
|
||||
"import": "./src/logging.ts"
|
||||
},
|
||||
"./shell": {
|
||||
"types": "./src/shell.ts",
|
||||
"import": "./src/shell.ts"
|
||||
},
|
||||
"./Net": {
|
||||
"types": "./src/Net.ts",
|
||||
"import": "./src/Net.ts"
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { extractPathFromShellOutput, readPathFromLoginShell } from "./shell";
|
||||
|
||||
describe("extractPathFromShellOutput", () => {
|
||||
it("extracts the path between capture markers", () => {
|
||||
expect(
|
||||
extractPathFromShellOutput("__T3CODE_PATH_START__\n/opt/homebrew/bin:/usr/bin\n__T3CODE_PATH_END__\n"),
|
||||
).toBe("/opt/homebrew/bin:/usr/bin");
|
||||
});
|
||||
|
||||
it("ignores shell startup noise around the capture markers", () => {
|
||||
expect(
|
||||
extractPathFromShellOutput(
|
||||
"Welcome to fish\n__T3CODE_PATH_START__\n/opt/homebrew/bin:/usr/bin\n__T3CODE_PATH_END__\nBye\n",
|
||||
),
|
||||
).toBe("/opt/homebrew/bin:/usr/bin");
|
||||
});
|
||||
|
||||
it("returns null when the markers are missing", () => {
|
||||
expect(extractPathFromShellOutput("/opt/homebrew/bin /usr/bin")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("readPathFromLoginShell", () => {
|
||||
it("uses a shell-agnostic printenv PATH probe", () => {
|
||||
const execFile = vi.fn<
|
||||
(
|
||||
file: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: { encoding: "utf8"; timeout: number },
|
||||
) => string
|
||||
>(() => "__T3CODE_PATH_START__\n/a:/b\n__T3CODE_PATH_END__\n");
|
||||
|
||||
expect(readPathFromLoginShell("/opt/homebrew/bin/fish", execFile)).toBe("/a:/b");
|
||||
expect(execFile).toHaveBeenCalledTimes(1);
|
||||
|
||||
const firstCall = execFile.mock.calls[0] as
|
||||
| [string, ReadonlyArray<string>, { encoding: "utf8"; timeout: number }]
|
||||
| undefined;
|
||||
expect(firstCall).toBeDefined();
|
||||
if (!firstCall) {
|
||||
throw new Error("Expected execFile to be called");
|
||||
}
|
||||
|
||||
const [shell, args, options] = firstCall;
|
||||
expect(shell).toBe("/opt/homebrew/bin/fish");
|
||||
expect(args).toHaveLength(2);
|
||||
expect(args?.[0]).toBe("-ilc");
|
||||
expect(args?.[1]).toContain("printenv PATH");
|
||||
expect(args?.[1]).toContain("__T3CODE_PATH_START__");
|
||||
expect(args?.[1]).toContain("__T3CODE_PATH_END__");
|
||||
expect(options).toEqual({ encoding: "utf8", timeout: 5000 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
const PATH_CAPTURE_START = "__T3CODE_PATH_START__";
|
||||
const PATH_CAPTURE_END = "__T3CODE_PATH_END__";
|
||||
const PATH_CAPTURE_COMMAND = [
|
||||
`printf '%s\n' '${PATH_CAPTURE_START}'`,
|
||||
"printenv PATH",
|
||||
`printf '%s\n' '${PATH_CAPTURE_END}'`,
|
||||
].join("; ");
|
||||
|
||||
type ExecFileSyncLike = (
|
||||
file: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: { encoding: "utf8"; timeout: number },
|
||||
) => string;
|
||||
|
||||
export function extractPathFromShellOutput(output: string): string | null {
|
||||
const startIndex = output.indexOf(PATH_CAPTURE_START);
|
||||
if (startIndex === -1) return null;
|
||||
|
||||
const valueStartIndex = startIndex + PATH_CAPTURE_START.length;
|
||||
const endIndex = output.indexOf(PATH_CAPTURE_END, valueStartIndex);
|
||||
if (endIndex === -1) return null;
|
||||
|
||||
const pathValue = output.slice(valueStartIndex, endIndex).trim();
|
||||
return pathValue.length > 0 ? pathValue : null;
|
||||
}
|
||||
|
||||
export function readPathFromLoginShell(
|
||||
shell: string,
|
||||
execFile: ExecFileSyncLike = execFileSync,
|
||||
): string | undefined {
|
||||
const output = execFile(shell, ["-ilc", PATH_CAPTURE_COMMAND], {
|
||||
encoding: "utf8",
|
||||
timeout: 5000,
|
||||
});
|
||||
return extractPathFromShellOutput(output) ?? undefined;
|
||||
}
|
||||
Reference in new issue
Block a user