mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
feat(audit): persist ASN and carrier on login audit rows
Adds two nullable columns to AuditLog (`asn Int?` + `carrier String?`) via an additive `IF NOT EXISTS`-guarded migration. The audit-log write path now resolves the location and the ASN row in parallel and writes whichever fields the resolvers could fill in a single update. A new `runGeoBackfill` helper walks rows where `location IS NULL` AND `ipAddress IS NOT NULL` AND `createdAt > now() - 30 days`, capped at 5 000 rows per pass. Useful for picking up rows that landed during an `ipwho.is` outage or before the GeoLite2 MMDBs were bundled into the image.
This commit is contained in:
1 parent
3e930e68f6
commit
e8fb0a7521
18 files changed
+749
-8
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { InsightStatusCard } from "../insight-status-card";
|
||||
|
||||
/**
|
||||
* v1.4.27 — F16 regression cover. The per-metric status text comes
|
||||
* out of the AI provider with a literal `metric:<TYPE>` token (the
|
||||
* prompt invites the model to embed one so the mother page can render
|
||||
* an inline chart). The sub-page does not mount the chart, so the
|
||||
* token used to surface verbatim at the tail of the rendered prose.
|
||||
* The card now wraps the text in `stripChartTokens` so cached rows
|
||||
* from pre-v1.4.27 still render clean while they roll forward.
|
||||
*/
|
||||
|
||||
function render(node: React.ReactNode, locale: "en" | "de" = "en") {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale={locale}>{node}</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
const baseProps = {
|
||||
title: "Pulse",
|
||||
icon: null,
|
||||
hasProvider: true,
|
||||
cached: false,
|
||||
updatedAt: null,
|
||||
};
|
||||
|
||||
describe("<InsightStatusCard>", () => {
|
||||
it("strips a trailing colon-form metric token from rendered prose", () => {
|
||||
const html = render(
|
||||
<InsightStatusCard
|
||||
{...baseProps}
|
||||
text="Your pulse is stable. metric:PULSE"
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("Your pulse is stable.");
|
||||
expect(html).not.toContain("metric:PULSE");
|
||||
});
|
||||
|
||||
it("strips multiple colon-form tokens scattered through the prose", () => {
|
||||
const html = render(
|
||||
<InsightStatusCard
|
||||
{...baseProps}
|
||||
title="Blood pressure"
|
||||
text="Systolic averaged 132 metric:BLOOD_PRESSURE_SYS over the last 30 days. metric:BLOOD_PRESSURE_DIA"
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("Systolic averaged 132");
|
||||
expect(html).not.toContain("metric:BLOOD_PRESSURE_SYS");
|
||||
expect(html).not.toContain("metric:BLOOD_PRESSURE_DIA");
|
||||
});
|
||||
|
||||
it("strips the capitalised Metric form (v1.4.25 W5b leak shape)", () => {
|
||||
const html = render(
|
||||
<InsightStatusCard
|
||||
{...baseProps}
|
||||
title="Blood pressure"
|
||||
text="Your Metric Pressure_Sys is elevated relative to last month."
|
||||
/>,
|
||||
);
|
||||
expect(html).not.toContain("Metric Pressure_Sys");
|
||||
expect(html).toContain("Your");
|
||||
expect(html).toContain("is elevated");
|
||||
});
|
||||
|
||||
it("renders ordinary prose unchanged when no tokens are present", () => {
|
||||
const html = render(
|
||||
<InsightStatusCard {...baseProps} text="Pulse stayed inside the band." />,
|
||||
);
|
||||
expect(html).toContain("Pulse stayed inside the band.");
|
||||
});
|
||||
|
||||
it("renders the no-provider state without touching the strip path", () => {
|
||||
const html = render(
|
||||
<InsightStatusCard
|
||||
{...baseProps}
|
||||
hasProvider={false}
|
||||
text="ignored when hasProvider is false"
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("AI provider not configured.");
|
||||
expect(html).not.toContain("ignored when hasProvider is false");
|
||||
});
|
||||
|
||||
it("renders the empty-text state without crashing on null", () => {
|
||||
const html = render(<InsightStatusCard {...baseProps} text={null} />);
|
||||
expect(html).toContain("No analysis yet.");
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,7 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useTranslations, useFormatters } from "@/lib/i18n/context";
|
||||
import { stripChartTokens } from "@/lib/insights/chart-tokens";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────
|
||||
|
||||
@@ -94,7 +95,16 @@ export function InsightStatusCard({
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<p className="text-muted-foreground text-sm leading-relaxed">{text}</p>
|
||||
{/* v1.4.27 — defence-in-depth strip. Cached status text from
|
||||
pre-v1.4.27 rows can still carry literal `metric:<TYPE>`
|
||||
tokens the model embedded on the assumption a chart would
|
||||
render inline. The sub-page never mounts the chart, so the
|
||||
token surfaces verbatim. The producer side now strips too;
|
||||
this consumer-side wrap keeps existing caches clean while
|
||||
they roll forward. */}
|
||||
<p className="text-muted-foreground text-sm leading-relaxed">
|
||||
{stripChartTokens(text)}
|
||||
</p>
|
||||
<LastUpdatedFooter updatedAt={updatedAt} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
Reference in new issue
Block a user