Skip to content

fix(types): derive every PageType list from the canonical enum - #2215

Merged
2witstudios merged 2 commits into
masterfrom
pu/issue-2150
Jul 23, 2026
Merged

2witstudios merged 2 commits into
masterfrom
pu/issue-2150

Conversation

@2witstudios

@2witstudios 2witstudios commented Jul 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

PageType (packages/lib/src/utils/enums.ts) has 10 members. Five separate hand-written re-declarations of that list had drifted, silently dropping FILE and/or MACHINE:

  • apps/web/.../search/glob/route.ts VALID_PAGE_TYPES (8/10) — an includeTypes=FILE request degraded to an empty filter, and globSearchPages treats an empty filter as "no filter", so the caller silently got every page instead of just files.
  • The AI glob_search tool's z.enum([...]) (8/10) — agents requesting FILE/MACHINE were rejected by zod before execute() ever ran.
  • page-service.ts's PageType union (9/10, missing FILE).
  • packages/sdk's GLOB_SEARCH_PAGE_TYPES (8/10) — same bug for SDK/CLI callers.
  • useBreadcrumbs.ts / get-page-breadcrumb-trail.ts unions (9/10, missing MACHINE — type-only drift, no runtime symptom).

Also fixed two stale prose lists: the create_page tool description (now interpolates from getCreatablePageTypes()/getPageTypeConfig() so it can't drift from its own schema again) and the marketing CLI docs page (was missing MACHINE).

Changes

  • New in packages/lib/src/utils/enums.ts: PageTypeValue, PAGE_TYPE_VALUES, isPageTypeValue, and parsePageTypesParam (the includeTypes query-param parser — now trims, drops empty segments, and dedupes; unknown values are still silently dropped, preserving prior behavior).
  • Every site above now derives from the enum instead of hand-listing members.
  • The SDK keeps an inlined literal list (a published SDK .d.ts can't reference the unpublished @pagespace/lib package), but is pinned to the canonical list by a compile-time AssertExact drift-guard test, same pattern as the existing roles-pageperm-drift-guard.test.ts.
  • New drift-guard tests: packages/lib/src/utils/__tests__/enums.test.ts (also pins lib against the DB pgEnum), apps/web/src/services/api/__tests__/page-type-drift-guard.test.ts, packages/sdk/src/operations/__tests__/glob-page-types-drift-guard.test.ts.

Test plan

  • bun --cwd packages/lib test src/utils/__tests__/enums.test.ts — 20 tests pass, including 100%-branch coverage of the parser and the DB-pgEnum drift guard.
  • bun --cwd packages/sdk test src/operations/__tests__ — 522 tests pass, including the new SDK drift guard.
  • bun --cwd apps/web test src/app/api/drives src/lib/ai/tools src/services/api — 2725 tests pass (1 unrelated pre-existing failure in activity-tools.test.ts from a local DB-role env issue, untouched by this change).
  • bun run typecheck — clean (drift guards would fail tsc here if lib/db/sdk/page-service lists ever diverge again).
  • bun run lint — clean (14/14 tasks, including next build).
  • bun run changelog:generate — fails in this worktree with ERR_MODULE_NOT_FOUND on scripts/changelog/index.ts; this is the known pre-existing staleness tracked in chore: remove stale docs/ and prune cross-references #1044, not something this PR introduces.

Closes #2150

https://claude.ai/code/session_01GC414LHWsWNYAh4qHsNVhF

Summary by CodeRabbit

  • New Features

    • Added support for all page types, including FILE and MACHINE, in glob search filters.
    • Improved parsing of page-type filters, including whitespace handling and duplicate removal.
    • Updated SDK validation to recognize the complete set of supported page types.
    • Enhanced AI page-creation guidance to reflect supported page types accurately.
  • Documentation

    • Updated CLI documentation to list MACHINE as a supported page type.
  • Bug Fixes

    • Fixed page-type inconsistencies across search, breadcrumbs, and API services.

PageType (packages/lib/src/utils/enums.ts) has 10 members. Several
consumers re-declared that list by hand and had drifted, silently
dropping FILE and MACHINE:

- apps/web glob search route's VALID_PAGE_TYPES (8/10) — an
  includeTypes=FILE request degraded to an empty filter, which
  globSearchPages treats as "no filter", silently returning every page.
- The AI glob_search tool's z.enum([...]) (8/10) — agents requesting
  FILE/MACHINE were rejected by zod before execute() ran.
- page-service.ts's PageType union (9/10, missing FILE).
- packages/sdk's GLOB_SEARCH_PAGE_TYPES (8/10).
- useBreadcrumbs/get-page-breadcrumb-trail unions (9/10, missing MACHINE).
- The create_page tool's prose description and the marketing CLI docs
  page also listed stale/incomplete type lists.

Adds packages/lib/src/utils/enums.ts: PageTypeValue, PAGE_TYPE_VALUES,
isPageTypeValue, and parsePageTypesParam (the includeTypes query-param
parser, now with trimming/dedupe/empty-segment-dropping). Every site
above now derives from this, and compile-time AssertExact drift-guard
tests pin lib against the DB pgEnum, page-service's local alias, and
the SDK's necessarily-inlined list (the SDK can't import @pagespace/lib
at runtime).

Closes #2150
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@2witstudios, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fb58e238-783f-4137-899d-03740ba5054d

📥 Commits

Reviewing files that changed from the base of the PR and between 4ff7d28 and 6de6ebe.

📒 Files selected for processing (1)
  • apps/web/src/lib/ai/tools/__tests__/page-write-tools.test.ts
📝 Walkthrough

Walkthrough

The pull request centralizes page-type values and parsing, adds FILE and MACHINE coverage across search and API typing, aligns SDK and AI tool validation, generates create-page descriptions from configuration, and updates CLI documentation.

Changes

Page-type contract and parsing

Layer / File(s) Summary
Canonical page-type contract
packages/lib/src/utils/enums.ts, packages/lib/src/utils/__tests__/enums.test.ts
Page-type values, validation, comma-separated parsing, deduplication, and database-enum drift checks are centralized and tested.

Search filter propagation

Layer / File(s) Summary
Search filter propagation
apps/web/src/app/api/drives/[driveId]/search/glob/..., apps/web/src/lib/ai/tools/search-tools*, packages/sdk/src/operations/search*
Glob search route, AI tools, and SDK validation use the complete canonical page-type set, including FILE and MACHINE, with regression and drift-guard tests.

Type and description alignment

Layer / File(s) Summary
Type and description alignment
apps/web/src/hooks/useBreadcrumbs.ts, apps/web/src/lib/pages/get-page-breadcrumb-trail.ts, apps/web/src/services/api/..., apps/web/src/lib/ai/tools/page-write-tools*, apps/marketing/src/app/docs/features/cli/page.tsx
Breadcrumb and service types use PageTypeValue; create-page descriptions derive from page-type configuration; CLI documentation lists MACHINE.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

  • #2150 — The changes directly address page-type drift and restore FILE and MACHINE support across search, AI tools, and API typing.

Possibly related PRs

  • 2witstudios/PageSpace#78 — Related AI tool tests are extended for page-type configuration mocks and glob-search validation.
  • 2witstudios/PageSpace#150 — Related changes extend shared PageType handling for additional page types.
  • 2witstudios/PageSpace#822 — Related AI page-creation changes derive accepted types and descriptions from shared page-type configuration.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 clearly and concisely captures the main change: deriving PageType lists from the canonical enum.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pu/issue-2150

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.

…s gloss

The prior test only checked the description contains "Create", which would
pass even if the getCreatablePageTypes()/getPageTypeConfig() interpolation
introduced in the #2150 fix silently produced empty or malformed prose.
Assert each creatable type's name-plus-gloss actually appears.
@2witstudios
2witstudios merged commit bb13b11 into master Jul 23, 2026
11 of 12 checks passed
@2witstudios
2witstudios deleted the pu/issue-2150 branch July 23, 2026 18:22
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.

types: PageType re-declared by hand — glob search and the AI search tool silently drop FILE and MACHINE pages

1 participant