01a3746fce34
unwrap history.head with a test helper instead of ! on an option (3.0.52)
- time
- 2026-09-24 19:35 UTC · 2 weeks ago
- machine
- koh2
- agent
- claude-opus-5-5
- session
- pin V
- parent
- 81f91e956b53
↓ koh-01a3746f.tar.gzatlas at this save
files changed3 files
VERSION+1 −1src/sync/sync_test.v+21 −16v.mod+1 −1src/sync/sync_test.v+21 −16
@@ -96,16 +96,16 @@9696 mut backend := remote.new_folder(os.join_path(base, 'remote'))!9797 offer_now(a, mut backend)!9898 assert a.state('remote_repo') or { '' } == 'proj'99- assert backend.get(head_key('proj'))!.body.bytestr() == history.head(a)!.id99+ assert backend.get(head_key('proj'))!.body.bytestr() == head_of(a).id100100 // Offer's step 3: the new remote head is recorded in state.101- assert a.state('remote_head') or { '' } == history.head(a)!.id101+ assert a.state('remote_head') or { '' } == head_of(a).id102102 103103 // A second offer, with the remote already holding our head, must not104104 // refuse: the name is remembered, so the remote is ours.105105 put(a.root, 'a.txt', 'two\n')!106106 commit(a, 'second')!107107 offer_now(a, mut backend)!108- assert backend.get(head_key('proj'))!.body.bytestr() == history.head(a)!.id108+ assert backend.get(head_key('proj'))!.body.bytestr() == head_of(a).id109109 }110110 111111 fn test_steal_fast_forwards_a_machine_that_has_nothing_of_its_own() {@@ -134,7 +134,7 @@134134 b.commit()!135135 snapshot.restore_files(b, b.root, snapshot.load(b.root), history.files_of(b, fetched.head)!, [])!136136 assert os.read_file(os.join_path(b.root, 'a.txt'))! == 'from A\n'137- assert history.head(b)!.id == fetched.head137+ assert head_of(b).id == fetched.head138138 }139139 140140 // A machine that is only ahead has nothing to combine: stealing must leave its@@ -156,7 +156,7 @@156156 ahead := commit(a, 'not offered yet')!157157 report := steal_now(a, mut backend)!158158 assert report.replayed == 0159- assert history.head(a)!.id == ahead.id159+ assert head_of(a).id == ahead.id160160 // Nothing was restored, so nothing is left marked as half-restored.161161 assert !snapshot.restore_pending(a)162162 assert history.all_saves(a)!.len == 2@@ -190,14 +190,14 @@190190 put(a.root, 'docs/a.md', 'from A\n')!191191 commit(a, 'A adds docs')!192192 offer_now(a, mut backend)!193- head_before := history.head(b)!.id193+ head_before := head_of(b).id194194 if _ := steal_now(b, mut backend) {195195 assert false, 'a steal writing through a symlinked folder must refuse'196196 } else {197197 assert err.msg().contains('docs')198198 }199199 assert os.read_file(os.join_path(outside, 'a.md'))! == 'precious\n'200- assert history.head(b)!.id == head_before200+ assert head_of(b).id == head_before201201 }202202 203203 // A steal onto a half-restored tree would replay it as somebody's work.@@ -246,7 +246,7 @@246246 b.close()247247 }248248 join(b, mut backend)!249- assert history.head(b)!.id == child.id249+ assert head_of(b).id == child.id250250 }251251 252252 // A chmod is unsaved work too: a steal would restore the old mode over it.@@ -323,7 +323,7 @@323323 // And the remote now has B's work too.324324 offer_now(b, mut backend)!325325 line_head := backend.get(head_key('proj'))!.body.bytestr().trim_space()326- assert line_head == history.head(b)!.id326+ assert line_head == head_of(b).id327327 }328328 329329 // An agent that edits a file and then undoes the edit leaves no net change, so@@ -371,7 +371,7 @@371371 // "B tries" only touched files A changed, so it has nothing left to372372 // replay; the second save carries h.txt. Both originals stay in history.373373 assert report.replayed == 1374- assert history.head(b)!.replayed_from == undone.id374+ assert head_of(b).replayed_from == undone.id375375 ids := history.all_saves(b)!.map(it.id)376376 assert tried.id in ids && undone.id in ids377377 assert history.files_of(b, tried.id)!.any(it.path == 'f.txt')@@ -423,7 +423,7 @@423423 assert err.msg().contains('changed while')424424 }425425 // The agent's save is still head, and a second steal combines it too.426- assert history.head(b)!.message == 'agent saves during the question'426+ assert head_of(b).message == 'agent saves during the question'427427 report := steal(b, mut backend, StealOptions{428428 mine: true429429 })!@@ -465,8 +465,8 @@465465 } else {466466 assert err.msg().contains('--mine') || err.msg().contains('--theirs')467467 }468- assert find_clashes(history.files_of(b, history.head(b)!.id)!, history.files_of(b,469- history.head(b)!.id)!, history.files_of(b, history.head(b)!.id)!).len == 0468+ assert find_clashes(history.files_of(b, head_of(b).id)!, history.files_of(b, head_of(b).id)!, history.files_of(b,469+ head_of(b).id)!).len == 0470470 471471 // Choosing the remote's version ends with A's content.472472 report := steal_now(b, mut backend)!@@ -506,9 +506,9 @@506506 assert report.kept_mine == 1507507 assert os.read_file(os.join_path(b.root, 'same.txt'))! == 'B version\n'508508 // The final save says what it kept.509- assert history.head(b)!.message.contains('combine: kept mine for 1 file')509+ assert head_of(b).message.contains('combine: kept mine for 1 file')510510 // The pre-combine tree is still reachable in history.511- assert history.head(b)!.restores == ''511+ assert head_of(b).restores == ''512512 assert history.all_saves(b)!.len >= 4513513 }514514 @@ -687,7 +687,7 @@687687 mut healthy := remote.new_folder(remote_dir)!688688 report := offer(a, mut healthy)!689689 assert report.saves == 2690- assert healthy.get(head_key('proj'))!.body.bytestr().trim_space() == history.head(a)!.id690+ assert healthy.get(head_key('proj'))!.body.bytestr().trim_space() == head_of(a).id691691 assert healthy.list('proj/saves')!.len == 2692692 }693693 @@ -1228,4 +1228,9 @@12281228 report := steal_now(b, mut backend)!12291229 assert report.flagged.map(it.save_id) == [suspect.id]12301230 assert report.flagged[0].reason == 'broke the build'1231+}1232+1233+// head_of unwraps the head for tests that know the repo has saves.1234+fn head_of(store &storage.Store) history.Save {1235+ return history.head(store) or { panic('this repo has no head') }12311236 }v.mod+1 −1
@@ -1,6 +1,6 @@11 Module {22 name: 'koh3'3- version: '3.0.51'3+ version: '3.0.52'44 description: 'One SQLite file per repo, one line of history.'55 license: 'MIT'66 }