Skip to content
  1. Home
  2. workspace
Checking…
Demo view — sanitized data only. Sign in over HTTPS to create projects and manage the workspace.

AI Engineering Workspace

Partial

Chat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.

Project files

read-only

app/qa/external-vps.mjs

1// Independent-VPS acceptance harness. NOT RUN YET (no separately authorized server exists). Usage: node qa/external-vps.mjs --public-host <VPS public IP or name> [--base https://cloud.zoobd.com:8443]
2// It labels the result `independent: true` ONLY if the enrolled node has a different hostname and public address than this control-plane host.
3import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { request } from "playwright"; import pg from "pg";
4const here = path.dirname(fileURLToPath(import.meta.url)); const ROOT = path.resolve(here, "../.."); const arg = (n, d) => { const i = process.argv.indexOf("--" + n); return i > 0 ? process.argv[i + 1] : d; };
5const BASE = arg("base", "https://cloud.zoobd.com:8443"); const HOSTP = arg("public-host"); if (!HOSTP) { console.error("usage: --public-host <ip|name>"); process.exit(2); } const O = { origin: BASE };
6const results = []; const rec = (n, ok, d = "") => { results.push({ n, ok: !!ok }); console.log(`${ok ? "PASS" : "FAIL"} ${n}${d ? " — " + d : ""}`); }; const sleep = ms => new Promise(r => setTimeout(r, ms)); const J = async r => r.json().catch(() => ({})); const ts = Date.now();
7const TOKEN = fs.readFileSync(path.join(os.homedir(), ".config/zoo-cloud-studio/admin-token"), "utf8").trim(); const pw = fs.readFileSync(path.join(os.homedir(), ".config/zoo-cloud-studio/pg-password"), "utf8").trim();
8const pool = new pg.Pool({ connectionString: `postgres://studio:${encodeURIComponent(pw)}@127.0.0.1:5432/studio`, max: 2 }); const q = async (t, p) => (await pool.query(t, p)).rows;
9const ctx = () => request.newContext({ baseURL: BASE }); const post = (c, u, b) => c.post(u, { data: b, headers: O }); const get = async u => { try { const r = await fetch(u, { signal: AbortSignal.timeout(5000) }); return { s: r.status, t: await r.text() }; } catch { return { s: 0, t: "" }; } };
10async function until(fn, ms, step = 2000) { const end = Date.now() + ms; while (Date.now() < end) { const v = await fn(); if (v) return v; await sleep(step); } return null; }
11const owner = await ctx(); await post(owner, "/api/auth/login", { token: TOKEN }); const dev0 = (await J(await owner.get("/api/super"))).security; const created = { orgs: [], users: [] };
12const email = `qa-ext-${ts}@example.test`; const org = await J(await post(owner, "/api/super", { action: "createOrg", name: `QA-TX ${ts}`, ownerEmail: email, ownerName: "QA external" })); created.orgs.push(org.id); created.users.push(org.ownerId);
13await post(owner, "/api/super", { action: "security", devCustomerOps: true, confirm: "ENABLE DEV CUSTOMER OPS" }); // temporary, restored in finally
14const C = await ctx(); await post(C, "/api/auth/login", { token: org.token });
15try {
16 const inst = await J(await post(C, "/api/cloud/instances", { name: "external-acceptance", target: "external" })); const en = await J(await post(C, "/api/cloud/servers", { action: "enroll", instanceId: inst.id, label: "independent-vps" }));
17 const man = JSON.parse(fs.readFileSync(path.join(ROOT, "app/data/packages/manifest.json"), "utf8")); const pk = man.packages[0]; const f = pk.file, s = pk.signature;
18 console.log(`\n=== Run this ONE command on the independent VPS as an unprivileged user (token valid 15 minutes, single use) ===\n\nmkdir -p ~/zloud-agent && cd ~/zloud-agent && curl -fsSO ${BASE}/packages/${f} -O ${BASE}/packages/${s} && \\\nnode ${f} verify --file ${f} --sig ${s} --pubkey ${man.signing.publicKey} && \\\nnode ${f} enroll --url ${BASE} --token ${en.token} --pubkey ${man.signing.publicKey} --public-host ${HOSTP} && \\\nnohup node ${f} run >agent.log 2>&1 &\n`);
19 const node = await until(async () => (await J(await C.get("/api/cloud/apps"))).nodes?.find(n => n.id === en.id && n.state === "online" && n.caps), 15 * 60_000); rec("tenant-bound enrollment + trusted gateway connection (no --pin needed)", !!node);
20 if (!node) throw new Error("no agent connected within 15 minutes");
21 const row = (await q("SELECT hostname,os,metrics FROM nodes WHERE id=$1", [en.id]))[0]; const m = JSON.parse(row.metrics ?? "{}"); await post(C, "/api/cloud/servers", { action: "authorize", nodeId: en.id });
22 const independent = row.hostname !== os.hostname() && HOSTP !== "127.0.0.1" && HOSTP !== "localhost" && !(await q("SELECT 1 x FROM nodes WHERE id=$1 AND hostname=$2", [en.id, os.hostname()])).length; rec("independence: different hostname and public address from the control-plane host", independent, `${row.hostname} / ${HOSTP}`);
23 rec("real resource metrics (memory, load, uptime) and capabilities reported", m.memTotalMb > 0 && m.uptimeS > 0 && /^v\d+/.test(m.caps?.node ?? ""), JSON.stringify(m));
24 const jb = await J(await post(C, "/api/cloud/servers", { action: "job", nodeId: en.id, kind: "collect-info" })); const jr = await until(async () => { const r = (await q("SELECT status,result FROM node_jobs WHERE id=$1", [jb.id]))[0]; return r?.status === "done" ? JSON.parse(r.result) : null; }, 60000); rec("remote job execution (collect-info) returns the VPS's own hostname", jr?.hostname === row.hostname);
25 const wait = async id => until(async () => (await J(await C.get("/api/cloud/apps"))).deployments.find(x => x.id === id && ["running", "failed"].includes(x.status)), 120000);
26 const a = await J(await post(C, "/api/cloud/apps", { action: "deploy", nodeId: en.id, template: "static-site", name: "ext-static", params: { html: `<h1>ext-${ts}</h1>` } })); const da = await wait(a.id); const ha = await get(`http://${HOSTP}:${a.port}/`);
27 rec("static website deployed and answering over the network from the control-plane host", da?.status === "running" && ha.t.includes(`ext-${ts}`), `${ha.s}`);
28 const code = "require('http').createServer((q,s)=>s.end('ext-node-ok')).listen(process.env.PORT,'0.0.0.0')"; const b = await J(await post(C, "/api/cloud/apps", { action: "deploy", nodeId: en.id, template: "node-app", name: "ext-node", params: { code } })); const db2 = await wait(b.id);
29 rec("Node.js application deployed and answering over the network", db2?.status === "running" && (await get(`http://${HOSTP}:${b.port}/`)).t === "ext-node-ok");
30 const det = await J(await C.get(`/api/cloud/apps?id=${a.id}`)); rec("live logs captured from the remote agent", /release is live/.test(det.jobs[0]?.log ?? ""));
31 const act = async (id, action, extra = {}) => { await post(C, "/api/cloud/apps", { action, deploymentId: id, ...extra }); await sleep(1500); await until(async () => (await q("SELECT COUNT(*) n FROM node_jobs WHERE org_id=$1 AND status IN ('queued','delivered')", [org.id]))[0].n == 0, 90000, 1500); };
32 await act(a.id, "stop"); const st = (await get(`http://${HOSTP}:${a.port}/`)).s === 0; await act(a.id, "start"); const sa = (await get(`http://${HOSTP}:${a.port}/`)).s === 200; await act(a.id, "restart"); rec("start / stop / restart on the remote server", st && sa && (await get(`http://${HOSTP}:${a.port}/`)).s === 200);
33 await act(b.id, "redeploy", { params: { code: "process.exit(1)" } }); const aft = await get(`http://${HOSTP}:${b.port}/`); rec("failed deployment recovery: broken release fails, previous release keeps serving", aft.t === "ext-node-ok");
34 await act(b.id, "redeploy", { params: { code: code.replace("ext-node-ok", "ext-v3") } }); await act(b.id, "rollback", { release: 1 }); rec("rollback to release 1 verified over the network", (await get(`http://${HOSTP}:${b.port}/`)).t === "ext-node-ok");
35 const jrot = await J(await post(C, "/api/cloud/servers", { action: "job", nodeId: en.id, kind: "agent.rotate" })); await until(async () => (await q("SELECT status FROM node_jobs WHERE id=$1", [jrot.id]))[0]?.status === "done", 60000); const online2 = await until(async () => (await J(await C.get("/api/cloud/apps"))).nodes?.find(n => n.id === en.id && n.state === "online"), 60000); rec("credential rotation by control-plane job; agent keeps working with the new credential", !!online2);
36 const jup = await J(await post(C, "/api/cloud/servers", { action: "job", nodeId: en.id, kind: "agent.upgrade" })); const ur = await until(async () => { const r = (await q("SELECT status,result FROM node_jobs WHERE id=$1", [jup.id]))[0]; return r?.status === "done" ? JSON.parse(r.result) : null; }, 90000); rec("signed agent upgrade check (verifies signature + version; reports upgraded or up-to-date)", ur?.ok === true, JSON.stringify(ur));
37 console.log("\nNow run on the VPS: node ~/zloud-agent/" + f + " uninstall (applications are preserved by default)"); const rev = await until(async () => (await q("SELECT revoked_at FROM nodes WHERE id=$1", [en.id]))[0]?.revoked_at, 10 * 60_000);
38 rec("uninstall: node revoked on the control plane", !!rev); rec("uninstall preserved the workloads (static site still answers)", (await get(`http://${HOSTP}:${a.port}/`)).s === 200);
39 console.log("\nTo clean up the preserved apps on the VPS: stop the processes under ~/.config/zoo-cloud-agent/apps or rerun uninstall with --remove-apps before deleting.");
40} catch (e) { rec("harness aborted", false, e.message); }
41finally { await post(owner, "/api/super", { action: "security", devCustomerOps: false }); for (const t of ["domains", "app_releases", "app_deployments", "node_jobs", "usage_records"]) await q(`DELETE FROM ${t} WHERE org_id = ANY($1)`, [created.orgs]); await q("DELETE FROM sessions WHERE org_id = ANY($1) OR user_id = ANY($2)", [created.orgs, created.users]); await q("DELETE FROM organizations WHERE id = ANY($1)", [created.orgs]); await q("DELETE FROM users WHERE id = ANY($1)", [created.users]); await pool.end(); }
42const f2 = results.filter(r => !r.ok).length; const independent = results.find(r => r.n.startsWith("independence"))?.ok === true;
43fs.writeFileSync(path.join(ROOT, "design/verification/external-vps.json"), JSON.stringify({ finished: new Date().toISOString(), independent, scope: independent ? "independent external VPS" : "NOT independent", passed: results.length - f2, failed: f2, results }, null, 2)); console.log(`\n${results.length - f2}/${results.length} checks passed; independent=${independent}`); process.exit(f2 ? 1 : 0);
44

Conversation

Partial
Sign in to start AI sessions.

Task checklist

  • Application shell deployed
  • Persistent projects
  • Agent runtime
  • Sandboxed terminal

Execution activity

No agent sessions. Git HEAD 692573d on master.

Approval requests

None pending.