Legacy backup recovery overwrites newer source and deletes the backup without conflict detection

Aperta
#34 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
testing-qa

Direzione di ricerca

Start with restore_backups in src/mutator/engine.py (around lines 17-31), which writes and unlinks files under target/mutator-backup. Run the reproduction probe from the issue to see the overwrite and deletion. The call site is in src/mutator/cli.py (around lines 486-488), and tests/test_engine.py has the existing backup test. Done means newer source survives, both versions are kept, a conflict is reported, and a separate test covers a verified interrupted mutant.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

restore_backups treats every target/mutator-backup file as authoritative. A stale backup overwrites legitimate newer source without comparison or confirmation, then the backup is deleted. Non-scan CLI runs invoke this recovery automatically when source files are selected.

Verified on main at 830ec7e9c39664d753f8699015bc796df67727b9 with Python 3.14.8. No package installation is required for this reproduction.

Minimal reproduction

Run with Python 3.11+ and Git. This uses only disposable fixture files and does not install or invoke the mutator launcher.

work=$(mktemp -d)
git clone https://github.com/unclebob/mutator.git "$work/mutator"
cd "$work/mutator"
git checkout 830ec7e9c39664d753f8699015bc796df67727b9
python3 -B - <<'PY'
"""Run from a mutator checkout using Python 3.11+; standard library only."""
import ast
import tempfile
from pathlib import Path

path = Path('src/mutator/engine.py')
tree = ast.parse(path.read_text())
module = ast.parse('from __future__ import annotations')
module.body += [n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == 'restore_backups']
g = {'Path': Path}
exec(compile(module, str(path), 'exec'), g)
with tempfile.TemporaryDirectory() as directory:
    root = Path(directory)
    source = root / 'calc.py'
    backup = root / 'target' / 'mutator-backup' / 'calc.py'
    backup.parent.mkdir(parents=True)
    backup.write_bytes(b'def answer():\n    return 1\n')
    # New legitimate code, not an in-place mutant left by an interrupted run.
    source.write_bytes(b'def answer():\n    return 42\n\ndef added():\n    return 7\n')
    newer = source.read_bytes()
    restored = g['restore_backups'](root)
    assert restored == [source]
    assert source.read_bytes() != newer
    assert source.read_bytes() == b'def answer():\n    return 1\n'
    assert not backup.exists()
    print('newer source overwritten with stale backup; backup deleted; no conflict reported')
PY

This standard-library probe executes the actual restore_backups function extracted with ast. All files are disposable fixtures inside TemporaryDirectory. It calls the recovery function directly rather than launching the CLI.

Observed output

newer source overwritten with stale backup; backup deleted; no conflict reported

Expected behavior

Do not overwrite legitimate newer source automatically. Preserve both versions on an ambiguous recovery and report a conflict, or require an explicit recovery decision backed by enough state to identify the interrupted mutant.

Actual behavior

A source file with a newer function and an added function is replaced with the stale backup; the added function disappears. The backup is unlinked and no conflict is reported.

Regression test

Place stale original bytes in target/mutator-backup and legitimate newer code at the corresponding source path. Invoke recovery and assert the newer source survives, both versions remain available, and the conflict is reported. Retain a separate test for an explicitly verified interrupted mutant.

The reproduction asserts the currently observed defect. A regression test should invert the defective-behavior assertions to enforce the expected behavior.

Source

Related #20 concerns final cleanup after current worker execution. This defect occurs before mutation execution in legacy restore_backups, so removing _restore_if_dirty does not fix it. No genuine duplicate found.

Lingua principale
Python
Stelle
112
Fork
53
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di unclebob/mutator

Tutte le issue di unclebob/mutator

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.