Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions scripts/build-backend-env
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,78 @@ meerkat_selected_build_backend() {
printf 'cargo\n'
fi
}

meerkat_discover_local_secrets_env() {
local root dir parent
root="${1:-}"
if [[ -z "${root}" ]]; then
root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
fi

if [[ -n "${MEERKAT_SECRETS_ENV:-}" ]]; then
if [[ -f "${MEERKAT_SECRETS_ENV}" ]]; then
printf '%s\n' "${MEERKAT_SECRETS_ENV}"
else
echo "warning: MEERKAT_SECRETS_ENV points to a missing file: ${MEERKAT_SECRETS_ENV}" >&2
fi
return 0
fi

dir="${root}"
while [[ -n "${dir}" && "${dir}" != "/" ]]; do
if [[ -f "${dir}/secrets.env" ]]; then
printf '%s\n' "${dir}/secrets.env"
return 0
fi
if [[ -n "${HOME:-}" && "${dir}" == "${HOME}" ]]; then
return 0
fi
parent="$(dirname "${dir}")"
if [[ "${parent}" == "${dir}" ]]; then
return 0
fi
dir="${parent}"
done
}

meerkat_secret_env_key_allowed() {
case "$1" in
ANTHROPIC_*|OPENAI_*|GEMINI_*|GOOGLE_*|RKAT_*|SMOKE_*|CLAUDE_CODE_OAUTH_TOKEN|BUILDBUDDY_API_KEY)
return 0
;;
*)
return 1
;;
esac
}

meerkat_load_local_secrets_env() {
local root secrets_env loaded_env line key value
root="${1:-}"
secrets_env="$(meerkat_discover_local_secrets_env "${root}")"
if [[ -z "${secrets_env}" ]]; then
return 0
fi

if ! loaded_env="$(
set +u
set -a
# shellcheck disable=SC1090
source "${secrets_env}" >/dev/null
env
)"; then
echo "warning: failed to load local secrets env from ${secrets_env}" >&2
return 0
fi

while IFS= read -r line; do
key="${line%%=*}"
value="${line#*=}"
if [[ "${key}" == "${line}" ]]; then
continue
fi
if meerkat_secret_env_key_allowed "${key}" && [[ -z "${!key:-}" ]]; then
export "${key}=${value}"
fi
done <<< "${loaded_env}"
}
8 changes: 5 additions & 3 deletions scripts/buildbuddy-bazel-poc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ case "${1:-}" in
;;
esac

workspace_root="$(git rev-parse --show-toplevel)"
source "${workspace_root}/scripts/build-backend-env"
meerkat_load_local_secrets_env "${workspace_root}"

if [[ -z "${BUILDBUDDY_API_KEY:-}" && -f "${HOME}/.zshrc" ]]; then
key_line="$(grep -m1 -E '^[[:space:]]*(export[[:space:]]+)?BUILDBUDDY_API_KEY=' "${HOME}/.zshrc" || true)"
if [[ -n "${key_line}" ]]; then
Expand All @@ -83,8 +87,6 @@ if [[ -z "${BUILDBUDDY_API_KEY:-}" ]]; then
exit 1
fi

workspace_root="$(git rev-parse --show-toplevel)"

if [[ -n "${BUILDBUDDY_BB:-}" ]]; then
bb_bin="${BUILDBUDDY_BB}"
elif command -v bb >/dev/null 2>&1; then
Expand Down Expand Up @@ -258,7 +260,7 @@ case "${command}" in
e2e-smoke-rbe)
command="build"
config="${BUILDBUDDY_BAZEL_CONFIG:-buildbuddy-macos-rbe}"
default_target="//tests/integration:e2e_smoke_lane_test //tests/integration:e2e_artifacts_bin //meerkat-cli:rkat //meerkat-cli:cli_mobpack_live_smoke_test //meerkat-cli:live_smoke_cli_test //meerkat-mcp-server:rkat_mcp_bin //meerkat-mob:smoke_mob_flow_runtime_test //meerkat-mob:smoke_mob_pictionary_test //meerkat-mob:smoke_mob_resume_test //meerkat-rest:rkat_rest_bin //meerkat-rpc:rkat_rpc_bin //meerkat-rpc:live_smoke_rpc_test //tests/integration:smoke_shared_realm_test"
default_target="@wasm_pack_darwin_arm64//:wasm-pack //tests/integration:e2e_smoke_lane_test //tests/integration:e2e_artifacts_bin //meerkat-cli:rkat //meerkat-cli:cli_mobpack_live_smoke_test //meerkat-cli:live_smoke_cli_test //meerkat-mcp-server:rkat_mcp_bin //meerkat-mob:smoke_mob_flow_runtime_test //meerkat-mob:smoke_mob_pictionary_test //meerkat-mob:smoke_mob_resume_test //meerkat-rest:rkat_rest_bin //meerkat-rpc:rkat_rpc_bin //meerkat-rpc:live_smoke_rpc_test //tests/integration:smoke_shared_realm_test"
extra_args+=(
--remote_download_outputs=toplevel
--color=no
Expand Down
7 changes: 7 additions & 0 deletions scripts/buildbuddy-dev
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ EOF

workspace_root="$(git rev-parse --show-toplevel)"
cd "${workspace_root}"
source "${workspace_root}/scripts/build-backend-env"

jobs="${BUILDBUDDY_JOBS:-64}"
dry_run=0
Expand Down Expand Up @@ -96,6 +97,12 @@ lane="$1"
shift
extra_args=("$@")

case "${lane}" in
e2e-live|e2e-smoke)
meerkat_load_local_secrets_env "${workspace_root}"
;;
esac

bb_config="${BUILDBUDDY_BAZEL_CONFIG:-buildbuddy-macos-rbe}"

print_command() {
Expand Down
37 changes: 37 additions & 0 deletions scripts/e2e-smoke-lane
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ root="$(git rev-parse --show-toplevel)"
cd "${root}"
export WORKSPACE_ROOT="${root}"

source "${root}/scripts/build-backend-env"
meerkat_load_local_secrets_env "${root}"

buildbuddy_enabled() {
case "${MEERKAT_BUILDBUDDY:-}" in
1|true|TRUE|yes|YES|on|ON|buildbuddy)
Expand Down Expand Up @@ -75,11 +78,45 @@ buildbuddy_e2e_artifacts_bin() {
return 1
}

buildbuddy_wasm_pack_bin() {
local output_base candidate
output_base="$(buildbuddy_output_base)"
for candidate in \
"${output_base}/external/+http_archive+wasm_pack_darwin_arm64/wasm-pack" \
"${output_base}/external/wasm_pack_darwin_arm64/wasm-pack" \
"${output_base}/execroot/_main/external/+http_archive+wasm_pack_darwin_arm64/wasm-pack" \
"${output_base}/execroot/_main/external/wasm_pack_darwin_arm64/wasm-pack"; do
if [[ -x "${candidate}" ]]; then
printf '%s\n' "${candidate}"
return 0
fi
done
candidate="$(
find -L "${output_base}" \
-type f \
-name wasm-pack \
-path '*/wasm_pack_darwin_arm64/*' \
-perm -111 \
2>/dev/null |
head -n 1
)"
if [[ -n "${candidate}" ]]; then
printf '%s\n' "${candidate}"
return 0
fi
return 1
}

e2e_artifacts_cmd=("${root}/scripts/repo-cargo" run -p meerkat-integration-tests --bin e2e_artifacts --)
if buildbuddy_enabled; then
if artifact_bin="$(buildbuddy_e2e_artifacts_bin)"; then
e2e_artifacts_cmd=("${artifact_bin}")
export MEERKAT_E2E_BAZEL_BIN_DIR="$(cd "$(dirname "${artifact_bin}")/../.." && pwd)"
if [[ -z "${RKAT_WASM_PACK_BIN:-}" && -z "${WASM_PACK:-}" ]] &&
wasm_pack_bin="$(buildbuddy_wasm_pack_bin)"; then
export RKAT_WASM_PACK_BIN="${wasm_pack_bin}"
export WASM_PACK="${wasm_pack_bin}"
fi
else
echo "error: BuildBuddy e2e-smoke foundation did not produce e2e_artifacts_bin" >&2
echo "Run MEERKAT_BUILDBUDDY=1 make e2e-smoke so scripts/buildbuddy-dev builds //tests/integration:e2e_artifacts_bin first." >&2
Expand Down
2 changes: 2 additions & 0 deletions scripts/run-build-backend-lane
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ case "${lane}" in
exec "${cargo_bin}" e2e-system
;;
e2e-live)
meerkat_load_local_secrets_env "${root}"
if meerkat_buildbuddy_enabled; then
exec "${root}/scripts/buildbuddy-dev" e2e-live
fi
exec "${cargo_bin}" e2e-live
;;
e2e-smoke)
meerkat_load_local_secrets_env "${root}"
if meerkat_buildbuddy_enabled; then
"${root}/scripts/buildbuddy-dev" e2e-smoke
case "${BUILDBUDDY_DRY_RUN:-}" in
Expand Down
5 changes: 3 additions & 2 deletions sdks/python/tests/test_e2e_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ async def test_smoke_scenario_57_realtime_channel_session_exchange():

if include_scenario(58):
@pytest.mark.asyncio
@requires_live_llm
@requires_openai_realtime
async def test_smoke_scenario_58_realtime_member_channel_respawn_continuity():
async with live_client() as client:
if not client.has_capability("mob"):
Expand Down Expand Up @@ -760,7 +760,7 @@ async def test_smoke_scenario_58_realtime_member_channel_respawn_continuity():

if include_scenario(64):
@pytest.mark.asyncio
@requires_mixed_llms
@requires_openai_realtime
async def test_smoke_scenario_64_realtime_member_channel_model_switch_continuity():
async with live_client() as client:
if not client.has_capability("mob"):
Expand Down Expand Up @@ -878,6 +878,7 @@ async def test_smoke_scenario_64_realtime_member_channel_model_switch_continuity
assert "py-member-post-switch-64" in final_preview
assert "maple" in final_preview
assert final_state.get("realtime_attachment_status") in {
"unattached",
"binding_not_ready",
"binding_ready",
"replacement_pending",
Expand Down
4 changes: 2 additions & 2 deletions sdks/typescript/tests/e2e_smoke.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,13 @@ describe("Live Smoke: TypeScript SDK", { skip: !binaryPath }, () => {
if (includeScenario(59)) {
it(
"Scenario 59: realtime channel session exchange through the packaged SDK",
{ skip: !hasAnthropicKey() },
{ skip: !hasOpenAIKey() },
async () => {
const scenario = "Scenario 59";
const client = await withStepTimeout(
scenario,
"connect client",
connectClient({ realmId: "env_default" }),
connectClient({ realmId: `ts-realtime-59-${Date.now()}-${process.pid}` }),
);

const session = await withStepTimeout(
Expand Down
22 changes: 18 additions & 4 deletions sdks/web/scripts/build-wasm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const OUT_DIR = path.join(SDK_DIR, "wasm");
const CRATE_DIR = path.resolve(SDK_DIR, "../../meerkat-web-runtime");
const WORKSPACE_DIR = path.resolve(SDK_DIR, "../..");
const CACHE_MANIFEST = path.join(OUT_DIR, ".meerkat-wasm-build.json");
const WASM_PACK_BIN =
process.env.RKAT_WASM_PACK_BIN || process.env.WASM_PACK || "wasm-pack";
const REQUIRED_OUTPUTS = [
"meerkat_web_runtime.js",
"meerkat_web_runtime_bg.wasm",
Expand Down Expand Up @@ -174,7 +176,13 @@ async function runCapture(command, args, options = {}) {
child.stderr.on("data", (chunk) => {
stderr += chunk;
});
child.on("error", reject);
child.on("error", (error) => {
reject(
new Error(
`failed to run ${command}: ${error.message}. Install wasm-pack or set RKAT_WASM_PACK_BIN/WASM_PACK to a wasm-pack binary.`,
),
);
});
child.on("exit", (code, signal) => {
if (code === 0) {
resolve(stdout);
Expand Down Expand Up @@ -264,7 +272,7 @@ async function computeSourceHash() {
hash.update("meerkat-web-runtime-wasm-v1\n");
hash.update(`rustflags=--cfg getrandom_backend="wasm_js"\n`);
hash.update(`profile=${BUILD_PROFILE}\n`);
hash.update(`wasm-pack=${(await runCapture("wasm-pack", ["--version"])).trim()}\n`);
hash.update(`wasm-pack=${(await runCapture(WASM_PACK_BIN, ["--version"])).trim()}\n`);
const inputs = await localCargoGraphInputs();
for (const filePath of inputs) {
const relativePath = path.relative(WORKSPACE_DIR, filePath);
Expand Down Expand Up @@ -309,7 +317,7 @@ async function run() {
const profileArgs =
BUILD_PROFILE === "release" ? [] : [`--${BUILD_PROFILE}`];
const child = spawn(
"wasm-pack",
WASM_PACK_BIN,
[
"build",
CRATE_DIR,
Expand All @@ -328,7 +336,13 @@ async function run() {
},
},
);
child.on("error", reject);
child.on("error", (error) => {
reject(
new Error(
`failed to run ${WASM_PACK_BIN}: ${error.message}. Install wasm-pack or set RKAT_WASM_PACK_BIN/WASM_PACK to a wasm-pack binary.`,
),
);
});
child.on("exit", (code, signal) => {
if (code === 0) {
resolve();
Expand Down
11 changes: 4 additions & 7 deletions tests/integration/src/e2e_lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3567,7 +3567,7 @@ fn scenario_spec(id: u16) -> Option<&'static Spec> {
lane: Lane::Smoke,
title: "Python SDK realtime channel session exchange",
timeout_secs: 1500,
required_env: &[&["RKAT_ANTHROPIC_API_KEY", "ANTHROPIC_API_KEY"]],
required_env: &[&["RKAT_OPENAI_API_KEY", "OPENAI_API_KEY"]],
required_bins: &["python3", "cargo"],
cwd: "sdks/python",
env: &[("MEERKAT_BIN_PATH", "{cargo_target_dir}/debug/rkat-rpc")],
Expand Down Expand Up @@ -3599,7 +3599,7 @@ fn scenario_spec(id: u16) -> Option<&'static Spec> {
lane: Lane::Smoke,
title: "Python SDK realtime member respawn continuity",
timeout_secs: 1800,
required_env: &[&["RKAT_ANTHROPIC_API_KEY", "ANTHROPIC_API_KEY"]],
required_env: &[&["RKAT_OPENAI_API_KEY", "OPENAI_API_KEY"]],
required_bins: &["python3", "cargo"],
cwd: "sdks/python",
env: &[("MEERKAT_BIN_PATH", "{cargo_target_dir}/debug/rkat-rpc")],
Expand Down Expand Up @@ -3631,7 +3631,7 @@ fn scenario_spec(id: u16) -> Option<&'static Spec> {
lane: Lane::Smoke,
title: "TypeScript SDK realtime channel session exchange",
timeout_secs: 1500,
required_env: &[&["RKAT_ANTHROPIC_API_KEY", "ANTHROPIC_API_KEY"]],
required_env: &[&["RKAT_OPENAI_API_KEY", "OPENAI_API_KEY"]],
required_bins: &["node", "npm", "cargo"],
cwd: "sdks/typescript",
env: &[("MEERKAT_BIN_PATH", "{cargo_target_dir}/debug/rkat-rpc")],
Expand Down Expand Up @@ -3812,10 +3812,7 @@ fn scenario_spec(id: u16) -> Option<&'static Spec> {
lane: Lane::Smoke,
title: "Python SDK realtime member model-switch continuity",
timeout_secs: 1800,
required_env: &[
&["RKAT_ANTHROPIC_API_KEY", "ANTHROPIC_API_KEY"],
&["RKAT_OPENAI_API_KEY", "OPENAI_API_KEY"],
],
required_env: &[&["RKAT_OPENAI_API_KEY", "OPENAI_API_KEY"]],
required_bins: &["python3", "cargo"],
cwd: "sdks/python",
env: &[("MEERKAT_BIN_PATH", "{cargo_target_dir}/debug/rkat-rpc")],
Expand Down
Loading
Loading