fix: fall back to the default when PECANS_CACHE_MAX_AGE is not a number#71
Merged
Conversation
parseInt of a non-numeric value produced NaN, which flowed into the backend's cache-age comparison where every check is false - the release cache was fetched once and never refreshed again. Parse the env var through parseCacheMaxAge, which falls back to the 2 hour default for missing or non-numeric values. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AtqCsX7ptP36t5rdyaJJhM
There was a problem hiding this comment.
Pull request overview
This PR fixes a caching edge case in configure() where an invalid PECANS_CACHE_MAX_AGE (e.g. non-numeric) could produce NaN, preventing the backend cache from ever refreshing after the initial fetch. It introduces a dedicated parseCacheMaxAge() helper (similar in spirit to parseTrustProxy) and adds unit tests for the parsing behavior.
Changes:
- Add
parseCacheMaxAge()with a 2-hour fallback default and use it fromconfigure(). - Ensure invalid/missing cache max age values don’t propagate
NaNinto backend cache refresh logic. - Add unit tests covering numeric, missing/empty, and garbage inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/index.ts | Adds parseCacheMaxAge() and routes PECANS_CACHE_MAX_AGE parsing through it to avoid NaN disabling cache refresh. |
| test/unit/index.spec.ts | Adds unit tests for parseCacheMaxAge() behavior. |
Copilot review follow-up: parseInt-permissive values like '3600ms' or '-1' now fall back to the default instead of silently changing caching behavior (a negative age refreshes on every request), and the 2 hour default is shared from the backend module instead of duplicated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AtqCsX7ptP36t5rdyaJJhM
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
parseIntof a non-numericPECANS_CACHE_MAX_AGEproducedNaN, which flowed into the backend's cache-age comparison where every check comes out false — the release cache was fetched once at startup and never refreshed again.configure()now parses the env var through a new exportedparseCacheMaxAge()helper (mirroringparseTrustProxy), which falls back to the 2-hour default for missing or non-numeric values.Includes unit tests for numeric, missing, empty, and garbage values.
From the 2.0 release review pass.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AtqCsX7ptP36t5rdyaJJhM
Generated by Claude Code