一句话:提出代码–测试协同翻译问题与CoTTrans框架,用测试一致性指标提升LLM程序迁移的准确性与稳定性。
程序迁移需将软件从一种语言翻译到另一种语言。现有LLM方法与基准多局限于简单片段,且假设目标语言测试已可用,难以应对真实程序。本文提出代码–测试协同翻译(CTCT)问题:程序与其测试套件应联合翻译以保持语义一致。实证研究发现测试一致性难度量且迭代修复易状态退化。为此提出CoTTrans,状态质量感知的翻译–修复框架,并设计测试用例一致性(TCC)指标,量化语法与语义一致性,结合测试通过率评估状态质量并回溯。BigCodeBench上,DeepSeek-V3正确性分数从0.360升至0.675,优于现有方法。
Program migration, which involves translating software systems from one programming language to another, is essential for modernizing legacy systems and improving maintainability. Recent large language models (LLMs) have demonstrated strong performance in code translation; however, existing methods and benchmarks still exhibit key limitations. (1) They primarily focus on simple, self-contained snippets that fail to capture the complexity of real-world programs, and (2) they often assume that target-language test cases are readily available for evaluation and feedback, an unrealistic assumption given the difficulty of manually creating equivalent tests across languages. In this paper, we argue for a more practical setting, termed the Code–Test Co-Translation (CTCT) problem, where both the program and its associated test suite should be jointly translated to preserve semantic and functional consistency. Through an empirical study on real-world programs, we identify two major challenges in CTCT: (1) the difficulty of measuring test-case consistency in the absence of ground truth, and (2) the ineffectiveness of existing iterative translation–repair strategies, which suffer from state degradation and poor initialization traps when handling complex, real-world features. To address these issues, we propose CoTTrans, a state-quality–aware iterative translation–repair framework guided by a novel Test Case Consistency (TCC) metric. TCC quantifies both syntactic and semantic consistency between source and translated tests, enabling fine-grained feedback that drives LLM-based refinement. CoTTrans further integrates TCC with test pass rates to assess state quality and triggers adaptive backtracking when low-quality states are detected during the translation. Evaluated on the BigCodeBench dataset, CoTTrans improves the translation correctness score from 0.360 to 0.675 on DeepSeek-V3, substantially outperforming existing methods, while TCC demonstrates superior effectiveness in measuring test consistency compared with existing metrics. These results show that CoTTrans enhances translation stability and accuracy, establishing a practical foundation for reliable code–test co-evolution in real-world program migration.
@article{paperbot12149,
title = {Code–Test Co-translation: Towards Practical and Effective Program Migration in the Wild},
author = {Xitao Li and Xiaofei Xie and Jiang Wu and Ting Liu and Haijun Wang},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {OOPSLA2},
year = {2026},
doi = {10.1145/3839490}
}