

























@@ -6,6 +6,7 @@ import { tmpdir } from "node:os";
66import path from "node:path";
77import { describe, expect, it } from "vitest";
88import { runReleaseUserJourneyAssertion } from "../../scripts/e2e/lib/release-user-journey/assertions.mjs";
9+import { withEnvAsync } from "../../src/test-utils/env.js";
9101011const ASSERTIONS_SCRIPT = "scripts/e2e/lib/release-user-journey/assertions.mjs";
1112const DISABLE_EXPERIMENTAL_WARNING = "--disable-warning=ExperimentalWarning";
@@ -40,25 +41,6 @@ function runAssertion(
4041});
4142}
424343-async function withEnv<T>(env: Record<string, string>, callback: () => Promise<T>): Promise<T> {
44-const previous = new Map<string, string | undefined>();
45-for (const [key, value] of Object.entries(env)) {
46-previous.set(key, process.env[key]);
47-process.env[key] = value;
48-}
49-try {
50-return await callback();
51-} finally {
52-for (const [key, value] of previous) {
53-if (value === undefined) {
54-delete process.env[key];
55-} else {
56-process.env[key] = value;
57-}
58-}
59-}
60-}
61-6244async function waitUntil(matches: () => boolean, label: string): Promise<void> {
6345const startedAt = Date.now();
6446while (Date.now() - startedAt < 1000) {
@@ -301,7 +283,7 @@ describe("release user journey assertions", () => {
301283302284try {
303285await expect(
304-withEnv({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "1000" }, () =>
286+withEnvAsync({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "1000" }, () =>
305287runReleaseUserJourneyAssertion("wait-clickclack-socket", [
306288`http://127.0.0.1:${server.port}`,
307289"1",
@@ -327,7 +309,7 @@ describe("release user journey assertions", () => {
327309328310try {
329311await expect(
330-withEnv({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "1000" }, () =>
312+withEnvAsync({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "1000" }, () =>
331313runReleaseUserJourneyAssertion("post-clickclack-inbound", [
332314`http://127.0.0.1:${server.port}`,
333315"hello",
@@ -351,7 +333,7 @@ describe("release user journey assertions", () => {
351333try {
352334const startedAt = Date.now();
353335await expect(
354-withEnv({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "100" }, () =>
336+withEnvAsync({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "100" }, () =>
355337runReleaseUserJourneyAssertion("wait-clickclack-socket", [
356338`http://127.0.0.1:${server.port}`,
357339"1",
@@ -374,7 +356,7 @@ describe("release user journey assertions", () => {
374356375357try {
376358await expect(
377-withEnv({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "100ms" }, () =>
359+withEnvAsync({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "100ms" }, () =>
378360runReleaseUserJourneyAssertion("wait-clickclack-socket", [
379361`http://127.0.0.1:${server.port}`,
380362"1",
@@ -396,14 +378,14 @@ describe("release user journey assertions", () => {
396378397379try {
398380await expect(
399-withEnv({ HOME: home }, () =>
381+withEnvAsync({ HOME: home }, () =>
400382runReleaseUserJourneyAssertion("wait-clickclack-socket", ["http://127.0.0.1:9", "1e3"]),
401383),
402384).rejects.toThrow(
403385'ClickClack websocket timeout seconds must be a positive integer. Got: "1e3"',
404386);
405387await expect(
406-withEnv({ HOME: home }, () =>
388+withEnvAsync({ HOME: home }, () =>
407389runReleaseUserJourneyAssertion("wait-clickclack-reply", [
408390statePath,
409391"OPENCLAW_E2E_OK",
@@ -428,7 +410,7 @@ describe("release user journey assertions", () => {
428410429411try {
430412await expect(
431-withEnv(
413+withEnvAsync(
432414{
433415HOME: home,
434416OPENCLAW_RELEASE_USER_JOURNEY_HTTP_BODY_MAX_BYTES: "16",
@@ -456,7 +438,7 @@ describe("release user journey assertions", () => {
456438457439try {
458440await expect(
459-withEnv(
441+withEnvAsync(
460442{
461443HOME: home,
462444OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "25",
@@ -486,7 +468,7 @@ describe("release user journey assertions", () => {
486468487469try {
488470await expect(
489-withEnv(
471+withEnvAsync(
490472{
491473HOME: home,
492474OPENCLAW_RELEASE_USER_JOURNEY_HTTP_BODY_MAX_BYTES: "16bytes",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。