feat: bootstrap a bundled Windows runtime and run documents on win32
ci/woodpecker/tag/ci Pipeline was successful

- bundle-runtime deps: launcher points bootstrap at runtime-deps when present;
- install native Windows CLI/Worker names and platform-aware executable lookup;
- accept pc-windows-msvc offline archive names and fix workspace path containment with path.relative;
- package-windows gains -RuntimeDeps with digest verification and records bundled_runtime;
- tests/docs for the Windows offline runtime and executable names.
This commit is contained in:
cflmy committed 2026-12-03 00:37:54 +08:00
1 parent 54f1c090fc
commit 0d3a9c4369
9 files changed
+92 -16

No files matched your search

+2
View File
@@ -55,6 +55,8 @@ MQDH_HOME\ # 用户数据,默认 %USERPROFILE%\.local
`install.ps1` 支持 `-Prefix`、`-NoPath`、`-NoShortcut`、`-Uninstall`。它把已解压树移入 `versions/`(同一卷内是移动,不复制整套依赖),写入 `current.json`,生成读指针的 `bin\mqdh.cmd`,可选加入用户 PATH 与开始菜单快捷方式;卸载只删除安装树与指向它的启动器,保留 `MQDH_HOME`。解压后的目录也可直接用根目录 `mqdh.cmd` 运行(便携模式)。Windows 产物当前未签名,应用内自动更新未验证;Windows 用户按发布说明手动下载安装新版本。
Windows 实验包内置离线运行时目录 `runtime-deps/`:一个 `marqdo-3.0.0-rc.7-x86_64-pc-windows-msvc.tar.gz` 及其 `.sha256`,内含 CLI、Provider Worker 与 `marqdo-stdlib 0.3.0` Bundle。`scripts/mqdh.mjs` 在未显式设置 `MQDH_BOOTSTRAP_OFFLINE` 时把 bootstrap 指向该目录,因此首次启动可在无网络时完成运行时安装与校验;`mqdh bootstrap --offline <dir>` 可覆盖。该离线包只提供运行时,默认 Knowledge/View Tool 在没有 Windows 归档时以 `bootstrap.offline_tool_missing` 显式跳过,不伪造安装。运行时归档、Bundle 摘要、平台 target 与二进制摘要由 `RELEASE_INFO.json` 声明并在安装前校验。
## 3. 发行合同
`mqdh-release.json`(一个平台一个文件)由 `scripts/release-manifest.ts` 生成:
+3 -1
View File
@@ -37,9 +37,11 @@ MQDH_PACKAGE_WORK=/var/tmp/mqdh-package bash scripts/package.sh
pnpm install --frozen-lockfile --ignore-scripts
pnpm run build
$env:MQDH_NODE24_DIR = 'C:\path\to\node24'
powershell -ExecutionPolicy Bypass -File .\scripts\package-windows.ps1
powershell -ExecutionPolicy Bypass -File .\scripts\package-windows.ps1 -RuntimeDeps C:\path\to\runtime-deps
```
`-RuntimeDeps` 是一个受控离线运行时目录:其中 `marqdo-<version>-x86_64-pc-windows-msvc.tar.gz` 与 `.sha256` 必须来自组件仓的 Windows 运行时构建,包含 CLI、Provider Worker、`RELEASE_INFO.json`、`SOURCE_SHA` 与 Bundle;打包脚本会逐字节校验摘要并把该目录放进应用树的 `runtime-deps/`,由启动器在首次 bootstrap 时使用。
输出 `.ci/marqdo-harness-<version>-x86_64-pc-windows-msvc.tar.gz`、`.sha256`、`mqdh-release.json`、`release-evidence.json`、`package-evidence.json`。发布使用实验性 tag(例如 `mqdh-win-experimental-<date>`),不属于 `mqdh-v<version>` 更新渠道;不得用它替换 Linux 正式 tag 或声称 Windows 已 supported。升级路径:用户手动下载运行新 `install.ps1`;应用内 Windows 更新未验证。
## 4. 签名(可选但推荐)
+2 -2
View File
@@ -102,7 +102,7 @@ sha256 `68cbb8f878af47a44a8e0ff7625b647ff4b8ac5817cda02e0a31fdc658fdcd7d`,
| BOOT-02 首次启动 Web 向导、真实进度、CLI bootstrap | PASS | `/mqdh/api/bootstrap` 与 `/mqdh` 页面实测;真实下载字节进度与步骤状态。 |
| BOOT-03 断点/恢复/并发锁、失败回滚、离线包 | PARTIAL | staging 清理 + 单实例锁 + 失败不切换已实现并测试;离线目录安装已实现;真实弱网/断网与续传演练未运行。 |
| BOOT-04 Knowledge/View 默认 Tool 安装与真实 smoke | PASS | knowledge v0.1.0-beta.3、view v0.3.0 安装成功;知识 compile/query hits=3;view 工具能力仍受上游接口限制(P09)。 |
| BOOT-05 跨平台验证、repair、发布候选 | PARTIAL | `repair` 已实现并测试;macOS/Windows 引导未验证。 |
| BOOT-05 跨平台验证、repair、发布候选 | PARTIAL | `repair` 已实现并测试;Windows 离线 bootstrap 已在本机真机验证(内置 `runtime-deps`,真实 check/call smoke=120),macOS 引导未验证。 |
## 诊断(DIAG)
@@ -120,7 +120,7 @@ sha256 `68cbb8f878af47a44a8e0ff7625b647ff4b8ac5817cda02e0a31fdc658fdcd7d`,
| --- | --- | --- |
| DIST-01 清单 schema、命名、tag/证据、Linux tar 冷安装 | PASS(已发布) | `mqdh-v0.1.0-beta.1`:`mqdh-release.json` + `.sha256` + `release-evidence.json`(含 `cli@63562d8…` 运行时依赖);归档 786,741,787 B / sha256 `68cbb8f8…`;冷安装/`doctor`/`dump-config` 通过;未签名。 |
| DIST-02 Linux `.deb`/AppImage、用户级安装/卸载 | PARTIAL | 用户级 `install.sh`/`--uninstall` 已实现并测试;`.deb`/AppImage 未构建。 |
| DIST-03 macOS/Windows 构建与冷安装 | PARTIAL | Windows x86_64 实验性归档已在本机原生构建并冷安装验证(未签名、无原生 CI lane、应用内更新未验证);macOS 无签名/公证证书,`UNVERIFIED`。 |
| DIST-03 macOS/Windows 构建与冷安装 | PARTIAL | Windows x86_64 实验性归档已在本机原生构建并冷安装验证,内置离线运行时可在无网络下完成 bootstrap(CLI rc.7 Windows + Bundle 0.3.0,check/call smoke=120);未签名、无原生 CI lane、应用内更新未验证;macOS 无签名/公证证书,`UNVERIFIED`。 |
| DIST-04 签名、SBOM、代理/镜像、离线安装 | PARTIAL | Ed25519 清单签名/验证与测试密钥通过;官方密钥、SBOM、离线应用更新未运行。 |
| DIST-05 更新检查/安装/回退、通知与对账 | PARTIAL | `update check` 对真实 Release 可用;`install/rollback` 仍只用本地发布服务器完成真实切换与回退;自动下载/安装按政策关闭,通知/对账未实现。 |
@@ -289,9 +289,12 @@ function envOffline(): string | undefined {
}
/** Extract kind/version/target from a component archive name. */
function archiveIdentity(name: string): { kind: ArchiveKind; version: string; target: string } | null {
const match = /^marqdo(?:-(knowledge|view|lint|prove))?-(\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?)-([a-z0-9_]+-unknown-[a-z0-9-]+)\.tar\.gz$/
.exec(name)
export function parseArchiveIdentity(name: string): { kind: ArchiveKind; version: string; target: string } | null {
const pattern = new RegExp(
'^marqdo(?:-(knowledge|view|lint|prove))?-(\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.]+)?)-'
+ '([a-z0-9_]+-(?:unknown|pc)-[a-z0-9-]+)\\.tar\\.gz$',
)
const match = pattern.exec(name)
if (!match) return null
const kind = (match[1] ?? 'cli') as ArchiveKind
return { kind, version: match[2] ?? '', target: match[3] ?? '' }
@@ -660,7 +663,7 @@ export class BootstrapManager {
if (entries === undefined) throw new BootstrapError('bootstrap.offline_missing', `offline directory is not readable: ${directory}`)
const match = entries
.flatMap((name) => {
const identity = archiveIdentity(name)
const identity = parseArchiveIdentity(name)
return identity !== null && identity.kind === 'cli' && identity.target === target ? [{ name, ...identity }] : []
})
.sort((left, right) => compareVersions(right.version, left.version))[0]
@@ -699,7 +702,7 @@ export class BootstrapManager {
const entries = await readdir(directory).catch(() => [] as string[])
const match = entries
.flatMap((name) => {
const identity = archiveIdentity(name)
const identity = parseArchiveIdentity(name)
return identity !== null && identity.kind === component && identity.target === target ? [{ name, ...identity }] : []
})
.sort((left, right) => compareVersions(right.version, left.version))[0]
@@ -110,6 +110,14 @@ export class EcosystemError extends Error {
override name = 'EcosystemError'
}
/** Filename of one shipped runtime binary for a Node platform. */
export function runtimeBinaryName(
base: 'marqdo' | 'marqdo-provider-worker',
nodePlatform: string = process.platform,
): string {
return nodePlatform === 'win32' ? `${base}.exe` : base
}
/** Recompute the bundle digest from the extracted stdlib directory. */
async function bundleDigest(directory: string): Promise<string> {
const manifest = await readJson<{ digest?: string }>(join(directory, 'stdlib.json'))
@@ -335,7 +343,7 @@ export class EcosystemManager {
throw new EcosystemError(`release version mismatch: manifest=${info.product_version}, tag=${candidate.tag}`)
}
// A real invocation, not a file-existence check.
const smoke = await runProcess(join(root, 'marqdo'), ['--version'], {
const smoke = await runProcess(join(root, runtimeBinaryName('marqdo')), ['--version'], {
cwd: root,
limits: {
timeoutMs: 30_000,
@@ -348,7 +356,7 @@ export class EcosystemManager {
}
await options.smoke?.({
root,
cli: join(root, 'marqdo'),
cli: join(root, runtimeBinaryName('marqdo')),
version: info.product_version,
sourceSha: info.source_sha ?? null,
bundleDigest: stdlib.tree_digest,
@@ -383,8 +391,8 @@ export class EcosystemManager {
tree_digest: stdlib.tree_digest,
aliases_digest: stdlib.aliases_digest ?? null,
},
cli_path: 'marqdo',
worker_path: 'marqdo-provider-worker',
cli_path: runtimeBinaryName('marqdo'),
worker_path: runtimeBinaryName('marqdo-provider-worker'),
tool_home: 'tool-home',
previous: previous?.id ?? null,
ci: candidate.ci,
+3 -2
View File
@@ -10,7 +10,7 @@
import { randomBytes } from 'node:crypto'
import { mkdir, readFile, unlink } from 'node:fs/promises'
import { isAbsolute, join, resolve } from 'node:path'
import { isAbsolute, join, relative, resolve } from 'node:path'
import { digestBytes, digestFile, readText } from '../core/fsx.ts'
import { runProcess } from '../core/process.ts'
import type { RunLimits, RunResult } from '../core/process.ts'
@@ -132,7 +132,8 @@ export function documentPath(workspace: string, relativePath: string): string {
}
const absolute = resolve(workspace, relativePath)
const root = resolve(workspace)
if (!absolute.startsWith(`${root}/`) || absolute.split('/').includes('..')) {
const within = relative(root, absolute)
if (within === '' || within.startsWith('..') || isAbsolute(within)) {
throw new ExecutionRejectedError(`document path escapes the workspace: ${relativePath}`)
}
return absolute
@@ -0,0 +1,29 @@
/** Native Windows runtime identity and offline-pack parsing. */
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { parseArchiveIdentity } from '../src/bootstrap/manager.ts'
import { runtimeBinaryName } from '../src/ecosystem/manager.ts'
test('offline archive identity accepts native Windows targets', () => {
assert.deepEqual(parseArchiveIdentity('marqdo-3.0.0-rc.7-x86_64-pc-windows-msvc.tar.gz'), {
kind: 'cli',
version: '3.0.0-rc.7',
target: 'x86_64-pc-windows-msvc',
})
assert.deepEqual(parseArchiveIdentity('marqdo-3.0.0-rc.7-x86_64-unknown-linux-gnu.tar.gz'), {
kind: 'cli',
version: '3.0.0-rc.7',
target: 'x86_64-unknown-linux-gnu',
})
assert.deepEqual(parseArchiveIdentity('marqdo-knowledge-0.2.0-aarch64-apple-darwin.tar.gz'), null)
assert.equal(parseArchiveIdentity('marqdo-3.0.0-rc.7-x86_64-pc-windows-msvc.zip'), null)
})
test('runtime binary names carry the Windows executable suffix', () => {
assert.equal(runtimeBinaryName('marqdo', 'win32'), 'marqdo.exe')
assert.equal(runtimeBinaryName('marqdo-provider-worker', 'win32'), 'marqdo-provider-worker.exe')
assert.equal(runtimeBinaryName('marqdo', 'linux'), 'marqdo')
assert.equal(runtimeBinaryName('marqdo-provider-worker', 'darwin'), 'marqdo-provider-worker')
})
+8 -1
View File
@@ -11,7 +11,7 @@
*/
import { access, chmod, mkdir, readFile, rmdir, symlink, unlink, writeFile } from 'node:fs/promises'
import { constants } from 'node:fs'
import { constants, existsSync } from 'node:fs'
import { homedir } from 'node:os'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
@@ -21,6 +21,13 @@ const here = dirname(fileURLToPath(import.meta.url))
const root = resolve(here, '..')
const productCommands = new Set(['bootstrap', 'status', 'doctor', 'repair', 'report', 'update', 'network', 'uninstall', 'help'])
// A packaged offline runtime pack makes first-run bootstrap usable without a
// network round trip; an explicit environment value still wins.
const bundledRuntimeDeps = join(root, 'runtime-deps')
if (!process.env.MQDH_BOOTSTRAP_OFFLINE && existsSync(bundledRuntimeDeps)) {
process.env.MQDH_BOOTSTRAP_OFFLINE = bundledRuntimeDeps
}
/** Resolve the application home without touching the user's `~/.dsh`. */
function resolveHome() {
const configured = process.env.MQDH_HOME?.trim()
+25 -1
View File
@@ -23,7 +23,8 @@
#>
[CmdletBinding()]
param(
[string]$OutDir = (Join-Path $PSScriptRoot '..\.ci')
[string]$OutDir = (Join-Path $PSScriptRoot '..\.ci'),
[string]$RuntimeDeps = ''
)
$ErrorActionPreference = 'Continue'
@@ -160,6 +161,28 @@ try {
Copy-Item -LiteralPath (Join-Path $root 'scripts\install.ps1') -Destination (Join-Path $app 'install.ps1') -Force
Copy-Item -LiteralPath (Join-Path $root 'scripts\mqdh.cmd') -Destination (Join-Path $app 'mqdh.cmd') -Force
# Optional bundled offline runtime pack: the launcher points bootstrap at it,
# so a fresh Windows install can install CLI/Worker/Bundle without network.
$bundledRuntime = @()
if ($RuntimeDeps -ne '') {
$deps = (Resolve-Path -LiteralPath $RuntimeDeps).Path
if (-not (Test-Path -LiteralPath $deps)) { throw "runtime deps directory is missing: $RuntimeDeps" }
$targetDeps = Join-Path $app 'runtime-deps'
New-Item -ItemType Directory -Force -Path $targetDeps | Out-Null
foreach ($file in Get-ChildItem -LiteralPath $deps -File) {
Copy-Item -LiteralPath $file.FullName -Destination (Join-Path $targetDeps $file.Name)
if ($file.Name -like '*.tar.gz') {
$sidecar = Join-Path $deps ($file.Name + '.sha256')
if (-not (Test-Path -LiteralPath $sidecar)) { throw "runtime deps archive has no .sha256 sidecar: $($file.Name)" }
$digest = (Get-FileHash -LiteralPath $file.FullName -Algorithm SHA256).Hash.ToLower()
$declared = (Get-Content -LiteralPath $sidecar -Raw).Trim().Split(' ')[0].ToLower()
if ($digest -ne $declared) { throw "runtime deps digest mismatch: $($file.Name)" }
$bundledRuntime += [ordered]@{ name = $file.Name; size = $file.Length; sha256 = $digest }
}
}
if ($bundledRuntime.Count -eq 0) { throw 'runtime deps directory has no component archive' }
}
$archive = Join-Path $OutDir "$name.tar.gz"
Remove-Item -LiteralPath $archive -Force -ErrorAction SilentlyContinue
& tar.exe -czf $archive -C $stage $name
@@ -212,6 +235,7 @@ try {
}
manifest = 'mqdh-release.json'
signature = 'unsigned'
bundled_runtime = $bundledRuntime
contains_marqdo_cli_source = $false
unverified = @(
'native Windows CI runner',