From 0ac0b71f3c3ee053fb08f6fd1fd6c1c7554f1f9c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Mar 2026 04:15:01 +0000 Subject: [PATCH] =?UTF-8?q?test:=20lazy=20utility=20and=20credential-store?= =?UTF-8?q?=20=E2=80=94=20error=20retry,=20reset,=20sensitive=20field=20co?= =?UTF-8?q?verage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) https://claude.ai/code/session_01WoqeutgfwXNcktweCKoLwd --- .../test/altimate/connections.test.ts | 11 +++++ packages/opencode/test/util/lazy.test.ts | 43 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/packages/opencode/test/altimate/connections.test.ts b/packages/opencode/test/altimate/connections.test.ts index 2fae89c911..c82fdba4fd 100644 --- a/packages/opencode/test/altimate/connections.test.ts +++ b/packages/opencode/test/altimate/connections.test.ts @@ -248,6 +248,17 @@ describe("CredentialStore", () => { expect(CredentialStore.isSensitiveField("authenticator")).toBe(false) }) + // altimate_change start — cover remaining SENSITIVE_FIELDS entries not in the test above + test("isSensitiveField covers BigQuery, SSL, and SSH credential fields", () => { + expect(CredentialStore.isSensitiveField("credentials_json")).toBe(true) + expect(CredentialStore.isSensitiveField("keyfile_json")).toBe(true) + expect(CredentialStore.isSensitiveField("ssl_key")).toBe(true) + expect(CredentialStore.isSensitiveField("ssl_cert")).toBe(true) + expect(CredentialStore.isSensitiveField("ssl_ca")).toBe(true) + expect(CredentialStore.isSensitiveField("ssh_password")).toBe(true) + }) + // altimate_change end + test("saveConnection strips inline private_key as sensitive", async () => { const config = { type: "snowflake", private_key: "-----BEGIN PRIVATE KEY-----\nMIIE..." } as any const { sanitized, warnings } = await CredentialStore.saveConnection("sf_keypair", config) diff --git a/packages/opencode/test/util/lazy.test.ts b/packages/opencode/test/util/lazy.test.ts index 66a08b7831..8b6292bd8b 100644 --- a/packages/opencode/test/util/lazy.test.ts +++ b/packages/opencode/test/util/lazy.test.ts @@ -34,6 +34,49 @@ describe("util.lazy", () => { expect(result1).toBe(result2) }) + // altimate_change start — test reset() and error-retry behavior + test("reset() clears cached value and re-invokes factory", () => { + let count = 0 + const getValue = lazy(() => ++count) + + expect(getValue()).toBe(1) + expect(getValue()).toBe(1) // cached + + getValue.reset() + + expect(getValue()).toBe(2) // re-invoked + expect(getValue()).toBe(2) // cached again + }) + + test("factory error is not cached — retries on next call", () => { + let shouldFail = true + const getValue = lazy(() => { + if (shouldFail) throw new Error("transient failure") + return "success" + }) + + expect(() => getValue()).toThrow("transient failure") + + shouldFail = false + expect(getValue()).toBe("success") // retries and succeeds + expect(getValue()).toBe("success") // now cached + }) + + test("reset() after error allows fresh initialization", () => { + let attempt = 0 + const getValue = lazy(() => { + attempt++ + if (attempt === 1) throw new Error("first call fails") + return `attempt-${attempt}` + }) + + expect(() => getValue()).toThrow("first call fails") + + getValue.reset() + expect(getValue()).toBe("attempt-2") + }) + // altimate_change end + test("should work with different return types", () => { const lazyString = lazy(() => "string") const lazyNumber = lazy(() => 123)