Skip to content

fix: Improve NAR file serving and remove old URL prefix workaround#838

Merged
kalbasit merged 2 commits intomainfrom
improve-nar-file-serving-remove-old-url-prefix-workaround
Feb 11, 2026
Merged

fix: Improve NAR file serving and remove old URL prefix workaround#838
kalbasit merged 2 commits intomainfrom
improve-nar-file-serving-remove-old-url-prefix-workaround

Conversation

@kalbasit
Copy link
Owner

@kalbasit kalbasit commented Feb 11, 2026

Update testdata server to properly handle NAR file paths with compression
extensions and support lookups by both original and normalized NAR hashes.
Also remove the old string replacement workaround from upstream cache since
URLs are now normalized through the Normalize() method.

Changes:

  • testdata/server.go:

    • Fix path construction to only append compression extension if non-empty
    • Add support for fetching narinfo by NAR hash (used when only NAR hash available)
    • Add support for fetching NARs by normalized hash (with prefix stripped)
    • Build normalized NAR paths with proper compression extension handling
  • pkg/cache/upstream/cache.go:

    • Remove ReplaceAll workaround for URL prefix trimming
    • URL normalization now handled via nar.URL.Normalize()

This fixes issues with NAR files that have no compression (extension would have
been ".nar." instead of ".nar") and ensures test server can serve NARs regardless
of whether they're requested using the original prefixed hash or the normalized hash.

Part of #806

Co-Authored-By: Claude Haiku 4.5 noreply@anthropic.com

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working go Pull requests that update go code labels Feb 11, 2026
@dosubot
Copy link

dosubot bot commented Feb 11, 2026

Related Documentation

Checked 7 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines how NAR (Nix Archive) files are served and processed, primarily by enhancing the test server's ability to handle various NAR URL formats, including those with and without compression extensions, and supporting lookups by different hash representations. Concurrently, it streamlines the upstream cache logic by removing a manual URL prefix trimming workaround, relying instead on a centralized normalization utility. These changes collectively improve the robustness and consistency of NAR file handling.

Highlights

  • NAR File Serving Improvements: The testdata server now correctly handles NAR file paths, ensuring compression extensions are appended only when present, and supports fetching NARs by both their original and normalized hashes.
  • URL Prefix Workaround Removal: An outdated string replacement workaround for trimming URL prefixes in the upstream cache has been removed, as URL normalization is now handled consistently via the nar.URL.Normalize() method.
  • Test Data Alignment: The nar7.go test data has been updated to reflect the non-prefixed format for NAR URLs, aligning with the new normalization logic.
Changelog
  • pkg/cache/upstream/cache.go
    • Removed strings.ReplaceAll call that was used to trim a hash prefix from NarURL, as normalization is now handled by nar.URL.Normalize().
  • testdata/nar7.go
    • Updated the NarInfoText URL to remove the narinfo hash prefix, aligning it with the non-prefixed format.
  • testdata/server.go
    • Imported the github.com/kalbasit/ncps/pkg/nar package to utilize its URL normalization capabilities.
    • Added logic to support fetching narinfo by the NAR hash directly.
    • Refactored NAR path construction to correctly append compression extensions (e.g., .nar.zst) only when an extension is present, preventing .nar. for uncompressed files.
    • Implemented support for serving NARs using their normalized hash (with the prefix stripped), including handling compression extensions for these normalized paths.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@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

The pull request effectively improves NAR file serving in the testdata server and removes an outdated URL prefix workaround in the upstream cache. The changes ensure that the test server correctly handles NAR file paths with compression extensions and supports lookups by both original and normalized NAR hashes. The removal of the strings.ReplaceAll workaround in pkg/cache/upstream/cache.go is a good step towards cleaner code, as URL normalization is now handled by the nar.URL.Normalize() method.

@kalbasit kalbasit force-pushed the improve-nar-file-serving-remove-old-url-prefix-workaround branch from 372be8b to 3d6c7ca Compare February 11, 2026 17:14
@kalbasit kalbasit force-pushed the apply-nar-url-normalization-in-storage-layer branch 2 times, most recently from fd85478 to 7800e7c Compare February 11, 2026 17:45
@kalbasit kalbasit force-pushed the improve-nar-file-serving-remove-old-url-prefix-workaround branch from 3d6c7ca to 6b35b08 Compare February 11, 2026 17:45
@kalbasit kalbasit force-pushed the apply-nar-url-normalization-in-storage-layer branch from 7800e7c to 0b7597e Compare February 11, 2026 17:49
@kalbasit kalbasit force-pushed the improve-nar-file-serving-remove-old-url-prefix-workaround branch from 6b35b08 to 4a589ea Compare February 11, 2026 17:49
Base automatically changed from apply-nar-url-normalization-in-storage-layer to main February 11, 2026 18:28
kalbasit and others added 2 commits February 11, 2026 10:36
Update testdata server to properly handle NAR file paths with compression
extensions and support lookups by both original and normalized NAR hashes.
Also remove the old string replacement workaround from upstream cache since
URLs are now normalized through the Normalize() method.

Changes:
- testdata/server.go:
  - Fix path construction to only append compression extension if non-empty
  - Add support for fetching narinfo by NAR hash (used when only NAR hash available)
  - Add support for fetching NARs by normalized hash (with prefix stripped)
  - Build normalized NAR paths with proper compression extension handling

- pkg/cache/upstream/cache.go:
  - Remove ReplaceAll workaround for URL prefix trimming
  - URL normalization now handled via nar.URL.Normalize()

This fixes issues with NAR files that have no compression (extension would have
been ".nar." instead of ".nar") and ensures test server can serve NARs regardless
of whether they're requested using the original prefixed hash or the normalized hash.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@kalbasit kalbasit force-pushed the improve-nar-file-serving-remove-old-url-prefix-workaround branch from 4a589ea to 44963b2 Compare February 11, 2026 18:37
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.41%. Comparing base (c6e9967) to head (44963b2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #838   +/-   ##
=======================================
  Coverage   85.41%   85.41%           
=======================================
  Files           2        2           
  Lines         480      480           
=======================================
  Hits          410      410           
  Misses         65       65           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit kalbasit merged commit 2831749 into main Feb 11, 2026
20 of 23 checks passed
@kalbasit kalbasit deleted the improve-nar-file-serving-remove-old-url-prefix-workaround branch February 11, 2026 19:11
kalbasit added a commit that referenced this pull request Feb 12, 2026
…ackport #838]

Update testdata server to properly handle NAR file paths with compression
extensions and support lookups by both original and normalized NAR hashes.
Also remove the old string replacement workaround from upstream cache since
URLs are now normalized through the Normalize() method.

Changes:
- testdata/server.go:
  - Fix path construction to only append compression extension if non-empty
  - Add support for fetching narinfo by NAR hash (used when only NAR hash available)
  - Add support for fetching NARs by normalized hash (with prefix stripped)
  - Build normalized NAR paths with proper compression extension handling

- pkg/cache/upstream/cache.go:
  - Remove ReplaceAll workaround for URL prefix trimming
  - URL normalization now handled via nar.URL.Normalize()

This fixes issues with NAR files that have no compression (extension would have
been ".nar." instead of ".nar") and ensures test server can serve NARs regardless
of whether they're requested using the original prefixed hash or the normalized hash.

Part of #806

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
(cherry picked from commit 2831749)
kalbasit added a commit that referenced this pull request Feb 12, 2026
…ackport #838]

Update testdata server to properly handle NAR file paths with compression
extensions and support lookups by both original and normalized NAR hashes.
Also remove the old string replacement workaround from upstream cache since
URLs are now normalized through the Normalize() method.

Changes:
- testdata/server.go:
  - Fix path construction to only append compression extension if non-empty
  - Add support for fetching narinfo by NAR hash (used when only NAR hash available)
  - Add support for fetching NARs by normalized hash (with prefix stripped)
  - Build normalized NAR paths with proper compression extension handling

- pkg/cache/upstream/cache.go:
  - Remove ReplaceAll workaround for URL prefix trimming
  - URL normalization now handled via nar.URL.Normalize()

This fixes issues with NAR files that have no compression (extension would have
been ".nar." instead of ".nar") and ensures test server can serve NARs regardless
of whether they're requested using the original prefixed hash or the normalized hash.

Part of #806

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
(cherry picked from commit 2831749)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant