Skip to content

chore(tests): pin team-usage subtests to seed month window#392

Merged
nijeesh-stream merged 1 commit into
masterfrom
nijeeshjoshy/chore-fix-team-usage-stats-flakes
May 13, 2026
Merged

chore(tests): pin team-usage subtests to seed month window#392
nijeesh-stream merged 1 commit into
masterfrom
nijeeshjoshy/chore-fix-team-usage-stats-flakes

Conversation

@nijeesh-stream

@nijeesh-stream nijeesh-stream commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

TestQueryTeamUsageStats_Integration and TestQueryTeamUsageStats_DataCorrectness mix two kinds of subtests:

  1. Date-filtered queries (StartDate=2026-02-01, Month=2026-02, etc.) — these target the seeded fixture window on the multi-tenant test app and always pass.

  2. No-parameter queries (QueryTeamUsageStats(ctx, nil)) — the backend defaults this to the current month (monthly mode), per controllers/chat/v1/query_team_usage_stats.go:145-150:

    } else {
        isMonthlyMode = true
        now := time.Now()
        fromDate, toDate, _ = parseMonthToDateRange(now.Format("2006-01"))
    }

    The OpenAPI spec confirms: "If neither provided, defaults to current month (monthly mode)".

The multi-tenant test app's seeded fixtures live in 2026-02 (assertAllMetricsExact reads from StartDate 2026-02-18 / EndDate 2026-02-19), so the no-param window only overlaps the seed when CI runs during that month. Outside that month → empty teams → require.Greater fires → whole job goes red.

Fix

Pin every assertion-bearing subtest to the seed-month window via a single const seedMonth = "2026-02". When the seed pipeline rotates, this is the one constant to update. Patches all 9 affected subtests (7 covered by the earlier skip-only attempt + the 2 it missed: "Pagination returns different teams" and "Metric totals non-negative" — both used limit-only / nil and silently passed when teams was empty).

Skip-on-empty was wrong: it would trigger forever (the seed pipeline doesn't refresh to the current month), so CI would be permanently "green on broken infra".

Real fix

Per-PR seeded test app — tracked separately. Backend seed pipeline also doesn't populate the current month, which is a real infra gap.

Test plan

  • go vet ./... clean
  • go test -c -o /dev/null . compiles clean
  • CI green on TestQueryTeamUsageStats_* across the Go matrix

@nijeesh-stream nijeesh-stream force-pushed the nijeeshjoshy/chore-fix-team-usage-stats-flakes branch 2 times, most recently from dd1ddb5 to cf86800 Compare May 12, 2026 17:29
QueryTeamUsageStats defaults the no-parameter overload to the current
month (monthly mode) per backend
controllers/chat/v1/query_team_usage_stats.go:147-150. The
multi-tenant test app's seeded fixtures live in 2026-02
(assertAllMetricsExact reads 2026-02-18 / 2026-02-19), so the default
window only overlaps the seed when CI runs during that month.
Otherwise: empty result, require.Greater fires, the whole job goes red.

Skipping on empty masks a permanent seed gap (skip path triggers
forever once we leave Feb), so pin every assertion-bearing subtest to
the seed month via a single `seedMonth = "2026-02"` constant. Also
covers the two previously silent loop-over-empty subtests that the
prior skip-only patch missed ("Pagination returns different teams",
"Metric totals non-negative"). When the seed pipeline rotates, this
is the one constant to update.

Real fix is a per-PR seeded test app — tracked separately.
@nijeesh-stream nijeesh-stream force-pushed the nijeeshjoshy/chore-fix-team-usage-stats-flakes branch from cf86800 to 1dc7ece Compare May 12, 2026 18:38
@nijeesh-stream nijeesh-stream changed the title chore(tests): skip TestQueryTeamUsageStats when no current-day data chore(tests): pin team-usage subtests to seed month window May 12, 2026
@nijeesh-stream nijeesh-stream merged commit d74f151 into master May 13, 2026
5 checks passed
@nijeesh-stream nijeesh-stream deleted the nijeeshjoshy/chore-fix-team-usage-stats-flakes branch May 13, 2026 09:04
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.

3 participants