fix: harden Windows startup and rebuild release

This commit is contained in:
shiyue
2026-07-28 08:01:14 +08:00
parent efe7c02ec3
commit 4d97446a6f
7 changed files with 166 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ const WebSocket = require('ws');
const REPO_DIR = path.resolve(__dirname, '..');
const SERVER_PATH = path.join(REPO_DIR, 'server.js');
const WINDOWS_START_PATH = path.join(REPO_DIR, 'start.bat');
const PUBLIC_APP_PATH = path.join(REPO_DIR, 'public', 'app.js');
const PUBLIC_INDEX_PATH = path.join(REPO_DIR, 'public', 'index.html');
const PUBLIC_STYLE_PATH = path.join(REPO_DIR, 'public', 'style.css');
@@ -3587,6 +3588,19 @@ function assertMultiAgentV2CompatibilityContract() {
assert(frontendSource.includes('entry.agentPath ? `路径: ${entry.agentPath}`'), 'Sub-agent cards should expose the canonical agent path');
}
function assertWindowsStartupContract() {
const source = fs.readFileSync(WINDOWS_START_PATH, 'utf8').replace(/\r\n/g, '\n');
assert(source.includes('cd /d "%~dp0"'), 'Windows startup should switch to its own directory and support other drive letters');
assert(/where node(?:\.exe)? >nul 2>&1/i.test(source), 'Windows startup should verify that Node.js is available');
assert(/process\.versions\.node[\s\S]*?>= 18/.test(source), 'Windows startup should reject Node.js versions below 18');
assert(/where npm\.cmd >nul 2>&1/i.test(source), 'Windows startup should verify that npm.cmd is available');
assert(/call npm\.cmd (?:ci|install)/i.test(source), 'Windows startup should use call when invoking npm.cmd');
assert(/if errorlevel 1[\s\S]*?exit \/b 1/i.test(source), 'Windows startup should stop after an environment or dependency failure');
assert(source.includes('set "APP_EXIT_CODE=%ERRORLEVEL%"'), 'Windows startup should preserve the server exit code');
assert(source.includes('exit /b %APP_EXIT_CODE%'), 'Windows startup should return the server exit code to the caller');
}
async function main() {
const targetIndex = process.argv.indexOf('--target');
const regressionTarget = targetIndex >= 0 ? String(process.argv[targetIndex + 1] || '').trim() : String(process.env.CC_WEB_REGRESSION_TARGET || '').trim();
@@ -3657,6 +3671,11 @@ async function main() {
console.log('Session item tooltip regression checks passed.');
return;
}
if (regressionTarget === 'windows-startup') {
assertWindowsStartupContract();
console.log('Windows startup regression checks passed.');
return;
}
throw new Error(`Unknown regression target: ${regressionTarget}`);
}
@@ -3682,6 +3701,7 @@ async function main() {
assertSessionSwitchRaceContract();
assertCodexAppChildToolFallbackContract();
assertMultiAgentV2CompatibilityContract();
assertWindowsStartupContract();
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'cc-web-regression-'));
const configDir = path.join(tempRoot, 'config');