Skip to content

🐛 Validate custom rules file types in profile file dialog - #1477

Open
ibolton336 wants to merge 1 commit into
konveyor:mainfrom
ibolton336:fix/580-ruleset-file-validation
Open

🐛 Validate custom rules file types in profile file dialog#1477
ibolton336 wants to merge 1 commit into
konveyor:mainfrom
ibolton336:fix/580-ruleset-file-validation

Conversation

@ibolton336

@ibolton336 ibolton336 commented Jul 28, 2026

Copy link
Copy Markdown
Member

Fixes #580

Summary

The "Select Custom Rules" dialog (Manage Profile → Configure Custom Rules) accepted any file type — .java, .png, etc. were silently added to the profile as custom rules.

Changes

  • Filter the file dialog to YAML rule files (.yaml/.yml), matching the webview upload path which already enforces YAML-only
  • Validate the selection after the dialog closes, since dialog filters don't apply to folders and aren't enforced on all platforms: non-YAML files are skipped with a warning listing the skipped names
  • Folders are still accepted as rule directories
  • Adds a changelog fragment

Verification

  • tsc --noEmit clean on vscode/core
  • eslint clean on the changed file
  • npm run changelog:validate passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Custom rule selection now accepts YAML rule files and directories while ignoring unsupported file types.
    • Invalid selections are skipped with a warning, helping prevent unintended files from being added.
    • The configuration flow now stops when no valid rule inputs remain.

Fixes konveyor#580

The Select Custom Rules dialog accepted any file type. Filter the dialog
to YAML rule files and validate the selection, skipping non-YAML files
with a warning (dialog filters don't apply to folders and are not
enforced on all platforms). Folders are still accepted as rule
directories, matching the webview upload path which already validates
.yaml/.yml.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ibolton336
ibolton336 requested a review from a team as a code owner July 28, 2026 16:56
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Custom rule selection now uses a YAML-specific file filter and validates each selected URI. Directories remain accepted, while non-YAML files are skipped and listed in a warning. The flow exits when no valid inputs remain, and the unreleased changelog documents this behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: abrugaro

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, uses the required 🐛 prefix, and accurately describes the main change.
Description check ✅ Passed The description includes the issue link, summary, changes, and verification details expected by the template.
Linked Issues check ✅ Passed The change blocks invalid custom-rule files while still accepting directories, matching the linked issue's core requirement.
Out of Scope Changes check ✅ Passed Only the changelog and custom-rules selection logic were changed; no unrelated scope appears introduced.
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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: 1

🤖 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 `@vscode/core/src/utilities/profiles/profileActions.ts`:
- Around line 21-34: Update the selection loop in profileActions to wrap each
workspace.fs.stat call in try/catch, recording failures separately from skipped
non-YAML filenames and continuing with subsequent URIs. Preserve the existing
directory/YAML validation for successful stats and ensure both failure
categories remain available for later handling.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d9e90cc-55ae-46a6-88ce-f3b6e69f6ae2

📥 Commits

Reviewing files that changed from the base of the PR and between ed42f5a and 2f0bfd0.

📒 Files selected for processing (2)
  • changes/unreleased/580-validate-custom-rules-file-types.yaml
  • vscode/core/src/utilities/profiles/profileActions.ts

Comment on lines +21 to +34
// Dialog filters don't apply to folders and are not enforced on all
// platforms, so validate the selection: directories are accepted as rule
// directories, files must be YAML.
const validUris: Uri[] = [];
const skippedNames: string[] = [];
for (const uri of fileUris) {
const stat = await workspace.fs.stat(uri);
const isDirectory = (stat.type & FileType.Directory) !== 0;
const isYamlFile = uri.fsPath.endsWith(".yaml") || uri.fsPath.endsWith(".yml");
if (isDirectory || isYamlFile) {
validUris.push(uri);
} else {
skippedNames.push(basename(uri.fsPath));
}

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Locate file =="
git ls-files | rg '(^|/)profileActions\.ts$|profiles/profileActions\.ts$' || true

echo "== File outline/size =="
wc -l vscode/core/src/utilities/profiles/profileActions.ts
ast-grep outline vscode/core/src/utilities/profiles/profileActions.ts || true

echo "== Relevant file section =="
sed -n '1,120p' vscode/core/src/utilities/profiles/profileActions.ts

echo "== Search stat/usages of validUris/skippedNames =="
rg -n "workspace\.fs\.stat|validUris|skippedNames|getProfiles|save|yaml|yml" vscode/core/src/utilities/profiles/profileActions.ts

Repository: konveyor/editor-extensions

Length of output: 4702


🌐 Web query:

Microsoft VSCode API workspace.fs.stat Error FileSystemError stat does not find file throws documentation

💡 Result:

In the Visual Studio Code extension API, the vscode.workspace.fs.stat method is designed to throw a vscode.FileSystemError when the target file or folder cannot be found [1][2]. When implementing or consuming this API, you should handle this scenario using a try-catch block [1][2]. Specifically, when a file is missing, the API throws an error that satisfies e instanceof vscode.FileSystemError and whose name or code corresponds to FileNotFound [1][2][3]. Key technical details: - Error Handling: To verify if a file does not exist, wrap the stat call in a try-catch and check for the FileNotFound error [1][2]. - Implementation Requirements: If you are implementing a custom FileSystemProvider, you are expected to throw vscode.FileSystemError.FileNotFound() when a requested path does not exist [4]. This allows VS Code to correctly propagate the state and identify the missing file [4]. - Identification: You can identify the specific error type by checking the error object's name or code property, which will be set to FileNotFound [3][5]. Note that some custom FileSystemProvider implementations (such as specific Git provider versions) may behave inconsistently if not properly configured to throw these errors; however, the standard expectation for the vscode.workspace.fs.stat API is that it must signal a missing entry by throwing the appropriate FileSystemError [6][4].

Citations:


🌐 Web query:

VSCode FileSystemError.name FileNotFound stat throws error code name

💡 Result:

In the Visual Studio Code extension API, when implementing a FileSystemProvider—such as the stat method—you should throw a vscode.FileSystemError.FileNotFound error to indicate that a requested file or directory does not exist [1][2]. For your implementation, use the built-in factory method: throw vscode.FileSystemError.FileNotFound(uri); Key technical details regarding FileSystemError codes: 1. Identifying Errors: The FileSystemError class includes a code property that identifies the type of error [3][4]. This code corresponds to the class name of the factory method (e.g., 'FileNotFound') [3][5]. 2. Internal Mappings: Internally, VS Code maps these errors to specific provider error codes (like EntryNotFound) [6]. When you throw using the provided factory methods, the VS Code file service correctly handles and identifies these errors [1][7]. 3. Best Practice: Always use the static factory methods provided by the vscode.FileSystemError class (e.g., FileExists, FileNotADirectory, NoPermissions) rather than manually constructing an error object [1][5][8]. This ensures the error is correctly recognized by the host side of the VS Code API [1].

Citations:


Handle workspace.fs.stat failures per selection.

window.showOpenDialog can return stale or unsupported URIs, and workspace.fs.stat(uri) can throw before later selections are evaluated. Wrap each stat call in try/catch, track stat failures separately from non-YAML files, and continue evaluating the remaining selections.

🤖 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 `@vscode/core/src/utilities/profiles/profileActions.ts` around lines 21 - 34,
Update the selection loop in profileActions to wrap each workspace.fs.stat call
in try/catch, recording failures separately from skipped non-YAML filenames and
continuing with subsequent URIs. Preserve the existing directory/YAML validation
for successful stats and ensure both failure categories remain available for
later handling.

fabianvf added a commit that referenced this pull request Aug 4, 2026
## Summary

`Test (macos)` has been failing on every PR since VS Code 1.131.0
shipped, and `Verify changelog fragment` fails on every fork PR. Both
are broken on main, not by any particular change. Confirmed by running
`npx vscode-test` on a clean `ed42f5a` checkout.

- 1.131.0 dropped `Contents/MacOS/Electron` for `Contents/MacOS/Code`,
and `@vscode/test-electron` 2.x still spawns the old name.
`.vscode-test.mjs` pins no version so it picks up stable at run time,
which is why this started on its own. #1477 passed on 1.130.0. macOS
failing then cancels linux and windows via fail-fast, so all three go
red.
- Bump `@vscode/test-electron` to 3.x. That gets it launching and
exposes a second macOS failure underneath: VS Code opens a unix socket
in its user data dir, and the default `.vscode-test/user-data` path is
over the 104 byte `sun_path` limit. CI's macOS path is exactly 104, so
the bump on its own would have swapped one failure for another. Point
`--user-data-dir` at a short temp path.
- `@vscode/test-cli` stops at 0.0.14 on purpose. 0.0.15 pulls
`yargs@18`, which wants node `^22.12.0`, and `.nvmrc` is v22.9.0, so
install dies with EBADENGINE before anything runs. Bumping `.nvmrc`
would also work but that is a bigger call than this PR should make.
- The changelog job checks out the PR head, which `actions/checkout` now
refuses under `pull_request_target` since that runs fork code with a
privileged token. It only needs the changed filenames, so ask the API
for them instead. Avoids opting into `allow-unsafe-pr-checkout`.

`test:integration` reports 0 passing before and after, because the
webpack build never emits `out/test/`. That step exists to launch VS
Code and exit clean, and it does again. The 150 tests CI reports come
from `test:unit-tests`.

## Test plan

- [x] `npx vscode-test` on main reproduces the macOS failure, and passes
with these changes
- [x] `Test (macos)`, `Test (linux)` and `Test (windows)` green on this
PR
- [ ] `Verify changelog fragment` green on the next bugfix or feature
PR. It is skipped here since this is `:seedling:`

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
fabianvf added a commit that referenced this pull request Aug 6, 2026
…) (#1481)

## Summary

`Test (macos)` has been failing on every PR since VS Code 1.131.0
shipped, and `Verify changelog fragment` fails on every fork PR. Both
are broken on main, not by any particular change. Confirmed by running
`npx vscode-test` on a clean `ed42f5a` checkout.

- 1.131.0 dropped `Contents/MacOS/Electron` for `Contents/MacOS/Code`,
and `@vscode/test-electron` 2.x still spawns the old name.
`.vscode-test.mjs` pins no version so it picks up stable at run time,
which is why this started on its own. #1477 passed on 1.130.0. macOS
failing then cancels linux and windows via fail-fast, so all three go
red.
- Bump `@vscode/test-electron` to 3.x. That gets it launching and
exposes a second macOS failure underneath: VS Code opens a unix socket
in its user data dir, and the default `.vscode-test/user-data` path is
over the 104 byte `sun_path` limit. CI's macOS path is exactly 104, so
the bump on its own would have swapped one failure for another. Point
`--user-data-dir` at a short temp path.
- `@vscode/test-cli` stops at 0.0.14 on purpose. 0.0.15 pulls
`yargs@18`, which wants node `^22.12.0`, and `.nvmrc` is v22.9.0, so
install dies with EBADENGINE before anything runs. Bumping `.nvmrc`
would also work but that is a bigger call than this PR should make.
- The changelog job checks out the PR head, which `actions/checkout` now
refuses under `pull_request_target` since that runs fork code with a
privileged token. It only needs the changed filenames, so ask the API
for them instead. Avoids opting into `allow-unsafe-pr-checkout`.

`test:integration` reports 0 passing before and after, because the
webpack build never emits `out/test/`. That step exists to launch VS
Code and exit clean, and it does again. The 150 tests CI reports come
from `test:unit-tests`.

## Test plan

- [x] `npx vscode-test` on main reproduces the macOS failure, and passes
with these changes
- [x] `Test (macos)`, `Test (linux)` and `Test (windows)` green on this
PR
- [ ] `Verify changelog fragment` green on the next bugfix or feature
PR. It is skipped here since this is `:seedling:`

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cherry Picker <noreply@github.com>

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>
Signed-off-by: Cherry Picker <noreply@github.com>
Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Custom Ruleset File Upload Accepts Invalid File Types like .java , .png etc

1 participant