interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / scripts / test-pkv-lib.sh

74 lines · 2914 bytes Raw Blame History
1#!/usr/bin/env bash
2# test-pkv-lib.sh: host-only self-test of scripts/own30b-pkv-lib.sh (sc#523 items 7 and 8) with
3# stub curl, ss and sleep on PATH: no server, no chip, no network, no real port. Proves:
4# wait_parks settles only on a number (a null or empty parked_chunks never counts as settled),
5# and a port still held at exit makes the EXIT trap fail the run without skipping its cleanup.
6set -euo pipefail
7ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8LIB="$ROOT/scripts/own30b-pkv-lib.sh"
9T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
10fail=0
11chk() { if eval "$1"; then echo " ok $2"; else echo " FAIL $2"; fail=1; fi; }
12
13mkdir "$T/bin"
14# curl: the live port never answers; any other URL answers with $T/health when it exists.
15cat >"$T/bin/curl" <<EOF
16#!/bin/sh
17case "\$*" in *:18091*) exit 7 ;; esac
18[ -f "$T/health" ] || exit 7
19cat "$T/health"
20EOF
21# ss: a listener on the port while $T/listening exists.
22cat >"$T/bin/ss" <<EOF
23#!/bin/sh
24[ -f "$T/listening" ] && echo "LISTEN 0 128 127.0.0.1:18098 0.0.0.0:*"
25exit 0
26EOF
27printf '#!/bin/sh\nexit 0\n' >"$T/bin/sleep"
28chmod +x "$T/bin/curl" "$T/bin/ss" "$T/bin/sleep"
29
30# wait_parks against a /health body; prints its exit status.
31parks() {
32 printf '%s\n' "$1" >"$T/health"
33 (PATH="$T/bin:$PATH"; set -euo pipefail; . "$LIB"; wait_parks) >/dev/null 2>&1 && echo 0 || echo $?
34}
35echo "test-pkv-lib: wait_parks (item 7)"
36chk '[ "$(parks "{\"persistent_kv\":{\"parked_chunks\":3}}")" = 0 ]' "a steady number settles"
37chk '[ "$(parks "{\"persistent_kv\":{\"parked_chunks\":0}}")" != 0 ]' "zero never settles"
38chk '[ "$(parks "{\"persistent_kv\":{\"parked_chunks\":null}}")" != 0 ]' "null never settles"
39chk '[ "$(parks "{\"persistent_kv\":{}}")" != 0 ]' "a missing counter never settles"
40chk '[ "$(parks "{\"status\":\"ok\"}")" != 0 ]' "persistence absent never settles"
41chk '[ "$(parks "")" != 0 ]' "an empty reply never settles"
42rm -f "$T/health"
43
44echo "test-pkv-lib: the EXIT trap with the port still held (item 8)"
45# pkv_begin with a free port, then something keeps listening after our server is gone.
46rc=0
47(
48 PATH="$T/bin:$PATH"
49 set -euo pipefail
50 . "$LIB"
51 dir="$T/ev" BIN=/bin/true
52 pkv_begin
53 echo "$work" >"$T/work"
54 echo 999999 >"$PIDF" # not an aien-serve-http: stop_server sends no signal
55 touch "$T/listening"
56) >"$T/trap.out" 2>&1 || rc=$?
57chk '[ "$rc" != 0 ]' "the run fails (exit $rc)"
58chk 'grep -q "still listens" "$T/trap.out"' "the leftover listener is reported"
59chk '[ -s "$T/work" ] && [ ! -e "$(cat "$T/work")" ]' "the trap still removed the private work dir"
60
61rm -f "$T/listening"
62rc=0
63(
64 PATH="$T/bin:$PATH"
65 set -euo pipefail
66 . "$LIB"
67 dir="$T/ev2" BIN=/bin/true
68 pkv_begin
69 echo "$work" >"$T/work2"
70) >/dev/null 2>&1 || rc=$?
71chk '[ "$rc" = 0 ]' "a clean stop exits 0 (control)"
72chk '[ ! -e "$(cat "$T/work2")" ]' "and removes the work dir"
73
74[ "$fail" = 0 ] && echo "test-pkv-lib: PASS" || { echo "test-pkv-lib: FAIL"; exit 1; }