Honor literal container-root cwd in the owned Linux fixture

Keep exact resource, company, run and environment checks before execution. Permit the canonical literal root used by normal restore commands while rejecting other foreign paths and symlink aliases. Restore the original workspace stamp behavior and retain real-shell coverage for missing directories.

Co-Authored-By: Codex <codex@users.noreply.github.com>
This commit is contained in:
DottaandCodex committed 2026-11-15 17:05:53 -06:00
1 parent ef1aa74463
commit a1c9ece663
3 files changed
+11 -5

No files matched your search

@@ -28,7 +28,10 @@ try {
|| request.args.some(value => typeof value !== "string" || value.length > 131072)) throw fail("invalid_command_request");
witnessStage="resolve_cwd";
const cwd = await realpath(request.cwd ?? root);
if (cwd !== root && !cwd.startsWith(root + "/")) throw fail("foreign_command_cwd");
// Public execute permits the literal container root as a stable command cwd.
// A different request path that resolves to root does not gain this exception.
const literalContainerRoot = request.cwd === "/" && cwd === "/";
if (!literalContainerRoot && cwd !== root && !cwd.startsWith(root + "/")) throw fail("foreign_command_cwd");
witnessStage="validate_budget";
const deadline = request.timeoutMs;
if (!Number.isSafeInteger(deadline) || deadline < 1 || deadline > 90000) throw fail("command_budget_invalid");
@@ -353,10 +353,11 @@ describe("native workspace sync durable metadata", () => {
const execute = vi.fn(async (request: {
command: string; args?: string[]; cwd?: string; timeoutMs?: number; bypassSession?: boolean;
}) => {
// Match the normal confined provider: omitted cwd uses its owned root;
// an explicit foreign cwd is refused before executing the real shell.
// The normal container provider accepts literal root as a stable cwd;
// other foreign paths and aliases to root remain refused.
const cwd = await realpath(request.cwd ?? remoteRoot);
if (cwd !== remoteRoot && !cwd.startsWith(remoteRoot + path.sep)) throw new Error("foreign_command_cwd");
const literalContainerRoot = request.cwd === "/" && cwd === "/";
if (!literalContainerRoot && cwd !== remoteRoot && !cwd.startsWith(remoteRoot + path.sep)) throw new Error("foreign_command_cwd");
expect(request.timeoutMs).toBe(15_000);
expect(request.bypassSession).toBe(true);
try {
@@ -391,7 +392,7 @@ describe("native workspace sync durable metadata", () => {
).resolves.toBe(true);
expect(execute).toHaveBeenCalledTimes(2);
expect(execute.mock.calls.map(([request]) => request.cwd)).toEqual([undefined, undefined]);
expect(execute.mock.calls.map(([request]) => request.cwd)).toEqual(["/", "/"]);
const remoteStamp = JSON.parse(await readFile(path.join(remoteCwd, ".paperclip-runtime", "paperclip-runner", "workspace-sync-v1.json"), "utf8"));
expect(remoteStamp).toMatchObject({ hostSha256: finalHostSha256, finalizedRunId: descriptor.binding.runId });
expect(persistedLeaseMetadata).toMatchObject({
@@ -707,6 +707,7 @@ async function writeRemoteStamp(input: {
"-c",
`umask 077; mkdir -p ${shellQuote(runtimeDir)} && printf %s ${shellQuote(encoded)} | base64 -d > ${shellQuote(tempPath)} && mv ${shellQuote(tempPath)} ${shellQuote(stampPath)}`,
],
cwd: "/",
timeoutMs: 15_000,
bypassSession: true,
});
@@ -753,6 +754,7 @@ async function remoteStampMatches(input: {
"-c",
[...gitChecks, `test -f ${shellQuote(stampPath)}`, `cat ${shellQuote(stampPath)}`].join(" && "),
],
cwd: "/",
timeoutMs: 15_000,
bypassSession: true,
});