Skip to content

chore: codebase optimization — reduce duplication, modernize Go, add linting and tests#30

Merged
qasim-nylas merged 9 commits intomainfrom
chore/codebase-optimization
Mar 10, 2026
Merged

chore: codebase optimization — reduce duplication, modernize Go, add linting and tests#30
qasim-nylas merged 9 commits intomainfrom
chore/codebase-optimization

Conversation

@qasim-nylas
Copy link
Collaborator

Summary

Comprehensive codebase optimization across CI infrastructure, Go modernization, test coverage, and documentation deduplication.

  • Add .golangci.yml (v2) with durationcheck, reassign, gofmt, goimports linters
  • Harden CI pipeline with gofmt check and govulncheck vulnerability scanning
  • Modernize Go — replace sort.Slice with slices.SortFunc, interface{} with any
  • Split oversized test files (3 files over 600 lines → 10 focused files)
  • Add 104 new test cases for audit commands, audit helpers, and httputil
  • Deduplicate .claude/ config — remove ~450 lines of duplicated content
  • Fix all lint violations in changed files (errcheck, misspell)

Net: +3,342 / −2,646 across 63 files. All CI checks pass (make ci-full).


Changes by Category

1. CI & Linting Infrastructure

File Change
.golangci.yml New — golangci-lint v2 config (conservative: only linters the codebase passes)
.github/workflows/ci.yml Added gofmt formatting check + govulncheck vulnerability scan
.claude/settings.json Wired auto-format.sh hook for Write tool (was only on Edit)

2. Go Modernization (34 files)

Change Files Details
interface{}any 31 test files Mechanical replacement across nylas, slack, webhookserver, air, integration
sort.Sliceslices.SortFunc 3 files store.go, memory.go, logs_summary.go — uses Go 1.21+ stdlib
Unchecked type assertions 7 test files v := x.(T)v, _ := x.(T) to satisfy errcheck
Misspelling fixes 2 test files behaviourbehavior (US English)

3. Oversized Test File Splits (3 → 10 files)

Original Lines Split Into
cli/audit_hooks_test.go 839 → deleted audit_hooks_context_test.go (125), audit_hooks_sanitize_test.go (230), audit_hooks_identity_test.go (284), audit_hooks_lifecycle_test.go (218)
cli/common/format_test.go 659 → deleted format_parse_test.go (60), format_output_test.go (271), format_table_test.go (347)
adapters/gpg/encrypt_test.go 681 → 291 + decrypt_test.go (216), keys_test.go (186)

All tests preserved — no logic changes, just file reorganization by responsibility.

4. New Tests (+1,053 lines, 104 cases)

File Cases Coverage
internal/cli/audit/commands_test.go 34 Audit command constructors, flag defaults, subcommand wiring
internal/cli/audit/helpers_test.go 52 Helper functions: FormatDuration, FormatStatus, table formatting
internal/httputil/httputil_test.go 18 WriteJSON, LimitedBody, DecodeJSON

5. .claude/ Config Deduplication (~450 lines removed)

File Before → After What Changed
CLAUDE.md 254 → 231 Condensed credential storage (28→4 lines), added CLI package list, removed stale refs
.claude/HOOKS-CONFIG.md 272 → 107 Rewrote — aligned with actual hook wiring status, removed 150+ lines of examples
.claude/README.md 174 → 133 Fixed stale counts (4 rules not 6, 9 agents not 6), removed duplicate credential table
.claude/commands/add-api-method.md 109 → 41 Replaced inline Go templates with pointers to shared adapter-patterns.md
.claude/commands/add-domain-type.md 120 → 28 Replaced inline Go templates with pointers to shared domain-patterns.md
.claude/commands/generate-crud-command.md 28 → deleted Was just a deprecation notice pointing to /add-command
.claude/commands/generate-tests.md 68 → 54 Removed duplicate test commands, added pointer to /run-tests
.claude/commands/update-docs.md 195 → 188 Replaced duplicate doc matrix with pointer to documentation-maintenance.md
.claude/agents/references/security-checklist.md 217 → 190 Replaced duplicate credential table with pointer to source of truth

6. Pre-existing Lint Fixes

File Fix
mcp/proxy_forward_test.go 5 unchecked type assertions → safe _, _ pattern
mcp/proxy_response_extra_test.go 5 unchecked type assertions → safe _, _ pattern

Test plan

  • make ci passes (fmt, vet, lint, unit tests, race detector, security, vuln, build)
  • make ci-full passes (above + integration tests + cleanup)
  • golangci-lint run --new-from-rev=main reports 0 issues
  • All split test files maintain original test coverage
  • No production logic changes — only test files, config, and docs modified
  • Security scan clean — no secrets, no vulnerabilities

qasim-nylas and others added 9 commits March 6, 2026 19:46
…linting and tests

- Add .golangci.yml (v2) with security, style, and bug linters
- Add gofmt check and govulncheck to CI pipeline
- Wire auto-format hook for Write tool in settings.json
- Replace interface{} with any across 31 test files
- Replace sort.Slice with slices.SortFunc (Go 1.21+)
- Split oversized test files (audit_hooks 839→4 files, format 659→3 files, gpg encrypt 681→3 files)
- Add new tests: audit commands (34 cases), audit helpers (52 cases), httputil (18 cases)
- Deduplicate .claude/ docs: consolidate credential storage, remove stale references
- Condense HOOKS-CONFIG.md (272→107 lines), README.md (174→133 lines), CLAUDE.md (254→231 lines)
- Remove deprecated generate-crud-command.md

659 insertions, 2982 deletions across 62 files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Pin golangci-lint-action to v2.11.1 (was resolving to v1 which
  rejects v2 config syntax)
- Run gofmt on email_gpg_test.go and test.go (pre-existing formatting
  issues caught by new CI check)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Action v6 does not support golangci-lint v2. Upgrade to v7.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CI was using Go 1.24 which has 5 known stdlib vulnerabilities
(crypto/x509, html/template, net/url, os) that cause govulncheck
to fail. Go 1.26 includes all fixes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hardcoded ANSI color expectations with dynamic offset computation
so TestGetTimezoneColor doesn't break during DST transitions.
@qasim-nylas qasim-nylas merged commit 403565e into main Mar 10, 2026
6 checks passed
@qasim-nylas qasim-nylas deleted the chore/codebase-optimization branch March 10, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants