Publish early battle QA report

This commit is contained in:
2026-07-05 20:30:51 +09:00
parent 620c9c3eca
commit 5fbfada47a
3 changed files with 91 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import { spawn } from 'node:child_process';
import { existsSync } from 'node:fs';
import { readFile, writeFile } from 'node:fs/promises';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { chromium } from 'playwright';
const cliOptions = parseCliOptions(process.argv.slice(2));
@@ -9,6 +10,7 @@ const targetUrl = process.env.QA_URL ?? `http://127.0.0.1:${defaultQaPort}/`;
const headless = process.env.QA_HEADLESS !== '0';
const maxRounds = Number(process.env.QA_MAX_ROUNDS ?? 80);
const cumulativeMode = process.env.QA_CUMULATIVE === '1';
const qaReportPath = cliOptions.report ?? process.env.QA_REPORT_PATH ?? 'dist/qa-representative-battles.json';
const campaignStorageKey = 'heros-web:campaign-state';
const campaignSlotStorageKey = 'heros-web:campaign-state:slot-1';
const campaignSnapshotPath = process.env.QA_CAMPAIGN_SNAPSHOT_PATH;
@@ -733,6 +735,8 @@ try {
);
}
await writeQaReport(qaReportPath, results, failed);
if (failed.length > 0) {
console.dir(
failed.map((result) => ({
@@ -1570,3 +1574,69 @@ function parseCliOptions(args) {
return options;
}
async function writeQaReport(reportPath, results, failed) {
if (!reportPath) {
return;
}
await mkdir(dirname(reportPath), { recursive: true });
const report = buildQaReport(results, failed);
await writeFile(reportPath, `${JSON.stringify(report, null, 2)}\n`, 'utf8');
console.log(`Wrote QA report ${reportPath}`);
}
function buildQaReport(results, failed) {
const missedObjectives = results.flatMap((result) =>
(result.objectiveDetails ?? [])
.filter((objective) => !objective.achieved)
.map((objective) => ({
battleNo: result.no,
battleId: result.id,
objectiveId: objective.id,
category: objective.category,
summary: objective.summary,
detail: objective.detail,
failureReason: objective.failureReason ?? ''
}))
);
return {
app: 'heros_web',
generatedAt: new Date().toISOString(),
set: qaSetName,
targetUrl,
headless,
maxRounds,
cumulativeMode,
requestedBattles: [...requestedBattles],
battleCount: results.length,
summary: {
victories: results.filter((result) => result.outcome === 'victory').length,
failures: failed.length,
missedObjectiveCount: missedObjectives.length,
battlesWithMissedObjectives: [...new Set(missedObjectives.map((objective) => objective.battleNo))]
},
missedObjectives,
results: results.map((result) => ({
no: result.no,
id: result.id,
outcome: result.outcome,
finalTurn: result.finalTurn,
alliesAlive: result.alliesAlive,
enemiesAlive: result.enemiesAlive,
itemsUsed: result.itemsUsed,
supports: result.supports,
objectivesAchieved: result.objectivesAchieved,
objectiveCount: result.objectiveCount,
missedObjectives: (result.objectiveDetails ?? []).filter((objective) => !objective.achieved),
protectedStatus: result.protectedStatus,
targetStatus: result.targetStatus,
allyStatus: result.allyStatus,
enemyStatus: result.enemyStatus,
battleLogTail: result.battleLogTail,
campSuppliesUsed: result.campSuppliesUsed,
campaign: result.campaign
}))
};
}