f96fdcb3b9
Lock health recording behind confirm-only state machines, reject public publishes for the health category, and ship the 14-day experiment Page Data templates with tests. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { validateExtractionResult } from './health-extraction.mjs';
|
|
|
|
test('accepts a high-confidence blood pressure extraction', () => {
|
|
const result = validateExtractionResult({
|
|
metric_set: 'blood_pressure',
|
|
systolic: 137,
|
|
diastolic: 82,
|
|
pulse: 72,
|
|
confidence: { systolic: 0.97, diastolic: 0.95, pulse: 0.96 },
|
|
});
|
|
assert.equal(result.ok, true);
|
|
assert.equal(result.requireConfirm, true);
|
|
assert.deepEqual(result.lowConfidence, []);
|
|
});
|
|
|
|
test('rejects out-of-range values instead of committing', () => {
|
|
const result = validateExtractionResult({
|
|
metric_set: 'blood_pressure',
|
|
systolic: 300,
|
|
diastolic: 82,
|
|
confidence: { systolic: 0.99, diastolic: 0.99 },
|
|
});
|
|
assert.equal(result.ok, false);
|
|
assert.equal(result.unreadable, true);
|
|
});
|
|
|
|
test('rejects inverted systolic/diastolic without guessing a swap', () => {
|
|
const result = validateExtractionResult({
|
|
metric_set: 'blood_pressure',
|
|
systolic: 80,
|
|
diastolic: 120,
|
|
confidence: { systolic: 0.99, diastolic: 0.99 },
|
|
});
|
|
assert.equal(result.ok, false);
|
|
assert.equal(result.error, 'systolic_not_greater');
|
|
});
|
|
|
|
test('low confidence fields stay pending', () => {
|
|
const result = validateExtractionResult({
|
|
metric_set: 'weight',
|
|
weight: 67.2,
|
|
confidence: { weight: 0.4 },
|
|
});
|
|
assert.equal(result.ok, true);
|
|
assert.deepEqual(result.lowConfidence, ['weight']);
|
|
});
|