Compare commits
2 Commits
e41676fa5e
...
df05820a95
| Author | SHA1 | Date | |
|---|---|---|---|
| df05820a95 | |||
| d8007fab3d |
@@ -57,17 +57,15 @@ test.describe('Propose Management', () => {
|
||||
console.log('✅ Project created');
|
||||
};
|
||||
|
||||
const createMilestone = async (page: any, name: string) => {
|
||||
const createMilestone = async (page: any, projectName: string, name: string) => {
|
||||
console.log(`📌 Creating milestone: ${name}`);
|
||||
// Navigate to first project and create milestone
|
||||
await page.goto(`${BASE_URL}/projects`);
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.click('.project-card:first-child');
|
||||
await page.click(`.project-card:has-text("${projectName}")`);
|
||||
await page.waitForURL(/\/projects\/\d+/, { timeout: 10000 });
|
||||
await page.click('button:has-text("Milestones")');
|
||||
await page.click('button:has-text("+ New")');
|
||||
await page.waitForSelector('.modal', { timeout: 10000 });
|
||||
await page.fill('.modal input[placeholder*="Milestone title"]', name);
|
||||
await page.fill('input[data-testid="milestone-title-input"]', name);
|
||||
await page.click('.modal button:has-text("Create")');
|
||||
await page.waitForTimeout(1000);
|
||||
console.log('✅ Milestone created');
|
||||
@@ -111,7 +109,7 @@ test.describe('Propose Management', () => {
|
||||
|
||||
// Verify detail page
|
||||
await expect(page.locator('h2')).toContainText(proposeTitle);
|
||||
await expect(page.locator('.project-desc')).toContainText(proposeDesc);
|
||||
await expect(page.locator('.section').filter({ has: page.locator('h3:has-text("Description")') }).locator('p')).toContainText(proposeDesc);
|
||||
await expect(page.locator('.badge:has-text("open")')).toBeVisible();
|
||||
|
||||
// Edit propose
|
||||
@@ -138,7 +136,7 @@ test.describe('Propose Management', () => {
|
||||
await createProject(page, projectName);
|
||||
|
||||
// Create milestone for accept
|
||||
await createMilestone(page, `Milestone for Accept ${TS}`);
|
||||
await createMilestone(page, projectName, `Milestone for Accept ${TS}`);
|
||||
|
||||
// Create propose
|
||||
await page.goto(`${BASE_URL}/proposes`);
|
||||
@@ -167,7 +165,7 @@ test.describe('Propose Management', () => {
|
||||
|
||||
// Verify status changed
|
||||
await expect(page.locator('.badge:has-text("accepted")')).toBeVisible({ timeout: 10000 });
|
||||
await expect(page.locator('.project-meta:has-text("Task:")')).toBeVisible();
|
||||
await expect(page.locator('button:has-text("View Generated Task")')).toBeVisible();
|
||||
|
||||
console.log('✅ Propose accept test passed');
|
||||
});
|
||||
@@ -193,19 +191,19 @@ test.describe('Propose Management', () => {
|
||||
await page.click(`.milestone-card:has-text("${proposeTitle}")`);
|
||||
await page.waitForURL(/\/proposes\/\d+/, { timeout: 10000 });
|
||||
|
||||
// Reject propose
|
||||
// Reject propose (current UI uses prompt, not modal)
|
||||
page.once('dialog', async (dialog) => {
|
||||
expect(dialog.type()).toBe('prompt');
|
||||
await dialog.accept('Rejected by automated test');
|
||||
});
|
||||
await page.click('button:has-text("Reject")');
|
||||
await page.waitForSelector('.modal:has-text("Reject Propose")', { timeout: 10000 });
|
||||
await page.click('.modal button:has-text("Confirm Reject")');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// Verify status changed
|
||||
await expect(page.locator('.badge:has-text("rejected")')).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Reopen propose
|
||||
// Reopen propose (current UI is direct action, no modal)
|
||||
await page.click('button:has-text("Reopen")');
|
||||
await page.waitForSelector('.modal:has-text("Reopen Propose")', { timeout: 10000 });
|
||||
await page.click('.modal button:has-text("Confirm Reopen")');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// Verify back to open
|
||||
@@ -219,7 +217,7 @@ test.describe('Propose Management', () => {
|
||||
await login(page);
|
||||
const projectName = `Edit Hidden Project ${TS}`;
|
||||
await createProject(page, projectName);
|
||||
await createMilestone(page, `Milestone ${TS}`);
|
||||
await createMilestone(page, projectName, `Milestone ${TS}`);
|
||||
|
||||
// Create and accept propose
|
||||
await page.goto(`${BASE_URL}/proposes`);
|
||||
@@ -236,7 +234,8 @@ test.describe('Propose Management', () => {
|
||||
|
||||
// Accept
|
||||
await page.click('button:has-text("Accept")');
|
||||
await page.selectOption('.modal select', { index: 0 });
|
||||
await page.waitForSelector('.modal:has-text("Accept Propose")', { timeout: 10000 });
|
||||
await page.selectOption('.modal select', { label: `Milestone ${TS}` });
|
||||
await page.click('.modal button:has-text("Confirm Accept")');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
const BACKEND_URL = process.env.BACKEND_URL || "http://backend:8000";
|
||||
const PLUGIN_SERVER_URL = process.env.PLUGIN_SERVER_URL || "https://vps.t1:8000";
|
||||
const TEST_TIMEOUT = 120000;
|
||||
|
||||
test.describe("Real OpenClaw Plugin Integration", () => {
|
||||
test.setTimeout(TEST_TIMEOUT);
|
||||
|
||||
test.beforeAll(async () => {
|
||||
console.log("🔌 Testing real plugin integration...");
|
||||
console.log(" Backend: " + BACKEND_URL);
|
||||
console.log(" Plugin Server: " + PLUGIN_SERVER_URL);
|
||||
});
|
||||
|
||||
async function loginAsAdmin(request: any) {
|
||||
const loginRes = await request.post(BACKEND_URL + "/auth/token", {
|
||||
form: { username: "admin", password: "admin123" },
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
});
|
||||
expect(loginRes.ok()).toBeTruthy();
|
||||
const loginData = await loginRes.json();
|
||||
return loginData.access_token;
|
||||
}
|
||||
|
||||
test("should register server and generate API key", async ({ request }) => {
|
||||
const token = await loginAsAdmin(request);
|
||||
|
||||
const serverRes = await request.post(BACKEND_URL + "/monitor/admin/servers", {
|
||||
headers: { Authorization: "Bearer " + token },
|
||||
data: {
|
||||
identifier: "test-real-plugin-vps-t1",
|
||||
display_name: "Test Real Plugin on vps.t1",
|
||||
},
|
||||
});
|
||||
|
||||
expect(serverRes.ok()).toBeTruthy();
|
||||
const serverData = await serverRes.json();
|
||||
const serverId = serverData.id;
|
||||
|
||||
console.log("✅ Server registered: ID=" + serverId);
|
||||
|
||||
const apiKeyRes = await request.post(BACKEND_URL + "/monitor/admin/servers/" + serverId + "/api-key", {
|
||||
headers: { Authorization: "Bearer " + token },
|
||||
});
|
||||
|
||||
expect(apiKeyRes.ok()).toBeTruthy();
|
||||
const apiKeyData = await apiKeyRes.json();
|
||||
|
||||
expect(apiKeyData.api_key).toBeDefined();
|
||||
expect(apiKeyData.api_key.length).toBeGreaterThan(30);
|
||||
|
||||
console.log("✅ API Key generated: " + apiKeyData.api_key.substring(0, 10) + "...");
|
||||
|
||||
process.env.TEST_SERVER_ID = String(serverId);
|
||||
process.env.TEST_API_KEY = apiKeyData.api_key;
|
||||
});
|
||||
|
||||
test("should receive heartbeat from real plugin", async ({ request }) => {
|
||||
const apiKey = process.env.TEST_API_KEY;
|
||||
const serverId = process.env.TEST_SERVER_ID;
|
||||
|
||||
expect(apiKey).toBeDefined();
|
||||
expect(serverId).toBeDefined();
|
||||
|
||||
const heartbeatRes = await request.post(BACKEND_URL + "/monitor/server/heartbeat-v2", {
|
||||
headers: { "X-API-Key": apiKey },
|
||||
data: {
|
||||
identifier: "test-real-plugin-vps-t1",
|
||||
openclaw_version: "0.1.0-test",
|
||||
agents: [{ id: "agent-1", name: "TestAgent", status: "active" }],
|
||||
cpu_pct: 45.5,
|
||||
mem_pct: 60.2,
|
||||
disk_pct: 70.1,
|
||||
swap_pct: 10.0,
|
||||
load_avg: [1.2, 0.8, 0.5],
|
||||
uptime_seconds: 3600,
|
||||
},
|
||||
});
|
||||
|
||||
expect(heartbeatRes.ok()).toBeTruthy();
|
||||
const heartbeatData = await heartbeatRes.json();
|
||||
|
||||
expect(heartbeatData.ok).toBe(true);
|
||||
expect(heartbeatData.server_id).toBe(parseInt(serverId));
|
||||
expect(heartbeatData.identifier).toBe("test-real-plugin-vps-t1");
|
||||
expect(heartbeatData.last_seen_at).toBeDefined();
|
||||
|
||||
console.log("✅ Heartbeat accepted by backend");
|
||||
});
|
||||
|
||||
test("should persist telemetry data to database", async ({ request }) => {
|
||||
const apiKey = process.env.TEST_API_KEY;
|
||||
const serverId = process.env.TEST_SERVER_ID;
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
const token = await loginAsAdmin(request);
|
||||
|
||||
const stateRes = await request.get(BACKEND_URL + "/monitor/admin/servers", {
|
||||
headers: { Authorization: "Bearer " + token },
|
||||
});
|
||||
|
||||
expect(stateRes.ok()).toBeTruthy();
|
||||
const servers = await stateRes.json();
|
||||
|
||||
const testServer = servers.find((s: any) => s.id === parseInt(serverId));
|
||||
expect(testServer).toBeDefined();
|
||||
|
||||
expect(testServer.openclaw_version).toBe("0.1.0-test");
|
||||
expect(testServer.cpu_pct).toBeCloseTo(45.5, 1);
|
||||
expect(testServer.mem_pct).toBeCloseTo(60.2, 1);
|
||||
expect(testServer.last_seen_at).toBeDefined();
|
||||
|
||||
console.log("✅ Telemetry data persisted");
|
||||
});
|
||||
|
||||
test("should reject heartbeat with invalid API key", async ({ request }) => {
|
||||
const heartbeatRes = await request.post(BACKEND_URL + "/monitor/server/heartbeat-v2", {
|
||||
headers: { "X-API-Key": "invalid-api-key-12345" },
|
||||
data: {
|
||||
identifier: "test-real-plugin-vps-t1",
|
||||
openclaw_version: "0.1.0-test",
|
||||
},
|
||||
});
|
||||
|
||||
expect(heartbeatRes.status()).toBe(401);
|
||||
const errorData = await heartbeatRes.json();
|
||||
expect(errorData.detail).toContain("Invalid");
|
||||
|
||||
console.log("✅ Invalid API key correctly rejected (401)");
|
||||
});
|
||||
|
||||
test("should reject heartbeat without API key", async ({ request }) => {
|
||||
const heartbeatRes = await request.post(BACKEND_URL + "/monitor/server/heartbeat-v2", {
|
||||
data: {
|
||||
identifier: "test-real-plugin-vps-t1",
|
||||
openclaw_version: "0.1.0-test",
|
||||
},
|
||||
});
|
||||
|
||||
expect(heartbeatRes.status()).toBe(422);
|
||||
console.log("✅ Missing API key correctly rejected (422)");
|
||||
});
|
||||
|
||||
test("should revoke API key and reject subsequent heartbeats", async ({ request }) => {
|
||||
const apiKey = process.env.TEST_API_KEY;
|
||||
const serverId = process.env.TEST_SERVER_ID;
|
||||
|
||||
const token = await loginAsAdmin(request);
|
||||
|
||||
const revokeRes = await request.delete(BACKEND_URL + "/monitor/admin/servers/" + serverId + "/api-key", {
|
||||
headers: { Authorization: "Bearer " + token },
|
||||
});
|
||||
|
||||
expect(revokeRes.status()).toBe(204);
|
||||
console.log("✅ API key revoked");
|
||||
|
||||
const heartbeatRes = await request.post(BACKEND_URL + "/monitor/server/heartbeat-v2", {
|
||||
headers: { "X-API-Key": apiKey },
|
||||
data: {
|
||||
identifier: "test-real-plugin-vps-t1",
|
||||
openclaw_version: "0.1.0-test",
|
||||
},
|
||||
});
|
||||
|
||||
expect(heartbeatRes.status()).toBe(401);
|
||||
console.log("✅ Revoked API key correctly rejected");
|
||||
});
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
const serverId = process.env.TEST_SERVER_ID;
|
||||
if (!serverId) return;
|
||||
|
||||
try {
|
||||
const token = await loginAsAdmin(request);
|
||||
await request.delete(BACKEND_URL + "/monitor/admin/servers/" + serverId, {
|
||||
headers: { Authorization: "Bearer " + token },
|
||||
});
|
||||
console.log("✅ Test server " + serverId + " cleaned up");
|
||||
} catch (e) {
|
||||
console.log("⚠️ Cleanup warning: " + e);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user