Refine Xiaopei supply road sortie

This commit is contained in:
2026-07-04 14:58:48 +09:00
parent 836b53586e
commit 62e2c58608
5 changed files with 100 additions and 17 deletions

View File

@@ -3,10 +3,10 @@ import { existsSync } from 'node:fs';
import { readFile, writeFile } from 'node:fs/promises';
import { chromium } from 'playwright';
const targetUrl = process.env.QA_URL ?? 'http://localhost:5173/';
const defaultQaPort = process.env.QA_PORT ?? '41737';
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 pnpmCommand = process.env.PNPM_CMD ?? 'pnpm';
const cumulativeMode = process.env.QA_CUMULATIVE === '1';
const campaignStorageKey = 'heros-web:campaign-state';
const campaignSlotStorageKey = 'heros-web:campaign-state:slot-1';
@@ -1478,9 +1478,13 @@ async function ensureLocalServer(url) {
return undefined;
}
const child = spawn(pnpmCommand, ['dev'], {
const viteArgs = localViteServerArgs(url);
if (!viteArgs) {
throw new Error(`QA target is not reachable and cannot be started locally: ${url}`);
}
const child = spawn(process.execPath, viteArgs, {
cwd: process.cwd(),
shell: true,
stdio: 'ignore',
windowsHide: true
});
@@ -1496,6 +1500,28 @@ async function ensureLocalServer(url) {
throw new Error(`Could not start dev server at ${url}`);
}
function localViteServerArgs(url) {
let parsed;
try {
parsed = new URL(url);
} catch {
return undefined;
}
const localHosts = new Set(['localhost', '127.0.0.1', '0.0.0.0', '[::1]', '::1']);
if (!localHosts.has(parsed.hostname) || !parsed.port) {
return undefined;
}
const viteCliPath = 'node_modules/vite/bin/vite.js';
if (!existsSync(viteCliPath)) {
return undefined;
}
const host = parsed.hostname === 'localhost' || parsed.hostname === '0.0.0.0' ? '127.0.0.1' : parsed.hostname;
return [viteCliPath, '--host', host, '--port', parsed.port, '--strictPort'];
}
async function isServerReachable(url) {
try {
const response = await fetch(url);