Skip to content

fix(types): re-enable type checking and validate environment variables with zod - #108

Merged
anthuanvasquez merged 2 commits into
masterfrom
feature/84
Sep 10, 2026
Merged

anthuanvasquez merged 2 commits into
masterfrom
feature/84

Conversation

@anthuanvasquez

Copy link
Copy Markdown
Owner

Summary

  • Re-enables typescript.typeCheck in nuxt.config.ts and tightens test typings to avoid regressions (Closes Re-enable type checking and tighten test typings #84).
  • Adds tests/tsconfig.json and tests/types.d.ts for proper Node and Nitro globals resolution in tests.
  • Implements Zod validation for runtime environment variables (app/utils/env.ts, app/composables/useEnv.ts, server/utils/env.ts, and server/plugins/env.ts).
  • Cleans up unnecessary @ts-expect-error and type assertions across server and client components.
  • Adds comprehensive unit tests for environment validation (tests/unit/utils/env.test.ts).

Verification

  • pnpm test: 11 test suites / 50 tests passing
  • pnpm typecheck: Passed with 0 errors
  • pnpm lint: Passed with 0 errors

Copilot AI lite review requested due to automatic review settings September 10, 2026 05:04
@anthuanvasquez anthuanvasquez self-assigned this Sep 10, 2026
@anthuanvasquez anthuanvasquez added the area:testing Test coverage and quality label Sep 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Production env validation currently yields generic “Required” errors when variables are unset, undermining the goal of actionable startup validation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR re-enables Nuxt type checking and introduces Zod-based runtime config validation to make environment variable usage type-safe and fail-fast (especially in production), while tightening test typings to prevent future regressions.

Changes:

  • Re-enabled Nuxt TypeScript type checking and reduced reliance on @ts-expect-error in tests.
  • Added Zod schemas + helpers for validating runtime config on both client (public) and server, plus a Nitro plugin to validate on startup.
  • Added/updated unit tests and test TypeScript configuration to support stricter typing.
File summaries
File Description
tests/unit/utils/env.test.ts Adds unit tests covering public + server env parsing and production enforcement.
tests/unit/utils/abusePatterns.test.ts Removes @ts-expect-error now that containsAbusePattern accepts nullish input.
tests/types.d.ts Introduces Node/Nitro global type declarations for unit tests.
tests/tsconfig.json Adds test-specific TS config to resolve Node/Nitro globals and Nuxt generated types.
tests/server/api.test.ts Tightens Nitro global mocks and avoids dynamic-property @ts-expect-error patterns.
tests/server/api-guard.test.ts Improves typing around getHeader and useRuntimeConfig mocking.
tests/components/sections/Projects.test.ts Adjusts assertions to satisfy stricter typing (but introduces weaker optional-chained assertions).
tests/components/elements/Chatbot.test.ts Improves DOM typing for textarea querying in tests.
server/utils/env.ts Adds a server helper to return validated runtime config.
server/plugins/env.ts Adds a Nitro plugin to validate runtime config at server startup (strict in prod).
server/middleware/api-guard.ts Removes unsafe type assertions from runtime config reads.
pnpm-lock.yaml Locks the new zod dependency.
package.json Adds zod as a dependency.
nuxt.config.ts Re-enables typescript.typeCheck.
app/utils/env.ts Implements Zod schemas + validation helpers for runtime config (public + server).
app/utils/abusePatterns.ts Expands input type to accept `string
app/pages/index.vue Switches to useEnv() for type-safe public env access.
app/composables/useEnv.ts Adds a composable for validated public runtime config access.
app/components/sections/MapRD.vue Switches to useEnv() for mapbox token retrieval.
app/components/layouts/Footer.vue Switches to useEnv() for email retrieval.
Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file

Suppressed comments (2)

app/utils/env.ts:29

  • Same issue as allowedOrigin: if chatSessionSecret is missing entirely in production, Zod will report a generic "Required" instead of the intended production-specific message. Add a default after the .min(...) so the error message stays actionable when the env var is unset.
  chatSessionSecret: z
    .string()
    .min(
      1,
      'chatSessionSecret (NUXT_CHAT_SESSION_SECRET) is required in production'
    ),

tests/components/sections/Projects.test.ts:57

  • Similarly for titles[0]/titles[1]: using ?. weakens the assertion output even though earlier expectations already ensure these elements exist. Use non-null assertions so a missing element fails loudly at the right place.
    const titles = component.findAll('[data-testid="project-title"]');
    expect(titles[0]?.text()).toBe('Project 1');
    expect(titles[1]?.text()).toBe('Project 2');
  • Files reviewed: 18/20 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/utils/env.ts
Comment thread tests/components/sections/Projects.test.ts
@anthuanvasquez
anthuanvasquez merged commit 5982933 into master Sep 10, 2026
3 checks passed
@anthuanvasquez
anthuanvasquez deleted the feature/84 branch September 10, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:testing Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-enable type checking and tighten test typings

2 participants