Fix config init --interactive ValueError in questionary.checkbox #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概述
修復
codesage config init --interactive命令中的ValueError錯誤,該錯誤由於questionary.checkbox()的default參數接受了錯誤的數據類型導致。修復方案使用questionary.Choice對象的正確 API 來實現多選項預選功能。問題描述
錯誤訊息
執行以下命令時:
在完成語言選擇和排除模式輸入後,會出現以下錯誤:
影響範圍
codesage config init --interactive根本原因
1. API 誤用
questionary.checkbox()的default參數類型定義:但代碼中錯誤地傳遞了列表:
2. 正確的 API 用法
根據 questionary 文檔,若要預選多個選項,應使用
Choice對象:3. 與默認配置的一致性
默認配置文件
codesage/cli/templates/default_config.yaml中定義:修復方案確保交互式嚮導的預選值與默認配置保持一致。
解決方案
修改文件
文件:
codesage/cli/interactive.py變更詳情
1. 添加導入
在文件頂部添加
Choice的導入:2. 修復 snapshot_formats checkbox
修改
codesage/cli/interactive.py:22-26:變更說明
Choice對象代替default參數預期效果
修復前
結果: ❌ 失敗,無法完成配置
修復後
結果: ✅ 成功,配置文件已生成
關於 Markdown 格式的說明
實現狀態
在修復方案中,我們將
markdown設為預選格式,這與默認配置文件一致。然而,需要注意的是:Markdown 格式生成器已實現:
MarkdownGenerator類存在於codesage/snapshot/markdown_generator.pytests/integration/test_snapshot_pipeline.py:65)CLI 命令標記為未完成:
codesage/cli/commands/snapshot.py:149標記為 "not yet implemented"測試驗證通過:
test_full_pipeline測試成功驗證了 Markdown 生成器的功能建議
如果需要完全支持 CLI 層面的 Markdown 格式,建議在後續 PR 中完善以下內容:
snapshot.py中移除 "not yet implemented" 標記MarkdownGenerator到 CLI 命令中測試計劃
單元測試
現有的單元測試
test_interactive_wizard.py使用 mock 方式,不會受此修復影響:手動測試
預期測試結果
工作量評估
檢查清單
ValueError: Invalid 'default' value passed錯誤ChoiceAPI 預選多個選項已知限制
Markdown 格式的 CLI 支持狀態:
測試覆蓋率:
參考資料
PR 標籤:
bug,fix,questionary,interactive-wizard,api-usage審查者: 待指派
測試者: 待指派
創建時間: 2025-12-25
預計修復時間: ~20 分鐘
狀態: 待審閱
--
Linked issues / bugs
Fixes #1