xb-init 2.9.0__tar.gz → 3.2.0__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 (161) hide show
  1. {xb_init-2.9.0 → xb_init-3.2.0}/PKG-INFO +15 -5
  2. {xb_init-2.9.0 → xb_init-3.2.0}/README.md +14 -4
  3. {xb_init-2.9.0 → xb_init-3.2.0}/pyproject.toml +1 -1
  4. xb_init-3.2.0/tests/test_cli.py +260 -0
  5. {xb_init-2.9.0 → xb_init-3.2.0}/tests/test_config_form.py +12 -0
  6. {xb_init-2.9.0 → xb_init-3.2.0}/tests/test_doctor.py +32 -9
  7. xb_init-3.2.0/tests/test_template_render.py +1216 -0
  8. xb_init-3.2.0/tests/test_update_templates.py +331 -0
  9. {xb_init-2.9.0 → xb_init-3.2.0}/xb/cli.py +3 -2
  10. {xb_init-2.9.0 → xb_init-3.2.0}/xb/commands/doctor.py +20 -5
  11. {xb_init-2.9.0 → xb_init-3.2.0}/xb/commands/init.py +137 -18
  12. {xb_init-2.9.0 → xb_init-3.2.0}/xb/commands/upgrade.py +4 -1
  13. xb_init-3.2.0/xb/templates/assets/app-icon.png +0 -0
  14. xb_init-3.2.0/xb/templates/backend/api/__init__.py.j2 +100 -0
  15. xb_init-3.2.0/xb/templates/backend/api/auth/routes.py.j2 +200 -0
  16. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/config.py.j2 +12 -4
  17. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/factory_test/routes.py.j2 +57 -1
  18. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/logs.py.j2 +19 -13
  19. xb_init-3.2.0/xb/templates/backend/api/notify.py.j2 +57 -0
  20. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/settings.py.j2 +91 -7
  21. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/terminal/routes.py.j2 +201 -23
  22. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/update/__init__.py.j2 +25 -6
  23. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/backend_build.py.j2 +3 -0
  24. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/main.py.j2 +56 -13
  25. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/managers/path_manager.py.j2 +6 -9
  26. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/requirements.txt.j2 +2 -1
  27. xb_init-3.2.0/xb/templates/backend/schemas/__init__.py.j2 +0 -0
  28. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/schemas/factory_test.py.j2 +1 -0
  29. xb_init-3.2.0/xb/templates/backend/services/auth/__init__.py.j2 +328 -0
  30. xb_init-3.2.0/xb/templates/backend/services/factory_test/dashboard.py.j2 +117 -0
  31. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/definition.py.j2 +10 -2
  32. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/report.py.j2 +29 -1
  33. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/result_compare.py.j2 +11 -0
  34. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/runner.py.j2 +47 -11
  35. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/test_control.py.j2 +4 -4
  36. xb_init-3.2.0/xb/templates/backend/services/factory_test/test_data.py.j2 +229 -0
  37. xb_init-3.2.0/xb/templates/backend/services/feishu_bitable.py.j2 +314 -0
  38. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/feishu_client.py.j2 +33 -4
  39. xb_init-3.2.0/xb/templates/backend/services/feishu_notify.py.j2 +228 -0
  40. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/updater.py.j2 +109 -44
  41. xb_init-3.2.0/xb/templates/configs/global_config.yaml.j2 +9 -0
  42. xb_init-3.2.0/xb/templates/configs/secrets.yaml.example.j2 +17 -0
  43. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/launcher.js.j2 +49 -7
  44. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/main.js.j2 +35 -1
  45. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/package.json.j2 +17 -8
  46. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/port_diagnostics.js.j2 +31 -2
  47. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/resources/polkit/privileged-helper.sh.j2 +24 -3
  48. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/resources/polkit/privileged.rules.j2 +6 -5
  49. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/resources/postinst.py.j2 +31 -7
  50. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/resources/postrm.py.j2 +23 -0
  51. xb_init-3.2.0/xb/templates/electron/resources/systemd/server.service.j2 +34 -0
  52. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/resources/uninstaller.nsh.j2 +2 -0
  53. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/index.html.j2 +1 -0
  54. xb_init-3.2.0/xb/templates/frontend/src/App.vue.j2 +230 -0
  55. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/GitVersionBadge.vue.j2 +2 -2
  56. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/LogViewer.vue.j2 +28 -6
  57. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/SettingsView.vue.j2 +67 -5
  58. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/TerminalPanel.vue.j2 +67 -2
  59. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/factory_test/CsvEditor.vue.j2 +2 -8
  60. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/factory_test/ManualConfirmBanner.vue.j2 +14 -1
  61. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/version/UpdatePanel.vue.j2 +23 -4
  62. xb_init-3.2.0/xb/templates/frontend/src/composables/useAuth.js.j2 +52 -0
  63. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/composables/useTerminalSessions.js.j2 +21 -2
  64. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/composables/useUpdate.js.j2 +32 -6
  65. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/services/factoryTestApi.js.j2 +15 -4
  66. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/style.css.j2 +159 -0
  67. xb_init-3.2.0/xb/templates/frontend/src/views/DashboardView.vue.j2 +631 -0
  68. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/views/FactoryTestView.vue.j2 +64 -34
  69. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/vite.config.js.j2 +17 -3
  70. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/.gitignore.j2 +1 -0
  71. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/AGENTS.md.j2 +8 -8
  72. xb_init-3.2.0/xb/templates/root/README.md.j2 +313 -0
  73. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/build.py.j2 +54 -4
  74. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/dev.py.j2 +39 -7
  75. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs/csv/346/265/213/350/257/225/345/274/225/346/223/216/350/257/264/346/230/216.md +27 -6
  76. xb_init-3.2.0/xb/templates/root/docs/images/setup-01-create-app.png +0 -0
  77. xb_init-3.2.0/xb/templates/root/docs/images/setup-02-app-credential.png +0 -0
  78. xb_init-3.2.0/xb/templates/root/docs/images/setup-03-fill-secrets.png +0 -0
  79. xb_init-3.2.0/xb/templates/root/docs/images/setup-04-permission.png +0 -0
  80. xb_init-3.2.0/xb/templates/root/docs/images/setup-06-redirect-url.png +0 -0
  81. xb_init-3.2.0/xb/templates/root/docs/images/setup-07-publish.png +0 -0
  82. xb_init-3.2.0/xb/templates/root/docs/images/setup-08-webhook.png +0 -0
  83. xb_init-3.2.0/xb/templates/root/docs/images/setup-09-bot-into-group.png +0 -0
  84. xb_init-3.2.0/xb/templates/root/docs/images/setup-10-create-bitable.png +0 -0
  85. xb_init-3.2.0/xb/templates/root/docs/images/setup-11-bitable-collaborator.png +0 -0
  86. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs/polkit/345/205/215/345/257/206/346/217/220/346/235/203/350/257/264/346/230/216.md +9 -7
  87. xb_init-3.2.0/xb/templates/root/docs//345/257/206/351/222/245/346/267/267/346/267/206/350/257/264/346/230/216.md +76 -0
  88. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs//346/211/223/345/214/205/344/270/216/350/277/220/350/241/214/350/267/257/345/276/204/350/257/264/346/230/216.md +2 -2
  89. xb_init-3.2.0/xb/templates/root/docs//346/234/215/345/212/241/345/231/250/351/203/250/347/275/262/350/257/264/346/230/216.md.j2 +138 -0
  90. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs//347/211/210/346/234/254/347/256/241/347/220/206/350/257/264/346/230/216.md +3 -1
  91. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs//350/207/252/345/212/250/346/233/264/346/226/260/350/257/264/346/230/216.md +25 -11
  92. xb_init-3.2.0/xb/templates/root/docs//351/243/236/344/271/246/345/244/232/347/273/264/350/241/250/346/240/274/350/257/264/346/230/216.md.j2 +96 -0
  93. xb_init-3.2.0/xb/templates/root/docs//351/243/236/344/271/246/347/231/273/345/275/225/350/257/264/346/230/216.md.j2 +100 -0
  94. xb_init-3.2.0/xb/templates/root/docs//351/243/236/344/271/246/351/200/232/347/237/245/350/257/264/346/230/216.md.j2 +43 -0
  95. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/pyproject.toml.j2 +2 -0
  96. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/version/scripts/gui_version_manager.py.j2 +2 -1
  97. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/version/scripts/version_manager.py.j2 +29 -0
  98. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/version/scripts/web_version_manager.py.j2 +53 -9
  99. {xb_init-2.9.0 → xb_init-3.2.0}/xb/utils/config_form.py +26 -1
  100. {xb_init-2.9.0 → xb_init-3.2.0}/xb/utils/template_engine.py +144 -27
  101. {xb_init-2.9.0 → xb_init-3.2.0}/xb/utils/version_check.py +9 -9
  102. xb_init-2.9.0/tests/test_cli.py +0 -119
  103. xb_init-2.9.0/tests/test_template_render.py +0 -487
  104. xb_init-2.9.0/tests/test_update_templates.py +0 -75
  105. xb_init-2.9.0/xb/templates/backend/api/__init__.py.j2 +0 -3
  106. xb_init-2.9.0/xb/templates/backend/services/factory_test/test_data.py.j2 +0 -106
  107. xb_init-2.9.0/xb/templates/configs/global_config.yaml.j2 +0 -3
  108. xb_init-2.9.0/xb/templates/configs/secrets.yaml.example.j2 +0 -8
  109. xb_init-2.9.0/xb/templates/frontend/src/App.vue.j2 +0 -118
  110. xb_init-2.9.0/xb/templates/frontend/src/components/factory_test/TestDataViewer.vue.j2 +0 -337
  111. xb_init-2.9.0/xb/templates/root/README.md.j2 +0 -174
  112. {xb_init-2.9.0 → xb_init-3.2.0}/.github/workflows/ci.yml +0 -0
  113. {xb_init-2.9.0 → xb_init-3.2.0}/.gitignore +0 -0
  114. {xb_init-2.9.0 → xb_init-3.2.0}/docs/screenshot.png +0 -0
  115. {xb_init-2.9.0 → xb_init-3.2.0}/tests/test_upgrade.py +0 -0
  116. {xb_init-2.9.0 → xb_init-3.2.0}/xb/__init__.py +0 -0
  117. {xb_init-2.9.0 → xb_init-3.2.0}/xb/commands/__init__.py +0 -0
  118. {xb_init-2.9.0 → xb_init-3.2.0}/xb/commands/build.py +0 -0
  119. {xb_init-2.9.0 → xb_init-3.2.0}/xb/commands/dev.py +0 -0
  120. {xb_init-2.9.0 → xb_init-3.2.0}/xb/commands/version.py +0 -0
  121. {xb_init-2.9.0/xb/templates/backend/schemas → xb_init-3.2.0/xb/templates/backend/api/auth}/__init__.py.j2 +0 -0
  122. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/factory_test/__init__.py.j2 +0 -0
  123. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/ports.py.j2 +0 -0
  124. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/api/terminal/__init__.py.j2 +0 -0
  125. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/app_version.py.j2 +0 -0
  126. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/managers/__init__.py.j2 +0 -0
  127. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/managers/logger_manager.py.j2 +0 -0
  128. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/managers/privileged_manager.py.j2 +0 -0
  129. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/managers/secret_obfuscator.py.j2 +0 -0
  130. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/managers/yaml_comments.py.j2 +0 -0
  131. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/__init__.py.j2 +0 -0
  132. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/__init__.py.j2 +0 -0
  133. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/command_executor.py.j2 +0 -0
  134. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/backend/services/factory_test/commands.py.j2 +0 -0
  135. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/configs/config_changes.json.j2 +0 -0
  136. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/configs/test_plan.csv.j2 +0 -0
  137. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/preload.js.j2 +0 -0
  138. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/prepare.js.j2 +0 -0
  139. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/electron/resources/polkit/privileged.policy.j2 +0 -0
  140. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/package.json.j2 +0 -0
  141. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/DashboardHome.vue.j2 +0 -0
  142. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/RefreshButton.vue.j2 +0 -0
  143. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/TerminalView.vue.j2 +0 -0
  144. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/ThemeToggle.vue.j2 +0 -0
  145. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/factory_test/TestGroupTable.vue.j2 +0 -0
  146. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/factory_test/TestLogPanel.vue.j2 +0 -0
  147. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/components/version/CommitHistoryPanel.vue.j2 +0 -0
  148. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/frontend/src/main.js.j2 +0 -0
  149. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/LICENSE.j2 +0 -0
  150. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs/images/feishu-folder.png +0 -0
  151. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs/images/feishu-permission.png +0 -0
  152. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs/images/release-upload.png +0 -0
  153. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/root/docs/images/update-dialog.png +0 -0
  154. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/scripts/example.py.j2 +0 -0
  155. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/scripts/feishu_upload.py.j2 +0 -0
  156. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/version/hooks/pre-commit.py.j2 +0 -0
  157. {xb_init-2.9.0 → xb_init-3.2.0}/xb/templates/version/scripts/install_hooks.py.j2 +0 -0
  158. {xb_init-2.9.0 → xb_init-3.2.0}/xb/utils/__init__.py +0 -0
  159. {xb_init-2.9.0 → xb_init-3.2.0}/xb/utils/click_helpers.py +0 -0
  160. {xb_init-2.9.0 → xb_init-3.2.0}/xb/utils/project.py +0 -0
  161. {xb_init-2.9.0 → xb_init-3.2.0}/xb/utils/validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: xb-init
