-
Notifications
You must be signed in to change notification settings - Fork 67
fix(env): fixed zod error changing to preprocess and coercing includi… #531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SandipGyawali
wants to merge
2
commits into
OpenRouterTeam:main
Choose a base branch
from
SandipGyawali:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { describe, it, expect, beforeEach } from 'vitest'; | ||
| import { envSchema, resetEnv } from '../../src/lib/env.js'; | ||
|
|
||
| describe('OPENROUTER_DEBUG env var parsing', () => { | ||
| beforeEach(() => { | ||
| resetEnv(); | ||
| }); | ||
|
|
||
| describe('explicit falsy values should disable debug logging', () => { | ||
| it('should parse OPENROUTER_DEBUG=false as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'false' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=0 as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: '0' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=off as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'off' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=no as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'no' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG="" as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: '' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('case-insensitive handling', () => { | ||
| it('should parse OPENROUTER_DEBUG=FALSE as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'FALSE' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=False as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'False' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=OFF as false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'OFF' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('explicit truthy values should enable debug logging', () => { | ||
| it('should parse OPENROUTER_DEBUG=true as true', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'true' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(true); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=1 as true', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: '1' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(true); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=on as true', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'on' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(true); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=yes as true', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'yes' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('actual boolean values passed programmatically', () => { | ||
| it('should accept boolean true', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: true }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept boolean false', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: false }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('undefined/unset behavior', () => { | ||
| it('should be undefined when not set', () => { | ||
| const result = envSchema.parse({}); | ||
| expect(result.OPENROUTER_DEBUG).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should be undefined when explicitly undefined', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: undefined }); | ||
| expect(result.OPENROUTER_DEBUG).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('regression: any non-empty string without the fix would be truthy', () => { | ||
| it('should NOT parse OPENROUTER_DEBUG= as true (empty string edge case)', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: '' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
|
|
||
| it('should parse OPENROUTER_DEBUG=disabled as true (arbitrary non-empty value)', () => { | ||
| const result = envSchema.parse({ OPENROUTER_DEBUG: 'disabled' }); | ||
| expect(result.OPENROUTER_DEBUG).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('resetEnv clears cache between tests', () => { | ||
| it('should return fresh value after reset', () => { | ||
| const result1 = envSchema.parse({ OPENROUTER_DEBUG: 'true' }); | ||
| expect(result1.OPENROUTER_DEBUG).toBe(true); | ||
| resetEnv(); | ||
| const result2 = envSchema.parse({ OPENROUTER_DEBUG: 'false' }); | ||
| expect(result2.OPENROUTER_DEBUG).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion]
src/lib/env.tscarries aCode generated by Speakeasy — DO NOT EDITheader — verify this change survives regeneration.Details
Why: Speakeasy regenerates this file from the OpenAPI spec. With
persistentEdits: enabled: "true"in.speakeasy/gen.yaml, Speakeasy will attempt to re-apply manual edits after regeneration, but this is not guaranteed — especially for logic changes inside schema fields. If a Speakeasy upgrade or spec bump triggers full file regeneration, the preprocess guard and tests may silently diverge from the schema.Options:
speakeasy runlocally and confirm the preprocess block survives in the regenerated output..speakeasy/overlays/boolean-query-params.overlay.yaml) to make this the generated default.Prompt for agents
Reviewed at
eed9ad8