Skip to content

fix: prevent corrupt release data from being cached and served#67

Merged
igboyes merged 1 commit intomainfrom
igboyes/vir-2116-make-sure-corrupt-data-is-not-written-to-virtoolcareleases
Apr 20, 2026
Merged

fix: prevent corrupt release data from being cached and served#67
igboyes merged 1 commit intomainfrom
igboyes/vir-2116-make-sure-corrupt-data-is-not-written-to-virtoolcareleases

Conversation

@igboyes
Copy link
Copy Markdown
Member

@igboyes igboyes commented Apr 20, 2026

Summary

  • Fixed a bug where filterReleases allowed through releases with empty or null assets arrays, leading to corrupt data being cached
  • Fixed a typo assert_errorasset_error in formatRelease, and added a final filter to strip any releases where asset extraction failed before caching
  • Added vitest as a dev dependency and a test suite for filterReleases and formatRelease to prevent regressions

Test plan

  • Run npm test and verify all new tests in src/utils/releases.test.ts pass
  • Confirm the releases page loads correctly and only shows releases with valid assets
  • Verify no corrupt/empty release data appears in the cache after a fresh fetch

Releases with empty asset arrays passed the filter because `[]` is
truthy in JS. This caused incomplete records (missing content_type,
download_url, etc.) to be written to the cache.

- Check `assets?.length > 0` instead of just truthiness
- Fix `assert_error` typo to `asset_error`
- Filter out releases with asset errors after formatting
- Remove debug `console.log(response.body)`
- Add vitest and unit tests for filterReleases and formatRelease
@linear
Copy link
Copy Markdown

linear Bot commented Apr 20, 2026

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates Vitest for unit testing, adding a new test suite for release utility functions and a test script to the package configuration. The release handling logic is refined to ensure assets are present, a typo in the asset error property is corrected, and releases with errors are filtered out. Feedback focuses on improving TypeScript type annotations to facilitate safer property access.

Comment thread src/utils/releases.ts
];

function filterReleases(releases: Array<object>): Array<object> {
export function filterReleases(releases: Array<object>): Array<object> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The type Array is overly restrictive in TypeScript and prevents accessing properties like assets or draft without type casting. Using any[] or Record<string, any>[] would be more appropriate here to allow for safe property access, or ideally, a dedicated interface for the GitHub release object.

Suggested change
export function filterReleases(releases: Array<object>): Array<object> {
export function filterReleases(releases: any[]): any[] {

Comment thread src/utils/releases.ts
}

function formatRelease(release) {
export function formatRelease(release) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The release parameter is missing a type annotation. Adding a type annotation (e.g., any or a specific interface) improves type safety and maintainability in TypeScript files.

Suggested change
export function formatRelease(release) {
export function formatRelease(release: any) {

@igboyes igboyes merged commit 362a58a into main Apr 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant