Skip to content

Conversation

@Konboi
Copy link
Contributor

@Konboi Konboi commented May 23, 2025

To use PTS, data is required, but collecting new data from scratch takes time.
Therefore, we will provide a --timestamp option to allow importing past data as well.

Summary by CodeRabbit

  • New Features
    • Added a new optional --timestamp command-line option to the build, tests, and session commands, allowing users to specify custom datetimes (with or without timezone) for importing historical data.
  • Bug Fixes
    • Improved handling of datetime inputs by automatically assigning local timezone if none is provided.
  • Tests
    • Added tests to verify correct parsing and handling of the new --timestamp option and datetime inputs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 23, 2025

"""

Walkthrough

The changes add an optional --timestamp CLI option to the build, tests, and session commands, enabling users to specify custom datetime values (with or without timezone) for importing historical data. A new Click parameter type parses these datetime inputs. Corresponding logic and tests are updated to handle and validate this feature.

Changes

File(s) Change Summary
launchable/commands/record/build.py, launchable/commands/record/tests.py, launchable/commands/record/session.py, launchable/commands/helper.py Added optional --timestamp CLI option (type: DATETIME_WITH_TZ) to build, tests, and session commands; updated function signatures and payloads to include optional timestamp for historical data import and override creation times. Propagated timestamp parameter to session helper function.
launchable/utils/click.py Introduced DateTimeWithTimezoneType Click parameter type for parsing datetimes with/without timezone; exported as DATETIME_WITH_TZ.
tests/commands/record/test_build.py, tests/commands/record/test_session.py Updated test payloads to include "timestamp" field; added tests verifying payloads with provided timestamps for build and session commands.
tests/commands/record/tests.py Added --timestamp CLI option and logic to override test creation times; updated report skipping and test case creation timestamps accordingly.
tests/utils/test_click.py Added tests for DATETIME_WITH_TZ option type, verifying correct parsing of various datetime formats and timezones.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant DateTimeParser
    participant API

    User->>CLI: run build/tests/session --timestamp <datetime>
    CLI->>DateTimeParser: Parse --timestamp value
    DateTimeParser-->>CLI: datetime object (with tzinfo)
    CLI->>API: Send payload including timestamp (ISO 8601)
    API-->>CLI: Response
Loading

Poem

In the warren where time hops by,
Now builds and tests can specify
A moment past, with zone and all—
Just add a timestamp, heed the call!
🕰️ Rabbits rejoice, for history’s clear,
With datetimes parsed, the past draws near.
Hoppily, we code without fear!
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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/utils/test_click.py (1)

51-75: ⚠️ Potential issue

Fix type annotation and improve test structure.

The test class has a critical type annotation error that's causing the mypy failure. The actual variable is declared as str but assigned a datetime.datetime object.

Apply this diff to fix the type annotation:

-    def test_conversion(self):
-        def scenario(expected: str, *args):
-            actual: str = ""
+    def test_conversion(self):
+        def scenario(expected: datetime.datetime, *args):
+            actual: datetime.datetime = None

Also, consider adding a test case for error handling:

+        # Test invalid datetime format
+        with self.assertRaises(click.BadParameter):
+            CliRunner().invoke(time, ['-t', 'invalid-datetime'])

Optional improvement: Add more comprehensive test coverage.

Consider testing edge cases like:

  • Empty timestamp argument
  • Different timezone formats
  • Invalid timezone names
def test_invalid_formats(self):
    @click.command()
    @click.option('-t', 'timestamp', type=DATETIME_WITH_TZ)
    def time(timestamp):
        pass
    
    runner = CliRunner()
    
    # Test invalid format
    result = runner.invoke(time, ['-t', 'not-a-date'])
    self.assertNotEqual(0, result.exit_code)
    
    # Test invalid timezone
    result = runner.invoke(time, ['-t', '2023-10-01T12:00:00+25:00'])
    self.assertNotEqual(0, result.exit_code)
🧰 Tools
🪛 GitHub Actions: Python package

[error] 65-65: mypy: Incompatible types in assignment (expression has type "datetime", variable has type "str") (assignment)

🧹 Nitpick comments (4)
launchable/utils/click.py (1)

99-111: Improve exception handling and error message clarity.

The implementation is solid, but consider these improvements:

  1. dateutil.parser.parse() can raise other exceptions besides ValueError (e.g., TypeError, OverflowError)
  2. The error message could be more descriptive about acceptable formats
 def convert(self, value: str, param: Optional[click.core.Parameter], ctx: Optional[click.core.Context]):
     try:
         dt = dateutil.parser.parse(value)
         if dt.tzinfo is None:
             return dt.replace(tzinfo=tzlocal())
         return dt
-    except ValueError:
-        self.fail("Expected datetime like 2023-10-01T12:00:00 but got '{}'".format(value), param, ctx)
+    except (ValueError, TypeError, OverflowError) as e:
+        self.fail("Expected datetime in ISO format (YYYY-MM-DDTHH:MM:SS[±HH:MM]) or similar, but got '{}'. Error: {}".format(value, str(e)), param, ctx)
launchable/commands/record/build.py (1)

100-106: Consider clarifying the TZD abbreviation in help text.

The CLI option implementation is excellent with comprehensive help text. Minor suggestion: "TZD" might not be familiar to all users.

-    help='Used to overwrite the build time when importing historical data. Note: Format must be `YYYY-MM-DDThh:mm:ssTZD` or `YYYY-MM-DDThh:mm:ss` (local timezone applied)',  # noqa: E501
+    help='Used to overwrite the build time when importing historical data. Note: Format must be `YYYY-MM-DDThh:mm:ss±HH:MM` (with timezone) or `YYYY-MM-DDThh:mm:ss` (local timezone applied)',  # noqa: E501
launchable/commands/record/tests.py (1)

415-421: Consider simplifying the timestamp check condition for readability.

The logic is correct but could be more readable. The condition properly bypasses the timestamp check when --timestamp is provided.

-            if (
-                    not self.is_allow_test_before_build  # nlqa: W503
-                    and not self.is_no_build  # noqa: W503
-                    and timestamp is None  # noqa: W503
-                    and self.check_timestamp  # noqa: W503
-                    and ctime.timestamp() < record_start_at.timestamp()  # noqa: W503
-            ):
+            should_skip_old_report = (
+                not self.is_allow_test_before_build
+                and not self.is_no_build
+                and timestamp is None
+                and self.check_timestamp
+                and ctime.timestamp() < record_start_at.timestamp()
+            )
+            if should_skip_old_report:
tests/commands/record/test_build.py (1)

270-270: Fix misplaced comment.

The comment appears to be copied from another test method and doesn't match the new test_with_timestamp functionality.

-# make sure the output of git-submodule is properly parsed
+# verify that --timestamp option correctly adds timestamp to payload
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7cfad1a and 824aa6c.

📒 Files selected for processing (5)
  • launchable/commands/record/build.py (4 hunks)
  • launchable/commands/record/tests.py (5 hunks)
  • launchable/utils/click.py (2 hunks)
  • tests/commands/record/test_build.py (7 hunks)
  • tests/utils/test_click.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/commands/record/test_build.py (2)
tests/cli_test_case.py (5)
  • CliTestCase (21-341)
  • cli (200-211)
  • assert_success (213-214)
  • payload (278-289)
  • assert_json_orderless_equal (297-313)
launchable/utils/session.py (1)
  • read_build (19-30)
🪛 GitHub Actions: Python package
tests/utils/test_click.py

[error] 5-5: mypy: Cannot find implementation or library stub for module named "zoneinfo" (import-not-found)


[error] 65-65: mypy: Incompatible types in assignment (expression has type "datetime", variable has type "str") (assignment)

🔇 Additional comments (15)
launchable/utils/click.py (2)

6-8: LGTM: Clean import additions for datetime parsing.

The imports for dateutil.parser and tzlocal are appropriate for the new datetime parsing functionality.


117-117: LGTM: Consistent constant naming pattern.

The DATETIME_WITH_TZ constant follows the established naming convention used by other parameter types in this file.

launchable/commands/record/build.py (4)

1-1: LGTM: Necessary import for timestamp functionality.

The datetime import is required for the new timestamp parameter type annotation.


15-15: LGTM: Correct import for the new parameter type.

The DATETIME_WITH_TZ import is appropriately added alongside the existing KEY_VALUE import.


113-113: LGTM: Function signature correctly updated.

The timestamp parameter is properly typed and positioned at the end of the parameter list.


337-338: LGTM: Proper timestamp handling in payload.

The implementation correctly formats the timestamp as ISO string when provided and sets it to None otherwise. The conditional expression is clean and appropriate.

launchable/commands/record/tests.py (4)

19-19: LGTM: Correct import for datetime parameter type.

The DATETIME_WITH_TZ import is appropriately added to support the new timestamp functionality.


162-168: LGTM: Comprehensive CLI option with clear help text.

The --timestamp option is well-documented and follows the same pattern as the build command. The help text clearly explains the use case for importing historical data.


187-187: LGTM: Function signature properly updated.

The timestamp parameter is correctly typed and positioned appropriately in the function signature.


453-456: LGTM: Correct timestamp override for historical data.

The implementation properly overrides the createdAt field with the provided timestamp when importing historical data. The ISO format conversion is appropriate.

tests/commands/record/test_build.py (2)

62-64: LGTM: Consistent test payload updates.

All existing test cases have been properly updated to include the new "timestamp": None field in their payload assertions. This ensures backward compatibility testing.

Also applies to: 97-99, 129-131, 188-190, 218-220, 258-260


271-297: LGTM: Comprehensive test for timestamp functionality.

The test properly verifies that:

  1. The --timestamp option is accepted
  2. The timestamp is correctly formatted as ISO string in the payload
  3. The build name is recorded correctly
  4. Other payload fields remain consistent

The test follows established patterns and uses appropriate mocking.

tests/utils/test_click.py (3)

1-2: LGTM: Standard datetime imports added.

The datetime and timezone imports are correctly added to support the new timestamp functionality.


9-9: LGTM: Required dateutil import added.

The tzlocal import is correctly added to support local timezone handling in the tests.


11-11: LGTM: New parameter type import added.

The DATETIME_WITH_TZ import is correctly added to test the new datetime parameter type functionality.

@Konboi Konboi force-pushed the timestamp-option branch 2 times, most recently from 5326e95 to 29ad71f Compare May 23, 2025 12:47
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: 0

♻️ Duplicate comments (1)
tests/utils/test_click.py (1)

5-5: ⚠️ Potential issue

Remove unused zoneinfo import that causes compatibility issues.

The zoneinfo import is causing Python version compatibility issues (only available in Python 3.9+) and is not actually used anywhere in the code, as confirmed by static analysis.

Apply this diff to remove the unused import:

-from zoneinfo import ZoneInfo
🧰 Tools
🪛 Ruff (0.11.9)

5-5: zoneinfo.ZoneInfo imported but unused

Remove unused import: zoneinfo.ZoneInfo

(F401)

🪛 GitHub Actions: Python package

[error] 5-5: mypy error: Cannot find implementation or library stub for module named "zoneinfo" (import-not-found). See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

🧹 Nitpick comments (1)
tests/utils/test_click.py (1)

51-74: Enhance test coverage for the new timestamp feature.

The basic test implementation is correct and follows good patterns. However, consider adding edge case testing to ensure robustness of the new timestamp CLI option.

Consider adding these additional test scenarios for better coverage:

+        # Test edge cases
+        with self.assertRaises(click.BadParameter):
+            CliRunner().invoke(time, ['-t', 'invalid-date'])
+        
+        with self.assertRaises(click.BadParameter):
+            CliRunner().invoke(time, ['-t', '2023-13-01 12:00:00'])  # Invalid month
+        
+        # Test additional timezone formats
+        scenario(datetime.datetime(2023, 10, 1, 15, 30, 0, tzinfo=timezone(timedelta(hours=5, minutes=30))), 
+                '-t', '2023-10-01T15:30:00+05:30')  # IST timezone
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5326e95 and 29ad71f.

📒 Files selected for processing (4)
  • launchable/commands/record/build.py (4 hunks)
  • launchable/commands/record/tests.py (5 hunks)
  • launchable/utils/click.py (2 hunks)
  • tests/utils/test_click.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • launchable/commands/record/tests.py
  • launchable/utils/click.py
  • launchable/commands/record/build.py
🧰 Additional context used
🪛 Ruff (0.11.9)
tests/utils/test_click.py

5-5: zoneinfo.ZoneInfo imported but unused

Remove unused import: zoneinfo.ZoneInfo

(F401)

🪛 GitHub Actions: Python package
tests/utils/test_click.py

[error] 5-5: mypy error: Cannot find implementation or library stub for module named "zoneinfo" (import-not-found). See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

@Konboi Konboi force-pushed the timestamp-option branch from 29ad71f to d4c1841 Compare May 23, 2025 12:51
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: 0

♻️ Duplicate comments (1)
tests/utils/test_click.py (1)

5-5: ⚠️ Potential issue

Fix Python version compatibility issue with zoneinfo.

The zoneinfo module is only available in Python 3.9+, which could cause compatibility issues with older Python versions. This import is also unused in the current code.

Remove the unused import and use dateutil.tz.gettz() if timezone handling is needed:

-from zoneinfo import ZoneInfo
🧰 Tools
🪛 Ruff (0.11.9)

5-5: zoneinfo.ZoneInfo imported but unused

Remove unused import: zoneinfo.ZoneInfo

(F401)

🧹 Nitpick comments (1)
tests/utils/test_click.py (1)

51-74: Test implementation looks good with minor naming improvement.

The test class correctly validates the DATETIME_WITH_TZ Click parameter type with comprehensive scenarios covering naive datetime strings, UTC offsets, and Z suffix notation. The test logic properly verifies timezone-aware datetime conversion.

Consider renaming the expected parameter in the scenario function for clarity:

-        def scenario(expected: str, *args):
+        def scenario(expected_datetime: datetime.datetime, *args):

And update the parameter type annotation since it expects a datetime object, not a string.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 29ad71f and d4c1841.

📒 Files selected for processing (4)
  • launchable/commands/record/build.py (4 hunks)
  • launchable/commands/record/tests.py (5 hunks)
  • launchable/utils/click.py (2 hunks)
  • tests/utils/test_click.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • launchable/utils/click.py
  • launchable/commands/record/tests.py
  • launchable/commands/record/build.py
🧰 Additional context used
🪛 Ruff (0.11.9)
tests/utils/test_click.py

5-5: zoneinfo.ZoneInfo imported but unused

Remove unused import: zoneinfo.ZoneInfo

(F401)

🪛 GitHub Actions: Python package
tests/utils/test_click.py

[error] 1-1: Test failure detected during test run.

@Konboi Konboi force-pushed the timestamp-option branch from d4c1841 to 76e9847 Compare May 23, 2025 12:58
@launchable-app

This comment has been minimized.

@Konboi Konboi force-pushed the timestamp-option branch from 31d4715 to 1c0da70 Compare May 23, 2025 13:16
@Konboi Konboi force-pushed the timestamp-option branch from 1c0da70 to ae64493 Compare May 23, 2025 13:22
@Konboi Konboi requested a review from kohsuke May 23, 2025 13:30
@sonarqubecloud
Copy link

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: 0

🔭 Outside diff range comments (1)
launchable/commands/helper.py (1)

96-107: ⚠️ Potential issue

Fix inconsistent timestamp handling between execution paths.

The timestamp parameter is only passed to session_command in the normal execution path (line 139) but not in the no-build execution path (lines 96-107). This inconsistency could lead to different behavior when using the --timestamp option with --no-build.

Apply this diff to ensure consistent timestamp handling:

        context.invoke(
            session_command,
            build_name=NO_BUILD_BUILD_NAME,
            save_session_file=True,
            print_session=False,
            flavor=flavor,
            is_observation=is_observation,
            links=links,
            is_no_build=is_no_build,
            lineage=lineage,
            test_suite=test_suite,
+           timestamp=timestamp,
        )

Also applies to: 128-140

🧹 Nitpick comments (1)
launchable/commands/helper.py (1)

68-68: Add documentation for the timestamp parameter.

The new timestamp parameter should be documented in the function's docstring Args section for consistency with other parameters.

        lineage: lineage option value
        test_suite: --test-suite option value
+       timestamp: Optional datetime for session creation
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 18c1951 and b9acf19.

📒 Files selected for processing (2)
  • launchable/commands/helper.py (3 hunks)
  • launchable/commands/record/tests.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • launchable/commands/record/tests.py
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: build (windows-latest, 3.6)
  • GitHub Check: build (windows-latest, 3.12)
  • GitHub Check: build (windows-latest, 3.11)
  • GitHub Check: build (windows-latest, 3.10)
  • GitHub Check: build (windows-latest, 3.9)
  • GitHub Check: build (windows-latest, 3.8)
  • GitHub Check: build (windows-latest, 3.7)
  • GitHub Check: build (ubuntu-22.04, 3.12)
  • GitHub Check: build (ubuntu-22.04, 3.11)
  • GitHub Check: build (ubuntu-22.04, 3.10)
  • GitHub Check: build (ubuntu-22.04, 3.9)
  • GitHub Check: build (ubuntu-22.04, 3.8)
  • GitHub Check: build (ubuntu-22.04, 3.7)
🔇 Additional comments (2)
launchable/commands/helper.py (2)

1-1: LGTM: Import statement is correctly placed.

The datetime import is appropriately added to support the new timestamp functionality.


139-139: LGTM: Timestamp parameter correctly passed to session_command.

The timestamp parameter is properly passed to the session_command in the normal execution path, enabling historical data import functionality.

@Konboi Konboi merged commit 692e68f into main May 26, 2025
16 checks passed
@Konboi Konboi deleted the timestamp-option branch May 26, 2025 01:21
@github-actions github-actions bot mentioned this pull request May 26, 2025
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.

3 participants