|
1 | | -import { test, expect, describe, afterEach, beforeEach } from "bun:test" |
| 1 | +import { test, expect, describe, afterEach, beforeEach, spyOn } from "bun:test" |
2 | 2 | import { Effect, Exit, Layer, Option } from "effect" |
3 | 3 | import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/unstable/http" |
4 | 4 | import { NodeFileSystem, NodePath } from "@effect/platform-node" |
@@ -28,6 +28,7 @@ import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner" |
28 | 28 | import { testEffect } from "../lib/effect" |
29 | 29 | import path from "path" |
30 | 30 | import fs from "fs/promises" |
| 31 | +import os from "os" |
31 | 32 | import { pathToFileURL } from "url" |
32 | 33 | import { Global } from "@opencode-ai/core/global" |
33 | 34 | import { ProjectID } from "../../src/project/schema" |
@@ -291,6 +292,20 @@ it.instance("loads config with defaults when no files exist", () => |
291 | 292 | }), |
292 | 293 | ) |
293 | 294 |
|
| 295 | +it.instance("falls back to generic username when system user info is unavailable", () => |
| 296 | + Effect.gen(function* () { |
| 297 | + const userInfo = spyOn(os, "userInfo").mockImplementation(() => { |
| 298 | + throw Object.assign(new Error("missing passwd entry"), { code: "ENOENT" }) |
| 299 | + }) |
| 300 | + try { |
| 301 | + const config = yield* Config.use.get() |
| 302 | + expect(config.username).toBe("user") |
| 303 | + } finally { |
| 304 | + userInfo.mockRestore() |
| 305 | + } |
| 306 | + }), |
| 307 | +) |
| 308 | + |
294 | 309 | it.effect("creates global jsonc config with schema when no global configs exist", () => |
295 | 310 | withGlobalConfig({}, ({ dir }) => |
296 | 311 | Effect.gen(function* () { |
|
0 commit comments