refactor(test): reuse env helper in gateway status e2e

This commit is contained in:
Peter Steinberger
2026-02-21 18:34:59 +00:00
parent 807968e4df
commit ec8288e9b8

View File

@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest";
import { withEnvAsync } from "../test-utils/env.js";
const loadConfig = vi.fn(() => ({
gateway: {
@@ -133,16 +134,6 @@ function createRuntimeCapture() {
return { runtime, runtimeLogs, runtimeErrors };
}
async function withUserEnv(user: string, fn: () => Promise<void>) {
const originalUser = process.env.USER;
try {
process.env.USER = user;
await fn();
} finally {
process.env.USER = originalUser;
}
}
describe("gateway-status command", () => {
it("prints human output by default", async () => {
const { runtime, runtimeLogs, runtimeErrors } = createRuntimeCapture();
@@ -206,7 +197,7 @@ describe("gateway-status command", () => {
it("skips invalid ssh-auto discovery targets", async () => {
const { runtime } = createRuntimeCapture();
await withUserEnv("steipete", async () => {
await withEnvAsync({ USER: "steipete" }, async () => {
loadConfig.mockReturnValueOnce({
gateway: {
mode: "remote",
@@ -234,7 +225,7 @@ describe("gateway-status command", () => {
it("infers SSH target from gateway.remote.url and ssh config", async () => {
const { runtime } = createRuntimeCapture();
await withUserEnv("steipete", async () => {
await withEnvAsync({ USER: "steipete" }, async () => {
loadConfig.mockReturnValueOnce({
gateway: {
mode: "remote",
@@ -268,7 +259,7 @@ describe("gateway-status command", () => {
it("falls back to host-only when USER is missing and ssh config is unavailable", async () => {
const { runtime } = createRuntimeCapture();
await withUserEnv("", async () => {
await withEnvAsync({ USER: "" }, async () => {
loadConfig.mockReturnValueOnce({
gateway: {
mode: "remote",