refactor: deduplicate utilities and remove dead code#69
Draft
NikolayS wants to merge 1 commit into
Draft
Conversation
Behavior-preserving cleanups across lib/. No public API or CLI flag changes. - Extract buildApiHeaders / debugLogRequest / debugLogResponse to lib/util.ts and use them throughout lib/issues.ts and lib/reports.ts (replaces ~15 copies of the same PostgREST-headers object and debug-logging blocks). - Extract UUID_PATTERN constant in lib/issues.ts (was duplicated in 4 places). - Export PG_ERROR_FIELDS from lib/init.ts and reuse in lib/supabase.ts instead of redeclaring the same list of node-postgres error fields. - Lift the begin/commit/rollback step runner in lib/init.ts to a shared executeStepInTransaction helper (applyInitPlan / applyUninitPlan had identical local copies). - Merge two separate "../lib/util" import lines in cli/bin/postgres-ai.ts into one. Verified: bun run typecheck still reports the same 20 pre-existing errors (test files only); targeted bun test runs for issues, reports, init, supabase, and mcp-server all pass. https://claude.ai/code/session_01U4F5KjW5neeCYxkKUZawfS
| console.error(`Debug: Resolved API base URL: ${params.base}`); | ||
| console.error(`Debug: ${params.method} URL: ${params.url}`); | ||
| console.error(`Debug: Auth scheme: access-token`); | ||
| console.error(`Debug: Request headers: ${JSON.stringify(debugHeaders)}`); |
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
Behavior-preserving code-quality cleanups across
cli/lib/**. No public API, CLI flag, config, SQL, or dependency changes.buildApiHeadershelper — extract the (previously copy-pasted ~15x) PostgREST request-header object intolib/util.ts. Applied inlib/issues.tsandlib/reports.ts.debugLogRequest/debugLogResponsehelpers — extract the matching debug-logging blocks intolib/util.tsand apply inlib/issues.tsandlib/reports.ts. (Side effect:reports.tsnow also logs response headers under--debug, matchingissues.ts— debug output only.)UUID_PATTERNconstant inlib/issues.ts— was redeclared inline 4 times acrossfetchActionItem,fetchActionItems,createActionItem,updateActionItem.PG_ERROR_FIELDSexported fromlib/init.tsand reused inlib/supabase.ts(was a 15-element list duplicated verbatim; Supabase variant adds two extra fields on top).executeStepInTransactionlifted to module scope inlib/init.ts—applyInitPlanandapplyUninitPlanhad identical localexecuteSteplambdas wrapping a step in BEGIN/COMMIT with ROLLBACK-on-failure."../lib/util"imports incli/bin/postgres-ai.tsinto a single line.Net diff: +172 / −325 lines.
Test plan
cd cli && bun run typecheck— same 20 pre-existing errors asorigin/main(all in test files, none touched here).cd cli && bun test test/issues.test.ts test/reports.test.ts test/init.test.ts test/supabase.test.ts test/mcp-server.test.ts— 298 pass, 0 fail.bun testsuite — 857 pass, 1 environmental timeout flake instorage.test.ts(500MB upload, passes on re-run; unrelated to this PR).https://claude.ai/code/session_01U4F5KjW5neeCYxkKUZawfS
Generated by Claude Code