Skip to content

Clean up shared code quality issues - #544

Merged
kentcdodds merged 5 commits into
mainfrom
cursor/code-quality-cleanup-d3a3
Jun 18, 2026
Merged

kentcdodds merged 5 commits into
mainfrom
cursor/code-quality-cleanup-d3a3

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Reuse the scheduled job schedule schema for summary output schema instead of maintaining a duplicate union.
  • Move job_get id alias resolution into the shared jobs capability module and fail fast on malformed schedule variants.
  • Add exhaustive schedule handling to job schedule helpers.
  • Factor repeated Durable Object env binding validation.
  • Extract shared maintenance handler auth/error handling.
  • Extract shared memory JSON string-array parsing.
  • Extract shared secret allow-list parsing and normalization mechanics.
  • Add a shared empty capability input schema and normalize several MCP capability imports.
  • Normalize the generated UI app resource import path.
  • Trim low-signal helper tests to match the repo's testing principles.

Larger follow-up

Testing

  • npx vitest run --project node-unit packages/worker/src/maintenance-handler.node.test.ts packages/worker/src/mcp/secrets/allowed-string-list.node.test.ts packages/worker/src/mcp/memory/service.node.test.ts packages/worker/src/mcp/secrets/service.node.test.ts packages/worker/src/app/handlers/account-secrets.node.test.ts
  • npx vitest run --project node-unit packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts packages/worker/src/jobs/schedule.node.test.ts
  • npm run typecheck
  • npm run validate
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Refactor

    • Consolidated request handling logic for reindex operations
    • Extracted shared utilities for empty input schemas and string-list parsing
    • Centralized job ID resolution and schedule validation helpers
    • Updated import paths for improved code organization
  • Tests

    • Added comprehensive test coverage for maintenance request handling
    • Added validation tests for allowed string lists

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2bb03377-89bf-4321-a7e7-ef6e231ce054

📥 Commits

Reviewing files that changed from the base of the PR and between 7868b00 and ea0e7f0.

📒 Files selected for processing (3)
  • packages/worker/src/maintenance-handler.node.test.ts
  • packages/worker/src/maintenance-handler.ts
  • packages/worker/src/mcp/secrets/allowed-string-list.node.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/worker/src/mcp/secrets/allowed-string-list.node.test.ts
  • packages/worker/src/maintenance-handler.ts

📝 Walkthrough

Walkthrough

Three maintenance handlers (capability, job, memory) have their inlined POST/secret/Bearer-token logic replaced by a new shared handleSecretMaintenanceRequest helper. A parseJsonStringArray utility is extracted for memory modules, and normalizeAllowedStringList/parseAllowedStringList helpers are introduced for MCP secrets. A shared emptyCapabilityInputSchema replaces inline z.object({}) across capability files, relative imports are migrated to #mcp/... aliases, and job schedule switches gain exhaustiveness guards via assertNever helpers.

Changes

Shared Utility Extraction and Refactoring

Layer / File(s) Summary
Shared maintenance handler: module, tests, and consumers
packages/worker/src/maintenance-handler.ts, packages/worker/src/maintenance-handler.node.test.ts, packages/worker/src/capability-maintenance.ts, packages/worker/src/job-maintenance.ts, packages/worker/src/memory-maintenance.ts
Introduces handleSecretMaintenanceRequest with readBearerToken, covering 405/503/401/200/500 response paths in tests, then replaces identical inlined logic in all three maintenance handlers with delegation calls.
Shared parseJsonStringArray: module and consumers
packages/worker/src/mcp/memory/json-string-array.ts, packages/worker/src/mcp/memory/memory-embed.ts, packages/worker/src/mcp/memory/memory-search.ts, packages/worker/src/mcp/memory/service.ts
Extracts parseJsonStringArray into a standalone module; removes three duplicate in-file implementations from memory-embed, memory-search, and service.
Shared allowed-string-list utilities: module, tests, and consumers
packages/worker/src/mcp/secrets/allowed-string-list.ts, packages/worker/src/mcp/secrets/allowed-string-list.node.test.ts, packages/worker/src/mcp/secrets/allowed-hosts.ts, packages/worker/src/mcp/secrets/allowed-packages.ts, packages/worker/src/mcp/secrets/allowed-capabilities.ts
Introduces normalizeAllowedStringList and parseAllowedStringList; tests normalization, deduplication, sorting, and error handling; refactors all three secret-list modules to delegate. Adds stringifyAllowedHosts export.
Shared emptyCapabilityInputSchema and path alias updates
packages/worker/src/mcp/capabilities/types.ts, packages/worker/src/mcp/capabilities/*/...
Adds emptyCapabilityInputSchema to types.ts and replaces inline z.object({}) across email, job, meta, packages, services, and values capability files. Converts relative ../define-domain.ts and ../... imports to #mcp/... aliases in all domain files and kody-official-guide.ts.
Jobs: resolveJobGetId, schedule exhaustiveness, and schema alias
packages/worker/src/mcp/capabilities/jobs/shared.ts, packages/worker/src/mcp/capabilities/jobs/job-get.ts, packages/worker/src/jobs/schedule.ts, packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts
Moves resolveJobGetId to shared.ts, aliases scheduledJobSummarySchema to scheduledJobScheduleSchema, adds assertNeverScheduledJobSchedule and assertNeverJobSchedule for exhaustive switch coverage, standardizes cron error formatting, and tests unhandled schedule type throws.
requiredDurableObjectNamespaceSchema helper in env-schema
packages/worker/src/env-schema.ts
Introduces requiredDurableObjectNamespaceSchema(message) and replaces four repeated inline createSchema blocks for JOB_MANAGER, STORAGE_RUNNER, PACKAGE_REALTIME_SESSION, and PACKAGE_SERVICE_INSTANCE.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • kentcdodds/kody#181: Introduces handleJobReindexRequest in job-maintenance.ts with the inlined secret/Bearer logic that this PR replaces with handleSecretMaintenanceRequest.
  • kentcdodds/kody#444: Introduces meta_get_current_user capability in meta-get-current-user.ts, whose inputSchema is refactored in this PR to use emptyCapabilityInputSchema.

Poem

🐇 Hop, hop — no more copy-paste!
A shared handler trims the waste,
parseJsonStringArray now stands alone,
emptyCapabilityInputSchema finds its home.
assertNever guards each switch with care —
One rabbit, tidy code everywhere! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the PR's main objective of consolidating duplicated code and extracting shared utilities across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/code-quality-cleanup-d3a3

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.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@cursor cursor Bot changed the title Clean up small code quality issues Clean up shared code quality issues Jun 18, 2026
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds marked this pull request as ready for review June 18, 2026 16:40
@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-544.kentcdodds.workers.dev

Worker: kody-pr-544
D1: kody-pr-544-db
KV: kody-pr-544-oauth-kv

Mocks:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/worker/src/mcp/capabilities/jobs/shared.ts`:
- Around line 394-395: The exhaustiveness check using the never type assignment
for the `exhaustive` variable enforces compile-time safety, but the code then
returns this variable, which allows invalid `schedule` objects to pass through
at runtime. Instead of returning `exhaustive`, throw an error to fail fast when
malformed data reaches this code path. Apply this change to both occurrences
(around lines 394-395 and 418-419) by replacing the return statement with a
throw statement that includes a descriptive error message about the unexpected
schedule value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6bdcf1d0-fb02-42d0-85c0-6d828a6c5369

📥 Commits

Reviewing files that changed from the base of the PR and between dd656d0 and 28cae1d.

📒 Files selected for processing (35)
  • packages/worker/src/capability-maintenance.ts
  • packages/worker/src/env-schema.ts
  • packages/worker/src/job-maintenance.ts
  • packages/worker/src/jobs/schedule.ts
  • packages/worker/src/maintenance-handler.node.test.ts
  • packages/worker/src/maintenance-handler.ts
  • packages/worker/src/mcp/capabilities/apps/domain.ts
  • packages/worker/src/mcp/capabilities/coding/domain.ts
  • packages/worker/src/mcp/capabilities/coding/kody-official-guide.ts
  • packages/worker/src/mcp/capabilities/email/email-inbox-list.ts
  • packages/worker/src/mcp/capabilities/jobs/domain.ts
  • packages/worker/src/mcp/capabilities/jobs/job-get.ts
  • packages/worker/src/mcp/capabilities/jobs/job-list.ts
  • packages/worker/src/mcp/capabilities/jobs/shared.ts
  • packages/worker/src/mcp/capabilities/meta/domain.ts
  • packages/worker/src/mcp/capabilities/meta/meta-get-current-user.ts
  • packages/worker/src/mcp/capabilities/meta/meta-get-mcp-server-instructions.ts
  • packages/worker/src/mcp/capabilities/meta/meta-list-remote-connector-status.ts
  • packages/worker/src/mcp/capabilities/packages/domain.ts
  • packages/worker/src/mcp/capabilities/packages/list-packages.ts
  • packages/worker/src/mcp/capabilities/services/domain.ts
  • packages/worker/src/mcp/capabilities/types.ts
  • packages/worker/src/mcp/capabilities/values/integration-list.ts
  • packages/worker/src/mcp/memory/json-string-array.node.test.ts
  • packages/worker/src/mcp/memory/json-string-array.ts
  • packages/worker/src/mcp/memory/memory-embed.ts
  • packages/worker/src/mcp/memory/memory-search.ts
  • packages/worker/src/mcp/memory/service.ts
  • packages/worker/src/mcp/resources/generated-ui-app-resource.ts
  • packages/worker/src/mcp/secrets/allowed-capabilities.ts
  • packages/worker/src/mcp/secrets/allowed-hosts.ts
  • packages/worker/src/mcp/secrets/allowed-packages.ts
  • packages/worker/src/mcp/secrets/allowed-string-list.node.test.ts
  • packages/worker/src/mcp/secrets/allowed-string-list.ts
  • packages/worker/src/memory-maintenance.ts

Comment thread packages/worker/src/mcp/capabilities/jobs/shared.ts Outdated
cursoragent and others added 2 commits June 18, 2026 16:48
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds merged commit eab06ea into main Jun 18, 2026
5 checks passed
@kentcdodds
kentcdodds deleted the cursor/code-quality-cleanup-d3a3 branch June 18, 2026 18:26
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