Package archive builder deletes existing file with unsupported suffix under --force

未关闭 适合新手
#57,727 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@akhil9tiet 已经在做这个了。

开始于 2026年10月28日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, rust
领域
cli, testing

调研方向

阅读 scripts/codex_package/archive.py,追踪 write_archive() 从归档格式验证到文件删除的执行过程;scripts/codex_package/cli.py 展示了公开调用方。在 scripts/codex_package/test_archive.py 中添加一个回归用例,使用一个已有的、扩展名不受支持的文件,并设置 force=True;当命令拒绝该扩展名并保留文件时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug
Summary

scripts/codex_package/archive.py::write_archive() deletes an existing --archive-output file when --force is supplied before validating the archive filename suffix. If the suffix is unsupported, the command fails with RuntimeError, but the pre-existing file has already been removed.

This is observable through the public package builder: scripts/codex_package/cli.py::archive_package() resolves each --archive-output and calls write_archive(..., force=args.force). The CLI accepts any path at argument parsing time.

Reproduction (isolated, no build required)

Using write_archive with an empty package directory and a pre-existing non-archive file:

from pathlib import Path
from tempfile import TemporaryDirectory
from codex_package.archive import write_archive

with TemporaryDirectory() as tmp:
    root = Path(tmp)
    package = root / "package"
    package.mkdir()
    output = root / "important.txt"
    output.write_text("keep this data")
    try:
        write_archive(package, output, force=True)
    except RuntimeError as exc:
        print(exc)  # Unsupported archive suffix ...
    assert output.read_text() == "keep this data"  # FAILS: FileNotFoundError

Set CODEX_REPO_ROOT to the repository root before importing the package, as required by codex_package.targets.

Expected

Reject unsupported archive suffixes without changing the existing output file.

Actual

write_archive runs archive_path.unlink() before archive_format_for_path(archive_path), so the original file is deleted even though no archive is written.

Evidence / verification

Reviewed scripts/codex_package/archive.py, scripts/codex_package/cli.py, scripts/codex_package/test_archive.py, and scripts/codex_package/test_cli.py at commit e742db9f7ba98e63e502b310857d49d047888518; rechecked the same order on the current default branch. An isolated local Python reproduction of the exact initial write_archive control flow confirmed the file disappears after the unsupported-suffix exception. Existing tests cover zstd resolution and version parsing, but not this failure case.

Suggested fix

Validate archive_format_for_path(archive_path) before any unlink/write side effects, and add a regression test asserting that a pre-existing file with an unsupported suffix is preserved when force=True.

No pull request has been submitted.

主要语言
Rust
星标
131k
派生
20.7k
平均合并
1 分钟
30 天内合并 PR
997

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/codex 的其他 Issue

查看 openai/codex 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。