fix(pi-workflow): allow offline verification command
This commit is contained in:
@@ -278,6 +278,11 @@ test("Git probe and approved host commands enforce identity and ownership", asyn
|
||||
"import bytecode_module\nassert bytecode_module.VALUE == 1\n",
|
||||
"utf8",
|
||||
);
|
||||
await writeFile(
|
||||
path.join(directory, "check-offline.cjs"),
|
||||
'process.exit(process.env.PI_OFFLINE === "1" ? 0 : 1)',
|
||||
"utf8",
|
||||
);
|
||||
await execFileAsync("git", ["-C", directory, "add", "."]);
|
||||
await execFileAsync("git", ["-C", directory, "commit", "-qm", "initial"]);
|
||||
const probe = new GitStateProbe();
|
||||
@@ -303,6 +308,62 @@ test("Git probe and approved host commands enforce identity and ownership", asyn
|
||||
access(path.join(directory, "src", "__pycache__")),
|
||||
/ENOENT/,
|
||||
);
|
||||
const offline = await executor.run({
|
||||
worktreeRoot: directory,
|
||||
ownedPaths: ["src"],
|
||||
executable: "env",
|
||||
args: ["PI_OFFLINE=1", process.execPath, "check-offline.cjs"],
|
||||
});
|
||||
assert.equal(offline.result.code, 0);
|
||||
await assert.rejects(
|
||||
executor.run({
|
||||
worktreeRoot: directory,
|
||||
ownedPaths: ["src"],
|
||||
executable: "env",
|
||||
args: ["OTHER=value", process.execPath, "check-offline.cjs"],
|
||||
}),
|
||||
/cannot invoke a command wrapper or shell/,
|
||||
);
|
||||
const blockedOfflineCommands: Array<{
|
||||
args: string[];
|
||||
expected: RegExp;
|
||||
}> = [
|
||||
{
|
||||
args: ["PI_OFFLINE=1", "OTHER=value", process.execPath],
|
||||
expected: /cannot invoke a command wrapper or shell/,
|
||||
},
|
||||
{
|
||||
args: ["PI_OFFLINE=1", "sh", "-c", "touch src/bypass"],
|
||||
expected: /cannot invoke a command wrapper or shell/,
|
||||
},
|
||||
{
|
||||
args: ["PI_OFFLINE=1", "git", "clean", "-fd"],
|
||||
expected: /Git host commands are not allowed/,
|
||||
},
|
||||
{
|
||||
args: ["PI_OFFLINE=1", process.execPath, "-e", "process.exit(0)"],
|
||||
expected: /cannot execute inline interpreter code/,
|
||||
},
|
||||
{
|
||||
args: ["PI_OFFLINE=1", "env", "PI_OFFLINE=1", process.execPath],
|
||||
expected: /cannot invoke a command wrapper or shell/,
|
||||
},
|
||||
{
|
||||
args: ["PI_OFFLINE=1", "npm", "exec", "git"],
|
||||
expected: /cannot invoke package-manager executable wrappers/,
|
||||
},
|
||||
];
|
||||
for (const blocked of blockedOfflineCommands) {
|
||||
await assert.rejects(
|
||||
executor.run({
|
||||
worktreeRoot: directory,
|
||||
ownedPaths: ["src"],
|
||||
executable: "env",
|
||||
args: blocked.args,
|
||||
}),
|
||||
blocked.expected,
|
||||
);
|
||||
}
|
||||
await assert.rejects(
|
||||
executor.run({
|
||||
worktreeRoot: directory,
|
||||
|
||||
Reference in New Issue
Block a user