evOo-local/infra/sandboxes/supervisor/src/project-workspace-ownership.test.ts
Cursor Agent efde47ed22
fix(ci): computer tools test uses non-login shell; fix ownership test import
Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>
2026-10-07 21:41:56 +00:00

50 lines
1.5 KiB
TypeScript

import { execFileSync } from "node:child_process";
import { mkdtempSync, rmSync, statSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { COMPUTER_IMAGE, hostComputerUser } from "./computer-spec.js";
function dockerAvailable(): boolean {
try {
execFileSync("docker", ["info"], { stdio: "ignore" });
return true;
} catch {
return false;
}
}
describe("project workspace bind ownership", () => {
it("writes project files with the host uid/gid", () => {
if (process.env.RAKAZO_PROJECT_WORKSPACE_OWNERSHIP_TEST !== "1" || !dockerAvailable()) {
return;
}
const hostDir = mkdtempSync(path.join(tmpdir(), "rakazo-project-own-"));
const marker = "ownership-marker.txt";
const user = hostComputerUser(process.getuid?.(), process.getgid?.());
try {
execFileSync(
"docker",
[
"run",
"--rm",
"-u",
user,
"-v",
`${hostDir}:/home/rakazo/project`,
process.env.RAKAZO_COMPUTER_IMAGE ?? COMPUTER_IMAGE,
"bash",
"-lc",
`echo ok > /home/rakazo/project/${marker}`,
],
{ stdio: "inherit" },
);
const stat = statSync(path.join(hostDir, marker));
expect(stat.uid).toBe(process.getuid?.());
expect(stat.gid).toBe(process.getgid?.());
} finally {
rmSync(hostDir, { recursive: true, force: true });
}
});
});