Add branch: filter and full-SHA support to test_instances search#90
Conversation
Pasting a full 40-char SHA into the search box used to miss the commit silently — the preprocessor was taking the first 8 characters of the input (`sha[(0..7)]` is inclusive) and comparing against the 7-char short_sha column. Truncate to 7 chars and downcase so any length of SHA prefix above 7 still resolves cleanly. Add `branch:` as a new top-level search key. Because branches relate to test instances transitively through commits + BranchMembership, it has to live outside the SearchOption mechanism — there is no branch_id column on TestInstance for the generic query_piece to target. Filter is comma-aware (OR across branches), composes with the rest of the query via AND, and reports unknown branch names back to the form instead of silently dropping the filter. Closes #37 — the workflow the issue described ("paste a SHA, find its instances") now works directly, and the same form answers the broader question of "show me failing tests on branch X from computer Y in the last N days."
The HTML and JSON formats of test_instances#search share the same TestInstance.query pipeline, so the new branch: key and the full-SHA fix flow through both automatically. Add a request spec that exercises the JSON envelope directly (results + failures) so a future controller refactor can't quietly break the API. While wiring up the spec, hit a pre-existing bug: TestInstance#as_json required its `options` argument, so as soon as the JSON endpoint had to serialize a non-empty result set Rails raised "wrong number of arguments". Make the argument optional — `options` isn't used in the body and the Rails as_json contract permits the default. The endpoint must have been broken for non-empty results for a while; nothing in the suite was hitting that code path. Auth on the JSON endpoint is a separate problem and out of scope here. The controller advertises an email/password fallback inside `authenticated?`, but the global `authorize_user` before_action redirects unauthenticated callers to /login before the action runs, so that fallback is dead code. Reaching the JSON endpoint without a browser session needs a `skip_before_action :authorize_user`; the spec uses POST /sessions to log in, which is the path that actually works today.
|
Yes — both formats route through the same Pre-existing JSON bug, fixed inline. Pre-existing JSON auth bug, out of scope. The controller's |
Summary
branch:as a new top-level key in the test_instances search query language. Filters to instances whose commit lives on the named branch; comma-separated for OR; composes with the rest of the query via AND; unknown branches are reported back inline.commit:to accept a full 40-character SHA. The old preprocessor sliced the first 8 chars (sha[(0..7)]is inclusive) and compared against the 7-char short_sha column — full SHAs always missed silently. Also makes the comparison case-insensitive.Closes #37 — the workflow the issue described ("paste a SHA, find its instances") now works directly, and the same form answers the broader question of "show me failing tests on branch X from computer Y in the last N days."
Test plan
bundle exec rspec spec/models/test_instance_query_spec.rb— 7 new examples coveringbranch:(single, comma-OR, composed-with-AND, unknown branch, partial-match) and the SHA bug fix (full 40-char, case-insensitive). 40 examples pass.bundle exec rspec— 311 examples, 0 failures).branch: main; passed: false→ 6317 failing instances on main.branch: main; computer: ccalin046; date: 2026-01-01-2026-05-26→ 5 failing radiative_levitation / starspots instances from ccalin046 in early 2026.branch: no-such-branch→ 0 results + "Invalid search parameters: branch (no-such-branch)" inline warning.commit: 0671b8f16bf6080e75bb8edea94fcf7cc80368d6→ 1 instance (custom_colors on VVEEGGAA). Previously returned nothing.