refactor(queue): extract manifest-policy gate from maybePublishPrPublicSurface - #4728
Conversation
…licSurface (#4607) Pulls the focus-manifest policy evaluation and E2E test-generation auto-trigger block out of maybePublishPrPublicSurface into a named maybeApplyManifestPolicyGate helper, matching the extraction pattern from parts 1 and 2 of the same effort (#4607). Pure code motion, verified byte-identical against the original inline block via a mechanical dedent+rename+diff script. Also resolves the two coverage gaps the relocation surfaced against this diff (both pre-existing on main, confirmed by comparing coverage runs before and after): a provably-unreachable gateFiles fallback gets a v8-ignore matching this file's own convention, and the manifest-finding filter's skip branch gets a real regression test.
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4728 +/- ##
=======================================
Coverage 94.21% 94.22%
=======================================
Files 439 439
Lines 38704 38704
Branches 14101 14100 -1
=======================================
+ Hits 36466 36468 +2
Misses 1576 1576
+ Partials 662 660 -2
🚀 New features to boost your workflow:
|
|
Warning 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏸️ Gittensory review result - manual review recommendedReview updated: 2026-07-10 21:26:01 UTC
⏸️ Suggested Action - Manual Review
Review summary Nits — 5 non-blocking
Concerns raised — review before merging
Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Summary
processors.tsmega-function breakup). This PR does one slice of themaybePublishPrPublicSurfaceportion of that issue — the largest and riskiest of the three functions,explicitly called out as needing "its own careful multi-part approach given the size" (2,600+ lines, 17%
of the file, up to 10 levels of nesting).
runAgentMaintenancePlanAndExecute(refactor(queue): extract plan-input builder from runAgentMaintenancePlanAndExecute #4688) andprocessGitHubWebhook(refactor(queue): split processGitHubWebhook into per-event handlers #4695) already shipped as the first two parts of this issue.one of the issue's own named extraction targets ("manifest-policy evaluation") — as the safest first
slice, over the other candidates (dry-run-chokepoint / unified-comment feature resolution / AI-vision BYOK
gate are already single-call sites into existing helpers with nothing left to extract; the unified-comment
render block and the review-memory suppression block are both more deeply nested, inside two stacked
conditionals after the function's own
try/catch). The manifest-policy block instead sits at the sameshallow, top-level sequential position in the gate-evaluation
tryblock as its already-extractedsiblings
maybeAddSecretLeakFinding/maybeAddLockfileTamperFinding(same file), has zero earlyreturns, and every one of its own locals is provably block-scoped — the surrounding code even has its own
comment confirming
e2eTestGenAvailableis "block-scoped to the manifestPolicyGateMode branch above...and out of scope here," independently re-resolving it a few hundred lines later.
if (settings.manifestPolicyGateMode !== "off") { ... }block (findings computationand the E2E test-generation auto-trigger it gates, both tightly coupled to the same
policyFindings/e2eTestGenAvailablevalues) into a new, namedmaybeApplyManifestPolicyGatehelper,colocated directly above
maybePublishPrPublicSurface, called from the exact spot the inline block usedto sit.
if (cond) { ... }shape rather thaninverting it into an early-return guard clause, specifically so a mechanical byte-diff could verify
fidelity without also having to reason about a control-flow rewrite. Wrote a small Node script
(not committed — a one-off local check, like the sibling PRs used) that: cuts the original inline block
from
origin/mainby exact line range, cuts the new function's body by exact line range, dedents both,and reverse-transforms the new text (
args.X→X, then collapses theX: Xobject-shorthand therename necessarily expanded back to bare
X, e.g.repoFullName: args.repoFullName→repoFullName) —confirmed byte-identical to the original. Every comment is preserved verbatim and in the same order.
maybePublishPrPublicSurfaceshrinks by ~77 lines (89 inline → a 12-line call), with thelogic itself now independently named and one step closer to independently testable.
Coverage follow-up in the same commit (the documented #4607 hard lesson)
Per PR #4695's own retro (a relocated-but-previously-untested line still counts as "new" against Codecov's
diff-based patch gate — line coverage alone also isn't enough, since Codecov measures branches too), I
cross-referenced
coverage/coverage-final.json'sstatementMap/sandbranchMap/b(not just theterminal summary table) against this diff's exact added-line ranges after the raw extraction, before
declaring it done. Found 3 gaps (1 statement + 2 branches, resolving to the same 2 underlying lines). For
each, I confirmed NEW-vs-PRE-EXISTING empirically — not by assumption — by running the identical
vitest --coveragecommand against an unmodifiedorigin/maincheckout (a throwawaygit worktree) anddiffing hit-count arrays at the original line numbers:
gateFiles ?? [](branch):hits=[20,0]onorigin/mainat line 10088,hits=[20,0]post-extraction —identical, confirmed pre-existing. It's also provably unreachable on the only real call path: the
sole caller only invokes this function when
manifestPolicyGateMode !== "off", and that exact samecondition is what makes the caller's own
gateFileslocal resolve viagetReviewFiles()(never null)immediately beforehand — the
| nullon the type exists only for TypeScript soundness on the caller'slet-then-conditionally-assigned local, not because of a reachable runtime null. Marked/* v8 ignore next -- see the comment above */, matching this exact file's own established convention(e.g. the neighboring
typeLabelsEnabled ?? true).if (!policyCodes.has(finding.code)) continue;(statement + branch):hits=[0,15]onorigin/mainatline 10126, identical post-extraction — also pre-existing, but genuinely reachable and testable:
buildFocusManifestGuidancecan produce finding codes outside the three enforceable ones (e.g.manifest_off_focus,manifest_preferred_path,manifest_missing_preferred_label), which this filter isspecifically there to drop before they reach the advisory. Added one real test
(
test/unit/queue.test.ts) that configureswantedPathsso an out-of-focus changed file produces amanifest_off_focusfinding alongside amanifest_missing_testsfinding from the same pass, and assertsthe published gate output contains the enforceable one's text but not the filtered one's — exercising
both sides of the branch with a real functional assertion, not just a coverage-padding call.
Re-ran the full cross-reference after both fixes: zero gaps remaining, at both line and branch level,
within this diff's added-line ranges.
Scope
type(scope): short summaryConventional Commit format, for examplefix(api): restore profile access checks.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #123) — a linked open issue is required for every contributor PR.Note on the issue link: this is
Part of #4607, notCloses/Fixes— the issue explicitly covers the restof
maybePublishPrPublicSurface(this is one slice of one of three parts) as further sequential PRs. Seethe issue body: "this is expected to land as multiple sequential PRs."
Validation
git diff --checknpm run actionlint— not run; no.github/workflows/**files touched.npm run typecheck— clean: before the coverage follow-up, after it, and again immediately afterrebasing onto fresh
origin/main.npm run test:coverage— not run as the literal full-suite command; a scoped coverage run (below)proved the diff itself is fully exercised at both line and branch level, matching the precedent set
by the two sibling Break up processors.ts mega-functions #4607 extraction PRs.
npm run test:workers— not run; notest/workers/**-relevant code touched.npm run build:mcp/npm run test:mcp-pack— not run; no MCP package changes.npm run ui:openapi:check/npm run ui:lint/npm run ui:typecheck/npm run ui:build— notrun; no
apps/gittensory-ui/**or API/schema changes.npm audit --audit-level=moderate— not run; no dependency changes.manifest_off_focusfilter branch (see Coverage follow-up above).If any required check was skipped, explain why:
src/queue/processors.tswithno UI, MCP, workers, schema, OpenAPI, workflow, or dependency surface touched, so those gates are left to
CI rather than duplicated locally (most path-filter out for this diff anyway). The checks that matter for
this change were run directly, in full, in the foreground, both before and after rebasing:
npm run typecheck: clean every time.npx vitest run test/unit/queue.test.ts: 810/810 tests passed (809 pre-existing, unmodified, plus1 new) — the primary suite exercising
maybePublishPrPublicSurfaceend-to-end via webhook processing,auto-action convergence, and the manifest-policy-gate-specific scenarios this PR's function now serves.
npx vitest run test/unit/queue.test.ts --coverage --coverage.include='src/queue/processors.ts' --coverage.reporter=json,parsed
coverage/coverage-final.jsondirectly (statementMap/sandbranchMap/b, not the mixedterminal summary) and cross-referenced against the diff's exact added-line ranges from
git diff origin/main --unified=0. Zero uncovered statements, zero partially-covered branches, withinthose ranges — full detail above.
git fetch origin && git rebase origin/mainimmediately before pushing completed with noconflicts (none of the 6 commits that had landed on
mainsince this branch was created touchedsrc/queue/processors.ts). Re-ran typecheck, the fullqueue.test.tssuite, and the coveragecross-reference again after rebasing — identical clean results.
Safety
UI Evidencesection below... — N/A, no visible/UI changes (backend-only refactor).CHANGELOG.mdintentionally not touched.UI Evidence
Not applicable — this PR has no visible/UI/frontend/docs surface; it is a backend-only, behavior-preserving
extraction inside
src/queue/processors.ts.Notes
maintainer-only).maybePublishPrPublicSurface"needs its own careful multi-part approach given the size" — did not attempt the unified-comment render
block, the review-memory suppression block, the AI-review cache/dispatch closure, or any of the other
large sections in the same pass, to keep this PR's own risk surface reviewable and its byte-diff
verification tractable.
maybePublishPrPublicSurface(unified-comment rendering, review-memory/publish-suppression, the AI-review dispatch closure, and
whatever else the next read of the function surfaces) — each is a substantially larger and more
deeply-nested/mutable-state-coupled unit than this one, and will need their own individually-scoped PRs
and their own byte-diff + coverage verification passes.