-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ux): humanize backend wire values in the UI #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // SPDX-FileCopyrightText: 2026 soundminds.ai | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| JUDGMENT_SOURCE_VALUES, | ||
| OBJECTIVE_METRIC_VALUES, | ||
| PRUNER_VALUES, | ||
| SAMPLER_VALUES, | ||
| } from '@/lib/enums'; | ||
| import { | ||
| formatMetricLabel, | ||
| humanizeWireValue, | ||
| JUDGMENT_SOURCE_LABELS, | ||
| METRIC_LABELS, | ||
| PRUNER_LABELS, | ||
| SAMPLER_LABELS, | ||
| } from '@/lib/labels'; | ||
|
|
||
| describe('humanizeWireValue', () => { | ||
| it('turns snake_case into Title case', () => { | ||
| expect(humanizeWireValue('still_improving')).toBe('Still improving'); | ||
| expect(humanizeWireValue('running')).toBe('Running'); | ||
| expect(humanizeWireValue('too_few_trials')).toBe('Too few trials'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('formatMetricLabel', () => { | ||
| it('renders NDCG@10 with the acronym uppercased and cutoff appended', () => { | ||
| expect(formatMetricLabel('ndcg', 10)).toBe('NDCG@10'); | ||
| expect(formatMetricLabel('map', 5)).toBe('MAP@5'); | ||
| }); | ||
| it('omits @k for cutoff-less metrics (k null)', () => { | ||
| expect(formatMetricLabel('mrr', null)).toBe('MRR'); | ||
| }); | ||
| it('falls back to uppercase for an unknown metric', () => { | ||
| expect(formatMetricLabel('foo', 3)).toBe('FOO@3'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('label maps cover every enum value (no raw value can leak)', () => { | ||
| it('METRIC_LABELS covers OBJECTIVE_METRIC_VALUES', () => { | ||
| for (const m of OBJECTIVE_METRIC_VALUES) expect(METRIC_LABELS[m]).toBeTruthy(); | ||
| }); | ||
| it('SAMPLER_LABELS covers SAMPLER_VALUES', () => { | ||
| for (const s of SAMPLER_VALUES) expect(SAMPLER_LABELS[s]).toBeTruthy(); | ||
| }); | ||
| it('PRUNER_LABELS covers PRUNER_VALUES', () => { | ||
| for (const p of PRUNER_VALUES) expect(PRUNER_LABELS[p]).toBeTruthy(); | ||
| }); | ||
| it('JUDGMENT_SOURCE_LABELS covers JUDGMENT_SOURCE_VALUES', () => { | ||
| for (const s of JUDGMENT_SOURCE_VALUES) expect(JUDGMENT_SOURCE_LABELS[s]).toBeTruthy(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // SPDX-FileCopyrightText: 2026 soundminds.ai | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * Human-readable labels for backend wire values. | ||
| * | ||
| * The backend emits snake_case / lowercase enum values (`pr_merged`, `ndcg`, | ||
| * `tpe`). Those are correct on the wire but must never reach the user verbatim. | ||
| * This module is the single source of display labels, so the same concept reads | ||
| * the same way everywhere (e.g. `NDCG@10`, not `ndcg` on one screen and | ||
| * `NDCG@10` on another). Wire values still come from `@/lib/enums` — these maps | ||
| * only decorate them for display; they never widen the type or bypass the | ||
| * enum-source-of-truth policy. | ||
| */ | ||
|
|
||
| import type { JudgmentSource, ObjectiveMetric, PrunerKind, SamplerKind } from '@/lib/enums'; | ||
|
|
||
| /** Fallback humanizer: `still_improving` → `Still improving`. */ | ||
| export function humanizeWireValue(value: string): string { | ||
| const spaced = value.replace(/_/g, ' '); | ||
| return spaced.charAt(0).toUpperCase() + spaced.slice(1); | ||
| } | ||
|
|
||
| /** Objective-metric acronyms (uppercase; `@k` appended by formatMetricLabel). */ | ||
| export const METRIC_LABELS: Record<ObjectiveMetric, string> = { | ||
| ndcg: 'NDCG', | ||
| map: 'MAP', | ||
| precision: 'Precision', | ||
| recall: 'Recall', | ||
| mrr: 'MRR', | ||
| }; | ||
|
|
||
| /** | ||
| * Canonical rendering of a metric with its cutoff, used everywhere a metric is | ||
| * shown. MRR ignores `k` (evaluates the full ranked list), so `@k` is omitted | ||
| * when `k` is null. | ||
| */ | ||
| export function formatMetricLabel(metric: string, k: number | null): string { | ||
| const base = METRIC_LABELS[metric as ObjectiveMetric] ?? metric.toUpperCase(); | ||
| return k != null ? `${base}@${k}` : base; | ||
| } | ||
|
|
||
| export const SAMPLER_LABELS: Record<SamplerKind, string> = { | ||
| tpe: 'TPE (learns from prior trials)', | ||
| random: 'Random', | ||
| }; | ||
|
|
||
| export const PRUNER_LABELS: Record<PrunerKind, string> = { | ||
| median: 'Median (early-stop weak trials)', | ||
| none: 'None', | ||
| }; | ||
|
|
||
| export const JUDGMENT_SOURCE_LABELS: Record<JudgmentSource, string> = { | ||
| llm: 'LLM-as-judge', | ||
| human: 'Human', | ||
| click: 'Click (UBI)', | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
proposal_prmapping inLABEL_TABLEis redundant becausehumanizeWireValuealready converts'open','closed', and'merged'to'Open','Closed', and'Merged'respectively. Removing this redundant mapping simplifies the code and reduces maintenance overhead.