Skip to content

fix(1388): fix auto decompress for download resources#1800

Merged
matthiasbruns merged 23 commits into
open-component-model:mainfrom
matthiasbruns:fix/1388_ocm_download_compress
Mar 6, 2026
Merged

fix(1388): fix auto decompress for download resources#1800
matthiasbruns merged 23 commits into
open-component-model:mainfrom
matthiasbruns:fix/1388_ocm_download_compress

Conversation

@matthiasbruns

@matthiasbruns matthiasbruns commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

This pr handles the missing decompression of a downloaded resource if it was uploaded with compression.
While the flags are correctly read and set to default auto, the decompression does not kick in.

This PR fixes the problem

Which issue(s) this PR fixes

Fixes: #1388

Summary by CodeRabbit

  • Bug Fixes

    • Improved resource download handling by adjusting the decompression and extraction workflow to ensure proper handling of compressed resources and extraction policies.
  • Tests

    • Added comprehensive integration tests validating resource extraction policies with various compression scenarios.

@github-actions github-actions Bot added kind/feature new feature, enhancement, improvement, extension size/m Medium labels Feb 18, 2026
@matthiasbruns matthiasbruns force-pushed the fix/1388_ocm_download_compress branch from d73ad42 to a998e3f Compare February 18, 2026 14:17
@github-actions github-actions Bot added the size/xl Extra large label Feb 18, 2026
@matthiasbruns matthiasbruns marked this pull request as ready for review February 18, 2026 14:47
@matthiasbruns matthiasbruns requested a review from a team as a code owner February 18, 2026 14:47
morri-son
morri-son previously approved these changes Feb 18, 2026
@Skarlso

Skarlso commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

We already have auto-decompress with extraction-policy. Why wasn't that working and why do we need a new flag now?

Comment thread cli/cmd/download/resource/cmd.go Outdated
@matthiasbruns matthiasbruns marked this pull request as draft February 18, 2026 17:53
@matthiasbruns

matthiasbruns commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

this turns out to be a bigger issue with DecompressedBlob and extractFSFromBlob

There is currently support for tar, but it seems we usually get
application/octet-stream from MediaType in DecompressedBlob

I will try to simplify this tomorrow, since I actually had it working for the wrong --decompressed flag without using extractFSFromBlob at all.

BTW this PR is sponsored by another TODO :D

  // TODO(jakobmoellerdev): once we add more compression algorithms, use blob media type for discovery.
  //  For now we just support tar.

@matthiasbruns

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-02-19 at 09 07 37 So I am digging down blobs / DecompressionBlob, compression etc

application/octet-stream+gzip is stored in the DecompressionBlob, but MediaTypeAware only returns application/octet-stream

that's why the isTar check does not trigger and we do not uncompress the blob.

Now I need to figure out why the mediaTypes are different 🕵️‍♂️

@matthiasbruns matthiasbruns changed the title feat(1388): add decompress flag for download resources fix(1388): fix auto decompress for download resources Feb 20, 2026
@github-actions github-actions Bot added the kind/bugfix Bug label Feb 20, 2026
On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns matthiasbruns force-pushed the fix/1388_ocm_download_compress branch from c7afa0a to 9064f4e Compare February 20, 2026 10:49
On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns matthiasbruns force-pushed the fix/1388_ocm_download_compress branch from 9064f4e to d889387 Compare February 20, 2026 10:49
@matthiasbruns

Copy link
Copy Markdown
Contributor Author

magically after rebasing main, the bug is fixed
I will test this locally to ensure that its working with the compiled binary

On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns

matthiasbruns commented Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

test.sh

#!/bin/zsh

set -e

rm -rf ./transport-archive ./downloaded-resource ./downloaded-resource-decompressed

./ocm add cv --repository ./transport-archive --constructor ./constructor.yaml

./ocm download resource ./transport-archive//ocm.software/compress-test:v1.0.0 --identity name=myfile,version=v1.0.0 --output ./downloaded-resource --extraction-policy disable

./ocm download resource ./transport-archive//ocm.software/compress-test:v1.0.0 --identity name=myfile,version=v1.0.0 --output ./downloaded-resource-decompressed

