fix(e2e): recover reliable local stack startup
This commit is contained in:
1 parent
dcc201e7bb
commit
3229de9b3b
7 files changed
+120
-28
No files matched your search
+10
-2
@@ -24,7 +24,15 @@ task e2e:down # stop; e2e/stack.sh reset also deletes the data
|
||||
Nothing reads the installed config: `stack.sh` points the XDG directories at
|
||||
`${ARCHIE_DEV_DIR:-~/.local/state/archie-dev}` and writes its overlay from
|
||||
`deployments/dev.toml`. Logs are in its `logs/`. `e2e/stack.sh restart archied`
|
||||
restarts one service.
|
||||
restarts one service. Run `task e2e:down` before starting again: startup refuses
|
||||
occupied service ports and checks that each launched process stays alive.
|
||||
|
||||
The seed creates a local test administrator: `operator@example.test`, password
|
||||
`archie-local-e2e-password`. Use it at `http://localhost:5173`; the browser
|
||||
checks sign in with the same account. These are test fixtures for this
|
||||
loopback-only stack. To use an existing test account, set `ARCHIE_E2E_EMAIL`
|
||||
and `ARCHIE_E2E_PASSWORD` for both seeding and browser checks. Seeding never
|
||||
resets an existing account or deletes test data.
|
||||
|
||||
The first run needs `npm ci --prefix e2e` and `npx --prefix e2e playwright
|
||||
install chromium`. In the cloud environment, Chromium and Playwright are
|
||||
@@ -55,7 +63,7 @@ trailing or doubled spaces. `seeded` checks the seed is visible.
|
||||
| Symptom | Cause | Fix |
|
||||
| --- | --- | --- |
|
||||
| State Store exits: server is older than PostgreSQL 18 | another server answered | `stack.sh` uses port 55432; set `ARCHIE_DEV_PGPORT` if that is taken |
|
||||
| Work request: repository is not configured | archied reads repository policies only at boot | `seed.sh` restarts it; do the same after changing policies |
|
||||
| Startup says a port is in use | a stack or another process already owns it | Run `task e2e:down`, then `task e2e:up`; inspect any remaining listener with `ss -ltnp` |
|
||||
| Your own shell is killed (exit 144) | `pkill -f` matched its own command line | `stack.sh stop` or `restart`, which kill by PID |
|
||||
| `npx shadcn-vue add` cannot fetch the registry | Node's fetch ignores the cloud agent proxy | `curl` the registry JSON and copy the files |
|
||||
| Postgres aborts in the cloud | `/tmp/claude-0` is reset to mode 700 | `stack.sh` keeps the root cluster in `/var/lib/archie-dev` |
|
||||
+13
-1
@@ -21,11 +21,23 @@ fs.mkdirSync(out, { recursive: true });
|
||||
|
||||
(async () => {
|
||||
const browser = await chromium.launch();
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
const login = await context.request.post(base + '/api/auth/login', {
|
||||
headers: { 'X-Archie-CSRF': '1', Origin: base },
|
||||
data: { email: process.env.ARCHIE_E2E_EMAIL || 'operator@example.test', password: process.env.ARCHIE_E2E_PASSWORD || 'archie-local-e2e-password' },
|
||||
});
|
||||
if (!login.ok()) {
|
||||
const error = `Test account sign-in failed (${login.status()}): ${await login.text()}`;
|
||||
await browser.close();
|
||||
throw new Error(error);
|
||||
}
|
||||
const storageState = await context.storageState();
|
||||
await context.close();
|
||||
const results = [];
|
||||
for (const name of names) {
|
||||
const check = require(path.join(__dirname, 'checks', name + '.cjs'));
|
||||
// A fresh page per check: open event streams pile up across navigations.
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 }, storageState });
|
||||
const errors = [];
|
||||
const notes = [];
|
||||
page.on('pageerror', (e) => errors.push(String(e)));
|
||||
|
||||
+18
-3
@@ -6,13 +6,28 @@ set -euo pipefail
|
||||
|
||||
base=${ARCHIE_E2E_API:-http://localhost:8484}
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
H=(-H 'Content-Type: application/json' -H 'X-Archie-CSRF: 1' -H "Origin: $base")
|
||||
cookie=$(mktemp)
|
||||
trap 'rm -f "$cookie"' EXIT
|
||||
H=(-b "$cookie" -c "$cookie" -H 'Content-Type: application/json' -H 'X-Archie-CSRF: 1' -H "Origin: $base")
|
||||
|
||||
get() { curl -fsS "$base$1"; }
|
||||
get() { curl -fsS -b "$cookie" "$base$1"; }
|
||||
post() { curl -fsS -X POST "$base$1" "${H[@]}" -d "$2"; }
|
||||
# jq-free JSON reads: py EXPR, with the parsed body as d.
|
||||
py() { python3 -c "import sys, json; d = json.load(sys.stdin); print($1)"; }
|
||||
|
||||
# This account belongs only to the isolated local test stack.
|
||||
email=${ARCHIE_E2E_EMAIL:-operator@example.test}
|
||||
password=${ARCHIE_E2E_PASSWORD:-archie-local-e2e-password}
|
||||
account=$(python3 -c 'import json,sys; print(json.dumps(dict(email=sys.argv[1], password=sys.argv[2], display_name="E2E operator", organisation_name="E2E", workspace_name="Local test", public_url=sys.argv[3])))' "$email" "$password" "${ARCHIE_E2E_URL:-http://localhost:5173}")
|
||||
if [ "$(get /api/auth/status | py 'd["setup_required"]')" = "True" ]; then
|
||||
post /api/auth/setup "$account" >/dev/null
|
||||
else
|
||||
if ! post /api/auth/login "$account" >/dev/null; then
|
||||
echo "Test account sign-in failed. Set ARCHIE_E2E_EMAIL and ARCHIE_E2E_PASSWORD to this test stack's account credentials." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Repository policy. archied applies it live; the pause lets the watch publish it.
|
||||
if ! get /api/control-plane/resources/repository-policies | grep -q '"widgets"'; then
|
||||
version=$(get /api/control-plane/resources/repository-policies | py 'd["resource"]["version"]')
|
||||
@@ -36,7 +51,7 @@ if ! get /api/sources | grep -q "\"$src\""; then
|
||||
post /api/sources "{\"path\":\"$src\"}" >/dev/null
|
||||
post "/api/sources/$src/signing" '{"signed":false}' >/dev/null
|
||||
post "/api/sources/$src/approve-unsigned" '{}' >/dev/null
|
||||
bash "$here/../tools/webhook-send.sh" --url "$base" --source "$src" --kind github-issue >/dev/null
|
||||
bash "$here/../tools/webhook-send.sh" --url "$base" --source "$src" --kind github-issue --quiet >/dev/null
|
||||
fi
|
||||
et=$(get /api/event-types | py '"".join(t["id"] for t in (d.get("event_types", []) if isinstance(d, dict) else d) if t["name"] == "issue-opened")')
|
||||
if [ -z "$et" ]; then
|
||||
|
||||
+37
-3
@@ -4,7 +4,7 @@
|
||||
# the installed config: XDG paths point into the dev directory.
|
||||
#
|
||||
# e2e/stack.sh start | stop | restart <service> | status | reset
|
||||
set -euo pipefail
|
||||
set -Eeuo pipefail
|
||||
|
||||
repo=$(cd "$(dirname "$0")/.." && pwd)
|
||||
dir=${ARCHIE_DEV_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/archie-dev}
|
||||
@@ -34,8 +34,17 @@ pgbin() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_process() {
|
||||
local pid
|
||||
if [ ! -f "$dir/pids/$1" ] || ! pid=$(cat "$dir/pids/$1") || ! kill -0 "$pid" 2>/dev/null; then
|
||||
echo "$1 exited; see $dir/logs/$1.log" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
wait_port() {
|
||||
for _ in $(seq 1 "${3:-60}"); do
|
||||
check_process "$2" || return 1
|
||||
(echo >"/dev/tcp/127.0.0.1/$1") 2>/dev/null && return 0
|
||||
sleep 1
|
||||
done
|
||||
@@ -75,8 +84,15 @@ prepare() {
|
||||
spawn() {
|
||||
local name=$1 cwd=$2
|
||||
shift 2
|
||||
rm -f "$dir/pids/$name"
|
||||
setsid -f bash -c 'cd "$1" && echo $$ >"$2" && shift 2 && exec "$@"' _ "$cwd" "$dir/pids/$name" "$@" \
|
||||
</dev/null >"$dir/logs/$name.log" 2>&1
|
||||
</dev/null >"$dir/logs/$name.log" 2>&1 9>&-
|
||||
for _ in $(seq 1 50); do
|
||||
[ ! -f "$dir/pids/$name" ] || { check_process "$name"; return; }
|
||||
sleep 0.1
|
||||
done
|
||||
echo "$name did not start; see $dir/logs/$name.log" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
start_service() {
|
||||
@@ -95,16 +111,29 @@ stop_pid() {
|
||||
}
|
||||
|
||||
start() {
|
||||
local port
|
||||
for port in 9091 8585 8586 8485 8484 5173; do
|
||||
if (echo >"/dev/tcp/127.0.0.1/$port") 2>/dev/null; then
|
||||
echo "Port $port is already in use. Run task e2e:down before task e2e:up; if it stays occupied, inspect its owner with ss -ltnp." >&2
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
trap 'trap - ERR; stop' ERR
|
||||
prepare
|
||||
start_pg
|
||||
start_pg 9>&-
|
||||
start_service archie-state-store
|
||||
wait_port 9091 archie-state-store 90
|
||||
local s
|
||||
for s in archie-gateway archied archie-messaging archie-ui; do start_service "$s"; done
|
||||
wait_port 8585 archie-gateway
|
||||
wait_port 8586 archie-messaging
|
||||
wait_port 8485 archied
|
||||
wait_port 8484 archie-ui
|
||||
[ -d "$repo/ui/node_modules" ] || (cd "$repo/ui" && npm ci --no-audit --no-fund >/dev/null)
|
||||
spawn vite "$repo/ui" npx vite --host 127.0.0.1 --port 5173 --strictPort
|
||||
wait_port 5173 vite
|
||||
for s in "${services[@]}" vite; do check_process "$s"; done
|
||||
trap - ERR
|
||||
echo "dashboard: http://localhost:5173 logs: $dir/logs"
|
||||
}
|
||||
|
||||
@@ -116,6 +145,11 @@ stop() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Keep concurrent invocations from replacing each other's process records.
|
||||
mkdir -p "$dir"
|
||||
exec 9>"$dir/stack.lock"
|
||||
flock -n 9 || { echo "Another e2e stack command is running" >&2; exit 1; }
|
||||
|
||||
case ${1:-} in
|
||||
start) start ;;
|
||||
stop) stop ;;
|
||||
|
||||
@@ -22,12 +22,12 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/toolbuilder"
|
||||
)
|
||||
|
||||
func (b *server) setupCurators(ctx context.Context) {
|
||||
func (b *server) setupCurators(ctx context.Context) bool {
|
||||
log := b.log.With("component", "curator")
|
||||
model, err := b.chatModels.ModelFor(ctx)
|
||||
if err != nil {
|
||||
log.Warn("curators disabled: chat model unavailable", "err", err)
|
||||
return
|
||||
log.Warn("curators disabled: chat model unavailable; configure a chat model and restart the gateway", "err", err)
|
||||
return false
|
||||
}
|
||||
skillsRoot := b.cfg.SkillsDir
|
||||
if skillsRoot == "" {
|
||||
@@ -58,6 +58,7 @@ func (b *server) setupCurators(ctx context.Context) {
|
||||
b.addCleanup(shutdownCuratorRuntime(rt, log))
|
||||
reg := b.curatorRegistry
|
||||
b.addCleanup(shutdownCuratorRegistry(reg, log))
|
||||
return true
|
||||
}
|
||||
|
||||
//nolint:contextcheck // shutdown runs after the parent context is cancelled
|
||||
@@ -174,3 +175,26 @@ func (b *server) watchCurators(ctx context.Context, version int64) error {
|
||||
func(update controlplane.AppliedCurators) error { return b.applyCurators(ctx, update.Definitions) })
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *server) startCurators(ctx context.Context) error {
|
||||
// Curators wake on this process's turns and read its conversations.
|
||||
if !b.setupCurators(ctx) {
|
||||
return nil
|
||||
}
|
||||
if err := b.curatorRuntime.Start(ctx); err != nil {
|
||||
b.log.Error("curator runtime startup", "err", err)
|
||||
}
|
||||
defs, version, err := b.controlPlane.Curators(ctx)
|
||||
if err == nil {
|
||||
err = b.applyCurators(ctx, defs)
|
||||
}
|
||||
b.applyStatus.Report(ctx, controlplane.CuratorsKind, version, err)
|
||||
if err != nil {
|
||||
b.log.Error("curator definitions apply failed", "err", err)
|
||||
}
|
||||
if err := b.watchCurators(ctx, version); err != nil {
|
||||
return fmt.Errorf("watch curators: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package archiegateway
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCuratorsWithoutChatModel(t *testing.T) {
|
||||
b := &server{log: slog.New(slog.DiscardHandler), chatModels: newChatModelManager(nil)}
|
||||
if err := b.startCurators(t.Context()); err != nil {
|
||||
t.Fatalf("unconfigured curators must not stop the gateway: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/app/controlplane"
|
||||
"github.com/samcharles93/archie-core/internal/app/servicekit"
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
@@ -65,21 +64,8 @@ func (b *server) startGatewayRuntime(ctx context.Context, actor gateway.ChatTask
|
||||
return nil, fmt.Errorf("runtime resource watches: %w", err)
|
||||
}
|
||||
b.startModelCatalogRefresh(ctx)
|
||||
// Curators wake on this process's turns and read its conversations.
|
||||
b.setupCurators(ctx)
|
||||
if err := b.curatorRuntime.Start(ctx); err != nil {
|
||||
b.log.Error("curator runtime startup", "err", err)
|
||||
}
|
||||
defs, version, err := b.controlPlane.Curators(ctx)
|
||||
if err == nil {
|
||||
err = b.applyCurators(ctx, defs)
|
||||
}
|
||||
b.applyStatus.Report(ctx, controlplane.CuratorsKind, version, err)
|
||||
if err != nil {
|
||||
b.log.Error("curator definitions apply failed", "err", err)
|
||||
}
|
||||
if err := b.watchCurators(ctx, version); err != nil {
|
||||
return nil, fmt.Errorf("watch curators: %w", err)
|
||||
if err := b.startCurators(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return contract, nil
|
||||
|
||||
Reference in new issue
Block a user