Skip to content

fix(validation): add missing analytics date range schema - #662

Open
r69shabh wants to merge 2 commits into
databuddy-analytics:stagingfrom
r69shabh:fix/validation-analytics-date-range
Open

fix(validation): add missing analytics date range schema#662
r69shabh wants to merge 2 commits into
databuddy-analytics:stagingfrom
r69shabh:fix/validation-analytics-date-range

Conversation

@r69shabh

@r69shabh r69shabh commented Aug 22, 2026

Copy link
Copy Markdown

Summary

bb15bd61f (feat(mcp): expand public workspace tool contract) added packages/ai/src/ai/mcp/tool-contracts.ts, which imports analyticsDateRangeSchema from @databuddy/validation — but the schema was never added to the package. This breaks the module graph at test time:

SyntaxError: Export named 'analyticsDateRangeSchema' not found in module
'packages/validation/src/index.ts'

This causes an unhandled error in the @databuddy/ai test suite (1 error, tests after it in the affected file fail).

Changes

  • Adds analyticsDateRangeSchema to packages/validation/src/schemas/analytics.ts: optional startDate/endDate ISO date (YYYY-MM-DD) fields with a cross-field refinement that startDate must be on or before endDate (reported as a custom issue, matching what tool-contracts.ts forwards into its own superRefine).

Verification

  • packages/validation: 83 pass
  • packages/ai: 3705 pass, 0 fail (previously crashed on import)

Found while rebasing #642 onto staging.


Summary by cubic

Adds analyticsDateRangeSchema to @databuddy/validation to match the MCP tool contract in @databuddy/ai, fixing import errors and test crashes. Previously, partial ranges (only startDate or only endDate) were accepted and defaulted downstream; now the schema requires both dates or none, validates ISO YYYY-MM-DD, and enforces startDate <= endDate.

  • Migration: If you pass a date range, include both startDate and endDate; otherwise omit both.

Written for commit fb5a3fa. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

@r69shabh is attempting to deploy a commit to the Databuddy OSS Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
vercel Bot temporarily deployed to Preview – documentation August 22, 2026 11:52 Inactive
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 24deb279-f84a-41b5-b94f-c78aed6929c3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
documentation Skipped Skipped Aug 22, 2026 12:48pm

@greptile-apps

greptile-apps Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores the missing analyticsDateRangeSchema export required by the AI MCP tool contract.

  • Adds strict ISO YYYY-MM-DD validation for optional start and end dates.
  • Adds cross-field validation preventing a start date later than the end date.
  • Partial ranges remain accepted even though downstream analytics procedures silently replace them with a default range.

Confidence Score: 4/5

The PR should not merge until partial date ranges are either rejected or consistently honored downstream, because currently a caller can receive analytics for an unintended default period.

The new schema repairs the package export and correctly validates complete ISO date ranges, but it also accepts single-ended ranges that downstream procedures discard in favor of their default date window.

Files Needing Attention: packages/validation/src/schemas/analytics.ts

Important Files Changed

Filename Overview
packages/validation/src/schemas/analytics.ts Adds the missing date-range schema and ordering refinement, but independently optional endpoints permit partial ranges that downstream consumers silently ignore.

Reviews (1): Last reviewed commit: "fix(validation): add missing analytics d..." | Re-trigger Greptile

Comment on lines +72 to +73
startDate: analyticsDateOnlySchema.optional(),
endDate: analyticsDateOnlySchema.optional(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Partial ranges are silently discarded

When an MCP analytics request supplies only from or only to, this schema accepts the incomplete range, but the downstream procedure requires both endpoints and replaces it with its default seven-day range, returning analytics for dates the caller did not request.

Partial ranges (only startDate or only endDate) were accepted by the
schema but silently replaced with a default range downstream, returning
analytics for dates the caller did not request. Require both endpoints
or neither.
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.

1 participant