A desktop coding agent with free access to frontier models.
TypeScript
import { expect } from "vitest";
import { runWorkflow, saveWorkflow } from "@omnirush/behaviors";
import { queryDenDatabase } from "@omnirush/env";
import { defaultDaytonaExec, execInSandbox } from "@omnirush/hosts";
import { spec } from "@omnirush/testkit";
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function record(value: unknown): Record<string, unknown> {
if (!isRecord(value)) throw new Error("Expected an object response");
return value;
}
function field(value: unknown, name: string): string {
const result = record(value)[name];
if (typeof result !== "string") throw new Error(`Expected ${name}`);
return result;
}
function runs(value: unknown): Record<string, unknown>[] {
const items = record(value).runs;
if (!Array.isArray(items)) throw new Error("Expected workflow runs");
return items.map(record);
}
// New journey: browse organization workflow activity and open the saved workflow
// from the visualization of the version that produced a particular run.
const test = spec.world(async (seed) => {
const den = await seed.den({ env: { DEN_PLAN_GATING_ENABLED: "true", DEN_ORG_MODE: "multi_org" }, org: { name: "Workflow activity", members: { colleague: { name: "Teammate" } } } });
const organizationId = field(record((await seed.api(den.admin, "/v1/org")).body).organization, "id");
const setEnterprise = async (enabled: boolean) => {
const statement = "UPDATE organization SET metadata = JSON_SET(COALESCE(metadata, JSON_OBJECT()), '$.plan', JSON_OBJECT('tier', ?, 'source', 'manual')) WHERE id = ?";
const values = [enabled ? "enterprise" : "free", organizationId];
if (den.placement?.kind === "daytona") {
const script = `import { createConnection } from "/workspace/ee/packages/den-db/node_modules/mysql2/promise.js";
const connection = await createConnection("mysql://root:[email protected]:3306/omnirush_den");
try { await connection.execute(${JSON.stringify(statement)}, ${JSON.stringify(values)}); } finally { await connection.end(); }`;
const encoded = Buffer.from(script).toString("base64");
const result = await execInSandbox(defaultDaytonaExec, den.placement.sandboxId, `printf %s ${encoded} | base64 -d | node --input-type=module`, { timeoutMs: 15_000, context: "Arrange isolated workspace plan" });
if (result.code !== 0) throw new Error("Could not arrange the workspace plan");
} else {
if (!den.database) throw new Error("Plan transition proof requires its own database");
await queryDenDatabase(den.database.url, statement, values);
}
};
const token = field((await seed.api(den.admin, "/v1/mcp/token", {
method: "POST", headers: { "x-omnirush-org-id": organizationId }, body: JSON.stringify({ scopes: ["mcp:read", "mcp:write"] }),
})).body, "token");
let requestId = 0;
const execute = async (code: string) => {
const response = await fetch(`${den.ref.apiUrl}/mcp/agent`, {
method: "POST",
headers: { authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json, text/event-stream" },
body: JSON.stringify({ jsonrpc: "2.0", id: ++requestId, method: "tools/call", params: {
name: "execute_capability_script", arguments: { code, input: { topic: "Weekly overview" } },
} }),
signal: AbortSignal.timeout(90_000),
});
const text = await response.text();
if (!response.ok) throw new Error(`Workflow setup failed (${response.status})`);
const data = text.split("\n").find((line) => line.startsWith("data:"));
const message = record(JSON.parse(data ? data.slice(5) : text));
if (message.error || record(message.result).isError) throw new Error("The setup execution failed");
};
const code = "const workers = await tools.den.getWorkers({}); let count = 0; for (const worker of workers.workers) { count += 1; } if (input.topic) { return { topic: input.topic, count }; } return { count };";
const inputSchema = { type: "object", properties: { topic: { type: "string" } }, required: ["topic"] };
await execute(code);
const saved = await saveWorkflow(den.admin, { name: "Weekly briefing", code, currentInput: { topic: "Weekly overview" }, inputSchema });
if (saved.status !== 201) throw new Error(`Saving the setup workflow failed (${saved.status})`);
const configObjectId = field(saved.body, "configObjectId");
const pluginId = field(saved.body, "pluginId");
const configObjectVersionId = field(saved.body, "configObjectVersionId");
const firstRun = await runWorkflow(den.admin, configObjectId, { pluginId, configObjectVersionId, input: { topic: "Weekly overview" } });
// Save another version without running it. History must retain the first graph.
const nextCode = "const workers = await tools.den.getWorkers({}); return { topic: input.topic, revisedCount: workers.workers.length };";
await execute(nextCode);
const revised = await saveWorkflow(den.admin, { name: "Weekly briefing", code: nextCode, inputSchema, currentInput: { topic: "Next week" } });
if (revised.status !== 201) throw new Error(`Revising the setup workflow failed (${revised.status})`);
const failed = await seed.api(den.admin, `/v1/workflows/${configObjectId}/run`, {
method: "POST", body: JSON.stringify({ pluginId, configObjectVersionId, input: {} }),
});
if (failed.response.ok) throw new Error("Missing workflow input must fail");
const web = await seed.web({ den, signedInAs: "admin", startPath: "/dashboard/workflow-runs", headless: true, viewport: { width: 1440, height: 1000 } });
return { den, web, setEnterprise, configObjectId, pluginId, configObjectVersionId, receiptId: field(firstRun, "receiptId"), originalGraph: record(saved.body).graph, revisedGraph: record(revised.body).graph };
}, { timeout: 600_000 });
test("workflow activity shows linked version diagrams and keeps one-off and inaccessible runs readable", async ({ world, user, probe, seed, evidence, step }) => {
const readRuns = async (session = world.den.admin) => {
const response = await probe.api(session, "/v1/workflow-runs");
expect(response.response.status, response.text).toBe(200);
return runs(response.body);
};
await step("restrict workflow analytics before an Enterprise upgrade", async () => {
for (const path of ["/v1/workflow-runs", "/v1/codemode-runs"]) {
const blocked = await probe.api(world.den.admin, path);
expect(blocked.response.status).toBe(402);
expect(blocked.body).toMatchObject({ error: "enterprise_plan_required", feature: "analytics" });
expect(record(blocked.body).runs).toBeUndefined();
}
// The old URL redirects into Analytics and receives the same gate.
await user.see({ text: "Workflow Runs is part of the Enterprise plan." }, { timeoutMs: 90_000 });
expect(await probe.eval(world.web, () => location.pathname)).toBe("/dashboard/analytics/workflow-runs");
await user.navigate(`${world.den.ref.webUrl}/dashboard/script-runs`);
await user.see({ text: "Workflow Runs is part of the Enterprise plan." });
expect(await probe.eval(world.web, () => location.pathname)).toBe("/dashboard/analytics/workflow-runs");
await user.see({ role: "link", label: /^Usage & adoption$/ });
await user.see({ role: "link", label: "Models & usage" });
await user.notSee({ testId: "nav-workflow-runs" });
await user.notSee({ role: "link", label: "Workflow Runs" });
await user.notSee({ testId: `workflow-run-link-${world.receiptId}` });
await user.navigate(`${world.den.ref.webUrl}/dashboard/analytics/workflow-runs`);
await user.see({ text: "Workflow Runs is part of the Enterprise plan." });
await user.notSee({ testId: `workflow-run-link-${world.receiptId}` });
await user.screenshot();
});
evidence.recordAssertionEvidence("Workflow run analytics is Enterprise-only through navigation, saved links and both API paths", "The free workspace's already executed workflows are hidden from analytics: both API aliases return 402 without runs, both legacy page URLs resolve to /dashboard/analytics/workflow-runs, which shows the Enterprise gate, and there is no standalone sidebar destination or Workflow Runs analytics link.", true);
await world.setEnterprise(true);
await user.reload();
await user.click({ role: "link", label: /^Usage & adoption$/ });
await user.click({ role: "link", label: "Workflow Runs" });
await user.notSee({ text: "Workflow Runs is part of the Enterprise plan." });
await user.notSee({ testId: "nav-workflow-runs" });
const before = await readRuns();
evidence.recordAssertionEvidence("An Enterprise upgrade unlocks Workflow Runs inside Analytics with existing history intact", "The upgraded workspace opens Workflow Runs from the shared Analytics navigation and the API returns its pre-upgrade receipts, including the original saved version.", before.some((run) => run.id === world.receiptId));
const first = before.find((run) => run.id === world.receiptId);
expect(first).toMatchObject({ workflow: { configObjectId: world.configObjectId, title: "Weekly briefing", graph: world.originalGraph } });
expect(record(first?.workflow).graph).not.toEqual(world.revisedGraph);
expect(before.filter((run) => run.source === "adhoc").every((run) => run.workflow === null)).toBe(true);
const failed = before.find((run) => run.status === "failed" && isRecord(run.workflow) && run.workflow.configObjectId === world.configObjectId);
expect(failed).toMatchObject({ workflow: { graph: world.originalGraph } });
const failedReceiptId = field(failed, "id");
const oneOff = before.find((run) => run.source === "adhoc" && run.status === "succeeded");
const oneOffReceiptId = field(oneOff, "id");
await step("read existing diagrams directly in the run list", async () => {
await user.see({ text: "Workflow Runs" }, { timeoutMs: 90_000 });
await user.see({ text: "Workflows are repeatable tasks you and your team can save, share, and run again. See their recent activity here." });
for (const receiptId of [world.receiptId, failedReceiptId]) {
// Scope rendered node text to each receipt; an empty diagram or the latest
// version (Revised count) must fail even when another card is correct.
await user.see({ testId: `workflow-run-visualization-${receiptId}` }, {
text: /^(?![\s\S]*Revised count)(?=[\s\S]*Get workers)(?=[\s\S]*For each item in workers workers)(?=[\s\S]*Topic is set)(?=[\s\S]*Finish with: Topic, Count)[\s\S]*$/,
});
await user.see({ testId: `workflow-run-link-${receiptId}` }, { text: "Weekly briefing" });
await user.see({ testId: `workflow-run-time-${receiptId}` });
}
await user.notSee({ testId: "den-workflow-flow-diagram", nth: 2 });
await user.see({ testId: `workflow-run-link-${world.receiptId}` }, { text: "Weekly briefing" });
await user.see({ testId: `workflow-run-time-${world.receiptId}` });
await user.see({ text: "Succeeded" });
await user.see({ text: "Failed" });
await user.notSee({ text: `plugin:${world.pluginId}:${world.configObjectId}` });
await user.see({ testId: `workflow-run-${oneOffReceiptId}` }, { text: /One-off task[\s\S]*Succeeded[\s\S]*Technical details/ });
await user.see({ testId: `workflow-run-time-${oneOffReceiptId}` });
await user.notSee({ testId: `workflow-run-link-${oneOffReceiptId}` });
await user.notSee({ testId: `workflow-run-visualization-${oneOffReceiptId}` });
await user.click({ testId: `workflow-run-details-${oneOffReceiptId}` });
await user.see({ testId: `workflow-run-${oneOffReceiptId}` }, { text: /Source[\s\S]*adhoc[\s\S]*Tool calls[\s\S]*den.getWorkers[\s\S]*Duration[\s\S]*\d+(?:\.\d+)? (?:ms|s)/ });
await user.click({ testId: `workflow-run-details-${oneOffReceiptId}` });
await user.notSee({ role: "link", label: "One-off task" });
await user.notSee({ label: "One-off task workflow visualization" });
await user.screenshot();
});
evidence.recordAssertionEvidence("Saved runs show the existing visualization of their executed version", "The API graph matches the original version and differs from the later edit. The activity page renders both saved-run diagrams with a library link, status and time; one-off runs have neither a fabricated link nor a visualization.", true);
evidence.recordAssertionEvidence("Workflow activity explains reuse and keeps raw run details collapsed", "The introduction is visible and the closed details element keeps raw source values out of the visible run card.", true);
await step("open the linked workflow in the existing library", async () => {
await user.click({ testId: `workflow-run-link-${world.receiptId}` });
await user.see({ testId: "den-workflow-detail" }, { timeoutMs: 60_000 });
await user.see({ text: "How it works" });
await user.see({ text: "Weekly briefing" });
expect(await readRuns()).toEqual(before);
await user.navigate(`${world.den.ref.webUrl}/dashboard/workflow-runs`);
await user.see({ text: "Workflow Runs" });
expect(await probe.eval(world.web, () => location.pathname)).toBe("/dashboard/analytics/workflow-runs");
await user.click({ testId: `workflow-run-details-${world.receiptId}` });
await user.see({ text: `plugin:${world.pluginId}:${world.configObjectId}` });
});
evidence.recordAssertionEvidence("The run opens its library workflow and technical details remain available", "Clicking the workflow name opens the existing library detail without creating any new runs. Expanding Technical details reveals its saved source.", true);
await step("respect member access when enriching activity", async () => {
const colleague = world.den.members.colleague;
expect(await readRuns(colleague)).toEqual([]);
const org = record((await probe.api(world.den.admin, "/v1/org")).body);
if (!Array.isArray(org.members)) throw new Error("Expected organization members");
const member = org.members.map(record).find((entry) => record(entry.user).email === colleague.email);
const grant = await seed.api(world.den.admin, `/v1/config-objects/${world.configObjectId}/access`, {
method: "POST", body: JSON.stringify({ orgMembershipId: field(member, "id"), role: "editor" }),
});
expect(grant.response.status, grant.text).toBe(201);
const memberRun = await runWorkflow(colleague, world.configObjectId, { pluginId: world.pluginId, configObjectVersionId: world.configObjectVersionId, input: { topic: "Member briefing" } });
const visible = await readRuns(colleague);
expect(visible).toHaveLength(1);
expect(visible[0]).toMatchObject({ id: memberRun.receiptId, workflow: { configObjectId: world.configObjectId } });
const memberNodes = record(record(visible[0].workflow).graph).nodes;
if (!Array.isArray(memberNodes)) throw new Error("Expected the shared workflow graph");
const originalNodes = record(world.originalGraph).nodes;
if (!Array.isArray(originalNodes)) throw new Error("Expected the authored workflow graph");
for (const [kind, label] of [["branch", "Condition"], ["loop", "Repeat"], ["return", "Result"]]) {
const authored = originalNodes.map(record).filter((node) => node.kind === kind);
const shared = memberNodes.map(record).filter((node) => node.kind === kind);
expect(authored.length).toBeGreaterThan(0);
expect(authored.every((node) => node.label !== label)).toBe(true);
expect(shared.map((node) => node.id)).toEqual(authored.map((node) => node.id));
expect(shared.map((node) => node.label)).toEqual(authored.map(() => label));
}
const removed = await seed.api(world.den.admin, `/v1/config-objects/${world.configObjectId}/access/${field(record(grant.body).item, "id")}`, { method: "DELETE" });
expect(removed.response.ok, removed.text).toBe(true);
const revoked = await readRuns(colleague);
expect(revoked).toHaveLength(1);
expect(revoked[0]).toMatchObject({ id: memberRun.receiptId, workflow: null });
expect((await probe.api(colleague, `/v1/workflows/${world.configObjectId}`)).response.status).toBe(403);
});
evidence.recordAssertionEvidence("Run previews follow workflow access without widening run visibility", "A member sees none of the admin's runs, then sees a redacted preview of their own shared workflow run. Revoking the workflow grant preserves their receipt but removes its preview and library metadata.", true);
await step("run the saved workflow from its simple form", async () => {
await user.navigate(`${world.den.ref.webUrl}/dashboard/library/workflows/${world.configObjectId}`);
await user.see({ testId: "workflow-overview" }, { text: /Run workflow[\s\S]*Latest result[\s\S]*How it works/, timeoutMs: 60_000 });
await user.see({ testId: "den-workflow-input-form" });
await user.notSee({ label: "Run input details" });
const beforeRun = await readRuns();
await user.see({ testId: "workflow-overview" }, { text: /^(?![\s\S]*No custom display yet)[\s\S]*Customize result display/ });
await user.click({ text: "Customize result display" });
await user.see({ text: /No custom display yet/ });
await user.click({ text: "Customize result display" });
await user.see({ testId: "workflow-overview" }, { text: /^(?![\s\S]*No custom display yet)[\s\S]*Customize result display/ });
await user.type({ role: "textbox", label: /^Topic/ }, "A fresh briefing", { replace: true, verify: true });
await user.click({ text: "Advanced input" });
await user.see({ label: "Run input details" }, { value: JSON.stringify({ topic: "A fresh briefing" }, null, 2) });
await user.click({ text: "Advanced input" });
await user.notSee({ label: "Run input details" });
expect(await readRuns()).toEqual(beforeRun);
await user.click({ role: "button", label: "Run workflow" });
await user.see({ testId: "den-workflow-artifact-result" }, { text: /A fresh briefing/, timeoutMs: 60_000 });
const afterRun = await readRuns();
expect(afterRun).toHaveLength(beforeRun.length + 1);
const added = afterRun.filter((run) => !beforeRun.some((previous) => previous.id === run.id));
expect(added).toHaveLength(1);
expect(added[0]).toMatchObject({ status: "succeeded", workflow: { configObjectId: world.configObjectId, graph: world.revisedGraph } });
await user.see({ role: "button", label: "Run workflow" });
await user.see({ testId: "den-workflow-flow-diagram" });
await user.screenshot();
});
evidence.recordAssertionEvidence("The workflow opens with a simple run form and shows the submitted result", "The form precedes the latest result and existing diagram. Advanced input starts hidden and stays synchronized with the named field; editing and inspecting it create no runs. Submitting creates exactly one successful run of the current saved version and displays the entered topic in its result.", true);
await step("keep workflow execution working after Enterprise access is removed", async () => {
await world.setEnterprise(false);
await user.navigate(`${world.den.ref.webUrl}/dashboard/analytics/workflow-runs`);
await user.see({ text: "Workflow Runs is part of the Enterprise plan." });
await user.notSee({ testId: `workflow-run-link-${world.receiptId}` });
await user.notSee({ role: "link", label: "Workflow Runs" });
expect((await probe.api(world.den.admin, "/v1/workflow-runs")).response.status).toBe(402);
await user.navigate(`${world.den.ref.webUrl}/dashboard/library/workflows/${world.configObjectId}`);
await user.see({ role: "button", label: "Run workflow" });
await user.type({ role: "textbox", label: /^Topic/ }, "Briefing after plan change", { replace: true, verify: true });
await user.click({ role: "button", label: "Run workflow" });
await user.see({ testId: "den-workflow-artifact-result" }, { text: /Briefing after plan change/, timeoutMs: 60_000 });
expect((await probe.api(world.den.admin, "/v1/workflow-runs")).response.status).toBe(402);
await user.screenshot();
});
evidence.recordAssertionEvidence("Removing Enterprise access hides history without breaking workflow execution", "After the downgrade, previously viewed receipts and the Workflow Runs link are absent and the API is locked. Running the saved workflow from the Library still succeeds and displays the newly submitted result.", true);
});