Skip to content
Merged
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
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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({})"
83 changes: 83 additions & 0 deletions src/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof validateSettings>[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<typeof validateSettings>[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', () => {
Expand Down