Skip to content

Stop two AI tests depending on timing they do not control - #5079

Open
elias-ba wants to merge 1 commit into
mainfrom
timeout-stable-message-order
Open

Stop two AI tests depending on timing they do not control#5079
elias-ba wants to merge 1 commit into
mainfrom
timeout-stable-message-order

Conversation

@elias-ba

@elias-ba elias-ba commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Description

Two tests that passed alone and failed in a full run, which is the worst kind of red: it lands on whoever pushes next rather than on whoever caused it.

The chat tests picked a reply with List.last/1, but messages are ordered by inserted_at and that is stored to the second, so a question and its answer written in the same millisecond tie and come back either way round. They now pick by role, which is what each of them meant. The ordering itself is left alone; that needs a migration and is filed as #5081.

The credentials schema test asserted that nothing at all was logged, which any warning from a neighbouring async test would break. It now asserts the absence of the one message it actually cares about.

Validation steps

  1. Nothing here is user-visible, so there is no scenario to click. The check is the suite: mix test test/lightning/ai_assistant/ai_assistant_test.exs test/lightning/credentials/schema_test.exs
  2. To see the flake it fixes, put List.last/1 back in place of assistant_message/1 and run the full suite a few times. The global chat assertions fail on some runs and not others.

Additional notes for the reviewer

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review with Claude Code)
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog
  • I have ticked a box in "AI usage" in this PR

Both passed alone and failed in a full run, which is the worst kind of
red: it lands on whoever pushed next rather than on whoever caused it.

The chat tests picked a reply with List.last/1. Messages come back
ordered by inserted_at alone and the schema keeps that to the second, so
a question and its answer written inside the same second tie and come
back either way round. Against a real model the answer takes seconds and
the order holds; here both writes land in the same millisecond, so it was
a coin toss that usually landed right. They now pick by role, which is
what each of them meant.

The ordering itself is left alone. It is only reachable when two messages
share a second, which needs a reply to arrive instantly, and changing it
means a migration to microsecond timestamps. Worth doing, not worth doing
here.

The schema test asserted that nothing at all was logged. with_log/1
captures everything logged in the window, including from the async tests
running beside it, so any warning anywhere failed it. It now asserts the
absence of the one message that would mean the types were not recognised,
which is what the test is about.
@github-project-automation github-project-automation Bot moved this to New Issues in Core Aug 17, 2026
@github-actions

Copy link
Copy Markdown

Security Review ✅

  • S0 (project scoping): N/A, test-only changes to test/lightning/ai_assistant/ai_assistant_test.exs and test/lightning/credentials/schema_test.exs — no query, controller, or LiveView code touched.
  • S1 (authorization): N/A, no changes under test/lightning/policies/ and no policy or web-layer code modified.
  • S2 (audit trail): N/A, no changes to configuration-resource writes or audit modules; only test assertions were adjusted for determinism.

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

Labels

None yet

Projects

Status: New Issues

Development

Successfully merging this pull request may close these issues.

1 participant