echo ""
echo "=== Verification ==="
echo "Compressed (disable extraction):"
file ./downloaded-resource

echo "Decompressed (auto extraction):"
file ./downloaded-resource-decompressed

echo ""
echo "Original content:   $(cat ./testfile.txt)"
echo "Decompressed content: $(cat ./downloaded-resource-decompressed)"

if diff -q ./testfile.txt ./downloaded-resource-decompressed > /dev/null 2>&1; then
  echo "PASS: Decompressed output matches original"
else
  echo "FAIL: Decompressed output does not match original"
  exit 1
fi

constructor.yaml

components:
  - name: ocm.software/compress-test
    version: v1.0.0
    provider:
      name: acme.org
    resources:
      - name: myfile
        version: v1.0.0
        type: blob
        input:
          type: file
          path: ./testfile.txt
          compress: true

testfile.txt

This is the original file content for compress test.

fixed and tested locally with

./test.sh

./ocm add cv --repository ./transport-archive --constructor ./constructor.yaml
time=2026-02-20T13:13:08.238+01:00 level=WARN msg="could not get credential consumer identity for component version repository" repository=./transport-archive error="failed to get component version repository: cannot resolve consumer identity for ctf: credentials not supported"
 COMPONENT                  │ VERSION │ PROVIDER 
────────────────────────────┼─────────┼──────────
 ocm.software/compress-test │ v1.0.0  │ acme.org 

./ocm download resource ./transport-archive//ocm.software/compress-test:v1.0.0 --identity name=myfile,version=v1.0.0 --output ./downloaded-resource --extraction-policy disable
time=2026-02-20T13:13:08.276+01:00 level=INFO msg="found artifact in descriptor" artifact="name=myfile,version=v1.0.0"
time=2026-02-20T13:13:08.277+01:00 level=INFO msg="resource downloaded successfully" output=./downloaded-resource

./ocm download resource ./transport-archive//ocm.software/compress-test:v1.0.0 --identity name=myfile,version=v1.0.0 --output ./downloaded-resource-decompressed
time=2026-02-20T13:13:08.297+01:00 level=INFO msg="found artifact in descriptor" artifact="name=myfile,version=v1.0.0"
time=2026-02-20T13:13:08.298+01:00 level=INFO msg="resource downloaded successfully" output=./downloaded-resource-decompressed

=== Verification ===
Compressed (disable extraction):
./downloaded-resource: gzip compressed data, original size modulo 2^32 52
Decompressed (auto extraction):
./downloaded-resource-decompressed: ASCII text, with no line terminators

Original content:   This is the original file content for compress test.
Decompressed content: This is the original file content for compress test.
PASS: Decompressed output matches original

@matthiasbruns matthiasbruns marked this pull request as ready for review February 20, 2026 12:11
Comment thread cli/cmd/download/resource/cmd.go Outdated
On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns matthiasbruns enabled auto-merge (squash) February 20, 2026 15:30
matthiasbruns and others added 2 commits February 25, 2026 09:04
On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns matthiasbruns force-pushed the fix/1388_ocm_download_compress branch from c003d13 to f7e3e48 Compare February 25, 2026 08:05
piotrjanik
piotrjanik previously approved these changes Mar 2, 2026
matthiasbruns and others added 2 commits March 2, 2026 10:54
On-behalf-of: SAP <matthias.bruns@sap.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@coderabbitai

coderabbitai Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes implement transparent decompression for the ocm download resource command. The auto extraction path now decompresses compressed resources first, then attempts filesystem extraction. Integration tests validate extraction policy behavior across compressed and uncompressed resource scenarios.

Changes

Cohort / File(s) Summary
Resource Download Command Logic
cli/cmd/download/resource/cmd.go
Modified auto extraction path to decompress resources before attempting filesystem extraction. Updated extractFSFromBlob to assert MediaTypeAware on blob input and construct tar filesystem directly from blob data. Enhanced error handling with updated messages.
Integration Tests
cli/integration/download_resource_integration_test.go
Added imports for bytes and blob/compression. Introduced Test_Integration_ConstructorCompress test function validating extraction policy behavior with compressed vs uncompressed resources. Added buildConstructorYAML helper function for test manifest generation with optional compression flag.

Sequence Diagram

sequenceDiagram
    participant Client as Download Request
    participant Cmd as Download Command
    participant Decomp as Decompression
    participant Extract as Extraction
    participant Output as Output Handler

    Client->>Cmd: download resource (auto extraction policy)
    activate Cmd
    Cmd->>Decomp: decompress blob
    activate Decomp
    Decomp->>Decomp: read compressed data
    Decomp->>Extract: return decompressed data
    deactivate Decomp
    
    Extract->>Extract: assert MediaTypeAware
    activate Extract
    Extract->>Extract: attempt filesystem extraction
    alt extraction succeeds
        Extract->>Output: copy extracted filesystem
    else extraction fails (non-ErrCannotExtractFS)
        Extract->>Output: return wrapped error
    else extraction fails (ErrCannotExtractFS)
        Extract->>Output: save decompressed blob
    end
    deactivate Extract
    
    Output->>Client: save to filesystem
    deactivate Cmd
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With whiskers twitching, I hop with glee,
Compressed no more—now decompressed, wild and free!
Tar files unfurl like carrots from the ground,
Resources extracted, no extra steps around!
A smoother path for all who seek,
No compression struggles, coding's chic! 🌱

🚥 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 'fix(1388): fix auto decompress for download resources' directly references the linked issue #1388 and accurately describes the main change: fixing the auto-decompression functionality for the download resources command.
Linked Issues check ✅ Passed The PR implementation meets the core objective from issue #1388: enabling transparent decompression of downloaded resources. The changes fix the auto extraction path to decompress resources first, then attempt filesystem extraction, fulfilling the requirement for automatic decompression when resources are compressed.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing auto-decompression for download resources. Command logic improvements, extractFSFromBlob modifications, and new integration tests for extraction policies with compressed resources are all within scope of issue #1388.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

🧹 Nitpick comments (2)
cli/integration/download_resource_integration_test.go (2)

437-437: Use extraction-policy constants instead of string literals in test cases.

Using resourceCMD.ExtractionPolicyDisable here avoids drift if the CLI value ever changes.

♻️ Proposed fix
-			extractionPolicy: "disable",
+			extractionPolicy: resourceCMD.ExtractionPolicyDisable,
...
-			extractionPolicy: "disable",
+			extractionPolicy: resourceCMD.ExtractionPolicyDisable,

Also applies to: 458-458

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/integration/download_resource_integration_test.go` at line 437, Replace
the string literal "disable" used for the extractionPolicy field in the test
with the constant resourceCMD.ExtractionPolicyDisable; update both occurrences
(the one at extractionPolicy: "disable" and the one at the other reported line)
so the test uses the constant instead of a raw string, referencing
resourceCMD.ExtractionPolicyDisable where the extractionPolicy value is set.

517-535: Quote filePath in generated YAML to harden constructor fixtures.

Plain-scalar YAML paths can break with special characters; quoting the path makes this helper more robust across environments.

🛠️ Proposed fix
-        path: %[5]s%[6]s
+        path: %[5]q%[6]s
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/integration/download_resource_integration_test.go` around lines 517 -
535, The buildConstructorYAML helper emits unquoted YAML file paths which can
break with special chars; update the format string in buildConstructorYAML
(function name) to quote the filePath placeholder so the returned YAML uses
path: "%[5]s" instead of path: %[5]s (keep the compressLine/%[6]s placement
unchanged) to harden the fixture generation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cli/integration/download_resource_integration_test.go`:
- Line 437: Replace the string literal "disable" used for the extractionPolicy
field in the test with the constant resourceCMD.ExtractionPolicyDisable; update
both occurrences (the one at extractionPolicy: "disable" and the one at the
other reported line) so the test uses the constant instead of a raw string,
referencing resourceCMD.ExtractionPolicyDisable where the extractionPolicy value
is set.
- Around line 517-535: The buildConstructorYAML helper emits unquoted YAML file
paths which can break with special chars; update the format string in
buildConstructorYAML (function name) to quote the filePath placeholder so the
returned YAML uses path: "%[5]s" instead of path: %[5]s (keep the
compressLine/%[6]s placement unchanged) to harden the fixture generation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50a3e654-8fe1-4228-b757-d0709557cc54

📥 Commits

Reviewing files that changed from the base of the PR and between 17ed3e2 and 7b38a89.

📒 Files selected for processing (2)
  • cli/cmd/download/resource/cmd.go
  • cli/integration/download_resource_integration_test.go

Comment thread cli/cmd/download/resource/cmd.go
@matthiasbruns matthiasbruns disabled auto-merge March 6, 2026 14:02
@matthiasbruns matthiasbruns merged commit 7c7a99e into open-component-model:main Mar 6, 2026
21 checks passed
@matthiasbruns matthiasbruns deleted the fix/1388_ocm_download_compress branch March 6, 2026 14:02
chrisbleyerSAP pushed a commit to chrisbleyerSAP/open-component-model that referenced this pull request Mar 6, 2026
…-model#1800)

<!-- markdownlint-disable MD041 -->
#### What this PR does / why we need it
This pr handles the missing decompression of a downloaded resource if it
was uploaded with compression.
While the flags are correctly read and set to default `auto`, the
decompression does not kick in.

This PR fixes the problem

#### Which issue(s) this PR fixes
Fixes:
open-component-model#1388


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved resource download handling by adjusting the decompression and
extraction workflow to ensure proper handling of compressed resources
and extraction policies.

* **Tests**
* Added comprehensive integration tests validating resource extraction
policies with various compression scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
Co-authored-by: Fabian Burth <fabian.burth@sap.com>
chrisbleyerSAP pushed a commit to chrisbleyerSAP/open-component-model that referenced this pull request Mar 6, 2026
…-model#1800)

<!-- markdownlint-disable MD041 -->
#### What this PR does / why we need it
This pr handles the missing decompression of a downloaded resource if it
was uploaded with compression.
While the flags are correctly read and set to default `auto`, the
decompression does not kick in.

This PR fixes the problem

#### Which issue(s) this PR fixes
Fixes:
open-component-model#1388


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved resource download handling by adjusting the decompression and
extraction workflow to ensure proper handling of compressed resources
and extraction policies.

* **Tests**
* Added comprehensive integration tests validating resource extraction
policies with various compression scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
Co-authored-by: Fabian Burth <fabian.burth@sap.com>
frewilhelm pushed a commit to frewilhelm/open-component-model that referenced this pull request Mar 12, 2026
…-model#1800)

<!-- markdownlint-disable MD041 -->
#### What this PR does / why we need it
This pr handles the missing decompression of a downloaded resource if it
was uploaded with compression.
While the flags are correctly read and set to default `auto`, the
decompression does not kick in.

This PR fixes the problem

#### Which issue(s) this PR fixes
Fixes:
open-component-model#1388


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved resource download handling by adjusting the decompression and
extraction workflow to ensure proper handling of compressed resources
and extraction policies.

* **Tests**
* Added comprehensive integration tests validating resource extraction
policies with various compression scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
Co-authored-by: Fabian Burth <fabian.burth@sap.com>
morri-son pushed a commit to morri-son/open-component-model that referenced this pull request Mar 18, 2026
…-model#1800)

<!-- markdownlint-disable MD041 -->
#### What this PR does / why we need it
This pr handles the missing decompression of a downloaded resource if it
was uploaded with compression.
While the flags are correctly read and set to default `auto`, the
decompression does not kick in.

This PR fixes the problem

#### Which issue(s) this PR fixes
Fixes:
open-component-model#1388

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved resource download handling by adjusting the decompression and
extraction workflow to ensure proper handling of compressed resources
and extraction policies.

* **Tests**
* Added comprehensive integration tests validating resource extraction
policies with various compression scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
Co-authored-by: Fabian Burth <fabian.burth@sap.com>
Signed-off-by: Gerald Morrison (SAP) <gerald.morrison@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bugfix Bug kind/feature new feature, enhancement, improvement, extension size/m Medium size/xl Extra large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ocm download resource to transparently uncompress it as well

6 participants