All checks were successful
CI / Unit & Component Tests (push) Successful in 5m10s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 5m14s
CI / fail2ban Regex (push) Successful in 50s
CI / Semgrep Security Scan (push) Successful in 27s
CI / Compose Bucket Idempotency (push) Successful in 1m5s
Closes #837 Makes `PersonRelationship` fully editable (type, related person, dates, notes), migrates its dates from `Integer fromYear/toYear` to `LocalDate + DatePrecision` (mirroring the #773 person pattern, ADR-039 / V76), activates the previously-dead `notes` column, and gives the Zeitstrahl's derived **Heirat** events full date precision for free. Both Open Decisions confirmed as adopted: **no `@Version`** (last-write-wins, single-writer archive) and **`DELETE` ownership-mismatch aligned 403 → 404** (anti-enumeration, matching the new `PUT`). ## What's in it - **V78** migrates `person_relationships.from_year/to_year` → `from_date`/`to_date` + NOT-NULL `*_date_precision` (default `UNKNOWN`); pre-check abort on corrupt years, `YYYY-01-01`/`YEAR` backfill, 5 named CHECK constraints, year columns dropped. - **`PUT /api/persons/{id}/relationships/{relId}`** (`@RequirePermission(WRITE_ALL)`) re-runs every create invariant (self / coherence / order / reverse-PARENT_OF / duplicate) and re-flags family membership; orientation preserved per viewpoint. - New `ErrorCode.INVALID_RELATIONSHIP_DATES` registered in all four sites (§3.6). - `TimelineEventService` sources the derived marriage date from `SPOUSE_OF.fromDate` + precision. - Frontend: `RelationshipDateField` (DAY/MONTH/YEAR), upsert-capable `AddRelationshipForm` (pre-fill + notes + in-flight submit lock), `RelationshipChip` Edit affordance, `updateRelationship` server action, read-view date range + notes, `formatRelationshipDateRange` helper. `api.ts` regenerated. - Docs: ADR-044, db-orm/db-relationships diagrams, DEPLOYMENT §5 deploy note, RTM REQ-001…REQ-019. ## Requirements All 19 EARS requirements implemented red/green and marked `Done` in `.specify/rtm.md`. ## Test plan - **Backend** (targeted, green): `RelationshipMigrationTest` (Testcontainers pg16, 8), `RelationshipServiceTest` (22), `RelationshipControllerTest` (15), `RelationshipServiceIntegrationTest` (real DB, 10), `DerivedEventsAssemblyTest` (17), `ArchitectureTest` (14); `clean package` builds. - **Frontend** (green): `relationshipDates.spec.ts`, `AddRelationshipForm.svelte.spec.ts`, `RelationshipChip.svelte.spec.ts`, `PersonRelationshipsCard.svelte.test.ts`, `page.server.spec.ts`, `messages.spec.ts`. `npm run check` = 798 (below the ~834 baseline); `npm run lint` clean. ## Notes for reviewers - **Spec deviation:** the edit form was built by making `AddRelationshipForm` upsert-capable rather than a duplicate `EditRelationshipForm` (DRY); RTM rows reference `AddRelationshipForm.svelte.spec.ts`. - `api.ts` regenerated from the live spec; only relationship-relevant hunks remain (one springdoc `PageableObject` field-reorder pruned). - **Deploy:** V78 is one-way and not rolling-deploy-safe — stop old JAR → start new JAR (Flyway runs first); targeted `pg_restore -t person_relationships` for rollback. No maintenance window. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Marcel <marcel@familienarchiv> Reviewed-on: #841
157 lines
5.0 KiB
TypeScript
157 lines
5.0 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { buildLineageIndex, highlightLineage } from './highlightLineage';
|
|
import type { components } from '$lib/generated/api';
|
|
|
|
type RelationshipDTO = components['schemas']['RelationshipDTO'];
|
|
|
|
// Fixture builders mirror buildLayout.test.ts. Ids are plain readable strings —
|
|
// the traversal is id-agnostic, so UUIDs add no value here.
|
|
function parentEdge(parentId: string, childId: string, id = parentId + childId): RelationshipDTO {
|
|
return {
|
|
id,
|
|
personId: parentId,
|
|
relatedPersonId: childId,
|
|
personDisplayName: '',
|
|
relatedPersonDisplayName: '',
|
|
relationType: 'PARENT_OF',
|
|
fromDatePrecision: 'UNKNOWN',
|
|
toDatePrecision: 'UNKNOWN'
|
|
};
|
|
}
|
|
|
|
function spouseEdge(a: string, b: string, id = a + b): RelationshipDTO {
|
|
return {
|
|
id,
|
|
personId: a,
|
|
relatedPersonId: b,
|
|
personDisplayName: '',
|
|
relatedPersonDisplayName: '',
|
|
relationType: 'SPOUSE_OF',
|
|
fromDatePrecision: 'UNKNOWN',
|
|
toDatePrecision: 'UNKNOWN'
|
|
};
|
|
}
|
|
|
|
function siblingEdge(a: string, b: string, id = a + b): RelationshipDTO {
|
|
return {
|
|
id,
|
|
personId: a,
|
|
relatedPersonId: b,
|
|
personDisplayName: '',
|
|
relatedPersonDisplayName: '',
|
|
relationType: 'SIBLING_OF',
|
|
fromDatePrecision: 'UNKNOWN',
|
|
toDatePrecision: 'UNKNOWN'
|
|
};
|
|
}
|
|
|
|
function lineage(edges: RelationshipDTO[], rootId: string) {
|
|
return highlightLineage(buildLineageIndex(edges), rootId);
|
|
}
|
|
|
|
function activeIds(edges: RelationshipDTO[], rootId: string): string[] {
|
|
return [...lineage(edges, rootId).active].sort();
|
|
}
|
|
|
|
describe('highlightLineage — active set (#703)', () => {
|
|
it('an isolated person highlights only themselves', () => {
|
|
expect(activeIds([], 'root')).toEqual(['root']);
|
|
});
|
|
|
|
it('walks the full pedigree upward (parents and grandparents)', () => {
|
|
const edges = [
|
|
parentEdge('father', 'root'),
|
|
parentEdge('mother', 'root'),
|
|
parentEdge('fatherFather', 'father'),
|
|
parentEdge('fatherMother', 'father'),
|
|
parentEdge('motherFather', 'mother'),
|
|
parentEdge('motherMother', 'mother')
|
|
];
|
|
expect(activeIds(edges, 'root')).toEqual([
|
|
'father',
|
|
'fatherFather',
|
|
'fatherMother',
|
|
'mother',
|
|
'motherFather',
|
|
'motherMother',
|
|
'root'
|
|
]);
|
|
});
|
|
|
|
it('walks the full descendant tree downward (children and grandchildren)', () => {
|
|
const edges = [
|
|
parentEdge('root', 'child'),
|
|
parentEdge('child', 'grandchild'),
|
|
parentEdge('child', 'grandchild2')
|
|
];
|
|
expect(activeIds(edges, 'root')).toEqual(['child', 'grandchild', 'grandchild2', 'root']);
|
|
});
|
|
|
|
it('activates all spouses of a blood person, including remarriages', () => {
|
|
// root's father remarried (mother + secondWife); root married twice (s1 + s2).
|
|
const edges = [
|
|
parentEdge('father', 'root'),
|
|
parentEdge('mother', 'root'),
|
|
spouseEdge('father', 'mother'),
|
|
spouseEdge('father', 'secondWife'),
|
|
spouseEdge('root', 's1'),
|
|
spouseEdge('root', 's2')
|
|
];
|
|
expect(activeIds(edges, 'root')).toEqual([
|
|
'father',
|
|
'mother',
|
|
'root',
|
|
's1',
|
|
's2',
|
|
'secondWife'
|
|
]);
|
|
});
|
|
|
|
it('stops at a married-in spouse — the in-law is active but their parents stay dimmed', () => {
|
|
const edges = [spouseEdge('root', 'inLaw'), parentEdge('inLawParent', 'inLaw')];
|
|
const { active } = lineage(edges, 'root');
|
|
expect(active.has('inLaw')).toBe(true);
|
|
expect(active.has('inLawParent')).toBe(false);
|
|
});
|
|
|
|
it('never pulls a collateral relative into the active set via a SIBLING_OF edge', () => {
|
|
const edges = [
|
|
parentEdge('parent', 'root'),
|
|
parentEdge('parent', 'sibling'),
|
|
siblingEdge('root', 'sibling')
|
|
];
|
|
const { active } = lineage(edges, 'root');
|
|
expect(active.has('parent')).toBe(true); // ancestor
|
|
expect(active.has('sibling')).toBe(false); // collateral — reached only down from an ancestor, never walked
|
|
});
|
|
});
|
|
|
|
describe('highlightLineage — connector predicate (#703)', () => {
|
|
it('is active only when both joined people are active', () => {
|
|
// root—inLaw (spouse), inLaw—inLawParent (parent). Only root + inLaw are active.
|
|
const edges = [
|
|
parentEdge('parent', 'root'),
|
|
spouseEdge('root', 'inLaw'),
|
|
parentEdge('inLawParent', 'inLaw')
|
|
];
|
|
const { isConnectorActive } = lineage(edges, 'root');
|
|
expect(isConnectorActive('root', 'parent')).toBe(true); // active ↔ active
|
|
expect(isConnectorActive('root', 'inLaw')).toBe(true); // active ↔ active spouse
|
|
expect(isConnectorActive('inLaw', 'inLawParent')).toBe(false); // active spouse ↔ dimmed in-law parent
|
|
});
|
|
});
|
|
|
|
describe('highlightLineage — cyclic data (REQ-STAMMBAUM-04 / AC10)', () => {
|
|
it('terminates on a PARENT_OF cycle and resolves the cycle members as active', () => {
|
|
// A is parent of B and B is parent of A — a cycle. The visited guard stops the
|
|
// walk re-visiting; both cycle members are reachable from root and stay active.
|
|
const edges = [parentEdge('a', 'b'), parentEdge('b', 'a')];
|
|
expect(activeIds(edges, 'a')).toEqual(['a', 'b']);
|
|
});
|
|
|
|
it('terminates on a self-referential PARENT_OF edge', () => {
|
|
const edges = [parentEdge('x', 'x')];
|
|
expect(activeIds(edges, 'x')).toEqual(['x']);
|
|
});
|
|
});
|