test: mock AnthropicClient in analyze tests to prevent live API calls

This commit is contained in:
Kazuma
2026-06-08 12:08:37 -04:00
parent 76c2a671f4
commit ad1c3fe3c9
31 changed files with 415 additions and 171 deletions
@@ -0,0 +1,177 @@
<script lang="ts">
import { untrack } from 'svelte';
import type { MarketContext } from '$lib/types.js';
let { ctx, collapsible = false }: { ctx: MarketContext; collapsible?: boolean } = $props();
// Read collapsible once for initial state — untrack avoids a reactive dep on the prop
let expanded = $state(untrack(() => !collapsible));
const cards = $derived.by(() => {
const b = ctx?.benchmarks ?? {};
return [
{
label: '10Y Yield',
value: ctx?.riskFreeRate != null ? ctx.riskFreeRate.toFixed(2) + '%' : '—',
tip: 'US 10-year Treasury yield — the risk-free rate benchmark. Higher = tighter conditions for stocks and bonds.',
},
{
label: 'VIX',
value: ctx?.vixLevel?.toFixed(1) ?? '—',
tip: 'CBOE Volatility Index — measures expected market volatility. Above 20 = elevated fear; above 30 = high stress.',
},
{
label: 'S&P 500',
value: ctx?.sp500Price?.toLocaleString() ?? '—',
tip: 'Live S&P 500 index price — broad US large-cap benchmark.',
},
{
label: 'S&P P/E',
value: b.marketPE != null ? b.marketPE.toFixed(1) + 'x' : '—',
tip: 'Trailing P/E ratio of SPY. Used to set the INFLATED mode P/E gate (S&P P/E × 1.5 in normal rates).',
},
{
label: 'Tech P/E',
value: b.techPE != null ? b.techPE.toFixed(1) + 'x' : '—',
tip: 'Trailing P/E of XLK (tech sector ETF). Sets the tech-sector gate in INFLATED mode (XLK P/E × 1.3).',
},
{
label: 'REIT Yield',
value: b.reitYield != null ? b.reitYield.toFixed(2) + '%' : '—',
tip: 'Dividend yield of XLRE (real estate ETF). Used as the REIT minimum yield gate in INFLATED mode.',
},
{
label: 'IG Spread',
value: b.igSpread != null ? b.igSpread.toFixed(2) + '%' : '—',
tip: 'Investment-grade bond spread (LQD yield 10Y yield). Sets the bond minimum spread gate in INFLATED mode.',
},
{
label: 'Rate Regime',
value: ctx?.rateRegime ?? '—',
tip: 'HIGH (>4.5%) compresses P/E gates and tightens bond/REIT requirements. NORMAL uses looser INFLATED gates.',
},
{
label: 'Volatility',
value: ctx?.volatilityRegime ?? '—',
tip: 'Derived from VIX level — LOW (<15), NORMAL (1525), HIGH (>25). Informational; not currently gating scores.',
},
];
});
</script>
<div class="ctx-wrap">
{#if collapsible}
<button class="ctx-toggle" onclick={() => expanded = !expanded}>
<span class="ctx-toggle-label">Market Context</span>
<span class="ctx-toggle-chevron">{expanded ? '▲' : '▼'}</span>
</button>
{/if}
{#if expanded}
<div class="grid">
{#each cards as c}
<div class="card">
<div class="label-row">
<span class="label">{c.label}</span>
<span class="tip-wrap">
<span class="tip-anchor">?</span>
<span class="tip-box">{c.tip}</span>
</span>
</div>
<div class="value">{c.value}</div>
</div>
{/each}
</div>
{/if}
</div>
<style>
.ctx-wrap { margin-bottom: 20px; }
/* ── Collapsible toggle ─────────────────────────────────────────── */
.ctx-toggle {
display: flex;
align-items: center;
gap: 8px;
background: none;
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 6px 12px;
cursor: pointer;
margin-bottom: 10px;
}
.ctx-toggle-label {
font-size: var(--fs-sm);
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.07em;
color: var(--text-dimmer);
}
.ctx-toggle-chevron { font-size: var(--fs-2xs); color: var(--text-faint); }
/* ── Cards grid ─────────────────────────────────────────────────── */
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
gap: 10px;
margin-bottom: 8px;
}
.card { background: var(--bg-card); border-radius: var(--radius-md); padding: 12px var(--space-lg); }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.label { font-size: var(--fs-xs); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
/* ── Tooltip ─────────────────────────────────────────────────────── */
.tip-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.tip-anchor {
display: inline-flex;
align-items: center;
justify-content: center;
width: 13px;
height: 13px;
border-radius: 50%;
background: var(--bg-card);
border: 1px solid var(--text-faint);
color: var(--text-dimmer);
font-size: var(--fs-2xs);
font-weight: 700;
cursor: help;
}
.tip-box {
display: none;
position: absolute;
bottom: calc(100% + 6px);
left: 50%;
transform: translateX(-50%);
width: 220px;
background: var(--bg-card);
border: 1px solid var(--text-faint);
border-radius: var(--radius-sm);
padding: 8px 10px;
font-size: var(--fs-sm);
color: var(--text-muted);
line-height: 1.5;
z-index: 50;
pointer-events: none;
white-space: normal;
}
.tip-box::after {
content: '';
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
border: 5px solid transparent;
border-top-color: var(--text-faint);
}
.tip-wrap:hover .tip-box { display: block; }
.value { font-size: 17px; font-weight: 700; color: var(--text-primary); margin-top: 4px; }
</style>
@@ -0,0 +1,69 @@
<script lang="ts">
import { fmtPE } from '$lib/utils.js';
import type { MarketContext } from '$lib/types.js';
let { ctx }: { ctx: MarketContext } = $props();
// Flat list of chips so the template stays declarative
const chips = $derived([
{ label: '10Y', value: ctx.riskFreeRate?.toFixed(2) + '%' },
{ label: 'VIX', value: ctx.vixLevel?.toFixed(1) },
{ label: 'S&P', value: ctx.sp500Price?.toLocaleString() },
{ label: 'S&P P/E', value: fmtPE(ctx.benchmarks?.marketPE) },
{ label: 'Tech P/E', value: fmtPE(ctx.benchmarks?.techPE) },
{ label: 'REIT Yld', value: ctx.benchmarks?.reitYield?.toFixed(2) + '%' },
{ label: 'IG Sprd', value: ctx.benchmarks?.igSpread?.toFixed(2) + '%' },
{ label: 'Rates', value: ctx.rateRegime, regime: ctx.rateRegime },
{ label: 'Vol', value: ctx.volatilityRegime, regime: ctx.volatilityRegime },
]);
</script>
<div class="ctx-strip">
{#each chips as chip}
<div class="ctx-chip">
<span class="ctx-label">{chip.label}</span>
<span class="ctx-val" class:ctx-regime={!!chip.regime} data-regime={chip.regime ?? ''}>
{chip.value ?? '—'}
</span>
</div>
{/each}
</div>
<style>
.ctx-strip {
display: flex;
gap: 1px;
background: var(--border);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
overflow: hidden;
}
.ctx-chip {
flex: 1;
min-width: 70px;
background: var(--bg-base);
padding: 10px var(--space-lg);
display: flex;
flex-direction: column;
gap: 3px;
}
.ctx-label {
font-size: var(--fs-2xs);
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--text-dimmer);
}
.ctx-val {
font-size: var(--fs-lg);
font-weight: 700;
color: var(--text-primary);
font-variant-numeric: tabular-nums;
}
.ctx-regime[data-regime='HIGH'] { color: var(--red); }
.ctx-regime[data-regime='NORMAL'] { color: var(--text-muted); }
.ctx-regime[data-regime='LOW'] { color: var(--green); }
</style>
@@ -0,0 +1,30 @@
<script lang="ts">
import type { Signal } from '$lib/types.js';
let { signal }: { signal: Signal | null | undefined } = $props();
const cls = () => {
if (signal?.includes('Strong')) return 'strong';
if (signal?.includes('Momentum')) return 'momentum';
if (signal?.includes('Speculation')) return 'spec';
if (signal?.includes('Neutral')) return 'neutral';
return 'avoid';
};
</script>
<span class="badge {cls()}">{signal ?? '—'}</span>
<style>
.badge {
display: inline-block;
font-size: 11px;
font-weight: 700;
padding: 3px 10px;
border-radius: 20px;
white-space: nowrap;
}
.strong { background: #14532d33; color: #4ade80; }
.momentum { background: #1e3a5f33; color: #60a5fa; }
.spec { background: #7c2d1233; color: #fb923c; }
.neutral { background: #1e293b; color: #94a3b8; }
.avoid { background: #450a0a33; color: #f87171; }
</style>
+137
View File
@@ -0,0 +1,137 @@
<script lang="ts">
let { size = 'md', label = null }: { size?: 'sm' | 'md' | 'lg'; label?: string | null } = $props();
</script>
{#if size === 'sm'}
<!-- Compact dot-pulse for buttons -->
<span class="dot-pulse">
<span></span><span></span><span></span>
</span>
{:else}
<!-- Market chart line animation for md / lg -->
<div class="chart-wrap" data-size={size}>
<svg
viewBox="0 0 160 60"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class="chart-svg"
aria-hidden="true"
>
<!-- Faint grid lines -->
<line x1="0" y1="15" x2="160" y2="15" stroke="#1e293b" stroke-width="1" />
<line x1="0" y1="30" x2="160" y2="30" stroke="#1e293b" stroke-width="1" />
<line x1="0" y1="45" x2="160" y2="45" stroke="#1e293b" stroke-width="1" />
<!-- The market line — rises, dips, spikes, recovers -->
<polyline
class="chart-line"
points="
0,45
12,38
22,42
32,28
42,32
52,18
62,24
72,14
82,20
92,10
104,22
114,16
124,28
134,20
148,8
160,12
"
/>
<!-- Glowing dot at the leading edge -->
<circle class="chart-dot" cx="160" cy="12" r="3" />
</svg>
{#if label}
<span class="chart-label">{label}</span>
{/if}
</div>
{/if}
<style>
/* ── Dot pulse (sm) ─────────────────────────────────────────────── */
.dot-pulse {
display: inline-flex;
align-items: center;
gap: 3px;
}
.dot-pulse span {
display: block;
width: 4px;
height: 4px;
border-radius: 50%;
background: #60a5fa;
animation: dot-bounce 0.9s ease-in-out infinite;
}
.dot-pulse span:nth-child(2) { animation-delay: 0.15s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.30s; }
@keyframes dot-bounce {
0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
40% { transform: scale(1); opacity: 1; }
}
/* ── Chart wrap (md / lg) ───────────────────────────────────────── */
.chart-wrap {
display: flex;
flex-direction: column;
align-items: center;
gap: 14px;
}
.chart-wrap[data-size="md"] .chart-svg { width: 120px; height: 45px; }
.chart-wrap[data-size="lg"] .chart-svg { width: 200px; height: 75px; }
.chart-svg { overflow: visible; }
/* The animated line */
.chart-line {
stroke: #3b82f6;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
fill: none;
/* total path length ≈ 220 — animate draw-in then loop */
stroke-dasharray: 220;
stroke-dashoffset: 220;
animation: draw-line 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes draw-line {
0% { stroke-dashoffset: 220; opacity: 1; }
70% { stroke-dashoffset: 0; opacity: 1; }
85% { stroke-dashoffset: 0; opacity: 0; }
100% { stroke-dashoffset: 220; opacity: 0; }
}
/* Glowing dot that appears when the line finishes drawing */
.chart-dot {
fill: #3b82f6;
filter: drop-shadow(0 0 4px #3b82f6);
opacity: 0;
animation: dot-appear 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes dot-appear {
0% { opacity: 0; }
60% { opacity: 0; }
70% { opacity: 1; }
85% { opacity: 1; }
100% { opacity: 0; }
}
.chart-label {
font-size: 12px;
color: #475569;
letter-spacing: 0.02em;
}
</style>
@@ -0,0 +1,6 @@
<script lang="ts">
import { verdictShort, vClass } from '$lib/utils.js';
let { label }: { label: string | null | undefined } = $props();
</script>
<span class="verdict-pill {vClass(label)}">{verdictShort(label)}</span>
+5
View File
@@ -0,0 +1,5 @@
export { default as Spinner } from './Spinner.svelte';
export { default as VerdictPill } from './VerdictPill.svelte';
export { default as SignalBadge } from './SignalBadge.svelte';
export { default as MarketContext } from './MarketContext.svelte';
export { default as MarketContextStrip } from './MarketContextStrip.svelte';