From c68d7376c76b5f091ee2b9c8ca4d54c80e427786 Mon Sep 17 00:00:00 2001 From: Ben Coombs Date: Tue, 14 Apr 2026 16:27:58 +0100 Subject: [PATCH 1/2] Add regression tests for logger schema zod 3/4 compatibility Six new tests covering the logger validation path that was broken by the z.function(...).args() call removed in zod 4: - valid logger with warn + error functions accepted - valid logger with optional debug function accepted - logger === false accepted (disables logging) - logger with non-function warn rejected - logger with missing error rejected - nested logger under defaultSettings in provider schema validated All 275 tests pass under both zod ^3.24 and zod ^4.1. --- src/validation.test.ts | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/validation.test.ts b/src/validation.test.ts index efae2ef..1d05f29 100644 --- a/src/validation.test.ts +++ b/src/validation.test.ts @@ -56,6 +56,89 @@ describe('validation', () => { validateSettings(settings, logger); expect(logger.warn).toHaveBeenCalled(); }); + + describe('logger schema (zod 3/4 compatibility)', () => { + // Regression tests for https://github.com/ben-vargas/ai-sdk-provider-opencode-sdk/issues/17 + // The loggerSchema was previously built with `z.function().args().returns()` + // which was removed in zod 4. These tests exercise the settings.logger + // validation path to ensure it works across both major zod versions. + + it('should accept a valid logger with warn and error functions', () => { + const settings = { + logger: { + warn: vi.fn(), + error: vi.fn(), + }, + }; + + const result = validateSettings(settings); + expect(result.warnings).toHaveLength(0); + }); + + it('should accept a valid logger with optional debug function', () => { + const settings = { + logger: { + warn: vi.fn(), + error: vi.fn(), + debug: vi.fn(), + }, + }; + + const result = validateSettings(settings); + expect(result.warnings).toHaveLength(0); + }); + + it('should accept logger === false (disables logging)', () => { + const settings = { + logger: false as const, + }; + + const result = validateSettings(settings); + expect(result.warnings).toHaveLength(0); + }); + + it('should reject logger where warn is not a function', () => { + const settings = { + logger: { + warn: 'not a function', + error: vi.fn(), + }, + } as unknown as Parameters[0]; + + const result = validateSettings(settings); + expect( + result.warnings.some((w) => w.includes('Settings validation')) + ).toBe(true); + }); + + it('should reject logger where error is missing', () => { + const settings = { + logger: { + warn: vi.fn(), + }, + } as unknown as Parameters[0]; + + const result = validateSettings(settings); + expect( + result.warnings.some((w) => w.includes('Settings validation')) + ).toBe(true); + }); + + it('should validate nested logger under defaultSettings in provider schema', () => { + const providerSettings = { + hostname: 'localhost', + defaultSettings: { + logger: { + warn: vi.fn(), + error: vi.fn(), + }, + }, + }; + + const result = validateProviderSettings(providerSettings); + expect(result.warnings).toHaveLength(0); + }); + }); }); describe('validateProviderSettings', () => { From 2bfd3f7be9bb8af26d221150c1bc3b546670e7b0 Mon Sep 17 00:00:00 2001 From: Ben Coombs Date: Tue, 14 Apr 2026 16:29:32 +0100 Subject: [PATCH 2/2] Add CI workflow with zod 3 + zod 4 matrix No CI exists on the repo today. Add a minimal GitHub Actions workflow that runs on push/PR to main and ai-sdk-v5, and exercises the full declared peer range (zod ^3.24, zod ^4.1) so regressions like #17 surface automatically rather than at consumer install time. Per-job steps: install, swap zod version, typecheck, lint (non-blocking), build, vitest, and a smoke test that imports the built CJS bundle. --- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6bbd046 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: CI + +on: + push: + branches: [main, ai-sdk-v5] + pull_request: + branches: [main, ai-sdk-v5] + +jobs: + test: + name: Test (zod ${{ matrix.zod }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Exercise the full declared peer range to catch zod 3 / zod 4 + # regressions early - see #17 for history. + zod: ['^3.24.0', '^4.1.0'] + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Install zod ${{ matrix.zod }} + run: npm install --no-save zod@${{ matrix.zod }} + + - name: Typecheck + run: npx tsc --noEmit + + - name: Lint + run: npx eslint . --max-warnings=0 + continue-on-error: true + + - name: Build + run: npm run build + + - name: Unit tests + run: npm test + + - name: Module loads under zod ${{ matrix.zod }} + run: node -e "require('./dist/index.cjs').createOpencode({})"