修复 dev:all 端口段与前端就绪判定
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 2m2s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 1m24s
Project CI / Backend tests (pull_request) Failing after 20s
Project CI / Frontend tests (pull_request) Successful in 2m38s
Project CI / Repository checks (pull_request) Failing after 17s
Project CI / AI game creator shell web tests (pull_request) Successful in 1m46s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 9m35s
Project CI / Native shell tests (pull_request) Successful in 6m31s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 11m5s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 2m2s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 1m24s
Project CI / Backend tests (pull_request) Failing after 20s
Project CI / Frontend tests (pull_request) Successful in 2m38s
Project CI / Repository checks (pull_request) Failing after 17s
Project CI / AI game creator shell web tests (pull_request) Successful in 1m46s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 9m35s
Project CI / Native shell tests (pull_request) Successful in 6m31s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 11m5s
将 CLI port-range 同步到 AGC 端口解析环境。 将主站和后台 HTTP readiness 限制为 2xx。 补充真实 HTTP 状态码与端口段传递测试。
This commit is contained in:
+20
-3
@@ -91,6 +91,20 @@ function buildRootDevArgs(argv = []) {
|
||||
];
|
||||
}
|
||||
|
||||
function buildDevAllBaseEnvironment(argv = [], baseEnv = process.env) {
|
||||
let portRange;
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
if (argv[index] === '--port-range') {
|
||||
portRange = argv[index + 1];
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return portRange
|
||||
? { ...baseEnv, GENARRATIVE_DEV_PORT_RANGE: portRange }
|
||||
: { ...baseEnv };
|
||||
}
|
||||
|
||||
function buildDevAllEnvironment(baseEnv = process.env, agcVitePort) {
|
||||
if (!Number.isInteger(agcVitePort) || agcVitePort < 1024) {
|
||||
throw new Error(`AGC Vite 端口无效: ${agcVitePort}`);
|
||||
@@ -120,7 +134,7 @@ async function isHttpReady(url, timeoutMs = 1_000) {
|
||||
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
||||
try {
|
||||
const response = await fetch(url, { signal: controller.signal });
|
||||
return response.status >= 200 && response.status < 500;
|
||||
return response.status >= 200 && response.status < 300;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
@@ -511,11 +525,12 @@ async function runDevAll(argv = process.argv.slice(2), dependencies = {}) {
|
||||
}
|
||||
|
||||
try {
|
||||
const baseEnv = buildDevAllBaseEnvironment(argv);
|
||||
const endpoint = await resolveEndpoint({
|
||||
env: process.env,
|
||||
env: baseEnv,
|
||||
strictConfigured: true,
|
||||
});
|
||||
const env = buildDevAllEnvironment(process.env, endpoint.port);
|
||||
const env = buildDevAllEnvironment(baseEnv, endpoint.port);
|
||||
const rootArgs = buildRootDevArgs(argv);
|
||||
|
||||
console.log(
|
||||
@@ -589,10 +604,12 @@ async function runDevAll(argv = process.argv.slice(2), dependencies = {}) {
|
||||
export {
|
||||
agcDatabase,
|
||||
agcDataDir,
|
||||
buildDevAllBaseEnvironment,
|
||||
buildDevAllEnvironment,
|
||||
buildManagedSpawnOptions,
|
||||
buildRootDevArgs,
|
||||
buildStartupSummary,
|
||||
isHttpReady,
|
||||
isSharedRootStackReady,
|
||||
readDevStackState,
|
||||
renderStartupTable,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { createServer } from 'node:http';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { describe, expect, test } from 'vitest';
|
||||
@@ -6,10 +8,12 @@ import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
agcDatabase,
|
||||
agcDataDir,
|
||||
buildDevAllBaseEnvironment,
|
||||
buildDevAllEnvironment,
|
||||
buildManagedSpawnOptions,
|
||||
buildRootDevArgs,
|
||||
buildStartupSummary,
|
||||
isHttpReady,
|
||||
isSharedRootStackReady,
|
||||
renderStartupTable,
|
||||
runDevAll,
|
||||
@@ -86,6 +90,48 @@ describe('dev:all 参数和共享开发栈合同', () => {
|
||||
expect(baseEnv.AGC_DEV_ADMIN_WEB).toBe('1');
|
||||
});
|
||||
|
||||
test('CLI port-range 覆盖旧环境并同步给 AGC', () => {
|
||||
const env = buildDevAllBaseEnvironment(['--port-range', '10100-10199'], {
|
||||
GENARRATIVE_DEV_PORT_RANGE: '10000-10099',
|
||||
});
|
||||
|
||||
expect(env.GENARRATIVE_DEV_PORT_RANGE).toBe('10100-10199');
|
||||
});
|
||||
|
||||
test.each([
|
||||
[200, true],
|
||||
[204, true],
|
||||
[299, true],
|
||||
[400, false],
|
||||
[401, false],
|
||||
[403, false],
|
||||
[404, false],
|
||||
[500, false],
|
||||
[503, false],
|
||||
])('HTTP %i 的前端就绪结果为 %s', async (status, expected) => {
|
||||
const server = createServer((_request, response) => {
|
||||
response.writeHead(status).end();
|
||||
});
|
||||
await new Promise<void>((resolveListen) => {
|
||||
server.listen(0, '127.0.0.1', resolveListen);
|
||||
});
|
||||
|
||||
try {
|
||||
const { port } = server.address() as AddressInfo;
|
||||
await expect(isHttpReady(`http://127.0.0.1:${port}`)).resolves.toBe(
|
||||
expected,
|
||||
);
|
||||
} finally {
|
||||
server.closeAllConnections();
|
||||
await new Promise<void>((resolveClose, rejectClose) => {
|
||||
server.close((error) => {
|
||||
if (error) rejectClose(error);
|
||||
else resolveClose();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('Windows 下通过 shell 启动 npm.cmd', () => {
|
||||
const options = buildManagedSpawnOptions(process.env);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user