Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,24 @@ export function episodeQuestionGroups<T extends {episode_id: string}>(result: Tr
});
}

// Keep headline values readable without rounding a nonzero measurement to zero.
// Full native precision remains available in the existing evidence/details.
function formatNativeMeasurement(value: number, zh: boolean, signed = false) {
const magnitude = Math.abs(value);
const scientific = magnitude > 0 && (magnitude < 0.0001 || magnitude >= 1_000_000);
return new Intl.NumberFormat(zh ? "zh-CN" : "en", {
maximumFractionDigits: 4,
...(scientific ? {notation: "scientific", maximumSignificantDigits: 4} : {}),
signDisplay: signed ? "exceptZero" : "auto",
}).format(value === 0 ? 0 : value);
}

// Format the native owner's existing projection, without deriving a gain,
// deciding adoption, or borrowing values from another pack.
function RetainedImprovement({native, zh, onCitation}: {native: NonNullable<ResearchProgressPack["native_outcomes"]>; zh: boolean; onCitation: (citation: AssessmentCitation, origin?: HTMLButtonElement) => void}) {
const outcomes = native.projection, improvement = outcomes.retained_improvement;
if (!improvement) return null;
const format = (value: number) => new Intl.NumberFormat(zh ? "zh-CN" : "en", {maximumSignificantDigits: 10, signDisplay: "exceptZero"}).format(value);
const format = (value: number) => formatNativeMeasurement(value, zh, true);
const label = zh ? "已采用成果增量" : "Retained improvement";
return <section className="research-retained-improvement" aria-label={label}>
<div className="research-progress-title"><h4>{label}</h4><ContextHelp label={zh ? "成果增量说明" : "About retained improvement"}>
Expand All @@ -113,7 +125,7 @@ function RetainedImprovement({native, zh, onCitation}: {native: NonNullable<Rese
{native.applicability === "historical" ? <p className="research-progress-warning" role="status">{zh ? "历史捕获 · 当前结果未核验" : "Historical capture · current result unverified"}</p> : null}
<details><summary aria-label={`${label}: ${improvement.value === null ? (zh ? "未知" : "Unknown") : `${format(improvement.value)} ${outcomes.metric.unit}`}`}>
<strong data-retained-improvement>{improvement.value === null ? "—" : format(improvement.value)}</strong>
<span>{improvement.value === null ? (zh ? "未知" : "Unknown") : outcomes.metric.unit} · {outcomes.metric.name}{improvement.baseline ? ` · ${zh ? "基线" : "baseline"} ${improvement.baseline.value}` : ""}</span><ChevronDown size={14} aria-hidden/>
<span>{improvement.value === null ? (zh ? "未知" : "Unknown") : outcomes.metric.unit} · {outcomes.metric.name}{improvement.baseline ? ` · ${zh ? "基线" : "baseline"} ${formatNativeMeasurement(improvement.baseline.value, zh)}` : ""}</span><ChevronDown size={14} aria-hidden/>
</summary><dl>
{([[improvement.baseline, zh ? "比较基线" : "Comparison baseline"], [outcomes.retained, zh ? "实际保留" : "Actually retained"]] as const).map(([point, title]) => <div key={title}><dt>{title}</dt><dd>{point ? <button type="button" onClick={event => onCitation(point.citation, event.currentTarget)}>{String(point.value)} · {point.candidate_ref}<ArrowUpRight size={13} aria-hidden/></button> : (zh ? "未知" : "Unknown")}</dd></div>)}
<div><dt>{zh ? "保留依据" : "Retention evidence"}</dt><dd>{improvement.retention_citation ? <button type="button" onClick={event => onCitation(improvement.retention_citation!, event.currentTarget)}>{zh ? "查看原文" : "Read original evidence"}<ArrowUpRight size={13} aria-hidden/></button> : (zh ? "未采集" : "Uncaptured")}</dd></div>
Expand All @@ -133,7 +145,7 @@ function NativeResults({native, zh, onCitation}: {native: ResearchProgressPack["
const point = outcomes[key];
return <div key={key} data-native-point={key}><dt>{zh ? cn : en}</dt><dd>{point ?
<button type="button" onClick={event => onCitation(point.citation, event.currentTarget)} aria-label={`${zh ? cn : en}: ${String(point.value)} ${outcomes.metric.unit} · ${zh ? "查看原始证据" : "Read original evidence"}`}>
<strong>{String(point.value)}</strong>{key === "best_valid" ? <span className="research-native-unit">{outcomes.metric.unit}</span> : null}<FileText size={14} aria-hidden/>
<strong>{formatNativeMeasurement(point.value, zh)}</strong>{key === "best_valid" ? <span className="research-native-unit">{outcomes.metric.unit}</span> : null}<FileText size={14} aria-hidden/>
</button> : <span className="research-native-unknown">{zh ? "未知" : "Unknown"}{key === "best_valid" ? <span className="research-native-unit"> · {outcomes.metric.unit}</span> : null}</span>}</dd></div>;
};
return <section className="research-native-results" aria-label={zh ? "原生测量" : "Native measurements"}>
Expand All @@ -158,7 +170,7 @@ function NativeResults({native, zh, onCitation}: {native: ResearchProgressPack["
<div><dt>{zh ? "来源" : "Source"}</dt><dd>{native.artifact}<br/><code>{native.artifact_sha256}</code></dd></div></dl>
<dl>{points.map(([key, cn, en]) => {
const point = outcomes[key];
return point ? <div key={key}><dt>{zh ? cn : en}</dt><dd><code>{point.candidate_ref}</code><br/>{zh ? "提交" : "Submission"} {point.submission_index} · {zh ? "提交时间" : "Submitted at"}: {point.submitted_at ?? (zh ? "未知" : "Unknown")}<br/>{zh ? "收到结果" : "Result received"}: {point.observed_at}</dd></div> : null;
return point ? <div key={key}><dt>{zh ? cn : en}</dt><dd>{String(point.value)} {outcomes.metric.unit}<br/><code>{point.candidate_ref}</code><br/>{zh ? "提交" : "Submission"} {point.submission_index} · {zh ? "提交时间" : "Submitted at"}: {point.submitted_at ?? (zh ? "未知" : "Unknown")}<br/>{zh ? "收到结果" : "Result received"}: {point.observed_at}</dd></div> : null;
})}</dl>
<ul>{outcomes.limitations.map((line, i) => <li key={i}>{line}</li>)}</ul>
</details>
Expand Down
20 changes: 18 additions & 2 deletions examples/personal-workspace-browser/research-native-reading.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export const researchNativeReadingScenario = {
{id: "partial", values: [8, 7, 9], higher: true, retained: 1, partial: true, expected: [9, null, 9, 7]},
{id: "empty", values: [], higher: true, retained: null, partial: true, expected: [null, null, null, null]},
{id: "long-unit", values: [3, 1, 2], higher: false, retained: 0, unit: "synthetic-unit-".repeat(5), expected: [1, 3, 2, 3]},
{id: "decimal", values: [0.8123456789012345, 0.8765432109876543, 0.8123456789012345], higher: true, retained: 1,
expected: [0.8765432109876543, 0.8123456789012345, 0.8123456789012345, 0.8765432109876543], display: ["0.8765", "0.8123", "0.8123", "0.8765"], gain: "+0.0642"},
{id: "tiny", values: [0.0000001234567890123456, 0.0000001123456789012345], higher: true, retained: 1,
expected: [0.0000001234567890123456, 0.0000001234567890123456, 0.0000001123456789012345, 0.0000001123456789012345], display: ["1.235E-7", "1.235E-7", "1.123E-7", "1.123E-7"], gain: "-1.111E-8"},
{id: "large", values: [123456789.12345679], higher: true, retained: 0,
expected: [123456789.12345679, 123456789.12345679, 123456789.12345679, 123456789.12345679], display: ["1.235E8", "1.235E8", "1.235E8", "1.235E8"], gain: "0"},
];
const root = await mkdtemp(resolve(tmpdir(), "loopx-native-reading-"));
let owner, page;
Expand All @@ -40,6 +46,8 @@ export const researchNativeReadingScenario = {
submitted_at: null, observed_at: `2026-01-01T00:0${index + 1}:00Z`, valid: value !== null, value,
citation: {source_id: "facts", first_line: index + 1, last_line: index + 1},
}));
if (c.gain) native.comparison = {baseline_result_id: "result-0",
retention_citation: {source_id: "facts", first_line: c.retained + 1, last_line: c.retained + 1}};
const text = c.values.map((v, i) => `Synthetic observation ${i}: value ${v ?? "unknown"}; valid ${v !== null}.`).join("\n") || "No measurements captured.";
a.artifacts["facts.txt"] = text;
a.artifacts["native.json"] = JSON.stringify(native);
Expand Down Expand Up @@ -67,8 +75,12 @@ export const researchNativeReadingScenario = {
if (c.expected[index] === null) {
assert.equal(await reading.locator("button").count(), 0);
assert.match(await reading.innerText(), /未知/);
} else assert.equal(await reading.locator("strong").textContent(), String(c.expected[index]));
} else {
assert.equal(await reading.locator("strong").textContent(), c.display?.[index] ?? String(c.expected[index]));
assert((await reading.locator("button").getAttribute("aria-label")).includes(String(c.expected[index])), "The exact native value remains bound to the evidence action");
}
}
if (c.gain) assert.equal(await page.locator("[data-retained-improvement]").textContent(), c.gain);
assert.match(await native.innerText(), c.higher ? /越高越好/ : /越低越好/);
assert.match(await native.locator(".research-native-best .research-native-unit").textContent(), new RegExp(c.unit ?? "points"), "The raw unit remains visible even when no valid measurement exists");
assert.match(await native.locator(".research-native-scope").innerText(), new RegExp(`${c.values.filter(v => v !== null).length} / ${c.values.length}.*有效结果`));
Expand All @@ -79,6 +91,7 @@ export const researchNativeReadingScenario = {
await details.locator(":scope > summary").focus();
await page.keyboard.press("Enter");
assert.match(await details.innerText(), /2026-01-01T00:00:00Z/);
if (c.display) for (const value of c.expected) assert((await details.innerText()).includes(String(value)), "Expanded sources retain the full native precision");
assert(await details.evaluate(e => parseFloat(getComputedStyle(e).fontSize) >= 14));
assert(await native.evaluate(e => e.scrollWidth <= e.clientWidth + 1));
if (c.id === "lower-negative") {
Expand Down Expand Up @@ -113,6 +126,9 @@ export const researchNativeReadingScenario = {
await page.evaluate(() => localStorage.setItem("loopx-pw-locale", "en"));
await page.reload({waitUntil: "domcontentloaded"});
await page.getByRole("region", {name: "Native measurements", exact: true}).waitFor();
await selector.selectOption({label: "decimal"});
await page.waitForFunction(() => document.querySelector('[data-native-point="best_valid"] strong')?.textContent === "0.8765");
assert.equal(await page.locator("[data-retained-improvement]").textContent(), "+0.0642");
await page.getByRole("button", {name: "About native measurements", exact: true}).focus();
await page.getByRole("tooltip").waitFor({state: "visible"});
await page.keyboard.press("Escape");
Expand All @@ -121,7 +137,7 @@ export const researchNativeReadingScenario = {
assert.equal(readback.mutation_attempts, 0);
assert.deepEqual(errors, []);
return {coverageEntries: collectCoverage ? await page.coverage.stopJSCoverage() : [],
note: "real-owner native result roles: signed/zero/invalid/missing/partial, exact citations, readable desktop/390/200%, Chinese and English; no mutation"};
note: "real-owner native result roles: signed/zero/invalid/missing/partial, compact decimal/tiny/large values with full-precision details, exact citations, readable desktop/390/200%, Chinese and English; no mutation"};
} finally {
await page?.close();
await owner?.close();
Expand Down
Loading