Skip to content

Conversation

@SkArchon
Copy link
Contributor

@SkArchon SkArchon commented Dec 16, 2025

This PR does the following

Introduces a limit parameter for schema checks to pass in a limit, we still do use a default limit if a value was not passed in, we also set a max number.

When determining if the limit was exceeded, we treat the following values as one grouping

lintWarnings + lintErrors
breakingChanges + nonBreakingChanges
graphPruneErrors + graphPruneWarnings

We however DO NOT treat compositionErrors and compositionWarnings as one entry because they are displayed in two tables on the CLI at the moment.

However when returning the counts, we return values for every individual attribute, which can be found in the SchemaCheckCounts definition. This includes for example lintWarnings and lintErrors being separate attributes, as they are part of the API, which would be harder to change later if we add lintWarningsAndErrors and want to break it into two values.

The CLI also has a new option for changing the limit with a default value, if there are any truncated entries we mention to the user in the CLI output and ask the user to refer the studio dashboard.

Note: This PR does not introduce pagination to studio.

TODO: Look at Control Panel tests

Summary by CodeRabbit

  • New Features

    • Added a --limit (-l) option to schema check commands (default 50, max 10,000) with input validation.
    • Schema check results now include summarized counts for linting, breaking/non-breaking changes, composition and prune findings.
    • Truncation notices are shown when results exceed the limit, referencing the dashboard for full details.
  • Documentation

    • Added a note on running code generation (make generate) in project docs.

✏️ Tip: You can customize this high-level summary in your review settings.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Walkthrough

Adds a row/entry limit to schema checks: CLI option (-l/--limit) with validation, proto request field, control-plane enforcement and slicing, counts aggregation in responses, CLI truncation messaging, and regenerated protobuf bindings updated accordingly.

Changes

Cohort / File(s) Summary
CLI limit option and validation
cli/src/commands/graph/monograph/commands/check.ts, cli/src/commands/subgraph/commands/check.ts
Add -l, --limit CLI option (default 50) with numeric validation (1..maxLimit); parse/validate early; propagate validated limit to API request payload and to result handler; exit with error on invalid input.
CLI result handling
cli/src/handle-check-result.ts
Extend handleCheckResult(resp, rowLimit) signature; detect when counts exceed rowLimit; append conditional truncation/studio dashboard message to both success and error outputs.
Protocol definitions
proto/wg/cosmo/platform/v1/platform.proto
Add optional int32 limit = 10 to CheckSubgraphSchemaRequest; add SchemaCheckCounts message (8 count fields); add optional SchemaCheckCounts counts = 19 to CheckSubgraphSchemaResponse.
Generated protobuf bindings
connect/src/wg/cosmo/platform/v1/platform_pb.ts
Regenerate TypeScript protobuf bindings to include new limit and counts fields and the SchemaCheckCounts message; many generated message/field additions reflect proto changes.
Control plane service logic
controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts
Introduce defaultRowLimit/maxRowLimit; compute returnLimit from request; use limitCombinedArrays to cap paired arrays; construct counts object aggregating totals; include counts in all response branches (changes public response shape).
Control plane utilities
controlplane/src/core/util.ts
Add limitCombinedArrays utility to distribute a numeric limit across multiple input arrays in priority order; note duplicate declaration appears present.
Documentation
proto/README.md
Add instruction: "To generate the definitions run make generate from the root folder."

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • connect/src/wg/cosmo/platform/v1/platform_pb.ts — inspect generated field numbers/types for proto-to-TS consistency.
    • controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts — validate slicing logic, limits, and that counts is included in every return path.
    • controlplane/src/core/util.ts — remove duplicate limitCombinedArrays if accidental.
    • cli/src/handle-check-result.ts — ensure messaging and signature change are backward-compatible with callers.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically describes the main change: limiting entries shown in schema checks CLI output.
✨ Finishing touches
  • 📝 Generate docstrings

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

