diff --git a/changelog.d/fixed-disabled-repos-exact-match.md b/changelog.d/fixed-disabled-repos-exact-match.md new file mode 100644 index 0000000000..17f5a4142a --- /dev/null +++ b/changelog.d/fixed-disabled-repos-exact-match.md @@ -0,0 +1 @@ +- Contribute `hub.disabled_repos` now matches a plain entry against the exact repository name (full or bare, case-insensitive), so disabling `owner/dakota` no longer also disables `owner/dakota-iso`; `*` globs and `/regex/` entries work as before, and the **Repos for contribute** toggles in the dashboard follow the same rule. diff --git a/src/pkg/config/filters.go b/src/pkg/config/filters.go index 899d70e01c..1c1f89a1b4 100644 --- a/src/pkg/config/filters.go +++ b/src/pkg/config/filters.go @@ -1,5 +1,7 @@ package config +import "strings" + // MatchesAny returns true if text matches any pattern in the list. func MatchesAny(text string, patterns []string) bool { for _, p := range patterns { @@ -10,6 +12,37 @@ func MatchesAny(text string, patterns []string) bool { return false } +// RepoMatchesAny reports whether a repository, given as its full owner/name +// and its bare name, matches any hub.disabled_repos style pattern. Unlike +// MatchesAny, a plain entry (no "*", not wrapped in /…/) must equal one of +// the two forms exactly, case-insensitively, so disabling "owner/dakota" +// does not also disable "owner/dakota-iso". Globs and /regex/ entries keep +// the WildcardMatch semantics against both forms. Empty entries never match. +// +// One deliberate divergence from WildcardMatch: a lone "/" is NOT treated as +// an empty regex (which would match every repo) but as a plain entry, which +// can never equal a repo name. A stray "/" in disabled_repos must not silently +// disable everything. +func RepoMatchesAny(full, name string, patterns []string) bool { + for _, p := range patterns { + p = strings.TrimSpace(p) + if p == "" { + continue + } + isRegex := len(p) > 1 && strings.HasPrefix(p, "/") && strings.HasSuffix(p, "/") + if isRegex || strings.Contains(p, "*") { + if WildcardMatch(full, p) || WildcardMatch(name, p) { + return true + } + continue + } + if strings.EqualFold(full, p) || strings.EqualFold(name, p) { + return true + } + } + return false +} + // Contribute filter modes for title/author/label gating. const ( // FilterModeDeny (the default) skips items that MATCH the list; everything diff --git a/src/pkg/config/repo_matches_test.go b/src/pkg/config/repo_matches_test.go new file mode 100644 index 0000000000..4508f20442 --- /dev/null +++ b/src/pkg/config/repo_matches_test.go @@ -0,0 +1,47 @@ +package config + +import "testing" + +func TestRepoMatchesAny(t *testing.T) { + cases := []struct { + name string + full string + bare string + patterns []string + want bool + }{ + {"exact full name", "projectbluefin/dakota", "dakota", []string{"projectbluefin/dakota"}, true}, + {"exact bare name", "projectbluefin/dakota", "dakota", []string{"dakota"}, true}, + {"full entry is a prefix of another repo", "projectbluefin/dakota-iso", "dakota-iso", []string{"projectbluefin/dakota"}, false}, + {"bare entry is a prefix of another repo", "projectbluefin/dakota-iso", "dakota-iso", []string{"dakota"}, false}, + {"bare entry is a substring of the owner", "projectbluefin/common", "common", []string{"bluefin"}, false}, + {"glob matches the prefixed repo", "projectbluefin/dakota-iso", "dakota-iso", []string{"projectbluefin/dakota*"}, true}, + {"glob matches the repo itself", "projectbluefin/dakota", "dakota", []string{"projectbluefin/dakota*"}, true}, + {"anchored regex matches exactly", "projectbluefin/dakota", "dakota", []string{`/^projectbluefin\/dakota$/`}, true}, + {"anchored regex skips the prefixed repo", "projectbluefin/dakota-iso", "dakota-iso", []string{`/^projectbluefin\/dakota$/`}, false}, + {"regex against the bare name", "projectbluefin/dakota-iso", "dakota-iso", []string{`/^dakota-/`}, true}, + {"invalid regex never matches", "projectbluefin/dakota", "dakota", []string{`/dakota(/`}, false}, + {"case-insensitive full name", "projectbluefin/dakota", "dakota", []string{"ProjectBluefin/Dakota"}, true}, + {"case-insensitive bare name", "projectbluefin/dakota", "dakota", []string{"DAKOTA"}, true}, + {"surrounding whitespace is ignored", "projectbluefin/dakota", "dakota", []string{" projectbluefin/dakota "}, true}, + {"empty entry never matches", "projectbluefin/dakota", "dakota", []string{"", " "}, false}, + {"lone slash is not an empty regex", "projectbluefin/dakota", "dakota", []string{"/"}, false}, + {"later entry matches", "projectbluefin/dakota", "dakota", []string{"other/repo", "dakota"}, true}, + {"no patterns", "projectbluefin/dakota", "dakota", nil, false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if got := RepoMatchesAny(tc.full, tc.bare, tc.patterns); got != tc.want { + t.Errorf("RepoMatchesAny(%q, %q, %q) = %v, want %v", tc.full, tc.bare, tc.patterns, got, tc.want) + } + }) + } +} + +// The title, label and author filters keep substring semantics for plain +// entries: only repository matching became exact. +func TestMatchesAnyKeepsSubstringSemantics(t *testing.T) { + if !MatchesAny("projectbluefin/dakota-iso", []string{"projectbluefin/dakota"}) { + t.Error("MatchesAny must keep matching a plain entry as a substring") + } +} diff --git a/src/pkg/dashboard/api_contribute.go b/src/pkg/dashboard/api_contribute.go index 0cfb2363c7..65c0703b9f 100644 --- a/src/pkg/dashboard/api_contribute.go +++ b/src/pkg/dashboard/api_contribute.go @@ -677,7 +677,7 @@ type contributeRepository struct { // contributeEligibleRepositories lists the repositories contributors may be // offered work from: the hub's monitored repositories minus hub.disabled_repos, -// matched with the same MatchesAny rule selectTask applies. The monitored set +// matched with the same RepoMatchesAny rule selectTask applies. The monitored set // is the status snapshot selection reads; before the first snapshot it is the // configured project repos, qualified with the org exactly as buildRepos does. func (s *Server) contributeEligibleRepositories() []contributeRepository { @@ -718,7 +718,7 @@ func (s *Server) contributeEligibleRepositories() []contributeRepository { if full == "" || !strings.Contains(full, "/") { continue } - if config.MatchesAny(r.full, disabled) || config.MatchesAny(r.name, disabled) { + if config.RepoMatchesAny(r.full, r.name, disabled) { continue } id := repoScopeID(repoScopeDefaultForge, host, full) diff --git a/src/pkg/dashboard/contribute_bugs_rest_test.go b/src/pkg/dashboard/contribute_bugs_rest_test.go index 4ca18d344d..dbe6b3e995 100644 --- a/src/pkg/dashboard/contribute_bugs_rest_test.go +++ b/src/pkg/dashboard/contribute_bugs_rest_test.go @@ -228,6 +228,7 @@ func TestGovernorHubReposUseCanonicalDisabledRepoMatching(t *testing.T) { for _, want := range []string{ "function contribRepoDisabledEntryMatches(repoFull, entry)", "text = String(text || '').toLowerCase();", + "return full.toLowerCase() === entry || short.toLowerCase() === entry;", "const enabled = contribRepoMatchingDisabledEntries(r, disabledRepos).length === 0;", `data-action="toggleContribRepo" data-arg1="' + esc(r.full) + '"`, "Raw disabled_repos:", diff --git a/src/pkg/dashboard/contribute_disabled_repo_prefix_test.go b/src/pkg/dashboard/contribute_disabled_repo_prefix_test.go new file mode 100644 index 0000000000..7ac7120626 --- /dev/null +++ b/src/pkg/dashboard/contribute_disabled_repo_prefix_test.go @@ -0,0 +1,155 @@ +package dashboard + +import ( + "os/exec" + "strings" + "testing" +) + +// #14707: a disabled_repos entry that is a prefix of another tracked repo's +// name disables only the named repo. dakota-iso keeps serving work while +// dakota is withheld with disabled_repo. +func TestReadyQueue_DisabledRepoPrefixDoesNotDisableLongerName(t *testing.T) { + for _, entry := range []string{"projectbluefin/dakota", "dakota", "ProjectBluefin/Dakota"} { + t.Run(entry, func(t *testing.T) { + hub, s := withheldHub(t, nil) + s.statusMu.Lock() + s.status.Repos = append(s.status.Repos, FrontendRepo{ + Name: "dakota-iso", + Full: "projectbluefin/dakota-iso", + ActionableIssues: []any{map[string]any{ + "number": float64(800), + "title": "iso work", + "url": "https://github.com/projectbluefin/dakota-iso/issues/800", + "author": "someone", + }}, + }) + s.statusMu.Unlock() + s.deps.Config.Hub.DisabledRepos = []string{entry} + + assertQueue(t, hub, 800) + assertAssigns(t, hub, 800) + + snap := hub.admissionQueueSnapshot(readyQueueDefaultLimit, withheldAll) + for _, key := range []string{"projectbluefin/dakota#601", "projectbluefin/dakota#700"} { + item, ok := findWithheld(snap.withheld, key) + if !ok { + t.Fatalf("%s is disabled but unexplained; collected %v", key, snap.withheld) + } + if item.Reason != withheldReasonDisabledRepo { + t.Errorf("%s reason = %q, want %q", key, item.Reason, withheldReasonDisabledRepo) + } + } + if item, ok := findWithheld(snap.withheld, "projectbluefin/dakota-iso#800"); ok { + t.Errorf("dakota-iso#800 must not be withheld, got reason %q", item.Reason) + } + }) + } +} + +// Execute the shipped Repos-for-contribute matcher and toggle: prefix-sharing +// names get their own state, a regex entry is honoured, and turning dakota-iso +// on keeps the projectbluefin/dakota entry in place. +func TestContribRepoToggleKeepsPrefixSharingEntries(t *testing.T) { + node, err := exec.LookPath("node") + if err != nil { + t.Skip("node unavailable: contribute repo toggle was not executed") + } + html := indexHTML(t) + var source strings.Builder + source.WriteString(`const assert = require('node:assert/strict'); +let toasts = []; +let dirty = []; +function showToast(msg) { toasts.push(msg); } +function markDirty(section, key, val) { dirty.push([section, key, val]); } +function renderConfigTab() {} +const _configState = { data: { hub: {} } }; +function onEl() { return { classList: { contains: (c) => c === 'on' } }; } +function offEl() { return { classList: { contains: () => false } }; } +`) + for _, name := range []string{ + "contribRepoShortName", + "contribRepoWildcardMatch", + "contribRepoIsRegexEntry", + "contribRepoDisabledEntryMatches", + "contribRepoMatchingDisabledEntries", + "toggleContribRepo", + } { + source.WriteString(jsFunc(t, html, name)) + source.WriteByte('\n') + } + source.WriteString(`const m = contribRepoDisabledEntryMatches; +assert.equal(m('projectbluefin/dakota', 'projectbluefin/dakota'), true); +assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota'), false); +assert.equal(m('projectbluefin/dakota', 'dakota'), true); +assert.equal(m('projectbluefin/dakota-iso', 'dakota'), false); +assert.equal(m('projectbluefin/dakota', 'ProjectBluefin/Dakota'), true); +assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota*'), true); +assert.equal(m('projectbluefin/dakota', '/^projectbluefin\\/dakota$/'), true); +assert.equal(m('projectbluefin/dakota-iso', '/^projectbluefin\\/dakota$/'), false); +assert.equal(m('projectbluefin/dakota', '/dakota(/'), false); +assert.equal(m('projectbluefin/dakota', ''), false); + +// Turning dakota-iso on leaves the dakota entry alone. +_configState.data.hub.disabled_repos = ['projectbluefin/dakota', 'projectbluefin/dakota-iso']; +toggleContribRepo(offEl(), 'projectbluefin/dakota-iso'); +assert.deepEqual(_configState.data.hub.disabled_repos, ['projectbluefin/dakota']); + +// Turning dakota-iso off adds its own entry even though dakota is disabled. +toggleContribRepo(onEl(), 'projectbluefin/dakota-iso'); +assert.deepEqual(_configState.data.hub.disabled_repos, ['projectbluefin/dakota', 'projectbluefin/dakota-iso']); + +// A regex blocker is reported, not deleted. +_configState.data.hub.disabled_repos = ['/^projectbluefin\\/dakota$/']; +toasts = []; +toggleContribRepo(offEl(), 'projectbluefin/dakota'); +assert.deepEqual(_configState.data.hub.disabled_repos, ['/^projectbluefin\\/dakota$/']); +assert.equal(toasts.length, 1); +assert.match(toasts[0], /regex/); +`) + if out, err := exec.Command(node, "-e", source.String()).CombinedOutput(); err != nil { + t.Fatalf("contribute repo toggle failed: %v\n%s", err, out) + } +} + +// TestAdminRepoDisabledEntryMatchesExactPlainEntries pins the Contribute +// landing admin page to the same rule as config.RepoMatchesAny, so its +// "Repos for Contribute" toggles cannot disagree with the hub or strip a +// prefix-sharing entry when another repo is enabled. +func TestAdminRepoDisabledEntryMatchesExactPlainEntries(t *testing.T) { + node, err := exec.LookPath("node") + if err != nil { + t.Skip("node unavailable: admin repo matcher was not executed") + } + body := renderContributePage(t) + var source strings.Builder + source.WriteString("const assert = require('node:assert/strict');\n") + for _, name := range []string{ + "adminRepoShortName", + "adminRepoWildcardMatch", + "adminRepoIsRegexEntry", + "adminRepoDisabledEntryMatches", + "adminRepoMatchingDisabledEntries", + } { + source.WriteString(jsFunc(t, body, name)) + source.WriteByte('\n') + } + source.WriteString(`const m = adminRepoDisabledEntryMatches; +assert.equal(m('projectbluefin/dakota', 'projectbluefin/dakota'), true); +assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota'), false); +assert.equal(m('projectbluefin/dakota', 'dakota'), true); +assert.equal(m('projectbluefin/dakota-iso', 'dakota'), false); +assert.equal(m('projectbluefin/dakota', 'ProjectBluefin/Dakota'), true); +assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota*'), true); +assert.equal(m('projectbluefin/dakota', '/^projectbluefin\\/dakota$/'), true); +assert.equal(m('projectbluefin/dakota-iso', '/^projectbluefin\\/dakota$/'), false); +assert.equal(m('projectbluefin/dakota', '/dakota(/'), false); +assert.equal(m('projectbluefin/dakota', ''), false); +assert.deepEqual( + adminRepoMatchingDisabledEntries('projectbluefin/dakota-iso', ['projectbluefin/dakota', 'projectbluefin/dakota-iso']), + ['projectbluefin/dakota-iso']); +`) + if out, err := exec.Command(node, "-e", source.String()).CombinedOutput(); err != nil { + t.Fatalf("admin repo matcher failed: %v\n%s", err, out) + } +} diff --git a/src/pkg/dashboard/contribute_landing.go b/src/pkg/dashboard/contribute_landing.go index ff9bb8504b..dbcf86ca65 100644 --- a/src/pkg/dashboard/contribute_landing.go +++ b/src/pkg/dashboard/contribute_landing.go @@ -4689,11 +4689,23 @@ function adminRepoWildcardMatch(text,pattern){ if(pattern.charAt(pattern.length-1)!=='*'&&last&&text.slice(-last.length)!==last)return false; return true; } +function adminRepoIsRegexEntry(entry){ + entry=String(entry||'').trim(); + return entry.length>1&&entry.charAt(0)==='/'&&entry.charAt(entry.length-1)==='/'; +} +// Mirrors config.RepoMatchesAny: a plain entry must equal the full or bare +// name (case-insensitive); * globs and /regex/ entries match either form. function adminRepoDisabledEntryMatches(repoFull,entry){ var full=String(repoFull||''),short=adminRepoShortName(full); entry=String(entry||'').trim(); if(!entry)return false; - return adminRepoWildcardMatch(full,entry)||adminRepoWildcardMatch(short,entry); + if(adminRepoIsRegexEntry(entry)){ + var re;try{re=new RegExp(entry.slice(1,-1),'i');}catch(e){return false;} + return re.test(full)||re.test(short); + } + if(entry.indexOf('*')>=0)return adminRepoWildcardMatch(full,entry)||adminRepoWildcardMatch(short,entry); + entry=entry.toLowerCase(); + return full.toLowerCase()===entry||short.toLowerCase()===entry; } function adminRepoMatchingDisabledEntries(repoFull,disabled){ return (disabled||[]).filter(function(entry){return adminRepoDisabledEntryMatches(repoFull,entry);}); @@ -4944,8 +4956,8 @@ onEl('ops-admin','click',function(e){ var dr=(adminHub.disabled_repos||[]).slice(); var matches=adminRepoMatchingDisabledEntries(repo,dr); if(matches.length){ - var wild=matches.filter(function(r){return String(r||'').indexOf('*')>=0;}); - if(wild.length){toast('This repo is disabled by wildcard disabled_repos entry: '+wild.join(', '),false);renderAdminControls();return;} + var wild=matches.filter(function(r){return String(r||'').indexOf('*')>=0||adminRepoIsRegexEntry(r);}); + if(wild.length){toast('This repo is disabled by wildcard or regex disabled_repos entry: '+wild.join(', '),false);renderAdminControls();return;} dr=dr.filter(function(r){return !adminRepoDisabledEntryMatches(repo,r);}); }else{ dr.push(repo); diff --git a/src/pkg/dashboard/contribute_opportunistic.go b/src/pkg/dashboard/contribute_opportunistic.go index 5556c75a1a..1804057fbb 100644 --- a/src/pkg/dashboard/contribute_opportunistic.go +++ b/src/pkg/dashboard/contribute_opportunistic.go @@ -203,7 +203,7 @@ func (h *ContributeWSHub) actionableAgeMinutes() map[string]int { disabledRepos = h.server.deps.Config.Hub.DisabledRepos } for _, repo := range status.Repos { - if config.MatchesAny(repo.Full, disabledRepos) || config.MatchesAny(repo.Name, disabledRepos) { + if config.RepoMatchesAny(repo.Full, repo.Name, disabledRepos) { continue } for _, raw := range repo.ActionableIssues { diff --git a/src/pkg/dashboard/contribute_select.go b/src/pkg/dashboard/contribute_select.go index 90c06beb0f..62190153a3 100644 --- a/src/pkg/dashboard/contribute_select.go +++ b/src/pkg/dashboard/contribute_select.go @@ -768,7 +768,7 @@ func (h *ContributeWSHub) selectTaskPass(c *ContributorConnection, skippedUnmint if len(repo.ActionableIssues) == 0 { continue } - if config.MatchesAny(repo.Full, disabledRepos) || config.MatchesAny(repo.Name, disabledRepos) { + if config.RepoMatchesAny(repo.Full, repo.Name, disabledRepos) { continue } if !repoScope.allows(repoScopeID(repoScopeDefaultForge, scopeHost, repo.Full)) { diff --git a/src/pkg/dashboard/contribute_sse.go b/src/pkg/dashboard/contribute_sse.go index 0567a7c647..0552bfd047 100644 --- a/src/pkg/dashboard/contribute_sse.go +++ b/src/pkg/dashboard/contribute_sse.go @@ -346,7 +346,7 @@ func (h *ContributeWSHub) admissionQueueSnapshot(limit int, scope withheldScope) if len(repo.ActionableIssues) == 0 { continue } - if config.MatchesAny(repo.Full, disabledRepos) || config.MatchesAny(repo.Name, disabledRepos) { + if config.RepoMatchesAny(repo.Full, repo.Name, disabledRepos) { // #6902: a disabled repository refuses all its candidates before // the per-issue ladder, so explain them here. Skip decoding when // diagnostics are not being collected. diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 00d3222cf8..92e7193801 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -47321,12 +47321,26 @@