From 0801b644f6efae0fdfd15d82fa9b721d67305cee Mon Sep 17 00:00:00 2001 From: wujunchen Date: Mon, 27 Apr 2026 20:19:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20address=20CR=20findings=20=E2=80=94=20bu?= =?UTF-8?q?mp=20script,=20test=20runner,=20temp=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - bump-version.mjs: reject duplicate versions (use --force to override), auto git-add manifest.json + versions.json for npm version hook - run-tests.mjs: use execFileSync to handle paths with spaces - test-setup.js: clean up esbuild temp directory on process exit Change-Id: I44410b550d09487dd7f5e30a8f9385a2c500252a --- scripts/bump-version.mjs | 16 +++++++++++++++- scripts/run-tests.mjs | 6 +++--- tests/test-setup.js | 9 +++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/bump-version.mjs b/scripts/bump-version.mjs index 0093eb2..6a02aeb 100644 --- a/scripts/bump-version.mjs +++ b/scripts/bump-version.mjs @@ -4,15 +4,17 @@ * Usage: node scripts/bump-version.mjs * Example: node scripts/bump-version.mjs 1.0.8 */ +import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const root = path.dirname(path.dirname(fileURLToPath(import.meta.url))); const version = process.argv[2]; +const force = process.argv.includes('--force'); if (!version || !/^\d+\.\d+\.\d+$/.test(version)) { - console.error('Usage: node scripts/bump-version.mjs '); + console.error('Usage: node scripts/bump-version.mjs [--force]'); console.error('Example: node scripts/bump-version.mjs 1.0.8'); process.exit(1); } @@ -23,6 +25,11 @@ const versionsPath = path.join(root, 'versions.json'); const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); const versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8')); +if (versions[version] !== undefined && !force) { + console.error(`Version ${version} already exists in versions.json. Use --force to override.`); + process.exit(1); +} + const oldVersion = manifest.version; manifest.version = version; versions[version] = manifest.minAppVersion; @@ -30,5 +37,12 @@ versions[version] = manifest.minAppVersion; fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, '\t') + '\n'); fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t') + '\n'); +// Stage files so npm version hook includes them in the auto-commit. +try { + execFileSync('git', ['add', manifestPath, versionsPath], { cwd: root }); +} catch (_) { + // Not in a git repo or git not available — skip staging. +} + console.log(`Bumped version: ${oldVersion} → ${version}`); console.log(`Updated: manifest.json, versions.json`); diff --git a/scripts/run-tests.mjs b/scripts/run-tests.mjs index 20468cb..524ca04 100644 --- a/scripts/run-tests.mjs +++ b/scripts/run-tests.mjs @@ -1,4 +1,4 @@ -import { execSync } from 'child_process'; +import { execFileSync } from 'child_process'; import { readdirSync } from 'fs'; import { join } from 'path'; @@ -9,9 +9,9 @@ const files = readdirSync(testsDir) let failed = 0; for (const file of files) { - const path = join(testsDir, file); + const filePath = join(testsDir, file); try { - execSync(`node ${path}`, { stdio: 'inherit' }); + execFileSync('node', [filePath], { stdio: 'inherit' }); } catch { failed++; } diff --git a/tests/test-setup.js b/tests/test-setup.js index 497460a..f8b2a9a 100644 --- a/tests/test-setup.js +++ b/tests/test-setup.js @@ -26,6 +26,15 @@ esbuild.buildSync({ const t = require(outfile); +// Clean up temp bundle on process exit. +process.on('exit', () => { + try { + fs.rmSync(tempDir, { recursive: true, force: true }); + } catch (_) { + // Best-effort cleanup. + } +}); + function openAiCardsResponse(cards) { const json = { choices: [