Skip to content

[INS 326] Fix active contributors tests#137

Merged
borfast merged 1 commit intomainfrom
improvement/ins-326-fix-active-contributors-tests
Mar 27, 2025
Merged

[INS 326] Fix active contributors tests#137
borfast merged 1 commit intomainfrom
improvement/ins-326-fix-active-contributors-tests

Conversation

@borfast
Copy link
Copy Markdown
Contributor

@borfast borfast commented Mar 26, 2025

This fixes the tests for the Active Contributors data source.

It just takes care of the most basic test. The goal is simply to have a basic security harness so we can refactor things without fear of breaking stuff.

Summary by CodeRabbit

  • New Features
    • Contributor analytics now display monthly data, offering a more consistent and clear view of performance trends.
  • Tests
    • Robust validations have been enhanced to ensure the accuracy and reliability of contributor metrics across reporting interfaces.

@borfast borfast added the feature New feature or request label Mar 26, 2025
@borfast borfast self-assigned this Mar 26, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2025

Walkthrough

This pull request refactors the tests for the Active Contributors Data Source and updates the associated mock data. The test file now uses a structured describe block and mocks the fetchFromTinybird function to simulate data retrieval. The mock file replaces weekly granularity data with monthly data, introducing new exports for monthly timeseries, current summary, and previous summary while removing outdated weekly mocks. No changes to public APIs or exported entities were made.

Changes

File Summary of Changes
frontend/server/data/tinybird/active-contributors-data-source.test.ts Refactored test cases by removing the placeholder test and adding a structured describe block. Introduced a mock function (mockFetchFromTinybird) with vi.doMock to simulate the Tinybird fetch, and added a detailed test case validating the fetchActiveContributors logic.
frontend/server/mocks/tinybird-active-contributors-response.mock.ts Updated the mock data structure from weekly to monthly granularity. Added new exports: mockMonthlyTimeseries, mockCurrentMonthlySummary, and mockPreviousMonthlySummary, and removed previous weekly mocks (mockWeeklyTimeseries, mockWeeklyCurrentSummary, mockWeeklyPreviousSummary).

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant FAC as fetchActiveContributors
    participant M as Mocked fetchFromTinybird

    T->>FAC: Call fetchActiveContributors(filter)
    FAC->>M: Invoke fetchFromTinybird(params)
    M-->>FAC: Return mock data (current & previous summaries, monthly timeseries)
    FAC-->>T: Return processed active contributors data
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@borfast borfast requested review from emlimlf and gaspergrom March 26, 2025 15:07
@borfast borfast force-pushed the improvement/add-github-action-for-tests branch from 8325e68 to 6c99d03 Compare March 27, 2025 11:29
Base automatically changed from improvement/add-github-action-for-tests to main March 27, 2025 11:30
Signed-off-by: Raúl Santos <4837+borfast@users.noreply.github.com>
@borfast borfast force-pushed the improvement/ins-326-fix-active-contributors-tests branch from e7deb4c to 05dc9aa Compare March 27, 2025 16:05
@borfast borfast merged commit f88a04d into main Mar 27, 2025
3 of 4 checks passed
@borfast borfast deleted the improvement/ins-326-fix-active-contributors-tests branch March 27, 2025 16:06
Copy link
Copy Markdown

@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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4e2ebc and 05dc9aa.

📒 Files selected for processing (2)
  • frontend/server/data/tinybird/active-contributors-data-source.test.ts (1 hunks)
  • frontend/server/mocks/tinybird-active-contributors-response.mock.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
frontend/server/data/tinybird/active-contributors-data-source.test.ts (1)
Learnt from: borfast
PR: LF-Engineering/insights#76
File: frontend/server/data/tinybird/active-contributors-data-source.test.ts:10-10
Timestamp: 2025-03-27T11:19:30.505Z
Learning: The tests in the frontend/server/data/tinybird directory became broken due to changes introduced in another branch and will need to be revisited later as part of the data sources refactoring.
🧬 Code Definitions (1)
frontend/server/data/tinybird/active-contributors-data-source.test.ts (2)
frontend/server/mocks/tinybird-active-contributors-response.mock.ts (3)
  • mockCurrentMonthlySummary (95-119)
  • mockPreviousMonthlySummary (122-146)
  • mockMonthlyTimeseries (4-92)
