Skip to content

[TEST] ZipArchiveFile: cover unzipDirectory error paths (#9460) - #9540

Merged
timosachsenberg merged 4 commits into
OpenMS:developfrom
timosachsenberg:test/9460-ziparchivefile-errors
Jul 1, 2026
Merged

timosachsenberg merged 4 commits into
OpenMS:developfrom
timosachsenberg:test/9460-ziparchivefile-errors

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a ZipArchiveFile_test section pinning unzipDirectory's error handling — the whole-archive counterpart to the single-file ZipIfstream corrupt-archive guard (#9535):

  • corrupt archive (existing, readable, but not a valid ZIP — garbage bytes) → Exception::InvalidValue (libzip's zip_open fails; a clear exception rather than a crash);
  • missing / unreadable input → Exception::FileNotFound;
  • already-unpacked directory input → returned as-is (the directory-or-zip bundle convention OpenMS uses for .oswpq / parquet bundles).

Why

Part of the §1 (Qt removal: minizip-ng → libzip) [AUTO] task in the OpenMS 3.6.0 pre-release testing plan (#9460):

Verify libzip decompression … whole-archive via ZipArchiveFile::unzipDirectory … Add … empty/corrupt-archive error-path cases. Pass: corrupt archive raises a clear exception; empty archive handled.

ZipArchiveFile_test previously only covered the happy path (add a file, extract, verify). I read the implementation to assert the exact thrown types: corrupt → InvalidValue (FileHandler.cpp/ZipArchiveFile.cpp zip_open failure), unreadable → FileNotFound, directory → early return. (#9535 covered the ZipIfstream single-file corrupt path, which throws FileNotReadable; this covers the distinct unzipDirectory whole-archive path.)

Test plan

Tests only — no production code changed. Verified locally: -fsyntax-only clean, full build green, test runs PASSED (InvalidValue / FileNotFound / directory-returned-as-is all OK).

Part of #9460. Follows #9524 … #9539.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Strengthened archive-related tests by adding explicit stream-open assertions during write and verification steps.
    • Added new coverage for directory extraction edge cases, including validation of correct exceptions for corrupt non-ZIP archives, missing archive paths, and behavior when the target directory is already unpacked (no re-extraction).

ZipArchiveFile_test only exercised the happy path (add + extract a valid archive).
Adds an [EXTRA] section pinning unzipDirectory's error handling -- the whole-archive
counterpart to the single-file ZipIfstream corrupt-archive guard:

- corrupt archive (existing, readable, but not a valid ZIP) -> Exception::InvalidValue
  (libzip's zip_open fails; a clear exception rather than a crash)
- missing / unreadable input                                -> Exception::FileNotFound
- already-unpacked directory input                          -> returned as-is (the
  directory-or-zip bundle convention)

Verified: builds clean and the test runs PASSED.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 511cb177-98b2-42bb-9382-05e13f6a3c8d

📥 Commits

Reviewing files that changed from the base of the PR and between 1442293 and 79607a1.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp

📝 Walkthrough

Walkthrough

The test file is strengthened in two ways: the existing addOrReplaceFromFile test now explicitly verifies that all std::ofstream and std::ifstream objects successfully open before use, and a new [EXTRA] test section is added to cover three error and edge cases for ZipArchiveFile::unzipDirectory—corrupt archives, missing paths, and directory inputs.

Changes

ZipArchiveFile test improvements

Layer / File(s) Summary
addOrReplaceFromFile test hardening
src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp
Existing test strengthened with TEST_TRUE(...is_open()) assertions after opening all std::ofstream and std::ifstream streams (initial write, extracted content verification, replacement content write, and version2 extraction); loop over listEntries also reformatted.
unzipDirectory error and edge case tests
src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp
New [EXTRA] section with three scenarios: corrupt (non-ZIP) archive throws Exception::InvalidValue, nonexistent archive path throws Exception::FileNotFound, and passing an already-unpacked directory returns that directory path unchanged without extraction.

🐇 A corrupt zip, a path that's gone astray,
A folder that needs no unzipping today—
Three edge cases caught with a test and a hop,
The archive now knows when it's time to stop!
sniff sniff No bad zips shall pass this way! 🗂️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding test coverage for error paths in the unzipDirectory method of ZipArchiveFile.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp`:
- Around line 92-97: Replace the manual temp file creation for the corrupt
archive test file with the NEW_TMP_FILE macro. Instead of manually constructing
the corrupt file path with tmp.getPath() and creating an ofstream directly, use
NEW_TMP_FILE to generate the temporary file path and handle, then write the
plain text bytes to that file. This ensures consistent temp-file handling across
all tests as per coding guidelines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55c11244-4166-4129-b8a1-41d3483707c7

📥 Commits

Reviewing files that changed from the base of the PR and between aacd941 and 1442293.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp

@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Timo Sachsenberg

Please consider applying the following patch:

--- AUTHORS	2026-06-15 17:17:21.710863983 +0000
+++ AUTHORS.new	2026-06-15 17:17:26.707204139 +0000
@@ -23,8 +23,8 @@
  - Chirag Dave
  - Chris Bauer
  - Chris Bielow
- - Christie Mathews
  - Christian Ehrlich
+ - Christie Mathews
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@timosachsenberg timosachsenberg mentioned this pull request Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Adversarial review result: I found a compile blocker in the added test.

NEW_TMP_FILE(corrupt); is used without declaring corrupt first. In ClassTest.h, NEW_TMP_FILE(filename) expands to an assignment (filename = TEST::createTmpFileName(...)); it does not declare the variable. This should fail to compile until the test declares something like std::string corrupt; before the macro call, matching the pattern used elsewhere.

No source/test comments with tracker-style issue references stood out in this diff.

I did not run the tests locally.

@timosachsenberg
timosachsenberg merged commit a81ca59 into OpenMS:develop Jul 1, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant