Skip to content

emrg: add bash_tool and base tool tests - #13

Merged
argszero merged 3 commits into
masterfrom
test/add-bash-and-base-tests
Jul 18, 2026
Merged

emrg: add bash_tool and base tool tests#13
argszero merged 3 commits into
masterfrom
test/add-bash-and-base-tests

Conversation

@argszero

Copy link
Copy Markdown
Owner

Changes

1. tests/test_bash_tool.py (4 tests)

  • test_bash_definition — verify name, required params, properties
  • test_bash_no_command — missing command key returns error
  • test_bash_empty_command — empty string command returns error
  • test_bash_simple_echo — integration test running real echo

2. tests/test_base_tool.py (2 tests)

  • test_tool_executor_is_abstract — verify ABC prevents direct instantiation
  • test_concrete_subclass_works — concrete subclass with both methods works

Tool test coverage status

Tool Tests PR
base ✅ 2 #13 (this PR)
bash ✅ 4 #13 (this PR)
edit ✅ 8 #9 (merged)
glob ✅ 6 existing
grep ✅ 9 existing
read ✅ 9 #11 (merged)
registry ✅ 7 #12 (open)
write ✅ 6 #10 (merged)

Verification

  • ✅ 79 tests passing (was 73 → +6)
  • from emrg.client.app import run_client; from emrg.tools.bash_tool import BashTool
  • python -m emrg --help

- tests/test_bash_tool.py: 4 tests covering definition(), missing/empty
  command error paths, and simple echo integration test.
- tests/test_base_tool.py: 2 tests verifying ToolExecutor ABC
  enforcement and concrete subclass instantiation.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle #12

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle #13

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ 需要修改:

  1. 回归except (ConnectionError, OSError)except Exceptionemrg/__main__.pyemrg/server/daemon.py 中回退了 PR #12 的 bare-except 修复。请 revert 这些修改。
  2. 测试丢失tests/test_registry.py 被删除。这个文件包含有效的 registry 测试(来自 PR #12),不应删除。

保留 test_base_tool.pytest_bash_tool.py(✅ 好的),但:

  • 恢复 except(ConnectionError, OSError)
  • 恢复 tests/test_registry.py

修完后再提交。

@argszero

Copy link
Copy Markdown
Owner Author

修复提交 094c7e2

  • ✅ revert 所有 except (ConnectionError, OSError)except Exception 回归
  • ✅ 恢复 tests/test_registry.py(来自 master)
  • ✅ 保留 tests/test_bash_tool.py + tests/test_base_tool.py
  • ✅ 86 tests passing, 无回归

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle #15

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle #16

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle #17

@argszero
argszero merged commit cd80306 into master Jul 18, 2026
argszero added a commit that referenced this pull request Jul 23, 2026
…158)

* emrg: replace NDJSON with length-prefix framing protocol (rant #13)

* emrg: fix read_frame EOF handling and add framing unit tests

---------

Co-authored-by: EMRG Evolution <emrg@argszero.dev>
argszero added a commit that referenced this pull request Aug 4, 2026
PR #377 引入两个回归(第 10 次 CI 实跑 4 平台全失败):

1. POSIX(macOS/Linux):PYEXE 探测 `ls 4个.exe 2>/dev/null | head -1` 在
   `set -euo pipefail` 下,POSIX 平台 .exe 全不存在 → ls 退出码 2 →
   管道整体非零 → set -e 杀死脚本。修复:`|| true` 吞掉 ls 失败。

2. Windows:`uv python dir` 返回 Windows 原生路径(C:\...),Git Bash 中
   glob `C:\.../cpython-3.13.9-*` 含字面反斜杠无法匹配 → PY_ROOT 定位失败
   → cp -R 源不存在 → 脚本退出。修复:`cygpath -u` 转 POSIX(仅 Windows,
   command -v 探测),并统一 glob 定位(弃用 uname 前缀拼接——Git Bash 返回
   MINGW64_NT-* 不可用),定位失败显式报错退出。

验证:
- bash -n OK
- set -euo pipefail 下 POSIX(无 .exe)/ Windows(有 .exe)双场景模拟通过
- 本机 macOS 实跑 build-runtime.sh 完整成功:runtime built OK(83M),
  python→python-dist/bin/python3.13 相对软链正确,python 3.13.9 可执行,
  version.txt=0.2.0
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
第 11 次实跑:3/4 平台成功(macOS + ubuntu×2,pipefail 修复生效),
Windows 失败于 build-runtime.sh 第 4 步 pip install:exit 127(command not found)。

根因:Git Bash 对带路径的直接执行不做 .exe 补全。Windows 复制产物为
bin/python.exe(bin/python 无扩展名文件不存在),而脚本用 `"$DIST/bin/python"`
(无扩展名)调用 → bash 找不到文件 → 127。POSIX 有 python 软链所以正常。
(bin/emrg.cmd 早已用 "%DIR%\python.exe",验证了引用方式差异。)

修复:PY_BIN 探测——bin/python 不存在且 bin/python.exe 存在时改用 .exe。
用 -e(存在性)而非 -x(可执行),cp 复制的 exe 执行位在 Git Bash 中不可靠。

验证:
- bash -n OK
- Windows(仅 python.exe)/ POSIX(仅 python 软链)双场景模拟正确
- 本机 macOS 实跑 build-runtime.sh 完整成功(83M runtime,pip deps 安装 OK)
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
…380)