frontend/server/data/tinybird/active-contributors-data-source.ts (2)
  • fetchActiveContributors (43-112)
  • ActiveContributorsResponse (21-31)
🔇 Additional comments (7)
frontend/server/data/tinybird/active-contributors-data-source.test.ts (4)

1-12: Well-structured imports and type declarations.

Good organization of imports, separating test utilities, external libraries, and project-specific imports for better readability.


13-26: Excellent implementation of mocking setup with helpful documentation.

The mock setup is well-structured with clear documentation about the challenges of vi.doMock not being hoisted. This comment is particularly valuable for future maintainers who might not be familiar with this Vitest behavior.


28-70: Comprehensive test implementation with proper assertions.

The test effectively:

  1. Imports the module after mocking to ensure the mock is applied
  2. Configures the mock to return expected values for each call
  3. Sets up realistic test parameters
  4. Verifies the transformation logic matches the implementation

This approach properly isolates the test from external dependencies, making it more reliable and faster.


72-73: Good recognition of needed test coverage improvements.

The TODO comment correctly identifies important edge cases that should be tested in the future, such as invalid dates, invalid data, and SQL injections. This helps establish a roadmap for improving test coverage.

Consider creating separate tickets for implementing these additional tests to ensure they're not forgotten.

frontend/server/mocks/tinybird-active-contributors-response.mock.ts (3)

2-92: Comprehensive monthly data mock with proper structure and realistic values.

The monthly timeseries mock data is well-structured with:

  1. Appropriate meta section defining field types
  2. Realistic data spanning March 2024 to March 2025
  3. Proper format matching the API response

This provides a solid foundation for testing the active contributors functionality.


94-119: Appropriate current monthly summary mock.

The mock properly reflects the current month's summary data with realistic statistics and contributor count. The URL comment provides helpful context about the API endpoint being mocked.


121-146: Well-structured previous monthly summary mock.

This new mock provides the necessary data for calculating percentage changes in the tests. The structure matches the API response format and includes realistic values for contributor count and statistics.

Comment on lines +39 to +44
const filter = {
granularity: FilterGranularity.WEEKLY,
project: 'the-linux-kernel-organization',
startDate,
endDate
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify granularity consistency between test and implementation.

The test uses FilterGranularity.WEEKLY but the mock data and URL comment in the mock file suggest monthly granularity. This might lead to confusion or potential bugs in the future.


🏁 Script executed:

#!/bin/bash
# Check if the granularity parameter is being used consistently

# First, check the implementation of fetchActiveContributors to see how granularity is used
echo "Checking how granularity is used in the implementation:"
rg -A 5 -B 5 "granularity:" "frontend/server/data/tinybird/active-contributors-data-source.ts"

# Then, check the actual API calls to see what granularity values are supported
echo "Checking API endpoints for granularity parameter:"
rg -A 2 "granularity=" "frontend/server"

Length of output: 1045


Action Required: Align Granularity Values Between Test and Mocks

The test in frontend/server/data/tinybird/active-contributors-data-source.test.ts sets the filter’s granularity to FilterGranularity.WEEKLY, while the API endpoint URL in frontend/server/mocks/tinybird-active-contributors-response.mock.ts uses granularity=monthly. This discrepancy can lead to confusion or potential bugs in the future. Please verify whether the system is intended to operate on a weekly or monthly basis and update the test, mocks, and/or implementation accordingly to maintain consistency.

  • Files to review/update:
    • frontend/server/data/tinybird/active-contributors-data-source.test.ts (test filter granularity)
    • frontend/server/mocks/tinybird-active-contributors-response.mock.ts (API endpoint granularity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants