Files
oh-my-pi/scripts/install-tests/run-ci.sh
T
can1357 1c968a7bfc feat(scripts): added native leaf-package publish checks to install smoke tests
- Added repeatable `--tag` argument parsing in `gen-npm-packages.ts` and threaded parsed tags into `generateNpmPackages` for targeted leaf publishing.
- Exported `prepareNativeCorePackage` and expanded package manifest typing to support scripted manifest rewrites used by release workflows.
- Reworked install-test smoke logic to pack the host leaf package, pack the rewritten natives core, and assert the platform leaf package resolves from the core optional dependency.
2026-05-30 19:52:45 +02:00

151 lines
5.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/../.."
ROOT_DIR="$(pwd)"
WORK_DIR="$(mktemp -d)"
TMP_WORK_DIR="$WORK_DIR/tmp"
mkdir -p "$TMP_WORK_DIR"
export TMPDIR="$TMP_WORK_DIR"
trap 'rm -rf "$WORK_DIR"' EXIT
section() {
echo ""
echo "=== $1 ==="
}
smoke_cli() {
local omp_bin="$1"
local runtime_dir
runtime_dir="$(mktemp -d "$WORK_DIR/compiled-runtime.XXXXXX")"
XDG_DATA_HOME="$runtime_dir/xdg" HOME="$runtime_dir/home" "$omp_bin" --version
XDG_DATA_HOME="$runtime_dir/xdg" HOME="$runtime_dir/home" "$omp_bin" --help >/dev/null
XDG_DATA_HOME="$runtime_dir/xdg" HOME="$runtime_dir/home" "$omp_bin" stats --summary >/dev/null
# Spawns the stats sync worker via `new Worker(...)` and waits for a pong.
# Regression probe for #1011 (browser tab worker) and #1027 (stats sync
# worker) — both broke silently in compiled binaries because the `with
# { type: "file" }` import pattern only copies the worker as a raw asset
# without bundling its imports. `stats --summary` doesn't catch this on a
# fresh install (no session files = no Worker spawn).
XDG_DATA_HOME="$runtime_dir/xdg" HOME="$runtime_dir/home" "$omp_bin" --smoke-test
}
find_tarball() {
local pattern="$1"
local matches=()
shopt -s nullglob
matches=("$pattern")
shopt -u nullglob
if [ "${#matches[@]}" -ne 1 ]; then
echo "Expected exactly one tarball matching: $pattern"
exit 1
fi
echo "${matches[0]}"
}
section "Binary install smoke"
bun --cwd=packages/natives run build
bun --cwd=packages/coding-agent run build
BINARY_DIR="$WORK_DIR/binary-bin"
mkdir -p "$BINARY_DIR"
cp packages/coding-agent/dist/omp "$BINARY_DIR/omp"
smoke_cli "$BINARY_DIR/omp"
section "Source install smoke"
SOURCE_BUN_HOME="$WORK_DIR/bun-source"
(
export BUN_INSTALL="$SOURCE_BUN_HOME"
export PATH="$BUN_INSTALL/bin:$PATH"
bun --cwd="$ROOT_DIR/packages/coding-agent" link
smoke_cli "$BUN_INSTALL/bin/omp"
)
section "Tarball install smoke"
TARBALL_DIR="$WORK_DIR/tarballs"
mkdir -p "$TARBALL_DIR"
host_tag="$(bun -e "process.stdout.write(\`\${process.platform}-\${process.arch}\`)")"
# Native addon split: the published core ships only the loader (no `.node`); the
# prebuilt binary lives in a per-platform leaf package pulled in as an optional
# dependency. Reproduce that exact published topology so this smoke proves the
# installed core resolves its addon through the leaf, not a bundled binary.
# 1. Generate + pack the host-platform leaf (carries the built `.node`).
bun --cwd=packages/natives run gen:npm --tag "$host_tag" >/dev/null
(
cd "$ROOT_DIR/packages/natives/npm/$host_tag"
bun pm pack --destination "$TARBALL_DIR" --quiet >/dev/null
)
# 2. Pack the core with its *published* manifest: the same rewrite release uses
# drops `.node` from `files` and adds the leaf `optionalDependencies`. Always
# restore the working-tree manifest so local runs aren't left mutated.
natives_pkg_backup="$WORK_DIR/natives-package.json.orig"
cp "$ROOT_DIR/packages/natives/package.json" "$natives_pkg_backup"
core_rc=0
{
bun -e 'import { prepareNativeCorePackage } from "./scripts/ci-release-publish.ts"; await prepareNativeCorePackage("packages/natives", true);' &&
( cd "$ROOT_DIR/packages/natives" && bun pm pack --destination "$TARBALL_DIR" --quiet >/dev/null )
} || core_rc=$?
cp "$natives_pkg_backup" "$ROOT_DIR/packages/natives/package.json"
[ "$core_rc" -eq 0 ] || exit "$core_rc"
# 3. Pack the remaining workspace packages (natives core handled above).
for pkg in utils hashline ai mnemosyne agent tui stats coding-agent; do
(
cd "$ROOT_DIR/packages/$pkg"
bun pm pack --destination "$TARBALL_DIR" --quiet >/dev/null
)
done
utils_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-utils-*.tgz)"
natives_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-natives-[0-9]*.tgz)"
natives_leaf_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-natives-"$host_tag"-*.tgz)"
hashline_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-hashline-*.tgz)"
ai_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-ai-*.tgz)"
mnemosyne_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-mnemosyne-*.tgz)"
agent_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-agent-core-*.tgz)"
tui_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-tui-*.tgz)"
stats_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-omp-stats-*.tgz)"
coding_agent_tgz="$(find_tarball "$TARBALL_DIR"/oh-my-pi-pi-coding-agent-*.tgz)"
TARBALL_APP_DIR="$WORK_DIR/tarball-install"
mkdir -p "$TARBALL_APP_DIR"
(
cd "$TARBALL_APP_DIR"
bun init -y >/dev/null
# Write overrides so bun resolves inter-package deps from tarballs, not the registry
# (version 12.x.y hasn't been published yet when CI runs pre-release)
node -e "
const pkg = JSON.parse(require('fs').readFileSync('package.json', 'utf8'));
pkg.overrides = {
'@oh-my-pi/pi-utils': '$utils_tgz',
'@oh-my-pi/pi-natives': '$natives_tgz',
'@oh-my-pi/pi-natives-$host_tag': '$natives_leaf_tgz',
'@oh-my-pi/hashline': '$hashline_tgz',
'@oh-my-pi/pi-ai': '$ai_tgz',
'@oh-my-pi/pi-mnemosyne': '$mnemosyne_tgz',
'@oh-my-pi/pi-agent-core': '$agent_tgz',
'@oh-my-pi/pi-tui': '$tui_tgz',
'@oh-my-pi/omp-stats': '$stats_tgz',
'@oh-my-pi/pi-coding-agent': '$coding_agent_tgz'
};
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2));
"
bun add "$utils_tgz" "$natives_tgz" "$hashline_tgz" "$ai_tgz" "$mnemosyne_tgz" "$agent_tgz" "$tui_tgz" "$stats_tgz" "$coding_agent_tgz"
# The platform leaf must arrive through the core's optionalDependencies +
# override, not as a direct dependency — assert it landed before smoking so a
# resolution regression is distinguishable from a runtime loader bug.
leaf_dir="node_modules/@oh-my-pi/pi-natives-$host_tag"
[ -d "$leaf_dir" ] || { echo "Platform leaf package not installed: $leaf_dir"; exit 1; }
smoke_cli ./node_modules/.bin/omp
)
echo ""
echo "All install method smoke tests passed"