Skip to content

Adjusted randomness for factories to fix rare failure collisions - #951

Merged
chrismaddalena merged 3 commits into
masterfrom
hotfix/test-hardening
Jul 28, 2026
Merged

Adjusted randomness for factories to fix rare failure collisions#951
chrismaddalena merged 3 commits into
masterfrom
hotfix/test-hardening

Conversation

@chrismaddalena

Copy link
Copy Markdown
Collaborator

Hardening pass on test cases to fix random, rare failures like https://github.com/GhostManager/Ghostwriter/actions/runs/30086305686/job/89459171980.

Copilot AI review requested due to automatic review settings July 28, 2026 16:59
@augmentcode

augmentcode Bot commented Jul 28, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR hardens Factory Boy test data generation to be deterministic and avoid rare identity collisions that intermittently fail CI.

Changes:

  • Replaced random/Faker-based identity fields with factory.Sequence/LazyAttribute identities for users, groups, clients, domains, and server IPs.
  • Pinned many time/date fields to stable “today ± N days” values and set several booleans to deterministic defaults.
  • Updated GenerateMockProject to distribute findings/objectives/scopes/targets/deconflictions predictably instead of using random selection.
  • Added a new FactoryIdentityTests test module to assert uniqueness and that explicit duplicates raise IntegrityError.
  • Extended serializer/view tests to validate the mock project fixture produces deliberate variants and to assert successful preview responses before inspecting content.

Technical Notes: The overall goal is to reduce flaky CI failures caused by randomness and unique-constraint collisions in factories.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ghostwriter/factories.py Outdated

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

This PR hardens Ghostwriter’s Django test factories and a few reporting tests to avoid rare, random collisions and improve determinism in test fixtures (referenced CI flake link in the PR description).

Changes:

  • Made several factory identity fields deterministic/unique (e.g., usernames, client names, domain names, IPs) and reduced random boolean/date/time generation.
  • Updated reporting preview view tests to use explicit usernames and added a few assertions to fail fast on unexpected response codes/roles.
  • Added targeted tests to ensure the “mock project” fixture contains deliberate data variants and that factory identity collisions fail loudly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
ghostwriter/reporting/tests/test_views.py Uses explicit usernames for preview tests and adds extra assertions to reduce flakiness.
ghostwriter/reporting/tests/test_serializers.py Adds assertions verifying GenerateMockProject() produces deliberate variants (severities, assignees, states).
ghostwriter/home/tests/test_factories.py New tests to validate factory uniqueness and role/privilege behavior.
ghostwriter/factories.py Core changes: deterministic sequences/defaults to reduce collisions; deterministic distribution in GenerateMockProject().
Comments suppressed due to low confidence (1)

ghostwriter/factories.py:1200

  • Same issue as above: without passing project=project, the connection will be linked to a newly created Project from the factory default instead of the project created in GenerateMockProject().
            DomainServerConnectionFactory(
                domain=domain,
                transient_server=cloud[index % len(cloud)],
                static_server=None,
            )

Comment thread ghostwriter/factories.py Outdated
Comment thread ghostwriter/factories.py Outdated
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.20%. Comparing base (8a18e3b) to head (e46ff51).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #951      +/-   ##
==========================================
+ Coverage   92.17%   92.20%   +0.02%     
==========================================
  Files         443      444       +1     
  Lines       33872    33957      +85     
==========================================
+ Hits        31223    31309      +86     
+ Misses       2649     2648       -1     

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI review requested due to automatic review settings July 28, 2026 17:19

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread ghostwriter/factories.py Outdated
Copilot AI review requested due to automatic review settings July 28, 2026 17:33

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@chrismaddalena
chrismaddalena merged commit b1498a5 into master Jul 28, 2026
8 checks passed
@chrismaddalena
chrismaddalena deleted the hotfix/test-hardening branch July 28, 2026 17:44
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.

2 participants