Skip to content

Commit 0ac0b71

Browse files
committed
test: lazy utility and credential-store — error retry, reset, sensitive field coverage
Cover untested behaviors in lazy() (error non-caching and reset) that power shell detection, plus complete isSensitiveField unit coverage for BigQuery/SSL/SSH fields. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> https://claude.ai/code/session_01WoqeutgfwXNcktweCKoLwd
1 parent 9ba2114 commit 0ac0b71

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎packages/opencode/test/altimate/connections.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ describe("CredentialStore", () => {
248248
expect(CredentialStore.isSensitiveField("authenticator")).toBe(false)
249249
})
250250

251+
// altimate_change start — cover remaining SENSITIVE_FIELDS entries not in the test above
252+
test("isSensitiveField covers BigQuery, SSL, and SSH credential fields", () => {
253+
expect(CredentialStore.isSensitiveField("credentials_json")).toBe(true)
254+
expect(CredentialStore.isSensitiveField("keyfile_json")).toBe(true)
255+
expect(CredentialStore.isSensitiveField("ssl_key")).toBe(true)
256+
expect(CredentialStore.isSensitiveField("ssl_cert")).toBe(true)
257+
expect(CredentialStore.isSensitiveField("ssl_ca")).toBe(true)
258+
expect(CredentialStore.isSensitiveField("ssh_password")).toBe(true)
259+
})
260+
// altimate_change end
261+
251262
test("saveConnection strips inline private_key as sensitive", async () => {
252263
const config = { type: "snowflake", private_key: "-----BEGIN PRIVATE KEY-----\nMIIE..." } as any
253264
const { sanitized, warnings } = await CredentialStore.saveConnection("sf_keypair", config)

‎packages/opencode/test/util/lazy.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,49 @@ describe("util.lazy", () => {
3434
expect(result1).toBe(result2)
3535
})
3636

37+
// altimate_change start — test reset() and error-retry behavior
38+
test("reset() clears cached value and re-invokes factory", () => {
39+
let count = 0
40+
const getValue = lazy(() => ++count)
41+
42+
expect(getValue()).toBe(1)
43+
expect(getValue()).toBe(1) // cached
44+
45+
getValue.reset()
46+
47+
expect(getValue()).toBe(2) // re-invoked
48+
expect(getValue()).toBe(2) // cached again
49+
})
50+
51+
test("factory error is not cached — retries on next call", () => {
52+
let shouldFail = true
53+
const getValue = lazy(() => {
54+
if (shouldFail) throw new Error("transient failure")
55+
return "success"
56+
})
57+
58+
expect(() => getValue()).toThrow("transient failure")
59+
60+
shouldFail = false
61+
expect(getValue()).toBe("success") // retries and succeeds
62+
expect(getValue()).toBe("success") // now cached
63+
})
64+
65+
test("reset() after error allows fresh initialization", () => {
66+
let attempt = 0
67+
const getValue = lazy(() => {
68+
attempt++
69+
if (attempt === 1) throw new Error("first call fails")
70+
return `attempt-${attempt}`
71+
})
72+
73+
expect(() => getValue()).toThrow("first call fails")
74+
75+
getValue.reset()
76+
expect(getValue()).toBe("attempt-2")
77+
})
78+
// altimate_change end
79+
3780
test("should work with different return types", () => {
3881
const lazyString = lazy(() => "string")
3982
const lazyNumber = lazy(() => 123)

0 commit comments

Comments
 (0)