Verify (Gitea) / gate (build · unit · facts) (push) Failing after 59s
Windows 构建机 TEMP 在 C:、仓库在 D:,rename 抛 EXDEV 后旧 fallback 只 unlink 第一层文件,子目录失败被 catch 吞掉、rmdir 也失败被吞,仍打印「已清空」, 四个目录插件(album/gallery/grouplib/promptlib)因此进了 v3.26.104-108 的 win 包。 现在:os.tmpdir → 同卷 src-tauri/target 二级降级 → 递归删除,末尾硬断言, 清不干净 exit 1;新增 tests/strip-plugins-test.js 覆盖两条路径与拦截路径。
82 lines
3.9 KiB
JavaScript
82 lines
3.9 KiB
JavaScript
'use strict'
|
||
// strip-plugins 回归:确保打包前 dist/plugins 真的被清空,清不干净必须 exit 1。
|
||
// 背景(v3.26.109):Windows 构建机 TEMP 在 C:、仓库在 D:,rename 抛 EXDEV 后旧 fallback
|
||
// 只删第一层文件、子目录删不掉又被 catch 吞掉,仍打印「已清空」,导致四个目录插件被静默打进
|
||
// v3.26.104–108 的 win 安装包。这里在临时沙箱里跑真实脚本,覆盖两条路径 + 硬断言。
|
||
const fs = require('fs')
|
||
const os = require('os')
|
||
const path = require('path')
|
||
const { execFileSync } = require('child_process')
|
||
|
||
const SRC = path.join(__dirname, '..', 'scripts', 'strip-plugins.js')
|
||
let pass = 0
|
||
let fail = 0
|
||
function ok(name, cond, extra) {
|
||
if (cond) { pass++; console.log(' ✅ ' + name) } else { fail++; console.log(' ❌ ' + name + (extra ? ' —— ' + extra : '')) }
|
||
}
|
||
|
||
function sandbox(name) {
|
||
const dir = path.join(os.tmpdir(), 'iwb-strip-test-' + name + '-' + Date.now())
|
||
fs.mkdirSync(path.join(dir, 'scripts'), { recursive: true })
|
||
fs.copyFileSync(SRC, path.join(dir, 'scripts', 'strip-plugins.js'))
|
||
fs.mkdirSync(path.join(dir, 'dist', 'plugins', 'album'), { recursive: true })
|
||
fs.mkdirSync(path.join(dir, 'dist', 'plugins', 'promptlib'), { recursive: true })
|
||
fs.writeFileSync(path.join(dir, 'dist', 'plugins', 'index.json'), '{}')
|
||
fs.writeFileSync(path.join(dir, 'dist', 'plugins', 'album', 'main.js'), '// a')
|
||
fs.writeFileSync(path.join(dir, 'dist', 'plugins', 'promptlib', 'main.js'), '// b')
|
||
return dir
|
||
}
|
||
function run(dir, env) {
|
||
try {
|
||
const out = execFileSync(process.execPath, [path.join(dir, 'scripts', 'strip-plugins.js')], {
|
||
env: Object.assign({}, process.env, env || {}), encoding: 'utf8', stdio: 'pipe'
|
||
})
|
||
return { code: 0, out }
|
||
} catch (e) {
|
||
return { code: e.status == null ? -1 : e.status, out: String(e.stdout || '') + String(e.stderr || '') }
|
||
}
|
||
}
|
||
function entries(dir) {
|
||
try { return fs.readdirSync(path.join(dir, 'dist', 'plugins')) } catch (e) { return [] }
|
||
}
|
||
function drop(dir) {
|
||
try { fs.chmodSync(path.join(dir, 'dist'), 0o700) } catch (e) { /* ignore */ }
|
||
try { fs.rmSync(dir, { recursive: true, force: true, maxRetries: 2 }) } catch (e) { /* ignore */ }
|
||
}
|
||
|
||
console.log('===== strip-plugins:dist/plugins 必须被真正清空 =====')
|
||
|
||
// 1. 正常路径:rename 到系统临时目录
|
||
const a = sandbox('rename')
|
||
const ra = run(a)
|
||
ok('rename 路径 exit 0', ra.code === 0, 'exit=' + ra.code + ' out=' + ra.out.trim())
|
||
ok('rename 路径后目录为空', entries(a).length === 0, JSON.stringify(entries(a)))
|
||
drop(a)
|
||
|
||
// 2. EXDEV 降级路径(用环境变量强制跳过 rename,模拟 TEMP 跨卷)
|
||
const b = sandbox('fallback')
|
||
const rb = run(b, { IWB_STRIP_PLUGINS_FORCE_FALLBACK: '1' })
|
||
ok('fallback 路径 exit 0', rb.code === 0, 'exit=' + rb.code + ' out=' + rb.out.trim())
|
||
ok('fallback 路径后子目录也清空(旧实现在这里静默失败)', entries(b).length === 0, JSON.stringify(entries(b)))
|
||
drop(b)
|
||
|
||
// 3. 删不掉时必须 exit 1(不能带着插件继续打包)
|
||
const c = sandbox('guard')
|
||
fs.chmodSync(path.join(c, 'dist'), 0o500)
|
||
const rc = run(c, { IWB_STRIP_PLUGINS_FORCE_FALLBACK: '1' })
|
||
ok('清理失败 exit 1', rc.code === 1, 'exit=' + rc.code)
|
||
ok('清理失败时明确报错', /拒绝带着插件继续打包/.test(rc.out), rc.out.trim().slice(0, 120))
|
||
ok('清理失败时仍有残留(证明确实拦住的是真实残留)', entries(c).length > 0)
|
||
drop(c)
|
||
|
||
// 4. 没有 dist/plugins 时跳过而不是报错
|
||
const d = path.join(os.tmpdir(), 'iwb-strip-test-none-' + Date.now())
|
||
fs.mkdirSync(path.join(d, 'scripts'), { recursive: true })
|
||
fs.copyFileSync(SRC, path.join(d, 'scripts', 'strip-plugins.js'))
|
||
const rd = run(d)
|
||
ok('dist/plugins 不存在时 exit 0 且提示跳过', rd.code === 0 && /不存在,跳过/.test(rd.out), rd.out.trim())
|
||
drop(d)
|
||
|
||
console.log('\nstrip-plugins checks: ' + pass + ' 通过 / ' + fail + ' 失败')
|
||
process.exit(fail ? 1 : 0)
|