Repository navigation
fix(change-quality): read Git paths without quoting or newline splitting #8364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gcl-coder
wants to merge
2
commits into
loopx-project:main
Choose a base branch
from
gcl-coder:fix/change-quality-scope-paths
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−25
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from loopx.capabilities.change_quality.result import ( | ||
| _validate_evidence_targets, | ||
| _normalize_evidence_ref, | ||
| _normalize_validation, | ||
| _relative_path, | ||
| ) | ||
| from loopx.capabilities.change_quality.scope import build_change_quality_scope | ||
|
|
||
|
|
||
| def _repository(tmp_path: Path) -> Path: | ||
| repo = tmp_path / "repo" | ||
| repo.mkdir() | ||
| subprocess.run(["git", "init", "-q", "-b", "main", str(repo)], check=True) | ||
| subprocess.run( | ||
| ["git", "-C", str(repo), "config", "user.email", "fixture@example.invalid"], | ||
| check=True, | ||
| ) | ||
| subprocess.run( | ||
| ["git", "-C", str(repo), "config", "user.name", "Fixture"], check=True | ||
| ) | ||
| (repo / "base.txt").write_text("base\n", encoding="utf-8") | ||
| subprocess.run(["git", "-C", str(repo), "add", "base.txt"], check=True) | ||
| subprocess.run(["git", "-C", str(repo), "commit", "-qm", "base"], check=True) | ||
| return repo | ||
|
|
||
|
|
||
| def _scope(repo: Path) -> dict: | ||
| return build_change_quality_scope(repo_path=repo, base_ref="HEAD") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("name", ["中文文件.txt", "café.txt", "ファイル.txt"]) | ||
| def test_untracked_names_outside_ascii_keep_their_exact_spelling( | ||
| tmp_path: Path, name: str | ||
| ) -> None: | ||
| """Git quotes non-ASCII names by default; the scope must still open them.""" | ||
|
|
||
| repo = _repository(tmp_path) | ||
| (repo / name).write_text("content\n", encoding="utf-8") | ||
|
|
||
| first = _scope(repo) | ||
| assert first["changed_files"] == [name] | ||
| assert first["sources"]["untracked"] == [name] | ||
|
|
||
| second = _scope(repo) | ||
| assert second["scope_fingerprint"] == first["scope_fingerprint"] | ||
|
|
||
|
|
||
| def test_untracked_names_keep_surrounding_spaces(tmp_path: Path) -> None: | ||
| repo = _repository(tmp_path) | ||
| name = " padded file .txt" | ||
| (repo / name).write_text("content\n", encoding="utf-8") | ||
|
|
||
| scope = _scope(repo) | ||
| assert scope["changed_files"] == [name] | ||
|
|
||
|
|
||
| @pytest.mark.skipif(os.name != "posix", reason="a newline in a path is POSIX-only") | ||
| def test_untracked_names_with_a_newline_stay_one_entry(tmp_path: Path) -> None: | ||
| repo = _repository(tmp_path) | ||
| name = "line\nbreak.txt" | ||
| (repo / name).write_text("content\n", encoding="utf-8") | ||
|
|
||
| scope = _scope(repo) | ||
| assert scope["changed_files"] == [name] | ||
| assert scope["changed_file_count"] == 1 | ||
|
|
||
|
|
||
| def test_changing_one_byte_of_an_untracked_file_changes_the_fingerprint( | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| repo = _repository(tmp_path) | ||
| name = "中文文件.txt" | ||
| (repo / name).write_text("content\n", encoding="utf-8") | ||
| before = _scope(repo)["scope_fingerprint"] | ||
|
|
||
| (repo / name).write_text("contenu\n", encoding="utf-8") | ||
| after = _scope(repo)["scope_fingerprint"] | ||
|
|
||
| assert after != before | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "name", | ||
| [" padded.py ", "line\nbreak.txt", "back\\slash.py", "café.txt"], | ||
| ) | ||
| def test_record_evidence_keeps_the_exact_scope_path(name: str) -> None: | ||
| """Evidence must name the file the scope reported, not a normalized copy.""" | ||
|
|
||
| ref = _normalize_evidence_ref(f"path:{name}", field="evidence_refs[]") | ||
| assert ref == f"path:{name}" | ||
| assert _relative_path(name, field="risk.path") == name | ||
|
|
||
| evidence = _normalize_validation( | ||
| { | ||
| "validator": "pytest", | ||
| "status": "passed", | ||
| "scope": "unit", | ||
| "covers_paths": [name], | ||
| }, | ||
| index=0, | ||
| ) | ||
| assert evidence["covers_paths"] == [name] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("target", ["/abs/file.txt", "../outside.py", "a/../../b"]) | ||
| def test_record_evidence_still_rejects_escapes(target: str) -> None: | ||
| with pytest.raises(ValueError, match="repo-relative"): | ||
| _normalize_evidence_ref(f"path:{target}", field="evidence_refs[]") | ||
|
|
||
|
|
||
| @pytest.mark.skipif(os.name != "posix", reason="special names are POSIX-only") | ||
| def test_scope_names_match_the_path_evidence_they_are_recorded_with( | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| """The names the scope reports must be the names evidence resolves against.""" | ||
|
|
||
| repo = _repository(tmp_path) | ||
| names = [" padded.py ", "line\nbreak.txt", "back\\slash.py", "café.txt"] | ||
| for name in names: | ||
| (repo / name).write_text("content\n", encoding="utf-8") | ||
|
|
||
| changed = set(_scope(repo)["changed_files"]) | ||
| assert changed == set(names) | ||
|
|
||
| for name in names: | ||
| ref = _normalize_evidence_ref(f"path:{name}", field="evidence_refs[]") | ||
| _validate_evidence_targets( | ||
| [ref], | ||
| field="evidence_refs", | ||
| changed_files=changed, | ||
| instruction_refs=set(), | ||
| validator_ids=set(), | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] 这里现在保留了合法名字,但 downstream record 的 _normalize_evidence_ref/_relative_path 仍 strip/collapse whitespace 并把 backslash 改成 slash。真实 prepare→record:带前后空格、内含换行和 literal POSIX backslash 的文件均 prepare 成功,提交 scope 报告的原路径后却分别被改成 path:padded.py、path:new line.py、path:back/slash.py,报 unknown evidence;普通 Unicode 路径则全旅程成功。请让 evidence、risk.path、covers_paths 保留同一精确 repo-relative 路径,并同时保留绝对/.. 越界拒绝。validator-only 引用的可能绕过不等于文件证据已可用。