feat(pipeline): 9→7 stage refactor + v1.1 hardening wave

Replaces the legacy 9-stage pipeline with 7 canonical stages
(enquiry → qualified → eoi → reservation → deposit_paid → contract →
nurturing) plus three doc sub-status columns (eoi_doc_status,
reservation_doc_status, contract_doc_status) that track sent/signed
within a single stage instead of branching it.

Schema (migration 0062):
- interests gains assigned_to, deposit_expected_amount/currency,
  three doc-status columns, two documenso-id columns, and
  date_reservation_signed.
- New tables: qualification_criteria (per-port admin-configurable),
  interest_qualifications (per-interest state), payments (deposit /
  balance / refund records keyed to interest + client).
- Default qualification criteria seeded for every existing port.
- Dummy-data UPDATEs collapse Sent/Signed pairs and 'completed' into
  the new stage + doc-status + outcome shape.

Migration 0063 adds interest_contact_log.voice_transcript and
template_used columns for v1.1-A/B (quick-template buttons + voice
transcription via Web Speech API).

v1.1 phase work bundled here:
- A/B: Quick-template buttons (Call / Visit / Email) + mic toggle on
       the contact-log compose dialog (useVoiceTranscription hook).
- C:   berth-rules-engine wraps state writes in pg_advisory_xact_lock
       with an idempotent re-read; emits rule_evaluated audit traces.
- D:   Documenso webhook: reservation/contract sub-status stamping
       moved out of the PDF-download try-block so a download failure
       no longer swallows the stamp. New integration test coverage.
- E:   /admin/qualification-criteria CRUD page + admin component.
- F:   default_new_interest_owner exposed in System Settings.
- G:   recentActivityCount + active_engagement deal-pulse signal
       surfaced as a chip on interests + hot-deals card.
- H:   interest_assigned notification on assignedTo change (skips
       self-assign, uses a dedupe key).

Plus the supporting components: AssignedToChip, DealPulseChip,
PaymentsSection, QualificationChecklist, MultiEoiChip,
SkipAheadBanner, WonStatusPanel, InterestBerthStatusBanner,
SupplementalInfoRequestButton, UserPicker.

Tests: 1370/1370 vitest pass (added deal-health unit suite +
expanded constants/validators/pipeline-transitions coverage). tsc
clean, eslint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-14 03:39:21 +02:00
parent b10bf9bf8e
commit 6b28459c45
110 changed files with 5402 additions and 796 deletions

View File

@@ -8,7 +8,11 @@
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { makeAuditMeta, makeCreateClientInput, makeCreateInterestInput } from '../helpers/factories';
import {
makeAuditMeta,
makeCreateClientInput,
makeCreateInterestInput,
} from '../helpers/factories';
const TEST_DB_URL =
process.env.TEST_DATABASE_URL || 'postgresql://test:test@localhost:5433/portnimara_test';
@@ -84,7 +88,11 @@ describe('Port Scoping — Clients', () => {
const meta = makeAuditMeta({ portId: portA });
const client = await createClient(portA, makeCreateClientInput({ fullName: 'Alice Scope' }), meta);
const client = await createClient(
portA,
makeCreateClientInput({ fullName: 'Alice Scope' }),
meta,
);
expect(client.portId).toBe(portA);
@@ -105,7 +113,11 @@ describe('Port Scoping — Clients', () => {
const { NotFoundError } = await import('@/lib/errors');
const meta = makeAuditMeta({ portId: portA });
const client = await createClient(portA, makeCreateClientInput({ fullName: 'Bob Scope' }), meta);
const client = await createClient(
portA,
makeCreateClientInput({ fullName: 'Bob Scope' }),
meta,
);
await expect(getClientById(client.id, portB)).rejects.toThrow(NotFoundError);
});
@@ -115,11 +127,15 @@ describe('Port Scoping — Clients', () => {
const { NotFoundError } = await import('@/lib/errors');
const meta = makeAuditMeta({ portId: portA });
const client = await createClient(portA, makeCreateClientInput({ fullName: 'Carol Scope' }), meta);
const client = await createClient(
portA,
makeCreateClientInput({ fullName: 'Carol Scope' }),
meta,
);
await expect(
updateClient(client.id, portB, { fullName: 'Hacked' }, meta),
).rejects.toThrow(NotFoundError);
await expect(updateClient(client.id, portB, { fullName: 'Hacked' }, meta)).rejects.toThrow(
NotFoundError,
);
});
itDb('archiveClient on wrong port throws NotFoundError', async () => {
@@ -127,7 +143,11 @@ describe('Port Scoping — Clients', () => {
const { NotFoundError } = await import('@/lib/errors');
const meta = makeAuditMeta({ portId: portA });
const client = await createClient(portA, makeCreateClientInput({ fullName: 'Dave Scope' }), meta);
const client = await createClient(
portA,
makeCreateClientInput({ fullName: 'Dave Scope' }),
meta,
);
await expect(archiveClient(client.id, portB, meta)).rejects.toThrow(NotFoundError);
});
@@ -144,7 +164,11 @@ describe('Port Scoping — Interests', () => {
const { createClient } = await import('@/lib/services/clients.service');
const meta = makeAuditMeta({ portId: portA });
const client = await createClient(portA, makeCreateClientInput({ fullName: 'Scope Test Client' }), meta);
const client = await createClient(
portA,
makeCreateClientInput({ fullName: 'Scope Test Client' }),
meta,
);
clientIdA = client.id;
});
@@ -157,7 +181,11 @@ describe('Port Scoping — Interests', () => {
const { createInterest, listInterests } = await import('@/lib/services/interests.service');
const meta = makeAuditMeta({ portId: portA });
const interest = await createInterest(portA, makeCreateInterestInput({ clientId: clientIdA }), meta);
const interest = await createInterest(
portA,
makeCreateInterestInput({ clientId: clientIdA }),
meta,
);
expect(interest.portId).toBe(portA);
@@ -178,20 +206,29 @@ describe('Port Scoping — Interests', () => {
const { NotFoundError } = await import('@/lib/errors');
const meta = makeAuditMeta({ portId: portA });
const interest = await createInterest(portA, makeCreateInterestInput({ clientId: clientIdA }), meta);
const interest = await createInterest(
portA,
makeCreateInterestInput({ clientId: clientIdA }),
meta,
);
await expect(getInterestById(interest.id, portB)).rejects.toThrow(NotFoundError);
});
itDb('changeInterestStage on wrong port throws NotFoundError', async () => {
const { createInterest, changeInterestStage } = await import('@/lib/services/interests.service');
const { createInterest, changeInterestStage } =
await import('@/lib/services/interests.service');
const { NotFoundError } = await import('@/lib/errors');
const meta = makeAuditMeta({ portId: portA });
const interest = await createInterest(portA, makeCreateInterestInput({ clientId: clientIdA }), meta);
const interest = await createInterest(
portA,
makeCreateInterestInput({ clientId: clientIdA }),
meta,
);
await expect(
changeInterestStage(interest.id, portB, { pipelineStage: 'details_sent' }, meta),
changeInterestStage(interest.id, portB, { pipelineStage: 'qualified' }, meta),
).rejects.toThrow(NotFoundError);
});
});