llmcodegen/issues/dependency-order-bug.issue

14 lines
1.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Bug 工单:严格按依赖顺序生成文件
name: 严格按依赖顺序生成文件
description: 当前代码生成器在生成文件时,虽然 `design.json` 中记录了文件间的依赖关系,但在实际生成过程中,可能没有严格按拓扑顺序生成,导致依赖文件尚未生成时,依赖它们的文件可能无法正确生成(例如,需要导入尚未生成的模块)。需要在生成前对文件列表进行拓扑排序,确保每个文件生成时其所有依赖都已存在。
steps_to_reproduce:
- 创建一个包含文件依赖的 `design.json`,例如文件列表顺序为 A.py、B.py、C.py但 A 依赖 BB 依赖 C。
- 运行 `llm-codegen init` 基于该 `design.json` 生成代码。
- 观察生成顺序,如果先生成 A.py则 A.py 中可能尝试导入 B 模块,但 B 尚未生成,导致生成失败或生成内容不完整。
expected_behavior: 生成器应自动根据依赖关系对文件列表进行拓扑排序,确保每个文件在其所有依赖之后生成。如果有循环依赖,应报错并终止。
actual_behavior: 当前可能按文件列表原始顺序生成,或仅部分考虑依赖,导致生成顺序错误,可能引发导入错误或代码不完整。
affected_files:
- src/llm_codegen/core.py # 需要修改生成主逻辑,调用排序函数
- src/llm_codegen/utils.py # 需要新增或修改依赖排序函数(例如 `topological_sort`
- tests/test_core.py # 需要添加测试用例验证排序逻辑