Skip to content

fix(tests): allow same-day rule tunings without updated_date bump - #6681

Open
Mikaayenson wants to merge 3 commits into
mainfrom
fix/same-day-updated-date-tuning
Open

fix(tests): allow same-day rule tunings without updated_date bump#6681
Mikaayenson wants to merge 3 commits into
mainfrom
fix/same-day-updated-date-tuning

Conversation

@Mikaayenson

@Mikaayenson Mikaayenson commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Allow same-day follow-up rule tunings without a new updated_date hunk in the git diff
  • Treat missing explicit metadata.updated_date as pass; require a bump when the date is stale
  • Compare "today" in UTC so evening local edits still match CI runners
  • Read updated_date via pytoml (aligned with endpoint-rules same-day check)
  • Bump detection_rules package version 2.1.62.1.7

Test plan

  • CI unit tests pass on this PR
  • Same-day retune (query change only, updated_date already UTC today) does not fail test_rule_change_has_updated_date
  • Stale updated_date with no bump still fails
  • Explicit +updated_date in the diff still passes

When a modified rule already has metadata.updated_date set to today (UTC),
skip requiring a new updated_date hunk in the git diff. Stale dates still
fail. Reads updated_date via pytoml.
@Mikaayenson Mikaayenson self-assigned this Aug 20, 2026
@Mikaayenson Mikaayenson added bug Something isn't working python Internal python for the repository patch labels Aug 20, 2026
@Mikaayenson
Mikaayenson marked this pull request as ready for review August 20, 2026 20:46
Copilot AI lite review requested due to automatic review settings August 20, 2026 20:46

Copilot AI 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.

Pull request overview

Updates the rule-modification test logic to allow same-day follow-up rule tunings without requiring an updated_date line change in the PR diff, while still enforcing updated_date bumps when the recorded date is stale (using UTC “today” for CI consistency).

Changes:

  • Update test_rule_change_has_updated_date to pass when updated_date is already today (UTC) even if the diff doesn’t include an updated_date hunk.
  • Treat missing metadata.updated_date as a pass rather than forcing a bump.
  • Parse rule TOML via pytoml and normalize updated_date values into a UTC date for comparison.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_all_rules.py
@unittest.skipIf(os.getenv("GITHUB_EVENT_NAME") == "push", "Skipping this test when not running on pull requests.")
def test_rule_change_has_updated_date(self):
"""Test to ensure modified rules have updated_date field updated."""
"""Fail when a modified rule lacks an updated_date bump and is not same-day UTC."""
Comment thread tests/test_all_rules.py
updated_date = metadata["updated_date"]
if isinstance(updated_date, datetime):
if updated_date.tzinfo is None:
updated_date = updated_date.replace(tzinfo=UTC)

@eric-forte-elastic eric-forte-elastic Aug 21, 2026

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.

In this case, other places in the code covert the time to non-UTC so this will still could cause an issue if fixed this way. Since in this repo updated date is required I think it needs to be handled a little differently.

Pulling local time:

  • detection_rules/cli_utils.py:62 time.strftime("%Y/%m/%d")
  • detection_rules/cli_utils.py:271 datetime.date.today()
  • detection_rules/devtools.py:1010,1165,1758,2026 time.strftime("%Y/%m/%d")

So cases with something like: US/Pacific, Aug 20 18:00 PDT (= Aug 21 01:00 UTC)

I think the simplest way to address this is to just have our functions in cli_utils.py and devtools.py also be timezone aware to UTC (e.g. datetime.now(UTC).strftime("%Y/%m/%d") ), to address the conflict.

patch to fix:

utc-date-stamping.patch.txt

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.

if this is the case, agreed, maybe a separate PR to add a globally accessible adjustment.

@eric-forte-elastic eric-forte-elastic 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.

Main comment, otherwise LGTM 👍

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

Labels

backport: auto bug Something isn't working patch python Internal python for the repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants