Skip to content

feat(Kamelets): implement getResourcesContentByType for local kamelets - #1462

Open
lordrip wants to merge 3 commits into
KaotoIO:mainfrom
lordrip:feat/get-resource-by-type
Open

feat(Kamelets): implement getResourcesContentByType for local kamelets#1462
lordrip wants to merge 3 commits into
KaotoIO:mainfrom
lordrip:feat/get-resource-by-type

Conversation

@lordrip

@lordrip lordrip commented Jul 28, 2026

Copy link
Copy Markdown
Member

Context

Implement the previously stubbed getResourcesContentByType method in VSCodeKaotoEditorChannelApi to load local .kamelet.yaml files from the directories configured in the kaoto.localKameletDirectories setting.

The method resolves configured paths relative to the currently edited document, reads all .kamelet.yaml files from each directory, and returns their filenames and contents as FileTypesResponse[].

Directory-reading logic is extracted into a standalone helper src/helpers/KameletFileReader.ts to keep cognitive complexity within the SonarQube threshold (typescript:S3776) and to make the behaviour independently testable.

A paths mapping for @kaoto/kaoto/models is added to tsconfig.unit-tests.json so that the new helper compiles correctly under the moduleResolution: Node setting used by the test build.

fix: #1461

Summary by CodeRabbit

  • New Features
    • Added support for loading Kamelet resources from user-configured local directories.
    • Kamelet resources are discovered based on the current document location.
    • Only .kamelet.yaml files are included in editor resources.
  • Bug Fixes
    • Improved resilience when directories or individual files can’t be read; missing/unavailable resources are skipped gracefully.
  • Tests
    • Added and expanded test coverage for Kamelet discovery, filtering, and local directory/path handling.
  • Chores
    • Updated the Kaoto runtime dependency to 2.12.0-RC1.

@lordrip
lordrip requested review from a team and djelinek July 28, 2026 18:17
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@lordrip, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a827e91a-44f3-43e4-8fad-4640377c4fd9

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab29c3 and 41ccbbd.

📒 Files selected for processing (2)
  • src/helpers/KameletFileReader.ts
  • src/test/VSCodeKaotoEditorChannelApi.test.ts
📝 Walkthrough

Walkthrough

Adds a helper for reading local .kamelet.yaml files, integrates configured directories into resource retrieval, adds VS Code and helper tests, updates test type resolution and the Kaoto dependency, and includes two minor cleanup edits.

Changes

Local Kamelet loading

Layer / File(s) Summary
Kamelet directory reader
src/helpers/KameletFileReader.ts, src/test/helpers/KameletFileReader.test.ts
Reads matching Kamelet files through VS Code’s filesystem API, decodes contents, skips failures, and validates filtering and non-recursive behavior.
Configured resource retrieval
src/webview/VSCodeKaotoEditorChannelApi.ts, src/test/VSCodeKaotoEditorChannelApi.test.ts, src/test/global.d.ts, tsconfig.unit-tests.json, package.json
Resolves configured local Kamelet directories relative to the current document, aggregates loaded resources, updates Kaoto model resolution and dependency version, and adds VS Code API and configuration coverage.

Maintenance edits

Layer / File(s) Summary
Return and type cleanup
src/helpers/SuggestionRegistry.ts, src/services/openapi-import.service.ts
Returns suggestion results directly and reformats the OpenAPI method union type.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EditorChannel as VSCodeKaotoEditorChannelApi
  participant Settings as WorkspaceConfiguration
  participant Reader as KameletFileReader
  participant FileSystem as vscode.workspace.fs
  EditorChannel->>Settings: Read local Kamelet directories
  EditorChannel->>EditorChannel: Resolve paths relative to current document
  EditorChannel->>Reader: Read each resolved directory
  Reader->>FileSystem: Enumerate and read .kamelet.yaml files
  FileSystem-->>Reader: File contents
  Reader-->>EditorChannel: Return FileTypesResponse entries
Loading

Possibly related PRs

Suggested reviewers: igarashitm, lhein

Poem

A rabbit hops through YAML bright,
Finds Kamelets tucked from sight.
Paths resolve and files appear,
Tests guard each burrow near.
“Hop hop!” the reader sings with cheer.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated edits in SuggestionRegistry and openapi-import.service that don't support local Kamelet loading. Remove or justify the unrelated refactors, or split them into a separate PR to keep this change focused.
✅ 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 names the main change: implementing local Kamelet resource loading.
Linked Issues check ✅ Passed The PR implements getResourcesContentByType to read configured local .kamelet.yaml files, matching the linked issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@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: 3

🧹 Nitpick comments (2)
src/helpers/KameletFileReader.ts (1)

19-19: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer node:path over path.

Static analysis flags this import; using the node: prefix is the current idiomatic convention for built-in modules.

♻️ Proposed fix
-import * as path from 'path';
+import * as path from 'node:path';
🤖 Prompt for 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.

In `@src/helpers/KameletFileReader.ts` at line 19, Update the built-in path module
import in KameletFileReader to use the node:path specifier instead of path,
preserving the existing path namespace usage.

Source: Linters/SAST tools

src/webview/VSCodeKaotoEditorChannelApi.ts (1)

178-198: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Parallelize directory reads instead of awaiting sequentially.

Each readKameletsFromDirectory call is independent I/O; awaiting them one at a time in the loop adds up latency linearly with the number of configured directories.

♻️ Proposed fix
-		const resources: FileTypesResponse[] = [];
-
-		for (const dir of resolvedDirs) {
-			const dirResources = await readKameletsFromDirectory(dir);
-			resources.push(...dirResources);
-		}
-
-		return resources;
+		const allResources = await Promise.all(Array.from(resolvedDirs).map((dir) => readKameletsFromDirectory(dir)));
+		return allResources.flat();
🤖 Prompt for 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.

In `@src/webview/VSCodeKaotoEditorChannelApi.ts` around lines 178 - 198, Update
getResourcesContentByType to initiate readKameletsFromDirectory for all
resolvedDirs concurrently and await the combined results, then flatten them into
resources while preserving the existing ordering and return behavior.
🤖 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/helpers/KameletFileReader.ts`:
- Around line 44-47: Update the entry filter in the directory-reading loop
around entries to test whether the FileType.File bit is set, rather than
requiring strict equality with FileType.File. Continue excluding non-file
entries and names without the .kamelet.yaml suffix, while allowing symbolic
links that also carry the File bit.

In `@src/test/VSCodeKaotoEditorChannelApi.test.ts`:
- Line 6: Correct the license header in VSCodeKaotoEditorChannelApi.test.ts by
removing the stray word “destination” from the parenthetical phrase, matching
the standard header used in KameletFileReader.ts.
- Around line 485-627: Move the `Deprecated Methods`, `URI and Path Utilities`,
and `Metadata File Path Normalization` suites out of the `should handle null
metadata values` test callback to the surrounding suite level so Mocha registers
them during collection. Keep only the `nullKey` metadata assertion inside that
test, preserving the existing suite contents and behavior.

---

Nitpick comments:
In `@src/helpers/KameletFileReader.ts`:
- Line 19: Update the built-in path module import in KameletFileReader to use
the node:path specifier instead of path, preserving the existing path namespace
usage.

In `@src/webview/VSCodeKaotoEditorChannelApi.ts`:
- Around line 178-198: Update getResourcesContentByType to initiate
readKameletsFromDirectory for all resolvedDirs concurrently and await the
combined results, then flatten them into resources while preserving the existing
ordering and return behavior.
🪄 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 Plus

Run ID: 4e8827af-60b1-4c55-b980-114c8978445b

📥 Commits

Reviewing files that changed from the base of the PR and between d061f34 and f5f4851.

📒 Files selected for processing (8)
  • src/helpers/KameletFileReader.ts
  • src/helpers/SuggestionRegistry.ts
  • src/services/openapi-import.service.ts
  • src/test/VSCodeKaotoEditorChannelApi.test.ts
  • src/test/global.d.ts
  • src/test/helpers/KameletFileReader.test.ts
  • src/webview/VSCodeKaotoEditorChannelApi.ts
  • tsconfig.unit-tests.json

Comment thread src/helpers/KameletFileReader.ts
Comment thread src/test/VSCodeKaotoEditorChannelApi.test.ts Outdated
Comment thread src/test/VSCodeKaotoEditorChannelApi.test.ts
djelinek
djelinek previously approved these changes Jul 29, 2026
@djelinek

Copy link
Copy Markdown
Contributor

code looks good to me.

  • The pipeline with released Kaoto UI build is failing because missing exports, I suppose this should fix Kaoto UI 2.12.0-RC1
  • the UI tests failures with Kaoto UI Main build I need to check.. in progress...

lordrip added 2 commits July 29, 2026 12:21
Implement the previously stubbed `getResourcesContentByType` method in
`VSCodeKaotoEditorChannelApi` to load local `.kamelet.yaml` files from
the directories configured in the `kaoto.localKameletDirectories` setting.

The method resolves configured paths relative to the currently edited
document, reads all `.kamelet.yaml` files from each directory, and returns
their filenames and contents as `FileTypesResponse[]`.

Directory-reading logic is extracted into a standalone helper
`src/helpers/KameletFileReader.ts` to keep cognitive complexity within
the SonarQube threshold (typescript:S3776) and to make the behaviour
independently testable.

A `paths` mapping for `@kaoto/kaoto/models` is added to
`tsconfig.unit-tests.json` so that the new helper compiles correctly
under the `moduleResolution: Node` setting used by the test build.

fix: KaotoIO#1461
@lordrip
lordrip force-pushed the feat/get-resource-by-type branch 2 times, most recently from 2818db9 to 0ab29c3 Compare July 29, 2026 12:38
Detect `FileType.File` as a bit flag instead of comparing for strict
equality, so kamelets reachable through a symbolic link are no longer
skipped. VS Code reports a symlinked file as `File | SymbolicLink` (65),
which never matched the previous `!==` check. Directories stay excluded,
since `Directory & File` is still 0.

Move the `Deprecated Methods`, `URI and Path Utilities` and `Metadata
File Path Normalization` suites out of the body of the `should handle
null metadata values` test and up to the top level. Mocha registers
suites during collection while test callbacks only run during execution,
so these eight tests were never registered and never ran, silently and
with a green build.

Remove a stray word from the license header of
`VSCodeKaotoEditorChannelApi.test.ts`.
@lordrip
lordrip force-pushed the feat/get-resource-by-type branch from 0ab29c3 to 41ccbbd Compare July 29, 2026 12:44
@sonarqubecloud

Copy link
Copy Markdown

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.

[VS Code] Implement getResourcesContentByType method to read local Kamelets

2 participants