Skip to content

fix: import primary artifacts before secondary artifacts - #562

Open
doraem-on wants to merge 2 commits into
microcks:masterfrom
doraem-on:codex/fix-import-dir-primary-order
Open

doraem-on wants to merge 2 commits into
microcks:masterfrom
doraem-on:codex/fix-import-dir-primary-order

Conversation

@doraem-on

Copy link
Copy Markdown

Fixes #561.

import-dir currently uploads examples.yaml before openapi.yaml because it follows filesystem discovery order. On a first import, a secondary artifact can arrive before its API exists and be ignored. This change uploads detected primary artifacts first, preserving discovery order within each group.

Regression tests cover flat and recursive directories, stable ordering, primary-only and secondary-only imports, filtering, and upload-failure accounting. Four cases fail before the fix; all six pass after it. Tests use the real filesystem and a recording upload client; no live Microcks server was used.

Validation:

  • go test ./...
  • go test -race ./cmd -run 'TestImportDirectory' -count=1
  • go build ./...
  • go vet ./...
  • Repository policy guards and git diff --check

AI disclosure: ChatGPT was used to help implement the fix, write regression tests, and review and double-check the changes.

Signed-off-by: Lalit Kishore <lr_be24@thapar.edu>
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

👋 @doraem-on

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

Comment thread cmd/importDir.go Outdated
Comment on lines +215 to +218
// Secondary artifacts can only enrich API definitions that already exist.
sort.SliceStable(files, func(i, j int) bool {
return detectFileType(files[i]).IsPrimary && !detectFileType(files[j]).IsPrimary
})

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.

Avoid sorting overhead. Its TC is in O(nlogn)..
A strict 2 slice partition will be better.

var primary, secondary []string
for _, f := range files {
	// primary and secondary classification
}
orderedFiles := append(primary, secondary...)
// proceed with upload loop over orderedFiles...

Signed-off-by: Lalit Kishore <lr_be24@thapar.edu>
@doraem-on
doraem-on requested a review from Vaishnav88sk October 7, 2026 06:33

This branch has not been deployed

No deployments
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.

import-dir uploads secondary artifacts before their primary API definition

2 participants