|
1 | | -import { readdir, readFile } from "node:fs/promises"; |
| 1 | +import { spawnSync } from "node:child_process"; |
| 2 | +import { mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises"; |
| 3 | +import { tmpdir } from "node:os"; |
2 | 4 | import path from "node:path"; |
3 | 5 | import { describe, expect, it } from "vitest"; |
4 | 6 |
|
@@ -33,10 +35,45 @@ describe("e2e shell tempfile hygiene", () => { |
33 | 35 | }); |
34 | 36 |
|
35 | 37 | it("preserves wizard exit status when reporting failures", async () => { |
36 | | - const contents = await readFile("scripts/e2e/lib/onboard/scenario.sh", "utf8"); |
| 38 | + const tempRoot = await mkdtemp(path.join(tmpdir(), "openclaw-onboard-status-test-")); |
| 39 | + const fixturePath = path.join(tempRoot, "wizard-status.sh"); |
| 40 | + await writeFile( |
| 41 | + fixturePath, |
| 42 | + `#!/usr/bin/env bash |
| 43 | +set -euo pipefail |
| 44 | +
|
| 45 | +export OPENCLAW_ONBOARD_SCENARIO_SOURCE_ONLY=1 |
| 46 | +export OPENCLAW_ONBOARD_E2E_TMPDIR=${JSON.stringify(tempRoot)} |
| 47 | +OPENCLAW_ENTRY=node |
| 48 | +openclaw_test_state_create() { :; } |
| 49 | +source scripts/e2e/lib/onboard/scenario.sh |
| 50 | +
|
| 51 | +openclaw_e2e_run_script_with_pty() { |
| 52 | + local _command="$1" |
| 53 | + local log_path="$2" |
| 54 | + printf 'fake wizard log\\n' >"$log_path" |
| 55 | + exit 7 |
| 56 | +} |
| 57 | +
|
| 58 | +send_noop() { :; } |
37 | 59 |
|
38 | | - expect(contents).not.toContain('if ! wait "$wizard_pid"'); |
39 | | - expect(contents).toContain('wait "$wizard_pid" || wizard_status=$?'); |
| 60 | +run_wizard_cmd failing-wizard fake-state "node fake-wizard" send_noop false |
| 61 | +`, |
| 62 | + ); |
| 63 | + |
| 64 | + try { |
| 65 | + const result = spawnSync("bash", [fixturePath], { |
| 66 | + cwd: process.cwd(), |
| 67 | + encoding: "utf8", |
| 68 | + }); |
| 69 | + const output = `${result.stdout}\n${result.stderr}`; |
| 70 | + |
| 71 | + expect(result.status).toBe(7); |
| 72 | + expect(output).toContain("Wizard exited with status 7"); |
| 73 | + expect(output).toContain("fake wizard log"); |
| 74 | + } finally { |
| 75 | + await rm(tempRoot, { force: true, recursive: true }); |
| 76 | + } |
40 | 77 | }); |
41 | 78 |
|
42 | 79 | it("checks local onboarding logs for systemd noise", async () => { |
|
0 commit comments