Skip to content

Fix flaky tests by making school teacher ID lookup deterministic#706

Merged
zetter-rpf merged 1 commit intomainfrom
cursor/api-user-ids-order-17d8
Mar 2, 2026
Merged

Fix flaky tests by making school teacher ID lookup deterministic#706
zetter-rpf merged 1 commit intomainfrom
cursor/api-user-ids-order-17d8

Conversation

@zetter-rpf
Copy link
Contributor

@zetter-rpf zetter-rpf commented Mar 2, 2026

Example failure - https://github.com/RaspberryPiFoundation/editor-api/actions/runs/22571941511/job/65381726124

This was making the order that teaches returned non-deterministic, which was causing intermittent test failures.

The test that was failing was the 'SchoolTeacher::List when successful when not passing teacher_ids returns a successful response with school teachers' test in ./spec/concepts/school_teacher/list_spec.rb.

@cursor
Copy link

cursor bot commented Mar 2, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@cla-bot cla-bot bot added the cla-signed label Mar 2, 2026
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Test coverage

89.92% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/22586956044

@zetter-rpf zetter-rpf force-pushed the cursor/api-user-ids-order-17d8 branch from df97f98 to d1cffd4 Compare March 2, 2026 12:18
@zetter-rpf zetter-rpf changed the title Api user IDs order Fix flaky tests by making school teacher ID lookup deterministic Mar 2, 2026
@zetter-rpf zetter-rpf marked this pull request as ready for review March 2, 2026 12:19
Copilot AI review requested due to automatic review settings March 2, 2026 12:19
Copy link
Contributor

Copilot AI left a comment

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 makes the teacher ID lookup used by SchoolTeacher::List deterministic to eliminate intermittent test failures caused by non-deterministic role ordering.

Changes:

  • Order teacher Role records by id before plucking user_ids when teacher_ids aren’t provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@mwtrew mwtrew left a comment

Choose a reason for hiding this comment

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

Is it safe to get rid of the [...]&.[...]? I'm not sure if a school can have no teachers, though.

@zetter-rpf
Copy link
Contributor Author

zetter-rpf commented Mar 2, 2026

Is it safe to get rid of the [...]&.[...]? I'm not sure if a school can have no teachers, though.

Yes, the query isn't executed until pluck is called on it. If there are no records matching, the result will be []. There's no point in adding the &. it will always be acting on a truthy value (the active record relation object that represents the query)

Example failure - https://github.com/RaspberryPiFoundation/editor-api/actions/runs/22571941511/job/65381726124

This was making the order that teaches returned non-deterministic, which was causing intermittent test failures.

The test that was failing was the 'SchoolTeacher::List when successful when not passing teacher_ids returns a successful response with school teachers' test in ./spec/concepts/school_teacher/list_spec.rb.

Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
@zetter-rpf zetter-rpf force-pushed the cursor/api-user-ids-order-17d8 branch from d1cffd4 to b2f4f26 Compare March 2, 2026 17:09
@zetter-rpf zetter-rpf merged commit b9efc3c into main Mar 2, 2026
8 checks passed
@zetter-rpf zetter-rpf deleted the cursor/api-user-ids-order-17d8 branch March 2, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants