For some reason after truncating verb_snapshots and then replaying events, states are not updating correctly when new events are applied.
Weirdly, snapshots ARE being updated correctly. Check out this code below...
How to reproduce the bug
<?php
use Thunk\Verbs\Event;
use Thunk\Verbs\State;
use Thunk\Verbs\Facades\Verbs;
use Illuminate\Support\Facades\DB;
use Thunk\Verbs\Attributes\Autodiscovery\StateId;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Thunk\Verbs\Models\VerbSnapshot;
class CountState extends State
{
public int $count = 0;
}
class CountUp extends Event
{
#[StateId(CountState::class)]
public int $count_id;
public function apply(CountState $count)
{
$count->count++;
}
}
uses(RefreshDatabase::class);
it('does something', function () {
$id = snowflake_id();
Verbs::commitImmediately();
$count = CountState::load($id);
CountUp::fire(count_id: $id);
expect($count->count)->toBe(1);
DB::table('verb_snapshots')->truncate();
Verbs::replay();
CountUp::fire(count_id: $id);
CountUp::fire(count_id: $id);
expect(VerbSnapshot::firstWhere('state_id', $id))
->data
->toBe(json_encode(['count' => 3]));
expect($count->count)->toBe(3);
});
Package Version
0.6.2
PHP Version
8.3
Laravel Version
11.x
Which operating systems does with happen with?
macOS
Notes
I dont have time to fully figure this out this moment but it has something to do with state rehydration from snapshots after a replay
What happened?
For some reason after truncating
verb_snapshots
and then replaying events, states are not updating correctly when new events are applied.Weirdly, snapshots ARE being updated correctly. Check out this code below...
How to reproduce the bug
Package Version
0.6.2
PHP Version
8.3
Laravel Version
11.x
Which operating systems does with happen with?
macOS
Notes
I dont have time to fully figure this out this moment but it has something to do with state rehydration from snapshots after a replay