@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 65.95745% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.92%. Comparing base (caaf2bd) to head (6a05577).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/handle-check-result.ts 5.55% 17 Missing ⚠️
cli/src/commands/graph/monograph/commands/check.ts 25.00% 6 Missing ⚠️
cli/src/commands/subgraph/commands/check.ts 62.50% 3 Missing ⚠️
...c/core/bufservices/subgraph/checkSubgraphSchema.ts 93.02% 3 Missing ⚠️
controlplane/src/core/util.ts 82.35% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2417       +/-   ##
===========================================
- Coverage   90.55%   35.92%   -54.63%     
===========================================
  Files          16      943      +927     
  Lines        3271   123021   +119750     
  Branches      871     4872     +4001     
===========================================
+ Hits         2962    44200    +41238     
- Misses        309    77265    +76956     
- Partials        0     1556     +1556     
Files with missing lines Coverage Δ
cli/src/commands/subgraph/commands/check.ts 76.74% <62.50%> (ø)
...c/core/bufservices/subgraph/checkSubgraphSchema.ts 58.56% <93.02%> (ø)
controlplane/src/core/util.ts 81.37% <82.35%> (ø)
cli/src/commands/graph/monograph/commands/check.ts 33.33% <25.00%> (ø)
cli/src/handle-check-result.ts 0.72% <5.55%> (ø)

... and 954 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link

github-actions bot commented Dec 16, 2025

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-f09a4f81da9338ed264f6be17d3494310518c8af

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
cli/src/commands/subgraph/commands/check.ts (1)

56-59: Consider extracting common limit validation logic.

The limit validation logic (lines 56-59) is duplicated in cli/src/commands/graph/monograph/commands/check.ts (lines 38-41). Consider extracting this into a shared utility function to follow the DRY principle.

Example shared utility:

// In cli/src/core/validation.ts or similar
export function validateCheckLimit(limit: string, maxLimit: number): number {
  const parsed = Number(limit);
  if (Number.isNaN(parsed) || parsed <= 0 || parsed > maxLimit) {
    program.error(pc.red(`The limit must be a valid number between 1 and ${maxLimit}. Received: '${limit}'`));
  }
  return parsed;
}

Then use it in both check commands:

const limit = validateCheckLimit(options.limit, maxLimit);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc5b022 and 1619b57.

⛔ Files ignored due to path filters (1)
  • connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go is excluded by !**/*.pb.go, !**/gen/**
📒 Files selected for processing (8)
  • cli/src/commands/graph/monograph/commands/check.ts (4 hunks)
  • cli/src/commands/subgraph/commands/check.ts (4 hunks)
  • cli/src/handle-check-result.ts (2 hunks)
  • connect/src/wg/cosmo/platform/v1/platform_pb.ts (5 hunks)
  • controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts (8 hunks)
  • controlplane/src/core/util.ts (1 hunks)
  • proto/README.md (1 hunks)
  • proto/wg/cosmo/platform/v1/platform.proto (2 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: JivusAyrus
Repo: wundergraph/cosmo PR: 2331
File: studio/src/components/operations/client-usage-table.tsx:65-65
Timestamp: 2025-11-19T11:26:26.657Z
Learning: In the Cosmo studio codebase (studio/src/components/operations/client-usage-table.tsx), converting BigInt request counts from the API to Number is acceptable because request counts are not expected to exceed JavaScript's safe integer limit (2^53 - 1).
📚 Learning: 2025-08-29T10:10:06.969Z
Learnt from: JivusAyrus
Repo: wundergraph/cosmo PR: 2156
File: studio/src/pages/[organizationSlug]/[namespace]/graph/[slug]/checks/[checkId]/index.tsx:0-0
Timestamp: 2025-08-29T10:10:06.969Z
Learning: The isCheckSuccessful function in both controlplane/src/core/util.ts and studio/src/components/check-badge-icon.tsx includes early exits for linked check validation. It returns false immediately if either isLinkedTrafficCheckFailed or isLinkedPruningCheckFailed is true, which means linked check failures automatically cause the overall check to fail.

Applied to files:

  • cli/src/handle-check-result.ts
  • controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts
📚 Learning: 2025-09-10T09:59:17.257Z
Learnt from: JivusAyrus
Repo: wundergraph/cosmo PR: 2156
File: controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts:417-419
Timestamp: 2025-09-10T09:59:17.257Z
Learning: When skipTrafficCheck is true in schema checks, the traffic inspection loop is completely bypassed (as shown in line 2040 of SubgraphRepository.ts with the continue statement), which means hasClientTraffic will be false. The traffic analysis doesn't run at all when skipTrafficCheck is true, unlike the previous understanding that it always ran to collect usage data.

Applied to files:

  • cli/src/commands/subgraph/commands/check.ts
📚 Learning: 2025-09-08T20:57:07.946Z
Learnt from: JivusAyrus
Repo: wundergraph/cosmo PR: 2156
File: controlplane/src/core/repositories/SubgraphRepository.ts:1746-1763
Timestamp: 2025-09-08T20:57:07.946Z
Learning: The checkSubgraphSchema.ts file already correctly implements linked subgraph functionality, using byName(linkedSubgraph.name, linkedSubgraph.namespace) to fetch target subgraphs and properly handles parse(newSchemaSDL) for schema building. The implementation doesn't need fixes for byId usage or schema parsing as it's already correct.

Applied to files:

  • controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts
📚 Learning: 2025-08-29T10:28:04.846Z
Learnt from: JivusAyrus
Repo: wundergraph/cosmo PR: 2156
File: controlplane/src/core/repositories/SubgraphRepository.ts:1749-1751
Timestamp: 2025-08-29T10:28:04.846Z
Learning: In the controlplane codebase, authentication and authorization checks (including organization scoping) are handled at the service layer in files like unlinkSubgraph.ts before calling repository methods. Repository methods like unlinkSubgraph() in SubgraphRepository.ts can focus purely on data operations without redundant security checks.

Applied to files:

  • controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts
📚 Learning: 2025-08-31T18:51:32.185Z
Learnt from: JivusAyrus
Repo: wundergraph/cosmo PR: 2156
File: controlplane/src/core/bufservices/check/getCheckSummary.ts:0-0
Timestamp: 2025-08-31T18:51:32.185Z
Learning: In the SchemaCheckRepository.getLinkedSchemaCheck method, organization-level security is implemented through post-query validation by checking `check.subgraphs[0].namespace.organizationId !== organizationId` and returning undefined if the linked check doesn't belong to the caller's organization, preventing cross-tenant data leakage.

Applied to files:

  • controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts
📚 Learning: 2025-09-10T09:52:46.326Z
Learnt from: JivusAyrus
Repo: wundergraph/cosmo PR: 2156
File: controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts:417-419
Timestamp: 2025-09-10T09:52:46.326Z
Learning: When skipTrafficCheck is true in schema checks, traffic analysis still runs to collect usage data, but hasClientTraffic can still be true if unsafe client traffic is detected. The difference is that traffic issues don't cause the overall check to fail, but the hasClientTraffic flag itself remains accurate based on the actual traffic analysis results.

Applied to files:

  • controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts
🧬 Code graph analysis (5)
cli/src/handle-check-result.ts (1)
connect/src/wg/cosmo/platform/v1/platform_pb.ts (1)
  • CheckSubgraphSchemaResponse (2237-2383)
cli/src/commands/subgraph/commands/check.ts (1)
cli/src/handle-check-result.ts (1)
  • handleCheckResult (9-324)
connect/src/wg/cosmo/platform/v1/platform_pb.ts (1)
connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go (3)
  • SchemaCheckCounts (3256-3269)
  • SchemaCheckCounts (3284-3284)
  • SchemaCheckCounts (3299-3301)
controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts (1)
controlplane/src/core/util.ts (2)
  • clamp (578-580)
  • limitCombinedArrays (487-507)
cli/src/commands/graph/monograph/commands/check.ts (1)
cli/src/handle-check-result.ts (1)
  • handleCheckResult (9-324)
🪛 GitHub Actions: wgc CI
cli/src/handle-check-result.ts

[error] 264-264: ESLint: 'eqeqeq' rule violated. Expected '!==' and instead saw '!='.

🪛 GitHub Check: build_test_node_matrix (20.x)
cli/src/handle-check-result.ts

[failure] 264-264:
Expected '!==' and instead saw '!='

🪛 GitHub Check: build_test_node_matrix (22.x)
cli/src/handle-check-result.ts

[failure] 264-264:
Expected '!==' and instead saw '!='

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: build-router
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: integration_test (./events)
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: image_scan (nonroot)
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: build_test
  • GitHub Check: image_scan
  • GitHub Check: build_push_image
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: build_test
  • GitHub Check: build_push_image
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
proto/README.md (1)

5-5: Documentation update is accurate and helpful.

The make generate command is verified in the Makefile, and both output paths (../connect for TypeScript and ../router/gen for Go) are correctly referenced from the proto/ directory. This documentation addition appropriately guides developers to regenerate protobuf bindings when proto definitions change, which is timely given the new proto fields (limit, counts, SchemaCheckCounts) added in this PR.

cli/src/commands/subgraph/commands/check.ts (1)

13-14: LGTM! Limit configuration is well-defined.

The maximum limit of 10,000 and default of 50 provide reasonable bounds for schema check output. The implementation correctly integrates with the existing CLI option pattern.

Also applies to: 36-36

cli/src/handle-check-result.ts (1)

9-9: Good implementation of row limiting with user feedback.

The addition of the rowLimit parameter and truncation messaging provides users with clear feedback when results are limited. The logic correctly evaluates grouped counts and provides helpful guidance to view full results in the studio dashboard.

Note: This approval is contingent on fixing the != vs !== issue on Line 264.

Also applies to: 252-268, 277-277, 285-285

proto/wg/cosmo/platform/v1/platform.proto (1)

106-106: LGTM! Protocol buffer definitions are well-structured.

The new limit field and SchemaCheckCounts message properly extend the schema check API with count metadata. The field numbers are properly assigned and types are appropriate for their purposes.

Also applies to: 288-300

controlplane/src/core/bufservices/subgraph/checkSubgraphSchema.ts (3)

255-255: Verify limit defaults and maximum values are aligned.

There's a discrepancy between the CLI and backend limit constraints:

  • CLI default: 50, max: 10,000
  • Backend default: 1, max: 100,000

This means the backend would accept limits up to 100,000 even though the CLI caps at 10,000. Consider whether these values should be aligned, or if the backend intentionally allows a higher maximum for other API clients.

Additionally, a default of 1 when no limit is provided seems quite restrictive. Was this intentional, or should it match the CLI default of 50?


291-307: LGTM! Array limiting logic correctly implements grouped behavior.

The implementation correctly applies limits:

  • Composition errors and warnings are limited separately (they appear in separate CLI tables)
  • Breaking/non-breaking changes are grouped (limited together with priority to breaking)
  • Lint errors/warnings are grouped (limited together with priority to errors)
  • Graph prune errors/warnings are grouped (limited together with priority to errors)

This matches the PR objectives and provides sensible prioritization when limits are exceeded.


310-319: LGTM! Counts object correctly tracks original result sizes.

The counts object properly captures the total counts from checkResult before any slicing occurs. This ensures that clients can detect when results have been truncated by comparing counts with the actual array lengths in the response.

connect/src/wg/cosmo/platform/v1/platform_pb.ts (1)

1102-1105: LGTM! Generated protobuf code correctly implements the schema check limit and counts.

The changes add:

  • Optional limit field to CheckSubgraphSchemaRequest for controlling result set size
  • Optional counts field to CheckSubgraphSchemaResponse for returning total counts
  • New SchemaCheckCounts message with 8 count fields matching the Go counterpart

Field numbers are consistent across TypeScript and Go implementations, and all structures follow standard protobuf-ts patterns.

Also applies to: 1124-1124, 2334-2337, 2365-2365, 2385-2462

@SkArchon SkArchon changed the title fix: Limit the number of entries shown in the table for schema checks on the cli fix: limit the number of entries shown in the table for schema checks on the cli Dec 16, 2025
isCheckExtensionSkipped,
checkExtensionErrorMessage,
} = await subgraphRepo.performSchemaCheck({
const returnLimit = clamp(req.limit ?? defaultRowLimit, 1, maxRowLimit);
Copy link
Member

Choose a reason for hiding this comment

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

i feel if the limit is not passed, return everything

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added Stale and removed Stale labels Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants