xb-init 2.5.2__tar.gz → 2.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. {xb_init-2.5.2 → xb_init-2.6.1}/PKG-INFO +9 -17
  2. {xb_init-2.5.2 → xb_init-2.6.1}/README.md +8 -16
  3. {xb_init-2.5.2 → xb_init-2.6.1}/pyproject.toml +1 -1
  4. {xb_init-2.5.2 → xb_init-2.6.1}/tests/test_cli.py +20 -44
  5. {xb_init-2.5.2 → xb_init-2.6.1}/tests/test_config_form.py +13 -41
  6. xb_init-2.6.1/tests/test_template_render.py +239 -0
  7. {xb_init-2.5.2 → xb_init-2.6.1}/tests/test_update_templates.py +0 -2
  8. {xb_init-2.5.2 → xb_init-2.6.1}/xb/commands/doctor.py +8 -12
  9. {xb_init-2.5.2 → xb_init-2.6.1}/xb/commands/init.py +11 -46
  10. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/api/config.py.j2 +0 -135
  11. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/main.py.j2 +1 -4
  12. xb_init-2.6.1/xb/templates/backend/managers/__init__.py.j2 +7 -0
  13. xb_init-2.6.1/xb/templates/backend/managers/privileged_manager.py.j2 +85 -0
  14. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/services/updater.py.j2 +21 -14
  15. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/configs/secrets.yaml.example.j2 +0 -3
  16. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/package.json.j2 +7 -0
  17. xb_init-2.6.1/xb/templates/electron/resources/polkit/privileged-helper.sh.j2 +58 -0
  18. xb_init-2.6.1/xb/templates/electron/resources/polkit/privileged.policy.j2 +34 -0
  19. xb_init-2.6.1/xb/templates/electron/resources/polkit/privileged.rules.j2 +22 -0
  20. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/resources/postinst.py.j2 +26 -0
  21. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/resources/postrm.py.j2 +18 -0
  22. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/App.vue.j2 +0 -6
  23. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/FileManager.vue.j2 +6 -77
  24. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/AGENTS.md.j2 +18 -19
  25. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/README.md.j2 +25 -26
  26. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/build.py.j2 +75 -98
  27. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/dev.py.j2 +202 -92
  28. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/docs//350/207/252/345/212/250/346/233/264/346/226/260/350/257/264/346/230/216.md +10 -9
  29. {xb_init-2.5.2 → xb_init-2.6.1}/xb/utils/config_form.py +6 -29
  30. {xb_init-2.5.2 → xb_init-2.6.1}/xb/utils/template_engine.py +27 -26
  31. xb_init-2.5.2/tests/test_template_render.py +0 -150
  32. xb_init-2.5.2/uv.lock +0 -445
  33. xb_init-2.5.2/xb/templates/backend/managers/__init__.py.j2 +0 -7
  34. xb_init-2.5.2/xb/templates/backend/managers/sudoers_manager.py.j2 +0 -165
  35. xb_init-2.5.2/xb/templates/configs/secrets.yaml.j2 +0 -9
  36. xb_init-2.5.2/xb/templates/frontend/src/components/ConfigSetup.vue.j2 +0 -227
  37. {xb_init-2.5.2 → xb_init-2.6.1}/.github/workflows/ci.yml +0 -0
  38. {xb_init-2.5.2 → xb_init-2.6.1}/.gitignore +0 -0
  39. {xb_init-2.5.2 → xb_init-2.6.1}/docs/screenshot.png +0 -0
  40. {xb_init-2.5.2 → xb_init-2.6.1}/tests/test_upgrade.py +0 -0
  41. {xb_init-2.5.2 → xb_init-2.6.1}/xb/__init__.py +0 -0
  42. {xb_init-2.5.2 → xb_init-2.6.1}/xb/cli.py +0 -0
  43. {xb_init-2.5.2 → xb_init-2.6.1}/xb/commands/__init__.py +0 -0
  44. {xb_init-2.5.2 → xb_init-2.6.1}/xb/commands/build.py +0 -0
  45. {xb_init-2.5.2 → xb_init-2.6.1}/xb/commands/dev.py +0 -0
  46. {xb_init-2.5.2 → xb_init-2.6.1}/xb/commands/upgrade.py +0 -0
  47. {xb_init-2.5.2 → xb_init-2.6.1}/xb/commands/version.py +0 -0
  48. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/api/__init__.py.j2 +0 -0
  49. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/api/ports.py.j2 +0 -0
  50. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/api/terminal/__init__.py.j2 +0 -0
  51. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/api/terminal/routes.py.j2 +0 -0
  52. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/api/update/__init__.py.j2 +0 -0
  53. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/app_version.py.j2 +0 -0
  54. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/backend_build.py.j2 +0 -0
  55. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/managers/logger_manager.py.j2 +0 -0
  56. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/managers/path_manager.py.j2 +0 -0
  57. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/managers/secret_obfuscator.py.j2 +0 -0
  58. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/requirements.txt.j2 +0 -0
  59. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/services/__init__.py.j2 +0 -0
  60. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/backend/services/feishu_client.py.j2 +0 -0
  61. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/configs/config_changes.json.j2 +0 -0
  62. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/configs/global_config.yaml.j2 +0 -0
  63. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/launcher.js.j2 +0 -0
  64. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/main.js.j2 +0 -0
  65. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/port_diagnostics.js.j2 +0 -0
  66. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/preload.js.j2 +0 -0
  67. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/prepare.js.j2 +0 -0
  68. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/electron/resources/uninstaller.nsh.j2 +0 -0
  69. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/index.html.j2 +0 -0
  70. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/package.json.j2 +0 -0
  71. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/DashboardHome.vue.j2 +0 -0
  72. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/GitVersionBadge.vue.j2 +0 -0
  73. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/RefreshButton.vue.j2 +0 -0
  74. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/TerminalPanel.vue.j2 +0 -0
  75. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/TerminalView.vue.j2 +0 -0
  76. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/ThemeToggle.vue.j2 +0 -0
  77. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/version/CommitHistoryPanel.vue.j2 +0 -0
  78. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/components/version/UpdatePanel.vue.j2 +0 -0
  79. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/composables/useTerminalSessions.js.j2 +0 -0
  80. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/composables/useUpdate.js.j2 +0 -0
  81. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/main.js.j2 +0 -0
  82. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/src/style.css.j2 +0 -0
  83. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/frontend/vite.config.js.j2 +0 -0
  84. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/.gitignore.j2 +0 -0
  85. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/LICENSE.j2 +0 -0
  86. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/docs/images/feishu-folder.png +0 -0
  87. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/docs/images/feishu-permission.png +0 -0
  88. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/docs/images/release-upload.png +0 -0
  89. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/docs/images/update-dialog.png +0 -0
  90. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/root/pyproject.toml.j2 +0 -0
  91. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/scripts/example.py.j2 +0 -0
  92. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/scripts/feishu_upload.py.j2 +0 -0
  93. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/version/hooks/pre-commit.py.j2 +0 -0
  94. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/version/scripts/gui_version_manager.py.j2 +0 -0
  95. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/version/scripts/install_hooks.py.j2 +0 -0
  96. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/version/scripts/version_manager.py.j2 +0 -0
  97. {xb_init-2.5.2 → xb_init-2.6.1}/xb/templates/version/scripts/web_version_manager.py.j2 +0 -0
  98. {xb_init-2.5.2 → xb_init-2.6.1}/xb/utils/__init__.py +0 -0
  99. {xb_init-2.5.2 → xb_init-2.6.1}/xb/utils/click_helpers.py +0 -0
  100. {xb_init-2.5.2 → xb_init-2.6.1}/xb/utils/project.py +0 -0
  101. {xb_init-2.5.2 → xb_init-2.6.1}/xb/utils/validators.py +0 -0
  102. {xb_init-2.5.2 → xb_init-2.6.1}/xb/utils/version_check.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: xb-init
3
- Version: 2.5.2
3
+ Version: 2.6.1
4
4
  Summary: Project management tool for UV + FastAPI + Vue3 + Electron desktop applications
5
5
  Project-URL: Homepage, https://github.com/xuebli/xb
6
6
  Project-URL: Documentation, https://github.com/xuebli/xb#readme
@@ -41,7 +41,6 @@ Description-Content-Type: text/markdown
41
41
  - 自动 `git init` 并提交首个 commit(含 lock 文件)
42
42
  - 自动生成 `AGENTS.md`(AI 编码助手协作约定)
43
43
  - 内置全局亮色/暗色主题切换
44
- - 可选 sudo 免密配置(`--sudoers`)
45
44
  - 可选内置终端(`--terminal`)
46
45
  - 可选应用内自动更新(`--update`,飞书云盘发布 + 版本检查 + 下载校验 + 自动安装)
47
46
  - 可选自定义应用图标(`--icon`)
@@ -75,15 +74,10 @@ xb --help
75
74
  # 创建项目
76
75
  xb init demo
77
76
 
78
- # 带 sudo 免密配置
79
- xb init demo --sudoers
80
77
  # 带内置终端
81
78
  xb init demo --terminal
82
79
 
83
- # 同时启用终端和 sudo 免密配置
84
- xb init demo --terminal --sudoers
85
-
86
- # 启用应用内自动更新(自动附带 --sudoers 免密,输入 sudo 密码即可)
80
+ # 启用应用内自动更新(Linux 提权走 polkit,管理员组无感更新,无密码落盘)
87
81
  xb init demo --update
88
82
 
89
83
  # 带自定义图标
@@ -110,16 +104,14 @@ xb dev stop
110
104
  ────────────────────────────────────────────────────────
111
105
  ❯ [ ] 应用显示名 : Demo
112
106
  [ ] 端口(后端/前端) : 8000 / 8001
113
- [ ] sudo 免密 ✘ (Linux 应用内更新需要)
114
107
  [ ] 内置终端 ✘ (Web 终端组件)
115
- [ ] 应用内更新 ✘ (自动附带 sudo 免密)
108
+ [ ] 应用内更新 ✘ (Linux 提权走 polkit,无密码落盘)
116
109
  [ ] 应用图标 : 使用默认
117
110
  [ ] 跳过依赖安装 ✘ (离线环境可跳过)
118
111
  ```
119
112
 
120
- - `--name/--port/--sudoers/--terminal/--update/--icon/--skip-install` 传了的参数
113
+ - `--name/--port/--terminal/--update/--icon/--skip-install` 传了的参数
121
114
  直接预填进表单并勾上,回车即确认,老用法不受影响
122
- - 勾选"应用内更新"会自动勾上"sudo 免密",且后者此时不可单独取消
123
115
  - 文本行(显示名/端口/图标)勾选时若仍是默认值则自动清空,直接输入即可
124
116
  - stdin 非终端时(脚本/CI 管道调用)自动跳过表单,沿用 CLI 参数
125
117
 
@@ -149,8 +141,8 @@ Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
149
141
  > nrm 全局管理
150
142
  > - electron 约 200MB 二进制走华为云镜像下载
151
143
  > - uv 源同样自动优化:首次依赖同步(dev.py)与后端构建(build.py -b/-a)
152
- > 前用 [chsrc](https://github.com/RubyMetric/chsrc) 测速切换最快镜像
153
- > (`chsrc set uv first`,未安装 chsrc 时自动安装)
144
+ > 前并行实测各镜像(要求最终 HTTP 200),自动切换到最快可用源(约
145
+ > 1-6 秒,纯标准库实现,无需额外工具)
154
146
  > - 若安装失败或超时,会打印提示但不中断项目创建,可稍后手动重试
155
147
  > - 执行 `git init` 并提交首个 commit(包含所有文件和 lock 文件)
156
148
  > - 若检测到 PyPI 有新版 xb,会询问是否先升级再创建项目
@@ -160,7 +152,7 @@ Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
160
152
 
161
153
  | 命令 | 说明 |
162
154
  |------|------|
163
- | `xb init <name> [--name 显示名] [--port 9000] [--sudoers] [--terminal] [--update] [--icon PATH] [--skip-install]` | 初始化项目 |
155
+ | `xb init <name> [--name 显示名] [--port 9000] [--terminal] [--update] [--icon PATH] [--skip-install]` | 初始化项目 |
164
156
  | `xb dev [start\|stop\|status]` | 启动/停止/查看开发环境 |
165
157
  | `xb build [all\|frontend\|backend\|electron]` | 构建项目 |
166
158
  | `xb build -f / -b / -e / -a` | 构建快捷 flag |
@@ -209,8 +201,8 @@ xb init demo --icon ./my-icon.png
209
201
 
210
202
  **客户端:** 启动时 / 每小时 / 点版本号徽章时检查更新;发现新版本后下载
211
203
  (4 线程分块 + SHA256 校验 + `.part` 防半截包)→ 备份配置 → 按
212
- `config_changes.json` 迁移 → Ubuntu 趁应用存活时免密 `sudo dpkg -i`
213
- (`--update` 默认附带 `--sudoers` 免密),Windows 等退出后静默安装。
204
+ `config_changes.json` 迁移 → Ubuntu 走 polkit 免密安装(授权规则由 DEB
205
+ postinst 预部署,管理员组无感、无密码落盘),Windows 等退出后静默安装。
214
206
 
215
207
  **飞书侧准备:** 开放平台建自建应用 → 开通 `drive:drive` 权限并发布 →
216
208
  建云盘文件夹,完整链接填入 `update_folder_url`。开发模式(源码运行)不支持
@@ -12,7 +12,6 @@
12
12
  - 自动 `git init` 并提交首个 commit(含 lock 文件)
13
13
  - 自动生成 `AGENTS.md`(AI 编码助手协作约定)
14
14
  - 内置全局亮色/暗色主题切换
15
- - 可选 sudo 免密配置(`--sudoers`)
16
15
  - 可选内置终端(`--terminal`)
17
16
  - 可选应用内自动更新(`--update`,飞书云盘发布 + 版本检查 + 下载校验 + 自动安装)
18
17
  - 可选自定义应用图标(`--icon`)
@@ -46,15 +45,10 @@ xb --help
46
45
  # 创建项目
47
46
  xb init demo
48
47
 
49
- # 带 sudo 免密配置
50
- xb init demo --sudoers
51
48
  # 带内置终端
52
49
  xb init demo --terminal
53
50
 
54
- # 同时启用终端和 sudo 免密配置
55
- xb init demo --terminal --sudoers
56
-
57
- # 启用应用内自动更新(自动附带 --sudoers 免密,输入 sudo 密码即可)
51
+ # 启用应用内自动更新(Linux 提权走 polkit,管理员组无感更新,无密码落盘)
58
52
  xb init demo --update
59
53
 
60
54
  # 带自定义图标
@@ -81,16 +75,14 @@ xb dev stop
81
75
  ────────────────────────────────────────────────────────
82
76
  ❯ [ ] 应用显示名 : Demo
83
77
  [ ] 端口(后端/前端) : 8000 / 8001
84
- [ ] sudo 免密 ✘ (Linux 应用内更新需要)
85
78
  [ ] 内置终端 ✘ (Web 终端组件)
86
- [ ] 应用内更新 ✘ (自动附带 sudo 免密)
79
+ [ ] 应用内更新 ✘ (Linux 提权走 polkit,无密码落盘)
87
80
  [ ] 应用图标 : 使用默认
88
81
  [ ] 跳过依赖安装 ✘ (离线环境可跳过)
89
82
  ```
90
83
 
91
- - `--name/--port/--sudoers/--terminal/--update/--icon/--skip-install` 传了的参数
84
+ - `--name/--port/--terminal/--update/--icon/--skip-install` 传了的参数
92
85
  直接预填进表单并勾上,回车即确认,老用法不受影响
93
- - 勾选"应用内更新"会自动勾上"sudo 免密",且后者此时不可单独取消
94
86
  - 文本行(显示名/端口/图标)勾选时若仍是默认值则自动清空,直接输入即可
95
87
  - stdin 非终端时(脚本/CI 管道调用)自动跳过表单,沿用 CLI 参数
96
88
 
@@ -120,8 +112,8 @@ Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
120
112
  > nrm 全局管理
121
113
  > - electron 约 200MB 二进制走华为云镜像下载
122
114
  > - uv 源同样自动优化:首次依赖同步(dev.py)与后端构建(build.py -b/-a)
123
- > 前用 [chsrc](https://github.com/RubyMetric/chsrc) 测速切换最快镜像
124
- > (`chsrc set uv first`,未安装 chsrc 时自动安装)
115
+ > 前并行实测各镜像(要求最终 HTTP 200),自动切换到最快可用源(约
116
+ > 1-6 秒,纯标准库实现,无需额外工具)
125
117
  > - 若安装失败或超时,会打印提示但不中断项目创建,可稍后手动重试
126
118
  > - 执行 `git init` 并提交首个 commit(包含所有文件和 lock 文件)
127
119
  > - 若检测到 PyPI 有新版 xb,会询问是否先升级再创建项目
@@ -131,7 +123,7 @@ Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
131
123
 
132
124
  | 命令 | 说明 |
133
125
  |------|------|
134
- | `xb init <name> [--name 显示名] [--port 9000] [--sudoers] [--terminal] [--update] [--icon PATH] [--skip-install]` | 初始化项目 |
126
+ | `xb init <name> [--name 显示名] [--port 9000] [--terminal] [--update] [--icon PATH] [--skip-install]` | 初始化项目 |
135
127
  | `xb dev [start\|stop\|status]` | 启动/停止/查看开发环境 |
136
128
  | `xb build [all\|frontend\|backend\|electron]` | 构建项目 |
137
129
  | `xb build -f / -b / -e / -a` | 构建快捷 flag |
@@ -180,8 +172,8 @@ xb init demo --icon ./my-icon.png
180
172
 
181
173
  **客户端:** 启动时 / 每小时 / 点版本号徽章时检查更新;发现新版本后下载
182
174
  (4 线程分块 + SHA256 校验 + `.part` 防半截包)→ 备份配置 → 按
183
- `config_changes.json` 迁移 → Ubuntu 趁应用存活时免密 `sudo dpkg -i`
184
- (`--update` 默认附带 `--sudoers` 免密),Windows 等退出后静默安装。
175
+ `config_changes.json` 迁移 → Ubuntu 走 polkit 免密安装(授权规则由 DEB
176
+ postinst 预部署,管理员组无感、无密码落盘),Windows 等退出后静默安装。
185
177
 
186
178
  **飞书侧准备:** 开放平台建自建应用 → 开通 `drive:drive` 权限并发布 →
187
179
  建云盘文件夹,完整链接填入 `update_folder_url`。开发模式(源码运行)不支持
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "xb-init"
7
- version = "2.5.2"
7
+ version = "2.6.1"
8
8
  description = "Project management tool for UV + FastAPI + Vue3 + Electron desktop applications"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -15,15 +15,9 @@ def test_upgrade_option_runs_without_subcommand(monkeypatch):
15
15
  assert "Missing command" not in result.output
16
16
 
17
17
 
18
- def _invoke_init(monkeypatch, tmp_path, args, password, platform="linux"):
19
- """跑 init 命令但替换掉耗时/有副作用的步骤,捕获传给模板引擎的参数。
20
-
21
- - 密码通过 monkeypatch rich Prompt.ask 注入而非 stdin 管道
22
- - platform 默认 patch 为 linux(询问密码的行为只在 Linux 分支),
23
- 否则真 Windows runner 上 sys.platform=win32 会直接跳过密码询问
24
- """
18
+ def _invoke_init(monkeypatch, tmp_path, args, platform="linux"):
19
+ """跑 init 命令但替换掉耗时/有副作用的步骤,捕获传给模板引擎的参数。"""
25
20
  captured = {}
26
- asked = []
27
21
  monkeypatch.setattr(init_module, "get_latest_if_newer", lambda _v: None)
28
22
  monkeypatch.setattr(init_module.shutil, "which", lambda _name: None)
29
23
  monkeypatch.setattr(init_module, "init_git_repo", lambda *_a, **_k: True)
@@ -34,46 +28,39 @@ def _invoke_init(monkeypatch, tmp_path, args, password, platform="linux"):
34
28
  lambda self, **kwargs: captured.update(kwargs),
35
29
  )
36
30
 
37
- def fake_ask(*_args, **_kwargs):
38
- asked.append(True)
39
- return password
40
-
41
- monkeypatch.setattr(init_module.Prompt, "ask", fake_ask)
42
-
43
31
  result = CliRunner().invoke(
44
32
  cli.main, ["init", str(tmp_path / "demo"), *args], input="\n"
45
33
  )
46
34
  assert result.exit_code == 0, result.output
47
- return captured, result.output, asked
35
+ return captured, result.output
48
36
 
49
37
 
50
- def test_update_implies_sudoers(monkeypatch, tmp_path):
51
- captured, _output, _asked = _invoke_init(monkeypatch, tmp_path, ["--update"], "pw123")
38
+ def test_update_passed_through(monkeypatch, tmp_path):
39
+ captured, output = _invoke_init(monkeypatch, tmp_path, ["--update"])
52
40
 
53
41
  assert captured["enable_update"] is True
54
- assert captured["enable_sudo"] is True
55
- assert captured["sudo_password"] == "pw123"
42
+ # Linux 上 --update 提示走 polkit(不再有 sudoers 密码询问)
43
+ assert "polkit" in output
56
44
 
57
45
 
58
- def test_sudoers_alone_still_prompts(monkeypatch, tmp_path):
59
- captured, output, asked = _invoke_init(monkeypatch, tmp_path, ["--sudoers"], "pw123")
46
+ def test_update_hint_suppressed_on_windows(monkeypatch, tmp_path):
47
+ captured, output = _invoke_init(
48
+ monkeypatch, tmp_path, ["--update"], platform="win32"
49
+ )
60
50
 
61
- assert captured["enable_update"] is False
62
- assert captured["enable_sudo"] is True
63
- assert captured["sudo_password"] == "pw123"
64
- assert "自动附带" not in output
51
+ assert captured["enable_update"] is True
52
+ assert "polkit" not in output
65
53
 
66
54
 
67
- def test_plain_init_has_no_sudo(monkeypatch, tmp_path):
68
- captured, output, asked = _invoke_init(monkeypatch, tmp_path, [], "")
55
+ def test_plain_init_has_no_update(monkeypatch, tmp_path):
56
+ captured, _ = _invoke_init(monkeypatch, tmp_path, [])
69
57
 
70
58
  assert captured["enable_update"] is False
71
- assert captured["enable_sudo"] is False
72
- assert captured["sudo_password"] == ""
59
+ assert captured["enable_terminal"] is False
73
60
 
74
61
 
75
62
  def test_display_name_passed_through(monkeypatch, tmp_path):
76
- captured, _, _asked = _invoke_init(
63
+ captured, _ = _invoke_init(
77
64
  monkeypatch, tmp_path, ["--name", "我的应用"], ""
78
65
  )
79
66
 
@@ -81,19 +68,19 @@ def test_display_name_passed_through(monkeypatch, tmp_path):
81
68
 
82
69
 
83
70
  def test_display_name_defaults_to_none(monkeypatch, tmp_path):
84
- captured, _, _asked = _invoke_init(monkeypatch, tmp_path, [], "")
71
+ captured, _ = _invoke_init(monkeypatch, tmp_path, [])
85
72
 
86
73
  assert captured["display_name"] is None
87
74
 
88
75
 
89
76
  def test_port_passed_through(monkeypatch, tmp_path):
90
- captured, _output, _asked = _invoke_init(monkeypatch, tmp_path, ["--port", "9100"], "")
77
+ captured, _output = _invoke_init(monkeypatch, tmp_path, ["--port", "9100"])
91
78
 
92
79
  assert captured["backend_port"] == 9100
93
80
 
94
81
 
95
82
  def test_port_defaults_to_none(monkeypatch, tmp_path):
96
- captured, _, _asked = _invoke_init(monkeypatch, tmp_path, [], "")
83
+ captured, _ = _invoke_init(monkeypatch, tmp_path, [])
97
84
 
98
85
  assert captured["backend_port"] is None
99
86
 
@@ -123,14 +110,3 @@ def test_pick_fastest_from_nrm_output():
123
110
  def test_pick_fastest_from_nrm_output_all_failed():
124
111
  output = " npmMirror ---- 1265 ms (Fetch error, if this is your private registry, please ignore)\n"
125
112
  assert init_module._pick_fastest_from_nrm_output(output) == ("", None)
126
-
127
-
128
- def test_windows_skips_sudo_password(monkeypatch, tmp_path):
129
- captured, output, asked = _invoke_init(
130
- monkeypatch, tmp_path, ["--sudoers"], "should-not-be-used", platform="win32"
131
- )
132
-
133
- assert captured["enable_sudo"] is True
134
- assert captured["sudo_password"] == ""
135
- assert asked == [] # Windows 不询问密码
136
- assert "跳过密码输入" in output
@@ -1,17 +1,10 @@
1
- """配置表单(ConfigForm)交互逻辑测试:不进键盘循环,直接驱动方法。
2
-
3
- 表单在 Windows 上会隐藏 sudoers 行,逻辑测试统一以 Linux 形态为准
4
- (mock os.name),Windows 隐藏行为由 test_sudoers_row_hidden_on_windows 覆盖。
5
- """
6
-
7
- import unittest.mock as mock
1
+ """配置表单(ConfigForm)交互逻辑测试:不进键盘循环,直接驱动方法。"""
8
2
 
9
3
  from xb.utils.config_form import ConfigForm, run_config_form
10
4
 
11
5
 
12
6
  def make_form(cli=None):
13
- with mock.patch("xb.utils.config_form.os.name", "posix"):
14
- return ConfigForm("demo", cli)
7
+ return ConfigForm("demo", cli)
15
8
 
16
9
 
17
10
  def _cursor_key(form, key):
@@ -19,28 +12,13 @@ def _cursor_key(form, key):
19
12
  i for i, r in enumerate(form.rows) if r["key"] == key)
20
13
 
21
14
 
22
- def test_update_checks_sudoers_and_blocks_unchecking():
23
- form = make_form()
24
- _cursor_key(form, "update")
25
- form.toggle()
26
- assert form._row("update")["checked"] is True
27
- assert form._row("sudoers")["checked"] is True
28
-
29
- # update 勾着时 sudoers 无法单独取消
30
- _cursor_key(form, "sudoers")
31
- form.toggle()
32
- assert form._row("sudoers")["checked"] is True
33
- assert form.message # 有提示
34
-
35
-
36
- def test_sudoers_toggle_without_update():
15
+ def test_toggle_switches_rows():
37
16
  form = make_form()
38
- _cursor_key(form, "sudoers")
17
+ _cursor_key(form, "terminal")
39
18
  form.toggle()
40
- assert form._row("sudoers")["checked"] is True
19
+ assert form._row("terminal")["checked"] is True
41
20
  form.toggle()
42
- assert form._row("sudoers")["checked"] is False
43
- assert not form.message
21
+ assert form._row("terminal")["checked"] is False
44
22
 
45
23
 
46
24
  def test_text_row_clears_default_on_first_check():
@@ -68,12 +46,16 @@ def test_text_row_keeps_custom_value_when_rechecked():
68
46
  assert form._row("display_name")["value"] == "机器人"
69
47
 
70
48
 
49
+ def test_no_sudo_row_in_any_platform():
50
+ """sudoers 行已随 polkit 方案彻底移除,任何平台都不应出现。"""
51
+ assert not make_form()._has("sudoers")
52
+
53
+
71
54
  def test_collect_unchecked_items_are_none():
72
55
  form = make_form()
73
56
  result = form.collect()
74
57
  assert result["display_name"] is None
75
58
  assert result["port"] is None
76
- assert result["sudoers"] is False
77
59
  assert result["terminal"] is False
78
60
  assert result["update"] is False
79
61
  assert result["icon"] is None
@@ -88,7 +70,6 @@ def test_collect_valid_port():
88
70
  form.feed_char(ch)
89
71
  result = form.collect()
90
72
  assert result["port"] == 9200
91
- assert result["sudoers"] is False
92
73
 
93
74
 
94
75
  def test_collect_invalid_port_falls_back_to_none():
@@ -102,14 +83,6 @@ def test_collect_invalid_port_falls_back_to_none():
102
83
  assert form._row("port")["checked"] is False
103
84
 
104
85
 
105
- def test_sudoers_row_hidden_on_windows():
106
- with mock.patch("xb.utils.config_form.os.name", "nt"):
107
- form = ConfigForm("demo")
108
- assert not form._has("sudoers")
109
- result = form.collect()
110
- assert result["sudoers"] is False
111
-
112
-
113
86
  def test_backspace_only_on_checked_text_row():
114
87
  form = make_form({"display_name": "abc"})
115
88
  _cursor_key(form, "display_name")
@@ -124,14 +97,13 @@ def test_run_config_form_skipped_when_not_tty():
124
97
  result = run_config_form("demo", {
125
98
  "display_name": None,
126
99
  "port": 9100,
127
- "sudoers": False,
128
100
  "terminal": True,
129
101
  "update": True,
130
102
  "icon": None,
131
103
  "skip_install": False,
132
104
  })
133
- # 非 tty 环境跳过表单,CLI 值原样透传且 update 联动 sudoers
105
+ # 非 tty 环境跳过表单,CLI 值原样透传
134
106
  assert result["port"] == 9100
135
- assert result["sudoers"] is True
136
107
  assert result["terminal"] is True
108
+ assert result["update"] is True
137
109
  assert result["display_name"] is None
@@ -0,0 +1,239 @@
1
+ """模板渲染矩阵测试:terminal x update 全组合。
2
+
3
+ 渲染到临时目录,校验:
4
+ - 条件文件按开关出现/缺席(防止模板改坏条件渲染)
5
+ - 所有生成的 .py 能通过 compile() 语法检查(防止模板产出非法 Python)
6
+ - polkit 三件套随 --update 生成且内容合法
7
+ """
8
+
9
+ import itertools
10
+ import json
11
+ import re
12
+ import xml.etree.ElementTree as ET
13
+
14
+ import pytest
15
+
16
+ from xb.utils.template_engine import TemplateEngine
17
+
18
+ COMBOS = list(itertools.product([False, True], repeat=2))
19
+
20
+
21
+ def _render(tmp_path, enable_terminal, enable_update, display_name=None,
22
+ backend_port=None):
23
+ target = tmp_path / "demo"
24
+ TemplateEngine().render_project(
25
+ target_dir=target,
26
+ package_name="demo",
27
+ display_name=display_name,
28
+ backend_port=backend_port,
29
+ enable_terminal=enable_terminal,
30
+ enable_update=enable_update,
31
+ )
32
+ return target
33
+
34
+
35
+ @pytest.mark.parametrize(("enable_terminal", "enable_update"), COMBOS)
36
+ def test_render_project_matrix(tmp_path, enable_terminal, enable_update):
37
+ target = _render(tmp_path, enable_terminal, enable_update)
38
+
39
+ # 基础骨架始终存在
40
+ for rel in (
41
+ "pyproject.toml",
42
+ "dev.py",
43
+ "build.py",
44
+ "README.md",
45
+ "LICENSE",
46
+ "AGENTS.md",
47
+ "backend/main.py",
48
+ "backend/managers/path_manager.py",
49
+ "frontend/src/App.vue",
50
+ "electron/main.js",
51
+ "configs/global_config.yaml",
52
+ "version/scripts/version_manager.py",
53
+ ):
54
+ assert (target / rel).exists(), f"缺少基础文件 {rel}"
55
+
56
+ # sudoers 已被 polkit 方案取代,任何组合都不应再生成
57
+ assert not (target / "backend" / "managers" / "sudoers_manager.py").exists()
58
+
59
+ # 条件文件按开关出现/缺席
60
+ conditional = {
61
+ "backend/api/terminal/routes.py": enable_terminal,
62
+ "frontend/src/components/TerminalPanel.vue": enable_terminal,
63
+ "frontend/src/composables/useTerminalSessions.js": enable_terminal,
64
+ "backend/api/update/__init__.py": enable_update,
65
+ "backend/services/updater.py": enable_update,
66
+ "backend/managers/secret_obfuscator.py": enable_update,
67
+ "backend/managers/privileged_manager.py": enable_update,
68
+ "scripts/feishu_upload.py": enable_update,
69
+ "frontend/src/composables/useUpdate.js": enable_update,
70
+ "electron/resources/polkit/privileged.policy": enable_update,
71
+ "electron/resources/polkit/privileged.rules": enable_update,
72
+ "electron/resources/polkit/privileged-helper.sh": enable_update,
73
+ }
74
+ for rel, should_exist in conditional.items():
75
+ assert (target / rel).exists() is should_exist, f"{rel} 存在性与开关不符"
76
+
77
+ # 生成的所有 Python 文件必须是合法语法(含带 jinja 条件的模板产物)
78
+ for py in target.rglob("*.py"):
79
+ source = py.read_text(encoding="utf-8")
80
+ compile(source, str(py), "exec")
81
+
82
+ # 所有 Vue 组件的 <script setup> 顶层不得有重复 const 声明,
83
+ # 且 setTimeout 的赋值目标必须已声明(ESM 严格模式下未声明赋值会抛错)
84
+ for vue in (target / "frontend" / "src").rglob("*.vue"):
85
+ text = vue.read_text(encoding="utf-8")
86
+ if "<script setup>" not in text:
87
+ continue
88
+ script = text.split("<script setup>")[1].split("</script>")[0]
89
+ decls = re.findall(r"^const (\w+)", script, re.M)
90
+ dupes = sorted(d for d in set(decls) if decls.count(d) > 1)
91
+ assert not dupes, f"{vue.name} 重复声明: {dupes}"
92
+ declared = set(decls) | set(re.findall(r"^let (\w+)", script, re.M))
93
+ assigned = set(re.findall(r"(\w+) = setTimeout", script))
94
+ undeclared = sorted(a for a in assigned if a not in declared)
95
+ assert not undeclared, f"{vue.name} 未声明的 timer: {undeclared}"
96
+
97
+
98
+ def test_render_project_main_py_switches(tmp_path):
99
+ """main.py 的路由注册随开关变化。"""
100
+ plain = _render(tmp_path / "a", False, False)
101
+ main_plain = (plain / "backend" / "main.py").read_text(encoding="utf-8")
102
+ assert "terminal_router" not in main_plain
103
+ assert "update_router" not in main_plain
104
+ assert "sudoers_manager" not in main_plain
105
+
106
+ full = _render(tmp_path / "b", True, True)
107
+ main_full = (full / "backend" / "main.py").read_text(encoding="utf-8")
108
+ assert "terminal_router" in main_full
109
+ assert "update_router" in main_full
110
+ assert "sudoers_manager" not in main_full
111
+
112
+
113
+ def test_display_name_defaults_to_capitalized_package(tmp_path):
114
+ target = _render(tmp_path, False, False)
115
+ assert "<title>Demo</title>" in (target / "frontend" / "index.html").read_text(
116
+ encoding="utf-8"
117
+ )
118
+
119
+
120
+ def test_ports_written_to_global_config(tmp_path):
121
+ """--port 指定后端端口时,前端端口自动 +1;不传时用默认值。"""
122
+ target = _render(tmp_path, False, False, backend_port=9100)
123
+ config = (target / "configs" / "global_config.yaml").read_text(encoding="utf-8")
124
+ assert "backend: 9100" in config
125
+ assert "frontend: 9101" in config
126
+
127
+ default = _render(tmp_path / "d", False, False)
128
+ default_config = (default / "configs" / "global_config.yaml").read_text(
129
+ encoding="utf-8"
130
+ )
131
+ assert "backend: 8000" in default_config
132
+ assert "frontend: 5173" in default_config
133
+
134
+
135
+ def test_display_name_with_quotes_and_chinese(tmp_path):
136
+ """显示名含引号/中文/空格时,各产物文件必须仍然合法。"""
137
+ display_name = '我的 "Cool" App'
138
+ target = _render(tmp_path, False, True, display_name=display_name)
139
+
140
+ # HTML 文案直接使用显示名
141
+ assert f"<title>{display_name}</title>" in (
142
+ target / "frontend" / "index.html"
143
+ ).read_text(encoding="utf-8")
144
+
145
+ # electron/package.json 必须是合法 JSON 且 description 正确
146
+ pkg = json.loads((target / "electron" / "package.json").read_text(encoding="utf-8"))
147
+ assert pkg["description"] == display_name
148
+ # 技术标识不被显示名污染
149
+ assert pkg["name"] == "demo"
150
+ assert pkg["build"]["productName"] == "Demo"
151
+
152
+ # Python 产物可编译且标题正确(tojson 转义后的字面量)
153
+ main_py = (target / "backend" / "main.py").read_text(encoding="utf-8")
154
+ compile(main_py, "main.py", "exec")
155
+ assert f"title={json.dumps(display_name, ensure_ascii=False)}" in main_py
156
+
157
+ # pyproject 的 TOML description 合法(TOML basic string 与 JSON 转义兼容)
158
+ pyproject = (target / "pyproject.toml").read_text(encoding="utf-8")
159
+ assert 'description = "我的 \\"Cool\\" App' in pyproject
160
+
161
+ # README 标题使用显示名
162
+ assert f"# {display_name}" in (target / "README.md").read_text(encoding="utf-8")
163
+
164
+
165
+ def test_polkit_assets_with_update(tmp_path):
166
+ """--update 项目自带 polkit 三件套,且内容合法、授权边界正确。"""
167
+ target = _render(tmp_path, False, True)
168
+ polkit_dir = target / "electron" / "resources" / "polkit"
169
+
170
+ # policy 是合法 XML,action id 与包名绑定(仅作声明文档,
171
+ # pkexec 判定固定走 org.freedesktop.policykit.exec)
172
+ policy = ET.parse(polkit_dir / "privileged.policy").getroot()
173
+ action = policy.find("action")
174
+ assert action.get("id") == "com.demo.privileged"
175
+
176
+ # helper 是白名单执行器:case 分支 + realpath 防路径逃逸
177
+ helper = (polkit_dir / "privileged-helper.sh").read_text(encoding="utf-8")
178
+ assert "case" in helper
179
+ assert "install-update" in helper
180
+ assert "realpath" in helper
181
+ assert "/home/" in helper
182
+ assert "datas/updates" in helper
183
+ assert helper.count("dpkg") == 1
184
+
185
+ # rules 免密放行必须写在 pkexec 固定的 exec action 上,
186
+ # 并用 program 白名单限定只对 privileged-helper 生效
187
+ rules = (polkit_dir / "privileged.rules").read_text(encoding="utf-8")
188
+ assert 'action.id == "org.freedesktop.policykit.exec"' in rules
189
+ assert (
190
+ 'action.lookup("program") == "/usr/local/share/demo/privileged-helper"'
191
+ in rules
192
+ )
193
+ assert "isInGroup" in rules
194
+ assert "com.demo.privileged" not in rules
195
+
196
+ # managers 导出统一特权入口
197
+ init = (target / "backend" / "managers" / "__init__.py").read_text(encoding="utf-8")
198
+ assert "privileged_manager" in init
199
+ mgr = (target / "backend" / "managers" / "privileged_manager.py").read_text(
200
+ encoding="utf-8"
201
+ )
202
+ compile(mgr, "privileged_manager.py", "exec")
203
+ assert 'HELPER = Path("/usr/local/share/demo/privileged-helper")' in mgr
204
+
205
+ # postinst 部署三件套,postrm 卸载即撤销授权
206
+ postinst = (target / "electron" / "resources" / "postinst.py").read_text(encoding="utf-8")
207
+ postrm = (target / "electron" / "resources" / "postrm.py").read_text(encoding="utf-8")
208
+ assert "polkit-1/actions" in postinst
209
+ assert "privileged-helper" in postinst
210
+ assert "polkit-1/actions" in postrm
211
+ # helper 目录 /usr/local/share/<app> 卸载时整个移除
212
+ assert "usr/local/share" in postrm
213
+
214
+ # updater 走 pkexec + 白名单 action,不再有 sudo 安装命令
215
+ updater = (target / "backend" / "services" / "updater.py").read_text(encoding="utf-8")
216
+ assert "pkexec" in updater
217
+ assert "install-update" in updater
218
+ assert "sudo -n" not in updater
219
+
220
+ # DEB 打包把 polkit 目录带进安装包
221
+ pkg = json.loads((target / "electron" / "package.json").read_text(encoding="utf-8"))
222
+ polkit_resource = next(
223
+ (r for r in pkg["build"]["extraResources"] if r.get("from") == "resources/polkit"),
224
+ None,
225
+ )
226
+ assert polkit_resource is not None
227
+
228
+ # secrets 模板不再有 sudo_password
229
+ example = (target / "configs" / "secrets.yaml.example").read_text(encoding="utf-8")
230
+ assert "sudo_password" not in example
231
+
232
+
233
+ def test_polkit_assets_absent_without_update(tmp_path):
234
+ target = _render(tmp_path, False, False)
235
+ assert not (target / "electron" / "resources" / "polkit").exists()
236
+ postinst = (target / "electron" / "resources" / "postinst.py").read_text(encoding="utf-8")
237
+ assert "polkit" not in postinst
238
+ # update 关闭时 updater 不生成,自然无 pkexec
239
+ assert not (target / "backend" / "services" / "updater.py").exists()
@@ -10,8 +10,6 @@ UPDATE_FILES = [
10
10
  "backend/services/feishu_client.py",
11
11
  "backend/api/update/__init__.py",
12
12
  "backend/managers/secret_obfuscator.py",
13
- "backend/managers/sudoers_manager.py",
14
- "backend/app_version.py",
15
13
  "scripts/feishu_upload.py",
16
14
  "configs/config_changes.json",
17
15
  "frontend/src/components/version/UpdatePanel.vue",