Skip to content

feat(#640): stats --label and --since filters for cohort measurement - #642

Merged
admarble merged 4 commits into
mainfrom
feature/640-feat-stats-add-label-and-since-filters-for-coh
May 14, 2026
Merged

admarble merged 4 commits into
mainfrom
feature/640-feat-stats-add-label-and-since-filters-for-coh

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Add --label <name> and --since <YYYY-MM-DD> to sequant stats for cohort measurement. Both filters apply to every output mode (table, --json, --csv, --detailed) and compose with AND. Obsoletes the manual jq workflow from #462's closeout.

  • New filterLogs(logs, { label, since }) helper runs after parseLogFile, before calculateStats / calculateDetailedAnalytics. A run is kept iff some issue in log.issues[] carries the label (mirrors the existing label-segment scan at stats.ts:744-761) and log.startTime >= <since>T00:00:00Z.
  • Filters force log-mode (bypass the metrics-first path). The metrics file's MetricRun.issues: number[] schema has no per-issue labels, so per-label filtering against metrics is impossible — documented inline.
  • Zero-match emits a clear "No matching runs" in the active output format via emitNoMatchingRuns (parallel shapes: JSON {error,runs:[]}, header-only CSV, headerBox + warning for human).
  • Invalid --since exits code 1 with a console.error matching the locks.ts pattern.

AC Coverage

  • AC-1: --label filters table / --json / --csv / --detailed
  • AC-2: --since YYYY-MM-DD filters by startTime (UTC midnight cutoff)
  • AC-3: --label and --since compose (AND)
  • AC-4: Zero-match → "No matching runs" in existing empty-branch format
  • AC-5: 5 new tests — label match, label miss/zero-match, --since cutoff, composed AND, invalid date
  • AC-6: bin/cli.ts registers both flags; README + docs/reference/analytics.md documented

Files Changed

  • src/commands/stats.ts — filterLogs + emitNoMatchingRuns helpers; gate wired into 4 output branches
  • bin/cli.ts — register .option("--label") + .option("--since")
  • src/commands/stats.test.ts — 5 new tests (18/18 total pass)
  • README.md + docs/reference/analytics.md — docs
  • CHANGELOG.md — [Unreleased] / Added

Test plan

  • npx vitest run src/commands/stats.test.ts → 18/18 pass
  • npm run build → clean
  • npm run lint → clean
  • CLI smoke: --help shows both flags
  • End-to-end: positive single filter, positive AND-composed filter, zero-match CSV, invalid-date error

Closes #640

admarble added 4 commits May 13, 2026 21:37
- Filter applied after parseLogFile, before calculateStats / calculateDetailedAnalytics
- Forces log-mode (bypasses metrics-first path) when either filter set; metrics
  schema carries only issue numbers, so per-label filtering is impossible there
- Zero-match emits 'No matching runs' in the active output format (JSON/CSV/human)
- Invalid --since exits 1 with a clear error, matching the locks.ts pattern
- 5 new tests: label match, label miss, --since cutoff, composed AND, invalid date
- Documented in README + docs/reference/analytics.md
…-detailed+filter test, README cleanup

- Strict YYYY-MM-DD regex before Date.parse for --since validation.
  Rejects 2026/01/01, 2026-1-1, Jan 1 2026, 2026-13-45 — all of which
  Date.parse would otherwise accept with engine-dependent UTC interpretation.
  Error message 'Expected YYYY-MM-DD' is now honest.
- Positive AND-composed unit test: --label bug --since 2026-02-01 against
  the Jan/Mar fixture survives one run (mar). Complements the existing
  zero-match composition test.
- New --detailed + filter test: --detailed --label nonexistent emits
  'No matching runs' and does NOT show QA Verdicts / Weekly Trends /
  Success by Label sections, proving the human-path short-circuit runs
  before the --detailed block.
- README: cohort-filtering example moved out of the code block into a
  standalone sentence with a deep link to docs/reference/analytics.md.
@admarble
admarble merged commit e929b74 into main May 14, 2026
5 checks passed
@admarble
admarble deleted the feature/640-feat-stats-add-label-and-since-filters-for-coh branch May 14, 2026 02:53
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.

feat(stats): add --label and --since filters for cohort measurement

1 participant