diff --git a/README.md b/README.md index 962853b70..be7d90df3 100644 --- a/README.md +++ b/README.md @@ -1038,7 +1038,7 @@ prove what a function does, not what its author called it. and the export rebuilds the game byte for byte from matched C plus assembly for what isn't matched yet. A game at 100%, polished, is the goal, and the first one will be announced here. -**How do I save and commit progress?** In **Settings → Save your progress**, choose your project folder and click **Save now**. Select the repository root if you have a decompdecomp build checkout: the app detects it and saves into its `progress/` subfolder, preserving build files. Then enable **Automatically commit new matches**. If needed, the app creates the progress repository and prepares its initial checkpoint before enabling the setting. Only saved-progress files are committed; unrelated source edits stay local. Commits remain local unless automatic pushing is enabled. For a detected build repository, **Update build files → Verify, commit and push** separately integrates matching C into the standalone tree and requires a byte-identical full rebuild. This is useful for build-based progress trackers such as ByteMatch. Saving progress alone does not update standalone source selections. +**How do I save and commit progress?** In **Settings → Save your progress**, choose your project folder and click **Save now**. Select the repository root if you have a decompdecomp build checkout: the app detects it and saves into its `progress/` subfolder, preserving build files. Then enable **Automatically commit new matches**. If needed, the app creates the progress repository and prepares its initial checkpoint before enabling the setting. Older copied saves refresh automatically when their only changes are appended notes and improved drafts proven by the project’s compiled attempt history; unknown source edits or changed headers/settings remain protected for review. Only saved-progress files are committed; unrelated source edits stay local. Commits remain local unless automatic pushing is enabled. For a detected build repository, **Update build files → Verify, commit and push** separately integrates matching C into the standalone tree and requires a byte-identical full rebuild. This is useful for build-based progress trackers such as ByteMatch. Saving progress alone does not update standalone source selections. **What do I end up with?** The source code of a game you own, that builds it again. A DS game started from scratch reached 2,400 matched functions (58% of its code) in under two days, about half of them matched by free models, and diff --git a/src/decompnet/app/repository_setup.py b/src/decompnet/app/repository_setup.py index e40ed6750..da70b157c 100644 --- a/src/decompnet/app/repository_setup.py +++ b/src/decompnet/app/repository_setup.py @@ -48,6 +48,54 @@ def status(net, slug): 'build_folder': str(build or '')} + +def known_older_save(net, proj, saved, latest): + """Prove an unreceipted backup contains older app attempts, not contributor edits. + + Settings, headers and matched C must agree. Only appended notes and improved + drafts already present in compiled attempt history may supersede this save. + """ + from .function_names import canonical_source + + old = json.loads(saved[saves.MANIFEST]) + new = json.loads(latest[saves.MANIFEST]) + old_functions = old.pop('functions', {}) + new_functions = new.pop('functions', {}) + old_notes = old.pop('notes', []) + new_notes = new.pop('notes', []) + if not isinstance(old_notes, list) or new_notes[:len(old_notes)] != old_notes: + return False + if old != new or old_functions.keys() != new_functions.keys(): + return False + changed = {name for name in saved.keys() | latest.keys() + if name != saves.MANIFEST and saved.get(name) != latest.get(name)} + store = net.project_store(proj['id']) + for name, info in old_functions.items(): + current = new_functions[name] + relative = 'best/' + name + '.c' + if info == current and relative not in changed: + continue + if ({k:v for k,v in info.items() if k not in ('best_score', 'best_by')} + != {k:v for k,v in current.items() if k not in ('best_score', 'best_by')} + or 'matched_by' in info or 'matched_by' in current + or not isinstance(info.get('best_score'), (int, float)) + or not isinstance(current.get('best_score'), (int, float)) + or current['best_score'] >= info['best_score'] + or relative not in saved or relative not in latest): + return False + row = store.one('SELECT id,name,vram,meta FROM functions WHERE project_id=? AND name=?', proj['id'], name) + if row is None: + return False + attempts = store.all('SELECT source FROM attempts WHERE function_id=? AND compiled=1 AND score=?', + row['id'], info['best_score']) + if not any(attempt['source'] is not None and + saves._source_text(canonical_source(row, attempt['source'])) == saved[relative] + for attempt in attempts): + return False + changed.discard(relative) + return not changed + + def bind(net, slug, path, proj, log=lambda line:None): """Refresh an untouched app backup, preserving external edits before adoption.""" if path == saves.default_folder(net, slug).resolve(): @@ -74,7 +122,7 @@ def comparable(files): saved, latest = comparable(previous), comparable(current) if saved != latest: differences = sorted(name for name in saved.keys() | latest.keys() if saved.get(name) != latest.get(name)) - if not untouched: + if not untouched and not known_older_save(net, proj, saved, latest): detail = ', '.join(differences[:20]) if len(differences) > 20:detail += f' (and {len(differences)-20} more)' raise NetworkError('This save differs from current progress and has external edits or no app save receipt. ' diff --git a/tests/test_repository_setup.py b/tests/test_repository_setup.py index 0e0a50021..dbf4de8c5 100644 --- a/tests/test_repository_setup.py +++ b/tests/test_repository_setup.py @@ -326,3 +326,36 @@ def concurrent(path,*args,**kwargs): repository_setup.run(net,'game','checkpoint','',lambda line:None) assert (target/'include/common.h').read_text()=='concurrent edit' assert saves.default_folder(net,'game')==folder + + +@pytest.mark.parametrize('external', [False, True, 'uncompiled']) +def test_unreceipted_old_attempt_refreshes_but_unknown_edits_survive(project, tmp_path, external): + net, folder, _ = project + agent, _ = net.local_agent('helper') + with net.store.tx() as db: + fid = db.execute("SELECT id FROM functions WHERE name='f'").fetchone()['id'] + db.execute("UPDATE functions SET best_source='old draft',best_score=30 WHERE id=?", (fid,)) + db.execute("INSERT INTO attempts(function_id,agent_id,score,compiled,context_version,source,created_at) " + "VALUES(?,?,30,1,1,'old draft',1)", (fid, agent.id)) + if external == 'uncompiled':db.execute('UPDATE attempts SET compiled=0 WHERE function_id=?', (fid,)) + net.progress.sync('game', force=True) + target = tmp_path/'backup' + # Reproduce a Git/manual copy, which has no app Save now receipt. + shutil.copytree(folder, target) + net._update_cfg('game', lambda cfg: cfg.update(save_folder=str(target))) + git(target, 'init', '--initial-branch=main') + git(target, 'config', 'user.name', 'Test') + git(target, 'config', 'user.email', 'test@example.invalid') + with net.store.tx() as db: + db.execute("UPDATE functions SET best_source='new draft',best_score=10 WHERE id=?", (fid,)) + if external: + if external is True:(target/'best/f.c').write_text('unknown contributor draft\n') + with pytest.raises(NetworkError, match='Files that differ'): + repository_setup.run(net, 'game', 'checkpoint', '', lambda line:None) + assert (target/'best/f.c').read_text() == ('unknown contributor draft\n' if external is True else 'old draft\n') + assert saves.default_folder(net, 'game') == folder + else: + state = repository_setup.run(net, 'game', 'checkpoint', '', lambda line:None) + assert state['checkpoint'] and state['linked'] + assert git(target, 'show', 'HEAD:best/f.c') == 'new draft' + assert match_commits.configure(net, 'game', True, str(target))['enabled']