test: add env and database vitest coverage#1834
Conversation
| function setRequiredServerEnv() { | ||
| process.env.DATABASE_URL = "mysql://user:password@localhost:3306/cap"; | ||
| process.env.WEB_URL = "https://cap.example"; | ||
| process.env.NEXTAUTH_SECRET = "test-secret"; | ||
| process.env.NEXTAUTH_URL = "https://cap.example"; | ||
| process.env.CAP_AWS_BUCKET = "cap-test-bucket"; | ||
| process.env.CAP_AWS_REGION = "us-east-1"; | ||
| process.env.NODE_ENV = "test"; | ||
| } |
There was a problem hiding this comment.
The "parses boolean string defaults" test is brittle because it checks that
S3_PATH_STYLE and CAP_VIDEOS_DEFAULT_PUBLIC take their schema-level defaults (true), yet setRequiredServerEnv() never unsets those variables. originalEnv is captured at module-load time, so if the developer's or CI environment already has either var set (e.g. S3_PATH_STYLE=false), ...process.env in experimental__runtimeEnv will propagate that value and override the Zod default, causing the test to fail with no obvious cause.
| function setRequiredServerEnv() { | |
| process.env.DATABASE_URL = "mysql://user:password@localhost:3306/cap"; | |
| process.env.WEB_URL = "https://cap.example"; | |
| process.env.NEXTAUTH_SECRET = "test-secret"; | |
| process.env.NEXTAUTH_URL = "https://cap.example"; | |
| process.env.CAP_AWS_BUCKET = "cap-test-bucket"; | |
| process.env.CAP_AWS_REGION = "us-east-1"; | |
| process.env.NODE_ENV = "test"; | |
| } | |
| function setRequiredServerEnv() { | |
| process.env.DATABASE_URL = "mysql://user:password@localhost:3306/cap"; | |
| process.env.WEB_URL = "https://cap.example"; | |
| process.env.NEXTAUTH_SECRET = "test-secret"; | |
| process.env.NEXTAUTH_URL = "https://cap.example"; | |
| process.env.CAP_AWS_BUCKET = "cap-test-bucket"; | |
| process.env.CAP_AWS_REGION = "us-east-1"; | |
| process.env.NODE_ENV = "test"; | |
| delete process.env.S3_PATH_STYLE; | |
| delete process.env.CAP_VIDEOS_DEFAULT_PUBLIC; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/env/server.test.ts
Line: 12-20
Comment:
The "parses boolean string defaults" test is brittle because it checks that `S3_PATH_STYLE` and `CAP_VIDEOS_DEFAULT_PUBLIC` take their schema-level defaults (`true`), yet `setRequiredServerEnv()` never unsets those variables. `originalEnv` is captured at module-load time, so if the developer's or CI environment already has either var set (e.g. `S3_PATH_STYLE=false`), `...process.env` in `experimental__runtimeEnv` will propagate that value and override the Zod default, causing the test to fail with no obvious cause.
```suggestion
function setRequiredServerEnv() {
process.env.DATABASE_URL = "mysql://user:password@localhost:3306/cap";
process.env.WEB_URL = "https://cap.example";
process.env.NEXTAUTH_SECRET = "test-secret";
process.env.NEXTAUTH_URL = "https://cap.example";
process.env.CAP_AWS_BUCKET = "cap-test-bucket";
process.env.CAP_AWS_REGION = "us-east-1";
process.env.NODE_ENV = "test";
delete process.env.S3_PATH_STYLE;
delete process.env.CAP_VIDEOS_DEFAULT_PUBLIC;
}
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in f8c9fcc. setRequiredServerEnv now deletes S3_PATH_STYLE and CAP_VIDEOS_DEFAULT_PUBLIC before importing serverEnv, so the boolean default assertions are isolated from any ambient developer or CI environment. Verification passed: corepack pnpm --filter @cap/env test; corepack pnpm --filter @cap/database test; corepack pnpm exec biome check on the touched test config and package files.
|
Small note on the Socket dependency table: the low-score packages shown there (for example |
/claim #54
Summary
@cap/envand@cap/databasebuildEnvpublic URL fallback/caching andserverEnvS3 endpoint/default boolean parsingS3_PATH_STYLE/CAP_VIDEOS_DEFAULT_PUBLICenv vars after Greptile feedbackVerification
corepack pnpm --filter @cap/env testcorepack pnpm --filter @cap/database testcorepack pnpm exec biome check packages/database/crypto.test.ts packages/database/vitest.config.ts packages/database/package.json packages/env/package.json packages/env/build.test.ts packages/env/server.test.ts packages/env/vitest.config.tsAI-assisted with Codex; diff reviewed and verified before submission.