[refactor] Semantic function clustering: duplicate isASCII helper and test-only wrapper in production code
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
Línea de trabajo
Empieza con las dos copias privadas de isASCII en internal/reposelector/reposelector.go (alrededor de la línea 90) y internal/sanitize/sanitize.go (alrededor de la línea 136), luego con el paquete compartido en internal/util. Añade un IsASCII exportado en internal/util, cambia ambos sitios de llamada para usarlo y elimina las copias privadas. Está terminado cuando go test ./internal/reposelector/ ./internal/sanitize/ ./internal/util/ pasa con el comportamiento sin cambios.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Overview
Analyzed 215 non-test Go files under internal/ (about 38.7k lines, 1,378 function and method declarations). The prompt's estimate of about 39 files is out of date. No open [refactor] issues existed, so nothing was closed. The package layout is largely sound: random-token helpers already delegate to internal/util, and the agent-filtered server builders share registerFilteredTools.
Two actionable items were confirmed: an exact duplicate isASCII helper, and a production-file wrapper (applyIfConfigured) that only tests call. A JSON Pointer cohesion issue is a minor third item. Several look-alike pairs have different semantics and should be left alone (see below).
Full Report
Method
- Listed every
funcdeclaration in non-test.gofiles and grouped them by package and file. - Scanned for repeated unexported free-function names across files. Repeated method names on different receivers were treated as expected and excluded.
- Read the bodies of candidate pairs and checked their call sites, including test references.
- Checked the import graph to confirm where a shared helper could live without an import cycle.
No code was modified. Detection is name- and body-based (grep and direct reads), not AST-based.
Priority 1: Actionable
1. Exact duplicate isASCII
| Location | Check |
|---|---|
internal/reposelector/reposelector.go:90 |
if s[i] > 0x7f { return false } |
internal/sanitize/sanitize.go:136 |
if s[i] >= 0x80 { return false } |
These are semantically identical. Both are used for ASCII-only validation: reposelector in IsCanonicalOwner and IsCanonicalRepositorySelector, and sanitize in SanitizeString.
Recommendation: export one IsASCII from internal/util, which has no internal imports, so neither package creates a cycle. sanitize already imports util. Update both call sites and keep the existing behavior.
2. Test-only wrapper in production code
internal/server/middleware_auth.go:17:applyIfConfigured(key, handler, middleware)has no production caller. It is referenced only frommiddleware_auth_test.goandshutdown_auth_helpers_test.go.- It is a thin wrapper over
applyIfConfiguredWithLog, which the productionapplyHMACIfConfiguredcalls directly.
Recommendation: move applyIfConfigured into a _test.go helper in package server, or have the tests call applyIfConfiguredWithLog directly. This removes dead production surface.
Priority 2: Cohesion
3. JSON Pointer escape logic split across files (internal/difc)
escapeJSONPointerTokenis inpath_collections.go:142.- The matching unescape (
~1to/, then~0to~) is inline insplitJSONPointerinpath_labels.go:329-330.
Recommendation: move both into one path_pointer.go so the encode and decode rules sit side by side under the one-file-per-feature rule.
Looked similar, but do not consolidate
| Pair | Why it stays separate |
|---|---|
logger.redactTags (logger/jsonl_logger.go:211) vs guard.logSafeTags (guard/pipeline.go:263) |
Both redact tags for logs, but one uses RedactPrivateSelectors and the other a keyed hash (util.HashForLog). Different policies. |
util.NormalizeStringCI (util/format.go:7, ToLower+TrimSpace) vs config.lowercaseASCII (config/guard_policy_validation.go:287) |
Merging would change behavior for non-ASCII scope strings, because lowercaseASCII leaves them unchanged and does not trim. |
Inline io.ReadAll in proxy/handler.go:627 vs httputil.readResponseBody |
The proxy path reports errors through rejectProxyRequest with a span. readResponseBody has only 3 callers. |
| 8 owner/repo split sites | They use Cut, SplitN, and Split with different validation. Unify only with a behavior review. |
generateRandomSpanID, generateOpaqueToken, randomSerial |
Already delegate to util.RandomBytes/RandomHex/RandomBigInt. Healthy. |
createAgentFilteredServer, createAgentFilteredUnifiedServer, createDelegationFilteredServer |
Already share registerFilteredTools. Healthy. |
Package Inventory (largest by function count)
| Package | Files | Funcs |
|---|---|---|
internal/server |
29 | 177 |
internal/config |
21 | 177 |
internal/difc |
13 | 135 |
internal/logger |
16 | 131 |
internal/proxy |
12 | 110 |
internal/guard |
14 | 95 |
internal/mcp |
12 | 80 |
Several packages have no free functions beyond types and constants (for example hmacutil, jqutil, mcpresult, reposelector, version).
Implementation Checklist
- Add
util.IsASCII; switchreposelectorandsanitizeto it; delete both private copies - Move
applyIfConfiguredout of production code, or have tests callapplyIfConfiguredWithLog - Consolidate JSON Pointer escape/unescape into
internal/difc/path_pointer.go - Run
go test ./internal/reposelector/ ./internal/sanitize/ ./internal/util/ ./internal/server/ ./internal/difc/
Analysis Metadata
- Total Go files analyzed: 215 (non-test, under
internal/) - Total functions cataloged: 1,378
- Outliers found: 1 (test-only wrapper); 1 cohesion issue
- Duplicates detected: 1 exact (
isASCII); 2 near-duplicates rejected on semantics - Detection method: declaration inventory, repeated-name scan, body comparison, call-site and import-graph checks
References: §45069342734
Generated by Semantic Function Refactoring · copilot · routed: haiku55 xhigh · ~12 AIC · ⊞ 7.4K · ◷
- Lenguaje dominante
- Go
- Estrellas
- 190
- Forks
- 61
- Merge medio
- 7 h 35 min
- PR fusionados (30 d)
- 215
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de github/gh-aw-mcpg
-
smoke-copilot
Dificultad 3/5 1-3 horas Aptitud para principiantes 8/100
github/gh-aw-mcpg#17112 ·
Los mantenedores suelen responder en 1 día
-
automation mcp-gateway test
Dificultad 1/5 Menos de una hora Aptitud para principiantes 5/100
github/gh-aw-mcpg#17110 ·
Los mantenedores suelen responder en 1 día
-
automation compliance specification
Dificultad 4/5 1-2 días Aptitud para principiantes 15/100
github/gh-aw-mcpg#17106 ·
Los mantenedores suelen responder en 1 día
-
Smoke Copilot - Issue GroupAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 4/100
github/gh-aw-mcpg#17090 ·
Los mantenedores suelen responder en 1 día
-
Smoke Copilot - Issue GroupAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 5/100
github/gh-aw-mcpg#17089 ·
Los mantenedores suelen responder en 1 día
Todos los issues de github/gh-aw-mcpg
Issues similares
-
go good first issue test
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 2 días
-
[UI] Guard webApis against undefined window in SSR environmentsPosiblemente ocupada @madhavzanwar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
kind/enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días