diff --git a/.github/workflows/e2e-vitest-scenarios.yaml b/.github/workflows/e2e-vitest-scenarios.yaml index 174b24ae263..a34e44b6de2 100644 --- a/.github/workflows/e2e-vitest-scenarios.yaml +++ b/.github/workflows/e2e-vitest-scenarios.yaml @@ -40,7 +40,7 @@ jobs: SCENARIOS: ${{ inputs.scenarios }} run: | set -euo pipefail - allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest" + allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,skill-agent-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest" if [ -n "${JOBS}" ] && [ -n "${SCENARIOS}" ]; then echo "::error::Use either scenarios or jobs, not both." >&2 exit 1 @@ -93,12 +93,12 @@ jobs: SCENARIOS: ${{ inputs.scenarios }} run: | set -euo pipefail - allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest" + allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,skill-agent-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest" args=(--emit-live-matrix) matrix="" hermes_selected=false registry_scenarios=() - free_standing_scenarios=(openshell-version-pin onboard-negative-paths inference-routing runtime-overrides hermes-e2e hermes-root-entrypoint-smoke network-policy rebuild-openclaw token-rotation openclaw-tui-chat-correlation double-onboard issue-4434-tui-unreachable-inference model-router-provider-routed-inference) + free_standing_scenarios=(openshell-version-pin onboard-negative-paths skill-agent inference-routing runtime-overrides hermes-e2e hermes-root-entrypoint-smoke network-policy rebuild-openclaw token-rotation openclaw-tui-chat-correlation double-onboard issue-4434-tui-unreachable-inference model-router-provider-routed-inference) is_free_standing_scenario() { local id="$1" local known @@ -363,6 +363,108 @@ jobs: if-no-files-found: ignore retention-days: 14 + # Focused coverage for test/e2e/test-skill-agent-e2e.sh's live skill + # injection + real OpenClaw agent-turn contract. The retained legacy bash + # lane remains in nightly-e2e.yaml until #5098 Phase 11 shell retirement. + skill-agent-vitest: + needs: [validate-jobs, generate-matrix] + if: ${{ (inputs.jobs == '' && inputs.scenarios == '') || contains(format(',{0},', inputs.jobs), ',skill-agent-vitest,') || contains(format(',{0},', inputs.scenarios), ',skill-agent,') }} + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + E2E_ARTIFACT_DIR: ${{ github.workspace }}/e2e-artifacts/vitest/skill-agent + NEMOCLAW_CLI_BIN: ${{ github.workspace }}/bin/nemoclaw.js + NEMOCLAW_RUN_E2E_SCENARIOS: "1" + steps: + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + persist-credentials: false + + - name: Authenticate to Docker Hub + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + shell: bash + run: | + set -euo pipefail + if [[ -z "${DOCKERHUB_USERNAME}" || -z "${DOCKERHUB_TOKEN}" ]]; then + echo "::notice::Docker Hub credentials not configured; continuing with anonymous pulls." + exit 0 + fi + login_succeeded=0 + for attempt in 1 2 3; do + if echo "${DOCKERHUB_TOKEN}" | timeout 30s docker login docker.io --username "${DOCKERHUB_USERNAME}" --password-stdin; then + login_succeeded=1 + break + fi + if [[ "$attempt" -lt 3 ]]; then + echo "::warning::Docker Hub login attempt ${attempt} failed; retrying." + sleep 5 + fi + done + if [[ "$login_succeeded" -ne 1 ]]; then + echo "::warning::Docker Hub login failed after 3 attempts; continuing with anonymous pulls." + fi + + - name: Set up Node + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.0.0 + with: + node-version: 22 + cache: npm + + - name: Install root dependencies + run: npm ci --ignore-scripts + + - name: Build CLI + run: npm run build:cli + + - name: Install OpenShell CLI + # The migrated skill-agent lane invokes helper scripts that call + # `openshell` after the repo CLI onboard command has returned. Install + # and resolve OpenShell in the workflow parent so PATH/OPENSHELL_BIN is + # available to both Vitest and the bash helpers. + run: bash scripts/install-openshell.sh + + - name: Run skill-agent live test + env: + NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }} + run: | + set -euo pipefail + export PATH="$HOME/.local/bin:$HOME/.npm-global/bin:$PATH" + if command -v openshell >/dev/null 2>&1; then + OPENSHELL_BIN="$(command -v openshell)" + elif [ -x "$HOME/.local/bin/openshell" ]; then + OPENSHELL_BIN="$HOME/.local/bin/openshell" + else + echo "::error::OpenShell CLI not found after install" + ls -la /usr/local/bin/openshell "$HOME/.local/bin/openshell" 2>&1 || true + exit 1 + fi + export OPENSHELL_BIN + echo "Using OPENSHELL_BIN=$OPENSHELL_BIN" + "$OPENSHELL_BIN" --version + npx vitest run --project e2e-scenarios-live \ + test/e2e-scenario/live/skill-agent.test.ts \ + --silent=false --reporter=default + + - name: Upload skill-agent artifacts + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: e2e-vitest-scenarios-skill-agent + path: | + e2e-artifacts/vitest/skill-agent/*/artifact-summary.json + e2e-artifacts/vitest/skill-agent/*/cleanup.json + e2e-artifacts/vitest/skill-agent/*/cleanup-skill-agent-summary.json + e2e-artifacts/vitest/skill-agent/*/scenario.json + e2e-artifacts/vitest/skill-agent/*/scenario-result.json + e2e-artifacts/vitest/skill-agent/*/shell/*.result.json + e2e-artifacts/vitest/skill-agent/*/shell/*.stdout.txt + e2e-artifacts/vitest/skill-agent/*/shell/*.stderr.txt + include-hidden-files: false + if-no-files-found: ignore + retention-days: 14 + hermes-root-entrypoint-smoke-vitest: needs: [validate-jobs, generate-matrix] if: ${{ needs.generate-matrix.result == 'success' && ((inputs.jobs == '' && inputs.scenarios == '') || contains(format(',{0},', inputs.jobs), ',hermes-root-entrypoint-smoke-vitest,') || contains(format(',{0},', inputs.scenarios), ',hermes-root-entrypoint-smoke,')) }} @@ -1390,6 +1492,7 @@ jobs: live-scenarios, openshell-version-pin-vitest, onboard-negative-paths-vitest, + skill-agent-vitest, inference-routing-vitest, credential-migration-vitest, runtime-overrides-vitest, diff --git a/test/e2e-scenario/live/skill-agent.test.ts b/test/e2e-scenario/live/skill-agent.test.ts new file mode 100644 index 00000000000..7aea5b070fa --- /dev/null +++ b/test/e2e-scenario/live/skill-agent.test.ts @@ -0,0 +1,414 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import path from "node:path"; +import { describe, it } from "vitest"; +import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; +import { + type SandboxClient, + trustedSandboxShellScript, + validateSandboxName, +} from "../fixtures/clients/sandbox.ts"; +import { expect, test } from "../fixtures/e2e-test.ts"; +import { shouldRunLiveE2EScenarios } from "../fixtures/live-project-gate.ts"; + +// Focused Vitest live replacement coverage for test/e2e/test-skill-agent-e2e.sh. +// Keep this as a direct live test: the legacy contract is skill fixture +// injection into a real OpenClaw sandbox plus an agent turn that must read +// SKILL.md and return the verification token. The retained legacy bash lane +// remains in nightly-e2e.yaml until #5098 Phase 11 shell retirement. + +const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); +const CLI_ENTRYPOINT = path.join(REPO_ROOT, "bin", "nemoclaw.js"); +const ADD_SKILL_SCRIPT = path.join( + REPO_ROOT, + "test", + "e2e", + "e2e-cloud-experimental", + "features", + "skill", + "add-sandbox-skill.sh", +); +const VERIFY_SKILL_SCRIPT = path.join( + REPO_ROOT, + "test", + "e2e", + "e2e-cloud-experimental", + "features", + "skill", + "verify-sandbox-skill-via-agent.sh", +); +const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-skill-agent"; +validateSandboxName(SANDBOX_NAME); +const SKILL_ID = "skill-smoke-fixture"; +const VERIFY_PHRASE = "SKILL_SMOKE_VERIFY_K9X2"; +const ONBOARD_TIMEOUT_MS = 20 * 60_000; +const AGENT_VERIFY_TIMEOUT_MS = 4 * 60_000; +const MAX_ATTEMPTS = Number.parseInt(process.env.E2E_SKILL_AGENT_MAX_ATTEMPTS ?? "3", 10); +const RETRY_SLEEP_MS = + Number.parseInt(process.env.E2E_SKILL_AGENT_RETRY_SLEEP_SEC ?? "15", 10) * 1_000; + +process.env.NEMOCLAW_CLI_BIN ??= CLI_ENTRYPOINT; + +function resultText(result: { stdout: string; stderr: string }): string { + return [result.stdout, result.stderr].filter(Boolean).join("\n"); +} + +function sleep(ms: number): Promise { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + +function shellQuote(value: string): string { + return `'${value.replaceAll("'", `'\\''`)}'`; +} + +function isExternalAgentVerificationFlake(text: string): boolean { + // Only provider/model/transport timeout signatures are skippable, and only + // after the fixture is proven present. OpenClaw tool/runtime errors must fail + // this migration guard because the contract is that the real agent can read + // SKILL.md and return the token. This tolerance can be narrowed once the live + // provider/agent turn is consistently non-429/non-timeout in scheduled runs. + return /LLM idle timeout|request timed out|fetch timeout|model did not produce a response|ssh\/agent exit 124|exit 124|HTTP 429|\b429\b|rate[- ]?limit|quota|temporarily unavailable/i.test( + text, + ); +} + +function isAgentVerificationFailClosed(text: string): boolean { + // Preserve the existing helper's fail-closed ordering: a non-zero helper + // result that reports tool/security/runtime failure must not be turned into + // success just because the agent transcript also echoed the token. + return /SsrFBlockedError|Blocked hostname|Blocked: resolves to|transport error|provider error|ECONNREFUSED|EAI_AGAIN|gateway unavailable/i.test( + text, + ); +} + +function shouldSkipExternalAgentVerificationFailure( + text: string, + fixturePresent: boolean, +): boolean { + return ( + fixturePresent && !isAgentVerificationFailClosed(text) && isExternalAgentVerificationFlake(text) + ); +} + +function isExternalProviderValidationFailure(text: string): boolean { + // Onboarding can fail before sandbox creation when the external NVIDIA + // endpoint validation is rate-limited or unavailable. Treat only those + // live-service states as inconclusive; repo-local onboarding errors still + // fail. This can be narrowed when endpoint validation stops producing + // intermittent 429/timeout failures in scheduled live runs. + return ( + /NVIDIA Endpoints endpoint validation failed/i.test(text) && + /HTTP 429|rate limit|quota|temporarily unavailable|timed out|timeout/i.test(text) + ); +} + +function agentSectionContainsToken(agentOutput: string): boolean { + const match = agentOutput.match(/--- agent stdout\/stderr[\s\S]*?--- end ---/); + if (!match) return false; + const collapsed = match[0].replace(/[\n\r`"']/g, "").toLowerCase(); + return collapsed.includes(VERIFY_PHRASE.toLowerCase()); +} + +function buildVerifySkillFixtureScript(): string { + // OpenShell rejects newline-bearing command args, so keep this readable as + // discrete clauses while emitting a single-line `sh -lc` script. + const skillPaths = [ + `/sandbox/.openclaw/skills/${SKILL_ID}/SKILL.md`, + `\${HOME:-/home/sandbox}/.openclaw/skills/${SKILL_ID}/SKILL.md`, + `/home/sandbox/.openclaw/skills/${SKILL_ID}/SKILL.md`, + `/home/openclaw/.openclaw/skills/${SKILL_ID}/SKILL.md`, + ]; + return [ + `token=${shellQuote(VERIFY_PHRASE)}`, + `skill=${shellQuote(SKILL_ID)}`, + "found=0", + `for path in ${skillPaths.map(shellQuote).join(" ")}; do if [ -f "$path" ] && grep -Fq "$token" "$path"; then echo "SKILL_TOKEN_PATH=$path"; found=1; fi; done`, + 'test "$found" = 1', + ].join("; "); +} + +async function verifySkillFixturePresent( + sandbox: SandboxClient, + sandboxName: string, +): Promise { + const result = await sandbox.execShell( + sandboxName, + trustedSandboxShellScript(buildVerifySkillFixtureScript()), + { + artifactName: "verify-skill-fixture-present", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }, + ); + return result.exitCode === 0; +} + +async function ignoreCleanupError(run: () => Promise): Promise { + try { + await run(); + } catch { + // Best-effort cleanup only; the test may be running before OpenShell exists + // or after onboarding already removed part of the runtime state. + } +} + +describe("skill-agent live test local classifiers", () => { + it("does not treat helper fail-closed output as a skippable provider flake", () => { + const output = `--- agent stdout/stderr\nSsrFBlockedError\n${VERIFY_PHRASE}\n--- end ---`; + + expect(isAgentVerificationFailClosed(output)).toBe(true); + expect(shouldSkipExternalAgentVerificationFailure(output, true)).toBe(false); + }); + + it("skips only timeout-like agent verification failures after fixture presence is proven", () => { + const timeoutOutput = `--- agent stdout/stderr\nLLM idle timeout\n--- end ---`; + + expect(shouldSkipExternalAgentVerificationFailure(timeoutOutput, false)).toBe(false); + expect(shouldSkipExternalAgentVerificationFailure(timeoutOutput, true)).toBe(true); + expect(shouldSkipExternalAgentVerificationFailure("require is not defined", true)).toBe(false); + expect(shouldSkipExternalAgentVerificationFailure("HTTP 429 rate limit", true)).toBe(true); + expect( + shouldSkipExternalAgentVerificationFailure("SsrFBlockedError plus request timed out", true), + ).toBe(false); + }); + + it("skips only NVIDIA endpoint validation outages during onboarding", () => { + expect( + isExternalProviderValidationFailure( + "NVIDIA Endpoints endpoint validation failed.\nChat Completions API validation returned HTTP 429", + ), + ).toBe(true); + expect(isExternalProviderValidationFailure("local docker preflight timed out")).toBe(false); + expect( + isExternalProviderValidationFailure("NVIDIA Endpoints endpoint validation failed."), + ).toBe(false); + }); + + it("matches the token only inside the delimited agent section", () => { + expect(agentSectionContainsToken(`helper echoed ${VERIFY_PHRASE}`)).toBe(false); + expect( + agentSectionContainsToken(`--- agent stdout/stderr\n\`${VERIFY_PHRASE}\`\n--- end ---`), + ).toBe(true); + }); +}); + +const runSkillAgentTest = shouldRunLiveE2EScenarios() ? test : test.skip; + +runSkillAgentTest( + "skill-agent: injected sandbox skill is read by a real OpenClaw agent turn", + async ({ artifacts, cleanup, host, sandbox, secrets, skip }) => { + expect( + fs.existsSync(CLI_ENTRYPOINT), + "run `npm run build:cli` before live repo CLI scenarios", + ).toBe(true); + expect(fs.existsSync(ADD_SKILL_SCRIPT), `missing skill add helper: ${ADD_SKILL_SCRIPT}`).toBe( + true, + ); + expect( + fs.existsSync(VERIFY_SKILL_SCRIPT), + `missing skill verify helper: ${VERIFY_SKILL_SCRIPT}`, + ).toBe(true); + + const docker = await host.command("docker", ["info"], { + artifactName: "prereq-docker-info-skill-agent", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }); + if (docker.exitCode !== 0) { + if (process.env.GITHUB_ACTIONS === "true") { + throw new Error(`Docker is required for skill-agent E2E: ${resultText(docker)}`); + } + skip("Docker is required for skill-agent E2E"); + } + + const apiKey = secrets.required("NVIDIA_API_KEY"); + expect(apiKey.startsWith("nvapi-"), "NVIDIA_API_KEY must start with nvapi-").toBe(true); + + await artifacts.writeJson("scenario.json", { + id: "skill-agent", + runner: "vitest", + boundary: "direct-cli-onboard-sandbox-skill-and-agent-turn", + legacySource: "test/e2e/test-skill-agent-e2e.sh", + contract: [ + "Docker is available before onboarding", + "NVIDIA_API_KEY is present and nvapi-prefixed", + "nemoclaw onboard creates/recreates a real OpenClaw sandbox", + "skill-smoke-fixture is injected into sandbox and home skill roots", + "openclaw agent reads SKILL.md and returns SKILL_SMOKE_VERIFY_K9X2", + "provider/tool-call transport flakes only skip after the skill fixture is proven present", + ], + }); + + let sandboxProvisioned = false; + const cleanupEnv = buildAvailabilityProbeEnv(); + await ignoreCleanupError(() => + host.command("node", [CLI_ENTRYPOINT, SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "pre-cleanup-nemoclaw-destroy-skill-agent", + env: cleanupEnv, + timeoutMs: 120_000, + }), + ); + await ignoreCleanupError(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "pre-cleanup-openshell-sandbox-delete-skill-agent", + env: cleanupEnv, + timeoutMs: 60_000, + }), + ); + + cleanup.add(`destroy skill-agent sandbox ${SANDBOX_NAME}`, async () => { + const destroy = await host.command( + "node", + [CLI_ENTRYPOINT, SANDBOX_NAME, "destroy", "--yes"], + { + artifactName: "cleanup-nemoclaw-destroy-skill-agent", + env: buildAvailabilityProbeEnv(), + timeoutMs: 120_000, + }, + ); + const deleteSandbox = await sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "cleanup-openshell-sandbox-delete-skill-agent", + env: buildAvailabilityProbeEnv(), + timeoutMs: 60_000, + }); + await artifacts.writeJson("cleanup-skill-agent-summary.json", { + sandboxProvisioned, + destroyExitCode: destroy.exitCode, + deleteExitCode: deleteSandbox.exitCode, + }); + if (sandboxProvisioned && destroy.exitCode !== 0 && deleteSandbox.exitCode !== 0) { + throw new Error( + `skill-agent cleanup failed\n${resultText(destroy)}\n${resultText(deleteSandbox)}`, + ); + } + }); + + const onboard = await host.command( + "node", + [ + CLI_ENTRYPOINT, + "onboard", + "--fresh", + "--non-interactive", + "--yes", + "--yes-i-accept-third-party-software", + ], + { + artifactName: "onboard-skill-agent", + env: { + ...buildAvailabilityProbeEnv(), + NVIDIA_API_KEY: apiKey, + NEMOCLAW_AGENT: "openclaw", + NEMOCLAW_PROVIDER: "cloud", + NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, + NEMOCLAW_RECREATE_SANDBOX: "1", + // This migration targets skill injection + agent skill discovery, not + // policy rendering/enforcement. Dedicated policy E2Es own that + // boundary; skipping policies keeps this live guard focused and avoids + // conflating policy setup failures with the skill-agent contract. + NEMOCLAW_POLICY_MODE: "skip", + }, + redactionValues: [apiKey], + timeoutMs: ONBOARD_TIMEOUT_MS, + }, + ); + const onboardText = resultText(onboard); + if (onboard.exitCode !== 0 && isExternalProviderValidationFailure(onboardText)) { + await artifacts.writeJson("scenario-result.json", { + id: "skill-agent", + status: "skipped", + reason: "external-provider-validation-unavailable-before-sandbox-skill-check", + onboardExitCode: onboard.exitCode, + }); + skip("NVIDIA endpoint validation was unavailable/rate-limited during onboarding"); + } + expect(onboard.exitCode, onboardText).toBe(0); + sandboxProvisioned = true; + + const addSkill = await host.command("bash", [ADD_SKILL_SCRIPT], { + artifactName: "add-sandbox-skill-fixture", + cwd: REPO_ROOT, + env: { + ...buildAvailabilityProbeEnv(), + SANDBOX_NAME, + SKILL_ID, + SKILL_DESCRIPTION: "E2E smoke skill injected for agent verification", + }, + timeoutMs: 120_000, + }); + expect(addSkill.exitCode, resultText(addSkill)).toBe(0); + expect(addSkill.stdout).toContain(`QUERY_PATH=/sandbox/.openclaw/skills/${SKILL_ID}/SKILL.md`); + expect(addSkill.stdout).toContain("HOME_QUERY_PATH="); + expect(await verifySkillFixturePresent(sandbox, SANDBOX_NAME)).toBe(true); + + let lastAgentOutput = ""; + let agentOk = false; + let lastExitCode: number | null = null; + const attempts = Math.max(1, Number.isFinite(MAX_ATTEMPTS) ? MAX_ATTEMPTS : 3); + + for (let attempt = 1; attempt <= attempts; attempt += 1) { + const verify = await host.command("bash", [VERIFY_SKILL_SCRIPT], { + artifactName: `verify-sandbox-skill-via-agent-${attempt}`, + cwd: REPO_ROOT, + env: { + ...buildAvailabilityProbeEnv(), + NVIDIA_API_KEY: apiKey, + SANDBOX_NAME, + SKILL_ID, + VERIFY_TOKEN: VERIFY_PHRASE, + SKILL_VERIFY_SESSION_ID: `skill-agent-vitest-${process.pid}-${attempt}`, + }, + redactionValues: [apiKey], + timeoutMs: AGENT_VERIFY_TIMEOUT_MS, + }); + lastAgentOutput = resultText(verify); + lastExitCode = verify.exitCode; + if (verify.exitCode === 0) { + agentOk = true; + break; + } + if (isAgentVerificationFailClosed(lastAgentOutput)) { + break; + } + if (agentSectionContainsToken(lastAgentOutput)) { + agentOk = true; + break; + } + if (attempt < attempts) await sleep(RETRY_SLEEP_MS); + } + + if (!agentOk) { + const fixturePresent = await verifySkillFixturePresent(sandbox, SANDBOX_NAME); + if (shouldSkipExternalAgentVerificationFailure(lastAgentOutput, fixturePresent)) { + await artifacts.writeJson("scenario-result.json", { + id: "skill-agent", + status: "skipped", + reason: "external-agent-verification-flake-after-fixture-present", + lastExitCode, + }); + skip( + "agent verification inconclusive due to model/tool-call behavior; skill fixture is present", + ); + } + } + + expect( + agentOk, + `Agent did not return ${VERIFY_PHRASE}; last exit ${lastExitCode}\n${lastAgentOutput.slice(-12_000)}`, + ).toBe(true); + + await artifacts.writeJson("scenario-result.json", { + id: "skill-agent", + status: "passed", + assertions: { + dockerRunning: docker.exitCode === 0, + onboardCompleted: onboard.exitCode === 0, + skillInjected: addSkill.exitCode === 0, + agentReturnedVerificationToken: agentOk, + }, + }); + }, + 30 * 60_000, +); diff --git a/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts b/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts index c4cfe853e5c..fd23df352c5 100644 --- a/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts +++ b/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts @@ -114,6 +114,20 @@ describe("e2e-vitest-scenarios workflow boundary", () => { selectedFreeStandingJobs: ["openshell-version-pin-vitest"], registryScenarios: [], }); + expect(evaluateE2eVitestWorkflowDispatchSelectors({ scenarios: "skill-agent" })).toMatchObject({ + valid: true, + liveScenariosRuns: false, + selectedFreeStandingJobs: ["skill-agent-vitest"], + registryScenarios: [], + }); + expect( + evaluateE2eVitestWorkflowDispatchSelectors({ jobs: "skill-agent-vitest" }), + ).toMatchObject({ + valid: true, + liveScenariosRuns: false, + selectedFreeStandingJobs: ["skill-agent-vitest"], + registryScenarios: [], + }); expect( evaluateE2eVitestWorkflowDispatchSelectors({ jobs: "runtime-overrides-vitest" }), ).toMatchObject({ diff --git a/tools/e2e-scenarios/workflow-boundary.mts b/tools/e2e-scenarios/workflow-boundary.mts index 0f259f6d11b..198b6682bcc 100644 --- a/tools/e2e-scenarios/workflow-boundary.mts +++ b/tools/e2e-scenarios/workflow-boundary.mts @@ -21,6 +21,7 @@ const SELECTOR_PATTERN = /^[A-Za-z0-9_-]+(,[A-Za-z0-9_-]+)*$/; const FREE_STANDING_SCENARIO_JOBS = new Map([ ["openshell-version-pin", "openshell-version-pin-vitest"], ["onboard-negative-paths", "onboard-negative-paths-vitest"], + ["skill-agent", "skill-agent-vitest"], ["inference-routing", "inference-routing-vitest"], ["runtime-overrides", "runtime-overrides-vitest"], ["hermes-e2e", "hermes-e2e-vitest"], @@ -282,6 +283,7 @@ function validateJobsSelector(errors: string[], jobs: WorkflowRecord): void { requireRunContains(errors, validate, "allowed_jobs="); requireRunContains(errors, validate, "openshell-version-pin-vitest"); requireRunContains(errors, validate, "onboard-negative-paths-vitest"); + requireRunContains(errors, validate, "skill-agent-vitest"); requireRunContains(errors, validate, "inference-routing-vitest"); requireRunContains(errors, validate, "credential-migration-vitest"); requireRunContains(errors, validate, "runtime-overrides-vitest"); @@ -381,6 +383,110 @@ function validateOpenShellVersionPinVitestJob(errors: string[], jobs: WorkflowRe } +function validateSkillAgentVitestJob(errors: string[], jobs: WorkflowRecord): void { + const jobName = "skill-agent-vitest"; + const job = asRecord(jobs[jobName]); + if (Object.keys(job).length === 0) { + errors.push("workflow missing skill-agent-vitest job"); + return; + } + + if (job["runs-on"] !== "ubuntu-latest") { + errors.push("skill-agent-vitest job must run on ubuntu-latest"); + } + validateFreeStandingJobSelector(errors, jobs, jobName, "skill-agent"); + + const jobEnv = asRecord(job.env); + if (jobEnv.NEMOCLAW_RUN_E2E_SCENARIOS !== "1") { + errors.push("skill-agent-vitest job must set NEMOCLAW_RUN_E2E_SCENARIOS=1"); + } + if (jobEnv.E2E_ARTIFACT_DIR !== "${{ github.workspace }}/e2e-artifacts/vitest/skill-agent") { + errors.push("skill-agent-vitest job must write artifacts under e2e-artifacts/vitest/skill-agent"); + } + if (!stringValue(jobEnv.NEMOCLAW_CLI_BIN).includes("bin/nemoclaw.js")) { + errors.push("skill-agent-vitest job must point NEMOCLAW_CLI_BIN at the repo CLI"); + } + requireEnvDoesNotExposeSecret(errors, "skill-agent-vitest job", jobEnv, "NVIDIA_API_KEY"); + + const steps = asSteps(job.steps); + requireNoDispatchInputInterpolation(errors, steps); + for (const step of steps) { + if (step.name !== "Run skill-agent live test") { + requireEnvDoesNotExposeSecret( + errors, + `skill-agent-vitest step '${step.name ?? step.uses ?? ""}'`, + asRecord(step.env), + "NVIDIA_API_KEY", + ); + } + } + + const checkout = steps.find((step) => stringValue(step.uses).startsWith("actions/checkout@")); + if (!checkout) errors.push("skill-agent-vitest job missing checkout step"); + requireFullShaAction(errors, checkout, "skill-agent-vitest checkout"); + if (asRecord(checkout?.with)["persist-credentials"] !== false) { + errors.push("skill-agent-vitest checkout step must set persist-credentials=false"); + } + + const setupNode = namedStep(steps, "Set up Node"); + if (!setupNode) errors.push("skill-agent-vitest job missing step: Set up Node"); + requireFullShaAction(errors, setupNode, "skill-agent-vitest setup-node"); + + const installRootDependencies = requireJobStep(errors, jobName, steps, "Install root dependencies"); + requireRunContains(errors, installRootDependencies, "npm ci --ignore-scripts"); + + const buildCli = requireJobStep(errors, jobName, steps, "Build CLI"); + requireRunContains(errors, buildCli, "npm run build:cli"); + + const installOpenShell = requireJobStep(errors, jobName, steps, "Install OpenShell CLI"); + requireRunContains(errors, installOpenShell, "bash scripts/install-openshell.sh"); + + const runVitest = requireJobStep(errors, jobName, steps, "Run skill-agent live test"); + const runEnv = asRecord(runVitest?.env); + if (runEnv.NVIDIA_API_KEY !== "${{ secrets.NVIDIA_API_KEY }}") { + errors.push("skill-agent-vitest run step must receive NVIDIA_API_KEY from secrets"); + } + requireRunContains(errors, runVitest, 'export PATH="$HOME/.local/bin:$HOME/.npm-global/bin:$PATH"'); + requireRunContains(errors, runVitest, 'OPENSHELL_BIN="$(command -v openshell)"'); + requireRunContains(errors, runVitest, "export OPENSHELL_BIN"); + requireRunContains(errors, runVitest, "npx vitest run --project e2e-scenarios-live"); + requireRunContains(errors, runVitest, "test/e2e-scenario/live/skill-agent.test.ts"); + + const upload = requireJobStep(errors, jobName, steps, "Upload skill-agent artifacts"); + requireFullShaAction(errors, upload, "skill-agent-vitest upload-artifact"); + const uploadWith = asRecord(upload?.with); + if (uploadWith.name !== "e2e-vitest-scenarios-skill-agent") { + errors.push("skill-agent-vitest artifact upload name must be stable"); + } + const uploadPath = stringValue(uploadWith.path); + for (const expected of [ + "e2e-artifacts/vitest/skill-agent/*/artifact-summary.json", + "e2e-artifacts/vitest/skill-agent/*/cleanup.json", + "e2e-artifacts/vitest/skill-agent/*/cleanup-skill-agent-summary.json", + "e2e-artifacts/vitest/skill-agent/*/scenario.json", + "e2e-artifacts/vitest/skill-agent/*/scenario-result.json", + "e2e-artifacts/vitest/skill-agent/*/shell/*.result.json", + "e2e-artifacts/vitest/skill-agent/*/shell/*.stdout.txt", + "e2e-artifacts/vitest/skill-agent/*/shell/*.stderr.txt", + ]) { + requireUploadPathContains(errors, uploadPath, expected); + } + for (const line of uploadPath.split("\n")) { + if (line.trim() === "e2e-artifacts/vitest/skill-agent/") { + errors.push("skill-agent-vitest artifact upload path must not list the whole skill-agent artifact directory"); + } + } + if (uploadWith["include-hidden-files"] !== false) { + errors.push("skill-agent-vitest artifact upload must set include-hidden-files: false"); + } + if (uploadWith["if-no-files-found"] !== "ignore") { + errors.push("skill-agent-vitest artifact upload must ignore missing fixture artifacts"); + } + if (uploadWith["retention-days"] !== 14) { + errors.push("skill-agent-vitest artifact upload retention-days must be 14"); + } +} + function validateNetworkPolicyVitestJob(errors: string[], jobs: WorkflowRecord): void { const jobName = "network-policy-vitest"; const job = asRecord(jobs[jobName]); @@ -1683,6 +1789,7 @@ export function validateE2eVitestScenariosWorkflowBoundary( validateOpenShellVersionPinVitestJob(errors, jobs); validateOnboardNegativePathsVitestJob(errors, jobs); + validateSkillAgentVitestJob(errors, jobs); validateFreeStandingJobSelector(errors, jobs, "credential-migration-vitest"); validateFreeStandingJobSelector(errors, jobs, "inference-routing-vitest", "inference-routing"); validateRuntimeOverridesVitestJob(errors, jobs); @@ -1718,6 +1825,7 @@ export function validateE2eVitestScenariosWorkflowBoundary( "live-scenarios", "openshell-version-pin-vitest", "onboard-negative-paths-vitest", + "skill-agent-vitest", "inference-routing-vitest", "credential-migration-vitest", "runtime-overrides-vitest",