stock-bot/apps/stock/web-app/src/features/backtest/components/ResultProvenance.tsx

89 lines
3.6 KiB
TypeScript

import type { BacktestRunResult } from '@stock-bot/types';
/** Display saved evidence only; the mutable definition remains a separate settings view. */
export function ResultProvenance({ result }: { result: BacktestRunResult }) {
const provenance = result.provenance;
const config = provenance?.configurationSource === 'stored-snapshot' ? result.config : null;
return (
<section
aria-label="Result provenance and limitations"
className="bg-surface-secondary border border-warning/40 rounded-lg p-3 text-sm space-y-2"
>
<div className="flex flex-wrap items-center gap-2">
<h3 className="font-medium text-text-primary">Saved run evidence</h3>
<span className="text-xs text-warning">Research only · Unverified economics</span>
</div>
<p className="text-text-secondary">
Completion is not financial validation. Do not use this result alone as evidence for
promotion to paper or live trading.
</p>
<p className="text-text-secondary">
Known limitations: same-bar execution, funding constraints, strategy attribution and metric
conventions.
</p>
<details>
<summary className="cursor-pointer text-text-primary">
Configuration, provenance and simulation limitations
</summary>
<div className="mt-3 space-y-3">
<dl className="grid grid-cols-1 sm:grid-cols-2 gap-2 text-text-secondary break-words">
<div>
<dt>Run</dt>
<dd>{result.runId}</dd>
</div>
<div>
<dt>Recorded engine</dt>
<dd>{result.engine === 'legacy' ? 'Unknown' : result.engine}</dd>
</div>
<div>
<dt>Engine build</dt>
<dd>{provenance?.engineVersion ?? 'Unknown — not recorded'}</dd>
</div>
<div>
<dt>Financial semantics version</dt>
<dd>{provenance?.economicsVersion ?? 'Unknown — not recorded'}</dd>
</div>
<div>
<dt>Strategy artifact</dt>
<dd>{provenance?.strategyArtifactHash ?? 'Unknown — not recorded'}</dd>
</div>
<div>
<dt>Dataset hash</dt>
<dd>{provenance?.datasetHash ?? 'Unknown — not recorded'}</dd>
</div>
</dl>
{config ? (
<div>
<h4 className="font-medium text-text-primary">Stored run configuration</h4>
<p className="text-text-secondary">
Exact saved snapshot, including parameters and data policy when recorded. This is
not the current editable definition.
</p>
<pre className="mt-2 overflow-auto max-h-64 text-xs text-text-secondary">
{JSON.stringify(config, null, 2)}
</pre>
</div>
) : (
<p className="text-text-secondary">
Stored run configuration: Unknown. Current strategy settings and defaults are not
historical evidence.
</p>
)}
{provenance ? (
<ul className="list-disc pl-5 space-y-1 text-text-secondary">
{provenance.limitations.map(limitation => (
<li key={limitation.code}>{limitation.message}</li>
))}
</ul>
) : (
<p className="text-text-secondary">
Provenance metadata is unavailable from this API. Execution timing, funding, strategy
attribution and metric conventions are unverified.
</p>
)}
</div>
</details>
</section>
);
}