fix: ensure codex fallback uses stdin
This commit is contained in:
parent
d6a88e483b
commit
01ead5754f
|
|
@ -16,6 +16,7 @@ from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import shlex
|
||||||
|
|
||||||
from automation.ai_config import (
|
from automation.ai_config import (
|
||||||
DEFAULT_COMMAND_CHAIN,
|
DEFAULT_COMMAND_CHAIN,
|
||||||
|
|
@ -674,18 +675,27 @@ def _run_codex_command(command: str, prompt: str, cwd: Path) -> tuple[str, str,
|
||||||
|
|
||||||
|
|
||||||
def _ensure_codex_json(command: str) -> str:
|
def _ensure_codex_json(command: str) -> str:
|
||||||
"""Ensure codex command runs via `codex exec --json --color=never` for machine parsing."""
|
"""Ensure codex command runs via `codex exec --json --color=never -` for machine parsing."""
|
||||||
parts = command.strip().split()
|
tokens = shlex.split(command)
|
||||||
if len(parts) >= 2 and parts[1] == "exec":
|
if not tokens:
|
||||||
base = command
|
return command
|
||||||
else:
|
|
||||||
base = command.replace("codex", "codex exec", 1)
|
|
||||||
|
|
||||||
if "--json" not in base:
|
if tokens[0] != "codex":
|
||||||
base = f"{base} --json"
|
return command
|
||||||
if "--color" not in base:
|
|
||||||
base = f"{base} --color=never"
|
if len(tokens) == 1 or tokens[1] != "exec":
|
||||||
return base
|
tokens.insert(1, "exec")
|
||||||
|
|
||||||
|
if "--json" not in tokens:
|
||||||
|
tokens.append("--json")
|
||||||
|
|
||||||
|
if not any(t.startswith("--color") for t in tokens):
|
||||||
|
tokens.append("--color=never")
|
||||||
|
|
||||||
|
if "-" not in tokens:
|
||||||
|
tokens.append("-")
|
||||||
|
|
||||||
|
return shlex.join(tokens)
|
||||||
|
|
||||||
|
|
||||||
def _extract_codex_last_message(stdout_text: str) -> str:
|
def _extract_codex_last_message(stdout_text: str) -> str:
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,12 @@ import pytest
|
||||||
|
|
||||||
from automation.config import RulesConfig
|
from automation.config import RulesConfig
|
||||||
from automation.ai_config import DEFAULT_SENTINEL
|
from automation.ai_config import DEFAULT_SENTINEL
|
||||||
from automation.patcher import ModelConfig, PatchGenerationError, generate_output
|
from automation.patcher import (
|
||||||
|
ModelConfig,
|
||||||
|
PatchGenerationError,
|
||||||
|
generate_output,
|
||||||
|
_ensure_codex_json,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
@ -59,11 +64,12 @@ diff --git a/Docs/features/FR_1/discussions/example.discussion.sum.md b/Docs/fea
|
||||||
assert output_file.exists()
|
assert output_file.exists()
|
||||||
assert output_file.read_text(encoding="utf-8") == "Line one\nLine two\n"
|
assert output_file.read_text(encoding="utf-8") == "Line one\nLine two\n"
|
||||||
|
|
||||||
staged = subprocess.run(
|
|
||||||
["git", "diff", "--cached", "--name-only"],
|
def test_ensure_codex_json_adds_exec_and_stdin() -> None:
|
||||||
cwd=temp_repo,
|
cmd = "codex --model gpt-5"
|
||||||
check=True,
|
rewritten = _ensure_codex_json(cmd)
|
||||||
capture_output=True,
|
# Should include exec, --json, --color=never, and '-' for stdin
|
||||||
text=True,
|
assert "codex exec" in rewritten
|
||||||
).stdout.split()
|
assert "--json" in rewritten
|
||||||
assert "Docs/features/FR_1/discussions/example.discussion.sum.md" in staged
|
assert "--color=never" in rewritten
|
||||||
|
assert rewritten.rstrip().endswith(" -") or " - " in rewritten
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue