#!/bin/sh
# Check that both modules load and that argument validation still rejects bad
# input.  The upstream suite needs vitest, which is not packaged, so this
# exercises the built artefacts instead.
set -eu

HERE=$(cd "$(dirname "$0")" && pwd)
SHARE=${NODEJS_SHARE:-/usr/share/nodejs}
cd "$HERE"

mkdir -p node_modules/@monacopilot
[ -e node_modules/@monacopilot/core ] || ln -s "$SHARE/@monacopilot/core" node_modules/@monacopilot/core
[ -e node_modules/monacopilot ] || ln -s "$SHARE/monacopilot" node_modules/monacopilot

# monacopilot itself require()s its sibling by bare name.
NODE_PATH="$SHARE${NODE_PATH:+:$NODE_PATH}"
export NODE_PATH

exec node --test "$HERE/api.test.js"
