Skip to content

Fix critical bugs and improve robustness across API client and tools - #37

Closed
bstets1 wants to merge 5 commits into
TheEagleByte:mainfrom
bstets1:claude/code-review-tech-debt-IkHae
Closed

bstets1 wants to merge 5 commits into
TheEagleByte:mainfrom
bstets1:claude/code-review-tech-debt-IkHae

Conversation

@bstets1

@bstets1 bstets1 commented Mar 10, 2026 •

Copy link
Copy Markdown

Summary

This PR addresses critical bugs in date/timezone handling, API response parsing, and tool output formatting. It also consolidates type definitions, improves error handling, and adds comprehensive test coverage for the client and config modules.

Key Changes

Critical Bug Fixes

  • Timezone date rollover (1.2): Changed addDays() to use T12:00:00 instead of T00:00:00 to prevent date shifts in negative-offset timezones
  • Missing IDs in responses (1.1): Added id fields to family member categories, lists, and list items output
  • Chores dateEnd logic (1.3): Fixed default dateEnd to be 7 days from provided startDate instead of from today
  • Day-of-week timezone bug (1.4): Updated parseDate() to determine current weekday using configured timezone via Intl.DateTimeFormat

Robustness Improvements

  • Fetch timeout (3.1): Added 30-second timeout to all fetch calls using AbortSignal.timeout()
  • Date/time validation (3.2): Added hour (0-23/1-12), minute (0-59), month (1-12), and day (1-31) range validation in parseTime() and parseDate()
  • Partial name matching (3.3): Fixed findCategoryByName() and findListByName() to prioritize exact matches before falling back to partial .includes() matching
  • Calendar event request format (3.4): Wrapped updateCalendarEvent() body in JSON:API envelope { data: { type, id, attributes } }

Code Quality & Security

  • Removed token logging: Replaced sensitive token prefix logging with generic "Login successful" message
  • Removed dead code: Eliminated unreachable 304 handler and unused auth cache functions
  • Deduplicated BASE_URL: Exported from client.ts and imported in auth.ts
  • Fixed hardcoded version: Now reads from package.json via createRequire()
  • Structured error handling: Updated auth.ts to throw AuthenticationError and SkylightError instead of plain Error

Type Safety & Consolidation

  • Centralized type definitions: Moved meal, avatar, color, and album types from endpoint modules into src/api/types.ts
  • Improved meal sittings: getMealSittings() now returns both sittings and included recipes for easier access
  • Better tool output formatting: Replaced raw Object.entries() dumps with selective, human-readable formatting in calendar, rewards, meals, photos, and misc tools
  • Added missing parameters: Exposed mealCategoryId in update_recipe and categoryIds in update_reward

Test Coverage

  • New client tests: Comprehensive tests for URL building, auth headers, error handling, and 401 retry logic for email/password auth
  • New config tests: Tests for both auth methods, validation, timezone handling, and error cases
  • Enhanced date tests: Added tests for getDateOffsetFrom(), timezone-aware date parsing, and time validation edge cases
  • ParseError tests: Added missing test coverage for ParseError class

Implementation Details

  • getDateOffsetFrom() helper added to support relative date calculations from arbitrary dates
  • Timezone parameter now consistently threaded through parseDate() and getDateOffset() for accurate day-of-week and date calculations
  • Meal sittings endpoint now includes meal_recipe relationship to avoid separate lookups
  • All tool response formatting now uses consistent patterns with explicit field selection and proper JSON stringification for nested objects

https://claude.ai/code/session_01HFK4pdBrGsWHs5YFyEv5SW

Summary by CodeRabbit

  • New Features

    • Recipe data now included with meal sittings for better meal planning visibility.
    • IDs now displayed in lists, items, categories, and members for easier reference.
  • Bug Fixes

    • Improved date and time validation across calendar and chore tools.
    • Enhanced timezone handling for accurate date interpretation.
    • Better error messages for authentication failures.
  • Improvements

    • Calendar events now display in structured format with key details.
    • Search matching prioritizes exact matches before partial matches.
    • API requests now include timeout protection for improved stability.
    • Refined data display formatting for avatars, colors, and photos.

claude added 5 commits March 10, 2026 00:58
Phase 1 - Critical bugs:
- Add missing IDs to family, lists, and list item tool responses
- Fix addDays timezone bug using T12:00:00 instead of T00:00:00
- Fix get_chores dateEnd to default relative to startDate, not today
- Fix day-of-week calculation to use configured timezone via Intl

Phase 2 - Security & dead code:
- Remove token logging from auth.ts
- Remove dead 304 handler from client.ts
- Remove unused auth cache code (cachedAuth, getAuth, clearAuthCache)
- Deduplicate BASE_URL (export from client.ts, import in auth.ts)
- Read version from package.json instead of hardcoding "1.0.0"

Phase 3 - Robustness:
- Add 30s fetch timeout via AbortSignal.timeout
- Add date/time parse validation (hour/minute ranges, month/day ranges)
- Fix partial name matching to prioritize exact matches
- Fix update_calendar_event to use JSON:API envelope format

Phase 4 - Tool response quality:
- Replace Object.entries raw dumps with selective human-readable formatting
- Add missing assignee param to update_reward
- Add missing mealCategoryId param to update_recipe
- Show recipe info in get_meal_sittings output
- Remove redundant ?? defaults after Zod .default()

https://claude.ai/code/session_01HFK4pdBrGsWHs5YFyEv5SW
Phase 5 - Type safety & consistency:
- Consolidate local types from meals/misc/photos into shared types.ts
  with typed attributes instead of bare [key: string]: unknown
- Use AuthenticationError/SkylightError in auth.ts instead of plain Error
- Fix config double-parse: server.ts now uses getConfig() for caching

Phase 6 - Test coverage:
- Add tests/config.test.ts (6 tests) for Zod validation and auth methods
- Add tests/client.test.ts (10 tests) for URL building, auth headers,
  error handling, and 401 retry logic
- Add date/time edge case tests: timezone params, 12:xx AM/PM,
  invalid values, getDateOffsetFrom, invalid YYYY-MM-DD
- Add ParseError tests in errors.test.ts

All 62 tests passing across 4 test files.

https://claude.ai/code/session_01HFK4pdBrGsWHs5YFyEv5SW
@coderabbitai

coderabbitai Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: da7919c3-ac58-430f-9de5-ba41abbe19b6

📥 Commits

Reviewing files that changed from the base of the PR and between c32284e and 638a278.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (25)
  • CODE_REVIEW_REMEDIATION.md
  • src/api/auth.ts
  • src/api/client.ts
  • src/api/endpoints/calendar.ts
  • src/api/endpoints/categories.ts
  • src/api/endpoints/lists.ts
  • src/api/endpoints/meals.ts
  • src/api/endpoints/misc.ts
  • src/api/endpoints/photos.ts
  • src/api/types.ts
  • src/server.ts
  • src/tools/calendar.ts
  • src/tools/chores.ts
  • src/tools/family.ts
  • src/tools/lists.ts
  • src/tools/meals.ts
  • src/tools/misc.ts
  • src/tools/photos.ts
  • src/tools/rewards.ts
  • src/tools/tasks.ts
  • src/utils/dates.ts
  • tests/client.test.ts
  • tests/config.test.ts
  • tests/dates.test.ts
  • tests/errors.test.ts

📝 Walkthrough

Walkthrough

The PR implements a comprehensive code remediation across multiple areas: centralizes type definitions from endpoints into a shared types module, restructures API response handling with JSON:API compliant payloads, improves error handling with structured error types, adds request timeout handling, enhances date/time parsing with validation, and introduces extensive test coverage for client, config, dates, and error handling.

Changes

Cohort / File(s) Summary
Documentation
CODE_REVIEW_REMEDIATION.md
New multi-phase remediation plan documenting fixes across critical bugs, security, robustness, tool response quality, type safety, and test coverage with execution log.
API Core & Authentication
src/api/auth.ts, src/api/client.ts
Switched to imported BASE_URL, added 30-second request timeout, structured error handling with AuthenticationError and SkylightError, removed cached auth helpers (getAuth, clearAuthCache).
API Type Consolidation
src/api/types.ts
Consolidated 19 new types (Meal/Avatar/Color/Album domain interfaces and responses) previously scattered across endpoint files.
API Endpoints - Types Moved
src/api/endpoints/meals.ts, src/api/endpoints/misc.ts, src/api/endpoints/photos.ts
Removed local type declarations and imported from central types.ts; meals endpoint now returns object with sittings and recipes, changed signature to Promise<GetMealSittingsResult>.
API Endpoints - Matching Logic
src/api/endpoints/categories.ts, src/api/endpoints/lists.ts
Enhanced name matching with two-step approach: exact case-insensitive match first, fall back to partial substring match.
API Endpoints - Other
src/api/endpoints/calendar.ts
Changed addDays to use "T12:00:00" instead of "T00:00:00" for date handling; wrapped updateCalendarEvent payload in JSON:API structure.
Server Configuration
src/server.ts
Replaced loadConfig with getConfig (caches config), resolved package version dynamically from package.json instead of hardcoded "1.0.0".
Tools - Output Formatting
src/tools/calendar.ts, src/tools/misc.ts, src/tools/photos.ts
Replaced generic key-value attribute iteration with structured, explicit field rendering (title/location for events, name/URL for avatars, name/count for albums).
Tools - Enhanced Data
src/tools/meals.ts, src/tools/rewards.ts
Added recipe lookup/attachment in meal sittings, extended mealCategoryId and assignee parameters for meal/reward operations, restructured display output.
Tools - ID Display & Minor Updates
src/tools/family.ts, src/tools/lists.ts
Appended IDs to category, member, list, and item labels; updated references from getDateOffset to getDateOffsetFrom in chores.
Tools - Task Handling
src/tools/tasks.ts
Removed default false assignment for routine flag; now passes routine as-is to allow schema defaults.
Date & Time Utilities
src/utils/dates.ts
Added getDateOffsetFrom function, enhanced parseDate with ISO format validation (regex check, month/day bounds), improved parseTime validation for 24-hour (0–23, 0–59) and 12-hour (1–12, 0–59) formats.
Test Coverage
tests/client.test.ts, tests/config.test.ts, tests/dates.test.ts, tests/errors.test.ts
Added 426 lines of new tests covering client URL/auth/error handling, config loading with env vars, date offset/timezone behaviors, and ParseError formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 Hop through the code, refactoring with care,
Types consolidated, no duplication spare,
With timeouts and validation so tight,
And structured responses, output just right,
The remediation makes everything flow,
A cleaner codebase, watch it now grow! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bstets1 bstets1 closed this Mar 10, 2026
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