fed-sx-m1: Step 8c-post-publish-http — POST /activity wires through nx_kernel:publish + 10 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s

This commit is contained in:
2026-05-28 12:12:30 +00:00
parent ccceb4a0b3
commit 05100ef050
3 changed files with 175 additions and 3 deletions

View File

@@ -7,7 +7,9 @@
projections_list_path/0, projections_prefix/0,
projections_list_response/0, projection_response/1,
activity_path/0, unauthorized_response/0,
post_activity_response/0]).
post_activity_response/0,
validation_failed_response/0,
cid_response/1]).
%% HTTP request router per design §16.1.
%%
@@ -199,11 +201,46 @@ post_activity_response() ->
handle_post_activity(Req, Cfg) ->
case check_bearer(Req, Cfg) of
ok ->
post_activity_response();
publish_if_kernel(Req);
{error, _} ->
unauthorized_response()
end.
%% publish_if_kernel/1 — if the nx_kernel gen_server is registered,
%% delegate the publish there and translate the result. Otherwise
%% keep the stub response so the auth-only tests stay green without
%% having to spin up a kernel process.
publish_if_kernel(Req) ->
case erlang:whereis(nx_kernel) of
undefined ->
post_activity_response();
_Pid ->
Body = field(body, Req),
Request = [{type, create}, {object, Body}],
case nx_kernel:publish(Request) of
{ok, Result} ->
case envelope:get_field(cid, Result) of
{ok, Cid} -> cid_response(Cid);
_ -> post_activity_response()
end;
{error, _} ->
validation_failed_response()
end
end.
%% 200 OK with body "cid: <cid>\n" (5 prefix bytes + cid + newline)
cid_response(Cid) ->
%% "cid: " — 99 105 100 58 32
Pre = <<99,105,100,58,32>>,
Body = <<Pre/binary, Cid/binary, 10>>,
ok_response(Body).
%% 422 Unprocessable Entity. Body "validation failed\n" — 18 bytes.
validation_failed_response() ->
[{status, 422}, {headers, []},
{body, <<118,97,108,105,100,97,116,105,111,110,32,
102,97,105,108,101,100,10>>}].
check_bearer(Req, Cfg) ->
case bearer_token(Req) of
{ok, Got} ->