Skip to content

Add comprehensive test coverage for API and Data protocol schemas#427

Merged
hotlong merged 4 commits into
mainfrom
copilot/update-api-test-cases
Jan 31, 2026
Merged

Add comprehensive test coverage for API and Data protocol schemas#427
hotlong merged 4 commits into
mainfrom
copilot/update-api-test-cases

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

Overview

Adds test coverage for 7 previously untested protocol schemas in packages/spec/src. Total: 344 new tests across API and Data protocols.

Changes

API Protocol Tests (242 tests)

  • odata.test.ts (64 tests) - OData v4 query syntax, filters, operators, response/error formats, metadata
  • protocol.test.ts (50 tests) - ObjectStack RPC protocol: discovery, metadata, CRUD, batch operations
  • router.test.ts (40 tests) - Route definitions, categories, CORS, security, static mounts
  • rest-server.test.ts (42 tests) - REST API config, CRUD endpoints, metadata/batch endpoint generation
  • view-storage.test.ts (46 tests) - Saved views (list/kanban/calendar/chart), layouts, CRUD contracts

Data Protocol Tests (102 tests)

  • hook.test.ts (45 tests) - Hook lifecycle events, execution order, async/sync modes, error policies
  • data-engine.test.ts (57 tests) - Query/insert/update/delete options, aggregations, vector search, batch operations

Example

// Before: No test coverage for OData schema
// After: Comprehensive validation of query parameters and helper functions

describe('ODataQuerySchema', () => {
  it('should build complex queries', () => {
    const query = ODataQuerySchema.parse({
      $select: ['name', 'email'],
      $filter: "country eq 'US' and revenue gt 100000",
      $orderby: 'revenue desc',
      $top: 10,
      $expand: ['orders'],
      $count: true,
    });
    
    const url = OData.buildUrl('/api/customers', query);
    // Validates URL encoding and parameter handling
  });
});

All tests follow existing Zod validation patterns and cover success/error cases, defaults, edge cases, and real-world integration scenarios.

Original prompt

完善objects ,API相关的测试用例


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 31, 2026

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

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jan 31, 2026 4:22am

Request Review

Copilot AI and others added 3 commits January 31, 2026 04:15
…t-server)

Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

This PR is very large. Consider breaking it into smaller PRs for easier review.

Copilot AI changed the title [WIP] 完善 API 相关的测试用例 Add comprehensive test coverage for API and Data protocol schemas Jan 31, 2026
Copilot AI requested a review from xuyushun441-sys January 31, 2026 04:23
});

// Get items
const itemsRequest = GetMetaItemsRequestSchema.parse({

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused variable itemsRequest.

Copilot Autofix

AI 4 months ago

To fix the problem, we should remove the unused variable while still preserving any needed side effects from calling GetMetaItemsRequestSchema.parse. The simplest way is to call parse without assigning its return value, or, if we want to assert something about the parsed data, actually use the variable in an expectation.

The minimal, behavior-preserving change is to drop the const itemsRequest = binding and keep the parse call as a standalone statement. This maintains the validation side effect (throwing on invalid input) but eliminates the unused variable. The change is localized to packages/spec/src/api/protocol.test.ts around line 623, inside the "should support metadata discovery workflow" test. No new imports or definitions are needed.

Suggested changeset 1
packages/spec/src/api/protocol.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/spec/src/api/protocol.test.ts b/packages/spec/src/api/protocol.test.ts
--- a/packages/spec/src/api/protocol.test.ts
+++ b/packages/spec/src/api/protocol.test.ts
@@ -620,7 +620,7 @@
     });
 
     // Get items
-    const itemsRequest = GetMetaItemsRequestSchema.parse({
+    GetMetaItemsRequestSchema.parse({
       type: 'object',
     });
 
EOF
@@ -620,7 +620,7 @@
});

// Get items
const itemsRequest = GetMetaItemsRequestSchema.parse({
GetMetaItemsRequestSchema.parse({
type: 'object',
});

Copilot is powered by AI and may make mistakes. Always verify output.
@hotlong hotlong marked this pull request as ready for review January 31, 2026 04:26
Copilot AI review requested due to automatic review settings January 31, 2026 04:26
@hotlong hotlong merged commit 7c553ce into main Jan 31, 2026
9 of 10 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive test coverage for 7 previously untested protocol schemas in the packages/spec repository. The changes include 344 new tests organized into:

Changes:

  • API Protocol Tests (242 tests): OData v4 query syntax, ObjectStack RPC protocol, routing, REST API configuration, and saved views
  • Data Protocol Tests (102 tests): Hook lifecycle events and data engine query/CRUD operations
  • All tests follow Zod validation patterns with comprehensive coverage of success cases, error cases, defaults, and edge cases

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/spec/src/api/odata.test.ts 64 tests validating OData v4 query parameters, filter operators, functions, response/error formats, and metadata schemas
packages/spec/src/api/protocol.test.ts 50 tests covering ObjectStack RPC protocol discovery, metadata endpoints, CRUD operations, and batch operations
packages/spec/src/api/router.test.ts 40 tests for route definitions, HTTP methods, path patterns, security, CORS, and routing configuration
packages/spec/src/api/rest-server.test.ts 42 tests validating REST API config including CRUD endpoints, metadata, batch operations, and documentation settings
packages/spec/src/api/view-storage.test.ts 46 tests for saved views (list/kanban/calendar/chart), layouts, visibility, and CRUD contracts
packages/spec/src/data/hook.test.ts 45 tests covering hook lifecycle events, execution order, async/sync modes, error policies, and context schemas
packages/spec/src/data/data-engine.test.ts 57 tests for data engine query options, filters, sorting, CRUD operations, aggregations, vector search, and batch requests


describe('HTTP Methods', () => {
it('should accept all HTTP methods', () => {
const methods: Array<z.infer<typeof HttpMethod>> = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The variable z is used but not imported from 'zod'. The line uses Array<z.infer<typeof HttpMethod>> which will cause a runtime error. Either import z from 'zod', or simply remove the type annotation since TypeScript can infer the type from the array literal.

Copilot uses AI. Check for mistakes.
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.

5 participants