fed-sx-m2: Step 5a — per-actor :actor_inbox log bucket + 14 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Adds the receiving-side log bucket every actor needs. add_actor/4
now opens a fresh in-memory log via log:open(ActorId, inbox_base_stub())
and stores it on the bucket as {actor_inbox, LogState} alongside
the outbox {log, _}. Two distinct base stubs ensure the in-memory
log module returns separate states even when the same ActorId is
the actor.
Pure-functional exports:
actor_inbox_state/2(ActorId, State) -> {ok, LogState} | {error, _}
actor_inbox_tip/2(ActorId, State) -> integer | nil
append_to_actor_inbox/3(ActorId, Activity, State)
-> {ok, NewTip, NewState} | {error, no_actor, State}
gen_server exports (mirror the outbox shape):
inbox_tip_for/1(ActorId) -> integer | nil
inbox_state_for/1(ActorId) -> {ok, LogState} | {error, _}
append_inbox/2(ActorId, Activity) -> {ok, NewTip} | {error, _}
handle_call dispatch added for all three.
Inbox and outbox tips are completely independent — appending to one
doesn't touch the other. This is the storage primitive 5b will
build the inbound validation pipeline on top of.
log:append/2 signature noted in code + progress log: it takes
(LogState, Activity) and returns {ok, NewState, Seq} — not
{ok, NewState} as I originally guessed.
next/tests/inbox_bucket.sh 14/14:
- fresh inbox tip = 0 (pure)
- actor_inbox_state {ok, _} (pure)
- append_to_actor_inbox/3 -> {ok, 1, _}
- tip advances after append
- unknown actor -> {error, no_actor, _}
- outbox + inbox tips fully independent
- two actors maintain independent inbox state
- gen_server inbox_tip_for/1 starts at 0
- gen_server append_inbox/2 -> {ok, 1}
- gen_server inbox != outbox tip
- gen_server unknown -> {error, no_actor}
- gen_server inbox_state_for {ok, _}
- two appends -> tip = 2
Conformance 761/761. 125/125 across 7 Step-5-adjacent suites
(inbox_bucket, nx_kernel_multi, nx_kernel_server, bootstrap_start,
http_publish, http_multi_actor, actor_lifecycle, smoke_app_pure).
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
actor_id/1, log_state/1, log_tip/1,
|
||||
key_spec/1, actor_state/1, projections/1, next_published/1,
|
||||
actor_log_state/2, actor_log_tip/2,
|
||||
actor_inbox_state/2, actor_inbox_tip/2,
|
||||
append_to_actor_inbox/3,
|
||||
actor_key_spec/2, actor_state/2, actor_projections/2,
|
||||
actor_next_published/2, actor_bucket/2,
|
||||
with_projections/2, with_actor_projections/3,
|
||||
@@ -18,6 +20,7 @@
|
||||
-export([start_link/3, publish/1, query/0, log_tip/0,
|
||||
with_projections/1, stop/0,
|
||||
add_actor/3, publish_to/2, log_tip_for/1, log_state_for/1,
|
||||
inbox_tip_for/1, inbox_state_for/1, append_inbox/2,
|
||||
actors/0, state_for/1, bucket_for/1,
|
||||
with_projections_for/2,
|
||||
bootstrap_actor/3]).
|
||||
@@ -61,9 +64,11 @@ add_actor(ActorId, KeySpec, AS, State) ->
|
||||
{error, already_present};
|
||||
false ->
|
||||
{ok, L0} = log:open(ActorId, base_stub()),
|
||||
{ok, I0} = log:open(ActorId, inbox_base_stub()),
|
||||
Bucket = [{key_spec, KeySpec},
|
||||
{actor_state, AS},
|
||||
{log, L0},
|
||||
{actor_inbox, I0},
|
||||
{projections, []},
|
||||
{next_published, 1}],
|
||||
Seq = field(next_actor_seq, State),
|
||||
@@ -183,6 +188,34 @@ actor_log_tip(ActorId, State) ->
|
||||
{error, _} -> nil
|
||||
end.
|
||||
|
||||
actor_inbox_state(ActorId, State) ->
|
||||
case actor_bucket(ActorId, State) of
|
||||
{ok, B} -> {ok, field(actor_inbox, B)};
|
||||
{error, _} -> {error, no_actor}
|
||||
end.
|
||||
|
||||
actor_inbox_tip(ActorId, State) ->
|
||||
case actor_inbox_state(ActorId, State) of
|
||||
{ok, I} -> log:tip(I);
|
||||
{error, _} -> nil
|
||||
end.
|
||||
|
||||
%% append_to_actor_inbox/3 — pure-functional inbox append. Mirrors
|
||||
%% publish/3's bucket-update shape; the activity is already signed
|
||||
%% + validated by the time it lands here (Step 5's pipeline handles
|
||||
%% sig verify + replay before this call).
|
||||
|
||||
append_to_actor_inbox(ActorId, Activity, State) ->
|
||||
case actor_bucket(ActorId, State) of
|
||||
{error, no_actor} ->
|
||||
{error, no_actor, State};
|
||||
{ok, Bucket} ->
|
||||
Inbox = field(actor_inbox, Bucket),
|
||||
{ok, NewInbox, _Seq} = log:append(Inbox, Activity),
|
||||
B1 = set(actor_inbox, NewInbox, Bucket),
|
||||
{ok, log:tip(NewInbox), set_bucket(ActorId, B1, State)}
|
||||
end.
|
||||
|
||||
actor_key_spec(ActorId, State) ->
|
||||
case actor_bucket(ActorId, State) of
|
||||
{ok, B} -> {ok, field(key_spec, B)};
|
||||
@@ -243,6 +276,13 @@ next_published(State) ->
|
||||
base_stub() ->
|
||||
<<98,97,115,101,95,115,116,117,98>>.
|
||||
|
||||
%% "inbox_base_stub" — distinct path stub so the in-memory log
|
||||
%% module's open/2 returns a fresh log state for the per-actor
|
||||
%% inbox bucket. Disk paths will namespace on this once Step 3b
|
||||
%% on-disk persistence is reactivated for inbox buckets.
|
||||
inbox_base_stub() ->
|
||||
<<105,110,98,111,120,95,115,116,117,98>>.
|
||||
|
||||
bucket_field(Key, State) ->
|
||||
case field(actors, State) of
|
||||
[] -> nil;
|
||||
@@ -324,6 +364,15 @@ log_tip_for(ActorId) ->
|
||||
log_state_for(ActorId) ->
|
||||
gen_server:call(nx_kernel, {log_state_for, ActorId}).
|
||||
|
||||
inbox_tip_for(ActorId) ->
|
||||
gen_server:call(nx_kernel, {inbox_tip_for, ActorId}).
|
||||
|
||||
inbox_state_for(ActorId) ->
|
||||
gen_server:call(nx_kernel, {inbox_state_for, ActorId}).
|
||||
|
||||
append_inbox(ActorId, Activity) ->
|
||||
gen_server:call(nx_kernel, {append_inbox, ActorId, Activity}).
|
||||
|
||||
actors() ->
|
||||
gen_server:call(nx_kernel, get_actors).
|
||||
|
||||
@@ -371,6 +420,15 @@ handle_call({log_tip_for, ActorId}, _From, State) ->
|
||||
{reply, actor_log_tip(ActorId, State), State};
|
||||
handle_call({log_state_for, ActorId}, _From, State) ->
|
||||
{reply, actor_log_state(ActorId, State), State};
|
||||
handle_call({inbox_tip_for, ActorId}, _From, State) ->
|
||||
{reply, actor_inbox_tip(ActorId, State), State};
|
||||
handle_call({inbox_state_for, ActorId}, _From, State) ->
|
||||
{reply, actor_inbox_state(ActorId, State), State};
|
||||
handle_call({append_inbox, ActorId, Activity}, _From, State) ->
|
||||
case append_to_actor_inbox(ActorId, Activity, State) of
|
||||
{ok, Tip, NewState} -> {reply, {ok, Tip}, NewState};
|
||||
{error, Reason, Same} -> {reply, {error, Reason}, Same}
|
||||
end;
|
||||
handle_call(get_actors, _From, State) ->
|
||||
{reply, actors(State), State};
|
||||
handle_call({state_for, ActorId}, _From, State) ->
|
||||
|
||||
Reference in New Issue
Block a user