diff --git a/.gitignore b/.gitignore index 22e394d..18288a7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ # 上游源码备份:本地保留,不入 git(用户决定) /backup/ +# 本机草稿目录(不属于仓库) +/test/ + # 日志与临时文件 *.log /agent/tmp/ diff --git a/README.md b/README.md index 7820405..a357a9a 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ ## 下载与运行 1. 在 [Releases](https://git.wucl12.cn/wucl12/md-preview/releases) 页下载 `MD-Preview-windows-x64.exe`(当前发布版本 `v1.4.2-local.5`,2026-10-30); -2. 放到一个固定目录(例如 `D:\Scripts\md-preview\`),不要随意改名/移动; +2. 放到一个固定目录(例如 `C:\Tools\md-preview\`),不要随意改名/移动; 3. 双击运行,或在任意 `.md` 上右键 → 打开方式 → 选择该 exe 并设为默认; 4. Windows 10/11 一般自带 WebView2 Runtime;若提示缺失,安装微软的 Evergreen Runtime 即可。 @@ -84,11 +84,12 @@ - WebView2 Runtime ```powershell -cargo test # 59 个测试 -.\agent\scripts\build.ps1 # release 构建 + 校验 + 复制到固定 exe 路径 +cargo test +.\agent\scripts\build.ps1 # release 构建 + 校验(产物留在 target\release\) +.\agent\scripts\publish.ps1 # 发布到 Nutstore(用户手动,普通 PowerShell) ``` -构建脚本会打印 exe 的 SHA256、检查已移除功能的字符串,并确认文件完整性级别为 Medium。 +构建脚本会打印 exe 的 SHA256、检查已移除功能的字符串,并报告完整性级别;开发构建是 Low,`publish.ps1` 会把它升到 Medium 并复制到 Nutstore。 更细的维护说明(工具链、完整性级别坑、验收清单)见 [`agent/docs/HANDOFF.md`](agent/docs/HANDOFF.md)。 ## 目录 @@ -96,9 +97,10 @@ cargo test # 59 个测试 ```text src/ Rust 源码(main.rs 界面/渲染/事件循环,session.rs 会话,instance.rs 单实例) assets/ 全部内嵌资源:highlight.js、KaTeX、Mermaid、图标、暗色代码主题 -agent/ 维护者文档、构建/冒烟脚本、测试夹具 - docs/ HANDOFF、STATUS、roadmap、扫描记录 - scripts/build.ps1 release 构建与校验 +agent/ 维护者文档、构建/冒烟/发布脚本、测试夹具 + docs/ HANDOFF、STATUS、roadmap、migration、扫描记录 + scripts/build.ps1 开发构建(release + 校验) + scripts/publish.ps1 发布到 Nutstore(用户手动) tests/ 冒烟脚本与 Markdown 样例 backup/ 上游源码备份(本地保留,不入 git) ``` diff --git a/agent/AGENTS.md b/agent/AGENTS.md index fe635c5..bc93919 100644 --- a/agent/AGENTS.md +++ b/agent/AGENTS.md @@ -4,54 +4,64 @@ ## 0. 工作区边界(最重要) -1. **只在工作区 `D:\Scripts\md-preview` 内创建、修改、删除文件。** -2. **任何工作区外的修改都必须先停下询问用户**,包括但不限于: +1. **仓库根**:`D:\Scripts\md-preview\AgentLowWorking`(2026-11-02 迁移后)。只在这个目录内创建、修改、删除文件。 + - DSH 工作区是父目录 `D:\Scripts\md-preview`;代码仓库在其下的 `AgentLowWorking`。改代码/跑 git 前先 `cd AgentLowWorking`(或 `git -C AgentLowWorking`)。 + - 父目录只放用户指定的小文件(发布启动器、AGENTS 指针);不要放源码/构建产物。 +2. **任何仓库外的修改都必须先停下询问用户**,包括但不限于: - `%TEMP%` / `%LOCALAPPDATA%` / 用户目录 / 其它磁盘; - 注册表、计划任务、服务、环境变量; - - 删除或移动任何不是本次刚在工作区内生成的文件。 + - 删除或移动任何不是本次刚在仓库内生成的文件。 询问时要给出:完整路径、要做的操作、原因、影响范围;得到明确同意后才执行。 -3. 不允许为了省事把构建/测试的临时文件写到工作区外。本仓库约定临时目录放在 - `target\test-tmp`、`target\tmp` 下(均被 `.gitignore` 忽略)。 -4. 每次收尾前自查:`git status` 是否只剩预期改动;本次是否在工作区外留下文件; +3. 构建/测试的临时文件留在 `target\tmp`、`target\test-tmp`(已忽略),不写 `%TEMP%`。 +4. 每次收尾前自查:`git status` 是否只剩预期改动;本次是否在仓库外留下文件; 若发现历史残留,只报告并询问,不擅自删除。 -5. DSH 当前以 **danger-full-access** 运行,没有文件系统护栏——这条规则是唯一防线,不得绕过。 +5. DSH 以 **workspace-write(Low 完整性)** 运行;仓库整棵树是 Low,因此可以正常改代码、编译、commit。**不要**把仓库改回 Medium,**不要**申请 danger-full-access 来改代码。 6. 截图、录屏等二进制验证产物**不入库**:放 `agent/tmp/`(已忽略)或 `target/tmp/`,看完即删;`agent/reports/` 只保留文本记录。 +7. `test/` 是本机草稿目录,已 gitignore;不要提交,不要当作仓库内容。 ## 1. 不变量 -- 产物路径固定:`D:\Scripts\md-preview\MD-Preview-windows-x64.exe`,默认 `.md` 打开方式指向它,不改名、不移动。 +- **仓库根**:`D:\Scripts\md-preview\AgentLowWorking`。 +- **发布产物**:`C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium);默认 `.md` 打开方式指向它。 +- 仓库内**不放成品 exe**;旧的 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe` 已删除,不要再生成。 +- Agent 编译出的 `target\release\md-preview.exe` 是 **Low**,不能直接双击运行(会 os error 5);冒烟必须把 `MD_PREVIEW_CONFIG_DIR` 指到仓库内目录。 - 离线:不引入联网、自动更新、遥测;外部链接交给系统浏览器。 - 轻量:不为小功能引入新库;优先原生 JS/CSS 与已有依赖。 - 右键菜单保持禁用;缩放只用 Ctrl + 滚轮与工具栏/快捷键。 -- 工作区完整性级别是 **Medium**;不要把工作区改成 Low。 ## 2. 改动流程 1. 一次只做一个功能;**加功能前先给方案,用户确认后再写代码**。 -2. 改动超出已确认范围(新增文件、改公共接口、动构建脚本、碰工作区外)时,立即停下询问。 -3. 写完先 `cargo test` 全绿,再部署验收;部署要替换固定 exe 并校验 SHA256/完整性级别。 +2. 改动超出已确认范围(新增文件、改公共接口、动构建脚本、碰仓库外)时,立即停下询问。 +3. 写完先 `cargo test` 全绿。 4. 每个功能一个 conventional commit,推送到 `origin main`。 +5. **发布只能由用户手动执行**:用户在普通 PowerShell(Medium)运行 `agent\scripts\publish.ps1`。Agent 不运行发布脚本、不改注册表、不碰 Nutstore。 ## 3. 构建与测试 -- 测试时把临时目录指到工作区内,避免 `%TEMP%` 残留: +- 测试/构建前把临时目录指到仓库内: - ```powershell - $env:TEMP = "$PWD\target\test-tmp"; $env:TMP = $env:TEMP + ~~~powershell + $env:TEMP = "$PWD\target\tmp"; $env:TMP = $env:TEMP New-Item -ItemType Directory -Force $env:TEMP | Out-Null - cargo test - ``` + ~~~ -- 正式构建用 `agent\scripts\build.ps1`(先关闭正在运行的 MD Preview)。 -- `git clean -xdf` 会删除被忽略的 `backup/` 与成品 exe,禁止使用。 +- 开发构建:`.\agent\scripts\build.ps1`(cargo test + build --release + 字符串校验;产物留在 `target\release\`)。 +- DSH 的 pwsh 执行策略可能阻止未签名脚本;先运行 `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force`。 +- 开发冒烟:`$env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke"; .\target\release\md-preview.exe `。 +- 不要把 `target\release\md-preview.exe` 复制到任何固定路径,也不要覆盖 Nutstore。 +- `git clean -xdf` 会删除被忽略的 `backup/`,禁止使用。 -## 4. 发布镜像(用户已授权) +## 4. 发布(用户手动) -- release 构建成功并发布到 Gitea 后,可以将固定 exe 复制到 Nutstore 镜像:`C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`,并用 SHA256 校验一致。 -- 仅限该路径;其他工作区外修改仍需先询问用户。 +- 用户在**普通 PowerShell**(Medium)运行 `agent\scripts\publish.ps1`。 +- 脚本流程:复制 `target\release\md-preview.exe` → Nutstore → 设 Medium → 校验 SHA256 → 刷新 `.md` 关联 → 删除旧 exe。 +- 发布前必须关闭正在运行的 MD Preview。 +- 仅 Nutstore 这一个仓库外目标;其他仓库外修改仍需先询问用户。 ## 5. 参考 -- `docs/HANDOFF.md`:工具链、构建、完整性级别坑、验收。 +- `docs/HANDOFF.md`:工具链、构建、完整性级别、验收。 - `docs/STATUS.md`:当前进度、已确认决策、下一步。 +- `docs/migration-2026-11-02.md`:Low 工作区迁移与目录移动步骤。 - `docs/roadmap.md`:功能方案与验收标准。 diff --git a/agent/README.md b/agent/README.md index 6024288..3224dca 100644 --- a/agent/README.md +++ b/agent/README.md @@ -1,20 +1,22 @@ # agent/ — MD Preview 维护者工作区 -这里是本项目的“Agent 附属区”:文档、构建/冒烟脚本、测试夹具与验证记录。应用代码仍在 `src/`。 +这里是本项目的“Agent 附属区”:文档、构建/冒烟/发布脚本、测试夹具与验证记录。应用代码仍在 `src/`。 ## 规则 -维护本仓库前先读 [`AGENTS.md`](AGENTS.md):**最高优先级是工作区边界——任何工作区外的文件修改都必须先停下询问用户。** +维护本仓库前先读 [`AGENTS.md`](AGENTS.md):**最高优先级是仓库边界——任何仓库外的文件修改都必须先停下询问用户。** ## 目录 | 路径 | 用途 | |---|---| -| `AGENTS.md` | Agent 运行规则(工作区边界、改动流程) | -| `docs/HANDOFF.md` | 主交接文档(工具链、构建、坑、验收) | +| `AGENTS.md` | Agent 运行规则(仓库边界、改动流程) | +| `docs/HANDOFF.md` | 主交接文档(工具链、构建、完整性级别、验收) | +| `docs/migration-2026-11-02.md` | Low 工作区迁移与目录移动步骤 | | `docs/scan-2026-10-21.md` | 代码扫描:残留、bug、修复建议 | | `docs/roadmap.md` | 功能路线图与验收标准 | -| `scripts/build.ps1` | release 构建 → 固定 exe 路径 → 校验 | +| `scripts/build.ps1` | 开发构建(cargo test + build --release + 校验) | +| `scripts/publish.ps1` | 用户手动发布到 Nutstore(Medium) | | `tests/smoke.ps1` | cargo test + 关联检查 + 可选隔离启动 | | `tests/fixtures/` | 手工/冒烟用 Markdown 样例 | | `reports/` | 验证记录(文本;截图放 `agent/tmp/`,不入库) | @@ -22,28 +24,31 @@ ## 不变量 -1. **产物路径固定**:`D:\Scripts\md-preview\MD-Preview-windows-x64.exe`。默认 `.md` 打开方式指向它,不要改名/移动。 +1. **仓库根**:`D:\Scripts\md-preview\AgentLowWorking`。默认 `.md` 打开方式指向 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`。 2. **离线**:不引入联网、自动更新、遥测;外部链接交给系统浏览器。 3. **轻量**:不为小功能引入新库;优先原生 JS/CSS 与已有依赖。 4. **测试**:`cargo test` 必须保持全绿;UI 行为用 `tests/fixtures` 做手工/冒烟回归。 ## 常用命令 -```powershell -# 构建并校验(推荐) +~~~powershell +# 开发构建(DSH workspace-write 可运行) .\agent\scripts\build.ps1 # 只跑测试 cargo test -# 冒烟(含注册表与可选启动) +# 冒烟(发布后;含注册表与可选启动) .\agent\tests\smoke.ps1 -Launch -``` + +# 发布(必须由用户在自己的普通 PowerShell 运行) +.\agent\scripts\publish.ps1 +~~~ ## 环境注意 -工作区是 **Medium** 完整性级别。DSH 用 `workspace-write` 打开时进程是 **Low**,会写不动(EPERM / os error 5)。改代码、编译、替换 exe 需要 DSH 以 **danger-full-access** 运行,或在你自己的普通 PowerShell 里执行。详见 `docs/HANDOFF.md` 第 4 节。 +仓库整棵树是 **Low** 完整性级别,DSH 以 `workspace-write` 运行即可改代码/编译。构建产物 `target\release\md-preview.exe` 也是 Low,不能直接双击;开发冒烟用 `MD_PREVIEW_CONFIG_DIR` 指到仓库内目录。发布由用户手动运行 `publish.ps1` 升到 Medium 并复制到 Nutstore。详见 `docs/migration-2026-11-02.md`。 ## Git -仓库由用户自行初始化(私有)。`backup/` 与成品 exe 不入库;`agent/` 全量入库。 +仓库由用户自行初始化(私有)。`backup/`、成品 exe、`test/` 不入库;`agent/` 全量入库(`agent/tmp/` 与日志/截图除外)。 diff --git a/agent/docs/HANDOFF.md b/agent/docs/HANDOFF.md index e697acf..0fa433f 100644 --- a/agent/docs/HANDOFF.md +++ b/agent/docs/HANDOFF.md @@ -1,18 +1,23 @@ # MD Preview 本地维护交接 -> 最后更新:2026-10-21 +> 最后更新:2026-11-02 > 维护范围:仅 Windows 本地构建,目标产物 `MD-Preview-windows-x64.exe` > > **Agent 必须先读 `agent/AGENTS.md`**:最高优先级是工作区边界,任何工作区外的文件修改都要先停下询问用户。 +> **2026-11-02 迁移(重要)**:代码仓库移到 `D:\Scripts\md-preview\AgentLowWorking`;DSH 工作区仍是父目录 `D:\Scripts\md-preview`; +> 仓库整棵树为 **Low**,DSH 用 **workspace-write** 即可改代码/编译; +> 成品只发布到 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium),仓库内不再放 exe。 +> 本文第 4 节等处的 “Medium / danger-full-access” 是旧模型;以 `agent/docs/migration-2026-11-02.md` 和 `AGENTS.md` 为准。 + ## 1. 当前状态 - 上游版本:`md-preview 1.4.2`(源码来自 `backup/md-preview-master.zip`) - 改造目标:**本地预览器,不联网、不自动更新**;预览/编辑/标签/会话等功能与上游一致 - 源码规模:`src/main.rs` 4354 行、`src/session.rs` 281 行、`src/instance.rs` 207 行 -- 当前产物:`D:\Scripts\md-preview\MD-Preview-windows-x64.exe` - - 大小 5,501,440 字节 - - SHA256 `F76BC3963BA13BBFC8259BC2B4E3D24468C34E3C9E26491D364D5D364BEDE96C` +- 当前产物(2026-11-02 起):`C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe` + - 当前发布版见 `STATUS.md` 第 2 节(v1.4.2-local.5,5,505,024 字节) + - 仓库内不再放成品 exe;旧 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe` 由 `publish.ps1` 删除 - 测试:`cargo test` → 43 passed, 0 failed - 编译警告:1 个 `dead_code`(macOS 专用事件枚举,Windows 下未构造),可忽略 - 2026-10-21 的全部功能需求已完成并部署,细节与实现要点见第 14 节。 @@ -36,62 +41,31 @@ DSH 的 pwsh 可能没有继承 PATH,构建时用完整路径: ## 3. 构建与运行 -```powershell -cd D:\Scripts\md-preview -cargo build --release -copy .\target\release\md-preview.exe .\MD-Preview-windows-x64.exe -.\MD-Preview-windows-x64.exe -``` +~~~powershell +cd D:\Scripts\md-preview\AgentLowWorking +.\agent\scripts\build.ps1 # 开发构建(cargo test + build --release) +# 发布由用户在自己的普通 PowerShell 运行: +.\agent\scripts\publish.ps1 +~~~ - 增量构建约 15 秒,清理后约 1–2 分钟(16 核,release 开启 LTO + opt-level=z) - 依赖锁定在 `Cargo.lock`(435 个包),**不要随手 `cargo update`** - 调试可 `cargo build`(debug,快),产物在 `target\debug\` -## 4. ⚠️ 必读:完整性级别与 os error 5 +## 4. ⚠️ 必读:Low 工作区与发布(2026-11-02 起) -这是本次维护踩过最大的坑,务必先读: +- 仓库根 `D:\Scripts\md-preview\AgentLowWorking` 整棵树是 **Low** 完整性级别;DSH 以 **workspace-write** 运行即可改代码、编译、commit。 +- 从 Low 工作区编译出的 exe 也是 Low:启动后写 `%LOCALAPPDATA%\md-preview\instance.lock` 会被 no-write-up 拒绝(os error 5)。这不是应用 bug。 +- 开发冒烟不要双击 `target\release\md-preview.exe`,用隔离配置目录: -- DSH 的 **workspace-write** 模式会把子进程降为 **Low 完整性级别(Low IL)**,并期望工作区文件也是 Low。 -- 从被标成 Low 的目录编译出的 exe 会继承 Low 标签;启动后写 `%LOCALAPPDATA%\md-preview\instance.lock` 会被 Windows 的 no-write-up 拒绝,弹窗: + ~~~powershell + $env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke" + .\target\release\md-preview.exe path\to\file.md + ~~~ - ``` - Could Not Open MD Preview - 拒绝访问 (os error 5) - ``` - -- 这不是应用 bug。同一个 exe 复制到 `D:\Installer\MD-Preview\` 就能正常运行(目标目录是 Medium)。 - -当前仓库状态:工作区已设为 **Medium**,DSH 必须以 **danger-full-access** 运行才能编辑/编译此目录。 -如果你用 workspace-write 打开本仓库,DSH 进程是 Low,会写不动 Medium 工作区(表现是编辑/编译全部 Access denied)。 - -### 如果 exe 又报 os error 5 - -```powershell -# 方案 1:把工作区(含 target)改回 Medium 后重建 -icacls D:\Scripts\md-preview /setintegritylevel "(OI)(CI)Medium" /T /C -cargo build --release - -# 方案 2:不改标签,直接把 exe 复制到普通目录再运行 -copy .\target\release\md-preview.exe D:\Installer\MD-Preview\MD-Preview-windows-x64.exe -``` - -检查标签: - -```powershell -icacls .\MD-Preview-windows-x64.exe # 应显示 Medium,不能是 Low -``` - -### 若坚持用 workspace-write 沙箱 - -工作区必须保持 Low,DSH 才能写;构建输出必须放到工作区外(否则 exe 又是 Low): - -1. `icacls D:\Scripts\md-preview /setintegritylevel "(OI)(CI)Low" /T /C` -2. 项目内 `.cargo\config.toml`: - ```toml - [build] - target-dir = "D:/MD-Preview-build/target" - ``` -3. 在**自己的普通 PowerShell**里构建,再把 exe 复制到 `D:\Installer\MD-Preview\` +- 发布:用户在**普通 PowerShell(Medium)**运行 `agent\scripts\publish.ps1`。脚本会复制到 Nutstore、设 Medium、校验 SHA256、刷新 `.md` 关联,最后删除旧 exe。 +- 如果发布后仍报 os error 5:`icacls | Select-String 'Mandatory Label'` 应为 Medium;确认不是从 Low 目录直接启动。 +- 不要再把仓库改回 Medium,也不要为了改代码申请 danger-full-access。 ## 5. 已删除的联网/更新功能(不要加回来) @@ -129,30 +103,23 @@ python -c "d=open(r'MD-Preview-windows-x64.exe','rb').read(); print(d.count(b'ap ## 7. 目录结构 -``` -D:\Scripts\md-preview -├─ Cargo.toml / Cargo.lock / build.rs -├─ src/main.rs 界面、页面模板、渲染、事件循环、Windows 集成(4354 行) -├─ src/session.rs 标签会话持久化 -├─ src/instance.rs 单实例锁与本地端口转发 -├─ assets/ 8 个被 include_str!/include_bytes! 内嵌的资源 -│ ├─ icon.ico -│ ├─ enhance/preview-enhance.js -│ ├─ hljs/(highlight.min.js、delphi、vs-dark.css) -│ ├─ katex/… -│ └─ mermaid/mermaid.min.js -├─ backup/md-preview-master.zip 上游源码备份(3.77 MB,本地保留,不入 git) -├─ MD-Preview-windows-x64.exe 构建产物(不入 git;默认打开方式指向此路径) -├─ target/ 编译缓存(不入 git,可删) -├─ agent/ Agent 文档 / 脚本 / 测试夹具 -│ ├─ AGENTS.md Agent 运行规则(最高优先级) -│ ├─ README.md -│ ├─ docs/{HANDOFF.md, STATUS.md, scan-2026-10-21.md, roadmap.md} -│ ├─ scripts/build.ps1 -│ └─ tests/{smoke.ps1, fixtures/} -├─ README.md 入口,指向 agent/docs/HANDOFF.md -├─ LICENSE / .gitignore / .gitattributes -``` +~~~ +D:\Scripts\md-preview\ +├─ AgentLowWorking\ ← 仓库根(整棵树 Low) +│ ├─ Cargo.toml / Cargo.lock / build.rs +│ ├─ src/ 应用源码 +│ ├─ assets/ 内嵌资源 +│ ├─ backup/ 上游源码备份(不入 git) +│ ├─ target/ 编译缓存(不入 git,可删) +│ ├─ agent/ Agent 文档 / 脚本 / 测试夹具 +│ │ ├─ AGENTS.md +│ │ ├─ docs/{HANDOFF.md, STATUS.md, migration-2026-11-02.md, ...} +│ │ ├─ scripts/{build.ps1, publish.ps1} +│ │ └─ tests/{smoke.ps1, fixtures/} +│ ├─ README.md / LICENSE / .gitignore / .gitattributes +│ └─ test/ 本机草稿(已忽略) +└─ MD-Preview-windows-x64.exe 旧产物;publish.ps1 成功后删除 +~~~ Git 由用户自行初始化(私有仓库;`backup/` 与成品 exe 不入 git)。`.gitignore` 已忽略 `/target/`、`MD-Preview-windows-x64.exe`、`/backup/` 与临时日志。 @@ -183,12 +150,13 @@ Git 由用户自行初始化(私有仓库;`backup/` 与成品 exe 不入 git ## 11. 验收清单 -```powershell -cd D:\Scripts\md-preview -cargo test # 43 passed -cargo build --release # Finished -.\MD-Preview-windows-x64.exe path\to\file.md -``` +~~~powershell +cd D:\Scripts\md-preview\AgentLowWorking +cargo test +.\agent\scripts\build.ps1 +# 发布由用户在自己的普通 PowerShell 运行: +.\agent\scripts\publish.ps1 +~~~ 手工检查: @@ -197,7 +165,7 @@ cargo build --release # Finished - [ ] 多标签切换、关闭、会话恢复 - [ ] 编辑后 700ms 自动保存,关闭前落盘 - [ ] 第二个实例打开文件时,第一个实例新增标签、第二个退出 -- [ ] `icacls MD-Preview-windows-x64.exe` 为 Medium +- [ ] `icacls "C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe"` 为 Medium ## 12. 追加修复(2026-10-21 下午) @@ -317,7 +285,7 @@ cargo test # 43 passed - Gitea Release `v1.4.2-local.1`:https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.1 - 附件 `MD-Preview-windows-x64.exe`(5,501,440 字节,SHA256 `F76BC396…BEDE96C`),发布说明见 `agent/docs/release-notes-v1.4.2-local.1.md`。 -- 发版流程:改版本 / 写 release notes → `build.ps1` → 推 tag 或用 Gitea API 建 release 并上传 exe。API 需要 `write:repository` scope 的 token,用完即删。 +- 发版流程:改版本 / 写 release notes → `build.ps1` → 用户在普通 PowerShell 运行 `publish.ps1` → 推 tag / 用 Gitea API 建 release 并上传 Nutstore 那份 exe。API 需要 `write:repository` scope 的 token,用完即删。 ### 14.6 下一次开工检查 diff --git a/agent/docs/STATUS.md b/agent/docs/STATUS.md index 388db67..40c3377 100644 --- a/agent/docs/STATUS.md +++ b/agent/docs/STATUS.md @@ -1,9 +1,9 @@ # 项目状态(滚动更新) -> 最后更新:2026-10-30 +> 最后更新:2026-11-02 > 用途:上下文压缩/交接后快速恢复。详细背景见 AGENTS.md、HANDOFF.md、scan-2026-10-21.md、roadmap.md。 > -> **当前:编辑 Tab/自动缩进 + 阅读 Find 选区填入/零滚动完成;59 个测试通过;固定 exe 已更新为 2026-10-30 build(5,505,024 字节,SHA256 A632EF03…);Gitea release v1.4.2-local.5 已发布;Nutstore 镜像已同步。** +> **当前(2026-11-02):仓库根迁移到 `D:\Scripts\md-preview\AgentLowWorking`,整棵树 Low、DSH workspace-write 可编译;成品只发布到 Nutstore;仓库内 exe 已删除。功能基线仍是 v1.4.2-local.5(59 tests)。** ## 1. 仓库 @@ -38,7 +38,7 @@ - `618ac47` feat: 阅读 Find 选区填入、选区锚点、零滚动打开 - 若干 docs 提交(状态/路线图/HANDOFF、local.3/local.4/local.5 release notes) - 忽略:`/target/`、`/MD-Preview-windows-x64.exe`、`/backup/`、`/agent/reports/*.png` -- **不变量**:exe 固定为 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe`,默认 .md 打开方式指向它,不要改名/移动。 +- **不变量(2026-11-02 起)**:仓库根 `D:\Scripts\md-preview\AgentLowWorking`;成品固定为 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium),默认 .md 打开方式指向它;仓库内不再放 exe。 ## 2. 当前构建/部署状态 @@ -47,7 +47,7 @@ - 大小 5,505,024 字节;版本 1.4.2.0 - SHA256 `A632EF0363D04CE6F72B9779BA742681868AC31D36A7FE57E4F6D44E7BEAD988` - 完整性级别 Medium - OK;禁用字符串检查全 0;PE subsystem=2(GUI,无双击 cmd)。 - - 构建方式:`cargo build --release` + `Copy-Item` + 同等校验。本机 DSH pwsh 下 `build.ps1` 会被 cargo 的 stderr 警告触发 `$ErrorActionPreference='Stop'`;脚本逻辑未改。 + - 构建方式:`cargo build --release`(build.ps1 已改为 Low 工作区版,不再复制到固定路径;cargo stderr 不会再触发 Stop)。 - 上一版(v1.4.2-local.4):5,499,392 字节;SHA256 `7134BBC68423605BE220E19DAA1D6CB679AFBB9153C526E717F50388C1A0841D`。 - 上一版部署(v1.4.2-local.3):5,507,584 字节;SHA256 `0BFF730209CE835B18DC1447740A1F2770EA0645577A91EB969A6215B1C2372E`。 - Nutstore 镜像:工作区外的 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe` 已同步为 v1.4.2-local.5(5,505,024 字节,SHA256 `A632EF03…`)。 @@ -150,15 +150,17 @@ ```powershell cargo test -.\agent\scripts\build.ps1 # 需要先关闭正在运行的 MD Preview -.\agent\tests\smoke.ps1 -Launch +.\agent\scripts\build.ps1 # 开发构建;产物在 target\release\ +.\agent\tests\smoke.ps1 -Launch # 发布后冒烟(Nutstore exe) +.\agent\scripts\publish.ps1 # 发布:用户在自己的普通 PowerShell 运行 ``` ## 8. 环境与规则 -- **最高优先级**:`agent/AGENTS.md` —— 只在工作区内改文件;工作区外的任何修改先停下询问用户。 -- 工作区是 Medium 完整性级别;DSH 需 danger-full-access 才能改/编译(workspace-write 会 EPERM / os error 5)。 -- 不要把工作区改成 Low。 +- **最高优先级**:`agent/AGENTS.md` —— 只在仓库内改文件;仓库外的任何修改先停下询问用户。 +- 仓库根 `D:\Scripts\md-preview\AgentLowWorking` 整棵树是 **Low**;DSH 用 **workspace-write** 即可改/编译。 +- 构建产物是 Low,不能直接双击;冒烟用 `MD_PREVIEW_CONFIG_DIR` 指到仓库内。 +- 发布由用户手动运行 `publish.ps1`(Medium);Agent 不运行发布脚本、不改注册表。 - `git clean -xdf` 会删除被忽略的 backup 与 exe。 - 截图/录屏等二进制验证产物**不入库**:放 `agent/tmp/` 或 `target/tmp/`,看完即删;`agent/reports/` 只留文本。 - `%TEMP%` 历史测试残留已于 2026-10-21 16:38 经用户同意清理;之后的测试/构建把 TEMP/TMP 指向 `target\tmp` 与 `target\test-tmp`。 @@ -182,3 +184,14 @@ cargo test - 仓库描述与 topics 已通过 API 设置(topics:windows, markdown, markdown-preview, rust, webview2, offline, desktop-app)。 - **Gitea token 位置**:`C:\Users\wucl1\.gitea-token`(工作区外;保留,不要提交/删除;读取后不要打印内容)。 - 工作区内的 `.gitea-token` 旧路径已 gitignore;以后优先使用上面的用户目录文件。 + +## 10. 2026-11-02 迁移(Low 工作区) + +- 仓库根:`D:\Scripts\md-preview\AgentLowWorking`(整棵树 Low)。 +- DSH 工作区仍是父目录 `D:\Scripts\md-preview`;代码在子目录 `AgentLowWorking`。 +- DSH 以 `workspace-write` 运行;不再需要 danger-full-access。 +- 开发构建:`.\agent\scripts\build.ps1`(产物 `target\release\md-preview.exe` 是 Low)。 +- 开发冒烟:`$env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke"; .\target\release\md-preview.exe `。 +- 发布:用户在自己的普通 PowerShell(Medium)运行 `.\agent\scripts\publish.ps1`;脚本复制到 Nutstore、设 Medium、校验 SHA256、刷新 `.md` 关联、删除旧 exe。 +- 仓库内不再放成品 exe;默认打开指向 Nutstore。 +- 迁移步骤与回滚见 `agent/docs/migration-2026-11-02.md`。 diff --git a/agent/docs/migration-2026-11-02.md b/agent/docs/migration-2026-11-02.md new file mode 100644 index 0000000..f56edc8 --- /dev/null +++ b/agent/docs/migration-2026-11-02.md @@ -0,0 +1,101 @@ +# 2026-11-02 迁移:Low 工作区 + Nutstore 单一发布 + +> 目标:DSH 以 **workspace-write(Low)** 运行就能改代码、编译、测试;成品只通过用户手动运行的 `publish.ps1` 发布到 Nutstore。 +> 执行前先读 `agent/AGENTS.md`。 + +## 1. 最终结构 + +~~~ +D:\Scripts\md-preview\ +├─ AgentLowWorking\ ← 仓库根(整棵树 Low,含 .git) +│ ├─ src / assets / agent / target / Cargo.* / README.md ... +│ └─ test\ 本机草稿(已 gitignore) +└─ MD-Preview-windows-x64.exe 旧产物(Medium);publish.ps1 成功后删除 +~~~ + +- 仓库根:`D:\Scripts\md-preview\AgentLowWorking` +- 发布产物:`C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium) +- 默认 `.md` 打开方式:由 `publish.ps1` 指向 Nutstore +- 仓库内不再放 exe + +## 2. 一次性移动(用户执行) + +DSH 工作区保持在父目录 `D:\Scripts\md-preview`,所以**不需要关 DSH**;只要没有编辑器/进程占用仓库文件即可。如果 `Move-Item` 报“文件被占用”,再关掉 DSH/编辑器重试。 + +~~~powershell +$old = 'D:\Scripts\md-preview' +$new = Join-Path $old 'AgentLowWorking' + +# 1) 创建新仓库根(继承 Low) +New-Item -ItemType Directory -Path $new -Force | Out-Null + +# 2) 移动除旧 exe 和新目录以外的全部内容(含 .git、target、backup、test) +Get-ChildItem -LiteralPath $old -Force | + Where-Object { $_.Name -notin @('AgentLowWorking', 'MD-Preview-windows-x64.exe') } | + Move-Item -Destination $new -Force + +# 3) 整棵树 relabel 成 Low(对目录用 /T,顶层文件也会覆盖) +icacls $new /setintegritylevel "(OI)(CI)Low" /T /C + +# 4) 校验:前三项 Low,最后一项 Medium +icacls (Join-Path $new 'src\main.rs') | Select-String 'Mandatory Label' +icacls (Join-Path $new 'Cargo.toml') | Select-String 'Mandatory Label' +icacls (Join-Path $new '.git') | Select-String 'Mandatory Label' +icacls (Join-Path $old 'MD-Preview-windows-x64.exe') | Select-String 'Mandatory Label' +~~~ + +移动是同卷 rename,`.git` 一起走:历史、分支、远程都不受影响,**不需要任何 rename 提交**。 + +## 3. 移动后继续 + +不需要重开 DSH;在 DSH 里 `cd AgentLowWorking`(或所有命令用绝对路径)。验证: + +~~~powershell +# 在 DSH 的 pwsh 里应能写 +Set-Content "$PWD\target\tmp\probe.txt" 'ok'; Get-Content "$PWD\target\tmp\probe.txt"; Remove-Item "$PWD\target\tmp\probe.txt" +cargo test +~~~ + +## 4. 开发循环 + +~~~powershell +.\agent\scripts\build.ps1 +# 产物 target\release\md-preview.exe 是 Low,不能直接双击 +$env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke" +.\target\release\md-preview.exe path\to\file.md +~~~ + +## 5. 发布(用户手动,普通 PowerShell) + +~~~powershell +cd D:\Scripts\md-preview\AgentLowWorking +.\agent\scripts\publish.ps1 +~~~ + +脚本会:检查 Medium 权限和进程占用 → 复制到 Nutstore → 设 Medium → 校验 SHA256 → 刷新 `.md` 关联 → 删除 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe`。 + +## 6. 回滚 + +如果新模型不可用: + +1. 关掉 DSH。 +2. 把 `AgentLowWorking` 里的内容移回 `D:\Scripts\md-preview`(同样排除 `AgentLowWorking`)。 +3. `icacls D:\Scripts\md-preview /setintegritylevel "(OI)(CI)Medium" /T /C`(旧模型)。 +4. 旧 exe 若已被删除,从 Nutstore 复制回来或重新发布。 +5. DSH 改回 danger-full-access。 + +## 7. 注意 + +- `publish.ps1` 只应在**普通 / Medium** PowerShell 里运行;DSH 的 Low shell 会被脚本拒绝。 +- 发布前关闭 MD Preview;Nutstore 同步也可能短暂锁文件。 +- 开发版写不了 HKCU,不会抢默认打开;不要用 Medium 的旧 exe 启动,否则关联会被改回旧路径。 +- `test/` 已 gitignore,移动后仍不提交。 + +## 8. 迁移后待办 + +- 在 DSH 里确认可写、`cargo test` 全绿。 +- 父目录可选:`publish.ps1` 启动器 + `AGENTS.md` 指针(让新会话在父目录也能找到仓库规则)。 +- 给 `.gitignore` 加 `/test/`(本机草稿目录)。 +- 更新根 `README.md` 的目录树/构建命令。 +- 提交:`git add -A && git commit -m "chore: move to Low workspace and Nutstore-only publish"`(不要提交 `test/`)。 +- 需要切换默认打开并删除旧 exe 时,运行 `publish.ps1`。 diff --git a/agent/scripts/build.ps1 b/agent/scripts/build.ps1 index 539f518..753da7f 100644 --- a/agent/scripts/build.ps1 +++ b/agent/scripts/build.ps1 @@ -1,14 +1,13 @@ #requires -Version 5.1 <# - MD Preview 发布构建脚本 - 固定产物:D:\Scripts\md-preview\MD-Preview-windows-x64.exe - - 运行环境:普通 PowerShell(Medium),或 DSH 的 danger-full-access。 - workspace-write 是 Low 完整性级别,写不动本目录(EPERM / os error 5)。 + MD Preview 开发构建(DSH workspace-write / Low 完整性可运行) + - cargo test + cargo build --release + - 只做校验,不复制到任何固定 exe 路径 + - 产物:target\release\md-preview.exe(Low) + - 发布:用户在自己的普通 PowerShell 里运行 agent\scripts\publish.ps1 #> [CmdletBinding()] param( - [string]$OutputPath = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe', [switch]$SkipTests ) @@ -16,7 +15,7 @@ $ErrorActionPreference = 'Stop' $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path Set-Location $repoRoot -# 工作区规则(agent/AGENTS.md):构建/测试的临时文件也留在 target\ 下,不污染 %TEMP%。 +# 工作区规则(agent/AGENTS.md):临时文件留在 target\ 下,不污染 %TEMP%。 $tmpRoot = Join-Path $repoRoot 'target\tmp' New-Item -ItemType Directory -Force $tmpRoot | Out-Null $env:TEMP = $tmpRoot @@ -29,51 +28,49 @@ if (-not (Test-Path $cargo)) { function Step([string]$text) { Write-Host ('==> ' + $text) -ForegroundColor Cyan } -function Assert-TargetNotRunning([string]$path) { - $ids = @() - foreach ($p in (Get-Process -ErrorAction SilentlyContinue)) { - $pPath = $null - try { $pPath = $p.Path } catch { } - if ($pPath -eq $path) { $ids += $p.Id } +function Invoke-Cargo([string[]]$arguments) { + $previous = $ErrorActionPreference + $code = 0 + try { + # cargo 把进度/警告写到 stderr;Stop 会把它们当成终止错误 + $ErrorActionPreference = 'Continue' + & $cargo @arguments + $code = $LASTEXITCODE + } finally { + $ErrorActionPreference = $previous } - if ($ids.Count -gt 0) { - throw ('MD Preview 正在运行(PID ' + ($ids -join ', ') + '),请先关闭窗口再构建。') + if ($code -ne 0) { + throw ('cargo ' + ($arguments -join ' ') + ' failed with exit code ' + $code) } } -Assert-TargetNotRunning $OutputPath +$built = Join-Path $repoRoot 'target\release\md-preview.exe' + +$running = @() +foreach ($process in (Get-Process -ErrorAction SilentlyContinue)) { + $path = $null + try { $path = $process.Path } catch { } + if ($path -eq $built) { $running += [string]$process.Id } +} +if ($running.Count -gt 0) { + throw ('开发版 MD Preview 正在运行(PID ' + ($running -join ', ') + '),请先关闭。') +} if (-not $SkipTests) { Step 'cargo test' - & $cargo test - if ($LASTEXITCODE -ne 0) { throw 'cargo test failed' } + Invoke-Cargo @('test') } Step 'cargo build --release' -& $cargo build --release -if ($LASTEXITCODE -ne 0) { throw 'cargo build failed' } +Invoke-Cargo @('build', '--release') -$built = Join-Path $repoRoot 'target\release\md-preview.exe' if (-not (Test-Path $built)) { throw ('missing build output: ' + $built) } -Step ('copy -> ' + $OutputPath) -$outDir = Split-Path -Parent $OutputPath -if (-not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir | Out-Null } -Assert-TargetNotRunning $OutputPath -try { - Copy-Item $built $OutputPath -Force -ErrorAction Stop -} catch { - throw ('复制失败(目标可能被占用):' + $_.Exception.Message) -} - -$info = Get-Item $OutputPath -$hash = (Get-FileHash $OutputPath -Algorithm SHA256).Hash -Write-Host ('size : {0:N0} bytes' -f $info.Length) -Write-Host ('sha256 : ' + $hash) -Write-Host ('version : ' + $info.VersionInfo.FileVersion) +$info = Get-Item $built +$hash = (Get-FileHash $built -Algorithm SHA256).Hash Step 'check removed update strings' -$bytes = [IO.File]::ReadAllBytes($OutputPath) +$bytes = [IO.File]::ReadAllBytes($built) $ascii = [Text.Encoding]::ASCII.GetString($bytes) $forbidden = @('api.github', 'btn-update', 'Check for Updates', 'powershell', 'update-check-result', 'open-url') $bad = @() @@ -84,13 +81,14 @@ foreach ($needle in $forbidden) { } if ($bad.Count -gt 0) { throw ('removed features still present: ' + ($bad -join ', ')) } -Step 'check integrity level' -$acl = (icacls $OutputPath | Out-String) -if ($acl -match 'Medium Mandatory Level') { - Write-Host ' Medium - OK' -} else { - Write-Warning '不是 Medium:启动时可能报 os error 5,见 agent/docs/HANDOFF.md 第 4 节' -} - +Step 'report' +$acl = (icacls $built | Out-String) +$integrity = 'Unknown' +if ($acl -match 'Mandatory Label\\(Low|Medium|High) Mandatory Level') { $integrity = $Matches[1] } +Write-Host ('output : ' + $built) +Write-Host ('size : {0:N0} bytes' -f $info.Length) +Write-Host ('sha256 : ' + $hash) +Write-Host ('version : ' + $info.VersionInfo.FileVersion) +Write-Host ('integrity : ' + $integrity + ' (workspace-write builds are Low)') Write-Host '' -Write-Host ('DONE ' + $OutputPath) -ForegroundColor Green +Write-Host 'DONE (build only). Publish: .\agent\scripts\publish.ps1 (normal PowerShell, Medium)' -ForegroundColor Green diff --git a/agent/scripts/publish.ps1 b/agent/scripts/publish.ps1 new file mode 100644 index 0000000..250316b --- /dev/null +++ b/agent/scripts/publish.ps1 @@ -0,0 +1,114 @@ +#requires -Version 5.1 +<# + MD Preview 发布(必须由用户在自己的普通 PowerShell / Medium 运行) + - 源:target\release\md-preview.exe(Low) + - 目标:C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe(Medium) + - 校验 SHA256 + Medium,刷新 .md 关联,最后删除旧 exe + - 不要从 DSH 的 workspace-write shell 运行 +#> +[CmdletBinding()] +param( + [string]$Source = '', + [string]$NutstorePath = 'C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe', + [string]$OldExe = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe', + [switch]$KeepOldExe +) + +$ErrorActionPreference = 'Stop' +$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path +Set-Location $repoRoot +if (-not $Source) { $Source = Join-Path $repoRoot 'target\release\md-preview.exe' } + +function Step([string]$text) { Write-Host ('==> ' + $text) -ForegroundColor Cyan } + +function Assert-Medium { + $groups = (whoami /groups | Out-String) + if ($groups -match 'Low Mandatory Level') { + throw '当前是 Low 完整性(DSH 沙箱)。请在自己的普通 PowerShell(Medium)里运行本脚本。' + } +} + +function Assert-NotRunning([string[]]$paths) { + $running = @() + foreach ($process in (Get-Process -ErrorAction SilentlyContinue)) { + $path = $null + try { $path = $process.Path } catch { } + if ($path -and ($paths -contains $path)) { + $running += ($process.ProcessName + ' (PID ' + $process.Id + '): ' + $path) + } + } + if ($running.Count -gt 0) { + throw ('请先关闭 MD Preview:' + [Environment]::NewLine + ($running -join [Environment]::NewLine)) + } +} + +function Get-Integrity([string]$path) { + $out = (icacls $path | Out-String) + if ($out -match 'Mandatory Label\\(Low|Medium|High) Mandatory Level') { return $Matches[1] } + return 'Unknown' +} + +function Set-RegistryDefault([string]$path, [string]$value) { + if (-not (Test-Path $path)) { New-Item -Path $path -Force | Out-Null } + Set-ItemProperty -Path $path -Name '(default)' -Value $value +} + +Assert-Medium +if (-not (Test-Path -LiteralPath $Source)) { + throw ('找不到构建产物:' + $Source + ';先运行 agent\scripts\build.ps1') +} + +Assert-NotRunning @($Source, $NutstorePath, $OldExe) + +$sourceHash = (Get-FileHash -LiteralPath $Source -Algorithm SHA256).Hash + +Step ('copy -> ' + $NutstorePath) +$nutstoreDir = Split-Path -Parent $NutstorePath +if (-not (Test-Path $nutstoreDir)) { New-Item -ItemType Directory -Path $nutstoreDir -Force | Out-Null } +Copy-Item -LiteralPath $Source -Destination $NutstorePath -Force -ErrorAction Stop + +Step 'set Nutstore exe integrity -> Medium' +$previous = $ErrorActionPreference +$ErrorActionPreference = 'Continue' +icacls $NutstorePath /setintegritylevel Medium | Out-Null +$icaclsCode = $LASTEXITCODE +$ErrorActionPreference = $previous +if ($icaclsCode -ne 0) { throw ('icacls failed with exit code ' + $icaclsCode) } + +$integrity = Get-Integrity $NutstorePath +if ($integrity -ne 'Medium') { throw ('完整性级别不是 Medium:' + $integrity) } + +$targetHash = (Get-FileHash -LiteralPath $NutstorePath -Algorithm SHA256).Hash +if ($sourceHash -ne $targetHash) { + throw ('SHA256 不一致:source=' + $sourceHash + ' target=' + $targetHash) +} + +Step 'refresh .md association -> Nutstore' +$progid = 'MDPreview.md' +$command = '"' + $NutstorePath + '" "%1"' +Set-RegistryDefault ('HKCU:\Software\Classes\' + $progid + '\shell\open\command') $command +Set-RegistryDefault ('HKCU:\Software\Classes\' + $progid + '\DefaultIcon') ('"' + $NutstorePath + '",0') +Set-RegistryDefault ('HKCU:\Software\Classes\Applications\MD-Preview-windows-x64.exe\shell\open\command') $command + +$actual = (Get-ItemProperty ('HKCU:\Software\Classes\' + $progid + '\shell\open\command')).'(default)' +if ($actual -ne $command) { throw ('关联写入失败:' + $actual) } + +$userChoiceKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.md\UserChoiceLatest\ProgId' +$userChoice = $null +if (Test-Path $userChoiceKey) { $userChoice = (Get-ItemProperty $userChoiceKey).ProgId } +if ($userChoice -ne $progid) { + Write-Warning ('.md 的 UserChoice ProgId 是 ' + $userChoice + ',不是 ' + $progid + ';请在 设置 -> 默认应用 里选择一次 MD Preview。') +} + +if (-not $KeepOldExe -and (Test-Path -LiteralPath $OldExe)) { + Step ('delete old exe -> ' + $OldExe) + Remove-Item -LiteralPath $OldExe -Force -ErrorAction Stop +} + +Write-Host '' +Write-Host ('size : {0:N0} bytes' -f (Get-Item -LiteralPath $NutstorePath).Length) +Write-Host ('sha256 : ' + $targetHash) +Write-Host ('integrity : ' + $integrity) +Write-Host ('default : ' + $actual) +Write-Host ('old exe : ' + $OldExe) +Write-Host 'DONE' -ForegroundColor Green diff --git a/agent/tests/smoke.ps1 b/agent/tests/smoke.ps1 index ab00ebd..06db414 100644 --- a/agent/tests/smoke.ps1 +++ b/agent/tests/smoke.ps1 @@ -1,26 +1,47 @@ -#requires -Version 5.1 +#requires -Version 5.1 <# MD Preview 冒烟测试 cargo test + 关联检查 + 可选隔离启动(不污染真实 %LOCALAPPDATA%) + 默认测试 Nutstore 发布版;-Dev 测试 target\release 开发版 #> [CmdletBinding()] param( - [string]$Exe = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe', - [switch]$Launch + [string]$Exe = 'C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe', + [switch]$Launch, + [switch]$Dev ) $ErrorActionPreference = 'Stop' $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path Set-Location $repoRoot +$tmpRoot = Join-Path $repoRoot 'target\tmp' +New-Item -ItemType Directory -Force $tmpRoot | Out-Null +$env:TEMP = $tmpRoot +$env:TMP = $tmpRoot + $cargo = Join-Path $env:USERPROFILE '.cargo\bin\cargo.exe' if (-not (Test-Path $cargo)) { $cargo = (Get-Command cargo -ErrorAction Stop).Source } -if (-not (Test-Path $Exe)) { throw ('missing exe: ' + $Exe + ' (先运行 agent/scripts/build.ps1)') } +if ($Dev) { + $Exe = Join-Path $repoRoot 'target\release\md-preview.exe' + if (-not $env:MD_PREVIEW_CONFIG_DIR) { + $env:MD_PREVIEW_CONFIG_DIR = Join-Path $repoRoot 'target\smoke' + New-Item -ItemType Directory -Force $env:MD_PREVIEW_CONFIG_DIR | Out-Null + } +} + +if (-not (Test-Path $Exe)) { + throw ('missing exe: ' + $Exe + '(先运行 agent/scripts/build.ps1,或先发布)') +} Write-Host '==> cargo test' -ForegroundColor Cyan +$previous = $ErrorActionPreference +$ErrorActionPreference = 'Continue' & $cargo test -if ($LASTEXITCODE -ne 0) { throw 'cargo test failed' } +$code = $LASTEXITCODE +$ErrorActionPreference = $previous +if ($code -ne 0) { throw 'cargo test failed' } Write-Host '==> --help' -ForegroundColor Cyan $help = (& $Exe --help 2>&1 | Out-String) @@ -30,20 +51,24 @@ if ($help -match 'MD Preview') { Write-Warning '--help 无输出(GUI 子系统在部分终端下不回显,可忽略)' } -Write-Host '==> registry association' -ForegroundColor Cyan -$reg = Get-ItemProperty 'HKCU:\Software\Classes\MDPreview.md\shell\open\command' -ErrorAction SilentlyContinue -$expected = '"' + $Exe + '" "%1"' -if ($null -eq $reg) { - Write-Warning 'ProgID 未注册(先运行一次 exe)' -} elseif ($reg.'(default)' -ne $expected) { - Write-Warning ('ProgID 指向不一致: ' + $reg.'(default)') +if ($Dev) { + Write-Host '==> registry association (skipped: Low build cannot write HKCU)' -ForegroundColor Cyan } else { - Write-Host ' OK' + Write-Host '==> registry association' -ForegroundColor Cyan + $reg = Get-ItemProperty 'HKCU:\Software\Classes\MDPreview.md\shell\open\command' -ErrorAction SilentlyContinue + $expected = '"' + $Exe + '" "%1"' + if ($null -eq $reg) { + Write-Warning 'ProgID 未注册(先运行一次 exe)' + } elseif ($reg.'(default)' -ne $expected) { + Write-Warning ('ProgID 指向不一致: ' + $reg.'(default)') + } else { + Write-Host ' OK' + } } if ($Launch) { Write-Host '==> launch with isolated config' -ForegroundColor Cyan - $config = Join-Path $env:TEMP ('mdp-smoke-' + [guid]::NewGuid().ToString('N')) + $config = Join-Path $tmpRoot ('mdp-smoke-' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $config | Out-Null $fixture = Join-Path $PSScriptRoot 'fixtures\long-headings.md' $env:MD_PREVIEW_CONFIG_DIR = $config