feat(tests): add isolated pi launchers
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawn } from "node:child_process"
|
||||
import { dirname, resolve } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
|
||||
const extensionPath = resolve(repoRoot, "index.ts")
|
||||
|
||||
const env = {
|
||||
...process.env,
|
||||
PI_SKIP_VERSION_CHECK: "1",
|
||||
}
|
||||
delete env.COMMANDCODE_API_KEY
|
||||
|
||||
const child = spawn(
|
||||
"pi",
|
||||
[
|
||||
"--no-extensions",
|
||||
"--extension",
|
||||
extensionPath,
|
||||
"--provider",
|
||||
"commandcode",
|
||||
"--model",
|
||||
"gpt-5.6-luna",
|
||||
"--models",
|
||||
"commandcode/*",
|
||||
...process.argv.slice(2),
|
||||
],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
env,
|
||||
stdio: "inherit",
|
||||
},
|
||||
)
|
||||
|
||||
for (const signal of ["SIGINT", "SIGTERM"]) {
|
||||
process.on(signal, () => child.kill(signal))
|
||||
}
|
||||
|
||||
child.once("error", (error) => {
|
||||
console.error(`Could not start pi: ${error.message}`)
|
||||
process.exitCode = 1
|
||||
})
|
||||
|
||||
child.once("exit", (status, signal) => {
|
||||
if (signal) process.kill(process.pid, signal)
|
||||
process.exitCode = status ?? 1
|
||||
})
|
||||
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawn } from "node:child_process"
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { dirname, join, resolve } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
|
||||
const testRoot = await mkdtemp(join(tmpdir(), "pi-commandcode-isolated-"))
|
||||
const agentDir = join(testRoot, "agent")
|
||||
const sessionDir = join(testRoot, "sessions")
|
||||
|
||||
await mkdir(agentDir, { mode: 0o700 })
|
||||
await mkdir(sessionDir, { mode: 0o700 })
|
||||
|
||||
const env = {
|
||||
...process.env,
|
||||
HOME: testRoot,
|
||||
USERPROFILE: testRoot,
|
||||
PI_CODING_AGENT_DIR: agentDir,
|
||||
PI_CODING_AGENT_SESSION_DIR: sessionDir,
|
||||
PI_SKIP_VERSION_CHECK: "1",
|
||||
}
|
||||
delete env.COMMANDCODE_API_KEY
|
||||
|
||||
let activeChild
|
||||
let receivedSignal
|
||||
|
||||
function forwardSignal(signal) {
|
||||
receivedSignal = signal
|
||||
activeChild?.kill(signal)
|
||||
}
|
||||
|
||||
const forwardSigint = () => forwardSignal("SIGINT")
|
||||
const forwardSigterm = () => forwardSignal("SIGTERM")
|
||||
process.on("SIGINT", forwardSigint)
|
||||
process.on("SIGTERM", forwardSigterm)
|
||||
|
||||
function runPi(args) {
|
||||
return new Promise((resolveRun, rejectRun) => {
|
||||
const child = spawn("pi", args, { cwd: repoRoot, env, stdio: "inherit" })
|
||||
activeChild = child
|
||||
child.once("error", rejectRun)
|
||||
child.once("exit", (status, signal) => {
|
||||
activeChild = undefined
|
||||
resolveRun({ status, signal })
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
let result
|
||||
try {
|
||||
console.error("Installing the current checkout into an isolated pi environment...")
|
||||
const install = await runPi(["install", repoRoot, "--no-approve"])
|
||||
if (install.status !== 0 || install.signal) {
|
||||
result = install
|
||||
} else {
|
||||
console.error("Starting pi. Temporary auth and sessions will be removed on exit.")
|
||||
result = await runPi([
|
||||
"--no-approve",
|
||||
"--provider",
|
||||
"commandcode",
|
||||
"--model",
|
||||
"gpt-5.6-luna",
|
||||
...process.argv.slice(2),
|
||||
])
|
||||
}
|
||||
} finally {
|
||||
process.removeListener("SIGINT", forwardSigint)
|
||||
process.removeListener("SIGTERM", forwardSigterm)
|
||||
await rm(testRoot, { recursive: true, force: true })
|
||||
console.error("Removed the isolated pi environment.")
|
||||
}
|
||||
|
||||
const signal = receivedSignal ?? result?.signal
|
||||
if (signal) process.kill(process.pid, signal)
|
||||
process.exitCode = result?.status ?? 1
|
||||
Reference in New Issue
Block a user