Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Operations helpers encode admin JSON fields, return a failure after any fleet host fails while still visiting remaining hosts, and isolate smoke-test response files.

- **Admin email login** — Encode Privy OTP email/code fields as JSON strings so quoted addresses and escape characters cannot break or reshape the upstream request.

## Release candidate v0.9.2 — Gemma QAT caching, adaptive MTP and Nemotron Lightning (not shipped; 2026-09-10)
Expand Down
8 changes: 7 additions & 1 deletion deploy/provider-fleet/update-fleet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ if [ -z "$HOSTS" ]; then
fi

echo "==> Updating $ENV_NAME fleet against $COORD_URL"
failed=0
for HOST in $HOSTS; do
echo "---- $HOST ----"
ssh "$HOST" "curl -fsSL $COORD_URL/install.sh | bash" || {
ssh "$HOST" "bash -o pipefail -c 'curl -fsSL $COORD_URL/install.sh | bash'" || {
echo "!!! $HOST failed — continuing" >&2
failed=$((failed + 1))
Comment thread
Gajesh2007 marked this conversation as resolved.
Resolved
}
done

if [ "$failed" -gt 0 ]; then
echo "==> Fleet update finished with $failed failed host(s)" >&2
exit 1
fi
echo "==> Fleet update complete"
6 changes: 5 additions & 1 deletion docs/developer/build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build

> Last updated: 2026-09-10 · commit `4f29957d2`
> Last updated: 2026-09-11 · commit `cb8c6ebf9`

How to build every component of Darkbloom from a fresh clone: the Go
coordinator, the Rust prompt-contract sidecar, the Swift provider CLI (with its
Expand All @@ -11,6 +11,10 @@ Model publishing can pass `HUGGING_FACE_ARTIFACT_JSON` through
`scripts/publish-model.sh` to registration. See the
[model publishing procedure](../operations/model-migration.md).

The admin, smoke and fleet helpers use the tools pinned here. Their local fixture
checks are covered by [script validation](test.md#6-scripts-and-release-integrity);
the [dev operations runbook](../operations/dev-environment.md) covers invocation.

Profiler wire changes require both coordinator and provider builds; the shared
Go/Swift fixture and focused checks are described in [test.md](test.md) and
[prediction telemetry](../reference/prediction-decision-telemetry.md).
Expand Down
6 changes: 5 additions & 1 deletion docs/developer/test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test

> Last updated: 2026-09-11 · commit `d22ad0cf3`
> Last updated: 2026-09-11 · commit `cb8c6ebf9`

How to run the unit tests for each component, the end-to-end suite that boots a
real coordinator + Swift provider against ephemeral Postgres, and the docs
Expand Down Expand Up @@ -923,6 +923,10 @@ node --test landing/earn-calculator-core.test.js

### 6. Scripts and release integrity

`python3 scripts/test_operations_scripts.py` checks admin JSON fields, fleet
partial-failure exit status and smoke-file ownership using stub transports. It
makes no network request, writes no login token and updates no host.

```bash
make benchmark-wrapper-test # python3 -m unittest discover -s gemma_contbatch/tests -t . (in scripts/)
./scripts/check-release-version.sh # ProviderCore.version == coordinator LatestProviderVersion (see operations/provider-release.md)
Expand Down
7 changes: 6 additions & 1 deletion docs/operations/dev-environment.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dev environment

> Last updated: 2026-09-06 · commit `f272f8641`
> Last updated: 2026-09-11 · commit `cb8c6ebf9`

Runbook for the Darkbloom dev environment on Google Cloud (project
`sepolia-ai`): a GCE VM running the same coordinator container as production,
Expand Down Expand Up @@ -170,6 +170,11 @@ re-runs the installer on every listed Mac.

## Verification

The fleet updater visits every configured host and exits nonzero if any update
fails. Authenticated smoke runs use a unique temporary response file and remove
it when the process exits. Admin login and release-deactivation commands encode
input as JSON values, preserving quotes and backslashes.

```bash
scripts/smoke-dev.sh # /health, /v1/stats, /v1/models/catalog, install.sh templating
API_KEY=<dev api key> scripts/smoke-dev.sh # + an authenticated chat completion
Expand Down
19 changes: 12 additions & 7 deletions scripts/admin.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

# EigenInference Admin CLI
# Darkbloom Admin CLI
#
# Authenticate with Privy and manage releases, models, and pricing.
#
Expand All @@ -19,6 +19,11 @@ TOKEN_FILE="$HOME/.darkbloom/admin_token"

# ─── Auth helpers ───────────────────────────────────────────

# Encode user-entered values once instead of interpolating them into JSON syntax.
json_body() {
python3 -c 'import json,sys; print(json.dumps(dict(zip(sys.argv[1::2], sys.argv[2::2]))))' "$@"
}

get_token() {
# Check for admin key (dev/pre-prod).
if [ -n "${EIGENINFERENCE_ADMIN_KEY:-}" ]; then
Expand Down Expand Up @@ -48,25 +53,25 @@ authed_curl() {
# ─── Commands ───────────────────────────────────────────────

cmd_login() {
echo "EigenInference Admin Login"
echo "Darkbloom Admin Login"
echo ""
read -p "Email: " EMAIL
read -r -p "Email: " EMAIL

echo "Sending OTP to $EMAIL..."
INIT_RESP=$(curl -fsSL -X POST "$COORDINATOR_URL/v1/admin/auth/init" \
-H "Content-Type: application/json" \
-d "{\"email\": \"$EMAIL\"}" 2>&1) || {
-d "$(json_body email "$EMAIL")" 2>&1) || {
echo "Failed to send OTP: $INIT_RESP"
exit 1
}

echo "Check your email for the verification code."
read -p "OTP Code: " CODE
read -r -p "OTP Code: " CODE

echo "Verifying..."
VERIFY_RESP=$(curl -fsSL -X POST "$COORDINATOR_URL/v1/admin/auth/verify" \
-H "Content-Type: application/json" \
-d "{\"email\": \"$EMAIL\", \"code\": \"$CODE\"}")
-d "$(json_body email "$EMAIL" code "$CODE")")

TOKEN=$(echo "$VERIFY_RESP" | python3 -c "import sys,json; print(json.load(sys.stdin).get('token',''))" 2>/dev/null || echo "")
if [ -z "$TOKEN" ]; then
Expand Down Expand Up @@ -95,7 +100,7 @@ cmd_releases_deactivate() {
local platform="${2:-macos-arm64}"
authed_curl -X DELETE "$COORDINATOR_URL/v1/admin/releases" \
-H "Content-Type: application/json" \
-d "{\"version\": \"$version\", \"platform\": \"$platform\"}"
-d "$(json_body version "$version" platform "$platform")"
echo ""
echo "Release $version ($platform) deactivated."
}
Expand Down
6 changes: 4 additions & 2 deletions scripts/smoke-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ fi
# Authenticated tests only run if an API key is supplied.
if [ -n "$API_KEY" ]; then
step "chat completions (authenticated)"
HTTP_CODE=$(curl -sS -o /tmp/smoke-chat.json -w '%{http_code}' \
smoke_result=$(mktemp -t darkbloom-smoke.XXXXXX)
trap 'rm -f "$smoke_result"' EXIT
HTTP_CODE=$(curl -sS -o "$smoke_result" -w '%{http_code}' \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"auto","messages":[{"role":"user","content":"ping"}],"max_tokens":8,"stream":false}' \
"$COORD/v1/chat/completions" || echo 000)
if [ "$HTTP_CODE" = "200" ]; then
green "chat OK"
else
fail "chat returned $HTTP_CODE: $(head -c 400 /tmp/smoke-chat.json)"
fail "chat returned $HTTP_CODE: $(head -c 400 "$smoke_result")"
fi
else
echo "(skipping authenticated tests — set API_KEY to enable)"
Expand Down
116 changes: 116 additions & 0 deletions scripts/test_operations_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"""Exercise operations CLIs with stub transports; no network or fleet mutations."""

import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest


ROOT = Path(__file__).resolve().parents[1]


class OperationsScriptsTests(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory()
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name)
self.log = self.root / "calls.jsonl"
self.bin = self.root / "bin"
self.bin.mkdir()
self.env = {**os.environ, "PATH": str(self.bin) + os.pathsep + os.environ["PATH"],
"OPERATIONS_TEST_LOG": str(self.log), "EIGENINFERENCE_ADMIN_KEY": "fixture-only"}

def stub(self, name, source):
path = self.bin / name
path.write_text("#!/usr/bin/env python3\n" + source)
path.chmod(0o755)

def calls(self):
return [json.loads(line) for line in self.log.read_text().splitlines()]

def test_admin_auth_and_deactivation_encode_user_values(self):
self.stub("curl", '''import json,os,sys
with open(os.environ["OPERATIONS_TEST_LOG"], "a") as log:
log.write(json.dumps(sys.argv[1:]) + "\\n")
print("{}")
''')
email, code = 'person"\\name@example.invalid', '\\123"456'
result = subprocess.run(["bash", str(ROOT / "scripts/admin.sh"), "login"],
input=email + "\n" + code + "\n", env=self.env,
capture_output=True, text=True)
# The stub returns no token, so login intentionally stops before any token write.
self.assertEqual(result.returncode, 1)
init, verify = self.calls()
self.assertEqual(json.loads(init[init.index("-d") + 1]), {"email": email})
self.assertEqual(json.loads(verify[verify.index("-d") + 1]), {"email": email, "code": code})
version, platform = '0.9.2"', 'macos\\arm64'
result = subprocess.run(["bash", str(ROOT / "scripts/admin.sh"), "releases", "deactivate", version, platform],
env=self.env, capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
call = self.calls()[-1]
self.assertEqual(json.loads(call[call.index("-d") + 1]), {"version": version, "platform": platform})

def test_fleet_continues_after_failure_but_returns_failure(self):
fleet = self.root / "update-fleet.sh"
shutil.copy2(ROOT / "deploy/provider-fleet/update-fleet.sh", fleet)
(self.root / "dev-inventory.txt").write_text("first\nsecond\nthird\n")
self.stub("ssh", '''import json,os,sys
with open(os.environ["OPERATIONS_TEST_LOG"], "a") as log:
log.write(json.dumps(sys.argv[1]) + "\\n")
sys.exit(1 if sys.argv[1] == "second" else 0)
''')
result = subprocess.run(["bash", str(fleet), "dev"], env=self.env, capture_output=True, text=True)
self.assertEqual(result.returncode, 1)
self.assertEqual(self.calls(), ["first", "second", "third"])
self.assertIn("1 failed host", result.stderr)
result = subprocess.run(["bash", str(fleet), "prod"], env=self.env, capture_output=True, text=True)
self.assertEqual(result.returncode, 2)
self.assertEqual(self.calls(), ["first", "second", "third"])

def test_fleet_propagates_remote_download_and_installer_failures(self):
fleet = self.root / "update-fleet.sh"
shutil.copy2(ROOT / "deploy/provider-fleet/update-fleet.sh", fleet)
(self.root / "dev-inventory.txt").write_text("fixture-host\n")
self.stub("ssh", '''import subprocess,sys
# Run only the supplied shell command locally against our curl stub.
sys.exit(subprocess.run(["/bin/sh", "-c", sys.argv[2]]).returncode)
''')
for curl_source in ("import sys; sys.exit(22)", "print('exit 7')", "print('exit 0')"):
with self.subTest(curl_source=curl_source):
self.stub("curl", curl_source)
result = subprocess.run(["bash", str(fleet), "dev"], env=self.env,
capture_output=True, text=True)
self.assertEqual(result.returncode, 0 if "exit 0" in curl_source else 1)

def test_smoke_uses_a_fresh_owned_response_file_and_removes_it(self):
self.stub("curl", '''import json,os,sys
from pathlib import Path
args = sys.argv[1:]
if "-o" in args:
path = args[args.index("-o") + 1]
Path(path).write_text("fixture response")
with open(os.environ["OPERATIONS_TEST_LOG"], "a") as log:
log.write(json.dumps(path) + "\\n")
print("500", end="")
elif args[-1].endswith("/v1/stats"):
print('{"providers_online": 1}')
elif args[-1].endswith("/v1/models/catalog"):
print('{"models": [1]}')
elif args[-1].endswith("/install.sh"):
print("https://api.dev.darkbloom.xyz")
''')
for _ in range(2):
result = subprocess.run(["bash", str(ROOT / "scripts/smoke-dev.sh")],
env={**self.env, "API_KEY": "fixture-only"}, capture_output=True, text=True)
self.assertEqual(result.returncode, 1)
self.assertIn("fixture response", result.stdout)
paths = self.calls()
self.assertEqual(len(set(paths)), 2)
self.assertTrue(all(not Path(path).exists() for path in paths))


if __name__ == "__main__":
unittest.main()
Loading