fix(cli): preserve notes during sync moves
Build and Push Docker Container / build-and-push (push) Successful in 1m52s

- Leave sync and watch notes empty by default instead of writing placeholder text.
- Preserve existing remote notes when moving or adopting files without --note.
- Detect tracked local moves by SHA-256 and update remote metadata safely.
- Skip files that vanish during watch scans instead of aborting the sync cycle.
- Bump NanoShare to 1.24.0 and the standalone CLI to 0.3.0.
This commit is contained in:
2026-07-27 21:40:30 +02:00
parent 993337be9f
commit 2b0215cd94
9 changed files with 95 additions and 15 deletions
+43
View File
@@ -37,6 +37,8 @@ class FakeClient:
if item['file_id'] == params['file_id']:
item['file_name'] = params['file_name']
item['file_path'] = params.get('file_path', '')
if 'note' in params:
item['note'] = params['note']
return {'updated': True}
return {'updated': False}
if method == 'files.delete':
@@ -91,6 +93,47 @@ def test_sync_uploads_nested_local_files(tmp_path, monkeypatch):
state = json.loads((tmp_path / '.nanoshare-sync' / 'state.json').read_text())
assert state['files']['docs/notes/hello.txt']['file_id'] == 'file_1'
def test_sync_updates_remote_path_when_tracked_file_moves(tmp_path, monkeypatch):
fake = FakeClient()
fake.remote_files = [{'file_id': 'file_1', 'file_name': 'old.txt', 'file_path': '', 'file_size': '5 Bytes'}]
monkeypatch.setattr(cli, 'make_client', lambda args: fake)
state_dir = tmp_path / '.nanoshare-sync'
state_dir.mkdir()
(state_dir / 'state.json').write_text(json.dumps({
'version': 1,
'files': {
'old.txt': {
'file_id': 'file_1',
'sha256': '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824',
'local_mtime': 1,
'file_name': 'old.txt',
'file_path': '',
}
}
}))
nested = tmp_path / 'docs' / 'new.txt'
nested.parent.mkdir(parents=True)
nested.write_text('hello')
code = cli.main([
'sync',
'--url', 'picoshare=https://example.com',
'--token', 'token',
'--delete',
str(tmp_path),
])
assert code == 0
assert fake.uploads == []
assert fake.deleted == []
assert fake.remote_files[0]['file_name'] == 'new.txt'
assert fake.remote_files[0]['file_path'] == 'docs'
assert 'note' not in fake.remote_files[0]
state = json.loads((state_dir / 'state.json').read_text())
assert 'old.txt' not in state['files']
assert state['files']['docs/new.txt']['file_id'] == 'file_1'
def test_sync_adopts_and_moves_existing_remote_file(tmp_path, monkeypatch):
fake = FakeClient()
fake.remote_files = [{'file_id': 'file_1', 'file_name': 'hello.txt', 'file_path': '', 'file_size': '5 Bytes'}]