fix(wiki): basic conflict detection in CompileReport
Add _detect_conflicts() using adversative keyword heuristic (but, however, in contrast, …) between chunks of different bibkeys; results populate CompileReport.conflicts and appear in wiki/log.md. Also add CompileReport.quarantined field (used by Fix 2). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -161,3 +161,67 @@ def test_wiki_check_index_and_log_ignored(
|
||||
assert result.exit_code == 0, (
|
||||
f"index.md / log.md should be excluded. exit={result.exit_code}, out={result.output}"
|
||||
)
|
||||
|
||||
|
||||
def test_wiki_check_exit_2_when_draft_not_empty(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""codex wiki check exits 2 when wiki/draft/ is non-empty (quarantined pages)."""
|
||||
wiki = tmp_path / "wiki"
|
||||
wiki.mkdir()
|
||||
draft = wiki / "draft"
|
||||
draft.mkdir()
|
||||
|
||||
(draft / "bad-concept.md").write_text(
|
||||
"# Bad Concept\n\n⚠ Ungrounded hallucination. [FakeBib2025 #chunk 0]\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from codex.config import Settings
|
||||
|
||||
mock_settings = MagicMock(spec=Settings)
|
||||
mock_settings.wiki_dir = str(wiki)
|
||||
monkeypatch.setattr("codex.cli.get_settings", lambda: mock_settings, raising=False)
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(app, ["wiki", "check", "--output-dir", str(wiki)])
|
||||
assert result.exit_code == 2, (
|
||||
f"Expected exit 2 (quarantined pages), got {result.exit_code}. Output: {result.output}"
|
||||
)
|
||||
|
||||
|
||||
def test_wiki_check_exit_2_takes_priority_over_exit_1(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Exit 2 (quarantined) takes priority over exit 1 (ungrounded in wiki/)."""
|
||||
wiki = tmp_path / "wiki"
|
||||
wiki.mkdir()
|
||||
draft = wiki / "draft"
|
||||
draft.mkdir()
|
||||
|
||||
# Main wiki with ungrounded claim
|
||||
(wiki / "concept-a.md").write_text(
|
||||
"# Concept A\n\n⚠ Ungrounded claim. [SomeBib #chunk 0]\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
# Draft with quarantined page
|
||||
(draft / "concept-b.md").write_text(
|
||||
"# Concept B\n\nQuarantined content.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from codex.config import Settings
|
||||
|
||||
mock_settings = MagicMock(spec=Settings)
|
||||
mock_settings.wiki_dir = str(wiki)
|
||||
monkeypatch.setattr("codex.cli.get_settings", lambda: mock_settings, raising=False)
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(app, ["wiki", "check", "--output-dir", str(wiki)])
|
||||
assert result.exit_code == 2
|
||||
|
||||
Reference in New Issue
Block a user