fix(chat): one gradient across the whole timeline; unknown tones never print undefined (BUG-2319)
Each block now shows its own slice of a single horizontal gradient whose stops sit at the middle of each stretch, instead of 有机会,但费力 carrying its own small gradient. A tone the page does not know (a receipt from another release) shows no words and the neutral fill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
@@ -31265,3 +31265,15 @@
|
||||
- 复审真实路由(同上桩,每题一次):事业 6 段 有机会 / 有机会 / 有机会,但费力 / 较费力 / 有机会,但费力 / 有机会,但费力;感情 5 段 有机会 / 不标 / 有机会,但费力 / 有机会 / 有机会;钱 7 段 较费力 / 不标 / 有机会 / 有机会,但费力 / 较费力 / 有机会 / 有机会。三条回答的时间条和结论卡里没有工程用词、两头的话、「平稳」「偏吃力」;年度底色都写进了结论那一句。截图已换成这一轮。
|
||||
- 测试:`chat-strip-status-2310` 每条规则分整年和窗口内两层各测,加年度底色、结论卡两头的话、判断依据重复行的写法,共 18 条。
|
||||
- 修复版本:分支 `claude/timeline-ruling-2310`(本地提交,未推送)。
|
||||
|
||||
## BUG-2319 | 问答时间条「有机会,但费力」每块各自一段小渐变,整条看着一截一截;旧页面读新回执时显示「undefined」
|
||||
|
||||
- 状态:fixed-pending-verify
|
||||
- 现象:负责人 2026-11-24 手机测试 staging(a30dc7a6):时间条上「有机会,但费力」的每一块都在块内从绿过渡到陶土色,几块并排像一截一截的小渐变;负责人要求「整个时间轴一个渐变」。同一轮里,部署前已打开的页面显示新回答时,时间条说明后出现「undefined」,色块全空白。
|
||||
- 触发条件:(1)回答里有「有机会,但费力」的段;(2)页面在 BUG-2310 部署前打开,未刷新,回答由新服务端生成。
|
||||
- 根因:(1)BUG-2310 复审把「有机会,但费力」做成块内两色渐变,每块按说法各用一个类单独上色,块与块之间没有关系。(2)BUG-2310 前的页面代码按旧取值(steady / heavy)查说法文字,查不到时直接把 undefined 拼进「起止,说法」;新回执的取值(chance / chance_costly / strain / none)它都不认识,样式类也对不上。
|
||||
- 修复:`chat-answer-shape.tsx` 新增 `stripSliceStyles`:整条时间条只算一个横向渐变,每段的颜色放在该段正中,与相邻段自然过渡;每块的背景尺寸取整条宽、位置移到自己那一段,显示整条渐变里属于自己的一片。「有机会,但费力」改成绿和陶土之间的一个中间色(`--strip-chance-costly`),不再块内渐变;图例色块用同一组颜色。说法文字的查找改为认不出就不显示(`toneWords`),颜色认不出就用中性色(`stripToneColor`),任何取值都不会拼出 undefined。还在生成、没有回执时仍是中性色。
|
||||
- 验证:新增 `tests/chat-strip-gradient-2319.test.tsx`(一条渐变、每块切片的尺寸与位置、单段与无回执、未知取值不出 undefined);`chat-answer-shape-2281`、`chat-answer-end-2305` 的类名断言按原值 / 新值 / 原因改为检查同一条渐变与图例颜色;改动文件相关的测试与三个守护测试逐个跑过;tsc、ESLint 0 错误。截图(组件渲染 + 产品样式,非真实页面):`/workspace/eval-read-1116/chat-ux-prototype/build/strip-gradient-2319/`。
|
||||
- 防复发:展示层读回执里的取值时,一律对未知取值兜底(不显示文字、中性色),不得直接拼接查表结果。发版后旧页面读新数据的整体问题见工单 #359。
|
||||
- 关联记录:BUG-2310(时间条按领域判断、新取值)、BUG-2305(时间条样式与回执说法)、BUG-2281(回答结构)。
|
||||
- 修复版本:分支 `claude/strip-gradient`。
|
||||
|
||||
@@ -2093,11 +2093,9 @@ button.chat-chart-resize-handle:active { position: absolute; top: 0; left: -3px;
|
||||
.chat-answer-strip-bar, .chat-answer-strip-ticks { display: grid; gap: 3px; }
|
||||
.chat-answer-strip-segment[data-slot="button"] { display: grid; min-width: 0; height: 44px; place-items: center; padding: 0 2px; border: 0; border-radius: 8px; color: var(--color-ink); font-size: var(--type-caption); font-weight: 400; line-height: 1.2; white-space: normal; cursor: pointer; overflow-wrap: anywhere; }
|
||||
/* BUG-2310: 有机会 / 有机会,但费力 / 较费力; no tag (and receipts stored with the old tones) stays the neutral fill. */
|
||||
.chat-answer-strip-segment.is-pending[data-slot="button"], .chat-answer-strip-segment.is-none[data-slot="button"], .chat-answer-strip-segment.is-steady[data-slot="button"], .chat-answer-strip-segment.is-heavy[data-slot="button"] { background: var(--color-canvas-strong); }
|
||||
.chat-answer-strip-segment.is-strain[data-slot="button"] { background: color-mix(in srgb, var(--color-action) 26%, var(--color-canvas)); }
|
||||
.chat-answer-strip-segment.is-chance[data-slot="button"] { background: color-mix(in srgb, var(--color-success) 22%, var(--color-canvas)); }
|
||||
/* 有机会,但费力: the 有机会 tint running into the 较费力 tint (the warning tint read as brown in dark mode). */
|
||||
.chat-answer-strip-segment.is-chance-costly[data-slot="button"] { background: linear-gradient(90deg, color-mix(in srgb, var(--color-success) 22%, var(--color-canvas)), color-mix(in srgb, var(--color-action) 26%, var(--color-canvas))); }
|
||||
/* BUG-2319: colours are inline slices of one gradient across the bar (chat-answer-shape.tsx stripSliceStyles); a bar with no tones (still streaming) stays neutral. */
|
||||
.chat-answer-strip { --strip-chance: color-mix(in srgb, var(--color-success) 22%, var(--color-canvas)); --strip-strain: color-mix(in srgb, var(--color-action) 26%, var(--color-canvas)); --strip-chance-costly: color-mix(in srgb, var(--color-success) 11%, color-mix(in srgb, var(--color-action) 13%, var(--color-canvas))); --strip-none: var(--color-canvas-strong); }
|
||||
.chat-answer-strip-segment.is-pending[data-slot="button"] { background: var(--strip-none); }
|
||||
.chat-answer-strip-segment[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--color-ink); }
|
||||
/* BUG-2308: the program's tones arrive when the answer completes: the colour eases in instead of flipping. */
|
||||
.chat-answer-strip-segment[data-slot="button"] { transition: background-color 240ms var(--ease-out), box-shadow 180ms var(--ease-out); }
|
||||
@@ -2117,9 +2115,6 @@ button.chat-chart-resize-handle:active { position: absolute; top: 0; left: -3px;
|
||||
/* BUG-2305: the legend and the birth-time line keep a one-line slot while the answer streams (filled at completion). */
|
||||
.chat-answer-strip-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); min-height: 1.5em; color: var(--color-ink-secondary); font-size: var(--type-caption); line-height: 1.5; }
|
||||
.chat-answer-strip-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 3px; vertical-align: -1px; }
|
||||
.chat-answer-strip-legend i.is-strain { background: color-mix(in srgb, var(--color-action) 26%, var(--color-canvas)); }
|
||||
.chat-answer-strip-legend i.is-chance { background: color-mix(in srgb, var(--color-success) 22%, var(--color-canvas)); }
|
||||
.chat-answer-strip-legend i.is-chance-costly { background: linear-gradient(90deg, color-mix(in srgb, var(--color-success) 22%, var(--color-canvas)), color-mix(in srgb, var(--color-action) 26%, var(--color-canvas))); }
|
||||
.chat-answer-shaped .chat-answer-strip-note { margin: 0; color: var(--color-ink); font-size: var(--type-body-md); line-height: 1.6; }
|
||||
.chat-answer-shaped .chat-answer-strip-caveat { min-height: 1.5em; margin: 0; overflow: hidden; color: var(--color-ink-tertiary); font-size: var(--type-caption); line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
|
||||
/* BUG-2305 (owner picked prototype style 3): 判断依据 and 盘面数据 in one muted rounded box, the verdict card's family; a
|
||||
|
||||
@@ -129,6 +129,41 @@ export function stripTicks(segments: readonly TimelineSegment[], weights: readon
|
||||
}
|
||||
|
||||
/** Segment widths in months (at least one each); equal widths when any range could not be read. */
|
||||
/** BUG-2319: the colour token of one stretch's tone; anything unknown (an older or newer receipt) is the neutral fill. */
|
||||
const STRIP_TONE_COLOR: Readonly<Record<string, string>> = {
|
||||
chance: "var(--strip-chance)",
|
||||
chance_costly: "var(--strip-chance-costly)",
|
||||
strain: "var(--strip-strain)",
|
||||
};
|
||||
export function stripToneColor(tone: string | undefined): string {
|
||||
return (tone && STRIP_TONE_COLOR[tone]) || "var(--strip-none)";
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2319: one gradient runs across the whole bar — each stretch's colour sits at its middle and blends into its
|
||||
* neighbours' — and every block shows its own slice of it (background sized to the whole bar, shifted to the block's
|
||||
* place), so the blocks read as one continuous axis instead of each carrying its own small gradient.
|
||||
*/
|
||||
export function stripSliceStyles(weights: readonly number[], tones: readonly (string | undefined)[] | null): Array<React.CSSProperties | undefined> {
|
||||
if (!tones) return weights.map(() => undefined);
|
||||
const total = weights.reduce((sum, weight) => sum + weight, 0) || 1;
|
||||
const starts: number[] = [];
|
||||
let at = 0;
|
||||
for (const weight of weights) { starts.push(at / total); at += weight; }
|
||||
const stops = weights.map((weight, index) => `${stripToneColor(tones[index])} ${((starts[index]! + weight / total / 2) * 100).toFixed(2)}%`);
|
||||
const image = weights.length === 1 ? stripToneColor(tones[0]) : `linear-gradient(90deg, ${stops.join(", ")})`;
|
||||
return weights.map((weight, index) => {
|
||||
const width = weight / total;
|
||||
if (weights.length === 1 || width >= 1) return { background: image };
|
||||
return {
|
||||
backgroundImage: image,
|
||||
backgroundSize: `${(100 / width).toFixed(3)}% 100%`,
|
||||
backgroundPosition: `${((starts[index]! / (1 - width)) * 100).toFixed(3)}% 0`,
|
||||
backgroundRepeat: "no-repeat",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function segmentWeights(segments: readonly TimelineSegment[]): number[] {
|
||||
if (segments.some((segment) => !segment.months)) return segments.map(() => 1);
|
||||
return segments.map((segment) => Math.max(1, segment.months![1] - segment.months![0] + 1));
|
||||
@@ -154,7 +189,12 @@ export function AnswerYearStrip({ timeline, tones, timeSensitive = false, reserv
|
||||
const columns = weights.map((weight) => `minmax(40px, ${weight}fr)`).join(" ");
|
||||
// BUG-2310: the legend lists only the labels present; a stretch with no tag has a neutral fill and no words.
|
||||
const used = known ? (["chance", "chance_costly", "strain"] as const).filter((tone) => known.includes(tone)) : [];
|
||||
const toneWords = (index: number) => (known && ANSWER_TONE_LABELS[known[index]!] ? `,${ANSWER_TONE_LABELS[known[index]!]}` : "");
|
||||
// #359: a tone this page does not know (a receipt written by a newer or older release) shows no words, never "undefined".
|
||||
const toneWords = (index: number) => {
|
||||
const label = known ? (ANSWER_TONE_LABELS as Readonly<Record<string, string | undefined>>)[known[index] as string] : undefined;
|
||||
return typeof label === "string" && label ? `,${label}` : "";
|
||||
};
|
||||
const slices = stripSliceStyles(weights, known);
|
||||
return (
|
||||
// BUG-2308: a strip that arrives in a live row (`reserve`) enters once, as a whole (opacity and transform only).
|
||||
<section className={`chat-answer-strip${reserve ? " is-arriving" : ""}`} aria-label={timeline.heading}>
|
||||
@@ -165,7 +205,8 @@ export function AnswerYearStrip({ timeline, tones, timeSensitive = false, reserv
|
||||
key={`${index}-${segment.title}`}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className={`chat-answer-strip-segment is-${known ? known[index]!.replace("_", "-") : "pending"}`}
|
||||
className={`chat-answer-strip-segment${known ? " is-toned" : " is-pending"}`}
|
||||
style={slices[index]}
|
||||
aria-pressed={index === selected}
|
||||
aria-label={`${segment.title},${segment.range}${toneWords(index)}`}
|
||||
onClick={() => setPicked(index)}
|
||||
@@ -193,7 +234,7 @@ export function AnswerYearStrip({ timeline, tones, timeSensitive = false, reserv
|
||||
</div>
|
||||
{used.length || reserve ? (
|
||||
<div className="chat-answer-strip-legend" aria-hidden="true">
|
||||
{used.map((tone) => <span key={tone}><i className={`is-${tone.replace("_", "-")}`} />{ANSWER_TONE_LABELS[tone]}</span>)}
|
||||
{used.map((tone) => <span key={tone}><i style={{ background: stripToneColor(tone) }} />{ANSWER_TONE_LABELS[tone]}</span>)}
|
||||
</div>
|
||||
) : null}
|
||||
{timeline.note ? <p className="chat-answer-strip-note">{timeline.note}</p> : null}
|
||||
|
||||
@@ -71,12 +71,15 @@ test("BUG-2305: the strip renders for the follow-up (neutral without a receipt;
|
||||
assert.deepEqual([...markup.matchAll(/chat-answer-strip-segment is-([\w-]+)/gu)].map((hit) => hit[1]), ["pending", "pending", "pending"]);
|
||||
assert.doesNotMatch(markup, /strip-when">[^<]*(?:平稳|偏吃力)|aria-label="[^"]*(?:平稳|偏吃力)|chat-answer-strip-legend/u, "no program label from the words");
|
||||
const legacy = renderToStaticMarkup(<ChatMessageContent text={`${ANSWER}\n\n${BASIS}`} structured answerShape={{ areas: [7], tones: ["steady", "heavy", "steady"] }} />);
|
||||
assert.deepEqual([...legacy.matchAll(/chat-answer-strip-segment is-([\w-]+)/gu)].map((hit) => hit[1]), ["none", "none", "none"]);
|
||||
// BUG-2319 原值:每块按说法一个类(is-none 等);新值:上了色的条每块都是 is-toned,颜色是整条渐变里自己那一片(行内样式);
|
||||
// 原因:负责人 2026-11-24「应该是整个时间轴一个渐变」。旧回执的说法全部按中性色。
|
||||
assert.deepEqual([...legacy.matchAll(/chat-answer-strip-segment is-([\w-]+)/gu)].map((hit) => hit[1]), ["toned", "toned", "toned"]);
|
||||
assert.doesNotMatch(legacy, /--strip-(?:chance|strain)/u, "older receipts' tones are all neutral");
|
||||
assert.doesNotMatch(legacy, /strip-when">[^<]*(?:平稳|偏吃力)|aria-label="[^"]*(?:平稳|偏吃力)|chat-answer-strip-legend"[^>]*><span/u);
|
||||
const programmed = renderToStaticMarkup(<ChatMessageContent text={`${ANSWER}\n\n${BASIS}`} structured answerShape={{ areas: [7], tones: ["chance", "chance_costly", "none"] }} />);
|
||||
assert.deepEqual([...programmed.matchAll(/chat-answer-strip-segment is-([\w-]+)/gu)].map((hit) => hit[1]), ["chance", "chance-costly", "none"]);
|
||||
assert.match(programmed, /<i class="is-chance"><\/i>有机会<\/span><span><i class="is-chance-costly"><\/i>有机会,但费力/u);
|
||||
assert.doesNotMatch(programmed, /is-none"><\/i>/u, "no legend entry for a stretch without a tag");
|
||||
assert.match(programmed, /linear-gradient\(90deg, var\(--strip-chance\) [\d.]+%, var\(--strip-chance-costly\) [\d.]+%, var\(--strip-none\) [\d.]+%\)/u);
|
||||
assert.match(programmed, /<i style="background:var\(--strip-chance\)"><\/i>有机会<\/span><span><i style="background:var\(--strip-chance-costly\)"><\/i>有机会,但费力/u);
|
||||
assert.doesNotMatch(programmed, /--strip-none\)"><\/i>/u, "no legend entry for a stretch without a tag");
|
||||
});
|
||||
|
||||
test("BUG-2305: areas — the question's domain first, then the cited rows; period rows add no house of their own", () => {
|
||||
|
||||
@@ -180,9 +180,15 @@ test("BUG-2281: the page — verdict card, chart row with the lit areas, strip,
|
||||
assert.match(markup, /这次看了 4 个地方:性格、事业、每天的工作、收入/u);
|
||||
assert.equal((markup.match(/class="is-lit"/gu) ?? []).length, 4);
|
||||
assert.equal((markup.match(/chat-answer-strip-segment is-/gu) ?? []).length, 3);
|
||||
assert.match(markup, /chat-answer-strip-segment is-strain/u);
|
||||
assert.match(markup, /<i class="is-chance"><\/i>有机会<\/span><span><i class="is-strain"><\/i>较费力/u);
|
||||
assert.doesNotMatch(markup, /<i class="is-chance-costly">|<i class="is-none">/u, "the legend shows only the labels in use, never one for no tag");
|
||||
// BUG-2319 原值:每块按说法各有一个类(is-strain 等),「有机会,但费力」块内各自一段小渐变,图例用同名类;
|
||||
// 新值:整条一个渐变,每块显示自己那一片(行内样式),图例色块用同一组颜色;原因:负责人 2026-11-24「应该是整个时间轴一个渐变」。
|
||||
assert.equal((markup.match(/chat-answer-strip-segment is-toned/gu) ?? []).length, 3);
|
||||
const images = [...markup.matchAll(/background-image:(linear-gradient\([^;"]+\))/gu)].map((m) => m[1]);
|
||||
assert.equal(images.length, 3);
|
||||
assert.equal(new Set(images).size, 1, "every block shows a slice of the same gradient");
|
||||
assert.match(images[0]!, /var\(--strip-none\)[^,]*, var\(--strip-chance\)[^,]*, var\(--strip-strain\)/u);
|
||||
assert.match(markup, /<i style="background:var\(--strip-chance\)"><\/i>有机会<\/span><span><i style="background:var\(--strip-strain\)"><\/i>较费力/u);
|
||||
assert.doesNotMatch(markup, /--strip-chance-costly\)"><\/i>|--strip-none\)"><\/i>/u, "the legend shows only the labels in use, never one for no tag");
|
||||
assert.match(markup, /consult-judgment-basis/u);
|
||||
// BUG-2305 原值:接着问在回答里、「判断依据」「盘面数据」下面(markup 里有 chat-answer-next,排在 consult-judgment-basis 之后);
|
||||
// 新值:回答里没有接着问,回答以依据框(chat-answer-evidence)结束,接着问由对话列表放在操作图标后面(chat-answer-order-2305 测试);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { AnswerYearStrip, stripSliceStyles, stripToneColor } from "../src/components/chat-answer-shape.tsx";
|
||||
|
||||
const timeline = {
|
||||
heading: "接下来一年",
|
||||
note: "",
|
||||
segments: [
|
||||
{ title: "收进", range: "现在到 2026 年 12 月", months: [0, 1] as [number, number], sentence: "进钱的门路是开的。", doThis: "先写清价格。", avoid: "别先垫钱。", raw: "" },
|
||||
{ title: "好谈", range: "2027 年 1 月到 2 月", months: [2, 3] as [number, number], sentence: "好谈。", doThis: "谈。", avoid: "别拖。", raw: "" },
|
||||
{ title: "守住", range: "2027 年 3 月到 6 月", months: [4, 7] as [number, number], sentence: "守住。", doThis: "守。", avoid: "别扩。", raw: "" },
|
||||
],
|
||||
};
|
||||
|
||||
test("BUG-2319: one gradient across the bar; each block is its own slice of it", () => {
|
||||
const styles = stripSliceStyles([2, 2, 4], ["chance_costly", "chance", "strain"]);
|
||||
const images = new Set(styles.map((style) => style?.backgroundImage));
|
||||
assert.equal(images.size, 1, "all blocks share one gradient");
|
||||
assert.match([...images][0]!, /^linear-gradient\(90deg, var\(--strip-chance-costly\) 12\.50%, var\(--strip-chance\) 37\.50%, var\(--strip-strain\) 75\.00%\)$/u);
|
||||
assert.deepEqual(styles.map((style) => style?.backgroundSize), ["400.000% 100%", "400.000% 100%", "200.000% 100%"]);
|
||||
assert.deepEqual(styles.map((style) => style?.backgroundPosition), ["0.000% 0", "33.333% 0", "100.000% 0"]);
|
||||
});
|
||||
|
||||
test("BUG-2319: no tones (streaming) → no inline colour; one block → a plain fill", () => {
|
||||
assert.deepEqual(stripSliceStyles([1, 1], null), [undefined, undefined]);
|
||||
assert.deepEqual(stripSliceStyles([3], ["chance"]), [{ background: "var(--strip-chance)" }]);
|
||||
});
|
||||
|
||||
test("#359: a tone this page does not know is neutral and shows no words — never 「undefined」", () => {
|
||||
assert.equal(stripToneColor("steady"), "var(--strip-none)");
|
||||
assert.equal(stripToneColor(undefined), "var(--strip-none)");
|
||||
const markup = renderToStaticMarkup(
|
||||
<AnswerYearStrip timeline={timeline} tones={["future_tone", "heavy", "chance"] as never} />,
|
||||
);
|
||||
assert.doesNotMatch(markup, /undefined/u);
|
||||
assert.match(markup, /现在到 2026 年 12 月<\/span>/u, "an unknown tone adds no words after the range");
|
||||
assert.match(markup, /2027 年 3 月到 6 月,有机会/u);
|
||||
});
|
||||
Reference in New Issue
Block a user