Skip to content

feat(cli): support short-syntax referencing for archives#618

Closed
jakobmoellerdev wants to merge 3 commits into
open-component-model:mainfrom
jakobmoellerdev:properly-discover-suffix-archives
Closed

feat(cli): support short-syntax referencing for archives#618
jakobmoellerdev wants to merge 3 commits into
open-component-model:mainfrom
jakobmoellerdev:properly-discover-suffix-archives

Conversation

@jakobmoellerdev

Copy link
Copy Markdown
Member

What this PR does / why we need it

  • Added logic to recognize and exclude archive-like file paths (e.g., .tar, .tgz) from being incorrectly identified as domains.
  • Introduced a utility function looksLikeArchive to validate archive paths against a set of whitelisted extensions (.tar, .tgz, .tar.gz).
  • Extended test coverage to include cases involving archive paths.

Which issue(s) this PR fixes

This enhancement ensures that archive paths are appropriately handled in short-syntax references, improving the accuracy of path resolution.

@github-actions github-actions Bot added kind/feature new feature, enhancement, improvement, extension size/s Small labels Aug 22, 2025
- Added logic to recognize and exclude archive-like file paths (e.g., `.tar`, `.tgz`) from being incorrectly identified as domains.
- Introduced a utility function `looksLikeArchive` to validate archive paths against a set of whitelisted extensions (`.tar`, `.tgz`, `.tar.gz`).
- Extended test coverage to include cases involving archive paths.

This enhancement ensures that archive paths are appropriately handled in short-syntax references, improving the accuracy of path resolution.

Signed-off-by: Jakob Möller <jakob.moeller@sap.com>
@jakobmoellerdev jakobmoellerdev force-pushed the properly-discover-suffix-archives branch from b9a85b3 to fd152b8 Compare August 22, 2025 10:31
@jakobmoellerdev jakobmoellerdev marked this pull request as ready for review August 22, 2025 10:48
@jakobmoellerdev jakobmoellerdev requested a review from a team as a code owner August 22, 2025 10:48
…uction

- Introduced tests to validate support for `.tar` and `.tar.gz` archive formats in component version construction.
- Ensured proper handling of working directory and YAML-based construction for archive inputs.
- Improved robustness of the CLI's archive-related functionality with additional test cases.

Signed-off-by: Jakob Möller <jakob.moeller@sap.com>
Signed-off-by: Jakob Möller <jakob.moeller@sap.com>
// be interpreted as path, it needs to be passed explicitly
func looksLikeArchive(s string) bool {
for _, ext := range allowListArchiveFilePathExtensions {
if strings.HasSuffix(s, ext) {

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.

Wouldn't it be a bit more reliable if we did an archive check via reading tar or something? You know something simple like this:

// isTar checks if a given content is a tar archive or not.
func isTar(content []byte) bool {
	tr := tar.NewReader(bytes.NewBuffer(content))
	_, err := tr.Next()

	return err == nil
}

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.

hm, I guess that would require to have the content here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess I was hoping to not have to open a file descriptor on here. I could do that of course in theory, but that would make the operation significantly more expensive. WDYT?

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.

I'd say let's roll with the looksLikeArchive logic - it is very simple and maintainable, and therefore, a very practical solution for the current problem.
Besides, I think relying on file extensions is a quite common thing to do.

Comment thread cli/cmd/cmd_test.go
text: foobar
`)

// Create a replacement test file to be added to the component version

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.

I don't understand that comment

Comment thread cli/cmd/cmd_test.go
"--constructor", constructorYAMLFilePath,
"--repository", filepath.Join("transport-archive", tc),
"--working-directory", tmp,
), test.WithOutput(logs))

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.

We aren't using the logs, are we?

Comment thread cli/cmd/cmd_test.go
Comment on lines +473 to +477
t.Run("archives", func(t *testing.T) {
tcs := []string{
".tar",
".tar.gz",
}

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.

I feel like this test should not be a table test. The table test should happen based on the allow list in the compref packages unit tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

so it should be a table test but use the allow list as entries? :D

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.

Sorry - might have been a little vague. I think the table test makes sense. But it should not be a table test in the e2e cli tests but rather in the reference parsing tests. Don't you think so?

@jakobmoellerdev

Copy link
Copy Markdown
Member Author

Closing in favor of a properly tested implementation as a learning opportunity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature new feature, enhancement, improvement, extension size/s Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants