Skip to content

refactor: deduplicate utilities and remove dead code#69

Draft
NikolayS wants to merge 1 commit into
mainfrom
claude/cleanup-code
Draft

refactor: deduplicate utilities and remove dead code#69
NikolayS wants to merge 1 commit into
mainfrom
claude/cleanup-code

Conversation

@NikolayS
Copy link
Copy Markdown
Contributor

Summary

Behavior-preserving code-quality cleanups across cli/lib/**. No public API, CLI flag, config, SQL, or dependency changes.

  1. buildApiHeaders helper — extract the (previously copy-pasted ~15x) PostgREST request-header object into lib/util.ts. Applied in lib/issues.ts and lib/reports.ts.
  2. debugLogRequest / debugLogResponse helpers — extract the matching debug-logging blocks into lib/util.ts and apply in lib/issues.ts and lib/reports.ts. (Side effect: reports.ts now also logs response headers under --debug, matching issues.ts — debug output only.)
  3. UUID_PATTERN constant in lib/issues.ts — was redeclared inline 4 times across fetchActionItem, fetchActionItems, createActionItem, updateActionItem.
  4. PG_ERROR_FIELDS exported from lib/init.ts and reused in lib/supabase.ts (was a 15-element list duplicated verbatim; Supabase variant adds two extra fields on top).
  5. executeStepInTransaction lifted to module scope in lib/init.tsapplyInitPlan and applyUninitPlan had identical local executeStep lambdas wrapping a step in BEGIN/COMMIT with ROLLBACK-on-failure.
  6. Merge duplicate "../lib/util" imports in cli/bin/postgres-ai.ts into a single line.

Net diff: +172 / −325 lines.

Test plan

  • cd cli && bun run typecheck — same 20 pre-existing errors as origin/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.
  • Full bun test suite — 857 pass, 1 environmental timeout flake in storage.test.ts (500MB upload, passes on re-run; unrelated to this PR).
  • Manual review of each refactor for behavior preservation.
  • CI green.

https://claude.ai/code/session_01U4F5KjW5neeCYxkKUZawfS


Generated by Claude Code

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
Comment thread cli/lib/util.ts
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)}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants