diff --git a/packages/opencode/test/util/lazy.test.ts b/packages/opencode/test/util/lazy.test.ts index 66a08b783..cb2c847ff 100644 --- a/packages/opencode/test/util/lazy.test.ts +++ b/packages/opencode/test/util/lazy.test.ts @@ -47,4 +47,44 @@ describe("util.lazy", () => { expect(lazyNull()).toBe(null) expect(lazyUndefined()).toBe(undefined) }) + + // altimate_change start — error recovery and reset tests + test("retries initialization after a throw (does not cache failures)", () => { + let attempt = 0 + const lazyValue = lazy(() => { + attempt++ + if (attempt === 1) throw new Error("init failed") + return "recovered" + }) + + expect(() => lazyValue()).toThrow("init failed") + expect(attempt).toBe(1) + + // Second call should retry, not return cached error + const result = lazyValue() + expect(result).toBe("recovered") + expect(attempt).toBe(2) + + // Third call should use cached value + const result2 = lazyValue() + expect(result2).toBe("recovered") + expect(attempt).toBe(2) + }) + + test("reset() allows re-initialization", () => { + let callCount = 0 + const lazyValue = lazy(() => { + callCount++ + return callCount + }) + + expect(lazyValue()).toBe(1) + expect(lazyValue()).toBe(1) + + lazyValue.reset() + + expect(lazyValue()).toBe(2) + expect(lazyValue()).toBe(2) + }) + // altimate_change end }) diff --git a/packages/opencode/test/util/proxied.test.ts b/packages/opencode/test/util/proxied.test.ts new file mode 100644 index 000000000..a268bb620 --- /dev/null +++ b/packages/opencode/test/util/proxied.test.ts @@ -0,0 +1,52 @@ +// altimate_change start — tests for proxied() corporate proxy detection +import { describe, test, expect, beforeEach, afterEach } from "bun:test" +import { proxied } from "../../src/util/proxied" + +describe("proxied(): corporate proxy detection", () => { + const PROXY_VARS = ["HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"] + const saved: Record = {} + + beforeEach(() => { + for (const v of PROXY_VARS) { + saved[v] = process.env[v] + delete process.env[v] + } + }) + + afterEach(() => { + for (const v of PROXY_VARS) { + if (saved[v] !== undefined) process.env[v] = saved[v] + else delete process.env[v] + } + }) + + test("returns false when no proxy env vars are set", () => { + expect(proxied()).toBe(false) + }) + + test("returns true when HTTP_PROXY is set", () => { + process.env.HTTP_PROXY = "http://proxy.corp.com:8080" + expect(proxied()).toBe(true) + }) + + test("returns true when HTTPS_PROXY is set", () => { + process.env.HTTPS_PROXY = "http://proxy.corp.com:8443" + expect(proxied()).toBe(true) + }) + + test("returns true when lowercase http_proxy is set", () => { + process.env.http_proxy = "http://proxy.corp.com:8080" + expect(proxied()).toBe(true) + }) + + test("returns true when lowercase https_proxy is set", () => { + process.env.https_proxy = "http://proxy.corp.com:8443" + expect(proxied()).toBe(true) + }) + + test("returns false when env var is set to empty string", () => { + process.env.HTTP_PROXY = "" + expect(proxied()).toBe(false) + }) +}) +// altimate_change end