Repository navigation
feat(scripts): 优化 EduWork 跨平台编译流程 - #76
Conversation
Add Node.js (.mjs) ports beside the existing PowerShell scripts so the Web assembly, desktop inputs, shell assembly and packaging can run without PowerShell. Shared helpers live in scripts/lib/. The .ps1 files and CI workflows are unchanged; shim conversion, test migration and the CI switch follow separately (see docs/SCRIPTS_MIGRATION.md). - scripts/local-desktop-pipeline.mjs: one-command local build, install and launch smoke (Windows x64, macOS arm64; Linux runs Web validation) - Release orchestrators accept --no-verify-snapshot for local working trees (recorded as sourceSnapshotVerified: false) and --runtime-source to reuse a verified DSH Runtime cache; defaults stay strict - dev-studio-web.mjs links the Studio profile in-process - source-receipt.json: review entries for the changed/new files Not yet validated end to end: the macOS run reached the Whisper model download; the Windows chain has not run on Windows.
assemble-macos.mjs copied only icon-blue/icon-red/dock-blue into the app payload. product.mjs resolves dock-red-1024.png at startup for the red Dock variant, so the installed app exited immediately with a missing asset error. - assemble-macos.mjs: copy all eight brand assets via the BRAND_ASSETS list, and assert that every file in brand/ is covered so a future asset cannot be dropped silently - assemble-macos.mjs: call build-dock-plugin.mjs after the plist edits and before signing; the Dock tile plugin was never compiled - assemble-macos.mjs: honour sourceAlpha (app name suffix, appId, disabled updates, and fail when Sparkle is enabled) - assemble-macos.mjs: skip the renderer step when the input is absent, matching the PowerShell behaviour - assemble-windows.mjs: same sourceAlpha handling, without which the Alpha build still emitted the GitHub update provider Verified on macOS arm64: re-assembly of the existing build workspace produced a ZIP with all eight assets, the Dock plugin, NSDockTilePlugIn set and a valid deep code signature; the extracted app installed to ~/Applications and ran without a crash report.
The audit aggregated each child directory with a spread call, so a working tree holding a large vendored subtree died with a RangeError before it reported anything. The generated directories that triggered the overflow were also reported as violations once reached, so the only way to audit a checked-out repository was to delete them first. Walk iteratively, keep one list of generated directory names driving both the traversal and the violation rule, and report what was pruned. Tests reproduce the overflow under a reduced stack and cover pruning plus a violation that must still be reported.
The release orchestrators hardcode one linear await chain each, so nothing can be re-run after a failure, nothing can overlap and every invocation rebuilds work it already did. The two platform chains have already drifted apart from each other. Add the layer they can share: stages declare the stages they consume, the parameters that change their output and the artifacts they produce. The runner orders them, runs independent ones together up to a job limit, and records a checkpoint that a later invocation re-enters. A recorded artifact that vanished or changed underneath the checkpoint stops the run instead of being trusted, and a non-empty workspace without a checkpoint is not adopted silently. The runner is platform-neutral; the orchestrator supplies the stages.
The macOS release orchestrator was a linear await chain: the order in which
steps ran was the order in which they were written, nothing recorded which
artifacts existed, and a rerun redid the whole build. This replaces that with
stage declarations the runner can order, skip and clean.
stage-runner.mjs gains three things the product tree forced:
* `mutableOutputs` — the desktop product is created by one stage and appended
to by later stages (native resources, Host modules). Its digest is not a
fingerprint, so it is verified to exist rather than to match.
* `clean` — a rerun removes what the stage owns before running it. Every
stage entry point still refuses an existing directory for direct CLI use;
the runner never trips that guard because it clears the path first.
* output ownership — two stages may not create the same tree, which would be
unordered and unsafe under parallelism.
The macOS pipeline is now three files: shared-desktop-stages.mjs holds the
spine every platform shares, macos-stages.mjs adds the native inputs, assembly,
acceptance and publish stages, and ci-eduwork-macos-release.mjs validates
arguments and writes the receipt. Platform differences enter through the stage
catalog, not through a platform branch in the orchestrator.
prepare-macos-release-inputs.mjs is split so the expensive half can be cached:
`prepare` builds a native input tree from the lock file alone, `install` copies
it into a product and checks the pinned speech model against the product's own
transcription catalog — a check that cannot run earlier, since that catalog
only exists once a product is installed.
The five failing tests in the suite (three source-reproducibility, two Web
launch) also fail on the parent commit; they are macOS /var symlink
assumptions, not regressions from this change.
Move the Windows release chain onto the same declarative catalog the macOS chain uses: native inputs, native install, desktop candidate assembly with the portable ZIP, packaged launch acceptance and publish. The orchestrator keeps only argument validation, workspace entry and the run receipt. Ownership is split so a rerun of one stage cannot destroy another's artifact: the ZIP is produced by `desktop` and copied by `publish`, and acceptance consumes it instead of packing it. Native inputs are reusable across products because `prepare` reads the pinned runtime manifests and the reviewed source catalog, while `install` is what checks the product's own transcription catalog. The Windows chain cannot be built on macOS and has never run on a Windows runner; both files say so explicitly.
Native inputs do two expensive things: download pinned archives and compile OpenSSL and whisper.cpp. Both are pure functions of data already in the repository, so both can be reused without weakening a pin. `download` gains a content-addressed layer keyed by the pinned SHA-256, which is also the integrity check. An unpinned download is deliberately not cached: without a hash there is no key, and storing an unverified response would make the cache a way around the pin. A corrupted entry is discarded rather than served. The compile layer keys on the source archive, the patch set, the target and the resolved tool versions, so a compiler upgrade invalidates it instead of silently reusing objects another compiler produced. A restored entry is re-hashed against its manifest before it is admitted, so a tampered cache cannot put different bytes into a release. Both layers live under the OS temporary directory by default, never inside the repository: the source audit rejects generated content, and a cache in the tree turns one build into the next one's failure. --cache-root overrides it.
Both were found by comparing an end-to-end run against the pre-refactor baseline, and neither would have shown up in a unit test. `native-install` rejected Python's own symlinks. The baseline extracted the Python tarball straight into `product/r/p`, so `bin/python3 -> python3.12` was created and never traversed. The prepare/install split copies a prepared tree instead, and the link-rejecting copy refused it. The runtime and the browser now use the link-preserving copy; payloads that must not depend on anything outside themselves still use the strict one. `product` pinned a file that `install-host` rewrites. `product` recorded `product/assembly.json` as an immutable output, but `install-product-host` conditionally rewrites it to record the adapter it installed, so re-entry failed with EDUWORK_MODIFIED_ARTIFACT. This is exactly what `mutableOutputs` is for: the stage now promises the tree exists, not that every byte is frozen.
The concurrency limit was a hand-passed number. Nothing in the code said how wide the pipeline could actually run, so the only safe default was one worker and a value above the real width silently bought nothing. `parallelSets` computes the waves from the declared edges — everything in a wave can run at once, and each wave depends only on earlier ones — and `maxParallelism` returns the widest one. No run can finish sooner than that, so it is the default: `--jobs 0` means "as wide as the graph allows" and an explicit number still wins. This is derived rather than written down for the same reason the decision diagram is generated rather than drawn: a hand-maintained stage order drifts from the stages.
The previous diagrams were drawn by hand and had already drifted: both stated a frozen file count that was wrong, and their stage numbering existed nowhere in the repository, so nothing could detect the difference. The generator reads the same stage catalogs the build runs, so the picture is a projection of the graph rather than a second description of it. Waves come from `parallelSets`, hashed dependencies draw solid and ordering-only edges dashed, and mutable-output stages are shaded because they decide where a later stage may legitimately append. Emitted as .drawio (the editable source of record), .mmd for text readers, and .json for tooling. A test regenerates them and fails on any difference, so a stale diagram is a failing build rather than a wrong document.
Each check replaces a failure that would otherwise surface minutes in, after downloads and compiles had already happened. Tools are probed and reported with their version. The probe only treats ENOENT as absent: `ditto --help` and `codesign --version` both exit non-zero on a healthy macOS, so a non-zero exit is not evidence a tool is missing. The upstream cache is inspected for the damage that has actually occurred — a pnpm virtual store left with build output but no `package.json`, while the bookkeeping that would trigger a reinstall still calls the tree complete. It reports and stops there: a half-installed cache is usually recoverable, and deleting someone's cache is not this script's decision. Pinned URLs are HEAD-probed, so a withdrawn release is discovered before a download rather than during one. The speech model also moves ahead of the OpenSSL and whisper.cpp compiles. It was fetched last, so a network failure discarded several minutes of build work that could not be reused.
Records the design, the verification and the limits of the restructured pipeline: the stage declarations and what each field commits to, why the cache has two layers, how artifact ownership decides the serialization, and how the parallel width is derived rather than chosen. States the limits plainly, including the one that is easy to overstate: the pipeline is not byte-reproducible, and was not before this work. Two builds of one commit differ in roughly 200 files through embedded absolute paths, timestamps and ad-hoc signatures. The Windows x64 chain is written against the same declarations but has never been executed, because it cannot be built on macOS. The document and the code both say so.
The one-command entry point gained --jobs, --reuse-workspace and --cache-root when the pipeline became a stage graph, and now preflights before the expensive work. BUILD.md described the entry point without them.
The checked-in .png was exported by hand from the .drawio, so nothing could compare it to the stages it claimed to show. That is the same failure that motivated generating the diagrams in the first place: the hand-drawn versions had already drifted by 70 files before anything noticed. - scripts/build-pipeline-diagram.mjs: emit .svg beside .drawio/.mmd/.json. The layout is the GitHub palette — a bordered header with the run summary, one labelled lane per wave, white cards, hashed dependencies solid green and ordering-only edges dashed grey, mutable-output stages in the attention colour. Descriptions are clipped to the card rather than overflowing it, which the previous 200x60 box did. - The .drawio export keeps its grid but adopts the same palette, so the two views no longer disagree about what the pipeline looks like. - tests/build-pipeline-diagram.test.mjs: compare the .svg against the stages like the other generated assets, and assert that every declared stage is drawn, both edge kinds are present, and the waves are labelled. - Delete docs/assets/build-pipeline-macos.png. The .svg replaces it and, unlike a raster, is diffable and therefore testable.
Three gaps in the checkpoint layer, all of which let a workspace be reused in a state the pipeline no longer describes. * Workspace lock. The one-owner-per-output rule is enforced inside a single process; two processes sharing one --workspace interleave stage runs and overwrite each other's records. Entry now takes an atomic lock directory with an owner record, released by `release()` and by `runStages` on both the pass and fail paths, so a failed run does not block the rerun that fixes it. A lock whose process is gone is recovered rather than honoured, and a lock held by the same process is re-entrant — the lock exists to keep a second process out, not to serialize a process against itself. `--lock-wait` bounds the wait; the default refuses immediately rather than queueing silently. * Catalog check. The checkpoint now records a digest of the stage catalog, and re-entry refuses when it differs. A deleted stage previously left its record behind forever; a stage whose *dependencies were narrowed* kept reusing a `dependenciesDigest` computed from an edge that no longer exists. Both were silent, because the recorded artifacts are still on disk. The error names the added and removed stages, and a checkpoint too old to carry the digest is refused rather than adopted. * Verification depth. `digestPath` hashes whole trees, so a GB-scale artifact cost more to check than to rebuild. Artifacts are now recorded with the depth they were checked at: `bytes` by default, falling back to the file list and sizes above `--digest-budget` (2 GiB), and `trust` only where a stage declares it. Both weaker depths are reported on every re-entry, because "admitted by size" and "checked" are not the same claim. Comparing a size digest against a bytes digest re-digests rather than reporting a difference that says nothing about the artifact. Adds 9 tests covering the refusal, the stale-lock recovery, the re-entrant case, all three catalog mismatches, the budget fallback and `trust`.
The cache defaulted to `os.tmpdir()`. On a GitHub-hosted runner that is `RUNNER_TEMP`, which is emptied at the start of every job and destroyed when the job ends, so both cache layers were silently useless in CI — the one place a cold cache costs the most. On macOS it is a long random per-user path that is also not the temporary directory most people mean. - On POSIX the default is now a flat `/tmp/eduwork-native-cache`; Windows keeps `%TEMP%`, which is the documented location there. `EDUWORK_TMPDIR` relocates the root and `EDUWORK_CACHE_ROOT` overrides the directory outright, so a CI caller can point the cache at something it actually persists (for example via actions/cache) without a code change. - Both release orchestrators and the local pipeline accept `--cache-root`, `--digest-budget` and `--lock-wait`, and set the cache root before any work starts, since the native-input stage is what reads it. - docs/NATIVE-INPUT-CACHE.md records why `$TMPDIR` was rejected rather than leaving the next reader to rediscover it.
|
已审查提交 native-inputs 缓存保存时,把单文件输出 whisper-cli 当成目录调用 readdir,触发 ENOTDIR 并中断构建。此前语音组件已经编译完成,但后续 Electron 装配、客户端启动及真实功能验收均被这个错误阻挡。 脚本测试通过不能代替实际完整构建。合并前需要正确处理文件与目录两类缓存输出,覆盖首次构建和缓存命中后的重复构建,解决与 main 的冲突,再从该分支生成完整 Mac 候选并验证能正常使用。当前应继续保持 Draft。 |
|
已接续审查并修复此前阻止 #76 合并的两处确定问题,接续 PR:#114。 第一处是原生缓存把 原贡献者提交历史保留,以 merge 对齐 main 后增补修复。最终提交为 性能对照的 123.2 → 15.0 秒来自较早的 最终候选的本机 QA 副本已经过 macOS 正常启动的真实客户端验收:在界面配置本机合成模型服务并鉴权发现模型、完成对话;真实上传 TXT 附件后,文件读取工具完整返回两行内容;包内 Chromium 经客户端一次工具授权,实际 navigate 和 snapshot 返回合成页面标题与正文。 实际 Electron safeStorage 保存合成模型密钥。通过原生应用菜单退出后,客户端及其跟踪子进程全部结束;正常重启后,会话、附件和工具历史保留,TXT 完整 SHA-256 一致,无需再次输入密钥即可再次鉴权对话。重启后再次正常退出也没有残留客户端进程。 Windows/Linux 完整原生构建与运行尚未验收,模型测试也未覆盖外部模型服务或机构 SSO。原生目录选择本次验收失败:旧选择器可并发弹出多个窗口,macOS 对话框没有归属 EduWork 主窗口。后续工具回归的合成工作区在应用退出后通过官方支持的可编辑 JSON 配置准备,不能视为原生选择通过。相关实现与 main 一致,属于单独跟进的既有问题。 此前两处确定的构建失败已经修复,Node 构建和缓存目标已通过 macOS 实际构建与客户端回归。接续 #114 的远端源码与已验收版本一致,四项自动 CI(local-web、macOS/Windows native-host、windows-extractor)全部通过,GitHub 确认无合并冲突。因此,现在建议合并接续 #114;原 #76 当前 head 仍为此前的实现,建议用保留其贡献历史的接续修复替代。 |
问题与修改
将桌面构建的主要流程从 PowerShell 迁移到 Node.js,统一本机构建、自动开发包和手动候选的构建配方,减少 Windows 与 macOS 之间的实现差异。
.mjs,微软 DLL 签名通过 Windows SDK SignTool 校验。renderer的问题,使不生成独立 renderer 目录的原生壳能够正常打包。验证
87858cb上完成本地开发包完整构建,退出码为 0。sourceSnapshotVerified: true。本次 Windows 验证使用开发版
0.4.1-dev.20261010.1,未执行稳定版升级契约、公开版解包器验收或 GitHub Release 发布。真实登录、模型会话及完整业务流程不在本次构建验证范围内。兼容性与后续事项