fix(1388): fix auto decompress for download resources#1800
Conversation
d73ad42 to
a998e3f
Compare
|
We already have auto-decompress with |
|
this turns out to be a bigger issue with There is currently support for tar, but it seems we usually get I will try to simplify this tomorrow, since I actually had it working for the wrong 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. |
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>
c7afa0a to
9064f4e
Compare
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
9064f4e to
d889387
Compare
|
magically after rebasing main, the bug is fixed |
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
#!/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
ficomponents:
- 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
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 |
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>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
c003d13 to
f7e3e48
Compare
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
📝 WalkthroughWalkthroughThe changes implement transparent decompression for the Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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.ExtractionPolicyDisablehere 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: QuotefilePathin 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
📒 Files selected for processing (2)
cli/cmd/download/resource/cmd.gocli/integration/download_resource_integration_test.go
…-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>
…-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>
…-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>
…-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>

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
Tests