Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default-specs.js validation params #8924

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Conversation

klakhov
Copy link
Contributor

@klakhov klakhov commented Jan 10, 2025

Motivation and context

Updated default specs file with params as some of them are not present

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • [] I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Enhanced validation parameter handling in task specification process
    • Added new checks for frame-related validation parameters
  • Tests

    • Updated default task specification function to improve parameter validation logic

@klakhov klakhov added the tests label Jan 10, 2025
@klakhov klakhov requested a review from azhavoro January 10, 2025 11:15
Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Important

Review skipped

Auto incremental 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.

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

Walkthrough

The changes focus on the defaultTaskSpec function in the Cypress support file, specifically modifying how validation parameters are processed. The function's logic for handling validation parameters has been restructured, introducing new checks for additional fields like frameShare, framesPerJobCount, and framesPerJobShare. The reorganization involves repositioning existing checks and adding new validation parameter assessments while maintaining the core functionality of parameter processing.

Changes

File Change Summary
tests/cypress/support/default-specs.js Restructured defaultTaskSpec function with enhanced validation parameter handling

Poem

🐰 Validation's dance, a code ballet so neat
Parameters shuffled, now more complete
New checks hop in with graceful might
Frames and seeds aligned just right
A rabbit's logic, precise and bright! 🔍


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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

🔭 Outside diff range comments (1)
tests/cypress/support/default-specs.js (1)

Add test coverage for new validation parameters

The following validation parameters lack test coverage:

  • frameShare
  • framesPerJobCount
  • framesPerJobShare

Please add test cases in tests/cypress/e2e/features/ground_truth_jobs.js to verify these parameters, following the existing test structure in the "Testing creating task with quality params" describe block.

🔗 Analysis chain

Line range hint 1-85: Verify test coverage for new validation parameters.

The PR objectives indicate that tests haven't been addressed. Let's verify the test coverage for the new validation parameters:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests using the new validation parameters
rg -l "frameShare|framesPerJobCount|framesPerJobShare" --type js tests/cypress/e2e/

Length of output: 85


Script:

#!/bin/bash
# Search for validation-related tests more broadly
rg -l "validation.*params|validationParams" --type js tests/

# Search for any test files containing "validation" to ensure we don't miss anything
rg -l "validation" --type js tests/

Length of output: 481


Script:

#!/bin/bash
# Check content of ground truth jobs test file
cat tests/cypress/e2e/features/ground_truth_jobs.js

# Also search for specific usage of validation parameters in this file
rg "validationParams" -A 5 -B 5 tests/cypress/e2e/features/ground_truth_jobs.js

Length of output: 17658

🧹 Nitpick comments (3)
tests/cypress/support/default-specs.js (3)

46-57: Add parameter validation and documentation.

While the parameter processing is consistent, there's no validation of the parameter values or documentation about their constraints. Consider:

  1. Adding JSDoc comments describing each parameter's purpose, constraints, and valid values
  2. Adding runtime validation for critical parameters

Example improvement:

/**
 * @typedef {Object} ValidationParams
 * @property {'gt_pool'|'expert_pool'} mode - The validation mode
 * @property {number} [randomSeed] - Seed for random frame selection
 * @property {number[]} [frames] - Specific frames to validate
 * ...
 */

// Add parameter validation
if (validationParams.mode && !['gt_pool', 'expert_pool'].includes(validationParams.mode)) {
    throw new Error('Invalid validation mode');
}

Line range hint 5-13: Add TypeScript or JSDoc type definitions.

The function lacks type definitions which could help prevent runtime errors and improve maintainability. Consider:

  1. Adding TypeScript types or JSDoc type definitions
  2. Providing default values for optional parameters

Example improvement:

/**
 * Creates a default task specification for testing.
 * @param {Object} params - The task parameters
 * @param {string} params.labelName - The name of the label
 * @param {string} [params.labelType='any'] - The type of the label
 * @param {string} params.taskName - The name of the task
 * @param {string[]} params.serverFiles - Array of server file paths
 * @param {number} [params.startFrame] - Starting frame number
 * @param {string} [params.frameFilter] - Frame filter expression
 * @param {number} [params.segmentSize] - Size of each segment
 * @param {ValidationParams} [params.validationParams] - Validation parameters
 * @returns {Object} The task specification object
 */

