Skip to content

Commit 662f4ba

Browse files
committed
fix publisher plugin tests
1 parent abce5c3 commit 662f4ba

7 files changed

Lines changed: 481 additions & 173 deletions

File tree

apps/agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"script:createToken": "node dist/scripts/createToken.js",
2222
"test": "PLAYWRIGHT_JUNIT_OUTPUT_NAME=DKG_Node_UI_Tests.xml npx playwright test spec/testUI.spec.js --grep '@gh_actions' --reporter=list,html,junit",
2323
"test:e2e": "PLAYWRIGHT_JUNIT_OUTPUT_NAME=DKG_Node_UI_Tests.xml npx playwright test spec/testUI.spec.js --reporter=list,html,junit",
24-
"test:e2e:publisher": "PLAYWRIGHT_JUNIT_OUTPUT_NAME=DKG_Node_Publisher_Tests.xml npx playwright test spec/publisherPluginTest.spec.js --reporter=list,html,junit",
24+
"test:e2e:publisher": "node tests/e2e/setup/cleanup.js && PLAYWRIGHT_JUNIT_OUTPUT_NAME=DKG_Node_Publisher_Tests.xml npx playwright test spec/publisherPluginTest.spec.js --reporter=list,html,junit",
2525
"test:install": "npx playwright install",
2626
"test:integration": "NODE_OPTIONS='--import tsx' mocha 'tests/integration/**/*.spec.ts' --require tests/integration/setup/global-setup.ts",
2727
"test:ragas": "NODE_OPTIONS='--import tsx' tsx tests/ragas/evaluate.ts",

apps/agent/tests/e2e/pages/chatbotPage.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,35 @@ class ChatbotPage {
99
this.btn_continue = this.page.getByTestId("tool-continue-button");
1010
}
1111

12-
async waitForChatReady() {
13-
// Wait for chat input to be enabled and ready (no timeout)
14-
await this.page.waitForFunction(
15-
() => {
16-
const chatInput = document.querySelector('[data-testid="chat-input"]');
17-
return chatInput && !chatInput.disabled && chatInput.value === "";
18-
},
19-
{},
20-
{ timeout: 0 },
21-
);
12+
async waitForChatReady(timeoutMs = 30000) {
13+
// Wait for chat input to be enabled and ready
14+
try {
15+
await this.page.waitForFunction(
16+
() => {
17+
const chatInput = document.querySelector('[data-testid="chat-input"]');
18+
return chatInput && !chatInput.disabled && chatInput.value === "";
19+
},
20+
{},
21+
{ timeout: timeoutMs },
22+
);
23+
} catch (error) {
24+
throw new Error(`Chat input not ready after ${timeoutMs}ms: ${error.message}`);
25+
}
2226
}
2327

24-
async waitForResponse(questionText = "") {
28+
async waitForResponse(questionText = "", timeoutMs = 60000) {
2529
// Wait for DKG Node to finish processing and provide a real response (not "Thinking...")
26-
const checkInterval = 5000; // Check every 5 seconds
30+
const checkInterval = 2000; // Check every 2 seconds
31+
const startTime = Date.now();
2732

2833
while (true) {
34+
// Check if we've exceeded the timeout
35+
if (timeoutMs > 0 && Date.now() - startTime > timeoutMs) {
36+
throw new Error(
37+
`waitForResponse timed out after ${timeoutMs}ms waiting for response to: "${questionText}"`
38+
);
39+
}
40+
2941
try {
3042
const messages = await this.page.$$eval(
3143
'[data-testid="chat-message-text"]',
@@ -39,7 +51,7 @@ class ChatbotPage {
3951
const isNotThinking = !lastMessage.trim().startsWith("Thinking");
4052
const isNotSameAsQuestion =
4153
lastMessage.trim() !== questionText.trim();
42-
const hasContent = lastMessage.length > 0;
54+
const hasContent = lastMessage.length > 10; // Require at least some content
4355

4456
const shouldComplete =
4557
hasContent && isNotThinking && isNotSameAsQuestion;
@@ -52,6 +64,8 @@ class ChatbotPage {
5264
// Wait before next check
5365
await this.page.waitForTimeout(checkInterval);
5466
} catch (error) {
67+
// Log error but continue trying
68+
console.log(` ⚠️ waitForResponse error: ${error.message}`);
5569
await this.page.waitForTimeout(checkInterval);
5670
}
5771
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Pre-test cleanup script
3+
* Runs BEFORE Playwright starts the dev server to ensure clean state
4+
*/
5+
6+
const Redis = require("ioredis");
7+
const mysql = require("mysql2/promise");
8+
const dotenv = require("dotenv");
9+
const path = require("path");
10+
11+
// Load test environment variables
12+
dotenv.config({
13+
path: path.join(__dirname, "..", ".env.testing.testnet.local"),
14+
override: true,
15+
});
16+
17+
async function cleanup() {
18+
console.log("\n🧹 Pre-test cleanup: Clearing Redis and Database...");
19+
20+
// Clear Redis
21+
try {
22+
const redis = new Redis({
23+
host: process.env.REDIS_HOST || "localhost",
24+
port: parseInt(process.env.REDIS_PORT || "6379"),
25+
retryStrategy: () => null,
26+
});
27+
28+
await redis.flushall();
29+
console.log("✅ Redis cleared (all BullMQ jobs removed)");
30+
await redis.quit();
31+
} catch (error) {
32+
console.warn("⚠️ Redis cleanup failed:", error.message);
33+
process.exit(1); // Fail the test if Redis can't be cleared
34+
}
35+
36+
// Clear MySQL
37+
try {
38+
const dbUrl = process.env.DKGP_DATABASE_URL || "mysql://root:@127.0.0.1:3306/dkg_publisher_db";
39+
const match = dbUrl.match(/mysql:\/\/([^:]+):([^@]*)@([^:]+):(\d+)\/(.+)/);
40+
41+
if (!match) {
42+
throw new Error("Invalid database URL format");
43+
}
44+
45+
const [, user, password, host, port, database] = match;
46+
47+
const connection = await mysql.createConnection({
48+
host,
49+
port: parseInt(port),
50+
user,
51+
password: password || undefined,
52+
database,
53+
});
54+
55+
await connection.execute("DELETE FROM publishing_attempts");
56+
await connection.execute("DELETE FROM assets");
57+
await connection.execute("UPDATE wallets SET is_locked = 0, locked_by = NULL, locked_at = NULL");
58+
await connection.execute("ALTER TABLE assets AUTO_INCREMENT = 1");
59+
60+
console.log("✅ Database cleared (assets, attempts, wallets unlocked)");
61+
console.log("✅ Asset ID counter reset to 1");
62+
await connection.end();
63+
} catch (error) {
64+
console.warn("⚠️ Database cleanup failed:", error.message);
65+
process.exit(1); // Fail the test if DB can't be cleared
66+
}
67+
68+
console.log("🚀 Cleanup complete - environment ready for fresh test\n");
69+
}
70+
71+
cleanup().catch((error) => {
72+
console.error("💥 Cleanup script failed:", error);
73+
process.exit(1);
74+
});

0 commit comments

Comments
 (0)