Skip to content

fix/setup vscode command failing with url and repo key - #527

Open
reshmifrog wants to merge 3 commits into
mainfrom
RTECO-1514-setup-vscode-fails-with-url-and-repo-key-for-ai-editor-extensions-repositories
Open

fix/setup vscode command failing with url and repo key#527
reshmifrog wants to merge 3 commits into
mainfrom
RTECO-1514-setup-vscode-fails-with-url-and-repo-key-for-ai-editor-extensions-repositories

Conversation

@reshmifrog

@reshmifrog reshmifrog commented Aug 4, 2026

Copy link
Copy Markdown
Contributor
  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • Appropriate label is added to auto generate release notes.
  • I used gofmt for formatting the code before submitting the pull request.
  • PR description is clear and concise, and it includes the proposed solution/fix.

Summary by CodeRabbit

  • New Features

    • Added support for resolving server connections from URLs, repository keys, credentials, and saved configuration.
    • Automatically normalizes repository URLs and provides clearer guidance when credentials or hosts do not match.
    • Added logging when URL corrections are applied.
  • Bug Fixes

    • Improved handling of malformed, API, repository, and unexpected-path URLs.
    • Prevented credential reuse across different server hosts.
  • Tests

    • Added comprehensive coverage for server resolution, URL validation, normalization, credential handling, and API URL construction.

@reshmifrog
reshmifrog requested a review from a team August 4, 2026 04:40
@reshmifrog reshmifrog added the bug Something isn't working label Aug 4, 2026
…epo-key-for-ai-editor-extensions-repositories
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change updates server-detail resolution, supports same-host URL overrides with credential reuse, normalizes Artifactory base URLs, and validates normalized details in AI editor setup parsing. Tests cover configuration paths, URL formats, validation, and constants.

Changes

Server configuration and URL flow

Layer / File(s) Summary
Server resolution and credential selection
ide/common/base.go, ide/common/base_test.go
GetServerDetails now handles credential flags, server IDs, URL overrides, and default configuration. Tests cover credential reuse and host validation.
Artifactory URL normalization
ide/common/base.go, ide/common/base_test.go
NormalizeArtifactoryBaseUrl validates paths, removes matching repository suffixes, and preserves URL components.
Base setup integration and validation
ide/commands/aieditorextensions/base.go, ide/commands/aieditorextensions/base_test.go
Base setup propagates errors, normalizes explicit URLs before validation, logs corrections, and validates the updated server details. Tests cover positional URLs and malformed configurations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ParseBaseSetupConfig
  participant GetServerDetails
  participant NormalizeArtifactoryBaseUrl
  participant RepositoryValidation
  ParseBaseSetupConfig->>GetServerDetails: resolve server details
  GetServerDetails-->>ParseBaseSetupConfig: return server details
  ParseBaseSetupConfig->>NormalizeArtifactoryBaseUrl: normalize URL and repository key
  NormalizeArtifactoryBaseUrl-->>ParseBaseSetupConfig: return normalized URL
  ParseBaseSetupConfig->>RepositoryValidation: validate normalized details
Loading

Suggested reviewers: agrasth, bhanurp

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the fix for the setup vscode command when used with a URL and repository key.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch RTECO-1514-setup-vscode-fails-with-url-and-repo-key-for-ai-editor-extensions-repositories

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

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
ide/commands/aieditorextensions/base.go (1)

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

Fix the split comment sentence.

The second line starts mid-sentence with a stray space.

✏️ Proposed change
-	// If --url was supplied, normalize it before we make any network call.
-	//  and rejects obviously wrong shapes like a full /api/… URL.
+	// If --url was supplied, normalize it before we make any network call.
+	// Normalization strips a trailing repo-key segment and rejects wrong
+	// shapes such as a full /api/… URL.
🤖 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 `@ide/commands/aieditorextensions/base.go` around lines 64 - 65, Fix the
adjacent comments in the URL normalization section so they form one
grammatically complete sentence, removing the stray leading space and sentence
fragment on the second line.
ide/common/base.go (1)

25-43: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Do not discard the config read error.

Line 27 merges a real failure from config.GetDefaultServerConf with the "no default server" case. If the JFrog config file is corrupt or unreadable, the user sees "no default server is configured" and loses the actual cause. Report the underlying error.

Also consider updating defaults.Url together with defaults.ArtifactoryUrl, so that both fields stay consistent for any consumer that reads Url.

🔧 Proposed change
 	if c.IsFlagSet("url") {
 		defaults, err := config.GetDefaultServerConf()
-		if err != nil || defaults == nil {
+		if err != nil {
+			return nil, fmt.Errorf("failed reading the configured servers: %w", err)
+		}
+		if defaults == nil {
 			return nil, fmt.Errorf(
 				"--url was provided but no default server is configured and no credentials were supplied. " +
 					"Either run 'jf config add' to configure a server, or pass --access-token " +
 					"(or --user and --password) alongside --url")
 		}
🤖 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 `@ide/common/base.go` around lines 25 - 43, Update the url-handling branch
around config.GetDefaultServerConf to distinguish a non-nil read error from a
nil defaults result, returning an error that preserves the underlying
configuration failure instead of reporting only a missing default server. When
overriding the configured host, update both defaults.ArtifactoryUrl and
defaults.Url so consumers of either field see the same URL.
ide/commands/aieditorextensions/base_test.go (1)

104-125: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the external network dependency from these two tests.

Both tests reach common.ValidateRepository, which sends a real HTTP request to acme.jfrog.io. The tests therefore depend on DNS and on how that external host responds. They are slow in CI, and they fail if the host ever returns a success response. The NotContains assertions also pass for any unrelated failure, so they do not confirm that the flow reached validation.

Point ArtifactoryUrl and --url at an httptest.Server that returns a controlled repository response. You can then assert the exact outcome, including the normalized base URL that reached the server.

Also applies to: 152-172

🤖 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 `@ide/commands/aieditorextensions/base_test.go` around lines 104 - 125, Update
TestParseBaseSetupConfig_UrlAlone_DefaultConfig_ReachesValidation and the
corresponding test around ParseBaseSetupConfig to use an httptest.Server for
both ArtifactoryUrl and --url instead of acme.jfrog.io. Configure the server to
return a controlled repository response, record the request, and replace broad
NotContains assertions with exact validation outcomes and an assertion that the
normalized base URL reached the test server.
🤖 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 `@ide/common/base.go`:
- Around line 197-215: Update the Case B logic in NormalizeArtifactoryBaseUrl so
it strips a matching repoKey only when it is directly after the artifactory
anchor or when no anchor exists; otherwise let Case C reject deep paths. Add a
TestNormalizeArtifactoryBaseUrl table case for
https://acme.jfrog.io/artifactory/some-repo/my-repo with repoKey "my-repo" and
assert the validation error.

---

Nitpick comments:
In `@ide/commands/aieditorextensions/base_test.go`:
- Around line 104-125: Update
TestParseBaseSetupConfig_UrlAlone_DefaultConfig_ReachesValidation and the
corresponding test around ParseBaseSetupConfig to use an httptest.Server for
both ArtifactoryUrl and --url instead of acme.jfrog.io. Configure the server to
return a controlled repository response, record the request, and replace broad
NotContains assertions with exact validation outcomes and an assertion that the
normalized base URL reached the test server.

In `@ide/commands/aieditorextensions/base.go`:
- Around line 64-65: Fix the adjacent comments in the URL normalization section
so they form one grammatically complete sentence, removing the stray leading
space and sentence fragment on the second line.

In `@ide/common/base.go`:
- Around line 25-43: Update the url-handling branch around
config.GetDefaultServerConf to distinguish a non-nil read error from a nil
defaults result, returning an error that preserves the underlying configuration
failure instead of reporting only a missing default server. When overriding the
configured host, update both defaults.ArtifactoryUrl and defaults.Url so
consumers of either field see the same URL.
🪄 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: 6be41a83-bba4-4a09-8a4d-e3819418d848

📥 Commits

Reviewing files that changed from the base of the PR and between cea6be6 and a7d15f8.

📒 Files selected for processing (4)
  • ide/commands/aieditorextensions/base.go
  • ide/commands/aieditorextensions/base_test.go
  • ide/common/base.go
  • ide/common/base_test.go

Comment thread ide/common/base.go
Comment on lines +197 to +215
// Case B: trailing segment matches --repo-key → strip it.
last := segments[len(segments)-1]
if repoKey != "" && strings.EqualFold(last, repoKey) {
return rebuildUrlWithoutLastSegment(u, rawUrl), nil
}

// Case C: extra segments after "/artifactory/"
if artIndex >= 0 && artIndex < len(segments)-1 {
extra := strings.Join(segments[artIndex+1:], "/")
hint := ""
if repoKey != "" {
hint = fmt.Sprintf(" (--repo-key is set to %q, which does not match)", repoKey)
}
return "", fmt.Errorf(
"--url %q includes a path segment after '/artifactory/' (%q)%s. "+
"--url must be the Artifactory base URL (e.g. https://acme.jfrog.io/artifactory), "+
"without a repository key. Move the repository name to --repo-key",
rawUrl, extra, hint)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Case B bypasses the Case C validation for deep paths.

Case B returns as soon as the last segment matches repoKey, so Case C never inspects the remaining path. For --url https://acme.jfrog.io/artifactory/some-repo/my-repo with --repo-key my-repo, the function returns https://acme.jfrog.io/artifactory/some-repo and reports no error. The caller then treats some-repo as part of the Artifactory base URL, so repository validation and the built service URL both target a wrong path. The equivalent input without the repo-key suffix (/artifactory/some-repo/nested/path) is correctly rejected.

Strip the trailing segment only when it sits directly after the artifactory anchor, or when no anchor exists.

🐛 Proposed fix
 	// Case B: trailing segment matches --repo-key → strip it.
 	last := segments[len(segments)-1]
-	if repoKey != "" && strings.EqualFold(last, repoKey) {
+	// Only strip when the repo key is the single segment below the anchor, so
+	// deeper paths still fall through to the Case C rejection below.
+	if repoKey != "" && strings.EqualFold(last, repoKey) &&
+		(artIndex < 0 || artIndex == len(segments)-2) {
 		return rebuildUrlWithoutLastSegment(u, rawUrl), nil
 	}

Please add a table case for https://acme.jfrog.io/artifactory/some-repo/my-repo with repoKey: "my-repo" in TestNormalizeArtifactoryBaseUrl.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Case B: trailing segment matches --repo-key → strip it.
last := segments[len(segments)-1]
if repoKey != "" && strings.EqualFold(last, repoKey) {
return rebuildUrlWithoutLastSegment(u, rawUrl), nil
}
// Case C: extra segments after "/artifactory/"
if artIndex >= 0 && artIndex < len(segments)-1 {
extra := strings.Join(segments[artIndex+1:], "/")
hint := ""
if repoKey != "" {
hint = fmt.Sprintf(" (--repo-key is set to %q, which does not match)", repoKey)
}
return "", fmt.Errorf(
"--url %q includes a path segment after '/artifactory/' (%q)%s. "+
"--url must be the Artifactory base URL (e.g. https://acme.jfrog.io/artifactory), "+
"without a repository key. Move the repository name to --repo-key",
rawUrl, extra, hint)
}
// Case B: trailing segment matches --repo-key → strip it.
last := segments[len(segments)-1]
// Only strip when the repo key is the single segment below the anchor, so
// deeper paths still fall through to the Case C rejection below.
if repoKey != "" && strings.EqualFold(last, repoKey) &&
(artIndex < 0 || artIndex == len(segments)-2) {
return rebuildUrlWithoutLastSegment(u, rawUrl), nil
}
// Case C: extra segments after "/artifactory/"
if artIndex >= 0 && artIndex < len(segments)-1 {
extra := strings.Join(segments[artIndex+1:], "/")
hint := ""
if repoKey != "" {
hint = fmt.Sprintf(" (--repo-key is set to %q, which does not match)", repoKey)
}
return "", fmt.Errorf(
"--url %q includes a path segment after '/artifactory/' (%q)%s. "+
"--url must be the Artifactory base URL (e.g. https://acme.jfrog.io/artifactory), "+
"without a repository key. Move the repository name to --repo-key",
rawUrl, extra, hint)
}
🤖 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 `@ide/common/base.go` around lines 197 - 215, Update the Case B logic in
NormalizeArtifactoryBaseUrl so it strips a matching repoKey only when it is
directly after the artifactory anchor or when no anchor exists; otherwise let
Case C reject deep paths. Add a TestNormalizeArtifactoryBaseUrl table case for
https://acme.jfrog.io/artifactory/some-repo/my-repo with repoKey "my-repo" and
assert the validation error.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant