Skip to content

fix: dynamic @required incorrectly resolved after type generation runs#371

Merged
theoephraim merged 1 commit intomainfrom
fix/dynamic-required-type-gen-cache
Mar 11, 2026
Merged

fix: dynamic @required incorrectly resolved after type generation runs#371
theoephraim merged 1 commit intomainfrom
fix/dynamic-required-type-gen-cache

Conversation

@theoephraim
Copy link
Copy Markdown
Member

@theoephraim theoephraim commented Mar 11, 2026

Summary

  • generateTypesIfNeeded() runs before resolveEnvValues() in the CLI, which caused getTypeGenInfo() to call resolve() on dynamic decorators (e.g. @required=eq($OTHER, foo)) before their dependencies were resolved
  • This cached a stale result on the decorator, so when processRequired() / processSensitive() later called resolve() during resolveEnvValues(), they got the wrong cached value
  • Fix: skip calling resolve() for any non-static @required, @optional, @sensitive, or @public decorator in getTypeGenInfo() — their runtime values are irrelevant for type generation anyway (dynamic required → typed as optional; dynamic sensitive is not a supported pattern)
  • Root decorators (@defaultRequired, @defaultSensitive) and string decorators (@icon, @docs) are always static so they're unaffected

Test plan

  • Added runTypeGeneration?: boolean option to envFilesTest helper — when set, calls getTypeGenInfo() on all items between finishLoad() and resolveEnvValues(), mirroring the real CLI flow
  • Updated existing test (dynamic @required works (with type gen running first)) to use runTypeGeneration: true — fails before the fix, passes after
  • All 16 tests in required-decorators.test.ts pass
  • All 25 tests in type-generation.test.ts pass

🤖 Generated with Claude Code

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: a1acf6b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
varlock Patch
@varlock/astro-integration Patch
@varlock/nextjs-integration Patch
@varlock/vite-integration Patch
@varlock/1password-plugin Patch
@varlock/aws-secrets-plugin Patch
@varlock/azure-key-vault-plugin Patch
@varlock/bitwarden-plugin Patch
@varlock/google-secret-manager-plugin Patch
@varlock/infisical-plugin Patch
@varlock/pass-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/varlock@371

commit: a1acf6b

When generateTypesIfNeeded() ran before resolveEnvValues() (as it does in the
CLI), getTypeGenInfo() would call resolve() on dynamic decorators before their
dependencies were resolved. This cached a stale result that corrupted the later
processRequired() / processSensitive() calls during resolveEnvValues().

Fix: skip calling resolve() for any non-static (@required, @optional, @sensitive,
@public) decorator in getTypeGenInfo(). Their runtime values are irrelevant for
type generation — dynamic required items are always typed as optional, and
dynamic sensitive decorators are not a documented pattern.

Adds runTypeGeneration option to envFilesTest helper to reproduce this class
of bug, and a failing test that now passes with the fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@theoephraim theoephraim force-pushed the fix/dynamic-required-type-gen-cache branch from be4c6b6 to a1acf6b Compare March 11, 2026 21:34
Copy link
Copy Markdown
Member

@philmillman philmillman left a comment

Choose a reason for hiding this comment

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

:shipit:

@theoephraim theoephraim merged commit 1b9797e into main Mar 11, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants