From 231177d9ab0c2eff4ea74973d7d67d37db8bcad2 Mon Sep 17 00:00:00 2001 From: Vageesha B R Date: Tue, 17 Nov 2026 07:35:41 +0530 Subject: [PATCH 1/5] XRAY-169343 - Parse the new all-versions-blocked message for npm and PyPI jf ca reads Xray's "All versions of 'X' (repo) are blocked from download by JFrog Curation." message from the npm debug log and from the PyPI 403 body. It reports every listed policy, uses the Note line as the explanation and the Action line as the recommendation, and keeps parsing the old message format. The Catalog link of a block message is kept as catalog_url in the JSON output, listed after the table, and links the package name in terminals that support hyperlinks. Co-Authored-By: Claude Opus 5.5 --- commands/curation/curationaudit.go | 129 ++++++++++++++++---- commands/curation/curationaudit_test.go | 156 +++++++++++++++++++++++- commands/curation/npmlogparser.go | 43 ++++++- commands/curation/npmlogparser_test.go | 75 ++++++++++-- 4 files changed, 356 insertions(+), 47 deletions(-) diff --git a/commands/curation/curationaudit.go b/commands/curation/curationaudit.go index 37f040eb5..9b6d05d46 100644 --- a/commands/curation/curationaudit.go +++ b/commands/curation/curationaudit.go @@ -1,6 +1,7 @@ package curation import ( + "cmp" "encoding/json" "errors" "fmt" @@ -18,6 +19,7 @@ import ( "sync/atomic" "github.com/google/uuid" + "github.com/jedib0t/go-pretty/v6/text" "github.com/jfrog/gofrog/datastructures" "github.com/jfrog/gofrog/parallel" rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" @@ -90,6 +92,11 @@ const ( // "All versions blocked - {policy:openssf-jfca,condition:openssf}". allVersionsBlockedMsgPattern = `(?i)all versions blocked\s*-\s*\{\s*policy:([^,}]+),condition:([^}]+)\}` + // allVersionsOfPattern matches Xray's whole-package-block message with its lines joined by spaces: + // "All versions of 'X' (repo) are blocked from download by JFrog Curation. Blocked by one or more of + // these policies: 1. P (C) 2. ... Note: ... Action: ... Details: ...". + allVersionsOfPattern = `All versions of '[^']+' \([^)]*\) are blocked from download by JFrog Curation\.(?: Blocked by one or more of these policies: (.*?))?(?: Note: ([^.]*\.))?(?: Action: (.*?))?(?: Details: (\S+))?$` + errorTemplateHeadRequest = "failed sending HEAD request to %s for package '%s:%s'. Status-code: %v. Cause: %v" errorTemplateUnsupportedTech = "It looks like this project uses '%s' to download its dependencies. " + @@ -130,7 +137,16 @@ const ( var CurationOutputFormats = []string{string(outFormat.Table), string(outFormat.Json)} var osGetwd = os.Getwd var npmGetConfigValue = npmtech.GetNpmConfigValue -var allVersionsBlockedMsgRegex = regexp.MustCompile(allVersionsBlockedMsgPattern) +var ( + allVersionsBlockedMsgRegex = regexp.MustCompile(allVersionsBlockedMsgPattern) + allVersionsOfMsgRegex = regexp.MustCompile(allVersionsOfPattern) + // catalogLinkRegex matches the Catalog link of a single-version block message. + catalogLinkRegex = regexp.MustCompile(`For details and alternatives, visit: (\S+)`) + // allVersionsOfPolicyNumberRegex matches the "1. " / " 2. " numbering between the items of the policy list. + allVersionsOfPolicyNumberRegex = regexp.MustCompile(`(?:^| )\d+\. `) + // allVersionsOfPolicyItemRegex matches one policy list item: P (C), where C may itself contain parentheses. + allVersionsOfPolicyItemRegex = regexp.MustCompile(`^(.+?) \((.*)\)$`) +) var supportedTech = map[techutils.Technology]func(ca *CurationAuditCommand) (bool, error){ techutils.Npm: func(ca *CurationAuditCommand) (bool, error) { return true, nil }, @@ -248,6 +264,7 @@ type PackageStatus struct { ParentName string `json:"direct_dependency_package_name"` ParentVersion string `json:"direct_dependency_package_version"` BlockedPackageUrl string `json:"blocked_package_url,omitempty"` + CatalogURL string `json:"catalog_url,omitempty"` PackageName string `json:"blocked_package_name"` PackageVersion string `json:"blocked_package_version"` BlockingReason string `json:"blocking_reason"` @@ -1564,6 +1581,30 @@ func (ca *CurationAuditCommand) requestWaiver(blockedPackages []*PackageStatus) return coreutils.PrintTable(pkgStatusTable, "Waiver request submitted!", "Requested 0 waivers", true) } +// catalogLinks lists the JFrog Catalog page of each blocked package that has one, once per page. +func catalogLinks(packagesStatus []*PackageStatus) string { + var names, urls []string + seen := map[string]bool{} + width := 0 + for _, ps := range packagesStatus { + if ps.CatalogURL == "" || seen[ps.CatalogURL] { + continue + } + seen[ps.CatalogURL] = true + names, urls = append(names, ps.PackageName), append(urls, ps.CatalogURL) + width = max(width, len(ps.PackageName)) + } + if len(urls) == 0 { + return "" + } + var sb strings.Builder + sb.WriteString("\nFor more details, visit:") + for i := range urls { + fmt.Fprintf(&sb, "\n %-*s %s", width, names[i], urls[i]) + } + return sb.String() +} + func printResult(format outFormat.OutputFormat, projectPath string, packagesStatus []*PackageStatus) error { if format == "" { format = outFormat.Table @@ -1578,17 +1619,22 @@ func printResult(format outFormat.OutputFormat, projectPath string, packagesStat } } case outFormat.Table: - pkgStatusTable := convertToPackageStatusTable(packagesStatus) + pkgStatusTable := convertToPackageStatusTable(packagesStatus, output.TerminalSupportsHyperlinks()) err := coreutils.PrintTable(pkgStatusTable, "Curation", "Found 0 blocked packages", true) if err != nil { return err } + if links := catalogLinks(packagesStatus); links != "" { + log.Output(links) + } } log.Output("\n") return nil } -func convertToPackageStatusTable(packagesStatus []*PackageStatus) []PackageStatusTable { +// convertToPackageStatusTable builds the table rows. With withLinks, a package name with a Catalog +// link becomes a terminal hyperlink to it. +func convertToPackageStatusTable(packagesStatus []*PackageStatus, withLinks bool) []PackageStatusTable { var pkgStatusTable []PackageStatusTable for index, pkgStatus := range packagesStatus { // We use auto-merge supported by the 'go-pretty' library. It doesn't have an option to merge lines by a group of unique fields. @@ -1597,11 +1643,15 @@ func convertToPackageStatusTable(packagesStatus []*PackageStatus) []PackageStatu if index%2 == 0 { uniqLineSep = " " } + packageName := pkgStatus.PackageName + if withLinks { + packageName = text.Hyperlink(pkgStatus.CatalogURL, packageName) + } pkgTable := PackageStatusTable{ ID: fmt.Sprintf("%d%s", index+1, uniqLineSep), ParentName: pkgStatus.ParentName + uniqLineSep, ParentVersion: pkgStatus.ParentVersion + uniqLineSep, - PackageName: pkgStatus.PackageName + uniqLineSep, + PackageName: packageName + uniqLineSep, PackageVersion: pkgStatus.PackageVersion + uniqLineSep, PkgType: pkgStatus.PkgType + uniqLineSep, } @@ -2650,21 +2700,21 @@ func (ca *CurationAuditCommand) runNpmLogFallback(logsDir string, tech techutils const allVersionsBlockedText = "All versions blocked" // wholePackageBlockedStatus synthesizes a *PackageStatus straight from the log's notice+403 -// evidence — no HEAD-check needed. Recommendation is filled in later by +// evidence — no HEAD-check needed. Recommendation is finished later by // applyTransitiveAwareRecommendation, once the graph walk knows the parent. func wholePackageBlockedStatus(entry npmLogEntry, info npmBlockedInfo, tech techutils.Technology) *PackageStatus { + policies := make([]Policy, len(info.Policies)) + for i, p := range info.Policies { + policies[i] = Policy{Policy: p.Policy, Condition: p.Condition, Explanation: cmp.Or(p.Explanation, allVersionsBlockedText), Recommendation: p.Recommendation} + } return &PackageStatus{ PackageName: entry.Name, PackageVersion: allVersionsBlockedText, Action: blocked, BlockingReason: BlockingReasonPolicy, PkgType: string(tech), - Policy: []Policy{{ - Policy: info.Policy, - Condition: info.Condition, - Explanation: allVersionsBlockedText, - // Recommendation is filled in by applyTransitiveAwareRecommendation. - }}, + Policy: policies, + CatalogURL: info.CatalogURL, } } @@ -2681,38 +2731,45 @@ func applyTransitiveAwareRecommendation(ps *PackageStatus, isDirectDependency bo ps.Policy = policies } -// normalizeMatchingWholePackagePolicies normalizes only entries in ps.Policy matching -// aggregatePolicies by Policy+Condition — the same block Step 0 confirmed. A genuinely -// different per-version policy is left untouched. -func normalizeMatchingWholePackagePolicies(ps *PackageStatus, aggregatePolicies []Policy, isDirectDependency bool) { +// normalizeMatchingWholePackagePolicies copies the Explanation/Recommendation of the already +// normalized aggregatePolicies onto the entries in ps.Policy matching them by Policy+Condition — +// the same block Step 0 confirmed. A genuinely different per-version policy is left untouched. +func normalizeMatchingWholePackagePolicies(ps *PackageStatus, aggregatePolicies []Policy) { policies := make([]Policy, len(ps.Policy)) copy(policies, ps.Policy) for i := range policies { - if !matchesAnyPolicy(policies[i], aggregatePolicies) { - continue + if c, ok := matchingPolicy(policies[i], aggregatePolicies); ok { + policies[i].Explanation, policies[i].Recommendation = c.Explanation, c.Recommendation } - normalizeWholePackagePolicy(&policies[i], ps, isDirectDependency) } ps.Policy = policies } -// matchesAnyPolicy reports whether p shares the same Policy+Condition as any of candidates. -func matchesAnyPolicy(p Policy, candidates []Policy) bool { +// matchingPolicy returns the first of candidates sharing the same Policy+Condition as p. +func matchingPolicy(p Policy, candidates []Policy) (Policy, bool) { for _, c := range candidates { if p.Policy == c.Policy && p.Condition == c.Condition { - return true + return c, true } } - return false + return Policy{}, false } // normalizeWholePackagePolicy rewrites a single Policy entry's Explanation/Recommendation -// to the generic, direct/transitive-aware text for a whole-package block. +// to the generic, direct/transitive-aware text for a whole-package block. An Explanation already on +// p is kept. A Recommendation already on p is the Action line of Xray's message and is kept; for a +// transitive dependency it follows the sentence naming the parent. func normalizeWholePackagePolicy(p *Policy, ps *PackageStatus, isDirectDependency bool) { - p.Explanation = allVersionsBlockedText - if isDirectDependency { + p.Explanation = cmp.Or(p.Explanation, allVersionsBlockedText) + action := p.Recommendation + switch { + case isDirectDependency && action != "": + case isDirectDependency: p.Recommendation = "Remove this package from your project and replace with an alternate package" - } else { + case action != "": + p.Recommendation = fmt.Sprintf("%s is a transitive dependency of %s and cannot be removed directly. %s", + ps.PackageName, ps.ParentName, action) + default: p.Recommendation = fmt.Sprintf( "%s is a transitive dependency of %s and cannot be removed directly. Apply a waiver if acceptable, or replace %s with an alternative that doesn't depend on %s.", ps.PackageName, ps.ParentName, ps.ParentName, ps.PackageName) @@ -3003,7 +3060,7 @@ func (nc *treeAnalyzer) fetchCvsBlockedStatus(pins []python.PinnedRequirement) [ // Normalize only the entries that match the aggregate's policy+condition — a // second, genuinely different real policy in the same probe must be preserved. if wholePackageBlocked && wholePackageFallback != nil && len(wholePackageFallback.Policy) > 0 { - normalizeMatchingWholePackagePolicies(pkStatus, wholePackageFallback.Policy, depRelation == directRelation) + normalizeMatchingWholePackagePolicies(pkStatus, wholePackageFallback.Policy) } statuses = append(statuses, pkStatus) } @@ -3098,6 +3155,10 @@ func (nc *treeAnalyzer) getBlockedPackageDetails(packageUrl string, name string, if strings.Contains(strings.ToLower(respError.Errors[0].Message), BlockMessageKey) { blockingReason := BlockingReasonPolicy policies := nc.extractPoliciesFromMsg(respError) + var catalogURL string + if m := catalogLinkRegex.FindStringSubmatch(respError.Errors[0].Message); m != nil { + catalogURL = m[1] + } if len(policies) == 0 { // a server predating per-policy pending behavior sends no {policy,...} groups, only these substrings lowerMsg := strings.ToLower(respError.Errors[0].Message) @@ -3121,6 +3182,20 @@ func (nc *treeAnalyzer) getBlockedPackageDetails(packageUrl string, name string, BlockingReason: blockingReason, WaiverAllowed: strings.Contains(respError.Errors[0].Message, "[waivers allowed]"), PkgType: string(nc.tech), + CatalogURL: catalogURL, + }, nil + } + if m := allVersionsOfMsgRegex.FindStringSubmatch(strings.ReplaceAll(respError.Errors[0].Message, "\n", " ")); m != nil { + policies := allVersionsOfPolicies(m) + return &PackageStatus{ + PackageName: name, + PackageVersion: version, + BlockedPackageUrl: packageUrl, + Action: blocked, + BlockingReason: BlockingReasonPolicy, + Policy: policies, + PkgType: string(nc.tech), + CatalogURL: m[4], }, nil } if m := allVersionsBlockedMsgRegex.FindStringSubmatch(respError.Errors[0].Message); m != nil { diff --git a/commands/curation/curationaudit_test.go b/commands/curation/curationaudit_test.go index cac0d2e31..36c7ea3d6 100644 --- a/commands/curation/curationaudit_test.go +++ b/commands/curation/curationaudit_test.go @@ -2604,6 +2604,7 @@ func TestGetBlockedPackageDetails_PolicyGroupsPreemptPendingSubstrings(t *testin wantReason string wantPolicies []Policy wantWaiver bool + wantCatalog string }{ { name: "old server: package not found in catalog", @@ -2627,7 +2628,8 @@ func TestGetBlockedPackageDetails_PolicyGroupsPreemptPendingSubstrings(t *testin Explanation: "The JFrog Catalog has no data for this package yet so the policy cannot be evaluated against it. This policy is set to block while a package is pending Catalog analysis.", Recommendation: "Request a waiver for this package or wait for the JFrog Catalog to analyze it.", }}, - wantWaiver: true, + wantWaiver: true, + wantCatalog: "http://localhost:8083/ui/catalog/packages/details/npm/@milkio%2Fstargate-worker?ecosystem=generic&showVersions=true", }, { name: "new server: policy group wins over on-demand", @@ -2639,12 +2641,14 @@ func TestGetBlockedPackageDetails_PolicyGroupsPreemptPendingSubstrings(t *testin Explanation: "This package is still being scanned so the policy cannot be evaluated against it. This policy is set to block until the scan finishes.", Recommendation: "Retry the download once the scan completes. No waiver is needed.", }}, + wantCatalog: "http://localhost:8083/ui/catalog/onDemand/packages/details/npm/@milkio%2Fstargate-worker/1.3.65?ecosystem=generic", }, { - name: "curation block with neither policy groups nor a pending substring", - message: `package @milkio/stargate-worker:1.3.65 download was blocked by jfrog packages curation service due to the following policies violated . For details and alternatives, visit: http://localhost:8083/ui/catalog/packages/details/npm/@milkio%2Fstargate-worker?ecosystem=generic&showVersions=true [waivers allowed]`, - wantReason: BlockingReasonUnknown, - wantWaiver: true, + name: "curation block with neither policy groups nor a pending substring", + message: `package @milkio/stargate-worker:1.3.65 download was blocked by jfrog packages curation service due to the following policies violated . For details and alternatives, visit: http://localhost:8083/ui/catalog/packages/details/npm/@milkio%2Fstargate-worker?ecosystem=generic&showVersions=true [waivers allowed]`, + wantReason: BlockingReasonUnknown, + wantWaiver: true, + wantCatalog: "http://localhost:8083/ui/catalog/packages/details/npm/@milkio%2Fstargate-worker?ecosystem=generic&showVersions=true", }, } @@ -2679,6 +2683,7 @@ func TestGetBlockedPackageDetails_PolicyGroupsPreemptPendingSubstrings(t *testin assert.Equal(t, tt.wantReason, got.BlockingReason) assert.Equal(t, tt.wantPolicies, got.Policy) assert.Equal(t, tt.wantWaiver, got.WaiverAllowed) + assert.Equal(t, tt.wantCatalog, got.CatalogURL) }) } } @@ -3693,6 +3698,49 @@ func TestRunNpmLogFallback_MissingPackageJsonStillRecoversReport(t *testing.T) { assert.True(t, directDepNamesContains(report, "blockedpkg"), "blockedpkg is a direct dependency of the real (log-recovered) root, so its recommendation must say so, not treat it as transitive") } +func TestRunNpmLogFallback_AllVersionsOfNotice(t *testing.T) { + serverMock, serverDetails, _ := coreCommonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) { + t.Errorf("unexpected HEAD-check for a whole-package-blocked entry: %s", r.URL.Path) + w.WriteHeader(http.StatusInternalServerError) + }) + defer serverMock.Close() + ca := &CurationAuditCommand{ + PackageManagerConfig: (&project.RepositoryConfig{}).SetTargetRepo("my-npm-remote").SetServerDetails(serverDetails), + extractPoliciesRegex: regexp.MustCompile(extractPoliciesRegexTemplate), + } + const action = "Waivers are allowed for some versions only. Please use a different package, or request a waiver for a version whose policies allow it." + logsDir := filepath.Join(t.TempDir(), "_logs") + require.NoError(t, os.MkdirAll(logsDir, 0755)) + logContent := "0 verbose cli node npm\n" + + "43 notice All versions of 'blockedpkg' (my-npm-remote) are blocked from download by JFrog Curation. " + + "Blocked by one or more of these policies: 1. Block Immature Packages (immature-7) 2. Block Malicious Packages (Malicious package) " + + "Note: Some versions are pending JFrog Catalog analysis. Action: " + action + " Details: https://example.jfrog.io/ui/catalog/blockedpkg\n" + + "44 http fetch GET 403 https://z0test.jfrogdev.org/artifactory/api/npm/my-npm-remote/blockedpkg 100ms (cache skip)\n" + + "45 silly placeDep ROOT blockedpkg@ OK for: realproj@9.9.9 want: ^1.0.0\n" + require.NoError(t, os.WriteFile(filepath.Join(logsDir, "2026-01-01T00_00_00_000Z-debug-0.log"), []byte(logContent), 0644)) + projectDir := t.TempDir() + orig := osGetwd + osGetwd = func() (string, error) { return projectDir, nil } + t.Cleanup(func() { osGetwd = orig }) + results := map[string]*CurationReport{} + + err := ca.runNpmLogFallback(logsDir, techutils.Npm, results, errors.New("error while running 'npm install': exit status 1"), false, 0) + + require.NoError(t, err) + require.Len(t, results, 1) + for _, report := range results { + require.Len(t, report.packagesStatus, 1) + got := report.packagesStatus[0] + assert.Equal(t, "blockedpkg", got.PackageName) + assert.Equal(t, allVersionsBlockedText, got.PackageVersion) + assert.Equal(t, "https://example.jfrog.io/ui/catalog/blockedpkg", got.CatalogURL) + assert.Equal(t, []Policy{ + {Policy: "Block Immature Packages", Condition: "immature-7", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: action}, + {Policy: "Block Malicious Packages", Condition: "Malicious package", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: action}, + }, got.Policy) + } +} + // directDepNamesContains checks pkgName's recommendation uses the direct, not transitive, wording. func directDepNamesContains(report *CurationReport, pkgName string) bool { for _, ps := range report.packagesStatus { @@ -5944,6 +5992,55 @@ func TestFetchCvsBlockedStatusRangedWholePackageBlocked(t *testing.T) { assert.Equal(t, expectedRecTemplate, s.Policy[0].Recommendation, "direct dependency must get the 'remove and replace' recommendation") } +func TestFetchCvsBlockedStatusRangedWholePackageBlockedAllVersionsOfMessage(t *testing.T) { + const action = "Please use a different package or request a waiver to use this one." + blockResponse := `{"errors":[{"status":403,"message":"All versions of 'urllib3' (test-pip-repo) are blocked from download by JFrog Curation.\n` + + `Blocked by one or more of these policies:\n1. p1 (c1 (fix version available))\n2. p2 (package pending JFrog Catalog analysis)\n` + + `Note: Some versions are pending JFrog Catalog analysis.\nAction: ` + action + `\nDetails: https://example.jfrog.io/ui/catalog"}]}` + serverMock, serverDetails, _ := coreCommonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusForbidden) + _, _ = w.Write([]byte(blockResponse)) + }) + defer serverMock.Close() + rtManager, err := rtUtils.CreateServiceManager(serverDetails, 0, 0, false) + require.NoError(t, err) + rtAuth := rtManager.GetConfig().GetServiceDetails() + tests := []struct { + name string + parent string + wantRecommendation string + }{ + {name: "direct", parent: "urllib3", wantRecommendation: action}, + {name: "transitive", parent: "requests", + wantRecommendation: "urllib3 is a transitive dependency of requests and cannot be removed directly. " + action}, + } + for _, tech := range []techutils.Technology{techutils.Pip, techutils.Poetry, techutils.Pipenv, techutils.Uv} { + for _, tt := range tests { + t.Run(tech.String()+"/"+tt.name, func(t *testing.T) { + analyzer := treeAnalyzer{ + rtManager: rtManager, + extractPoliciesRegex: regexp.MustCompile(extractPoliciesRegexTemplate), + rtAuth: rtAuth, + httpClientDetails: rtAuth.CreateHttpClientDetails(), + url: rtAuth.GetUrl(), + repo: "test-pip-repo", + tech: tech, + } + statuses := analyzer.fetchCvsBlockedStatus([]python.PinnedRequirement{{Name: "urllib3", VersionRange: ">=2.0.0", ParentName: tt.parent}}) + + require.Len(t, statuses, 1) + assert.Equal(t, allVersionsBlockedText, statuses[0].PackageVersion) + assert.Equal(t, BlockingReasonPolicy, statuses[0].BlockingReason) + assert.Equal(t, []Policy{ + {Policy: "p1", Condition: "c1 (fix version available)", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: tt.wantRecommendation}, + {Policy: "p2", Condition: "package pending JFrog Catalog analysis", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: tt.wantRecommendation}, + }, statuses[0].Policy) + assert.Equal(t, "https://example.jfrog.io/ui/catalog", statuses[0].CatalogURL) + }) + } + } +} + // TestFetchCvsBlockedStatusPinnedWholePackageBlockedDifferentPolicyThanAggregate covers a // pinned version blocked by a DIFFERENT policy than Step 0's aggregate check. The // per-version detail must be preserved, not overwritten with the unrelated generic text. @@ -7721,3 +7818,52 @@ func TestCredentialFallbackServerDetailsHostCheck(t *testing.T) { }) } } + +func TestCatalogLinks(t *testing.T) { + tests := []struct { + name string + statuses []*PackageStatus + want string + }{ + {name: "no links", statuses: []*PackageStatus{{PackageName: "axios"}}}, + { + name: "one line per link, names aligned", + statuses: []*PackageStatus{ + {PackageName: "axios", CatalogURL: "https://a"}, + {PackageName: "axios", CatalogURL: "https://a"}, + {PackageName: "left-pad"}, + {PackageName: "urllib3", CatalogURL: "https://u"}, + }, + want: "\nFor more details, visit:\n axios https://a\n urllib3 https://u", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, catalogLinks(tt.statuses)) + }) + } +} + +func TestConvertToPackageStatusTableLinksPackageName(t *testing.T) { + statuses := []*PackageStatus{ + {PackageName: "axios", CatalogURL: "https://a"}, + {PackageName: "left-pad"}, + } + tests := []struct { + name string + withLinks bool + want []string + }{ + {name: "terminal", withLinks: true, want: []string{"\x1b]8;;https://a\x1b\\axios\x1b]8;;\x1b\\ ", "left-pad"}}, + {name: "not a terminal", withLinks: false, want: []string{"axios ", "left-pad"}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var got []string + for _, row := range convertToPackageStatusTable(statuses, tt.withLinks) { + got = append(got, row.PackageName) + } + assert.Equal(t, tt.want, got) + }) + } +} diff --git a/commands/curation/npmlogparser.go b/commands/curation/npmlogparser.go index 98a0c61b9..b5782ff38 100644 --- a/commands/curation/npmlogparser.go +++ b/commands/curation/npmlogparser.go @@ -2,6 +2,7 @@ package curation import ( "bufio" + "cmp" "encoding/json" "fmt" "net/url" @@ -50,15 +51,17 @@ const ( npmEntryETARGET ) -// npmBlockedInfo carries the policy/condition parsed from a whole-package-block notice line. +// npmBlockedInfo carries the policies and Catalog link parsed from a whole-package-block notice line. type npmBlockedInfo struct { - Policy string - Condition string + Policies []Policy + CatalogURL string } var ( // Matches: 42 notice All versions blocked - {policy:X,condition:Y} npmNoticeBlockedRegex = regexp.MustCompile(`^\d+\s+notice\s+All versions blocked - \{policy:([^,]+),condition:([^}]+)\}`) + // Matches: 42 notice All versions of 'X' (repo) are blocked from download by JFrog Curation. Blocked by ... + npmNoticeAllVersionsOfRegex = regexp.MustCompile(`^\d+\s+notice\s+` + allVersionsOfPattern) // Matches: 43 http fetch GET 403 https://.../api/npm// ... — excludes tarball fetches (path has /-/). npmFetch403Regex = regexp.MustCompile(`^\d+\s+http fetch GET 403\s+\S*/api/npm/[^/\s]+/((?:@[^/\s]+/)?[^/\s]+)\s`) // Matches: 110 silly placeDep ROOT accepts@2.0.0 OK for: express@5.2.1 want: ^2.0.0 @@ -96,7 +99,35 @@ func parseNpmDebugLog(logsDir string, afterKey int64) (entries []npmLogEntry, bl // npmUnknownBlockedInfo replaces a guessed policy/condition when the notice→403 FIFO pairing // is ambiguous — a wrong guess is worse than an honest "unknown". -var npmUnknownBlockedInfo = npmBlockedInfo{Policy: "unknown", Condition: "unknown"} +var npmUnknownBlockedInfo = npmBlockedInfo{Policies: []Policy{{Policy: "unknown", Condition: "unknown"}}} + +// parseNpmBlockedNotice returns the policies of a whole-package-block notice line, in either message format. +func parseNpmBlockedNotice(line string) (npmBlockedInfo, bool) { + if m := npmNoticeBlockedRegex.FindStringSubmatch(line); m != nil { + return npmBlockedInfo{Policies: []Policy{{Policy: strings.TrimSpace(m[1]), Condition: strings.TrimSpace(m[2])}}}, true + } + if m := npmNoticeAllVersionsOfRegex.FindStringSubmatch(line); m != nil { + return npmBlockedInfo{Policies: allVersionsOfPolicies(m), CatalogURL: m[4]}, true + } + return npmBlockedInfo{}, false +} + +// allVersionsOfPolicies returns the policies of a match of allVersionsOfPattern. The Note line, or +// allVersionsBlockedText without one, becomes the Explanation, and the Action line the Recommendation, +// of every policy. +func allVersionsOfPolicies(m []string) []Policy { + explanation := cmp.Or(m[2], allVersionsBlockedText) + var policies []Policy + for _, item := range allVersionsOfPolicyNumberRegex.Split(m[1], -1) { + if p := allVersionsOfPolicyItemRegex.FindStringSubmatch(item); p != nil { + policies = append(policies, Policy{Policy: p[1], Condition: p[2], Explanation: explanation, Recommendation: m[3]}) + } + } + if len(policies) == 0 { + return []Policy{{Explanation: explanation, Recommendation: m[3]}} + } + return policies +} // pendingNotice is a queued "notice" awaiting its matching 403. ambiguous is set once it has // ever overlapped with another unresolved notice, since FIFO order can no longer be trusted @@ -123,8 +154,8 @@ func scanNpmDebugLogChunk(logFile string, entries []npmLogEntry, blockedPackages for scanner.Scan() { line := scanner.Text() - if m := npmNoticeBlockedRegex.FindStringSubmatch(line); m != nil { - next := pendingNotice{info: npmBlockedInfo{Policy: strings.TrimSpace(m[1]), Condition: strings.TrimSpace(m[2])}} + if info, ok := parseNpmBlockedNotice(line); ok { + next := pendingNotice{info: info} if len(pendingNotices) > 0 { // A prior notice is still unresolved — both it and this one become ambiguous, // since same-relative-order with their eventual 403s is no longer provable. diff --git a/commands/curation/npmlogparser_test.go b/commands/curation/npmlogparser_test.go index fdeb70018..45d2bb7d2 100644 --- a/commands/curation/npmlogparser_test.go +++ b/commands/curation/npmlogparser_test.go @@ -21,8 +21,8 @@ func TestParseNpmDebugLog(t *testing.T) { // Whole-package block: notice immediately followed by the matching 403 fetch line. require.Contains(t, blockedPackages, "depd") - assert.Equal(t, "blocks open ssf", blockedPackages["depd"].Policy) - assert.Equal(t, "open ssf", blockedPackages["depd"].Condition) + assert.Equal(t, "blocks open ssf", blockedPackages["depd"].Policies[0].Policy) + assert.Equal(t, "open ssf", blockedPackages["depd"].Policies[0].Condition) byName := map[string]npmLogEntry{} for _, e := range entries { @@ -162,8 +162,8 @@ func TestParseNpmDebugLog_OverlappingPendingNoticesDegradeToUnknownPolicy(t *tes require.NoError(t, err) require.Contains(t, blockedPackages, "pkg-a", "still reported as blocked — just with unknown policy, not dropped entirely") require.Contains(t, blockedPackages, "pkg-b") - assert.Equal(t, "unknown", blockedPackages["pkg-a"].Policy) - assert.Equal(t, "unknown", blockedPackages["pkg-b"].Policy) + assert.Equal(t, "unknown", blockedPackages["pkg-a"].Policies[0].Policy) + assert.Equal(t, "unknown", blockedPackages["pkg-b"].Policies[0].Policy) } // A single notice resolved before the next one ever queues is unambiguous — FIFO order is @@ -183,8 +183,8 @@ func TestParseNpmDebugLog_SequentialNonOverlappingNoticesKeepRealPolicy(t *testi require.NoError(t, err) require.Contains(t, blockedPackages, "pkg-a") require.Contains(t, blockedPackages, "pkg-b") - assert.Equal(t, "blocks-cve", blockedPackages["pkg-a"].Policy) - assert.Equal(t, "blocks-license", blockedPackages["pkg-b"].Policy) + assert.Equal(t, "blocks-cve", blockedPackages["pkg-a"].Policies[0].Policy) + assert.Equal(t, "blocks-license", blockedPackages["pkg-b"].Policies[0].Policy) } // npm splits one run's debug log into multiple numbered chunk files past 50,000 log lines, @@ -221,7 +221,7 @@ func TestParseNpmDebugLog_MultipleChunksOfSameRunAreAllRead(t *testing.T) { require.Contains(t, blockedPackages, "depd", "the notice from chunk 0 must still pair with its matching 403 in chunk 1") - assert.Equal(t, "blocks open ssf", blockedPackages["depd"].Policy) + assert.Equal(t, "blocks open ssf", blockedPackages["depd"].Policies[0].Policy) } func TestParseNpmDebugLog_NoLogsDir(t *testing.T) { @@ -232,6 +232,63 @@ func TestParseNpmDebugLog_NoLogsDir(t *testing.T) { assert.Empty(t, logFilePaths) } +func TestParseNpmBlockedNotice(t *testing.T) { + const header = "42 notice All versions of '@hono/node-server' (npm-remote) are blocked from download by JFrog Curation." + const waiverAction = "Please use a different package or request a waiver to use this one." + const withNote = "Some versions are pending JFrog Catalog analysis." + tests := []struct { + name string + line string + want npmBlockedInfo + wantOk bool + }{ + { + name: "every listed policy, conditions with parentheses", + line: header + " Blocked by one or more of these policies: 1. BlockHighCVEs (CVE with CVSS score between 7.0 and 8.9 (fix version available)) " + + "2. Block Immature (package pending JFrog Catalog analysis) Note: Some versions are pending JFrog Catalog analysis. " + + "Action: " + waiverAction + " Details: https://example.jfrog.io/ui/catalog", + want: npmBlockedInfo{CatalogURL: "https://example.jfrog.io/ui/catalog", Policies: []Policy{ + {Policy: "BlockHighCVEs", Condition: "CVE with CVSS score between 7.0 and 8.9 (fix version available)", Explanation: withNote, Recommendation: waiverAction}, + {Policy: "Block Immature", Condition: "package pending JFrog Catalog analysis", Explanation: withNote, Recommendation: waiverAction}, + }}, + wantOk: true, + }, + { + name: "no policy list", + line: header + " Action: " + waiverAction, + want: npmBlockedInfo{Policies: []Policy{{Explanation: allVersionsBlockedText, Recommendation: waiverAction}}}, + wantOk: true, + }, + { + name: "old format", + line: "42 notice All versions blocked - {policy:blocks open ssf,condition:open ssf}", + want: npmBlockedInfo{Policies: []Policy{{Policy: "blocks open ssf", Condition: "open ssf"}}}, + wantOk: true, + }, + { + name: "unrelated notice", + line: "42 notice New major version of npm available!", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, ok := parseNpmBlockedNotice(tt.line) + assert.Equal(t, tt.wantOk, ok) + assert.Equal(t, tt.want, got) + }) + } +} + +func TestWholePackageBlockedStatusKeepsEveryPolicy(t *testing.T) { + info := npmBlockedInfo{CatalogURL: "u", Policies: []Policy{{Policy: "p1", Condition: "c1", Explanation: "e", Recommendation: "a"}, {Policy: "p2", Condition: "c2", Recommendation: "a"}}} + got := wholePackageBlockedStatus(npmLogEntry{Name: "axios"}, info, techutils.Npm) + assert.Equal(t, []Policy{ + {Policy: "p1", Condition: "c1", Explanation: "e", Recommendation: "a"}, + {Policy: "p2", Condition: "c2", Explanation: allVersionsBlockedText, Recommendation: "a"}, + }, got.Policy) + assert.Equal(t, "u", got.CatalogURL) +} + // Git host shorthand (github:/gitlab:/bitbucket:/gist:) must not regress — real evidence // (github:jonschlinkert/is-thirteen) depends on it. func TestClassifyNpmSpecifier(t *testing.T) { @@ -276,7 +333,7 @@ func TestClassifyNpmSpecifier(t *testing.T) { } func TestClassifyBlankVersionEntry(t *testing.T) { - blockedPackages := map[string]npmBlockedInfo{"depd": {Policy: "blocks open ssf", Condition: "open ssf"}} + blockedPackages := map[string]npmBlockedInfo{"depd": {Policies: []Policy{{Policy: "blocks open ssf", Condition: "open ssf"}}}} assert.Equal(t, npmEntryResolved, classifyBlankVersionEntry( npmLogEntry{Name: "accepts", Version: "2.0.0"}, blockedPackages)) @@ -369,7 +426,7 @@ func TestResolveNpmAliasEntriesLeavesMalformedAliasUntouched(t *testing.T) { // of npmEntryNonRegistrySpecifier — the exact misclassification reported live against a // "blocks open ssf" policy (RTECO-1882 / XRAY-157605). func TestClassifyBlankVersionEntryAfterAliasResolution(t *testing.T) { - blockedPackages := map[string]npmBlockedInfo{"strip-ansi": {Policy: "blocks open ssf", Condition: "open ssf"}} + blockedPackages := map[string]npmBlockedInfo{"strip-ansi": {Policies: []Policy{{Policy: "blocks open ssf", Condition: "open ssf"}}}} entries := resolveNpmAliasEntries([]npmLogEntry{ {Name: "strip-ansi-cjs", Version: "", ParentName: "myproj", ParentVersion: "1.0.0", Specifier: "npm:strip-ansi@6.0.1"}, }) From 334623e61274876d1e7a9dd1d95f5da19fee9aae Mon Sep 17 00:00:00 2001 From: Vageesha B R Date: Tue, 17 Nov 2026 14:56:06 +0530 Subject: [PATCH 2/5] XRAY-169343 - Review comments --- commands/curation/curationaudit.go | 15 ++++++++++++--- commands/curation/curationaudit_test.go | 15 +++++++++++---- commands/curation/npmlogparser_test.go | 6 ++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/commands/curation/curationaudit.go b/commands/curation/curationaudit.go index 9b6d05d46..347c5dc38 100644 --- a/commands/curation/curationaudit.go +++ b/commands/curation/curationaudit.go @@ -94,8 +94,9 @@ const ( // allVersionsOfPattern matches Xray's whole-package-block message with its lines joined by spaces: // "All versions of 'X' (repo) are blocked from download by JFrog Curation. Blocked by one or more of - // these policies: 1. P (C) 2. ... Note: ... Action: ... Details: ...". - allVersionsOfPattern = `All versions of '[^']+' \([^)]*\) are blocked from download by JFrog Curation\.(?: Blocked by one or more of these policies: (.*?))?(?: Note: ([^.]*\.))?(?: Action: (.*?))?(?: Details: (\S+))?$` + // these policies: 1. P (C) 2. ... Note: ... Action: ... Details: ...". Any other text after the + // first sentence matches with empty groups. + allVersionsOfPattern = `All versions of '[^']+' \([^)]*\) are blocked from download by JFrog Curation\.(?:(?: Blocked by one or more of these policies: (.*?))?(?: Note: ([^.]*\.))?(?: Action: (.*?))?(?: Details: (\S+))?$|.*)` errorTemplateHeadRequest = "failed sending HEAD request to %s for package '%s:%s'. Status-code: %v. Cause: %v" @@ -3062,6 +3063,9 @@ func (nc *treeAnalyzer) fetchCvsBlockedStatus(pins []python.PinnedRequirement) [ if wholePackageBlocked && wholePackageFallback != nil && len(wholePackageFallback.Policy) > 0 { normalizeMatchingWholePackagePolicies(pkStatus, wholePackageFallback.Policy) } + if wholePackageBlocked && wholePackageFallback != nil && wholePackageFallback.CatalogURL != "" { + pkStatus.CatalogURL = wholePackageFallback.CatalogURL + } statuses = append(statuses, pkStatus) } @@ -3187,12 +3191,17 @@ func (nc *treeAnalyzer) getBlockedPackageDetails(packageUrl string, name string, } if m := allVersionsOfMsgRegex.FindStringSubmatch(strings.ReplaceAll(respError.Errors[0].Message, "\n", " ")); m != nil { policies := allVersionsOfPolicies(m) + blockingReason := BlockingReasonPolicy + if m[1] == "" && m[3] == "" { + log.Debug(fmt.Sprintf("curation: could not parse the policies of the all-versions block message for %s: %s", name, respError.Errors[0].Message)) + policies, blockingReason = nil, BlockingReasonUnknown + } return &PackageStatus{ PackageName: name, PackageVersion: version, BlockedPackageUrl: packageUrl, Action: blocked, - BlockingReason: BlockingReasonPolicy, + BlockingReason: blockingReason, Policy: policies, PkgType: string(nc.tech), CatalogURL: m[4], diff --git a/commands/curation/curationaudit_test.go b/commands/curation/curationaudit_test.go index 36c7ea3d6..9074040f9 100644 --- a/commands/curation/curationaudit_test.go +++ b/commands/curation/curationaudit_test.go @@ -2650,6 +2650,11 @@ func TestGetBlockedPackageDetails_PolicyGroupsPreemptPendingSubstrings(t *testin wantWaiver: true, wantCatalog: "http://localhost:8083/ui/catalog/packages/details/npm/@milkio%2Fstargate-worker?ecosystem=generic&showVersions=true", }, + { + name: "all-versions message with a reworded tail", + message: "All versions of '@milkio/stargate-worker' (npm-remote) are blocked from download by JFrog Curation.\nBlocked by these policies:\n1. P (C)", + wantReason: BlockingReasonUnknown, + }, } for _, tt := range tests { @@ -6134,14 +6139,15 @@ func TestFetchCvsBlockedStatusPinnedWholePackageBlockedSamePolicyAsAggregate(t * whlRelativePath = "packages/ca/25/urllib3-2.0.0-py3-none-any.whl" ) // Step 0's aggregate probe: confirmed whole-package block under policy openssf-jfca-test/openssf. - wholePackageBlockResponse := fmt.Sprintf( - `{"errors":[{"status":403,"message":"All versions blocked - {policy:%s,condition:%s}"}]}`, - policyName, condName, + wholePackageBlockMsg := fmt.Sprintf( + "All versions of '%s' (%s) are blocked from download by JFrog Curation.\nBlocked by one or more of these policies:\n1. %s (%s)\nDetails: https://x/pkg", + blockedPkg, repo, policyName, condName, ) + wholePackageBlockResponse := fmt.Sprintf(`{"errors":[{"status":403,"message":%q}]}`, wholePackageBlockMsg) // Steps 1-3's per-version probe: the SAME policy+condition, but with the raw, // inconsistently-worded backend message (as opposed to Step 0's generic phrasing). blockMsg := fmt.Sprintf( - "Package %s:%s download was blocked by JFrog Packages Curation service due to the following policies violated {%s, %s, %s, %s}.", + "Package %s:%s download was blocked by JFrog Packages Curation service due to the following policies violated {%s, %s, %s, %s}. For details and alternatives, visit: https://x/version", blockedPkg, blockedVer, policyName, condName, rawExpl, rawRec, ) versionBlockResponse := fmt.Sprintf(`{"errors":[{"status":403,"message":%q}]}`, blockMsg) @@ -6196,6 +6202,7 @@ func TestFetchCvsBlockedStatusPinnedWholePackageBlockedSamePolicyAsAggregate(t * "same policy as aggregate must be normalized to the generic text, not leak the raw inconsistent backend message") assert.Equal(t, "Remove this package from your project and replace with an alternate package", s.Policy[0].Recommendation, "direct pinned dependency, same policy as aggregate, must get the generic npm-parity recommendation") + assert.Equal(t, "https://x/pkg", s.CatalogURL) } // TestFetchCvsBlockedStatusPinnedWholePackageBlockedMultiPolicyPartialMatch verifies that diff --git a/commands/curation/npmlogparser_test.go b/commands/curation/npmlogparser_test.go index 45d2bb7d2..8b8f5afc8 100644 --- a/commands/curation/npmlogparser_test.go +++ b/commands/curation/npmlogparser_test.go @@ -259,6 +259,12 @@ func TestParseNpmBlockedNotice(t *testing.T) { want: npmBlockedInfo{Policies: []Policy{{Explanation: allVersionsBlockedText, Recommendation: waiverAction}}}, wantOk: true, }, + { + name: "reworded tail", + line: header + " Blocked by these policies: 1. P (C)", + want: npmBlockedInfo{Policies: []Policy{{Explanation: allVersionsBlockedText}}}, + wantOk: true, + }, { name: "old format", line: "42 notice All versions blocked - {policy:blocks open ssf,condition:open ssf}", From c607654a7cb3b594b694ad767c2cbd59a3183f1d Mon Sep 17 00:00:00 2001 From: Vageesha B R Date: Wed, 18 Nov 2026 08:33:53 +0530 Subject: [PATCH 3/5] XRAY-169343 - Show the all-versions-blocked rows once per package For a whole-package block the Explanation is "All versions blocked" and the Recommendation is Xray's Note line followed by its Action line. Both cells are printed once per package instead of once per policy. The Catalog links after the table are listed once per package name. In terminals that support hyperlinks the heading is bold and linked package names are blue and underlined. The all-versions message is matched case-insensitively. A PyPI requirement without a version whose versions are all blocked is reported as a blocked row instead of failing the audit. Co-Authored-By: Claude Opus 5.5 --- commands/curation/curationaudit.go | 73 +++++++++++-------- commands/curation/curationaudit_test.go | 42 +++++++++-- commands/curation/npmlogparser.go | 15 ++-- commands/curation/npmlogparser_test.go | 16 ++-- .../python/python_cvs_fallback.go | 22 ++++++ .../python/python_cvs_fallback_test.go | 10 +++ 6 files changed, 127 insertions(+), 51 deletions(-) diff --git a/commands/curation/curationaudit.go b/commands/curation/curationaudit.go index 347c5dc38..95dbc58aa 100644 --- a/commands/curation/curationaudit.go +++ b/commands/curation/curationaudit.go @@ -1,7 +1,6 @@ package curation import ( - "cmp" "encoding/json" "errors" "fmt" @@ -19,6 +18,7 @@ import ( "sync/atomic" "github.com/google/uuid" + "github.com/gookit/color" "github.com/jedib0t/go-pretty/v6/text" "github.com/jfrog/gofrog/datastructures" "github.com/jfrog/gofrog/parallel" @@ -96,7 +96,7 @@ const ( // "All versions of 'X' (repo) are blocked from download by JFrog Curation. Blocked by one or more of // these policies: 1. P (C) 2. ... Note: ... Action: ... Details: ...". Any other text after the // first sentence matches with empty groups. - allVersionsOfPattern = `All versions of '[^']+' \([^)]*\) are blocked from download by JFrog Curation\.(?:(?: Blocked by one or more of these policies: (.*?))?(?: Note: ([^.]*\.))?(?: Action: (.*?))?(?: Details: (\S+))?$|.*)` + allVersionsOfPattern = `(?i)All versions of '[^']+' \([^)]*\) are blocked from download by JFrog Curation\.(?:(?: Blocked by one or more of these policies: (.*?))?(?: Note: ([^.]*\.))?(?: Action: (.*?))?(?: Details: (\S+))?$|.*)` errorTemplateHeadRequest = "failed sending HEAD request to %s for package '%s:%s'. Status-code: %v. Cause: %v" @@ -291,8 +291,8 @@ type PackageStatusTable struct { PkgType string `col-name:"Package\nType" auto-merge:"true"` Policy string `col-name:"Violated\nPolicy\nName"` Condition string `col-name:"Violated Condition\nName"` - Explanation string `col-name:"Explanation"` - Recommendation string `col-name:"Recommendation"` + Explanation string `col-name:"Explanation" auto-merge:"true"` + Recommendation string `col-name:"Recommendation" auto-merge:"true"` } type treeAnalyzer struct { @@ -1582,26 +1582,38 @@ func (ca *CurationAuditCommand) requestWaiver(blockedPackages []*PackageStatus) return coreutils.PrintTable(pkgStatusTable, "Waiver request submitted!", "Requested 0 waivers", true) } -// catalogLinks lists the JFrog Catalog page of each blocked package that has one, once per page. -func catalogLinks(packagesStatus []*PackageStatus) string { +// catalogLinkStyle is the style of a package name that is a terminal hyperlink to its Catalog page. +var catalogLinkStyle = color.New(color.FgBlue, color.OpUnderscore) + +// catalogLinks lists one JFrog Catalog page per blocked package name, the first one found. With withLinks, +// the heading is bold and each package name is a styled terminal hyperlink to its page. +func catalogLinks(packagesStatus []*PackageStatus, withLinks bool) string { var names, urls []string seen := map[string]bool{} width := 0 for _, ps := range packagesStatus { - if ps.CatalogURL == "" || seen[ps.CatalogURL] { + if ps.CatalogURL == "" || seen[ps.PackageName] { continue } - seen[ps.CatalogURL] = true + seen[ps.PackageName] = true names, urls = append(names, ps.PackageName), append(urls, ps.CatalogURL) width = max(width, len(ps.PackageName)) } if len(urls) == 0 { return "" } + heading := "For more details, visit:" + if withLinks { + heading = color.OpBold.Render(heading) + } var sb strings.Builder - sb.WriteString("\nFor more details, visit:") + sb.WriteString("\n" + heading) for i := range urls { - fmt.Fprintf(&sb, "\n %-*s %s", width, names[i], urls[i]) + name := names[i] + if withLinks { + name = catalogLinkStyle.Render(text.Hyperlink(urls[i], name)) + } + fmt.Fprintf(&sb, "\n %s%s %s", name, strings.Repeat(" ", width-len(names[i])), urls[i]) } return sb.String() } @@ -1620,12 +1632,13 @@ func printResult(format outFormat.OutputFormat, projectPath string, packagesStat } } case outFormat.Table: - pkgStatusTable := convertToPackageStatusTable(packagesStatus, output.TerminalSupportsHyperlinks()) + withLinks := output.TerminalSupportsHyperlinks() + pkgStatusTable := convertToPackageStatusTable(packagesStatus, withLinks) err := coreutils.PrintTable(pkgStatusTable, "Curation", "Found 0 blocked packages", true) if err != nil { return err } - if links := catalogLinks(packagesStatus); links != "" { + if links := catalogLinks(packagesStatus, withLinks); links != "" { log.Output(links) } } @@ -1634,7 +1647,7 @@ func printResult(format outFormat.OutputFormat, projectPath string, packagesStat } // convertToPackageStatusTable builds the table rows. With withLinks, a package name with a Catalog -// link becomes a terminal hyperlink to it. +// link becomes a styled terminal hyperlink to it. func convertToPackageStatusTable(packagesStatus []*PackageStatus, withLinks bool) []PackageStatusTable { var pkgStatusTable []PackageStatusTable for index, pkgStatus := range packagesStatus { @@ -1645,8 +1658,8 @@ func convertToPackageStatusTable(packagesStatus []*PackageStatus, withLinks bool uniqLineSep = " " } packageName := pkgStatus.PackageName - if withLinks { - packageName = text.Hyperlink(pkgStatus.CatalogURL, packageName) + if withLinks && pkgStatus.CatalogURL != "" { + packageName = catalogLinkStyle.Render(text.Hyperlink(pkgStatus.CatalogURL, packageName)) } pkgTable := PackageStatusTable{ ID: fmt.Sprintf("%d%s", index+1, uniqLineSep), @@ -1662,8 +1675,8 @@ func convertToPackageStatusTable(packagesStatus []*PackageStatus, withLinks bool } for _, policyCond := range pkgStatus.Policy { pkgTable.Policy = policyCond.Policy - pkgTable.Explanation = policyCond.Explanation - pkgTable.Recommendation = policyCond.Recommendation + pkgTable.Explanation = policyCond.Explanation + uniqLineSep + pkgTable.Recommendation = policyCond.Recommendation + uniqLineSep pkgTable.Condition = policyCond.Condition pkgStatusTable = append(pkgStatusTable, pkgTable) } @@ -2701,28 +2714,23 @@ func (ca *CurationAuditCommand) runNpmLogFallback(logsDir string, tech techutils const allVersionsBlockedText = "All versions blocked" // wholePackageBlockedStatus synthesizes a *PackageStatus straight from the log's notice+403 -// evidence — no HEAD-check needed. Recommendation is finished later by +// evidence — no HEAD-check needed. Explanation and Recommendation are finished later by // applyTransitiveAwareRecommendation, once the graph walk knows the parent. func wholePackageBlockedStatus(entry npmLogEntry, info npmBlockedInfo, tech techutils.Technology) *PackageStatus { - policies := make([]Policy, len(info.Policies)) - for i, p := range info.Policies { - policies[i] = Policy{Policy: p.Policy, Condition: p.Condition, Explanation: cmp.Or(p.Explanation, allVersionsBlockedText), Recommendation: p.Recommendation} - } return &PackageStatus{ PackageName: entry.Name, PackageVersion: allVersionsBlockedText, Action: blocked, BlockingReason: BlockingReasonPolicy, PkgType: string(tech), - Policy: policies, + Policy: slices.Clone(info.Policies), CatalogURL: info.CatalogURL, } } -// applyTransitiveAwareRecommendation normalizes every ps.Policy entry to generic, -// direct/transitive-aware text for a whole-package block (matches npm). Only safe when -// all entries are already whole-package (e.g. Step 0). For a per-version probe result, -// use normalizeMatchingWholePackagePolicies instead. +// applyTransitiveAwareRecommendation applies normalizeWholePackagePolicy to every ps.Policy entry of a +// whole-package block. Only safe when all entries are already whole-package (e.g. Step 0). For a +// per-version probe result, use normalizeMatchingWholePackagePolicies instead. func applyTransitiveAwareRecommendation(ps *PackageStatus, isDirectDependency bool) { policies := make([]Policy, len(ps.Policy)) copy(policies, ps.Policy) @@ -2756,15 +2764,16 @@ func matchingPolicy(p Policy, candidates []Policy) (Policy, bool) { return Policy{}, false } -// normalizeWholePackagePolicy rewrites a single Policy entry's Explanation/Recommendation -// to the generic, direct/transitive-aware text for a whole-package block. An Explanation already on -// p is kept. A Recommendation already on p is the Action line of Xray's message and is kept; for a -// transitive dependency it follows the sentence naming the parent. +// normalizeWholePackagePolicy sets the Explanation of a whole-package Policy entry to allVersionsBlockedText. +// A Recommendation already on p holds the Note and Action lines of Xray's message and is kept; for a +// transitive dependency it follows a sentence naming the parent. Without one, a generic +// direct/transitive-aware text is used. func normalizeWholePackagePolicy(p *Policy, ps *PackageStatus, isDirectDependency bool) { - p.Explanation = cmp.Or(p.Explanation, allVersionsBlockedText) + p.Explanation = allVersionsBlockedText action := p.Recommendation switch { case isDirectDependency && action != "": + // Xray's Note and Action lines are used as is. case isDirectDependency: p.Recommendation = "Remove this package from your project and replace with an alternate package" case action != "": diff --git a/commands/curation/curationaudit_test.go b/commands/curation/curationaudit_test.go index 9074040f9..9846d4a9e 100644 --- a/commands/curation/curationaudit_test.go +++ b/commands/curation/curationaudit_test.go @@ -27,6 +27,7 @@ import ( "github.com/jfrog/jfrog-cli-security/utils/formats" "github.com/google/uuid" + "github.com/jedib0t/go-pretty/v6/text" biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/gofrog/datastructures" rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" @@ -3740,8 +3741,8 @@ func TestRunNpmLogFallback_AllVersionsOfNotice(t *testing.T) { assert.Equal(t, allVersionsBlockedText, got.PackageVersion) assert.Equal(t, "https://example.jfrog.io/ui/catalog/blockedpkg", got.CatalogURL) assert.Equal(t, []Policy{ - {Policy: "Block Immature Packages", Condition: "immature-7", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: action}, - {Policy: "Block Malicious Packages", Condition: "Malicious package", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: action}, + {Policy: "Block Immature Packages", Condition: "immature-7", Explanation: allVersionsBlockedText, Recommendation: "Some versions are pending JFrog Catalog analysis. " + action}, + {Policy: "Block Malicious Packages", Condition: "Malicious package", Explanation: allVersionsBlockedText, Recommendation: "Some versions are pending JFrog Catalog analysis. " + action}, }, got.Policy) } } @@ -6015,9 +6016,9 @@ func TestFetchCvsBlockedStatusRangedWholePackageBlockedAllVersionsOfMessage(t *t parent string wantRecommendation string }{ - {name: "direct", parent: "urllib3", wantRecommendation: action}, + {name: "direct", parent: "urllib3", wantRecommendation: "Some versions are pending JFrog Catalog analysis. " + action}, {name: "transitive", parent: "requests", - wantRecommendation: "urllib3 is a transitive dependency of requests and cannot be removed directly. " + action}, + wantRecommendation: "urllib3 is a transitive dependency of requests and cannot be removed directly. Some versions are pending JFrog Catalog analysis. " + action}, } for _, tech := range []techutils.Technology{techutils.Pip, techutils.Poetry, techutils.Pipenv, techutils.Uv} { for _, tt := range tests { @@ -6037,8 +6038,8 @@ func TestFetchCvsBlockedStatusRangedWholePackageBlockedAllVersionsOfMessage(t *t assert.Equal(t, allVersionsBlockedText, statuses[0].PackageVersion) assert.Equal(t, BlockingReasonPolicy, statuses[0].BlockingReason) assert.Equal(t, []Policy{ - {Policy: "p1", Condition: "c1 (fix version available)", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: tt.wantRecommendation}, - {Policy: "p2", Condition: "package pending JFrog Catalog analysis", Explanation: "Some versions are pending JFrog Catalog analysis.", Recommendation: tt.wantRecommendation}, + {Policy: "p1", Condition: "c1 (fix version available)", Explanation: allVersionsBlockedText, Recommendation: tt.wantRecommendation}, + {Policy: "p2", Condition: "package pending JFrog Catalog analysis", Explanation: allVersionsBlockedText, Recommendation: tt.wantRecommendation}, }, statuses[0].Policy) assert.Equal(t, "https://example.jfrog.io/ui/catalog", statuses[0].CatalogURL) }) @@ -7833,6 +7834,15 @@ func TestCatalogLinks(t *testing.T) { want string }{ {name: "no links", statuses: []*PackageStatus{{PackageName: "axios"}}}, + { + name: "versions of one package", + statuses: []*PackageStatus{ + {PackageName: "vm2", PackageVersion: "3.9.18", CatalogURL: "https://v18"}, + {PackageName: "vm2", PackageVersion: "3.9.19", CatalogURL: "https://v19"}, + {PackageName: "axios", PackageVersion: allVersionsBlockedText, CatalogURL: "https://a"}, + }, + want: "\nFor more details, visit:\n vm2 https://v18\n axios https://a", + }, { name: "one line per link, names aligned", statuses: []*PackageStatus{ @@ -7846,11 +7856,29 @@ func TestCatalogLinks(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.Equal(t, tt.want, catalogLinks(tt.statuses)) + assert.Equal(t, tt.want, catalogLinks(tt.statuses, false)) }) } } +func TestCatalogLinksWithLinks(t *testing.T) { + got := catalogLinks([]*PackageStatus{{PackageName: "axios", CatalogURL: "https://a"}}, true) + if want := text.Hyperlink("https://a", "axios"); !strings.Contains(got, want) { + t.Errorf("catalogLinks(axios, true) = %q, want it to contain %q", got, want) + } +} + +func TestPackageStatusTableMergesSharedText(t *testing.T) { + policies := []Policy{{Policy: "p1", Explanation: "expl", Recommendation: "rec"}, {Policy: "p2", Explanation: "expl", Recommendation: "rec"}} + statuses := []*PackageStatus{{PackageName: "a", Policy: policies}, {PackageName: "b", Policy: policies}} + tw, err := coreutils.PrepareTable(convertToPackageStatusTable(statuses, false), "", false) + require.NoError(t, err) + got := tw.Render() + if n := strings.Count(got, "rec"); n != 2 { + t.Errorf("PrepareTable(two packages with two policies each) shows the recommendation %d times, want 2:\n%s", n, got) + } +} + func TestConvertToPackageStatusTableLinksPackageName(t *testing.T) { statuses := []*PackageStatus{ {PackageName: "axios", CatalogURL: "https://a"}, diff --git a/commands/curation/npmlogparser.go b/commands/curation/npmlogparser.go index b5782ff38..6fadc3793 100644 --- a/commands/curation/npmlogparser.go +++ b/commands/curation/npmlogparser.go @@ -2,7 +2,6 @@ package curation import ( "bufio" - "cmp" "encoding/json" "fmt" "net/url" @@ -112,19 +111,21 @@ func parseNpmBlockedNotice(line string) (npmBlockedInfo, bool) { return npmBlockedInfo{}, false } -// allVersionsOfPolicies returns the policies of a match of allVersionsOfPattern. The Note line, or -// allVersionsBlockedText without one, becomes the Explanation, and the Action line the Recommendation, -// of every policy. +// allVersionsOfPolicies returns the policies of a match of allVersionsOfPattern. Every policy gets the +// Action line, preceded by the Note line, as its Recommendation. func allVersionsOfPolicies(m []string) []Policy { - explanation := cmp.Or(m[2], allVersionsBlockedText) + recommendation := m[3] + if recommendation != "" && m[2] != "" { + recommendation = m[2] + " " + recommendation + } var policies []Policy for _, item := range allVersionsOfPolicyNumberRegex.Split(m[1], -1) { if p := allVersionsOfPolicyItemRegex.FindStringSubmatch(item); p != nil { - policies = append(policies, Policy{Policy: p[1], Condition: p[2], Explanation: explanation, Recommendation: m[3]}) + policies = append(policies, Policy{Policy: p[1], Condition: p[2], Recommendation: recommendation}) } } if len(policies) == 0 { - return []Policy{{Explanation: explanation, Recommendation: m[3]}} + return []Policy{{Recommendation: recommendation}} } return policies } diff --git a/commands/curation/npmlogparser_test.go b/commands/curation/npmlogparser_test.go index 8b8f5afc8..ea26a628f 100644 --- a/commands/curation/npmlogparser_test.go +++ b/commands/curation/npmlogparser_test.go @@ -248,21 +248,27 @@ func TestParseNpmBlockedNotice(t *testing.T) { "2. Block Immature (package pending JFrog Catalog analysis) Note: Some versions are pending JFrog Catalog analysis. " + "Action: " + waiverAction + " Details: https://example.jfrog.io/ui/catalog", want: npmBlockedInfo{CatalogURL: "https://example.jfrog.io/ui/catalog", Policies: []Policy{ - {Policy: "BlockHighCVEs", Condition: "CVE with CVSS score between 7.0 and 8.9 (fix version available)", Explanation: withNote, Recommendation: waiverAction}, - {Policy: "Block Immature", Condition: "package pending JFrog Catalog analysis", Explanation: withNote, Recommendation: waiverAction}, + {Policy: "BlockHighCVEs", Condition: "CVE with CVSS score between 7.0 and 8.9 (fix version available)", Recommendation: withNote + " " + waiverAction}, + {Policy: "Block Immature", Condition: "package pending JFrog Catalog analysis", Recommendation: withNote + " " + waiverAction}, }}, wantOk: true, }, { name: "no policy list", line: header + " Action: " + waiverAction, - want: npmBlockedInfo{Policies: []Policy{{Explanation: allVersionsBlockedText, Recommendation: waiverAction}}}, + want: npmBlockedInfo{Policies: []Policy{{Recommendation: waiverAction}}}, + wantOk: true, + }, + { + name: "different capitalization", + line: "42 notice ALL VERSIONS OF 'x' (r) ARE BLOCKED FROM DOWNLOAD BY JFROG CURATION. Action: " + waiverAction, + want: npmBlockedInfo{Policies: []Policy{{Recommendation: waiverAction}}}, wantOk: true, }, { name: "reworded tail", line: header + " Blocked by these policies: 1. P (C)", - want: npmBlockedInfo{Policies: []Policy{{Explanation: allVersionsBlockedText}}}, + want: npmBlockedInfo{Policies: []Policy{{}}}, wantOk: true, }, { @@ -290,7 +296,7 @@ func TestWholePackageBlockedStatusKeepsEveryPolicy(t *testing.T) { got := wholePackageBlockedStatus(npmLogEntry{Name: "axios"}, info, techutils.Npm) assert.Equal(t, []Policy{ {Policy: "p1", Condition: "c1", Explanation: "e", Recommendation: "a"}, - {Policy: "p2", Condition: "c2", Explanation: allVersionsBlockedText, Recommendation: "a"}, + {Policy: "p2", Condition: "c2", Recommendation: "a"}, }, got.Policy) assert.Equal(t, "u", got.CatalogURL) } diff --git a/sca/bom/buildinfo/technologies/python/python_cvs_fallback.go b/sca/bom/buildinfo/technologies/python/python_cvs_fallback.go index eb50e827f..2adabd7e4 100644 --- a/sca/bom/buildinfo/technologies/python/python_cvs_fallback.go +++ b/sca/bom/buildinfo/technologies/python/python_cvs_fallback.go @@ -1,6 +1,7 @@ package python import ( + "cmp" "errors" "fmt" "regexp" @@ -50,6 +51,14 @@ var pipFailedRangeReqRegex = regexp.MustCompile( `([A-Za-z0-9][A-Za-z0-9._-]*)(?:\[[^\]]*\])?((?:(?:~=|!=|>=|<=|>|<)[^\s,(]+(?:,(?:~=|!=|>=|<=|>|<)[^\s,(]+)*))` + `(?:\s+\(from\s+([A-Za-z0-9][A-Za-z0-9._-]*)(?:==([^\s)]+))?\))?`) +// pipFailedBareReqRegex matches a failed requirement with no version specifier in pip's error output. +// Groups: (1) name, (2) the first "(from ...)" clause: "versions: ..." for a direct requirement, else the parent. +var pipFailedBareReqRegex = regexp.MustCompile( + `satisfies the requirement\s+([A-Za-z0-9][A-Za-z0-9._-]*)(?:\[[^\]]*\])?\s+\(from\s+([^)]*)\)`) + +// pipFromParentRegex matches the parent in a "(from ...)" clause. Groups: (1) name, (2) version (optional). +var pipFromParentRegex = regexp.MustCompile(`^([A-Za-z0-9][A-Za-z0-9._-]*)(?:==(\S+))?$`) + // pipCollectingRegex matches packages pip collected before failing; used to recover parent version omitted in "(from )". // Groups: (1) name, (2) version. var pipCollectingRegex = regexp.MustCompile( @@ -185,6 +194,19 @@ func parseCvsFailedPackages(pipOutput string) []PinnedRequirement { failed = append(failed, pr) } + for _, m := range pipFailedBareReqRegex.FindAllStringSubmatch(pipOutput, -1) { + name := normalizePyPIName(m[1]) + if seen[name] { + continue + } + seen[name] = true + pr := PinnedRequirement{Name: name, ParentName: name, ConfirmedDirect: true} + if p := pipFromParentRegex.FindStringSubmatch(m[2]); p != nil { + pr.ParentName, pr.ParentVersion, pr.ConfirmedDirect = normalizePyPIName(p[1]), cmp.Or(p[2], collected[normalizePyPIName(p[1])]), false + } + failed = append(failed, pr) + } + // ResolutionImpossible: deep transitive deps stripped by CVS never appear in a // "No matching distribution found" line, so add them as name-only entries. if m := pipResolutionImpossibleRegex.FindStringSubmatch(pipOutput); len(m) > 1 { diff --git a/sca/bom/buildinfo/technologies/python/python_cvs_fallback_test.go b/sca/bom/buildinfo/technologies/python/python_cvs_fallback_test.go index e2b34761f..ca6717147 100644 --- a/sca/bom/buildinfo/technologies/python/python_cvs_fallback_test.go +++ b/sca/bom/buildinfo/technologies/python/python_cvs_fallback_test.go @@ -35,6 +35,16 @@ func TestParseCvsFailedPackages(t *testing.T) { {Name: "deepagents", Version: "0.5.5", ParentName: "deepagents", ParentVersion: "0.5.5"}, }, }, + { + name: "no version specifier", + output: "ERROR: Could not find a version that satisfies the requirement sccp (from versions: none)\nERROR: No matching distribution found for sccp\n", + want: []PinnedRequirement{{Name: "sccp", ParentName: "sccp", ConfirmedDirect: true}}, + }, + { + name: "no version specifier, transitive", + output: "ERROR: Could not find a version that satisfies the requirement sccp (from parentpkg==1.0) (from versions: none)\nERROR: No matching distribution found for sccp\n", + want: []PinnedRequirement{{Name: "sccp", ParentName: "parentpkg", ParentVersion: "1.0"}}, + }, { name: "range spec without parent", output: "ERROR: No matching distribution found for langchain-core>=1.4.0,<2.0.0", From cdb3c36703400d0e6c02d3d8367715e82bb179d5 Mon Sep 17 00:00:00 2001 From: Vageesha B R Date: Wed, 18 Nov 2026 09:42:39 +0530 Subject: [PATCH 4/5] XRAY-169343 - Move the Catalog link to its own table column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A hyperlinked package name was cut inside its escape sequence when the table wrapped a name wider than its column. The package name is plain text again, and terminals that support hyperlinks get a "Blocked Package Link" column with an "Open ↗" link, as in download-status. The column is omitted when no row has a link. The "For more details, visit:" list is printed only when the terminal does not support hyperlinks. Co-Authored-By: Claude Opus 5.5 --- commands/curation/curationaudit.go | 31 ++++++++++--------------- commands/curation/curationaudit_test.go | 28 ++++++++++++---------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/commands/curation/curationaudit.go b/commands/curation/curationaudit.go index 95dbc58aa..ab0c9ebde 100644 --- a/commands/curation/curationaudit.go +++ b/commands/curation/curationaudit.go @@ -293,6 +293,7 @@ type PackageStatusTable struct { Condition string `col-name:"Violated Condition\nName"` Explanation string `col-name:"Explanation" auto-merge:"true"` Recommendation string `col-name:"Recommendation" auto-merge:"true"` + Link string `col-name:"Blocked\nPackage\nLink" auto-merge:"true" omitempty:"true"` } type treeAnalyzer struct { @@ -1585,9 +1586,8 @@ func (ca *CurationAuditCommand) requestWaiver(blockedPackages []*PackageStatus) // catalogLinkStyle is the style of a package name that is a terminal hyperlink to its Catalog page. var catalogLinkStyle = color.New(color.FgBlue, color.OpUnderscore) -// catalogLinks lists one JFrog Catalog page per blocked package name, the first one found. With withLinks, -// the heading is bold and each package name is a styled terminal hyperlink to its page. -func catalogLinks(packagesStatus []*PackageStatus, withLinks bool) string { +// catalogLinks lists one JFrog Catalog page per blocked package name, the first one found. +func catalogLinks(packagesStatus []*PackageStatus) string { var names, urls []string seen := map[string]bool{} width := 0 @@ -1602,18 +1602,10 @@ func catalogLinks(packagesStatus []*PackageStatus, withLinks bool) string { if len(urls) == 0 { return "" } - heading := "For more details, visit:" - if withLinks { - heading = color.OpBold.Render(heading) - } var sb strings.Builder - sb.WriteString("\n" + heading) + sb.WriteString("\nFor more details, visit:") for i := range urls { - name := names[i] - if withLinks { - name = catalogLinkStyle.Render(text.Hyperlink(urls[i], name)) - } - fmt.Fprintf(&sb, "\n %s%s %s", name, strings.Repeat(" ", width-len(names[i])), urls[i]) + fmt.Fprintf(&sb, "\n %-*s %s", width, names[i], urls[i]) } return sb.String() } @@ -1638,7 +1630,7 @@ func printResult(format outFormat.OutputFormat, projectPath string, packagesStat if err != nil { return err } - if links := catalogLinks(packagesStatus, withLinks); links != "" { + if links := catalogLinks(packagesStatus); !withLinks && links != "" { log.Output(links) } } @@ -1646,8 +1638,8 @@ func printResult(format outFormat.OutputFormat, projectPath string, packagesStat return nil } -// convertToPackageStatusTable builds the table rows. With withLinks, a package name with a Catalog -// link becomes a styled terminal hyperlink to it. +// convertToPackageStatusTable builds the table rows. With withLinks, a package with a Catalog link gets a +// styled "Open ↗" terminal hyperlink to it in the Link column; the column is omitted when no row has one. func convertToPackageStatusTable(packagesStatus []*PackageStatus, withLinks bool) []PackageStatusTable { var pkgStatusTable []PackageStatusTable for index, pkgStatus := range packagesStatus { @@ -1657,17 +1649,18 @@ func convertToPackageStatusTable(packagesStatus []*PackageStatus, withLinks bool if index%2 == 0 { uniqLineSep = " " } - packageName := pkgStatus.PackageName + var link string if withLinks && pkgStatus.CatalogURL != "" { - packageName = catalogLinkStyle.Render(text.Hyperlink(pkgStatus.CatalogURL, packageName)) + link = catalogLinkStyle.Render(text.Hyperlink(pkgStatus.CatalogURL, "Open ↗")) + uniqLineSep } pkgTable := PackageStatusTable{ ID: fmt.Sprintf("%d%s", index+1, uniqLineSep), ParentName: pkgStatus.ParentName + uniqLineSep, ParentVersion: pkgStatus.ParentVersion + uniqLineSep, - PackageName: packageName + uniqLineSep, + PackageName: pkgStatus.PackageName + uniqLineSep, PackageVersion: pkgStatus.PackageVersion + uniqLineSep, PkgType: pkgStatus.PkgType + uniqLineSep, + Link: link, } if len(pkgStatus.Policy) == 0 { pkgStatusTable = append(pkgStatusTable, pkgTable) diff --git a/commands/curation/curationaudit_test.go b/commands/curation/curationaudit_test.go index 9846d4a9e..146cbfd12 100644 --- a/commands/curation/curationaudit_test.go +++ b/commands/curation/curationaudit_test.go @@ -7856,18 +7856,11 @@ func TestCatalogLinks(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.Equal(t, tt.want, catalogLinks(tt.statuses, false)) + assert.Equal(t, tt.want, catalogLinks(tt.statuses)) }) } } -func TestCatalogLinksWithLinks(t *testing.T) { - got := catalogLinks([]*PackageStatus{{PackageName: "axios", CatalogURL: "https://a"}}, true) - if want := text.Hyperlink("https://a", "axios"); !strings.Contains(got, want) { - t.Errorf("catalogLinks(axios, true) = %q, want it to contain %q", got, want) - } -} - func TestPackageStatusTableMergesSharedText(t *testing.T) { policies := []Policy{{Policy: "p1", Explanation: "expl", Recommendation: "rec"}, {Policy: "p2", Explanation: "expl", Recommendation: "rec"}} statuses := []*PackageStatus{{PackageName: "a", Policy: policies}, {PackageName: "b", Policy: policies}} @@ -7879,7 +7872,7 @@ func TestPackageStatusTableMergesSharedText(t *testing.T) { } } -func TestConvertToPackageStatusTableLinksPackageName(t *testing.T) { +func TestConvertToPackageStatusTableLinkColumn(t *testing.T) { statuses := []*PackageStatus{ {PackageName: "axios", CatalogURL: "https://a"}, {PackageName: "left-pad"}, @@ -7889,16 +7882,27 @@ func TestConvertToPackageStatusTableLinksPackageName(t *testing.T) { withLinks bool want []string }{ - {name: "terminal", withLinks: true, want: []string{"\x1b]8;;https://a\x1b\\axios\x1b]8;;\x1b\\ ", "left-pad"}}, - {name: "not a terminal", withLinks: false, want: []string{"axios ", "left-pad"}}, + {name: "terminal", withLinks: true, want: []string{text.Hyperlink("https://a", "Open ↗") + " ", ""}}, + {name: "not a terminal", withLinks: false, want: []string{"", ""}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var got []string for _, row := range convertToPackageStatusTable(statuses, tt.withLinks) { - got = append(got, row.PackageName) + got = append(got, row.Link) + if row.PackageName != "axios " && row.PackageName != "left-pad" { + t.Errorf("PackageName = %q, want the plain name", row.PackageName) + } } assert.Equal(t, tt.want, got) }) } } + +func TestPackageStatusTableOmitsEmptyLinkColumn(t *testing.T) { + tw, err := coreutils.PrepareTable(convertToPackageStatusTable([]*PackageStatus{{PackageName: "axios", CatalogURL: "https://a"}}, false), "", false) + require.NoError(t, err) + if got := tw.Render(); strings.Contains(got, "LINK") { + t.Errorf("PrepareTable(rows without links) has a link column:\n%s", got) + } +} From 5c12c70e71f4d5ef1a4ed052d26a18e1a376b3b4 Mon Sep 17 00:00:00 2001 From: Vageesha B R Date: Wed, 18 Nov 2026 10:46:46 +0530 Subject: [PATCH 5/5] XRAY-169343 - Expect the styled link in the link column test The test compared the link cell with an unstyled hyperlink, which fails where colour output is enabled, such as on Windows. Co-Authored-By: Claude Opus 5.5 --- commands/curation/curationaudit_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/curation/curationaudit_test.go b/commands/curation/curationaudit_test.go index 146cbfd12..6a3b1acd7 100644 --- a/commands/curation/curationaudit_test.go +++ b/commands/curation/curationaudit_test.go @@ -7882,7 +7882,7 @@ func TestConvertToPackageStatusTableLinkColumn(t *testing.T) { withLinks bool want []string }{ - {name: "terminal", withLinks: true, want: []string{text.Hyperlink("https://a", "Open ↗") + " ", ""}}, + {name: "terminal", withLinks: true, want: []string{catalogLinkStyle.Render(text.Hyperlink("https://a", "Open ↗")) + " ", ""}}, {name: "not a terminal", withLinks: false, want: []string{"", ""}}, } for _, tt := range tests {