Skip to content

Enhance downloader functionality and version bump to v0.6.1#8

Merged
chris-c-thomas merged 2 commits intomainfrom
feat/downloader-enhancement
Mar 3, 2026
Merged

Enhance downloader functionality and version bump to v0.6.1#8
chris-c-thomas merged 2 commits intomainfrom
feat/downloader-enhancement

Conversation

@chris-c-thomas
Copy link
Copy Markdown
Owner

@chris-c-thomas chris-c-thomas commented Mar 3, 2026

This pull request introduces an enhancement to the downloader logic for U.S. Code XML files: when all 54 titles are requested, the system now downloads a single bulk zip file (xml_uscAll@{releasePoint}.zip) instead of making 54 individual HTTP requests, significantly improving efficiency. If the bulk zip is unavailable, it gracefully falls back to individual downloads. The change is reflected across the core, CLI, and USC packages, with updated tests and documentation.

Bulk download enhancement

  • Added logic to downloadTitles in packages/usc/src/downloader.ts to detect requests for all 54 titles and fetch a single bulk zip file, falling back to per-title downloads if the bulk file is unavailable.
  • Implemented helper isAllTitles to determine if a request covers all 54 titles, handling duplicates and arbitrary ordering.
  • Added extraction routines (extractAllXmlFromZip, downloadAndExtractAllTitles) to handle bulk zip files and extract individual XML files for each title.

Testing and exports

  • Added comprehensive tests for isAllTitles in packages/usc/src/downloader.test.ts to ensure correct detection of all-title requests.
  • Exported isAllTitles in packages/usc/src/index.ts for use in other modules.

Documentation and versioning

  • Updated changelogs in CHANGELOG.md, packages/cli/CHANGELOG.md, packages/core/CHANGELOG.md, and packages/usc/CHANGELOG.md to document the bulk download enhancement and dependency updates. [1] [2] [3] [4]
  • Bumped package versions to 0.6.1 in packages/cli/package.json, packages/core/package.json, and packages/usc/package.json. [1] [2] [3]

Summary by CodeRabbit

Release Notes – Version 0.6.1

  • New Features

    • Optimized bulk download: Download --all now retrieves all titles from a single compressed archive instead of individual requests, with automatic fallback to per-title downloads if unavailable.
  • Tests

    • Added comprehensive test coverage for bulk download scenarios and title set validation.

@chris-c-thomas chris-c-thomas requested a review from Copilot March 3, 2026 20:46
@chris-c-thomas chris-c-thomas self-assigned this Mar 3, 2026
@chris-c-thomas chris-c-thomas added enhancement Enhancements made to exisiting features or codebase feature New feature implemented labels Mar 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 3, 2026

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 4a103a9 and 035fc99.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • packages/cli/CHANGELOG.md
  • packages/cli/package.json
  • packages/core/CHANGELOG.md
  • packages/core/package.json
  • packages/usc/CHANGELOG.md
  • packages/usc/package.json
  • packages/usc/src/downloader.test.ts
  • packages/usc/src/downloader.ts
  • packages/usc/src/index.ts

📝 Walkthrough

Walkthrough

Version 0.6.1 release patch that optimizes the USC package downloader to fetch all 54 titles from a single bulk XML ZIP when all titles are downloaded, with automatic fallback to per-title downloads if unavailable. Includes version bumps and changelog entries across packages.

Changes

Cohort / File(s) Summary
Release Version Bumps
CHANGELOG.md, packages/cli/CHANGELOG.md, packages/core/CHANGELOG.md, packages/usc/CHANGELOG.md, packages/cli/package.json, packages/core/package.json, packages/usc/package.json
Version bumped to 0.6.1 across all packages with changelog entries documenting enhanced downloader behavior for all-titles downloads and updated interdependencies.
Downloader Bulk Download Logic
packages/usc/src/downloader.ts
Added isAllTitles() function to detect full title coverage; introduced bulk download pathway with downloadAndExtractAllTitles(), extractAllXmlFromZip(), and URL builders (buildDownloadUrl, buildAllTitlesUrl, releasePointToPath); updated downloadTitles() to attempt bulk download when all titles requested, falling back to per-title flow on failure.
Downloader Tests & Exports
packages/usc/src/downloader.test.ts, packages/usc/src/index.ts
Added comprehensive test suite for isAllTitles() covering full sequences, shuffled orders, subsets, duplicates, and edge cases; re-exported isAllTitles from index for public API.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Downloader as downloadTitles()
    participant Check as isAllTitles()
    participant BulkDL as downloadAndExtractAllTitles()
    participant HTTP as HTTP Request
    participant ZIP as ZIP Extractor
    participant FileSystem as File System
    participant Fallback as Per-title Downloads

    Client->>Downloader: downloadTitles(titles?)
    Downloader->>Check: isAllTitles(titles)
    alt All 54 titles requested
        Check-->>Downloader: true
        Downloader->>BulkDL: downloadAndExtractAllTitles()
        BulkDL->>HTTP: GET xml_uscAll@{releasePoint}.zip
        HTTP-->>BulkDL: bulk ZIP file
        BulkDL->>ZIP: extractAllXmlFromZip()
        ZIP->>FileSystem: extract all uscNN.xml
        FileSystem-->>ZIP: file paths
        ZIP-->>BulkDL: DownloadedFile[]
        BulkDL-->>Downloader: success
        Downloader-->>Client: DownloadedFile[]
    else Bulk download fails or partial titles
        Check-->>Downloader: false / error
        Downloader->>Fallback: downloadTitles() per-title
        Fallback->>HTTP: GET per-title XMLs
        HTTP-->>Fallback: individual files
        Fallback-->>Downloader: DownloadedFile[]
        Downloader-->>Client: DownloadedFile[]
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@chris-c-thomas chris-c-thomas merged commit a9ed346 into main Mar 3, 2026
3 of 5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves @law2md/usc downloader efficiency by adding a bulk-download path when all 54 USC titles are requested, alongside a repo-wide version bump to 0.6.1 and corresponding changelog updates.

Changes:

  • Add isAllTitles helper and bulk xml_uscAll@{releasePoint}.zip download + extraction path with per-title fallback.
  • Add unit tests for isAllTitles and export it from @law2md/usc.
  • Bump package versions to 0.6.1 and update changelogs.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/usc/src/index.ts Re-export isAllTitles from the downloader module.
packages/usc/src/downloader.ts Implements bulk all-titles zip download/extract path and isAllTitles helper.
packages/usc/src/downloader.test.ts Adds unit tests for isAllTitles.
packages/usc/package.json Bumps @law2md/usc version to 0.6.1.
packages/usc/CHANGELOG.md Documents downloader enhancement and dependency updates.
packages/core/package.json Bumps @law2md/core version to 0.6.1.
packages/core/CHANGELOG.md Adds a 0.6.1 entry (currently describing downloader enhancement).
packages/cli/package.json Bumps CLI version to 0.6.1.
packages/cli/CHANGELOG.md Notes downloader enhancement and dependency updates.
CHANGELOG.md Adds top-level 0.6.1 release notes for bulk download behavior.

Comment on lines +106 to +113
// Use bulk zip when all 54 titles are requested
if (options.titles === undefined || isAllTitles(titles)) {
try {
const files = await downloadAndExtractAllTitles(releasePoint, options.outputDir);
return { releasePoint, files, errors: [] };
} catch {
// Fall back to per-title downloads
}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The bulk-download attempt swallows all errors and falls back silently, but it can leave a partially downloaded uscAll.zip and/or partially extracted XML files in outputDir. Consider narrowing the fallback to expected “bulk unavailable” failures (e.g., 404/410), and ensure temp artifacts are cleaned up on bulk failure (e.g., cleanup in a finally inside the bulk download/extract helper, or delete uscAll.zip + partial outputs before continuing).

Copilot uses AI. Check for mistakes.
Comment on lines +396 to +405
// Extract all XML files from zip
const extracted = await extractAllXmlFromZip(zipPath, outputDir);

// Clean up zip file
await unlink(zipPath);

// Stat each extracted file and build results
const files: DownloadedFile[] = [];
for (const { titleNumber, filePath } of extracted) {
const fileStat = await stat(filePath);
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

downloadAndExtractAllTitles treats any extraction result as success. If the bulk zip layout changes (or the regex fails), extractAllXmlFromZip can return an empty/partial list and downloadTitles will return { errors: [] }, silently skipping titles. Add a completeness check (e.g., ensure the extracted title numbers cover 1–54 and/or that 54 files were extracted) and throw if incomplete so the caller can fall back to per-title downloads.

Copilot uses AI. Check for mistakes.
Comment on lines +358 to +365
zipFile.on("end", () => {
ended = true;
maybeResolve();
});

zipFile.on("error", (zipErr: Error) => {
reject(new Error(`Zip error: ${zipErr.message}`));
});
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

extractAllXmlFromZip never closes the zipFile on the successful path (and also doesn’t close it in the zipFile.on("error") handler). This can leak file descriptors, especially when downloading all titles repeatedly. Ensure zipFile.close() is called when finishing (after end/pending resolves) and when handling zip-level errors.

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +114
// Use bulk zip when all 54 titles are requested
if (options.titles === undefined || isAllTitles(titles)) {
try {
const files = await downloadAndExtractAllTitles(releasePoint, options.outputDir);
return { releasePoint, files, errors: [] };
} catch {
// Fall back to per-title downloads
}
}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

New bulk-download behavior (single uscAll zip, extraction of all titles, and fallback when unavailable) isn’t covered by tests here. Consider adding tests that mock fetch to (1) return a small in-memory zip with a few uscNN.xml entries to verify extraction/mapping, and (2) simulate a 404 for the bulk URL to verify the per-title fallback path is used.

Copilot uses AI. Check for mistakes.

### Patch Changes

- Enhance downloader for when all titles are downloaded
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

This changelog entry attributes the bulk USC downloader enhancement to @law2md/core, but the downloader implementation lives in @law2md/usc. To avoid misleading consumers, adjust this entry to reflect actual core changes in 0.6.1 (e.g., dependency bump / no functional changes) and leave the downloader note to the usc/cli changelogs.

Suggested change
- Enhance downloader for when all titles are downloaded
- Internal maintenance and dependency updates; no functional changes in core

Copilot uses AI. Check for mistakes.
@chris-c-thomas chris-c-thomas deleted the feat/downloader-enhancement branch March 3, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancements made to exisiting features or codebase feature New feature implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants