Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/agent_env/explorer/ui/e2e/home.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test, expect } from '@playwright/test';

test('explorer home renders its navigation', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('link', { name: /environments/i }).first()).toBeVisible();
});
13 changes: 13 additions & 0 deletions src/agent_env/explorer/ui/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig, devices } from '@playwright/test';

// Factory starts the app and passes its address; every case keeps a screenshot as evidence.
export default defineConfig({
testDir: '.',
retries: 0,
use: {
baseURL: process.env.FACTORY_BROWSER_BASE_URL ?? 'http://localhost:3000',
screenshot: 'on',
viewport: { width: 1280, height: 800 },
},
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
});
22 changes: 22 additions & 0 deletions src/agent_env/explorer/ui/e2e/quick-start.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, expect } from '@playwright/test';

const COMMANDS = [
'agent-env up',
'agent-env env deploy --id <env-id>',
'agent-env task run --id <task-id>',
];

test('home shows the quick start commands, each with a copy button', async ({ page, context }) => {
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
await page.goto('/');

const card = page.getByRole('region', { name: 'Quick start' });
await expect(card).toBeVisible();
for (const command of COMMANDS) {
await expect(card.getByText(command, { exact: true })).toBeVisible();
await expect(card.getByRole('button', { name: `Copy ${command}` })).toBeVisible();
}

await card.getByRole('button', { name: `Copy ${COMMANDS[0]}` }).click();
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(COMMANDS[0]);
});
13 changes: 13 additions & 0 deletions src/agent_env/explorer/ui/factory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Factory browser checks for the agent-env explorer UI (docs/specs/browser-checks.md in scaleapi/factory).
# Each passing case keeps a screenshot as visual evidence.
browser_checks:
runner: playwright
evidence: [screenshot]
allow_skipped: false
timeout_minutes: 10
server:
command: [sh, -c, 'npx next dev --port "$FACTORY_BROWSER_PORT"']
ready_path: /
ready_timeout_seconds: 180
playwright:
config: e2e/playwright.config.ts
25 changes: 1 addition & 24 deletions src/agent_env/explorer/ui/src/components/flow-shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import React, {
useState,
useMemo,
useCallback,
useEffect,
useRef,
} from 'react';
import { Copy, Check } from 'lucide-react';
import {
ReactFlow,
Background,
Expand All @@ -18,28 +16,7 @@ import {
} from '@xyflow/react';
import '@xyflow/react/dist/style.css';

export function CopyButton({ text }: { text: string }) {
const [copied, setCopied] = useState(false);
const handleCopy = useCallback(() => {
navigator.clipboard.writeText(text).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
});
}, [text]);
return (
<button
onClick={handleCopy}
className="p-1 rounded hover:bg-[var(--accent)] text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors"
title="Copy JSON"
>
{copied ? (
<Check size={14} className="text-green-500" />
) : (
<Copy size={14} />
)}
</button>
);
}
export { CopyButton } from './shared';

/* ---- Dynamic config detail renderer ---- */

Expand Down
31 changes: 30 additions & 1 deletion src/agent_env/explorer/ui/src/components/home-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
BookOpen,
} from 'lucide-react';
import Link from 'next/link';
import { type Page, type HomeCardGroup, PAGE_PATH } from './shared';
import { type Page, type HomeCardGroup, CopyButton, PAGE_PATH } from './shared';

export const QUICK_START_COMMANDS: { purpose: string; command: string }[] = [
{ purpose: 'Open this explorer', command: 'agent-env up' },
{ purpose: 'Deploy an environment', command: 'agent-env env deploy --id <env-id>' },
{ purpose: 'Run a task against it', command: 'agent-env task run --id <task-id>' },
];

export const HOME_CARD_GROUPS: HomeCardGroup[] = [
{
Expand Down Expand Up @@ -84,6 +90,29 @@ export function HomePage({
return (
<div className="p-8">
<h1 className="text-2xl font-semibold mb-8">Home</h1>
<section
aria-labelledby="quick-start-heading"
className="mb-8 max-w-4xl p-6 rounded-lg border border-[var(--border)]"
>
<h2
id="quick-start-heading"
className="text-base font-semibold text-[var(--foreground)] mb-4"
>
Quick start
</h2>
<ol className="flex flex-col gap-3">
{QUICK_START_COMMANDS.map(({ purpose, command }, i) => (
<li key={command} className="flex items-center gap-3">
<span className="w-5 text-sm text-[var(--muted-foreground)]">{i + 1}.</span>
<span className="w-48 text-sm text-[var(--muted-foreground)]">{purpose}</span>
<code className="flex-1 px-3 py-1.5 rounded bg-[var(--muted)] font-mono text-sm text-[var(--foreground)]">
{command}
</code>
<CopyButton text={command} label={`Copy ${command}`} />
</li>
))}
</ol>
</section>
{groups.map(group => (
<div key={group.label} className="mb-8">
<h2 className="text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)] mb-3">
Expand Down
27 changes: 26 additions & 1 deletion src/agent_env/explorer/ui/src/components/shared.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Home as HomeIcon } from 'lucide-react';
import { useCallback, useState } from 'react';
import { Check, Copy, Home as HomeIcon } from 'lucide-react';
import Link from 'next/link';

/** Base URL for hub API calls. Empty by default → same-origin relative paths that next.config.mjs rewrites to
Expand All @@ -19,6 +20,30 @@ export function objectContentUrl(objectUrl: string): string {
return `${BACKEND_URL}/api/v1/objects/content?object_url=${encodeURIComponent(objectUrl)}`;
}

export function CopyButton({ text, label = 'Copy JSON' }: { text: string; label?: string }) {
const [copied, setCopied] = useState(false);
const handleCopy = useCallback(() => {
navigator.clipboard.writeText(text).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
});
}, [text]);
return (
<button
onClick={handleCopy}
className="p-1 rounded hover:bg-[var(--accent)] text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors"
title={label}
aria-label={label}
>
{copied ? (
<Check size={14} className="text-green-500" />
) : (
<Copy size={14} />
)}
</button>
);
}

export const SECTION_HEADER_CLASS =
'text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)]';

Expand Down
Loading