Repository navigation
feat: filter chats by diff URL via the q search parameter - #24970
Conversation
Docs preview📖 View docs preview for |
|
/coder-agents-review |
There was a problem hiding this comment.
Clean feature addition. The EXISTS subquery with fan-in through root_chat_id is the right shape for this, the partial index aligns with the query predicates, and the test suite covers root match, sub-agent fan-in, case insensitivity, no-match, and invalid input. Good use of existing patterns (requireSDKError, dbgen.Chat, the subtest structure in TestListChats).
Six reviewers independently noted that Chats() is now the only search function that does not pre-lowercase the entire query string. The change is correct (URL path segments are case-meaningful, and strconv.ParseBool handles standard casings), but the asymmetry with the other six search functions is a maintenance consideration for future filters.
Nit [DEREM-3] coderd/database/sqlc.yaml: DiffUrl breaks the project's naming convention for URL-suffixed identifiers. The sqlc rename section maps every other _url column to the Go-idiomatic URL suffix (callback_url: CallbackURL, avatar_url: AvatarURL, troubleshooting_url: TroubleshootingURL, icon_url: IconURL, oauth2_auth_url: OAuth2AuthURL, oauth2_token_url: OAuth2TokenURL). The new diff_url named parameter is missing from this map, so sqlc generates DiffUrl instead of DiffURL. This propagates into modelqueries.go, search.go, exp_chats.go, and test files. Fix: add diff_url: DiffURL to the rename section and regenerate. (Mafuuu)
3 P3, 1 Nit.
"I tried to build a case against this change and could not." Pariston
🤖 This review was automatically generated with Coder Agents.
| @@ -1266,6 +1266,65 @@ func TestSearchChats(t *testing.T) { | |||
| Query: "archived:", | |||
| ExpectedErrorContains: "cannot start or end with ':'", | |||
| }, | |||
There was a problem hiding this comment.
P3 [DEREM-1] Removing the blanket strings.ToLower(query) from Chats() narrows the set of accepted casings for archived values. Before: any mixed-case like tRuE resolved to "true" via lowering, then strconv.ParseBool succeeded. After: the value passes through in original case, and ParseBool only accepts a fixed set (true, TRUE, True, 1, t, T and their false equivalents).
Realistic impact is low (nobody types tRuE), but the behavioral change has no regression test. The existing ArchivedTrue test uses "archived:true" (already lowercase), so it passes regardless. Adding a row for archived:TRUE would document the new behavior boundary and catch regressions if someone re-adds the blanket lowercase or if a future filter requires different casing rules.
{
Name: "ArchivedTrueUpperCase",
Query: "archived:TRUE",
Expected: database.GetChatsParams{
Archived: sql.NullBool{Bool: true, Valid: true},
},
},(Bisky P3, Hisoka P3)
🤖
There was a problem hiding this comment.
Added an ArchivedTrueUpperCase parser case in c182a93 with a comment explaining the boundary. Locks in archived:TRUE so a regression to blanket lowercasing would fail loudly.
| } | ||
| }) | ||
|
|
||
| t.Run("DiffURLFilter", func(t *testing.T) { |
There was a problem hiding this comment.
P3 [DEREM-2] No E2E test for archived + diff_url composition at the SQL layer. The parser test DiffURLWithArchived proves both fields populate GetChatsParams, but the SQL query has two independent AND CASE clauses whose interaction is never tested against the database. Every chat in the DiffURLFilter fixture is unarchived.
If one chat were archived with a matching diff URL, the default query (archived:false) should exclude it, and archived:true diff_url:"..." should surface it. Neither path is tested. Sketch: archive rootWithPR, then assert the filter excludes it by default and includes it when archived:true is explicit.
(Bisky)
🤖
There was a problem hiding this comment.
Done in c182a93. Added an archived fixture chat with its own diff URL plus two subtests: ArchivedFilteredOut confirms the default archived:false excludes it, and ArchivedTrueComposes confirms archived:true diff_url:"..." surfaces it.
| _, err := client.ListChats(ctx, &codersdk.ListChatsOptions{ | ||
| Query: `diff_url:"ftp://example.com/x"`, | ||
| }) | ||
| requireSDKError(t, err, http.StatusBadRequest) |
There was a problem hiding this comment.
P3 [DEREM-4] InvalidURL test checks only the HTTP status code, not which validation path produced the 400. requireSDKError(t, err, http.StatusBadRequest) confirms a 400 but discards the returned *codersdk.Error without inspecting Validations. The 400 could come from validateDiffURL (the intended path) or from searchTerms rejecting the URL's colons if quote handling changes. Since requireSDKError already returns the error, asserting on the validation field is one line:
sdkErr := requireSDKError(t, err, http.StatusBadRequest)
require.Contains(t, sdkErr.Validations[0].Field, "diff_url")(Chopper)
🤖
There was a problem hiding this comment.
Done in c182a93. The InvalidURL test now captures the returned *codersdk.Error and asserts Validations[0].Field == "diff_url", so the test fails loudly if the 400 ever stops coming from validateDiffURL.
|
Thanks for the review. Addressed all four items in c182a93:
On the broader observation about The commit also picks up regenerated apidoc/swagger output for stdlib Reply authored by a Coder Agent on behalf of @kylecarbs. |
c182a93 to
1d18602
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
All four R1 findings addressed in 1d18602. Four reviewers (Bisky, Mafuuu, Pariston, Meruem) independently verified each fix against the current code.
DEREM-1: ArchivedTrueUpperCase test added, documents the strconv.ParseBool acceptance boundary. DEREM-2: ArchivedFilteredOut and ArchivedTrueComposes confirm the SQL-layer composition. DEREM-3: diff_url: DiffURL in sqlc.yaml, generated code is clean. DEREM-4: InvalidURL now asserts Validations[0].Field == "diff_url".
No new findings. The feature is well-scoped, the SQL and index design is correct, and the test suite covers the contract thoroughly.
"I traced the root_chat_id semantics through subagent.go:937-940... the SQL condition correctly resolves multi-level hierarchies." Pariston
🤖 This review was automatically generated with Coder Agents.
1d18602 to
d36b0fd
Compare
Adds a 'diff_url:' term to the chats list endpoint's q search parameter so callers can look up chats associated with a pull request, merge request, or any other URL stored on the chat's diff status. The match is case-insensitive and surfaces a root chat when the URL lives on a delegated sub-agent's diff status.
- Rename DiffUrl to DiffURL via sqlc.yaml so the generated field follows the project's URL-suffix convention. - Add ArchivedTrueUpperCase parser test to lock in the behavior boundary now that the Chats parser no longer pre-lowercases the full query string. - Assert the validation error field on the InvalidURL E2E test so the assertion exercises validateDiffURL specifically. - Add ArchivedFilteredOut and ArchivedTrueComposes E2E subtests to cover the SQL-level interaction between the archived and diff_url predicates. Also includes regenerated apidoc/swagger output that was already drifted on main from the stdlib net/url documentation update.
d36b0fd to
dcb2b64
Compare
Adds a
diff_url:term to theqsearch parameter onGET /api/experimental/chatsso callers can look up the chat associated with a particular pull request, merge request, or any other URL persisted on the chat's diff status.Match is case-insensitive. When the URL lives on a delegated sub-agent's diff status, the parent chat is returned so the relationship surfaces from a single lookup.
Design notes
chat_diff_statuses.urlcolumn rather than introducing apr:vocabulary, since the SDK already documents the URL as "may point to a pull request or a branch page depending on whether a PR has been opened." Works for GitHub PRs, GitLab MRs, branch pages, etc.archived:. The two terms can be combined:q=archived:true diff_url:"...".qstring up front, which would mangle URL path segments. Switched to lowercasing only the field key insidesearchTerms(already happens there) and keeping the value as the caller typed it. The SQL comparison lowercases on both sides.diff_urlmust be a syntactically valid HTTP(S) URL with a non-empty host. No forge-specific validation.idx_chat_diff_statuses_url_loweronLOWER(url)so the lookup is cheap even on large datasets.EXISTSclause matches when the URL lives on the chat itself or any chat withroot_chat_idequal to the chat's id, so a delegated sub-agent's PR pulls in its parent.pr:any/pr:noneand a forge-agnostic state filter (diff_state:open|merged|closed) were intentionally left out of this change. They couple cleanly to a second forge or a clearer product call, and shipping them now would lock in vocabulary we may want to revisit.Tests
coderd/searchquery: parser tests for valid URLs, case handling (key insensitive, value preserved), composition witharchived:, and validation errors (non-HTTP scheme, missing host, malformed URL).coderd/exp_chats_test.go: end-to-end coverage hittingListChats. Verifies a root chat matches its own URL, a parent chat surfaces when only a sub-agent has the URL, lookups are case-insensitive, non-matching URLs return empty, and invalid URLs return400.This PR was authored by a Coder Agent on behalf of @kylecarbs.