124 lines
5.0 KiB
PHP
124 lines
5.0 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
$base = "/var/www/html/api/ambre-pw-tests";
|
|
|
|
$spec = <<<'JS'
|
|
const { test, expect } = require("@playwright/test");
|
|
|
|
const CAPABILITIES = [
|
|
{ name: "PDF", msg: "Genere un PDF sur: strategie WEVIA 2026", needle: "generated/wevia-" },
|
|
{ name: "Word", msg: "Genere un document Word sur: procedure qualite", needle: "generated/wevia-" },
|
|
{ name: "PPT", msg: "Genere une presentation sur: pitch deck investor", needle: "generated/wevia-" },
|
|
{ name: "Mermaid", msg: "Genere un schema mermaid pour: workflow commandes", needle: "graph TD" },
|
|
{ name: "Image", msg: "Genere une image: paysage nature forest", needle: "generated/wevia-img" },
|
|
{ name: "Code", msg: "Ecris le code python pour: fibonacci recursif", needle: "wevia-code" },
|
|
{ name: "Traduire", msg: "Traduis en anglais: merci beaucoup mon ami", needle: "English" },
|
|
{ name: "Bilan", msg: "bilan complet system", needle: "WEVIA" },
|
|
];
|
|
|
|
test("V7 8/8 capabilities · robust JSON + retry · full video", async ({ page }) => {
|
|
test.setTimeout(480000);
|
|
|
|
let errorCount = 0;
|
|
page.on("pageerror", err => { errorCount++; console.log(`[err] ${err.message.substring(0, 150)}`); });
|
|
page.on("console", msg => {
|
|
if (msg.type() === "error") {
|
|
const t = msg.text();
|
|
if (!t.includes("503") && !t.includes("favicon")) console.log(`[console err] ${t.substring(0, 150)}`);
|
|
}
|
|
});
|
|
|
|
await page.goto("/wevia.html");
|
|
await page.waitForLoadState("networkidle");
|
|
await page.waitForTimeout(2500);
|
|
await page.screenshot({ path: "output/v7-00-initial.png", fullPage: false });
|
|
console.log("📸 Initial v7 captured");
|
|
|
|
const results = [];
|
|
|
|
for (let i = 0; i < CAPABILITIES.length; i++) {
|
|
const cap = CAPABILITIES[i];
|
|
const num = String(i + 1).padStart(2, "0");
|
|
console.log(`\n[${num}/8] ${cap.name}`);
|
|
console.log(` msg: ${cap.msg}`);
|
|
|
|
let success = false;
|
|
let attempts = 0;
|
|
const maxAttempts = 2;
|
|
|
|
while (!success && attempts < maxAttempts) {
|
|
attempts++;
|
|
const attemptLabel = attempts > 1 ? ` (retry ${attempts})` : "";
|
|
|
|
try {
|
|
const beforeNeedleCount = await page.evaluate((n) =>
|
|
(document.body.innerText.match(new RegExp(n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g")) || []).length
|
|
, cap.needle);
|
|
|
|
const input = page.locator("#msgInput");
|
|
await input.click({ force: true });
|
|
await page.keyboard.press("Control+A");
|
|
await page.keyboard.press("Delete");
|
|
await input.fill(cap.msg);
|
|
await page.waitForTimeout(400);
|
|
await input.press("Enter");
|
|
console.log(` 📤 sent${attemptLabel} (needle "${cap.needle}" before: ${beforeNeedleCount})`);
|
|
|
|
const waitStart = Date.now();
|
|
while (Date.now() - waitStart < 45000) {
|
|
const afterCount = await page.evaluate((n) =>
|
|
(document.body.innerText.match(new RegExp(n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g")) || []).length
|
|
, cap.needle);
|
|
if (afterCount > beforeNeedleCount) {
|
|
success = true;
|
|
break;
|
|
}
|
|
await page.waitForTimeout(1500);
|
|
}
|
|
const elapsed = ((Date.now() - waitStart) / 1000).toFixed(1);
|
|
|
|
if (success) {
|
|
console.log(` ✅ PASS in ${elapsed}s${attemptLabel}`);
|
|
} else {
|
|
console.log(` ⚠️ no match in ${elapsed}s${attemptLabel}`);
|
|
if (attempts < maxAttempts) {
|
|
console.log(` 🔁 will retry...`);
|
|
await page.waitForTimeout(3000);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.log(` ❌ attempt${attemptLabel} err: ${e.message.substring(0, 100)}`);
|
|
if (attempts < maxAttempts) await page.waitForTimeout(2000);
|
|
}
|
|
}
|
|
|
|
// Scroll + screenshot
|
|
await page.evaluate(() => {
|
|
const msgs = document.getElementById("messages");
|
|
if (msgs) msgs.scrollTop = msgs.scrollHeight;
|
|
});
|
|
await page.waitForTimeout(2500);
|
|
await page.screenshot({ path: `output/v7-${num}-${cap.name}.png`, fullPage: false });
|
|
console.log(` 📸 v7-${num}-${cap.name}.png`);
|
|
|
|
results.push({ name: cap.name, pass: success, attempts: attempts });
|
|
await page.waitForTimeout(1500);
|
|
}
|
|
|
|
// Final full page
|
|
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
|
await page.waitForTimeout(2000);
|
|
await page.screenshot({ path: "output/v7-99-final.png", fullPage: true });
|
|
|
|
const passCount = results.filter(r => r.pass).length;
|
|
console.log(`\n═══ V7 BILAN ═══`);
|
|
console.log(`Result: ${passCount}/8 capabilities PASS`);
|
|
console.log(`Page errors: ${errorCount}`);
|
|
results.forEach(r => console.log(` ${r.pass ? "✅" : "❌"} ${r.name} (${r.attempts} attempt${r.attempts>1?"s":""})`));
|
|
});
|
|
JS;
|
|
file_put_contents("$base/tests/capabilities-v7.spec.js", $spec);
|
|
@unlink("$base/tests/capabilities-v6.spec.js");
|
|
|
|
echo json_encode(["ok"=>true, "size"=>filesize("$base/tests/capabilities-v7.spec.js")]);
|