Multiplayer agent harness for work.
Install layer tools outside /workspace on DigitalOcean computers (#2195)
Joshua Francec40f77ebf0db
diff --git a/src/sandbox/managed-agents-sandbox.ts b/src/sandbox/managed-agents-sandbox.tsindex 0ebdf9afc..f3e535f52 100644--- a/src/sandbox/managed-agents-sandbox.ts+++ b/src/sandbox/managed-agents-sandbox.ts@@ -324,8 +324,25 @@ export function createManagedAgentsSandbox(workspace: WorkspaceStore, opts: Mana};const procSessions = createExecProcessSessions(procIo);- const writeAbsBytes = (name: string, absPath: string, data: Uint8Array): Promise<void> =>- withSession(name, (session) => session.writeFileBytes(absPath, data));+ const writeAbsBytes = async (name: string, absPath: string, data: Uint8Array): Promise<void> => {+ if (absPath.startsWith(`/${WORKSPACE_BASENAME}/`)) {+ await withSession(name, (session) => session.writeFileBytes(absPath, data));+ return;+ }+ const staged = `${HOME_DIR}/.qm-upload-${randomUUID()}`;+ await withSession(name, (session) => session.writeFileBytes(staged, data));+ const moved = await execRaw(+ name,+ `mkdir -p ${shq(absPath.slice(0, absPath.lastIndexOf("/")) || "/")} && mv -f ${shq(staged)} ${shq(absPath)}`,+ 60,+ );+ if (moved.code !== 0) {+ await execRaw(name, `rm -f ${shq(staged)}`, 30).catch(+ swallowAs("managed-agents-sandbox: clean staged upload", undefined),+ );+ throw new Error(`do-managed-agents write ${absPath} failed: ${(moved.stderr || moved.stdout).slice(0, 200)}`);+ }+ };const readAbsBytes = (name: string, absPath: string): Promise<Uint8Array | null> =>withSession(name, (session) => session.readFileBytes(absPath));const installLayerTools = opts.layerToolFiles ? createLayerToolInstaller(opts.layerToolFiles) : null;diff --git a/test/managed-agents-sandbox.test.ts b/test/managed-agents-sandbox.test.tsindex d651e7474..cdef79e65 100644--- a/test/managed-agents-sandbox.test.ts+++ b/test/managed-agents-sandbox.test.ts@@ -395,3 +395,14 @@ test("process sessions stream output through the data plane exec path", async ()assert.match(output, /one/);assert.match(output, /two/);});++test("layer tools install outside /workspace by staging inside it", async () => {+ const target = join(mkdtempSync(join(tmpdir(), "managed-agents-bin-")), "tool");+ sandbox = make({+ layerToolFiles: () => [{ to: target, content: "#!/bin/sh\necho ok\n", mode: "755" }],+ });+ const h = await sandbox.provision(layers);+ const r = await sandbox.run(h, `${target}`);+ assert.equal(r.code, 0, r.stderr);+ assert.equal(r.stdout.trim(), "ok");+});diff --git a/test/support/fake-managed-agents.ts b/test/support/fake-managed-agents.tsindex 39754201d..aa57c8f57 100644--- a/test/support/fake-managed-agents.ts+++ b/test/support/fake-managed-agents.ts@@ -143,6 +143,8 @@ export function installFakeManagedAgents(): FakeManagedAgents {},async writeFileBytes(absPath, data): Promise<void> {alive(r);+ if (!absPath.startsWith("/workspace/"))+ throw new Error('7 PERMISSION_DENIED: path outside workspace (workspace "/workspace")');const hostPath = absPath.startsWith(GUEST_HOME_DIR) ? r.home + absPath.slice(GUEST_HOME_DIR.length) : absPath;mkdirSync(dirname(hostPath), { recursive: true });writeFileSync(hostPath, Buffer.from(data));