Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 4784bb3

Browse files
os-teslaclaude
andauthored
fix(plugin-detail): the summary chip reads the declared percent source (#9168)
The `summaryFields` chip beside the record H1 scaled a stored `percent` by a rule of its own -- a pass-through above 1, a scale-by-100 at or below it -- while `percentDisplayValue` in `@object-ui/core`, the declared single source of truth that the list cell (`formatPercent` / `PercentCellRenderer`), the dashboard measure (`formatMeasure`) and the grid column summary all reach, uses the symmetric `value > -1 && value < 1`. The two disagreed at exactly 1 and at every value at or below -1, so one stored record read `100%` on the chip and `1%` everywhere else. The local predicate is deleted rather than realigned: aligning it would leave two rules agreeing by coincidence, which is the shape that produced the drift. Only the SCALING half moves; the chip keeps its own text convention, and the pin records that so the remaining half is a measurement rather than a silence. Part of objectui#9071 Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 50798f3 commit 4784bb3

5 files changed

Lines changed: 334 additions & 56 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
The `summaryFields` chip beside the record H1 reads the repo's percent authority
6+
instead of a drifted copy of it (objectui#9071).
7+
8+
The chip scaled a stored `percent` by a rule of its own — a pass-through above 1,
9+
a scale-by-100 at or below it — while `percentDisplayValue` in `@object-ui/core`,
10+
the declared single source of truth that the list cell (`formatPercent` /
11+
`PercentCellRenderer`), the dashboard measure (`formatMeasure`) and the grid
12+
column summary all reach, uses the symmetric `value > -1 && value < 1`. The local
13+
predicate is deleted, not realigned.
14+
15+
**Two values move, and only these two.** They are exactly where the two rules
16+
disagreed:
17+
18+
- a stored `1` now reads `1%` beside a bar at 1%, where it read `100%` beside a
19+
full bar — one percentage point, the answer every other surface already gave;
20+
- a stored value at or below `-1` is passed through: a stored `-5` now reads
21+
`-5%` where it read `-500%`. The bar is unchanged for these inputs, since any
22+
negative clamps to an empty track either way.
23+
24+
Everything inside the band the two rules always agreed on is byte-identical: a
25+
stored `0.25` still reads `25%`, `0.123` still reads `12.3%`, `12.3` still reads
26+
`12.3%`, `250` still reads `250%`, and the float-residue trim that keeps `0.07`
27+
reading `7%` rather than `7.000000000000001%` is unchanged.

‎packages/plugin-detail/src/DetailView.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,13 @@ export const DetailView: React.FC<DetailViewProps> = ({
11281128
// text states it, the bar below draws it clamped to
11291129
// its track. They used to scale `num` by two different
11301130
// rules, so a stored `0.123` said `0.123%` beside a bar
1131-
// at 12.3% (objectui#8728). Which rule survived, and
1132-
// why it is not the repo-wide one, is in
1131+
// at 12.3% (objectui#8728). That number is now the
1132+
// repo's — `percentDisplayValue` in `@object-ui/core`,
1133+
// the same authority the list cell and the dashboard
1134+
// measure read, so one record cannot state two
1135+
// percentages in two places (objectui#9071). Which
1136+
// predicate was deleted to get there, and which half of
1137+
// that authority this chip still does not take, are in
11331138
// `./summaryChipPercent`.
11341139
const points = summaryChipPercentPoints(num);
11351140
display = `${points}%`;

‎packages/plugin-detail/src/__tests__/summaryChip.percentOneRule-8728.test.tsx‎

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,23 @@
4444
* ## The boundary rows
4545
*
4646
* `EXACTLY 1` is the fork triage named: is a stored `1` one percent or one
47-
* hundred? This chip answers 100%, because that is what its bar already drew
48-
* and the ruling was that the text follows the bar. ⚠️ That answer is this
49-
* chip's alone — `percentDisplayValue` in `@object-ui/core`, and so the list
50-
* cell, the dashboard measure and the grid column summary, all render a stored
51-
* `1` as `1%`. The census and the three routes out are objectui#9071; the row
52-
* below exists so the answer is PINNED rather than incidental, and so that
53-
* card's PR has to state which way it is moving.
47+
* hundred? This chip used to answer 100%, because that is what its bar already
48+
* drew and the ruling here was that the text follows the bar — an answer that
49+
* was this chip's alone, while `percentDisplayValue` in `@object-ui/core`, and
50+
* so the list cell, the dashboard measure and the grid column summary, all
51+
* rendered a stored `1` as `1%`.
52+
*
53+
* ⭐ objectui#9071 MOVED IT, and this is the row that recorded which way. That
54+
* card took the census this one asked for, found the local predicate to be the
55+
* only spelling of its kind on this side of the tree, and deleted it in favour
56+
* of the declared source. A stored `1` now reads `1%` here as it always did
57+
* everywhere else, and a stored `-5` reads `-5%` rather than `-500%`. The rows
58+
* below carry the new answers; what did NOT move — every value inside the band
59+
* the two rules always agreed on, the control among them — is the rest of this
60+
* table, unchanged. The two-places pin is
61+
* `summaryChip.percentSource-9071.test.tsx`; this file keeps stating the
62+
* relation objectui#8728 is about, that the chip's two halves never disagree
63+
* with EACH OTHER.
5464
*
5565
* ## Instruments
5666
*
@@ -144,9 +154,9 @@ const ROWS: Row[] = [
144154
// CONTROL. Already percentage points, so nothing about it may move.
145155
{ what: 'CONTROL — a value already in points is untouched', stored: 12.3, text: '12.3%' },
146156
{ what: 'zero', stored: 0, text: '0%' },
147-
// THE FORK. See the header: this chip's answer, pinned, and objectui#9071's
148-
// to move.
149-
{ what: 'EXACTLY 1 — this chip reads it as a ratio', stored: 1, text: '100%' },
157+
// THE FORK, after objectui#9071 moved it. See the header: one percentage
158+
// point, the answer every other band already gave.
159+
{ what: 'EXACTLY 1 — one percentage point, as everywhere else', stored: 1, text: '1%' },
150160
{ what: 'just above 1 — the other side of the same boundary', stored: 1.5, text: '1.5%' },
151161
// Agreement has to survive the clamp: the text keeps the real number, the
152162
// bar saturates. A row that only ever tested unclamped values would let a
@@ -155,11 +165,13 @@ const ROWS: Row[] = [
155165
// The residue row. `0.07 * 100` is `7.000000000000001` in binary floating
156166
// point — invisible as a CSS width, unreadable as a label.
157167
{ what: 'a ratio whose scaling carries float residue', stored: 0.07, text: '7%' },
158-
// The drift, now visible on both halves instead of one. Before the fix the
159-
// text read `-5%` here while the bar drew an empty track; the bar's rule
160-
// scales it, and the ruling was that the text follows the bar. Recorded on
161-
// objectui#9071 with the census that names it.
162-
{ what: 'a negative at or below -1 — moves with the bar\'s rule', stored: -5, text: '-500%' },
168+
// The other end of the same boundary. objectui#8728 moved this text to
169+
// `-500%` because the bar's rule scaled it and the ruling was that the text
170+
// follows the bar; objectui#9071 then replaced that rule with the declared
171+
// source, which passes a value at or below -1 straight through. The bar is
172+
// unchanged across both cards — any negative clamps to an empty track — so
173+
// this row only ever moved on the half that reads the number.
174+
{ what: 'a negative at or below -1 — passed through by the shared rule', stored: -5, text: '-5%' },
163175
];
164176

165177
describe('summary chip percent — one stored number, one percentage (objectui#8728)', () => {
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* ONE record, TWO places, ONE number (objectui#9071).
11+
*
12+
* ## What this pins, and why it is not "the chip's new number is right"
13+
*
14+
* The chip beside the record H1 scaled a stored `percent` by a rule of its
15+
* own — a pass-through above 1, a scale-by-100 at or below it — while the
16+
* declared single source of truth (`percentDisplayValue` in
17+
* `@object-ui/core`, which the list cell reaches through `formatPercent`)
18+
* uses the symmetric `value > -1 && value < 1`. The two rules disagree at
19+
* EXACTLY 1 and at every value at or below -1.
20+
*
21+
* Triage's judgement is the acceptance, and it is about DISAGREEMENT, not
22+
* about the chip:
23+
*
24+
* "a stored `1` renders `100%` in the chip and `1%` everywhere else" — the
25+
* same record showing two different numbers in two places is the kind of
26+
* disagreement a user reports as a data bug rather than a formatting one.
27+
*
28+
* So every case here renders BOTH surfaces from the SAME stored value and the
29+
* SAME field, and asserts they agree. A pin that only checked the chip could
30+
* not fail for the reason this card exists: it would go green on a chip that
31+
* had simply moved to a fourth rule of its own.
32+
*
33+
* ## Two instruments, because neither alone covers the disagreement set
34+
*
35+
* - **The stated text.** The only instrument that reaches a value at or below
36+
* -1: both bars clamp a negative to an empty track, so the bar cannot tell
37+
* `-5%` from `-500%`. ⚠️ Valid only where the two surfaces' CONVENTIONS
38+
* coincide — the chip appends a bare `%` to the full number, the cell renders
39+
* through the locale's percent affix at the field's precision (0 by default).
40+
* Every row asserted by text below scales to an integral count of percentage
41+
* points under four digits, where the two conventions are byte-identical.
42+
* The last case pins a value where they are NOT, so the half this card does
43+
* not fix is a recorded fact rather than a silence.
44+
* - **The drawn bar.** Read off each surface's own fill width, before any
45+
* rounding, so it states agreement on the scaled MAGNITUDE independently of
46+
* how either side spells it.
47+
*
48+
* ## The live control
49+
*
50+
* `0.25` is inside the band where the two rules already agreed before this
51+
* change. It renders identically in both places on both legs of the ablation —
52+
* if it ever moves, the repair reached further than the boundary.
53+
*/
54+
55+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
56+
import { render, cleanup } from '@testing-library/react';
57+
import * as React from 'react';
58+
import { I18nProvider, LocalizationProvider } from '@object-ui/i18n';
59+
import { PercentCellRenderer } from '@object-ui/fields';
60+
import { DetailView } from '../DetailView';
61+
import type { DetailViewSchema, FieldMetadata } from '@object-ui/types';
62+
63+
/**
64+
* `useRecordEditable` falls back to the GLOBAL fetch with no
65+
* `SchemaRendererProvider` in the tree; under happy-dom that is a real request.
66+
* Served from a double so no case here depends on the network.
67+
*/
68+
beforeEach(() => {
69+
vi.stubGlobal(
70+
'fetch',
71+
vi.fn(async () => ({ ok: true, json: async () => ({ record: { visible: true } }) })),
72+
);
73+
});
74+
afterEach(() => {
75+
vi.unstubAllGlobals();
76+
cleanup();
77+
});
78+
79+
/**
80+
* The field both surfaces are handed. `ratio` is deliberate: it does NOT match
81+
* the cell renderer's whole-percent name pattern (`progress` / `completion`),
82+
* so both surfaces are on the fraction-inferring path this card is about.
83+
*/
84+
const FIELD: FieldMetadata = { name: 'ratio', label: 'Ratio', type: 'percent' };
85+
86+
interface Rendered {
87+
/** What the surface SAYS, whitespace-collapsed. */
88+
text: string;
89+
/** What the surface DRAWS, read off its own fill width. */
90+
bar: number;
91+
}
92+
93+
/** Place one: the `summaryFields` chip beside the record H1. */
94+
function renderChip(stored: number): Rendered {
95+
const container = render(
96+
<DetailView
97+
schema={
98+
{
99+
type: 'record:details',
100+
objectName: 'account',
101+
summaryFields: ['ratio'],
102+
fields: [{ ...FIELD }],
103+
data: { id: 'A9', name: 'Acme', ratio: stored },
104+
} as unknown as DetailViewSchema
105+
}
106+
/>,
107+
).container;
108+
const chip = container.querySelector<HTMLElement>('[data-summary-chip="ratio"]');
109+
expect(chip, 'a summary chip for "ratio" is beside the H1').not.toBeNull();
110+
const fill = chip!.querySelector<HTMLElement>('[aria-hidden] span[style]');
111+
expect(fill, 'the chip draws its own bar fill').not.toBeNull();
112+
return { text: (chip!.textContent ?? '').replace(/\s+/g, ' ').trim(), bar: pct(fill!.style.width) };
113+
}
114+
115+
/**
116+
* Place two: the list cell — `PercentCellRenderer`, the surface that reaches
117+
* `percentDisplayValue` through `formatPercent`. Mounted under an explicit
118+
* `en` session so the comparison is a property of the SCALING and not of
119+
* whatever locale the runner happens to carry.
120+
*/
121+
function renderCell(stored: number): Rendered {
122+
const container = render(
123+
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }} persistLanguage={false}>
124+
<LocalizationProvider value={{ locale: 'en' }}>
125+
<PercentCellRenderer value={stored} field={{ ...FIELD }} />
126+
</LocalizationProvider>
127+
</I18nProvider>,
128+
).container;
129+
const bar = container.querySelector<HTMLElement>('[role="progressbar"] div[style]');
130+
expect(bar, 'the cell draws its own bar fill').not.toBeNull();
131+
const value = container.querySelector<HTMLElement>('span.tabular-nums');
132+
expect(value, 'the cell states its own percentage').not.toBeNull();
133+
return { text: (value!.textContent ?? '').replace(/\s+/g, ' ').trim(), bar: pct(bar!.style.width) };
134+
}
135+
136+
function pct(width: string): number {
137+
expect(width, 'the fill width is a percentage').toMatch(/%$/);
138+
return Number(width.slice(0, -1));
139+
}
140+
141+
interface Row {
142+
what: string;
143+
stored: number;
144+
/** The one percentage BOTH surfaces state. */
145+
text: string;
146+
/** The one magnitude BOTH surfaces draw, after each clamps to its track. */
147+
bar: number;
148+
}
149+
150+
const ROWS: Row[] = [
151+
// LIVE CONTROL — inside the band where the two rules already agreed. Green
152+
// before this change and green after; it is the row that says the repair did
153+
// not reach past the boundary.
154+
{ what: 'CONTROL — inside the band both rules already agreed on', stored: 0.25, text: '25%', bar: 25 },
155+
// THE FORK objectui#8728 pinned and handed here. The chip read a stored 1 as
156+
// a ratio and said `100%` beside a full bar; every other band reads it as one
157+
// percentage point.
158+
{ what: 'EXACTLY 1 — one percentage point, not one hundred', stored: 1, text: '1%', bar: 1 },
159+
// The far edge of the same boundary. `percentDisplayValue` passes -1 through;
160+
// the chip's rule scaled it to -100.
161+
{ what: 'EXACTLY -1 — the symmetric edge the chip did not have', stored: -1, text: '-1%', bar: 0 },
162+
// Below -1. Bars are useless here (both clamp to an empty track), which is
163+
// why the text instrument exists.
164+
{ what: 'below -1 — the half the bar cannot see', stored: -5, text: '-5%', bar: 0 },
165+
];
166+
167+
describe('the summary chip reads the declared percent source (objectui#9071)', () => {
168+
it.each(ROWS)('$what: a stored $stored reads $text in BOTH places', ({ stored, text, bar }) => {
169+
const chip = renderChip(stored);
170+
cleanup();
171+
const cell = renderCell(stored);
172+
173+
expect(
174+
chip.text,
175+
'THE PIN: the chip and the list cell state the same percentage for the same stored value',
176+
).toBe(cell.text);
177+
expect(chip.text, 'and it is this percentage').toBe(text);
178+
expect(chip.bar, 'the chip draws what the cell draws').toBe(cell.bar);
179+
expect(chip.bar, 'and it is this magnitude').toBe(bar);
180+
});
181+
182+
/**
183+
* The relation stated once over the whole table rather than row by row, so a
184+
* repair that fixed one row and broke another is red here even if someone
185+
* edited that row's expected string to match.
186+
*/
187+
it('never states one percentage in the chip and another in the cell', () => {
188+
const disagreements = ROWS.filter(({ stored }) => {
189+
const chip = renderChip(stored);
190+
cleanup();
191+
const cell = renderCell(stored);
192+
cleanup();
193+
return chip.text !== cell.text || chip.bar !== cell.bar;
194+
});
195+
expect(disagreements.map((r) => r.stored), 'every stored value reads the same in both places').toEqual([]);
196+
});
197+
198+
/**
199+
* ⚠️ THE HALF THIS CARD DOES NOT FIX, pinned so it cannot go quiet.
200+
*
201+
* `percentDisplayValue`'s doc comment requires a third surface to take BOTH
202+
* halves — the scaling AND the convention. This card moves the SCALING only,
203+
* because taking the convention half would change what the chip prints for
204+
* values it renders correctly today: the cell rounds to the field's precision
205+
* (0 by default) and groups through `Intl`, the chip states the full number
206+
* with a bare `%`. So a stored `12.3` still reads `12.3%` on the chip and
207+
* `12%` in the cell — DIFFERENT SPELLINGS OF THE SAME MAGNITUDE, which the
208+
* bars prove by agreeing exactly.
209+
*/
210+
it('agrees on the magnitude even where the two surfaces spell it differently', () => {
211+
const chip = renderChip(12.3);
212+
cleanup();
213+
const cell = renderCell(12.3);
214+
215+
expect(chip.bar, 'the scaling agrees — this is what objectui#9071 repaired').toBe(cell.bar);
216+
expect(chip.bar, 'both draw 12.3 points').toBe(12.3);
217+
expect(chip.text, 'the chip states the full number with a bare percent sign').toBe('12.3%');
218+
expect(cell.text, "the cell rounds to the field's precision and renders the locale's affix").toBe('12%');
219+
});
220+
});

0 commit comments

Comments
 (0)