Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): harden the #825 gate context, store-log read and credentials
Alfredo Lopeze439d2c7ba91
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.ymlindex c27f9cd6e..f3c506f1d 100644--- a/.github/workflows/ci-public.yml+++ b/.github/workflows/ci-public.yml@@ -743,8 +743,11 @@ jobs:- name: Test minikube Makefile targetsrun: bash scripts/tests/test-minikube-makefile.sh- - name: Test the #825 Desktop gate context guard and report verdict- run: node scripts/tests/run-node-test-files.mjs scripts/e2e/playwright-report-gate.test.mjs+ - name: Test the #825 gate context guards, report verdict and E2E helpers+ run: >-+ node scripts/tests/run-node-test-files.mjs+ scripts/e2e/playwright-report-gate.test.mjs+ scripts/e2e/e2e-hcc-storage-layout-switch.test.mjs# make test-service-matrix fails when Makefile TEST_SERVICES and the# `test` job's service matrix above drift apart.diff --git a/Makefile b/Makefileindex eb59eb7bf..850fcc2e6 100644--- a/Makefile+++ b/Makefile@@ -1404,7 +1404,7 @@ test-e2e-stateless-suspend-wake: ## Run stateless suspend/wake E2E gate (Phase 1.PHONY: test-e2e-hcc-storage-layout-switchtest-e2e-hcc-storage-layout-switch: ## Run the #825 storage-layout gate across lifecycle switches (needs an owned branch profile, E2E_PROFILE_PORTS_ENV, E2E_DEV_LOGIN_EMAIL, forwards held)@echo "Running HCC storage-layout switch E2E gate..."- E2E_ALLOW_STATELESS_CADENCE_ACCELERATION=1 KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-hcc-storage-layout-switch.sh+ E2E_ALLOW_STATELESS_CADENCE_ACCELERATION=1 KUBECONTEXT="$${KUBECONTEXT:-$(E2E_KUBECONTEXT)}" bash scripts/e2e/e2e-hcc-storage-layout-switch.sh.PHONY: test-e2e-825-desktop-continuitytest-e2e-825-desktop-continuity: ## Run the #825 Desktop journey across stateful/stateless switches (owned branch profile, forwards held, real model turns)diff --git a/desktop-app/test/branchProfileContext.test.ts b/desktop-app/test/branchProfileContext.test.tsnew file mode 100644index 000000000..086aa955e--- /dev/null+++ b/desktop-app/test/branchProfileContext.test.ts@@ -0,0 +1,27 @@+import { describe, expect, it } from 'vitest'+import { assertBranchProfileContext } from './e2e-playwright/helpers/branchProfileContext.js'++describe('assertBranchProfileContext', () => {+ it('accepts a generated branch-scoped profile name', () => {+ expect(() =>+ assertBranchProfileContext('clerum-fix-issue-825-storage-layout-v2-569a1d53')+ ).not.toThrow()+ expect(() => assertBranchProfileContext('clerum-a-0123abcd')).not.toThrow()+ })++ it.each([+ 'minikube',+ 'clerum-test',+ 'prod',+ 'clerum',+ 'gke_eventfire-491421_us-central1-a_clerum-dev',+ 'clerum-fix-ABC-0123abcd',+ 'clerum-fix-0123abc',+ 'clerum-fix-0123abcd-extra',+ ' clerum-fix-0123abcd',+ ])('refuses %j', context => {+ expect(() => assertBranchProfileContext(context)).toThrow(+ `Context '${context}' is not a branch-scoped Minikube profile`+ )+ })+})diff --git a/desktop-app/test/e2e-playwright/helpers/branchProfileContext.ts b/desktop-app/test/e2e-playwright/helpers/branchProfileContext.tsnew file mode 100644index 000000000..b7abea96b--- /dev/null+++ b/desktop-app/test/e2e-playwright/helpers/branchProfileContext.ts@@ -0,0 +1,16 @@+/**+ * The branch-profile name shape `make` enforces for the #825 lanes+ * (`Makefile`, `^clerum-[a-z0-9][a-z0-9-]*-[0-9a-f]{8}$`). Specs that create+ * and delete cluster objects check it themselves, so a direct+ * `npx playwright test` run cannot target the shared `minikube` profile or+ * any other cluster.+ */+const BRANCH_PROFILE_RE = /^clerum-[a-z0-9][a-z0-9-]*-[0-9a-f]{8}$/++export function assertBranchProfileContext(context: string): void {+ if (!BRANCH_PROFILE_RE.test(context)) {+ throw new Error(+ `Context '${context}' is not a branch-scoped Minikube profile (expected ${BRANCH_PROFILE_RE.source}).`+ )+ }+}diff --git a/desktop-app/test/e2e-playwright/stateful-stateless-switch-continuity.spec.ts b/desktop-app/test/e2e-playwright/stateful-stateless-switch-continuity.spec.tsindex bc0f95282..9fe0893fb 100644--- a/desktop-app/test/e2e-playwright/stateful-stateless-switch-continuity.spec.ts+++ b/desktop-app/test/e2e-playwright/stateful-stateless-switch-continuity.spec.ts@@ -13,8 +13,8 @@* - `E2E_825_DESKTOP_CONTINUITY=1` opts in. Without exactly `1` the file is* skipped, so the default lane never mutates a cluster.* - `E2E_K8S_CONTEXT` (or `KUBECONTEXT`) names the branch-owned Minikube- * profile; the spec refuses any context that is not a Minikube node of that- * name.+ * profile; the spec refuses any context whose name is not branch-scoped+ * (`clerum-<branch>-<8 hex>`) or that is not a Minikube node of that name.* - `CONTROL_API_BASE_URL` (or `E2E_CONTROL_API_URL`) and the admin password* (`E2E_ADMIN_PASSWORD` / `ADMIN_PASSWORD` / `ADMIN_PASS` /* `TEST_ADMIN_PASSWORD`) are required; `TEST_ADMIN_USERNAME` defaults to@@ -37,6 +37,7 @@ import { execFile } from 'node:child_process'import { realpathSync } from 'node:fs'import nodePath from 'node:path'import { promisify } from 'node:util'+import { assertBranchProfileContext } from './helpers/branchProfileContext'import {DESKTOP_APP_ROOT,EXTERNAL_REST_API_BASE_URL,@@ -102,6 +103,7 @@ async function kubectlJson(args: string[]): Promise<any> {}async function assertMinikubeProfile(): Promise<void> {+ assertBranchProfileContext(kubeContext())const nodes = await kubectlJson(['get', 'nodes'])const names = (nodes.items ?? []).map((node: any) => node.metadata?.labels?.['minikube.k8s.io/name'] ?? ''diff --git a/scripts/e2e/e2e-hcc-storage-layout-switch.sh b/scripts/e2e/e2e-hcc-storage-layout-switch.shindex 60b97ead8..a65072046 100755--- a/scripts/e2e/e2e-hcc-storage-layout-switch.sh+++ b/scripts/e2e/e2e-hcc-storage-layout-switch.sh@@ -81,6 +81,7 @@ RUN="$(od -An -N3 -tx1 /dev/urandom | tr -d ' \n')"POD_READY_TIMEOUT="${E2E_825_POD_READY_TIMEOUT:-300}"SUSPEND_TIMEOUT="${E2E_825_SUSPEND_TIMEOUT:-300}"TURN_TIMEOUT="${E2E_825_TURN_TIMEOUT:-240}"+STORE_LOG_TIMEOUT="${E2E_825_STORE_LOG_TIMEOUT:-30}"BASE_INIT_FIXTURE="${REPO_ROOT}/host-context-controller/test/__fixtures__/base-workspace-layout-init.sh"[ -r "$BASE_INIT_FIXTURE" ] || die "missing base init fixture ${BASE_INIT_FIXTURE}"@@ -110,8 +111,16 @@ http() {HTTP_CODE="$(tail -n1 <<<"$resp")"HTTP_BODY="$(sed '$d' <<<"$resp")"}-admin() { HTTP_HEADERS=(-H "Cookie: control_ui_admin_session=${ADMIN_COOKIE}"); http "$@"; }-rpc() { HTTP_HEADERS=(-H "Authorization: Bearer ${RPC_TOKEN}"); http "$@"; }+# auth_header KIND LINE: write one header line to a 0600 file under $SCRATCH+# and print its path. Credentials reach curl through `-H @file`, never argv,+# where any local user can read them with ps.+auth_header() {+ local file="${SCRATCH}/${1}.header"+ (umask 077 && printf '%s\n' "$2" >"$file")+ printf '%s' "$file"+}+admin() { HTTP_HEADERS=(-H "@$(auth_header admin "Cookie: control_ui_admin_session=${ADMIN_COOKIE}")"); http "$@"; }+rpc() { HTTP_HEADERS=(-H "@$(auth_header rpc "Authorization: Bearer ${RPC_TOKEN}")"); http "$@"; }admin_login() {local headers="${SCRATCH}/admin-login.headers" line cookie@@ -144,7 +153,7 @@ user_login() {mint_rpc_token() {local refsrefs="$(printf '%s\n' "${CREATED_HOSTS[@]}" | jq -R . | jq -cs .)"- HTTP_HEADERS=(-H "Authorization: Bearer ${SESSION_TOKEN}")+ HTTP_HEADERS=(-H "@$(auth_header session "Authorization: Bearer ${SESSION_TOKEN}")")http POST "${EXT_BASE}/api/v1/rpc/token" "$(jq -cn --argjson refs "$refs" '{hostRefs:$refs,scopes:["host:message:invoke","host:session:read","host:status:read","host:health:read","host:wake:write","host:model:write"]}')" || true@@ -273,7 +282,7 @@ assert_pod() {return 1fiprintf '%s' "$storage" >"${SCRATCH}/${name}.storage"- db="$(store_path "$name")" || return 1+ db="$(store_path "$name")" || { fail "${name}: no store-opened log line (reason above)"; return 1; }[ "$db" = "${path}/state.db" ] || { fail "${name}: mcp-host opened ${db}, expected ${path}/state.db"; return 1; }if [ -s "${SCRATCH}/${name}.dbpath" ] && [ "$(cat "${SCRATCH}/${name}.dbpath")" != "$db" ]; thenfail "${name}: store changed across the switch: $(cat "${SCRATCH}/${name}.dbpath") -> ${db}"@@ -284,16 +293,28 @@ assert_pod() {}# store_path NAME: the database the running mcp-host opened, read from its one-# "[ConversationStore] opened" log line (kubectl logs, no exec).+# "[ConversationStore] opened" log line (kubectl logs, no exec). mcp-host+# writes the line after the worker's first answer, which can come after Pod+# Ready, so the log is re-read for up to STORE_LOG_TIMEOUT seconds. Callers+# run it inside $(...), so the reason goes to stderr and the caller records+# the FAIL.store_path() {- local pod lines+ local pod lines deadline=$((SECONDS + STORE_LOG_TIMEOUT))pod="$(jq -r '.metadata.name' <<<"$POD_JSON")"- lines="$(kctl logs "$pod" -n "$HOST_NS" -c mcp-host |- jq -Rr 'fromjson? | select(.msg == "[ConversationStore] opened") | .dbPath')" ||- { fail "${1}: could not read the mcp-host log of ${pod}"; return 1; }- [ -n "$lines" ] && [ "$(wc -l <<<"$lines" | tr -d ' ')" = 1 ] ||- { fail "${1}: expected one store-opened line in ${pod}, got: ${lines:-<none>}"; return 1; }- printf '%s' "$lines"+ while :; do+ lines="$(kctl logs "$pod" -n "$HOST_NS" -c mcp-host |+ jq -Rr 'fromjson? | select(.msg == "[ConversationStore] opened") | .dbPath')" ||+ { echo "${1}: could not read the mcp-host log of ${pod}" >&2; return 1; }+ if [ -n "$lines" ]; then+ [ "$(wc -l <<<"$lines" | tr -d ' ')" = 1 ] ||+ { echo "${1}: expected one store-opened line in ${pod}, got: ${lines}" >&2; return 1; }+ printf '%s' "$lines"+ return 0+ fi+ [ "$SECONDS" -lt "$deadline" ] ||+ { echo "${1}: expected one store-opened line in ${pod}, got: <none> after ${STORE_LOG_TIMEOUT}s" >&2; return 1; }+ sleep 1+ done}# switch_and_witness NAME STATELESS: request the switch, then require a new@@ -819,7 +840,7 @@ scenario_S7() {# RACE: concurrent model selections on new chats create one session each and# never restart the Host (A7.13).race_host() { # NAME STATELESS- local name=$1 stateless=$2 model uid restarts round i chat codes pids pods+ local name=$1 stateless=$2 model uid restarts round i chat codes pids pods rpc_headercreate_host "$name" "$stateless" || return 1wait_new_ready_pod "$name" '' "$POD_READY_TIMEOUT" || return 1assert_pod "$name" "$stateless" /workspace || return 1@@ -827,12 +848,13 @@ race_host() { # NAME STATELESSrestarts="$(jq -r '[.status.containerStatuses[] | select(.name == "mcp-host") | .restartCount] | first' <<<"$POD_JSON")"rpc GET "${RPC_BASE}/api/v1/rpc/hosts/${name}/models" || truemodel="$(jq -er '.hostDefault' <<<"$HTTP_BODY")" || { fail "${name}: models returned ${HTTP_CODE}: ${HTTP_BODY}"; return 1; }+ rpc_header="$(auth_header rpc "Authorization: Bearer ${RPC_TOKEN}")"for round in 1 2 3 4 5; dochat="e2e-825-race-${RUN}-${round}"pids=()for i in 1 2 3 4; docurl -sS -m 60 -o /dev/null -w '%{http_code}\n' -X POST "${RPC_BASE}/api/v1/rpc/hosts/${name}/model" \- -H "Authorization: Bearer ${RPC_TOKEN}" -H 'Content-Type: application/json' \+ -H "@${rpc_header}" -H 'Content-Type: application/json' \-d "$(jq -cn --arg c "$chat" --arg m "$model" '{chatId:$c,model:$m}')" >"${SCRATCH}/race-${round}-${i}" &pids+=("$!")donediff --git a/scripts/e2e/e2e-hcc-storage-layout-switch.test.mjs b/scripts/e2e/e2e-hcc-storage-layout-switch.test.mjsnew file mode 100644index 000000000..d8901d587--- /dev/null+++ b/scripts/e2e/e2e-hcc-storage-layout-switch.test.mjs@@ -0,0 +1,121 @@+import assert from 'node:assert/strict'+import { spawnSync } from 'node:child_process'+import { mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import path from 'node:path'+import test from 'node:test'+import { fileURLToPath } from 'node:url'++// Runs single helpers of e2e-hcc-storage-layout-switch.sh under bash with+// stubbed kubectl/curl, so their failure paths are checked without a cluster.++const SCRIPT = fileURLToPath(new URL('./e2e-hcc-storage-layout-switch.sh', import.meta.url))+const SOURCE = readFileSync(SCRIPT, 'utf8')++function helper(name) {+ const lines = SOURCE.split('\n')+ const start = lines.findIndex(l => l.startsWith(`${name}() {`))+ assert.notEqual(start, -1, `helper ${name} not found`)+ if (lines[start].trimEnd().endsWith('}')) return lines[start]+ const end = lines.findIndex((l, i) => i > start && l === '}')+ assert.notEqual(end, -1, `helper ${name} has no closing brace`)+ return lines.slice(start, end + 1).join('\n')+}++function bash(body, env = {}) {+ return spawnSync('bash', ['-c', body], {+ encoding: 'utf8',+ env: { PATH: process.env.PATH, ...env },+ timeout: 30_000,+ })+}++const OPENED = '{"msg":"[ConversationStore] opened","dbPath":"/workspace/state.db"}'++function runStorePath(dir, readyAfterCalls) {+ const calls = path.join(dir, 'kctl-calls')+ writeFileSync(calls, '0')+ const body = `+fail() { echo "FAIL — $*"; }+kctl() {+ local n; n=$(cat "$CALLS"); echo $((n + 1)) >"$CALLS"+ echo 'not json'+ if [ "$READY_AFTER" -ge 0 ] && [ "$n" -ge "$READY_AFTER" ]; then echo '${OPENED}'; fi+}+POD_JSON='{"metadata":{"name":"pod-1"}}' HOST_NS=e2e STORE_LOG_TIMEOUT=3+${helper('store_path')}+db="$(store_path s1)"; rc=$?+printf 'RC=%s DB=[%s]\\n' "$rc" "$db"+`+ const run = bash(body, { CALLS: calls, READY_AFTER: String(readyAfterCalls) })+ return { ...run, calls: Number(readFileSync(calls, 'utf8').trim()) }+}++test('store_path re-reads the log until the store-opened line appears', () => {+ const dir = mkdtempSync(path.join(tmpdir(), 'e2e-825-store-path-'))+ try {+ const run = runStorePath(dir, 1)+ assert.equal(run.status, 0, run.stderr)+ assert.equal(run.stdout.trim(), 'RC=0 DB=[/workspace/state.db]')+ assert.equal(run.calls, 2)+ } finally {+ rmSync(dir, { recursive: true, force: true })+ }+})++test('store_path reports its failure reason on stderr, not in the captured value', () => {+ const dir = mkdtempSync(path.join(tmpdir(), 'e2e-825-store-path-'))+ try {+ const run = runStorePath(dir, -1)+ assert.equal(run.status, 0, run.stderr)+ assert.equal(run.stdout.trim(), 'RC=1 DB=[]')+ assert.match(run.stderr, /s1: expected one store-opened line in pod-1/)+ // Witness: the log was read more than once before giving up.+ assert.ok(run.calls > 1, `kctl calls: ${run.calls}`)+ } finally {+ rmSync(dir, { recursive: true, force: true })+ }+})++test('admin and rpc send their credentials through a header file, never in curl argv', () => {+ const dir = mkdtempSync(path.join(tmpdir(), 'e2e-825-headers-'))+ try {+ const argv = path.join(dir, 'argv')+ const sent = path.join(dir, 'sent-headers')+ const body = `+curl() {+ printf '%s\\n' "$@" >>"$ARGV"+ local a; for a in "$@"; do case $a in @*) cat "\${a#@}" >>"$SENT" ;; esac; done+ cat >/dev/null; printf 'ok\\n200'+}+SCRATCH="$DIR" ADMIN_COOKIE=cookie-secret-1 RPC_TOKEN=rpc-secret-2 HTTP_HEADERS=()+${helper('auth_header')}+${helper('http')}+${helper('admin')}+${helper('rpc')}+admin GET http://127.0.0.1:1/admin && rpc GET http://127.0.0.1:2/rpc && echo "CODE=$HTTP_CODE"+`+ const run = bash(body, { DIR: dir, ARGV: argv, SENT: sent })+ assert.equal(run.status, 0, run.stderr)+ assert.equal(run.stdout.trim(), 'CODE=200')+ const args = readFileSync(argv, 'utf8')+ assert.doesNotMatch(args, /secret/)+ // Witness: both credentials did reach curl, through the files.+ assert.equal(+ readFileSync(sent, 'utf8'),+ 'Cookie: control_ui_admin_session=cookie-secret-1\nAuthorization: Bearer rpc-secret-2\n'+ )+ for (const kind of ['admin', 'rpc']) {+ assert.equal(statSync(path.join(dir, `${kind}.header`)).mode & 0o777, 0o600)+ }+ } finally {+ rmSync(dir, { recursive: true, force: true })+ }+})++test('no curl call in the script puts a Cookie or Authorization header in argv', () => {+ assert.doesNotMatch(SOURCE, /-H\s+["']?(Cookie|Authorization):/i)+ // Witness: the credentials are still sent, through auth_header.+ const uses = SOURCE.match(/auth_header (admin|session|rpc) /g) ?? []+ assert.ok(uses.length >= 4, `auth_header uses: ${uses.length}`)+})diff --git a/scripts/e2e/playwright-report-gate.test.mjs b/scripts/e2e/playwright-report-gate.test.mjsindex b5b04cdc7..c97d20d35 100644--- a/scripts/e2e/playwright-report-gate.test.mjs+++ b/scripts/e2e/playwright-report-gate.test.mjs@@ -65,6 +65,27 @@ function runDesktopTarget(context, extraEnv = {}) {})}+test('make test-e2e-hcc-storage-layout-switch keeps the caller KUBECONTEXT', () => {+ const env = {+ PATH: process.env.PATH,+ HOME: process.env.HOME,+ KUBECONTEXT: 'clerum-fix-issue-825-gate-test-0123abcd',+ E2E_PROFILE_PORTS_ENV: path.join(tmpdir(), 'playwright-report-gate-no-such-ports.env'),+ }+ const run = spawnSync(+ 'make',+ ['--no-print-directory', '-C', REPO_ROOT, 'test-e2e-hcc-storage-layout-switch'],+ { encoding: 'utf8', env, timeout: 60_000 }+ )+ assert.notEqual(run.status, 0)+ // The caller's branch context passes the context check (the Makefile+ // default MINIKUBE_PROFILE would not) and the run stops at the ports.env+ // check, before any cluster call.+ const out = `${run.stdout}${run.stderr}`+ assert.doesNotMatch(out, /select an explicit branch-scoped Minikube context/)+ assert.match(out, /provide E2E_PROFILE_PORTS_ENV from the owned branch profile/)+})+test('make test-e2e-825-desktop-continuity refuses a context that is not a branch profile', () => {const shared = runDesktopTarget('minikube')assert.notEqual(shared.status, 0)