Skip to content

flake: TestGetUsersFilter #1488

@flake-investigator

Description

@flake-investigator

CI Run Link: https://github.com/coder/coder/actions/runs/24789059592
Workflow Job: test-go-pg-17
Commit: 7904bed9476393f4627c4e12a60cf18ae3806fca by Michael Suchacz
When: 2026-04-22 16:13 UTC

What failed

  • Package: github.com/coder/coder/v2/coderd
  • Test: TestGetUsersFilter

Evidence from logs

Error: Received unexpected error:
POST http://127.0.0.1:41239/api/v2/users: unexpected status code 400: Validation failed.
    username: Validation failed for tag "username" with value: "uninterested-christiansen672-gh14"
Test: TestGetUsersFilter

Root cause hypothesis

  • Username validation requires <=32 chars (codersdk.NameValid).
  • coderdtest.RandomUsername() uses namesgenerator.UniqueNameWith("-") and can generate 28+ chars.
  • In coderdtest.UsersFilter, when i%7==0 it appends -gh%d to the username. For i=14, the example name became length 33 (uninterested-christiansen672-gh14), causing the 400 validation error. This is intermittent depending on the randomly generated base name length.

Precise assignment analysis

  • Failing line: coderd/coderdtest/users.go in UsersFilter where r.Username += fmt.Sprintf("-gh%d", i) is set before creating the user.
  • Commands used:
    • git log --oneline -10 --follow coderd/coderdtest/users.go
  • The logic for UsersFilter (including the -gh%d mutation) appears to originate in commit 24ab216dd1369aa06d70cebda0605f18008e0b7c by Asher (code-asher). Recent commits (e.g., c5f1a2f) adjust service account options but do not modify the username mutation line.
  • Assigning to: @code-asher (closest owner of the UsersFilter helper and username mutation logic).

Classification

  • Type: Flaky test (random data can exceed username length constraint)
  • No data race indicators found
  • No panic/OOM indicators found

Related issues

  • None found after searching coder/internal for:
    • "TestGetUsersFilter"
    • "UsersFilter username validation failed"
    • "Validation failed" username
    • "unexpected status code 400" users

Proposed fix

  • Truncate or sanitize the username in UsersFilter when appending -gh%d to ensure length <=32 (e.g., shorten base name before suffix), or generate deterministic usernames within length constraints.

Reproduction hints

  • Re-run: go test ./coderd -run TestGetUsersFilter -count=50
  • Intermittent failure when random username length + suffix exceeds 32 characters.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions