fed-sx-m1: Step 8c-art — GET /artifacts/{cid} route reusing match_prefix + 9 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 29s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 29s
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
-export([route/1, ok_response/1, not_found_response/0,
|
||||
welcome_body/0, capabilities_body/0,
|
||||
capabilities_path/0,
|
||||
match_prefix/2, actors_prefix/0, actor_doc_response/1]).
|
||||
match_prefix/2, actors_prefix/0, actor_doc_response/1,
|
||||
artifacts_prefix/0, artifact_response/1]).
|
||||
|
||||
%% HTTP request router per design §16.1.
|
||||
%%
|
||||
@@ -35,16 +36,18 @@ dispatch(<<71, 69, 84>>,
|
||||
<<47,46,119,101,108,108,45,107,110,111,119,110,
|
||||
47,115,120,45,99,97,112,97,98,105,108,105,116,105,101,115>>) ->
|
||||
ok_response(capabilities_body());
|
||||
%% GET /actors/{id}
|
||||
%% GET /actors/{id} or /artifacts/{cid}
|
||||
dispatch(<<71, 69, 84>>, Path) ->
|
||||
case match_prefix(actors_prefix(), Path) of
|
||||
{ok, Id} ->
|
||||
case byte_size(Id) of
|
||||
0 -> not_found_response();
|
||||
_ -> actor_doc_response(Id)
|
||||
end;
|
||||
nomatch ->
|
||||
not_found_response()
|
||||
{ok, Id} when byte_size(Id) > 0 ->
|
||||
actor_doc_response(Id);
|
||||
_ ->
|
||||
case match_prefix(artifacts_prefix(), Path) of
|
||||
{ok, Cid} when byte_size(Cid) > 0 ->
|
||||
artifact_response(Cid);
|
||||
_ ->
|
||||
not_found_response()
|
||||
end
|
||||
end;
|
||||
dispatch(_, _) ->
|
||||
not_found_response().
|
||||
@@ -112,3 +115,16 @@ actor_doc_response(Id) ->
|
||||
Pre = <<97,99,116,111,114,58,32>>,
|
||||
Body = <<Pre/binary, Id/binary, 10>>,
|
||||
ok_response(Body).
|
||||
|
||||
%% "/artifacts/" — 11 bytes
|
||||
artifacts_prefix() ->
|
||||
<<47,97,114,116,105,102,97,99,116,115,47>>.
|
||||
|
||||
%% Artifact stub. Real implementation will fetch the bytes from
|
||||
%% the registry (or a CID-keyed store) and content-negotiate.
|
||||
%% v1 echoes the CID so route resolution can be tested.
|
||||
artifact_response(Cid) ->
|
||||
%% "artifact: " — 10 bytes
|
||||
Pre = <<97,114,116,105,102,97,99,116,58,32>>,
|
||||
Body = <<Pre/binary, Cid/binary, 10>>,
|
||||
ok_response(Body).
|
||||
|
||||
108
next/tests/http_artifacts.sh
Executable file
108
next/tests/http_artifacts.sh
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env bash
|
||||
# next/tests/http_artifacts.sh — Step 8c-art acceptance test.
|
||||
#
|
||||
# Exercises GET /artifacts/{cid} via the shared match_prefix
|
||||
# machinery. Mirrors the actors-route test shape. 9 cases.
|
||||
|
||||
set -uo pipefail
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
|
||||
SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}"
|
||||
if [ ! -x "$SX_SERVER" ]; then
|
||||
SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe"
|
||||
fi
|
||||
if [ ! -x "$SX_SERVER" ]; then
|
||||
echo "ERROR: sx_server.exe not found." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERBOSE="${1:-}"
|
||||
PASS=0; FAIL=0; ERRORS=""
|
||||
TMPFILE=$(mktemp); trap "rm -f $TMPFILE" EXIT
|
||||
|
||||
cat > "$TMPFILE" <<'EPOCHS'
|
||||
(epoch 1)
|
||||
(load "lib/erlang/tokenizer.sx")
|
||||
(load "lib/erlang/parser.sx")
|
||||
(load "lib/erlang/parser-core.sx")
|
||||
(load "lib/erlang/parser-expr.sx")
|
||||
(load "lib/erlang/parser-module.sx")
|
||||
(load "lib/erlang/transpile.sx")
|
||||
(load "lib/erlang/runtime.sx")
|
||||
(load "lib/erlang/vm/dispatcher.sx")
|
||||
|
||||
(epoch 2)
|
||||
(eval "(get (erlang-load-module (file-read \"next/kernel/http_server.erl\")) :name)")
|
||||
|
||||
;; artifacts_prefix is "/artifacts/" — 11 bytes
|
||||
(epoch 10)
|
||||
(eval "(erlang-eval-ast \"byte_size(http_server:artifacts_prefix())\")")
|
||||
|
||||
;; GET /artifacts/<cid> -> 200
|
||||
(epoch 11)
|
||||
(eval "(get (erlang-eval-ast \"Cid = <<98,97,102,107,114,101,49>>, Req = [{method, <<71,69,84>>}, {path, <<(http_server:artifacts_prefix())/binary, Cid/binary>>}], case http_server:route(Req) of [{status, 200} | _] -> ok; _ -> bad end\") :name)")
|
||||
|
||||
;; The cid is echoed in the body (carries 'artifact: ' prefix)
|
||||
(epoch 12)
|
||||
(eval "(get (erlang-eval-ast \"Cid = <<98,97,102,107,114,101,49>>, Req = [{method, <<71,69,84>>}, {path, <<(http_server:artifacts_prefix())/binary, Cid/binary>>}], R = http_server:route(Req), case R of [_, _, {body, B}] -> http_server:match_prefix(<<97,114,116,105,102,97,99,116,58,32>>, B) =/= nomatch; _ -> false end\") :name)")
|
||||
|
||||
;; GET /artifacts/ (empty cid) -> 404
|
||||
(epoch 13)
|
||||
(eval "(get (erlang-eval-ast \"Req = [{method, <<71,69,84>>}, {path, http_server:artifacts_prefix()}], case http_server:route(Req) of [{status, 404} | _] -> ok; _ -> bad end\") :name)")
|
||||
|
||||
;; POST /artifacts/<cid> -> 404 (only GET)
|
||||
(epoch 14)
|
||||
(eval "(get (erlang-eval-ast \"Cid = <<98,97,102>>, Req = [{method, <<80,79,83,84>>}, {path, <<(http_server:artifacts_prefix())/binary, Cid/binary>>}], case http_server:route(Req) of [{status, 404} | _] -> ok; _ -> bad end\") :name)")
|
||||
|
||||
;; Actor and artifact routes don't collide
|
||||
(epoch 15)
|
||||
(eval "(get (erlang-eval-ast \"R1 = http_server:route([{method, <<71,69,84>>}, {path, <<47,97,99,116,111,114,115,47,97>>}]), R2 = http_server:route([{method, <<71,69,84>>}, {path, <<(http_server:artifacts_prefix())/binary, 98>>}]), case {R1, R2} of {[{status, 200} | _], [{status, 200} | _]} -> ok; _ -> bad end\") :name)")
|
||||
|
||||
;; Existing routes (GET /, capabilities) still work
|
||||
(epoch 16)
|
||||
(eval "(get (erlang-eval-ast \"R1 = case http_server:route([{method, <<71,69,84>>}, {path, <<47>>}]) of [{status, 200} | _] -> ok; _ -> bad end, R2 = case http_server:route([{method, <<71,69,84>>}, {path, http_server:capabilities_path()}]) of [{status, 200} | _] -> ok; _ -> bad end, {R1, R2} =:= {ok, ok}\") :name)")
|
||||
|
||||
;; artifacts_prefix starts with '/'
|
||||
(epoch 17)
|
||||
(eval "(get (erlang-eval-ast \"case http_server:artifacts_prefix() of <<47, _/binary>> -> ok; _ -> bad end\") :name)")
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
|
||||
check() {
|
||||
local epoch="$1" desc="$2" expected="$3"
|
||||
local actual
|
||||
actual=$(echo "$OUTPUT" | awk -v e="$epoch" '
|
||||
$0 ~ "^\\(ok-len " e " " { getline; print; exit }
|
||||
$0 ~ "^\\(ok " e " " { print; exit }
|
||||
$0 ~ "^\\(error " e " " { print; exit }
|
||||
')
|
||||
[ -z "$actual" ] && actual="<no output for epoch $epoch>"
|
||||
if echo "$actual" | grep -qF -- "$expected"; then
|
||||
PASS=$((PASS+1))
|
||||
[ "$VERBOSE" = "-v" ] && echo " ok $desc"
|
||||
else
|
||||
FAIL=$((FAIL+1))
|
||||
ERRORS+=" FAIL [$desc] (epoch $epoch) expected: $expected | actual: $actual
|
||||
"
|
||||
fi
|
||||
}
|
||||
|
||||
check 2 "module load name" "http_server"
|
||||
check 10 "artifacts_prefix size = 11" "11"
|
||||
check 11 "GET /artifacts/<cid> -> 200" "ok"
|
||||
check 12 "body carries 'artifact: '" "true"
|
||||
check 13 "GET /artifacts/ (empty) -> 404" "ok"
|
||||
check 14 "POST /artifacts/<cid> -> 404" "ok"
|
||||
check 15 "actors + artifacts no collision" "ok"
|
||||
check 16 "static routes still 200" "true"
|
||||
check 17 "artifacts_prefix leading /" "ok"
|
||||
|
||||
TOTAL=$((PASS+FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL next/tests/http_artifacts.sh passed"
|
||||
else
|
||||
echo "FAIL $PASS/$TOTAL passed, $FAIL failed:"
|
||||
echo "$ERRORS"
|
||||
fi
|
||||
[ $FAIL -eq 0 ]
|
||||
Reference in New Issue
Block a user