3
- Version: 2.9.0
3
+ Version: 3.2.0
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
@@ -46,6 +46,9 @@ Description-Content-Type: text/markdown
46
46
  - 通用设置页(yaml 加一行"值 + 行尾 `# 显示名`"即自动出表单,注释回填不丢失;secrets.yaml 的 key 自动渲染为密码框)
47
47
  - 可选应用内自动更新(`--update`,飞书云盘发布 + 版本检查 + 下载校验 + 自动安装)
48
48
  - 可选 CSV 测试引擎(`--csv-test`,产测专用:CSV 定义测试项、人工确认、PASS 判定、HTML 报告归档与历史查看)
49
+ - 可选飞书登录(`--feishu-auth`,OAuth 扫码登录 + 单会话制 + 可开关的强制登录墙,多人协作/服务器部署用)
50
+ - 可选飞书群通知(`--feishu-notify`,webhook 只发文字 / 自建应用可发文件附件,产测归档自动推送,业务可直接调用)
51
+ - 可选飞书多维表格(`--feishu-bitable`,数据写入多维表格:自动建字段/附件上传/wiki 链接解析,产测勾选推送,业务可直接调用)
49
52
  - 特权操作免密提权标配(Linux polkit,管理员组无感、无密码落盘;helper 白名单执行器)
50
53
  - 可选自定义应用图标(`--icon`)
51
54
  - 内置开发、构建、版本管理命令
@@ -122,7 +125,7 @@ xb dev stop
122
125
  [ ] 跳过依赖安装 ✘ (离线环境可跳过)
123
126
  ```
124
127
 
125
- - `--name/--port/--terminal/--update/--logs/--csv-test/--icon/--skip-install` 传了的参数
128
+ - `--name/--port/--terminal/--update/--logs/--csv-test/--feishu-auth/--feishu-notify/--feishu-bitable/--icon/--skip-install` 传了的参数
126
129
  直接预填进表单并勾上,回车即确认,老用法不受影响
127
130
  - 文本行(显示名/端口/图标)勾选时若仍是默认值则自动清空,直接输入即可
128
131
  - stdin 非终端时(脚本/CI 管道调用)自动跳过表单,沿用 CLI 参数
@@ -138,6 +141,8 @@ python .\dev.py stop
138
141
 
139
142
  使用 `--terminal` 时,Windows 终端使用 PowerShell + ConPTY,支持上下箭头
140
143
  命令历史、复制粘贴、Tab 补全和 Ctrl+C;Ubuntu/Debian 使用 bash + Unix PTY。
144
+ 后端、Vite 与终端 WebSocket 默认仅允许本机访问并校验页面 Origin;
145
+ 在补齐身份认证前不要改为 `0.0.0.0` 暴露到局域网。
141
146
 
142
147
  Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
143
148
  若安装过程被网络中断,生成项目的
@@ -164,13 +169,13 @@ Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
164
169
 
165
170
  | 命令 | 说明 |
166
171
  |------|------|
167
- | `xb init <name> [--name 显示名] [--port 9000] [--terminal] [--update] [--logs] [--icon PATH] [--skip-install]` | 初始化项目 |
172
+ | `xb init <name> [--name 显示名] [--port 9000] [--terminal] [--update] [--logs] [--csv-test] [--feishu-auth] [--feishu-notify] [--feishu-bitable] [--icon PATH] [--skip-install]` | 初始化项目 |
168
173
  | `xb dev [start\|stop\|status]` | 启动/停止/查看开发环境 |
169
174
  | `xb build [all\|frontend\|backend\|electron]` | 构建项目 |
170
175
  | `xb build -f / -b / -e / -a` | 构建快捷 flag |
171
176
  | `xb version [patch\|minor\|major]` | 读取或更新版本号 |
172
177
  | `xb doctor [--fix]` | 检查开发环境;`--fix` 自动安装 nrm/uv、交互式配置 git 身份 |
173
- | `xb --upgrade` | 升级 xb 到 PyPI 最新版本 |
178
+ | `xb --upgrade` / `xb upgrade` | 升级 xb 到 PyPI 最新版本 |
174
179
 
175
180
  ## 应用图标
176
181
 
@@ -234,7 +239,12 @@ postinst 预部署,管理员组无感、无密码落盘),Windows 等退出
234
239
  | [自动更新说明.md](xb/templates/root/docs/自动更新说明.md) | 应用内自动更新:发版流程、配置迁移清单、AI 开发者纪律 |
235
240
  | [polkit免密提权说明.md](xb/templates/root/docs/polkit免密提权说明.md) | Linux polkit 免密提权:安全模型、三件套部署、新增特权操作、排障 |
236
241
  | [打包与运行路径说明.md](xb/templates/root/docs/打包与运行路径说明.md) | 构建产物、DEB/NSIS 安装布局、运行时数据目录、三种运行形态判定 |
242
+ | [服务器部署说明.md](xb/templates/root/docs/服务器部署说明.md.j2) | 无头后端服务器部署:Ubuntu systemd / Windows 计划任务、日常管理、升级卸载(`.j2` 按项目渲染包名/端口) |
243
+ | [密钥混淆说明.md](xb/templates/root/docs/密钥混淆说明.md) | 敏感值落盘混淆:SENSITIVE_TAGS 判断规则、obf1 格式、触发时机、防围观边界 |
237
244
  | [csv测试引擎说明.md](xb/templates/root/docs/csv测试引擎说明.md) | 产测 CSV 引擎:测试项格式、指令键注册、HTML 报告、纪律(`--csv-test` 项目) |
245
+ | [飞书登录说明.md](xb/templates/root/docs/飞书登录说明.md.j2) | 飞书登录前提条件:开放平台建应用/网页应用/重定向白名单/发布、企业定制域名、单会话制、排障(`--feishu-auth` 项目,`.j2` 按项目渲染端口) |
246
+ | [飞书通知说明.md](xb/templates/root/docs/飞书通知说明.md.j2) | 群通知双模式(webhook/自建应用+chat_id)、配置步骤、排障(`--feishu-notify` 项目) |
247
+ | [飞书多维表格说明.md](xb/templates/root/docs/飞书多维表格说明.md.j2) | 多维表格上传:配置、完整写入链路(三重门/结构准备/附件并行)、字段映射、排障(`--feishu-bitable` 项目) |
238
248
  | [版本管理说明.md](xb/templates/root/docs/版本管理说明.md) | 版本号 single source of truth、三模态 bump 弹窗、手动 bump、hook 纪律 |
239
249
 
240
250
  ## 生成的项目结构
@@ -260,7 +270,7 @@ demo/
260
270
  │ ├── package.json
261
271
  │ ├── package-lock.json
262
272
  │ ├── main.js
263
- │ └── resources/ # icon + Linux DEB hooks
273
+ │ └── resources/ # icon.png/icon.ico/icons/ 图标集 + systemd 单元模板 + Linux DEB hooks
264
274
  ├── version/ # 版本管理(pre-commit hook)
265
275
  ├── configs/ # 配置文件
266
276
  ├── datas/ # 运行时数据(gitignore)
@@ -17,6 +17,9 @@
17
17
  - 通用设置页(yaml 加一行"值 + 行尾 `# 显示名`"即自动出表单,注释回填不丢失;secrets.yaml 的 key 自动渲染为密码框)
18
18
  - 可选应用内自动更新(`--update`,飞书云盘发布 + 版本检查 + 下载校验 + 自动安装)
19
19
  - 可选 CSV 测试引擎(`--csv-test`,产测专用:CSV 定义测试项、人工确认、PASS 判定、HTML 报告归档与历史查看)
20
+ - 可选飞书登录(`--feishu-auth`,OAuth 扫码登录 + 单会话制 + 可开关的强制登录墙,多人协作/服务器部署用)
21
+ - 可选飞书群通知(`--feishu-notify`,webhook 只发文字 / 自建应用可发文件附件,产测归档自动推送,业务可直接调用)
22
+ - 可选飞书多维表格(`--feishu-bitable`,数据写入多维表格:自动建字段/附件上传/wiki 链接解析,产测勾选推送,业务可直接调用)
20
23
  - 特权操作免密提权标配(Linux polkit,管理员组无感、无密码落盘;helper 白名单执行器)
21
24
  - 可选自定义应用图标(`--icon`)
22
25
  - 内置开发、构建、版本管理命令
@@ -93,7 +96,7 @@ xb dev stop
93
96
  [ ] 跳过依赖安装 ✘ (离线环境可跳过)
94
97
  ```
95
98
 
96
- - `--name/--port/--terminal/--update/--logs/--csv-test/--icon/--skip-install` 传了的参数
99
+ - `--name/--port/--terminal/--update/--logs/--csv-test/--feishu-auth/--feishu-notify/--feishu-bitable/--icon/--skip-install` 传了的参数
97
100
  直接预填进表单并勾上,回车即确认,老用法不受影响
98
101
  - 文本行(显示名/端口/图标)勾选时若仍是默认值则自动清空,直接输入即可
99
102
  - stdin 非终端时(脚本/CI 管道调用)自动跳过表单,沿用 CLI 参数
@@ -109,6 +112,8 @@ python .\dev.py stop
109
112
 
110
113
  使用 `--terminal` 时,Windows 终端使用 PowerShell + ConPTY,支持上下箭头
111
114
  命令历史、复制粘贴、Tab 补全和 Ctrl+C;Ubuntu/Debian 使用 bash + Unix PTY。
115
+ 后端、Vite 与终端 WebSocket 默认仅允许本机访问并校验页面 Origin;
116
+ 在补齐身份认证前不要改为 `0.0.0.0` 暴露到局域网。
112
117
 
113
118
  Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
114
119
  若安装过程被网络中断,生成项目的
@@ -135,13 +140,13 @@ Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
135
140
 
136
141
  | 命令 | 说明 |
137
142
  |------|------|
138
- | `xb init <name> [--name 显示名] [--port 9000] [--terminal] [--update] [--logs] [--icon PATH] [--skip-install]` | 初始化项目 |
143
+ | `xb init <name> [--name 显示名] [--port 9000] [--terminal] [--update] [--logs] [--csv-test] [--feishu-auth] [--feishu-notify] [--feishu-bitable] [--icon PATH] [--skip-install]` | 初始化项目 |
139
144
  | `xb dev [start\|stop\|status]` | 启动/停止/查看开发环境 |
140
145
  | `xb build [all\|frontend\|backend\|electron]` | 构建项目 |
141
146
  | `xb build -f / -b / -e / -a` | 构建快捷 flag |
142
147
  | `xb version [patch\|minor\|major]` | 读取或更新版本号 |
143
148
  | `xb doctor [--fix]` | 检查开发环境;`--fix` 自动安装 nrm/uv、交互式配置 git 身份 |
144
- | `xb --upgrade` | 升级 xb 到 PyPI 最新版本 |
149
+ | `xb --upgrade` / `xb upgrade` | 升级 xb 到 PyPI 最新版本 |
145
150
 
146
151
  ## 应用图标
147
152
 
@@ -205,7 +210,12 @@ postinst 预部署,管理员组无感、无密码落盘),Windows 等退出
205
210
  | [自动更新说明.md](xb/templates/root/docs/自动更新说明.md) | 应用内自动更新:发版流程、配置迁移清单、AI 开发者纪律 |
206
211
  | [polkit免密提权说明.md](xb/templates/root/docs/polkit免密提权说明.md) | Linux polkit 免密提权:安全模型、三件套部署、新增特权操作、排障 |
207
212
  | [打包与运行路径说明.md](xb/templates/root/docs/打包与运行路径说明.md) | 构建产物、DEB/NSIS 安装布局、运行时数据目录、三种运行形态判定 |
213
+ | [服务器部署说明.md](xb/templates/root/docs/服务器部署说明.md.j2) | 无头后端服务器部署:Ubuntu systemd / Windows 计划任务、日常管理、升级卸载(`.j2` 按项目渲染包名/端口) |
214
+ | [密钥混淆说明.md](xb/templates/root/docs/密钥混淆说明.md) | 敏感值落盘混淆:SENSITIVE_TAGS 判断规则、obf1 格式、触发时机、防围观边界 |
208
215
  | [csv测试引擎说明.md](xb/templates/root/docs/csv测试引擎说明.md) | 产测 CSV 引擎:测试项格式、指令键注册、HTML 报告、纪律(`--csv-test` 项目) |
216
+ | [飞书登录说明.md](xb/templates/root/docs/飞书登录说明.md.j2) | 飞书登录前提条件:开放平台建应用/网页应用/重定向白名单/发布、企业定制域名、单会话制、排障(`--feishu-auth` 项目,`.j2` 按项目渲染端口) |
217
+ | [飞书通知说明.md](xb/templates/root/docs/飞书通知说明.md.j2) | 群通知双模式(webhook/自建应用+chat_id)、配置步骤、排障(`--feishu-notify` 项目) |
218
+ | [飞书多维表格说明.md](xb/templates/root/docs/飞书多维表格说明.md.j2) | 多维表格上传:配置、完整写入链路(三重门/结构准备/附件并行)、字段映射、排障(`--feishu-bitable` 项目) |
209
219
  | [版本管理说明.md](xb/templates/root/docs/版本管理说明.md) | 版本号 single source of truth、三模态 bump 弹窗、手动 bump、hook 纪律 |
210
220
 
211
221
  ## 生成的项目结构
@@ -231,7 +241,7 @@ demo/
231
241
  │ ├── package.json
232
242
  │ ├── package-lock.json
233
243
  │ ├── main.js
234
- │ └── resources/ # icon + Linux DEB hooks
244
+ │ └── resources/ # icon.png/icon.ico/icons/ 图标集 + systemd 单元模板 + Linux DEB hooks
235
245
  ├── version/ # 版本管理(pre-commit hook)
236
246
  ├── configs/ # 配置文件
237
247
  ├── datas/ # 运行时数据(gitignore)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "xb-init"
7
- version = "2.9.0"
7
+ version = "3.2.0"
8
8
  description = "Project management tool for UV + FastAPI + Vue3 + Electron desktop applications"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -0,0 +1,260 @@
1
+ import click
2
+ import pytest
3
+ from click.testing import CliRunner
4
+
5
+ import xb.commands.init as init_module
6
+ from xb import cli
7
+
8
+
9
+ def test_upgrade_option_runs_without_subcommand(monkeypatch):
10
+ called = []
11
+ monkeypatch.setattr(cli, "run_upgrade", lambda: called.append(True))
12
+
13
+ result = CliRunner().invoke(cli.main, ["--upgrade"])
14
+
15
+ assert result.exit_code == 0
16
+ assert called == [True]
17
+ assert "Missing command" not in result.output
18
+
19
+
20
+ def test_upgrade_subcommand_registered(monkeypatch):
21
+ called = []
22
+ monkeypatch.setattr(cli, "ensure_check", lambda _v: None)
23
+ monkeypatch.setattr(cli, "get_pending_upgrade_hint", lambda _v: None)
24
+ monkeypatch.setattr("xb.commands.upgrade.run_upgrade", lambda: called.append(True))
25
+
26
+ result = CliRunner().invoke(cli.main, ["upgrade"])
27
+
28
+ assert result.exit_code == 0
29
+ assert called == [True]
30
+
31
+
32
+ def _invoke_init(monkeypatch, tmp_path, args, platform="linux"):
33
+ """跑 init 命令但替换掉耗时/有副作用的步骤,捕获传给模板引擎的参数。"""
34
+ captured = {}
35
+ monkeypatch.setattr(init_module, "get_latest_if_newer", lambda _v: None)
36
+ monkeypatch.setattr(init_module.shutil, "which", lambda _name: None)
37
+ monkeypatch.setattr(init_module, "init_git_repo", lambda *_a, **_k: True)
38
+ monkeypatch.setattr(init_module.sys, "platform", platform)
39
+ monkeypatch.setattr(
40
+ init_module.TemplateEngine,
41
+ "render_project",
42
+ lambda self, **kwargs: captured.update(kwargs),
43
+ )
44
+
45
+ result = CliRunner().invoke(
46
+ cli.main, ["init", str(tmp_path / "demo"), *args], input="\n"
47
+ )
48
+ assert result.exit_code == 0, result.output
49
+ return captured, result.output
50
+
51
+
52
+ def test_update_passed_through(monkeypatch, tmp_path):
53
+ captured, output = _invoke_init(monkeypatch, tmp_path, ["--update"])
54
+
55
+ assert captured["enable_update"] is True
56
+ # Linux 上 --update 提示走 polkit(不再有 sudoers 密码询问)
57
+ assert "polkit" in output
58
+
59
+
60
+ def test_update_hint_suppressed_on_windows(monkeypatch, tmp_path):
61
+ captured, output = _invoke_init(
62
+ monkeypatch, tmp_path, ["--update"], platform="win32"
63
+ )
64
+
65
+ assert captured["enable_update"] is True
66
+ assert "polkit" not in output
67
+
68
+
69
+ def test_logs_passed_through(monkeypatch, tmp_path):
70
+ captured, _ = _invoke_init(monkeypatch, tmp_path, ["--logs"])
71
+
72
+ assert captured["enable_logs"] is True
73
+
74
+
75
+ def test_plain_init_has_no_update(monkeypatch, tmp_path):
76
+ captured, _ = _invoke_init(monkeypatch, tmp_path, [])
77
+
78
+ assert captured["enable_update"] is False
79
+ assert captured["enable_terminal"] is False
80
+ assert captured["enable_logs"] is False
81
+
82
+
83
+ def test_display_name_passed_through(monkeypatch, tmp_path):
84
+ captured, _ = _invoke_init(
85
+ monkeypatch, tmp_path, ["--name", "我的应用"], ""
86
+ )
87
+
88
+ assert captured["display_name"] == "我的应用"
89
+
90
+
91
+ def test_display_name_defaults_to_none(monkeypatch, tmp_path):
92
+ captured, _ = _invoke_init(monkeypatch, tmp_path, [])
93
+
94
+ assert captured["display_name"] is None
95
+
96
+
97
+ def test_port_passed_through(monkeypatch, tmp_path):
98
+ captured, _output = _invoke_init(monkeypatch, tmp_path, ["--port", "9100"])
99
+
100
+ assert captured["backend_port"] == 9100
101
+
102
+
103
+ def test_port_defaults_to_none(monkeypatch, tmp_path):
104
+ captured, _ = _invoke_init(monkeypatch, tmp_path, [])
105
+
106
+ assert captured["backend_port"] is None
107
+
108
+
109
+ def test_port_out_of_range_rejected(monkeypatch, tmp_path):
110
+ monkeypatch.setattr(init_module, "get_latest_if_newer", lambda _v: None)
111
+
112
+ result = CliRunner().invoke(
113
+ cli.main, ["init", str(tmp_path / "demo"), "--port", "70000"], input="\n"
114
+ )
115
+
116
+ assert result.exit_code != 0
117
+
118
+
119
+ def test_port_65535_rejected(monkeypatch, tmp_path):
120
+ """后端 65535 会让前端端口变成 65536,必须提前拒绝。"""
121
+ monkeypatch.setattr(init_module, "get_latest_if_newer", lambda _v: None)
122
+
123
+ result = CliRunner().invoke(
124
+ cli.main, ["init", str(tmp_path / "demo"), "--port", "65535"], input="\n"
125
+ )
126
+
127
+ assert result.exit_code != 0
128
+
129
+
130
+ def test_init_current_directory_rejected(monkeypatch):
131
+ """防止 `xb init .` 在覆盖确认后删除当前工作区。"""
132
+ monkeypatch.setattr(init_module, "get_latest_if_newer", lambda _v: None)
133
+
134
+ result = CliRunner().invoke(cli.main, ["init", "."], input="\n")
135
+
136
+ assert result.exit_code != 0
137
+ assert "当前工作目录" in result.output
138
+
139
+
140
+ def _prepare_interactive_overwrite(monkeypatch, render_project):
141
+ """隔离 init 的外部副作用,并允许测试进入覆盖流程。"""
142
+ monkeypatch.setattr(init_module, "get_latest_if_newer", lambda _v: None)
143
+ monkeypatch.setattr(init_module, "run_config_form", lambda _package, values: values)
144
+ monkeypatch.setattr(init_module.Confirm, "ask", lambda *_a, **_k: True)
145
+ monkeypatch.setattr(init_module.shutil, "which", lambda _name: None)
146
+ monkeypatch.setattr(init_module, "init_git_repo", lambda *_a, **_k: True)
147
+ monkeypatch.setattr(init_module.TemplateEngine, "render_project", render_project)
148
+
149
+ class TtyInput:
150
+ @staticmethod
151
+ def isatty():
152
+ return True
153
+
154
+ monkeypatch.setattr(init_module.sys, "stdin", TtyInput())
155
+
156
+
157
+ def _invoke_init_callback(target, icon=None):
158
+ init_module.init_command.callback(
159
+ package=str(target),
160
+ display_name=None,
161
+ port=None,
162
+ terminal=False,
163
+ icon=icon,
164
+ update=False,
165
+ logs=False,
166
+ csv_test=False,
167
+ feishu_auth=False,
168
+ feishu_notify=False,
169
+ feishu_bitable=False,
170
+ skip_install=True,
171
+ )
172
+
173
+
174
+ def test_init_rejects_symlink_without_touching_target(monkeypatch, tmp_path):
175
+ external = tmp_path / "external"
176
+ external.mkdir()
177
+ sentinel = external / "keep.txt"
178
+ sentinel.write_text("keep", encoding="utf-8")
179
+ link = tmp_path / "demo"
180
+ try:
181
+ link.symlink_to(external, target_is_directory=True)
182
+ except OSError as exc:
183
+ pytest.skip(f"当前平台无法创建目录符号链接: {exc}")
184
+
185
+ monkeypatch.setattr(init_module, "get_latest_if_newer", lambda _v: None)
186
+ with pytest.raises(click.Abort):
187
+ _invoke_init_callback(link)
188
+
189
+ assert sentinel.read_text(encoding="utf-8") == "keep"
190
+ assert list(external.iterdir()) == [sentinel]
191
+
192
+
193
+ def test_init_render_failure_preserves_existing_project(monkeypatch, tmp_path):
194
+ target = tmp_path / "demo"
195
+ target.mkdir()
196
+ sentinel = target / "keep.txt"
197
+ sentinel.write_text("old", encoding="utf-8")
198
+
199
+ def fail_render(_self, **kwargs):
200
+ work_dir = kwargs["target_dir"]
201
+ (work_dir / "partial.txt").write_text("partial", encoding="utf-8")
202
+ raise RuntimeError("render failed")
203
+
204
+ _prepare_interactive_overwrite(monkeypatch, fail_render)
205
+ with pytest.raises(click.Abort):
206
+ _invoke_init_callback(target)
207
+
208
+ assert sentinel.read_text(encoding="utf-8") == "old"
209
+ assert list(target.iterdir()) == [sentinel]
210
+ assert not list(tmp_path.glob(".demo.xb-*"))
211
+
212
+
213
+ def test_init_replaces_existing_project_only_after_success(monkeypatch, tmp_path):
214
+ target = tmp_path / "demo"
215
+ target.mkdir()
216
+ (target / "old.txt").write_text("old", encoding="utf-8")
217
+
218
+ def render(_self, **kwargs):
219
+ work_dir = kwargs["target_dir"]
220
+ assert work_dir != target
221
+ (work_dir / "new.txt").write_text("new", encoding="utf-8")
222
+
223
+ _prepare_interactive_overwrite(monkeypatch, render)
224
+ _invoke_init_callback(target)
225
+
226
+ assert not (target / "old.txt").exists()
227
+ assert (target / "new.txt").read_text(encoding="utf-8") == "new"
228
+ assert not list(tmp_path.glob(".demo.xb-*"))
229
+
230
+
231
+ def test_init_missing_icon_preserves_existing_project(monkeypatch, tmp_path):
232
+ target = tmp_path / "demo"
233
+ target.mkdir()
234
+ sentinel = target / "keep.txt"
235
+ sentinel.write_text("old", encoding="utf-8")
236
+
237
+ _prepare_interactive_overwrite(monkeypatch, lambda *_a, **_k: None)
238
+ with pytest.raises(click.BadParameter):
239
+ _invoke_init_callback(target, icon=str(tmp_path / "missing.png"))
240
+
241
+ assert sentinel.read_text(encoding="utf-8") == "old"
242
+ assert list(target.iterdir()) == [sentinel]
243
+ assert not list(tmp_path.glob(".demo.xb-*"))
244
+
245
+
246
+ def test_pick_fastest_from_nrm_output():
247
+ output = """ npm ---------- 807 ms
248
+ yarn --------- 795 ms
249
+ tencent ------ 284 ms
250
+ cnpm --------- 803 ms
251
+ * taobao ------- 163 ms
252
+ npmMirror ---- 1265 ms (Fetch error, if this is your private registry, please ignore)
253
+ huawei ------- 96 ms
254
+ """
255
+ assert init_module._pick_fastest_from_nrm_output(output) == ("huawei", 96)
256
+
257
+
258
+ def test_pick_fastest_from_nrm_output_all_failed():
259
+ output = " npmMirror ---- 1265 ms (Fetch error, if this is your private registry, please ignore)\n"
260
+ assert init_module._pick_fastest_from_nrm_output(output) == ("", None)
@@ -90,6 +90,18 @@ def test_collect_invalid_port_falls_back_to_none():
90
90
  assert form._row("port")["checked"] is False
91
91
 
92
92
 
93
+ def test_collect_port_65535_falls_back_to_none():
94
+ """前端端口 = 后端 + 1,因此表单后端上限是 65534。"""
95
+ form = make_form()
96
+ _cursor_key(form, "port")
97
+ form.toggle()
98
+ for ch in "65535":
99
+ form.feed_char(ch)
100
+ result = form.collect()
101
+ assert result["port"] is None
102
+ assert form._row("port")["checked"] is False
103
+
104
+
93
105
  def test_backspace_only_on_checked_text_row():
94
106
  form = make_form({"display_name": "abc"})
95
107
  _cursor_key(form, "display_name")
@@ -18,7 +18,7 @@ def test_doctor_plain_run_does_not_fix(monkeypatch):
18
18
 
19
19
  result = CliRunner().invoke(cli.main, ["doctor"])
20
20
 
21
- assert result.exit_code == 0
21
+ assert result.exit_code == 1
22
22
  assert called == []
23
23
  assert "需要处理" in result.output
24
24
  assert "正在修复" not in result.output
@@ -38,7 +38,7 @@ def test_doctor_fix_invokes_fixer_and_rechecks(monkeypatch):
38
38
 
39
39
  result = CliRunner().invoke(cli.main, ["doctor", "--fix"])
40
40
 
41
- assert result.exit_code == 0, result.output
41
+ assert result.exit_code == 1, result.output
42
42
  assert calls == ["uv"]
43
43
  assert "可自动修复" in result.output
44
44
  assert "uv 已修复" in result.output
@@ -57,10 +57,28 @@ def test_doctor_fix_reports_failure(monkeypatch):
57
57
 
58
58
  result = CliRunner().invoke(cli.main, ["doctor", "--fix"])
59
59
 
60
- assert result.exit_code == 0
60
+ assert result.exit_code == 1
61
61
  assert "uv 修复失败" in result.output
62
62
 
63
63
 
64
+ def test_node_21_is_rejected(monkeypatch):
65
+ """Vite 8 的分段区间不包含奇数版本 Node 21。"""
66
+ versions = {
67
+ "uv": "uv 0.5.0",
68
+ "node": "v21.0.0",
69
+ "npm": "10.0.0",
70
+ "git": "git version 2.43.0",
71
+ "nrm": "2.0.0",
72
+ }
73
+ monkeypatch.setattr(doctor_module, "_command_version", lambda command, args=None: versions.get(command))
74
+ monkeypatch.setattr(doctor_module.shutil, "which", lambda command: f"/bin/{command}")
75
+ monkeypatch.setattr(doctor_module, "_git_global_config", lambda key: "xb" if key == "user.name" else "x@b.c")
76
+
77
+ checks = doctor_module._collect_checks()
78
+ node = next(item for item in checks if item.name == "Node.js")
79
+ assert node.ok is False
80
+
81
+
64
82
  def test_doctor_fix_nothing_fixable(monkeypatch):
65
83
  monkeypatch.setattr(
66
84
  doctor_module,
@@ -70,7 +88,7 @@ def test_doctor_fix_nothing_fixable(monkeypatch):
70
88
 
71
89
  result = CliRunner().invoke(cli.main, ["doctor", "--fix"])
72
90
 
73
- assert result.exit_code == 0
91
+ assert result.exit_code == 1
74
92
  assert "没有可自动修复的问题" in result.output
75
93
 
76
94
 
@@ -81,11 +99,16 @@ def test_doctor_fix_git_identity(monkeypatch):
81
99
  commands.append(cmd)
82
100
  return subprocess.CompletedProcess(cmd, 0)
83
101
 
84
- monkeypatch.setattr(
85
- doctor_module,
86
- "_collect_checks",
87
- lambda: [CheckResult("git 身份", False, "未配置 user.name, user.email", fixable=True)],
88
- )
102
+ # 首次检查失败,修复成功后复查通过。
103
+ iter_values = iter([
104
+ [CheckResult("git 身份", False, "未配置 user.name, user.email", fixable=True)],
105
+ [CheckResult("git 身份", True, "张三 <zhangsan@test.com>", fixable=True)],
106
+ ])
107
+
108
+ def fake_checks():
109
+ return next(iter_values)
110
+
111
+ monkeypatch.setattr(doctor_module, "_collect_checks", fake_checks)
89
112
  monkeypatch.setattr(doctor_module.shutil, "which", lambda name: "/usr/bin/git")
90
113
  monkeypatch.setattr(doctor_module.subprocess, "run", fake_run)
91
114