Files
capy-bearer/scripts/test_nested_component_props.sh
rootandClaude Fable 5.1 88be6723b2 Bind request implicitly in handlers and add capture parameters
Handlers take (props : dval, request : dval) for COMPONENT and TASK and
(request : dval) otherwise; every parameter is optional and keeps its name,
and request is bound in every handler body. name : capture type fills an
omitted argument from the caller variable of that name. Exported (dval) dval
functions carry an implicit request capture. Request builtins capture
request; redirect writes request.out. The runtime builds one request value
per request, passes request and props handles to handlers, applies
request.out once after the top-level handler, and drops the pending-props
slot, handler frames, per-handler refresh, and current_request(). Core ABI
38, unit ABI 39. Legacy request type checks and the removed-API migration
table are gone from the compiler. Documentation, generated routes, tests,
and the project home follow; the home page loses the demo and starter.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-13 14:05:04 +00:00

80 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
test_name="nested-component-props-test-$$"
site_directory="${BEARER_TEST_SITE_DIRECTORY:-site}"
if [[ -z "${BEARER_TEST_SITE_DIRECTORY:-}" && -r /etc/bearer/settings.cfg ]]; then
configured_site_directory=$(awk -F= '/^[[:space:]]*SITE_DIRECTORY[[:space:]]*=/ {gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2; exit}' /etc/bearer/settings.cfg)
if [[ -n "${configured_site_directory:-}" ]]; then
site_directory="$configured_site_directory"
fi
fi
source_dir="$site_directory/$test_name"
threshold_ms="${BEARER_NESTED_COMPONENT_PROPS_MAX_MS:-1500}"
bin_directory="${BIN_DIRECTORY:-}"
if [[ -z "$bin_directory" && -r /etc/bearer/settings.cfg ]]; then
bin_directory=$(awk -F= '/^[[:space:]]*BIN_DIRECTORY[[:space:]]*=/ {gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2; exit}' /etc/bearer/settings.cfg)
fi
bin_directory="${bin_directory:-/tmp/bearer/work}"
cache_dir=""
cleanup() {
rm -rf "$source_dir"
if [[ -n "$cache_dir" ]]; then
rm -rf "$cache_dir"
fi
}
trap cleanup EXIT
mkdir -p "$source_dir"
cache_dir="$(scripts/unit_cache_directory "$bin_directory")$(realpath "$source_dir")"
cat >"$source_dir/parent.capy" <<'EOF'
function CLI() {
var payload := "nested-props"
var props := {items: []}
for i := 0..300 { props.items = push(props.items, payload) }
var output := component("outer", props)
if length(props.items) != 300 { print("caller props changed"); return }
print(output)
}
EOF
cat >"$source_dir/outer.capy" <<'EOF'
function COMPONENT(props : dval) {
if length(props.items) != 300 { print("outer props missing"); return }
for i := 0..300 {
var leaf_props := {index: "value"}
component_render("leaf", leaf_props)
if length(props.items) != 300 { print("outer props changed"); return }
}
print("nested-component-props-ok")
}
EOF
cat >"$source_dir/leaf.capy" <<'EOF'
function COMPONENT(props : dval) {
if string(props.index) == "" { print("leaf props missing") }
}
EOF
warm_output=$(scripts/bearer-cli "/$test_name/parent.capy")
if [[ "$warm_output" != "nested-component-props-ok" ]]; then
echo "nested component props warmup failed: $warm_output" >&2
exit 1
fi
start_ns=$(date +%s%N)
output=$(scripts/bearer-cli "/$test_name/parent.capy")
elapsed_ms=$(( ($(date +%s%N) - start_ns) / 1000000 ))
if [[ "$output" != "nested-component-props-ok" ]]; then
echo "nested component props failed: $output" >&2
exit 1
fi
if (( elapsed_ms > threshold_ms )); then
echo "nested component props took ${elapsed_ms}ms (limit ${threshold_ms}ms)" >&2
exit 1
fi
echo "nested component props passed in ${elapsed_ms}ms"