Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/opencode/test/util/lazy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
52 changes: 52 additions & 0 deletions packages/opencode/test/util/proxied.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, string | undefined> = {}

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
Loading