Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(ci): name the Tier 2 provider-key skip instead of reporting a keyed run
garrytanae75f8fb060e
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.ymlindex 77fe92aa5c..9527ded211 100644--- a/.github/workflows/e2e.yml+++ b/.github/workflows/e2e.yml@@ -685,6 +685,9 @@ jobs:retention-days: 14if-no-files-found: warnoverwrite: true+ # Tier 2 runs keyless by decision (no paid spend): its bare `bun test`+ # step does not set GBRAIN_TEST_KEEP_PROVIDER_KEYS, so the test preload+ # strips the keys and this notice names the skip.- name: Provider-key coverage noticeif: ${{ !cancelled() }}env:@@ -971,6 +974,8 @@ jobs:env:OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}+ # scripts/run-e2e.sh passes the keys to its tests (it exports this).+ GBRAIN_TEST_KEEP_PROVIDER_KEYS: '1'run: bash scripts/e2e-provider-key-notice.sh- name: Upload coverageif: always()diff --git a/scripts/e2e-provider-key-notice.sh b/scripts/e2e-provider-key-notice.shindex 7f81fd8fd8..d4df375b4f 100755--- a/scripts/e2e-provider-key-notice.sh+++ b/scripts/e2e-provider-key-notice.sh@@ -3,26 +3,39 @@## e2e.yml passes the OPENAI_API_KEY / ANTHROPIC_API_KEY repo secrets to its# key-gated jobs; when a secret is empty, the key-gated tests self-skip and-# the job still goes green. This step says so in the log (::warning::) and the-# step summary, with the owner-only fix, so a green run is never read as-# keyed coverage. Exit 0 always: it reports, it does not gate.+# the job still goes green. The test preload (test/helpers/provider-keys-preload.ts)+# also strips both keys from every test process unless the step that ran the+# tests set GBRAIN_TEST_KEEP_PROVIDER_KEYS=1 (scripts/run-e2e.sh sets it; a+# bare `bun test` step such as Tier 2 does not). The workflow passes this step+# the value the test step had, so a run whose keys were stripped is never+# reported as keyed. This step says what happened in the log (::warning::) and+# the step summary. Exit 0 always: it reports, it does not gate.set -euo pipefail+summary="${GITHUB_STEP_SUMMARY:-/dev/null}"missing=()[ -n "${OPENAI_API_KEY:-}" ] || missing+=(OPENAI_API_KEY)[ -n "${ANTHROPIC_API_KEY:-}" ] || missing+=(ANTHROPIC_API_KEY)-summary="${GITHUB_STEP_SUMMARY:-/dev/null}"-if [ "${#missing[@]}" -eq 0 ]; then- echo "Provider secrets set (OPENAI_API_KEY, ANTHROPIC_API_KEY): key-gated E2E tests ran keyed."+if [ "${#missing[@]}" -gt 0 ]; then+ fix=$(printf 'gh secret set %s; ' "${missing[@]}")+ echo "::warning::Key-gated E2E tests skipped for missing keys: empty secret(s) ${missing[*]}. Why: only the repo owner can set secrets. Fix (owner-only): ${fix%; }"+ {+ echo "## Key-gated E2E tests skipped for missing keys"+ echo "Empty secret(s): ${missing[*]}. Tests gated on these keys self-skipped, so this job's green is keyless coverage only."+ echo ""+ echo "- Fix (owner-only): \`${fix%; }\`"+ } >> "$summary"+ exit 0+fi++if [ "${GBRAIN_TEST_KEEP_PROVIDER_KEYS:-}" != "1" ]; then+ echo "::warning::Key-gated E2E tests skipped: provider keys not passed (GBRAIN_TEST_KEEP_PROVIDER_KEYS unset). The secrets are set, but the test preload stripped them, so this job's green is keyless coverage only. A keyed run spends on the providers: set GBRAIN_TEST_KEEP_PROVIDER_KEYS=1 on the test step only with that spend approved."+ {+ echo "## Key-gated E2E tests skipped: provider keys not passed"+ echo "GBRAIN_TEST_KEEP_PROVIDER_KEYS was unset on the test step, so the test preload stripped OPENAI_API_KEY and ANTHROPIC_API_KEY. This job's green is keyless coverage only."+ } >> "$summary"exit 0fi-fix=$(printf 'gh secret set %s; ' "${missing[@]}")-echo "::warning::Key-gated E2E tests skipped for missing keys: empty secret(s) ${missing[*]}. Why: only the repo owner can set secrets. Fix (owner-only): ${fix%; }"-{- echo "## Key-gated E2E tests skipped for missing keys"- echo "Empty secret(s): ${missing[*]}. Tests gated on these keys self-skipped, so this job's green is keyless coverage only."- echo ""- echo "- Fix (owner-only): \`${fix%; }\`"-} >> "$summary"+echo "Provider keys passed to the tests (OPENAI_API_KEY, ANTHROPIC_API_KEY, GBRAIN_TEST_KEEP_PROVIDER_KEYS=1): key-gated E2E tests ran keyed."diff --git a/test/scripts/e2e-provider-key-notice.test.ts b/test/scripts/e2e-provider-key-notice.test.tsindex 0a7323a539..0375aeecfd 100644--- a/test/scripts/e2e-provider-key-notice.test.ts+++ b/test/scripts/e2e-provider-key-notice.test.ts@@ -3,6 +3,7 @@ import { spawnSync } from 'node:child_process';import { mkdtempSync, readFileSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';+import { load } from 'js-yaml';const SCRIPT = resolve(import.meta.dir, '..', '..', 'scripts', 'e2e-provider-key-notice.sh');@@ -29,10 +30,34 @@ describe('scripts/e2e-provider-key-notice.sh', () => {expect(r.summary).toContain('## Key-gated E2E tests skipped for missing keys');});- test('both secrets set prints no warning and no summary', () => {- const r = run({ OPENAI_API_KEY: 'set', ANTHROPIC_API_KEY: 'set' });+ test('both secrets set and passed to the tests prints no warning and no summary', () => {+ const r = run({ OPENAI_API_KEY: 'set', ANTHROPIC_API_KEY: 'set', GBRAIN_TEST_KEEP_PROVIDER_KEYS: '1' });expect(r.status).toBe(0);expect(r.stdout).not.toContain('::warning::');+ expect(r.stdout).toContain('key-gated E2E tests ran keyed');expect(r.summary).toBe('');});++ test.each(['', '0'])('secrets set but stripped by the test preload (GBRAIN_TEST_KEEP_PROVIDER_KEYS=%p) is a named skip, never a keyed run', keep => {+ const r = run({ OPENAI_API_KEY: 'set', ANTHROPIC_API_KEY: 'set', GBRAIN_TEST_KEEP_PROVIDER_KEYS: keep });+ expect(r.status).toBe(0);+ expect(r.stdout).toContain('::warning::Key-gated E2E tests skipped: provider keys not passed (GBRAIN_TEST_KEEP_PROVIDER_KEYS unset).');+ expect(r.stdout).not.toContain('ran keyed');+ expect(r.summary).toContain('## Key-gated E2E tests skipped: provider keys not passed');+ });++ test('each e2e.yml notice step is told what its test step passed: the step\'s own GBRAIN_TEST_KEEP_PROVIDER_KEYS, or 1 under run-e2e.sh', () => {+ type Step = { name?: string; run?: string; env?: Record<string, string> };+ const jobs = (load(readFileSync(resolve(import.meta.dir, '..', '..', '.github', 'workflows', 'e2e.yml'), 'utf8')) as { jobs: Record<string, { steps: Step[] }> }).jobs;+ expect(readFileSync(resolve(import.meta.dir, '..', '..', 'scripts', 'run-e2e.sh'), 'utf8')).toContain('export GBRAIN_TEST_KEEP_PROVIDER_KEYS=1');+ const noticed = Object.entries(jobs).filter(([, job]) => job.steps.some(step => step.run === 'bash scripts/e2e-provider-key-notice.sh'));+ expect(noticed.map(([name]) => name).sort()).toEqual(['coverage-full-e2e', 'tier2']);+ for (const [name, job] of noticed) {+ const notice = job.steps.find(step => step.run === 'bash scripts/e2e-provider-key-notice.sh')!;+ const tests = job.steps.find(step => step.env?.OPENAI_API_KEY && step !== notice)!;+ const passed = tests.run!.includes('scripts/run-e2e.sh') ? '1' : tests.env!.GBRAIN_TEST_KEEP_PROVIDER_KEYS;+ expect(notice.env?.GBRAIN_TEST_KEEP_PROVIDER_KEYS, name).toBe(passed);+ }+ expect(jobs.tier2.steps.find(step => step.run === 'bash scripts/e2e-provider-key-notice.sh')!.env?.GBRAIN_TEST_KEEP_PROVIDER_KEYS).toBeUndefined();+ });});