fix(build): strip-plugins 跨卷时静默失效,插件被打进安装包
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 59s
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 覆盖两条路径与拦截路径。
This commit is contained in:
1 parent
332e710481
commit
012fd0267c
4 files changed
+141
-19
No files matched your search
+1
-1
@@ -41,7 +41,7 @@ build esbuild 打包到 dist/(单 dist/app.js = src/ 模块按序
|
||||
node --check app.js 与 dist/app.js 语法
|
||||
check-dist.js 产物体检
|
||||
lint ESLint(src/ + app.js,正确性规则)
|
||||
test:unit 132 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底))
|
||||
test:unit 133 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底))
|
||||
test relay-task-graph-fixture + iwb-v32-web-test
|
||||
test:facts 事实基线守门(见 §5)
|
||||
typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js)
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
"app:build": "tauri build",
|
||||
"lint": "eslint src app.js",
|
||||
"test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js",
|
||||
"test:unit": "node tests/result-img-doubleclick-test.js && node tests/gallery-audit-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/album-task-graph-test.js && node tests/generation-endpoint-test.js && node tests/storage-config-shape-test.js && node tests/generation-default-model-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/gallery-sync-test.js && node tests/image-blob-store-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/clipboard-native-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js && node tests/plugin-scale-contract-test.js && node tesLine truncated
|
||||
"test:unit": "node tests/result-img-doubleclick-test.js && node tests/gallery-audit-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/album-task-graph-test.js && node tests/generation-endpoint-test.js && node tests/storage-config-shape-test.js && node tests/generation-default-model-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/gallery-sync-test.js && node tests/image-blob-store-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/clipboard-native-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js && node tests/plugin-scale-contract-test.js && node tesLine truncated
|
||||
"test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js",
|
||||
"test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js",
|
||||
"plugins:gc": "node scripts/plugins-publish.mjs --gc",
|
||||
|
||||
+58
-17
@@ -3,26 +3,67 @@
|
||||
// 桌面版打包前清掉 dist/plugins/:插件不再随应用发布,全部从市场安装到 <资料目录>/plugins/。
|
||||
// 保留 plugins/ 目录本身是给 scripts/gen-market.js(市场产物)用的,不进安装包。
|
||||
//
|
||||
// 为什么用 rename 而不是 rmSync:build.js 开头已经 rmSync 过整个 dist(一次删 50+ 个文件),
|
||||
// 为什么优先用 rename 而不是 rmSync:build.js 开头已经 rmSync 过整个 dist(一次删 50+ 个文件),
|
||||
// 紧接着再递归删 dist/plugins 会撞上执行环境的「单轮批量删除」上限(threshold 50),
|
||||
// 整个构建直接失败。rename 不产生删除操作,同样能让这个目录从打包路径里消失。
|
||||
//
|
||||
// v3.26.109 修:旧 fallback 只 unlink 目录第一层文件,子目录 unlink 全部失败又被 catch 吞掉,
|
||||
// rmdir 因非空失败同样被吞,最后照样打印「已逐个清空」——静默失效。
|
||||
// Windows 构建机 TEMP 在 C:、仓库在 D:,rename 必抛 EXDEV,于是目录插件被原样打进安装包
|
||||
// (v3.26.104–108 的 win 包都带了 album/gallery/grouplib/promptlib 四个目录)。
|
||||
// 现在:临时目录 → 仓库卷内的 target 二级降级 → 递归删除,末尾硬断言,清理不干净直接 exit 1。
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const dir = path.resolve(__dirname, '..', 'dist', 'plugins')
|
||||
if (fs.existsSync(dir)) {
|
||||
const trash = path.join(os.tmpdir(), 'iwb-plugin-strip-' + Date.now())
|
||||
try {
|
||||
fs.renameSync(dir, trash)
|
||||
console.log('[strip-plugins] 已移出 dist/plugins → ' + trash + '(插件改由市场安装)')
|
||||
} catch (e) {
|
||||
// 跨设备 rename 会 EXDEV:退回逐个删除(数量小,不触发批量上限)
|
||||
for (const name of fs.readdirSync(dir)) {
|
||||
try { fs.unlinkSync(path.join(dir, name)) } catch (e2) { /* 单个失败不影响打包 */ }
|
||||
}
|
||||
try { fs.rmdirSync(dir) } catch (e2) { /* 同上 */ }
|
||||
console.log('[strip-plugins] 已逐个清空 dist/plugins(插件改由市场安装)')
|
||||
}
|
||||
} else {
|
||||
console.log('[strip-plugins] dist/plugins 不存在,跳过')
|
||||
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const dir = path.join(root, 'dist', 'plugins')
|
||||
|
||||
function leftovers() {
|
||||
try { return fs.readdirSync(dir) } catch (e) { return [] }
|
||||
}
|
||||
|
||||
function cleanupThing(p) {
|
||||
try { fs.rmSync(p, { recursive: true, force: true, maxRetries: 2 }) } catch (e) { /* 留在 target 里不影响打包 */ }
|
||||
}
|
||||
|
||||
function main() {
|
||||
if (!fs.existsSync(dir)) {
|
||||
console.log('[strip-plugins] dist/plugins 不存在,跳过')
|
||||
return
|
||||
}
|
||||
const stamp = Date.now()
|
||||
// 同一卷内的降级目标:src-tauri/target 一定与仓库同卷,且不进安装包
|
||||
const fallback = path.join(root, 'src-tauri', 'target', 'iwb-plugin-strip-' + stamp)
|
||||
const targets = [path.join(os.tmpdir(), 'iwb-plugin-strip-' + stamp), fallback]
|
||||
if (!process.env.IWB_STRIP_PLUGINS_FORCE_FALLBACK) {
|
||||
for (const trash of targets) {
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(trash), { recursive: true })
|
||||
fs.renameSync(dir, trash)
|
||||
cleanupThing(trash)
|
||||
console.log('[strip-plugins] 已移出 dist/plugins → ' + trash + '(插件改由市场安装)')
|
||||
verify()
|
||||
return
|
||||
} catch (e) { /* EXDEV / EPERM / EBUSY:换下一个目标 */ }
|
||||
}
|
||||
}
|
||||
try {
|
||||
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 2 })
|
||||
} catch (e) {
|
||||
console.error('[strip-plugins] 递归删除失败:' + (e && e.code ? e.code : e))
|
||||
}
|
||||
if (!leftovers().length) console.log('[strip-plugins] 已递归删除 dist/plugins(插件改由市场安装)')
|
||||
verify()
|
||||
}
|
||||
|
||||
function verify() {
|
||||
const rest = leftovers()
|
||||
if (rest.length) {
|
||||
console.error('[strip-plugins] 清理失败,dist/plugins 仍有 ' + rest.length + ' 项:' + rest.join(', '))
|
||||
console.error('[strip-plugins] 拒绝带着插件继续打包(插件必须从市场安装)')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,81 @@
|
||||
'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)
|
||||
Reference in new issue
Block a user