Line range hint 23-31: Extract sorting method logic to a separate function.

The sorting method determination is embedded in the dataSpec object. Consider extracting this logic to improve readability and testability:

function determineSortingMethod(validationParams) {
    return (validationParams?.mode === 'gt_pool') ? 'random' : 'lexicographical';
}

const dataSpec = {
    ...
    sorting_method: determineSortingMethod(validationParams),
    ...
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43cc1f3 and 26a6bd2.

📒 Files selected for processing (1)
  • tests/cypress/support/default-specs.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build
  • GitHub Check: generate_github_pages
  • GitHub Check: testing
  • GitHub Check: Analyze (python)
  • GitHub Check: Linter
  • GitHub Check: Analyze (javascript)

Comment on lines +61 to +68
if (validationParams.frameShare) {
convertedParams.frame_share = validationParams.frameShare;
}
if (validationParams.framesPerJobCount) {
convertedParams.frames_per_job_count = validationParams.framesPerJobCount;
}
if (validationParams.mode) {
convertedParams.mode = validationParams.mode;
}
if (validationParams.randomSeed) {
convertedParams.random_seed = validationParams.randomSeed;
if (validationParams.framesPerJobShare) {
convertedParams.frames_per_job_share = validationParams.framesPerJobShare;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Parameters are mutually exclusive based on frame selection method

Based on the API schema, these parameters should be used as follows:

  • For random uniform selection: use either frameShare (percentage) or frameCount (absolute)
  • For random per-job selection: use either framesPerJobShare (percentage) or framesPerJobCount (absolute)
  • Never combine percentage-based parameters with count-based parameters
🔗 Analysis chain

Consider mutual exclusivity of parameters.

The new parameters frameShare, framesPerJobCount, and framesPerJobShare might be mutually exclusive. Consider:

  1. Adding validation to prevent conflicting parameter combinations
  2. Documenting which parameters can be used together

Let's verify the parameter usage in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for examples of validation parameter usage to understand valid combinations
rg -A 5 "validation_params.*frame" --type js

Length of output: 46


Script:

#!/bin/bash
# Search for any usage of these parameters in both camelCase and snake_case forms
rg -i "frameShare|frame_share" --type js
rg -i "framesPerJobCount|frames_per_job_count" --type js
rg -i "framesPerJobShare|frames_per_job_share" --type js

# Search for test cases or specs that might demonstrate parameter combinations
fd -e spec.js -e test.js -e cy.js -X rg -l "frame"

# Look for validation logic
ast-grep --pattern 'if ($PARAM) { $$$_BODY }'  tests/cypress/support/default-specs.js

Length of output: 3895


Script:

#!/bin/bash
# Search for documentation about these parameters
fd -e md -X rg -l "frame.*share|frames.*job"

# Look for any configuration or schema files that might define parameter relationships
fd -e json -e yaml -e yml -X rg -l "frame.*share|frames.*job"

# Search for test cases that might show parameter combinations
rg -B 5 -A 5 "validation_params.*=.*{" --type js

Length of output: 1515


Script:

#!/bin/bash
# Check schema file for parameter definitions
cat cvat/schema.yml

# Look for test examples with correct syntax
rg -B 5 -A 5 "validation_params.*=" --type js

# Check specific documentation files that might be relevant
cat site/content/en/docs/api_sdk/cli/_index.md
cat site/content/en/docs/manual/advanced/specification.md

Length of output: 65804

@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.83%. Comparing base (411f8e7) to head (ca725af).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8924      +/-   ##
===========================================
- Coverage    73.84%   73.83%   -0.02%     
===========================================
  Files          412      412              
  Lines        44261    44261              
  Branches      3993     3993              
===========================================
- Hits         32686    32680       -6     
- Misses       11575    11581       +6     
Components Coverage Δ
cvat-ui 78.38% <ø> (-0.03%) ⬇️
cvat-server 69.97% <ø> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants