chore: remove dead scaffolding + guard GPC cookie clear (audit cleanup)#45
Merged
Conversation
Cuts the bloat findings from /m:audit --bloat — all scaffolding for paths the architecture deliberately doesn't use. Zero behavior change. - Remove trackConversion() + ConversionEvent (lib/ab-testing.ts): the function only console.log'd in dev; real conversion tracking is the variant written to Notion in the waitlist route (its own comment admitted this). Dropped the call site, import, and 4 tests. - Remove getGpcFromCookie() (lib/gpc.ts): exported "for server components" but zero production callers — GPC is read client-side in AnalyticsGate/GpcNotice and request-side in middleware. Dropping it also removes the only next/headers cookies() import. Dropped 4 tests. - Remove POSTHOG_ASSETS_HOST (lib/posthog/config.ts): exported, never imported. The CSP uses literal strings; init only sets api_host. - Trim phase-2-in-comments (lib/posthog/events.ts) and restating JSDoc (lib/gpc.ts). Kept the @see INFRA refs and load-bearing compliance comments. Perf finding (PERF-01): middleware now only clears being_gpc when the cookie is actually present (request.cookies.has), instead of emitting a needless clearing Set-Cookie on every no-GPC request — that Set-Cookie on ~all traffic defeats shared/CDN caching of HTML responses. Updated the middleware test accordingly (clears-when-present + does-not-emit- when-absent). Also: add /.open-next/ to .gitignore. The OpenNext Cloudflare build output (27MB) was untracked-but-not-ignored, so a local `opennextjs-cloudflare build` pollutes git status and makes `eslint` glob 12k+ generated files. Pre-existing gap, fixed here since it bit this very cleanup. Net: ~70 LOC removed, 80 → 75 tests (removed 6 dead-path tests, added 1 middleware test). lint + typecheck clean, build + worker build OK. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cleanup from `/m:audit --bloat` + the one `--performance` finding. All cuts are scaffolding for code paths the architecture deliberately doesn't use — zero behavior change. Net −121 LOC.
Dead code removed (bloat findings)
trackConversion()+ConversionEventlib/ab-testing.tsconsole.log'd in dev. Real conversion tracking is thevariantwritten to Notion in the waitlist route — the function's own comment admitted this.getGpcFromCookie()lib/gpc.tsAnalyticsGate,GpcNotice) and request-side (middleware). Removing it also drops the onlynext/headerscookies()import.POSTHOG_ASSETS_HOSTlib/posthog/config.tsinit()only setsapi_host.lib/posthog/events.ts,lib/gpc.ts@see INFRA-*refs and load-bearing compliance comments.Plus the corresponding tests for the deleted functions (6 tests removed).
Performance finding (PERF-01)
middleware.tscleared thebeing_gpccookie on every non-GPC request — emitting aSet-Cookieon ~all traffic, which defeats shared/CDN caching of HTML responses. Now guarded:Only emits the clearing
Set-Cookiewhen there's actually a stale cookie to clear. Updated the middleware test:clears-when-present+ newdoes-not-emit-when-absent.Bonus:
.gitignorefix/.open-next/(the 27MB OpenNext Cloudflare build output) was untracked-but-not-ignored. A localopennextjs-cloudflare buildpollutesgit statusand makeseslintglob 12k+ generated files (it bit this very cleanup — a stray build produced 469 phantom lint errors). Pre-existing gap, fixed here./.next/was already ignored;.open-nextwas just missed.Verification
npm run lint— cleannpm run typecheck— cleannpm test— 75 pass (was 80: −6 dead-path tests, +1 new middleware test)npm run build— all 17 routes staticRelationship to #44
Independent of the security PR (#44, dep updates) — different files, no conflict. Either can merge first.
🤖 Generated with Claude Code