From 1cee567865284be756e6676de297bee680b068b2 Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Fri, 10 Jul 2026 04:28:16 -0700 Subject: [PATCH] refactor(review): consolidate 3 duplicate helper implementations (#4611) Three independent, low-risk duplicate cleanups from the review-stack architecture audit's duplication dimension: - isCommentLine: extracted the byte-identical body shared by unsafe-any.ts, complexity.ts, and floating-promise.ts into a new isBasicCommentLine export in review-enrichment's diff-lines.ts. hardcoded-url.ts and a11y-regression.ts keep their own isCommentLine override, now composing the shared base plus their deliberate per-language extras (shell/Python #, HTML ", "import x from 'y'", "from y import x"]) { + assert.equal(isBasicCommentLine(line), false, line); + } + // Real code → never flagged. + for (const line of ["const x = 1;", " return a && b;", "export function run() {"]) { + assert.equal(isBasicCommentLine(line), false, line); + } +}); diff --git a/src/api/routes.ts b/src/api/routes.ts index f6293414b6..e074d17300 100644 --- a/src/api/routes.ts +++ b/src/api/routes.ts @@ -166,6 +166,7 @@ import { decidePendingAgentAction } from "../services/agent-approval-queue"; import { explainScoreBreakdown } from "../services/score-breakdown"; import { buildMcpClientTelemetry } from "../services/client-telemetry"; import { + authoritativeContributorRepoStats, buildAndPersistContributorDecisionPack, CONTRIBUTOR_DECISION_PACK_SIGNAL, loadContributorDecisionPackForServing, @@ -5204,14 +5205,6 @@ function parseBackfillSegment(value: unknown): Extract>, - cachedRepoStats: Awaited>, -) { - const officialRepoStats = contributorRepoStatsFromGittensor(gittensorSnapshot); - return officialRepoStats.length > 0 ? officialRepoStats : cachedRepoStats; -} - async function persistSignal( env: Env, signalType: string, diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 9de690e595..e9c3c0df35 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -86,7 +86,7 @@ import { preparePrPacketWithAgent, startAgentRun, } from "../services/agent-orchestrator"; -import { loadContributorDecisionPackForServing, repoDecisionFromPack } from "../services/decision-pack"; +import { authoritativeContributorRepoStats, loadContributorDecisionPackForServing, repoDecisionFromPack } from "../services/decision-pack"; import { buildPublicPrBodyDraft } from "../services/pr-body-draft"; import { buildRemediationPlan } from "../services/remediation-plan"; import { deriveEligibilityPlan } from "../services/eligibility-plan"; @@ -3782,14 +3782,6 @@ function redactSensitiveForMcp(value: unknown): unknown { ); } -function authoritativeContributorRepoStats( - gittensorSnapshot: Awaited>, - cachedRepoStats: Awaited>, -) { - const officialRepoStats = contributorRepoStatsFromGittensor(gittensorSnapshot); - return officialRepoStats.length > 0 ? officialRepoStats : cachedRepoStats; -} - async function authenticateMcpRequest(c: AppContext): Promise { const identity = await authenticatePrivateToken(c.env, extractBearerToken(c.req.header("authorization"))); if (!identity || identity.kind !== "session") return identity; diff --git a/src/queue/processors.ts b/src/queue/processors.ts index c83e6abc66..a16f5898f2 100644 --- a/src/queue/processors.ts +++ b/src/queue/processors.ts @@ -228,6 +228,7 @@ import { refreshScoringModelSnapshot, } from "../scoring/model"; import { + authoritativeContributorRepoStats, buildAndPersistContributorDecisionPack, loadDecisionPackSharedInputs, } from "../services/decision-pack"; @@ -15558,17 +15559,6 @@ function officialGittensorContributorDetection( }; } -function authoritativeContributorRepoStats( - gittensorSnapshot: Awaited< - ReturnType - >, - cachedRepoStats: Awaited>, -) { - const officialRepoStats = - contributorRepoStatsFromGittensor(gittensorSnapshot); - return officialRepoStats.length > 0 ? officialRepoStats : cachedRepoStats; -} - /** Split `owner/name` into the project/repo key shape shared by RAG indexing and retrieval. */ export function splitRepoForRag(repoFullName: string): [string, string] { const slash = repoFullName.indexOf("/"); diff --git a/src/services/decision-pack.ts b/src/services/decision-pack.ts index 27a4adb390..3bb323cffc 100644 --- a/src/services/decision-pack.ts +++ b/src/services/decision-pack.ts @@ -1794,7 +1794,11 @@ function snapshotAgeMs(generatedAt: string): number { return Number.isFinite(parsed) ? Date.now() - parsed : Number.POSITIVE_INFINITY; } -function authoritativeContributorRepoStats( +/** The gittensor-official snapshot's repo stats when present, falling back to the last cached copy — + * gittensor is the authoritative source when reachable, the cache is only a degrade-gracefully fallback for + * when it isn't. Shared by every site that resolves a contributor's repo stats (#4611) — mcp/server.ts, + * api/routes.ts, and queue/processors.ts all import this rather than redefining it. */ +export function authoritativeContributorRepoStats( gittensorSnapshot: Awaited>, cachedRepoStats: ContributorRepoStatRecord[], ) {