Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,8 @@ async function pathExists(filePath: string): Promise<boolean> {
}
}

function resolveCommand(command: string, args: string[]): { file: string; args: string[] } {
if (/\.(mjs|cjs|js|ts)$/i.test(command)) {
return {
file: process.execPath,
args: [command, ...args]
};
}

return {
file: command,
args
};
}

async function runCommand(command: string, args: string[], cwd: string): Promise<CommandResult> {
const invocation = resolveCommand(command, args);
const result = await execFileAsync(invocation.file, invocation.args, {
const result = await execFileAsync(command, args, {
cwd,
maxBuffer: 10 * 1024 * 1024,
timeout: Number.parseInt(process.env.CSTACK_GITHUB_COMMAND_TIMEOUT_MS ?? "", 10) || DEFAULT_GITHUB_COMMAND_TIMEOUT_MS
Expand Down Expand Up @@ -1104,7 +1089,7 @@ export async function performGitHubDeliverMutations(options: PerformGitHubMutati
);
const remote = await resolveRemoteForPush(options.cwd);
const { repository } = await detectRepository(options.cwd, policy.repository);
const ghCommand = policy.command || "gh";
const ghCommand = "gh";
const defaultBranchInfo = await resolveDefaultBranch({ ghCommand, cwd: options.cwd, repository });
const defaultBranch = defaultBranchInfo.name;
let branch = options.gitBranch;
Expand Down Expand Up @@ -1619,7 +1604,7 @@ export async function collectGitHubDeliveryEvidence(options: CollectGitHubDelive
};
}

const ghCommand = policy.command || "gh";
const ghCommand = "gh";
const { repository, remoteUrl } = await detectRepository(options.cwd, policy.repository);
const headSha = await detectHeadSha(options.cwd);
const defaultBranchInfo = await resolveDefaultBranch({ ghCommand, cwd: options.cwd, repository });
Expand Down
11 changes: 9 additions & 2 deletions test/deliver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,19 @@ async function initGitRepo(repoDir: string): Promise<{ remoteDir: string }> {
describe("runDeliver", () => {
let repoDir: string;
let remoteDir: string;
let originalPath: string | undefined;

beforeEach(async () => {
repoDir = await fs.mkdtemp(path.join(os.tmpdir(), "cstack-deliver-"));
const fakeCodexPath = path.resolve("test/fixtures/fake-codex.mjs");
const fakeGhPath = path.resolve("test/fixtures/fake-gh.mjs");
const fakeGhBinDir = await fs.mkdtemp(path.join(os.tmpdir(), "cstack-deliver-fake-gh-bin-"));
chmodSync(fakeCodexPath, 0o755);
chmodSync(fakeGhPath, 0o755);
await fs.copyFile(fakeGhPath, path.join(fakeGhBinDir, "gh"));
chmodSync(path.join(fakeGhBinDir, "gh"), 0o755);
originalPath = process.env.PATH;
process.env.PATH = `${fakeGhBinDir}${path.delimiter}${originalPath ?? ""}`;

await fs.mkdir(path.join(repoDir, ".cstack", "prompts"), { recursive: true });
await fs.mkdir(path.join(repoDir, ".cstack", "runs"), { recursive: true });
Expand All @@ -131,7 +137,7 @@ describe("runDeliver", () => {
"",
"[workflows.deliver.github]",
'enabled = true',
`command = "${fakeGhPath.replaceAll("\\", "\\\\")}"`,
'command = "gh"',
'repository = "ganesh47/cstack"',
'pushBranch = true',
'branchPrefix = "cstack"',
Expand Down Expand Up @@ -167,6 +173,7 @@ describe("runDeliver", () => {
});

afterEach(async () => {
process.env.PATH = originalPath;
delete process.env.FAKE_CODEX_FAIL_BUILD;
delete process.env.FAKE_CODEX_DELAY_MS;
delete process.env.FAKE_CODEX_VALIDATION_COMMAND;
Expand Down Expand Up @@ -1599,7 +1606,7 @@ describe("runDeliver", () => {
issueNumbers: [906],
policy: {
enabled: true,
command: path.resolve("test/fixtures/fake-gh.mjs"),
command: "gh",
repository: "ganesh47/cstack",
pushBranch: true,
branchPrefix: "cstack",
Expand Down
9 changes: 8 additions & 1 deletion test/ship.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,19 @@ async function seedInitiativeReviewRun(repoDir: string, buildRunId: string): Pro
describe("runShip", () => {
let repoDir: string;
let remoteDir: string;
let originalPath: string | undefined;

beforeEach(async () => {
repoDir = await fs.mkdtemp(path.join(os.tmpdir(), "cstack-ship-"));
const fakeCodexPath = path.resolve("test/fixtures/fake-codex.mjs");
const fakeGhPath = path.resolve("test/fixtures/fake-gh.mjs");
const fakeGhBinDir = await fs.mkdtemp(path.join(os.tmpdir(), "cstack-ship-fake-gh-bin-"));
chmodSync(fakeCodexPath, 0o755);
chmodSync(fakeGhPath, 0o755);
await fs.copyFile(fakeGhPath, path.join(fakeGhBinDir, "gh"));
chmodSync(path.join(fakeGhBinDir, "gh"), 0o755);
originalPath = process.env.PATH;
process.env.PATH = `${fakeGhBinDir}${path.delimiter}${originalPath ?? ""}`;

await fs.mkdir(path.join(repoDir, ".cstack", "prompts"), { recursive: true });
await fs.mkdir(path.join(repoDir, ".cstack", "runs"), { recursive: true });
Expand All @@ -191,7 +197,7 @@ describe("runShip", () => {
"",
"[workflows.deliver.github]",
'enabled = true',
`command = "${fakeGhPath.replaceAll("\\", "\\\\")}"`,
'command = "gh"',
'repository = "ganesh47/cstack"',
'pushBranch = true',
'branchPrefix = "cstack"',
Expand Down Expand Up @@ -224,6 +230,7 @@ describe("runShip", () => {
});

afterEach(async () => {
process.env.PATH = originalPath;
await fs.rm(repoDir, { recursive: true, force: true });
await fs.rm(remoteDir, { recursive: true, force: true });
});
Expand Down
Loading