test(#4085): preserve checker dirty-state compatibility
This commit is contained in:
1 parent
a261e46e7e
commit
5f8fd9d85a
2 files changed
+34
-3
No files matched your search
+9
-3
@@ -1280,12 +1280,14 @@ def _check_repo(path, name, channel=DEFAULT_UPDATE_CHANNEL):
|
||||
return None
|
||||
|
||||
|
||||
def _probe_dirty(path: Path, timeout: int = 1) -> bool | None:
|
||||
def _probe_dirty(
|
||||
path: Path, timeout: int = 1, *, legacy_empty_is_dirty: bool = False,
|
||||
) -> bool | None:
|
||||
"""Return dirty, clean, or unknown for a working-tree probe."""
|
||||
out, ok = _run_git(['diff-index', '--quiet', 'HEAD', '--'], path, timeout=timeout)
|
||||
if ok:
|
||||
return False
|
||||
if out == 'git exited with status 1':
|
||||
if out == 'git exited with status 1' or (legacy_empty_is_dirty and not out):
|
||||
return True
|
||||
logger.warning(
|
||||
'git dirty probe failed; treating working-tree state as unknown: %s',
|
||||
@@ -1303,7 +1305,11 @@ def _is_dirty(path: Path, timeout: int = 1) -> bool:
|
||||
reported as clean so a transient probe failure never produces a false-
|
||||
positive "local changes" alert.
|
||||
"""
|
||||
return _probe_dirty(path, timeout=timeout) is True
|
||||
# Older checker consumers model diff-index status 1 as ('', False). Keep
|
||||
# that boolean contract here; force updates use the strict tri-state form.
|
||||
return _probe_dirty(
|
||||
path, timeout=timeout, legacy_empty_is_dirty=True,
|
||||
) is True
|
||||
|
||||
|
||||
def _ignored_agent_update_info() -> dict:
|
||||
|
||||
@@ -88,6 +88,31 @@ def test_check_repo_reports_release_gap_even_when_tag_fetch_fails(tmp_path):
|
||||
assert info['dirty'] is False
|
||||
|
||||
|
||||
def test_is_dirty_preserves_legacy_empty_failure_contract(tmp_path, monkeypatch):
|
||||
(tmp_path / '.git').mkdir()
|
||||
monkeypatch.setattr(updates, '_run_git', lambda *args, **kwargs: ('', False))
|
||||
|
||||
assert updates._is_dirty(tmp_path) is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'probe_output',
|
||||
[
|
||||
'git exited with status 2',
|
||||
'git exited with status 128',
|
||||
'git exited with status -9',
|
||||
'fatal: unable to read index',
|
||||
],
|
||||
)
|
||||
def test_probe_dirty_keeps_non_status_one_failures_unknown(tmp_path, monkeypatch, probe_output):
|
||||
(tmp_path / '.git').mkdir()
|
||||
monkeypatch.setattr(
|
||||
updates, '_run_git', lambda *args, **kwargs: (probe_output, False),
|
||||
)
|
||||
|
||||
assert updates._probe_dirty(tmp_path) is None
|
||||
|
||||
|
||||
def test_check_repo_redacts_credentialed_fetch_failure(tmp_path):
|
||||
"""Update-check errors must not expose credentials from git remotes."""
|
||||
(tmp_path / '.git').mkdir()
|
||||
|
||||
Reference in new issue
Block a user