Skip to content

Updated SQL modes in tests to match production. - #31445

Merged
getvictor merged 33 commits into
mainfrom
victor/31444-sql-modes
Aug 3, 2025
Merged

Updated SQL modes in tests to match production.#31445
getvictor merged 33 commits into
mainfrom
victor/31444-sql-modes

Conversation

@getvictor

@getvictor getvictor commented Jul 31, 2025

Copy link
Copy Markdown
Member

Fixes #31444

The changes are primarily in tests. The only changes in production code are a couple validations/checks for invalid values in:

  • mysql/apple_mdm.go
  • mysql/hosts.go
  • mysql/queries.go

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of timestamp and default values across various features to prevent database errors and warnings.
    • Enhanced validation and data consistency for Apple Business Manager tokens and MDM profiles.
    • Updated test data and logic to comply with stricter database constraints and realistic scenarios, including date handling and field lengths.
  • Chores

    • Updated test setups to reflect schema changes, improve data integrity, and avoid future compatibility issues.
    • Standardized SQL mode and timestamp usage in test environments.
    • Refined test data for VPP apps, software installers, and device enrollments for better reliability.
  • Tests

    • Expanded and updated tests to cover new fields, stricter validation, and more accurate simulation of real-world conditions.

@coderabbitai

coderabbitai Bot commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto 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

Walkthrough

This change updates the MySQL test environment to use stricter SQL modes that match production MySQL 8.0 defaults, improving data integrity checks. It introduces a new SQL mode constant, updates test database connections to use this mode, and adjusts test data to comply with stricter validation, such as timestamp handling and string length constraints.

Changes

Cohort / File(s) Change Summary
Test SQL mode enforcement
server/datastore/mysql/common_mysql/common.go, server/datastore/mysql/testing_utils.go, server/mdm/android/mysql/testing_utils.go
Added TestSQLMode constant with MySQL 8 strict modes and updated all test DB connections to use it, ensuring stricter data validation during tests.
Timestamp and date compliance in tests
server/datastore/mysql/hosts.go, server/datastore/mysql/apple_mdm.go, server/datastore/mysql/queries.go, server/service/integration_core_test.go, server/datastore/mysql/android_test.go, server/datastore/mysql/software_installers_test.go, server/datastore/mysql/scripts_test.go, server/datastore/mysql/activities_test.go, server/datastore/mysql/hosts_test.go, server/datastore/mysql/mdm_test.go, server/datastore/mysql/scep_test.go, server/datastore/mysql/software_test.go, server/service/integration_mdm_test.go, server/service/integration_enterprise_test.go, server/service/integration_mdm_profiles_test.go, server/service/integration_mdm_ddm_test.go, server/service/apple_mdm_ddm_test.go, server/worker/apple_mdm_test.go, server/service/integration_live_queries_test.go
Updated test data to use valid, non-zero timestamps, realistic expiration dates, and correct date handling to comply with stricter SQL mode.
Test data and schema adjustments
server/datastore/mysql/apple_mdm_test.go, server/datastore/mysql/apple_mdm_ddm_test.go, server/datastore/mysql/hosts_test.go, server/datastore/mysql/labels_test.go, server/datastore/mysql/scim_test.go, server/datastore/mysql/software_test.go, server/datastore/mysql/software_titles_test.go, server/datastore/mysql/teams_test.go, server/datastore/mysql/microsoft_mdm_test.go, server/datastore/mysql/software_installers_test.go, server/test/activities.go
Adjusted test insert statements and helper functions to include new or required columns, correct binary data formats, and field length limits to match stricter schema validation.
Configuration and environment updates
docker-compose.yml
Increased MySQL redo log capacity for the test MySQL container to avoid warnings, no impact on application logic.

Sequence Diagram(s)

Not applicable for this change, as it focuses on test configuration and data validation rather than control flow or feature logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Assessment against linked issues

Objective Addressed Explanation
Update MySQL test SQL mode to include all MySQL 8 strict modes (e.g., STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, etc.) to match production and catch data integrity issues (#31444)
Ensure test data and insertions comply with stricter SQL modes, avoiding silent truncation and invalid values (#31444)
Refactor test helpers and insert statements to handle stricter validation and schema requirements (#31444)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found. All modifications are directly related to enforcing stricter SQL modes and updating test data to comply with these modes, as required by the linked issue.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/31444-sql-modes

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 generate unit tests to generate unit tests for 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.

@codecov

codecov Bot commented Jul 31, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.89041% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.73%. Comparing base (87aa2d1) to head (c62b2a9).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
server/datastore/mysql/apple_mdm.go 83.33% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #31445   +/-   ##
=======================================
  Coverage   63.73%   63.73%           
=======================================
  Files        1958     1958           
  Lines      190652   190705   +53     
  Branches     6179     6179           
=======================================
+ Hits       121504   121550   +46     
- Misses      59625    59627    +2     
- Partials     9523     9528    +5     
Flag Coverage Δ
backend 65.08% <95.89%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@getvictor
getvictor marked this pull request as ready for review August 1, 2025 13:07
@getvictor
getvictor requested a review from a team as a code owner August 1, 2025 13:07
@getvictor getvictor assigned juan-fdz-hawa and unassigned sgress454 Aug 1, 2025
}

// Check that RenewAt is not zero
if tok.RenewAt.IsZero() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Don't we want to do this check earlier?, so that we avoid doing the unnecessary encrypt call on this line

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, makes sense. Thank you.

`INSERT INTO nano_enrollments (id, device_id, type, topic, push_magic, token_hex, enabled) VALUES (?, ?, ?, ?, ?, ?, ?)`,
hostUUID, hostUUID, "Device", "topic", "push_magic", "token_hex", 1)
`INSERT INTO nano_enrollments (id, device_id, type, topic, push_magic, token_hex, enabled, last_seen_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
hostUUID, hostUUID, "Device", "topic", "push_magic", "token_hex", 1, time.Now())

@juan-fdz-hawa juan-fdz-hawa Aug 2, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just double checking, does last_seen_at needs to be in UTC or doesn't matter? (I can't remember if the sqlx library auto-magically converts time.Time to UTC).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The MySQL driver converts it to UTC for storage, so it doesn't matter. However, when retrieving it, it converts it back to the session timezone.

title.Version,
title.ID,
"checksum",
hex.EncodeToString([]byte("checksum")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious, why do we have to hex encode the string just to UNHEX it while inserting the data?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right. It is not needed here.

@juan-fdz-hawa juan-fdz-hawa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM just a couple of small questions.

@getvictor

Copy link
Copy Markdown
Member Author

@juan-fdz-hawa I will merge this PR and address your suggestions in a follow up PR.

@getvictor
getvictor merged commit a0e9d88 into main Aug 3, 2025
42 checks passed
@getvictor
getvictor deleted the victor/31444-sql-modes branch August 3, 2025 06:18
@coderabbitai coderabbitai Bot mentioned this pull request Dec 31, 2025
3 tasks
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.

Tests use incorrect MySQL SQL modes, hiding data integrity violations

3 participants