refactor(insights): type-check the generic metric previous-context scope

The generic metric-status generator read its previous-context row through an
`as never` cast, because `getPreviousInsightContext` was typed to the seven
specialised scopes only. Widen the helper's `scope` param to a
`PreviousContextScope` union that also accepts the `metric:<ID>-status` scope
form, so the generic call type-checks honestly instead of silently disabling
type checking on the argument. No behaviour change — the helper only
interpolates the scope into the audit action.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 899d59b6fa219a14ba39eacded2e042f0f95c2c5)
This commit is contained in:
Marc-André Bombeck committed 2026-06-02 14:03:00 +02:00
1 parent 58b793ee4a
commit bd8a4e7990
2 files changed
+15 -3

No files matched your search

+11 -1
View File
@@ -33,6 +33,16 @@ export type InsightScope =
| "medication-compliance-status"
| "mood-status";
/**
* v1.8.7.1 — the generic per-HealthKit-metric assessments key their
* previous-context rows under `insights.metric:<ID>-status.<locale>`, the
* same `-status` action shape the seven specialised scopes use. Accept
* that scope form alongside the seven so the generic generator can read
* its comparison row without an `as never` cast that would silently
* disable type checking on the argument.
*/
export type PreviousContextScope = InsightScope | `metric:${string}-status`;
export interface PreviousInsightContext {
/** ISO timestamp the previous analysis was rendered. */
generatedAt: string;
@@ -59,7 +69,7 @@ export interface PreviousInsightContext {
*/
export async function getPreviousInsightContext(
userId: string,
scope: InsightScope,
scope: PreviousContextScope,
locale: "de" | "en",
minAgeHours: number = 12,
): Promise<PreviousInsightContext | null> {
+4 -2
View File
@@ -280,8 +280,10 @@ export async function generateMetricStatus(args: {
args.userId,
// memory.ts keys previous context by the `insights.<scope>.<locale>`
// action; the generic scope (`metric:<ID>-status`) carries the same
// `-status` suffix so the comparison row reads back correctly.
`${scope}-status` as never,
// `-status` suffix so the comparison row reads back correctly. The
// `getPreviousInsightContext` param is typed to accept this scope form
// (`PreviousContextScope`), so the argument type-checks honestly.
`${scope}-status`,
locale,
12,
);