feat(ai-psychosis): promote domain_context to array for multi-domain support

This commit is contained in:
Kjell Tore Guttormsen 2026-05-01 21:28:36 +02:00
commit a5bc53cb42
6 changed files with 72 additions and 11 deletions

View file

@ -62,6 +62,29 @@ test('relationship_domain_count matches fixture count', () => {
assert.equal(result.null_domain_count, 2);
});
test('v1.2 array domain_context aggregates correctly (relationship in array)', () => {
const fixture = [
// v1.2 — multi-domain array containing 'relationship'
{ session_id: 'a', duration_min: 30, domain_context: ['relationship', 'health'],
flags: { dependency: 0, escalation: 0, fatigue: 0, validation: 0, pushback: 1 } },
// v1.2 — array without 'relationship'
{ session_id: 'b', duration_min: 30, domain_context: ['legal'],
flags: { dependency: 0, escalation: 0, fatigue: 0, validation: 0, pushback: 0 } },
// v1.2 — empty array (no domain detected this session)
{ session_id: 'c', duration_min: 30, domain_context: [],
flags: { dependency: 0, escalation: 0, fatigue: 0, validation: 0, pushback: 0 } },
// v1.1 — string shape (must still aggregate as relationship)
{ session_id: 'd', duration_min: 30, domain_context: 'relationship',
flags: { dependency: 0, escalation: 0, fatigue: 0, validation: 0, pushback: 1 } },
];
const jsonl = fixture.map(o => JSON.stringify(o)).join('\n') + '\n';
const result = runReader(jsonl);
assert.equal(result.relationship_domain_count, 2,
'v1.2 array containing relationship + v1.1 string both increment relationship counter');
assert.equal(result.other_domain_count, 1, 'v1.2 ["legal"] is "other" until Step 14 adds per-domain breakdown');
assert.equal(result.null_domain_count, 1, 'empty array counts as null');
});
test('backward-compat: v1.0.0 records without pushback/domain do not produce NaN', () => {
const fixture = [
// v1.0.0 — no pushback in flags, no domain_context at top level