Skip to content

Add branch: filter and full-SHA support to test_instances search#90

Merged
wmwolf merged 2 commits into
masterfrom
feature-instance-search-branch-filter
May 26, 2026
Merged

Add branch: filter and full-SHA support to test_instances search#90
wmwolf merged 2 commits into
masterfrom
feature-instance-search-branch-filter

Conversation

@wmwolf
Copy link
Copy Markdown
Member

@wmwolf wmwolf commented May 26, 2026

Summary

  • Adds 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.
  • Fixes 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.
  • Updates the form's syntax reference and the field list to reflect both changes.

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 covering branch: (single, comma-OR, composed-with-AND, unknown branch, partial-match) and the SHA bug fix (full 40-char, case-insensitive). 40 examples pass.
  • Full suite green (bundle exec rspec — 311 examples, 0 failures).
  • Manually verified against dev DB (live snapshot of production):
    • 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.

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."
@wmwolf wmwolf mentioned this pull request May 26, 2026
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.
@wmwolf
Copy link
Copy Markdown
Member Author

wmwolf commented May 26, 2026

Yes — both formats route through the same TestInstance.query pipeline, so branch: and the full-SHA commit: both work on the JSON endpoint. Just pushed b5667e2 with a request spec that exercises the JSON envelope (results + failures) directly, plus two notes worth surfacing:

Pre-existing JSON bug, fixed inline. TestInstance#as_json required its options argument. As soon as the endpoint had to serialize a non-empty result set, Rails raised wrong number of arguments (given 0, expected 1). Made options optional (one-character fix; the value isn't used in the body). The endpoint must have been broken for non-empty results for a while — nothing in the existing suite touched that code path.

Pre-existing JSON auth bug, out of scope. The controller's authenticated? advertises an email/password fallback, but the global authorize_user before_action redirects unauthenticated callers to /login before the action body runs. So the JSON endpoint is reachable only via a browser session today. The new spec uses POST /sessions to log in, matching the path that actually works. Worth opening a separate ticket for the API-auth gap if external clients still depend on it.

@wmwolf wmwolf merged commit 06480ef into master May 26, 2026
1 check passed
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.

Search by commit hash

1 participant