第 12 次实跑:3/4 平台成功,Windows 仍失败于 build-runtime.sh 第 4 步
pip install:exit 127(0.059s 即失败 = 命令未启动)。

根因:python-build-standalone Windows 版把 python313.dll 等 DLL 放在
python-dist/ 根目录。第 2 步把 python.exe 复制到 bin/ 后,DLL 不在 exe
目录也不在 PATH → Windows loader 找不到 DLL → 进程启动失败 → bash 报 127。
(PR #379 的 PY_BIN 探测已生效:bin/python.exe 存在,但 DLL 缺失。)

连带发现:bin/emrg.cmd 和 bin/emrgd.cmd 也用 bin/python.exe 复制品——
发布后的 Windows 用户启动同样会失败。同源修复。

修复(3 文件):
1. build-runtime.sh 第 4 步:Windows 直接用 python-dist/ 根目录的
   python.exe(与 DLL 同目录),POSIX 保持 bin/python 软链
2. bin/emrg.cmd:改用 %DIR%\python-dist\python.exe(不存在则回退
   python3.13.exe)
3. bin/emrgd.cmd:同上

验证:
- bash -n OK
- Windows(python-dist 根 exe)/ POSIX(软链)双场景模拟正确
- 本机 macOS 实跑 build-runtime.sh 完整成功(83M runtime,pip deps OK)
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
第 13 次实跑:3/4 平台成功,Windows build-runtime 已通过(DLL 修复生效,
runtime built OK 89M),新失败在 bundle-git-gh.sh:chmod bin/gh 失败。

根因:Windows gh zip 内可执行文件名为 gh.exe(不是 gh)。第 60 行
`find  -name gh -type f` 在 Windows 找不到 → xargs 不执行 →
/bin/gh 不存在 → chmod exit 1。且 Windows 目标名需为 gh.exe
(PATH 注入后命令解析需要 .exe)。

修复:find 同时探测 gh 与 gh.exe;目标名按平台——windows → bin/gh.exe,
其他 → bin/gh;找不到可执行文件时显式报错退出。

验证:
- bash -n OK
- Windows(gh.exe 存在 → 目标 gh.exe)/ POSIX(gh → 目标 gh)逻辑正确
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
#382)

第 14 次实跑:3/4 平台成功(Windows build-runtime + bundle-git-gh 已通过),
新失败在 make-installer.sh Inno Setup 编译:
`emrg.iss 第 10 行: Unknown constant "userhome"` → Compile aborted exit 2。

根因:DefaultDirName={userhome} 需 Inno Setup 6.1+(2022 年引入),
windows-2025 runner 的 iscc 版本较旧(5.x)不识 {userhome} 常量。
注释里写了 fallback {userdocs}\.. 但代码未实现。

修复:改用 {%USERPROFILE}——所有 Inno 版本支持的环境变量常量,
展开为安装用户主目录,且与 [Registry] 段的 %USERPROFILE%\.emrg\install 一致。
heredoc 中 {%USERPROFILE} 无 $,不会误展开。

验证:
- bash -n OK
- .iss 生成逻辑复核:{%USERPROFILE} 无转义问题,{userprograms}/{userdesktop}/{app} 均 Inno 5 标准常量
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
第 15 次实跑:3/4 平台成功(Windows build-runtime + bundle-git-gh 已通过),
新失败在 Inno 编译:emrg.iss 第 16 行 The system cannot find the path specified。

根因:iscc 是 Windows 原生程序,读不懂 Git Bash POSIX 路径。
.iss 中 OutputDir=/artifacts、SetupIconFile=/.../icon.ico、
Source="/payload\*" 均为 /d/a/emrg/emrg/... POSIX 形式 →
iscc 找不到路径 → 编译失败(常量关已过,路径关没过)。

修复:Windows 段用 cygpath -m 将 ROOT/DIST/STAGE 转 Windows 路径
(正斜杠形式 D:/a/emrg/emrg,iscc 可读);cygpath 仅 Git Bash 有,
无则兜底保持原样。STAGE 在转换前创建(顺序修正)。

验证:
- bash -n OK
- 转换逻辑分支验证(有/无 cygpath 双路径)
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
#384)

第 16 次实跑:3/4 平台成功(Windows build-runtime + bundle-git-gh 通过,
Inno 常量关/路径关均过),新失败:emrg.iss 第 26 行
Parameter "Flags" includes an unknown flag([Tasks] 段 Flags: checked)。

推断:iscc 版本在 6.0.x({userhome} 需 6.1+ 报错→<6.1;
PrivilegesRequiredOverridesAllowed 通过→>=6.0),该版本对
[Tasks] 段某些 flag 兼容性异常。

修复:
1. 移除 [Tasks] 段(桌面快捷方式任务)及 [Icons] 中 Tasks: desktopicon
   引用——桌面快捷方式非安装包核心功能,开始菜单入口保留
2. 编译前打印 iscc 版本(iscc /?)到 CI 日志——若还有其他
   Flags 报错可据版本精准修复

验证:
- bash -n OK;无 Tasks/desktopicon 残留
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
…rant #13) (#385)

第 17 次实跑:3/4 平台成功,Windows Inno Setup 编译通过(iscc 版本
打印 + artifacts 生成),新失败在 smoke-test:7 pass / 4 fail。

4 个 fail 同一根因——安装后 bin/python(复制品)缺 DLL 不可用:
  1. emrg --version    → bin/emrg exec bin/python → 失败
  2. daemon port file  → bin/emrgd exec bin/python → 失败
  4. server stop       → 依赖 daemon → 失败
  7. python+deps       → PATH 里 python(复制品缺 DLL)→ 失败
(前轮修的 emrg.cmd/emrgd.cmd 已用 python-dist,但 bash 版 bin/emrg/
 emrgd 仍 exec bin/python;python-build-standalone DLL 在 python-dist/ 根)

修复(3 文件):
1. bin/emrg:exec 前探测 python-dist/python.exe(Windows),POSIX 保持
   bin/python 软链(R100)
2. bin/emrgd:同上
3. build-runtime.sh 第 2 步:Windows 复制 python-dist 根目录 *.dll 到
   bin/(使 PATH 里的 python 命令可用——session-scoped 脚本依赖)

验证:
- bash -n OK(3 文件)
- Windows/POSIX 双场景 PY_BIN 探测模拟正确;DLL 复制模拟正确
- 本机 macOS 实跑 build-runtime.sh 完整成功(83M + pip deps)
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
#386)

第 18 次实跑:3/4 平台成功,Windows Inno 编译通过,smoke 8 pass / 3 fail
(从 7/4 改善——emrg --version + python+deps 已过,DLL 修复生效)。

3 个 fail 均与 daemon 启动有关:
  2. daemon did not write port file
  4. server stop(依赖 daemon)
  5. rant(daemon not running)

根因:smoke 用 `nohup emrgd & ` 后台启动 bash 版 emrgd——Windows Git
Bash 无完整 POSIX 进程模型,nohup 后台 bash 脚本立即退出 → daemon 未
实际运行 → 不写 port 文件。GUI 实际用 emrgd.cmd(cmd 启动器)不受影响。

修复(R101):smoke-test.sh 两处 daemon 启动加平台分支——
Windows(WINDIR 或存在 emrgd.cmd)用 `cmd //c start /b emrgd.cmd`
后台启动;POSIX 保持 nohup emrgd(与原来完全一致)。

验证:
- bash -n OK
- 分支选择模拟:POSIX→nohup ✓;Windows→cmd ✓
- pytest 464 passed;import checks OK
- 注:未本机跑完整 smoke(其 pkill 会杀宿主 daemon 影响会话)
argszero added a commit that referenced this pull request Aug 4, 2026
…387)

第 19 次实跑 4 平台全失败(exit 127)——PR #386 引入回归:
smoke-test.sh 的 Windows 判断 `[ -n "${WINDIR:-}" ] || [ -f .../emrgd.cmd ]`
在 macOS/Linux 误判为 Windows——build-runtime.sh 第 70 行跨平台复制
emrgd.cmd(POSIX 也有此文件)→ 文件探测恒真 → macOS 走 cmd 分支 →
macOS 无 cmd 命令 → exit 127。

修复:Windows 判断只保留 ${WINDIR} 环境变量(Windows Git Bash 必有,
macOS/Linux 无),去掉文件探测。2 处同步。

验证:
- bash -n OK
- macOS 模拟(无 WINDIR 但有 emrgd.cmd 文件)→ nohup ✓
- Windows 模拟(有 WINDIR)→ cmd ✓
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
…#388)

第 20 次实跑:3/4 平台成功(WINDIR 判断修复生效,POSIX 恢复),
Windows Inno 编译通过(artifacts 生成),smoke 第 1 步 ✓,第 2 步
daemon 启动 exit 1(5 秒即挂,短于 15 秒轮询)。

根因:cmd //c start 分支的 $HOME 是 Git Bash POSIX 路径
(/c/Users/runneradmin/...),cmd 是 Windows 原生程序不认识
POSIX 路径 → start 失败 → daemon 未启动 → exit 1。

修复:cmd 分支用 cygpath -m 将 $HOME/.emrg/install/bin/emrgd.cmd
转 Windows 路径(C:/Users/... 正斜杠形式,cmd 可读)。2 处同步。

验证:
- bash -n OK
- cygpath -m 转换模拟:/c/Users/runneradmin/... → C:/Users/runneradmin/... ✓
- POSIX 分支不受影响(无 WINDIR → nohup)✓
- pytest 464 passed;import checks OK
argszero added a commit that referenced this pull request Aug 4, 2026
…13)

根因:Windows 分支经 cmd 启动 emrgd.cmd → 原生 python.exe 的 Path.home()
读 USERPROFILE(真实用户目录),不认 Git Bash 的 $HOME(mktemp 隔离目录)。
daemon 去真实目录找 config.toml → FileNotFoundError 崩溃 → 不写 port 文件,
smoke 在隔离目录轮询 15s 无果。

修复:
- Windows 下同步 USERPROFILE/HOMEDRIVE/HOMEPATH 到隔离 $HOME(cygpath -w)
- daemon 启动输出保留到 emrgd-debug.log(原 /dev/null 丢弃),失败时 cat
  诊断 traceback,避免下次盲猜 daemon did not write port file
argszero added a commit that referenced this pull request Aug 4, 2026
…13) (#389)

根因:Windows 分支经 cmd 启动 emrgd.cmd → 原生 python.exe 的 Path.home()
读 USERPROFILE(真实用户目录),不认 Git Bash 的 $HOME(mktemp 隔离目录)。
daemon 去真实目录找 config.toml → FileNotFoundError 崩溃 → 不写 port 文件,
smoke 在隔离目录轮询 15s 无果。

修复:
- Windows 下同步 USERPROFILE/HOMEDRIVE/HOMEPATH 到隔离 $HOME(cygpath -w)
- daemon 启动输出保留到 emrgd-debug.log(原 /dev/null 丢弃),失败时 cat
  诊断 traceback,避免下次盲猜 daemon did not write port file
argszero added a commit that referenced this pull request Aug 4, 2026
#390)

第 22 次实跑(1c8b256):4 平台 build 首次全绿(Windows HOME 同步生效),
但 release job 失败:softprops/action-gh-release 创建 release 时 403
"Resource not accessible by integration" —— workflow 无顶层 permissions,
GITHUB_TOKEN 默认缺 contents:write,generate_release_notes 的 REST 调用被拒。

修复:release job 声明 permissions: contents: write(最小权限,仅 release job)。
argszero added a commit that referenced this pull request Aug 4, 2026
…tep 5) (#391)

第 23 次实跑(37732da):4 平台 build + release job 全绿,但 Release v0.2.0
资产只有 4 个:macos-arm64.pkg / windows-x64.exe / linux-x86_64.tar.gz /
linux-aarch64.tar.gz —— Linux 缺 AppImage(rant #13 验收项 Step 5 要求
linux-x86_64.AppImage / linux-aarch64.AppImage)。

根因:make-installer.sh Linux 分支只生成 tar.gz,electron-builder 的
AppImage(emrg/gui/dist/*.AppImage)从未被收集到 dist/artifacts/ →
upload-artifact 的 dist/artifacts/*.AppImage 为空 → release 只有 tar.gz。

修复:Linux 分支收集 emrg/gui/dist/*.AppImage → 复制为
EMRG-<ver>-linux-<uname -m>.AppImage(x86_64/aarch64 与验收命名一致)。
未找到时警告但继续(tar.gz 兜底,不 fail build)。
argszero added a commit that referenced this pull request Aug 4, 2026
…392)

R116(PR #391)后 Linux 分支同时产出 tar.gz + AppImage,但注释与 echo
仍停留在"AppImage built by electron-builder in CI"的旧描述——日志与
文档与实际行为不一致。修正为反映收集动作(collected R116),方便
CI 排障时快速确认 AppImage 已被脚本收集到 artifacts。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant