feat(recommender): SQL ranking + tier ladder + heat scoring
Plan §4.4 + §13: pure SQL recommender, no AI. Single CTE chain
(feasible -> aggregates) + JS-side tier classification, fall-through
cooldown filter, heat scoring, and fit ranking. Per-port settings via
system_settings layered over global + DEFAULT_RECOMMENDER_SETTINGS.
Tier ladder (default):
A : no interest history
B : lost-only history (still recommendable + boosted by heat)
C : active interest in early stage (open..eoi_signed)
D : active interest at deposit_10pct or beyond (hidden by default)
Heat (only for tier B):
recency weight 30 full @ <=30 days, decays to 0 @ 365 days
furthest stage weight 40 full when prior reached deposit
interest count weight 15 saturates at 5+
EOI count weight 15 saturates at 3+
Multi-port isolation enforced (§14.10 critical): the SQL filters by
port_id AND the entry-point function rejects cross-port interest
lookups with an explicit error. Fall-through policy supports
immediate_with_heat (default), cooldown, and never_auto_recommend.
15 unit tests covering tier classification, heat saturation, weight
tuning, zero-weight guard. Smoke-tested end-to-end via
scripts/dev-recommender-smoke.ts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 02:58:34 +02:00
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
classifyTier,
|
|
|
|
|
computeHeat,
|
|
|
|
|
DEFAULT_RECOMMENDER_SETTINGS,
|
|
|
|
|
} from '@/lib/services/berth-recommender.service';
|
|
|
|
|
|
|
|
|
|
describe('classifyTier', () => {
|
|
|
|
|
it('"A" when there is no interest history at all', () => {
|
|
|
|
|
expect(classifyTier({ activeInterestCount: 0, lostCount: 0, maxActiveStage: 0 })).toBe('A');
|
|
|
|
|
});
|
|
|
|
|
it('"B" when only lost interests exist (no active)', () => {
|
|
|
|
|
expect(classifyTier({ activeInterestCount: 0, lostCount: 2, maxActiveStage: 0 })).toBe('B');
|
|
|
|
|
});
|
2026-05-15 01:18:13 +02:00
|
|
|
// L-001 renumber: 7-stage ranks are 1=enquiry, 2=qualified/nurturing,
|
|
|
|
|
// 3=eoi, 4=reservation, 5=deposit_paid, 6=contract. Tier D fires at
|
|
|
|
|
// deposit_paid (5) or later.
|
|
|
|
|
it('"C" when an active interest is in an early stage (eoi)', () => {
|
feat(recommender): SQL ranking + tier ladder + heat scoring
Plan §4.4 + §13: pure SQL recommender, no AI. Single CTE chain
(feasible -> aggregates) + JS-side tier classification, fall-through
cooldown filter, heat scoring, and fit ranking. Per-port settings via
system_settings layered over global + DEFAULT_RECOMMENDER_SETTINGS.
Tier ladder (default):
A : no interest history
B : lost-only history (still recommendable + boosted by heat)
C : active interest in early stage (open..eoi_signed)
D : active interest at deposit_10pct or beyond (hidden by default)
Heat (only for tier B):
recency weight 30 full @ <=30 days, decays to 0 @ 365 days
furthest stage weight 40 full when prior reached deposit
interest count weight 15 saturates at 5+
EOI count weight 15 saturates at 3+
Multi-port isolation enforced (§14.10 critical): the SQL filters by
port_id AND the entry-point function rejects cross-port interest
lookups with an explicit error. Fall-through policy supports
immediate_with_heat (default), cooldown, and never_auto_recommend.
15 unit tests covering tier classification, heat saturation, weight
tuning, zero-weight guard. Smoke-tested end-to-end via
scripts/dev-recommender-smoke.ts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 02:58:34 +02:00
|
|
|
expect(classifyTier({ activeInterestCount: 1, lostCount: 0, maxActiveStage: 3 })).toBe('C');
|
|
|
|
|
});
|
|
|
|
|
it('"C" even when a prior interest was lost, if there is an active one', () => {
|
|
|
|
|
expect(classifyTier({ activeInterestCount: 1, lostCount: 5, maxActiveStage: 2 })).toBe('C');
|
|
|
|
|
});
|
|
|
|
|
it('"D" when an active interest is at deposit or beyond', () => {
|
2026-05-15 01:18:13 +02:00
|
|
|
expect(classifyTier({ activeInterestCount: 1, lostCount: 0, maxActiveStage: 5 })).toBe('D');
|
feat(recommender): SQL ranking + tier ladder + heat scoring
Plan §4.4 + §13: pure SQL recommender, no AI. Single CTE chain
(feasible -> aggregates) + JS-side tier classification, fall-through
cooldown filter, heat scoring, and fit ranking. Per-port settings via
system_settings layered over global + DEFAULT_RECOMMENDER_SETTINGS.
Tier ladder (default):
A : no interest history
B : lost-only history (still recommendable + boosted by heat)
C : active interest in early stage (open..eoi_signed)
D : active interest at deposit_10pct or beyond (hidden by default)
Heat (only for tier B):
recency weight 30 full @ <=30 days, decays to 0 @ 365 days
furthest stage weight 40 full when prior reached deposit
interest count weight 15 saturates at 5+
EOI count weight 15 saturates at 3+
Multi-port isolation enforced (§14.10 critical): the SQL filters by
port_id AND the entry-point function rejects cross-port interest
lookups with an explicit error. Fall-through policy supports
immediate_with_heat (default), cooldown, and never_auto_recommend.
15 unit tests covering tier classification, heat saturation, weight
tuning, zero-weight guard. Smoke-tested end-to-end via
scripts/dev-recommender-smoke.ts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 02:58:34 +02:00
|
|
|
expect(classifyTier({ activeInterestCount: 1, lostCount: 0, maxActiveStage: 6 })).toBe('D');
|
|
|
|
|
});
|
2026-05-15 01:18:13 +02:00
|
|
|
it('still "C" at reservation (stage 4) - tier D only kicks in at deposit', () => {
|
|
|
|
|
expect(classifyTier({ activeInterestCount: 1, lostCount: 0, maxActiveStage: 4 })).toBe('C');
|
feat(recommender): SQL ranking + tier ladder + heat scoring
Plan §4.4 + §13: pure SQL recommender, no AI. Single CTE chain
(feasible -> aggregates) + JS-side tier classification, fall-through
cooldown filter, heat scoring, and fit ranking. Per-port settings via
system_settings layered over global + DEFAULT_RECOMMENDER_SETTINGS.
Tier ladder (default):
A : no interest history
B : lost-only history (still recommendable + boosted by heat)
C : active interest in early stage (open..eoi_signed)
D : active interest at deposit_10pct or beyond (hidden by default)
Heat (only for tier B):
recency weight 30 full @ <=30 days, decays to 0 @ 365 days
furthest stage weight 40 full when prior reached deposit
interest count weight 15 saturates at 5+
EOI count weight 15 saturates at 3+
Multi-port isolation enforced (§14.10 critical): the SQL filters by
port_id AND the entry-point function rejects cross-port interest
lookups with an explicit error. Fall-through policy supports
immediate_with_heat (default), cooldown, and never_auto_recommend.
15 unit tests covering tier classification, heat saturation, weight
tuning, zero-weight guard. Smoke-tested end-to-end via
scripts/dev-recommender-smoke.ts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 02:58:34 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('computeHeat', () => {
|
|
|
|
|
const w = DEFAULT_RECOMMENDER_SETTINGS;
|
|
|
|
|
const NOW = new Date('2026-05-05T00:00:00Z');
|
|
|
|
|
|
|
|
|
|
it('zero heat when nothing in history', () => {
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: null,
|
|
|
|
|
totalInterestCount: 0,
|
|
|
|
|
eoiSignedCount: 0,
|
|
|
|
|
fallthroughMaxStage: 0,
|
|
|
|
|
},
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(h.total).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('full recency for a fall-through within the last 30 days', () => {
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: new Date('2026-04-25T00:00:00Z'),
|
|
|
|
|
totalInterestCount: 0,
|
|
|
|
|
eoiSignedCount: 0,
|
|
|
|
|
fallthroughMaxStage: 1,
|
|
|
|
|
},
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
// recency component should be the full heat_weight_recency (30)
|
|
|
|
|
expect(h.recency).toBeCloseTo(30, 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('zero recency for an ancient fall-through (>1 year)', () => {
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: new Date('2024-01-01T00:00:00Z'),
|
|
|
|
|
totalInterestCount: 0,
|
|
|
|
|
eoiSignedCount: 0,
|
|
|
|
|
fallthroughMaxStage: 1,
|
|
|
|
|
},
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(h.recency).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('full furthest-stage when the fall-through reached deposit', () => {
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: null,
|
|
|
|
|
totalInterestCount: 0,
|
|
|
|
|
eoiSignedCount: 0,
|
2026-05-15 01:18:13 +02:00
|
|
|
fallthroughMaxStage: 5, // deposit_paid (was deposit_10pct=6 pre-refactor)
|
feat(recommender): SQL ranking + tier ladder + heat scoring
Plan §4.4 + §13: pure SQL recommender, no AI. Single CTE chain
(feasible -> aggregates) + JS-side tier classification, fall-through
cooldown filter, heat scoring, and fit ranking. Per-port settings via
system_settings layered over global + DEFAULT_RECOMMENDER_SETTINGS.
Tier ladder (default):
A : no interest history
B : lost-only history (still recommendable + boosted by heat)
C : active interest in early stage (open..eoi_signed)
D : active interest at deposit_10pct or beyond (hidden by default)
Heat (only for tier B):
recency weight 30 full @ <=30 days, decays to 0 @ 365 days
furthest stage weight 40 full when prior reached deposit
interest count weight 15 saturates at 5+
EOI count weight 15 saturates at 3+
Multi-port isolation enforced (§14.10 critical): the SQL filters by
port_id AND the entry-point function rejects cross-port interest
lookups with an explicit error. Fall-through policy supports
immediate_with_heat (default), cooldown, and never_auto_recommend.
15 unit tests covering tier classification, heat saturation, weight
tuning, zero-weight guard. Smoke-tested end-to-end via
scripts/dev-recommender-smoke.ts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 02:58:34 +02:00
|
|
|
},
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(h.furthestStage).toBeCloseTo(40, 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('saturates interest-count at 5+', () => {
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: null,
|
|
|
|
|
totalInterestCount: 10,
|
|
|
|
|
eoiSignedCount: 0,
|
|
|
|
|
fallthroughMaxStage: 0,
|
|
|
|
|
},
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(h.interestCount).toBeCloseTo(15, 1); // full weight
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('saturates EOI-count at 3+', () => {
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: null,
|
|
|
|
|
totalInterestCount: 0,
|
|
|
|
|
eoiSignedCount: 5,
|
|
|
|
|
fallthroughMaxStage: 0,
|
|
|
|
|
},
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(h.eoiCount).toBeCloseTo(15, 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('total ≈ 100 when everything is maxed', () => {
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: new Date('2026-04-25T00:00:00Z'),
|
|
|
|
|
totalInterestCount: 5,
|
|
|
|
|
eoiSignedCount: 3,
|
|
|
|
|
fallthroughMaxStage: 6,
|
|
|
|
|
},
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(h.total).toBeGreaterThanOrEqual(99);
|
|
|
|
|
expect(h.total).toBeLessThanOrEqual(100);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('respects tunable per-port weights (skewed toward recency)', () => {
|
|
|
|
|
const skewed = {
|
|
|
|
|
heatWeightRecency: 100,
|
|
|
|
|
heatWeightFurthestStage: 0,
|
|
|
|
|
heatWeightInterestCount: 0,
|
|
|
|
|
heatWeightEoiCount: 0,
|
|
|
|
|
};
|
|
|
|
|
const recent = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: new Date('2026-04-25T00:00:00Z'),
|
|
|
|
|
totalInterestCount: 0,
|
|
|
|
|
eoiSignedCount: 0,
|
|
|
|
|
fallthroughMaxStage: 0,
|
|
|
|
|
},
|
|
|
|
|
skewed,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(recent.total).toBeCloseTo(100, 1);
|
|
|
|
|
|
|
|
|
|
const old = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: new Date('2024-01-01T00:00:00Z'),
|
|
|
|
|
totalInterestCount: 5,
|
|
|
|
|
eoiSignedCount: 3,
|
|
|
|
|
fallthroughMaxStage: 6,
|
|
|
|
|
},
|
|
|
|
|
skewed,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(old.total).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('zero-weights guard (no division-by-zero blow-up)', () => {
|
|
|
|
|
const zeros = {
|
|
|
|
|
heatWeightRecency: 0,
|
|
|
|
|
heatWeightFurthestStage: 0,
|
|
|
|
|
heatWeightInterestCount: 0,
|
|
|
|
|
heatWeightEoiCount: 0,
|
|
|
|
|
};
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{
|
|
|
|
|
latestFallthroughAt: new Date(),
|
|
|
|
|
totalInterestCount: 5,
|
|
|
|
|
eoiSignedCount: 3,
|
|
|
|
|
fallthroughMaxStage: 6,
|
|
|
|
|
},
|
|
|
|
|
zeros,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
|
|
|
|
expect(h.total).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
feat(audit-cleanup): finish all 15 outstanding items from verified backlog
Audit cleanup completion plan, all tiers shipped:
Tier 1 (security + data integrity)
- A.7 RTBF true wipe: redact email_messages body/subject/addresses for
threads owned by deleted client; redact document_sends.recipient_email;
collect file storage keys + delete blobs post-commit.
- A.8 user_permission_overrides FK: documented inline why cascade is
correct (not set-null as audit suggested) — overrides have no value
without their user.
- W2.14 PII redaction: camelCase normalization in audit.ts +
error-events.service.ts isSensitiveKey; added city/postal/country/
birth fragments. firstName/lastName/dateOfBirth/postalCode etc. now
caught in BOTH masker paths. 12 new test cases lock the coverage.
Tier 2 (Documenso completion + refactor)
- C.2: documentEvents.recipient_email column + partial unique index for
per-recipient webhook dedup (migration 0075). handleDocumentSigned
now sets recipient_email on insert.
- Phase 2: completion_cc_emails distribution. handleDocumentCompleted
reads documents.completionCcEmails, filters out signer-duplicates
case-insensitively, fans signed PDF out to non-signer recipients.
- C.4: extracted createPublicInterest() service from the 346-line
api/public/interests route. Route becomes a thin shell (rate-limit,
port resolution, audit log, email fan-out). The trio creation logic
is now unit-testable without an HTTP fixture.
- Phase 4: POST /api/v1/document-templates/[id]/detect-fields wired
to document-field-detector.detectFields(). Sparkles "Auto-detect"
button added to template-editor.tsx — maps DetectedField → marker
with best-guess merge token (DATE / NAME / EMAIL); user retags.
Tier 3 (reporting + recommender snapshot lockfiles)
- W7.reports: extracted rollupStageRevenue / rollupStageCounts /
computeTotalForecast / computeOccupancyRate / rollupBerthStatusCounts
into src/lib/services/report-math.ts (pure functions). 16 new tests
including an inline-snapshot lockfile on a representative 7-stage
forecast. report-generators.ts now delegates.
- W7.recommender: 18 new toMatchSnapshot tripwires on classifyTier
boundaries + computeHeat at canonical input points.
Tier 4 (rolling)
- W6.attach: fixed outdated CLAUDE.md claim — threshold banner is
informational and never depended on IMAP; bounce monitoring (the
IMAP poller) is separate.
- D.1 + D.2: documented deferral inline with full why-not-build-it
reasoning so a future engineer sees the rationale.
- G.1: representative formatDate sweep (audit-log-list, user-list,
document-templates merge tokens, document-signing email). Rest of
the ~100 sites stay rolling.
Quality gates: 1420/1420 vitest (46 new tests above baseline of 1374),
tsc clean, 0 lint errors.
Plan: docs/superpowers/plans/2026-05-18-audit-cleanup-completion.md
Migration: 0075_c2_document_events_recipient_email.sql (applied to dev DB).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 18:22:36 +02:00
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
// ─── W7 snapshot lockfile - locks current tier-ladder boundaries and heat
|
feat(audit-cleanup): finish all 15 outstanding items from verified backlog
Audit cleanup completion plan, all tiers shipped:
Tier 1 (security + data integrity)
- A.7 RTBF true wipe: redact email_messages body/subject/addresses for
threads owned by deleted client; redact document_sends.recipient_email;
collect file storage keys + delete blobs post-commit.
- A.8 user_permission_overrides FK: documented inline why cascade is
correct (not set-null as audit suggested) — overrides have no value
without their user.
- W2.14 PII redaction: camelCase normalization in audit.ts +
error-events.service.ts isSensitiveKey; added city/postal/country/
birth fragments. firstName/lastName/dateOfBirth/postalCode etc. now
caught in BOTH masker paths. 12 new test cases lock the coverage.
Tier 2 (Documenso completion + refactor)
- C.2: documentEvents.recipient_email column + partial unique index for
per-recipient webhook dedup (migration 0075). handleDocumentSigned
now sets recipient_email on insert.
- Phase 2: completion_cc_emails distribution. handleDocumentCompleted
reads documents.completionCcEmails, filters out signer-duplicates
case-insensitively, fans signed PDF out to non-signer recipients.
- C.4: extracted createPublicInterest() service from the 346-line
api/public/interests route. Route becomes a thin shell (rate-limit,
port resolution, audit log, email fan-out). The trio creation logic
is now unit-testable without an HTTP fixture.
- Phase 4: POST /api/v1/document-templates/[id]/detect-fields wired
to document-field-detector.detectFields(). Sparkles "Auto-detect"
button added to template-editor.tsx — maps DetectedField → marker
with best-guess merge token (DATE / NAME / EMAIL); user retags.
Tier 3 (reporting + recommender snapshot lockfiles)
- W7.reports: extracted rollupStageRevenue / rollupStageCounts /
computeTotalForecast / computeOccupancyRate / rollupBerthStatusCounts
into src/lib/services/report-math.ts (pure functions). 16 new tests
including an inline-snapshot lockfile on a representative 7-stage
forecast. report-generators.ts now delegates.
- W7.recommender: 18 new toMatchSnapshot tripwires on classifyTier
boundaries + computeHeat at canonical input points.
Tier 4 (rolling)
- W6.attach: fixed outdated CLAUDE.md claim — threshold banner is
informational and never depended on IMAP; bounce monitoring (the
IMAP poller) is separate.
- D.1 + D.2: documented deferral inline with full why-not-build-it
reasoning so a future engineer sees the rationale.
- G.1: representative formatDate sweep (audit-log-list, user-list,
document-templates merge tokens, document-signing email). Rest of
the ~100 sites stay rolling.
Quality gates: 1420/1420 vitest (46 new tests above baseline of 1374),
tsc clean, 0 lint errors.
Plan: docs/superpowers/plans/2026-05-18-audit-cleanup-completion.md
Migration: 0075_c2_document_events_recipient_email.sql (applied to dev DB).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 18:22:36 +02:00
|
|
|
// ordering so weight-tuning changes can't silently shift outputs. The
|
|
|
|
|
// existing toBe / toBeCloseTo tests above cover correctness; these
|
|
|
|
|
// inline snapshots are the regression-catching tripwires.
|
|
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('W7 snapshots - tier-ladder boundaries', () => {
|
feat(audit-cleanup): finish all 15 outstanding items from verified backlog
Audit cleanup completion plan, all tiers shipped:
Tier 1 (security + data integrity)
- A.7 RTBF true wipe: redact email_messages body/subject/addresses for
threads owned by deleted client; redact document_sends.recipient_email;
collect file storage keys + delete blobs post-commit.
- A.8 user_permission_overrides FK: documented inline why cascade is
correct (not set-null as audit suggested) — overrides have no value
without their user.
- W2.14 PII redaction: camelCase normalization in audit.ts +
error-events.service.ts isSensitiveKey; added city/postal/country/
birth fragments. firstName/lastName/dateOfBirth/postalCode etc. now
caught in BOTH masker paths. 12 new test cases lock the coverage.
Tier 2 (Documenso completion + refactor)
- C.2: documentEvents.recipient_email column + partial unique index for
per-recipient webhook dedup (migration 0075). handleDocumentSigned
now sets recipient_email on insert.
- Phase 2: completion_cc_emails distribution. handleDocumentCompleted
reads documents.completionCcEmails, filters out signer-duplicates
case-insensitively, fans signed PDF out to non-signer recipients.
- C.4: extracted createPublicInterest() service from the 346-line
api/public/interests route. Route becomes a thin shell (rate-limit,
port resolution, audit log, email fan-out). The trio creation logic
is now unit-testable without an HTTP fixture.
- Phase 4: POST /api/v1/document-templates/[id]/detect-fields wired
to document-field-detector.detectFields(). Sparkles "Auto-detect"
button added to template-editor.tsx — maps DetectedField → marker
with best-guess merge token (DATE / NAME / EMAIL); user retags.
Tier 3 (reporting + recommender snapshot lockfiles)
- W7.reports: extracted rollupStageRevenue / rollupStageCounts /
computeTotalForecast / computeOccupancyRate / rollupBerthStatusCounts
into src/lib/services/report-math.ts (pure functions). 16 new tests
including an inline-snapshot lockfile on a representative 7-stage
forecast. report-generators.ts now delegates.
- W7.recommender: 18 new toMatchSnapshot tripwires on classifyTier
boundaries + computeHeat at canonical input points.
Tier 4 (rolling)
- W6.attach: fixed outdated CLAUDE.md claim — threshold banner is
informational and never depended on IMAP; bounce monitoring (the
IMAP poller) is separate.
- D.1 + D.2: documented deferral inline with full why-not-build-it
reasoning so a future engineer sees the rationale.
- G.1: representative formatDate sweep (audit-log-list, user-list,
document-templates merge tokens, document-signing email). Rest of
the ~100 sites stay rolling.
Quality gates: 1420/1420 vitest (46 new tests above baseline of 1374),
tsc clean, 0 lint errors.
Plan: docs/superpowers/plans/2026-05-18-audit-cleanup-completion.md
Migration: 0075_c2_document_events_recipient_email.sql (applied to dev DB).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 18:22:36 +02:00
|
|
|
it.each([
|
|
|
|
|
[0, 0, 0],
|
|
|
|
|
[0, 1, 0],
|
|
|
|
|
[0, 5, 0],
|
|
|
|
|
[1, 0, 1],
|
|
|
|
|
[1, 0, 3],
|
|
|
|
|
[1, 0, 4],
|
|
|
|
|
[1, 0, 5],
|
|
|
|
|
[1, 0, 6],
|
|
|
|
|
[1, 5, 6],
|
|
|
|
|
[2, 0, 5],
|
|
|
|
|
[3, 2, 4],
|
|
|
|
|
])(
|
|
|
|
|
'tier(active=%i, lost=%i, stage=%i) is stable',
|
|
|
|
|
(activeInterestCount, lostCount, maxActiveStage) => {
|
|
|
|
|
expect({
|
|
|
|
|
in: { activeInterestCount, lostCount, maxActiveStage },
|
|
|
|
|
out: classifyTier({ activeInterestCount, lostCount, maxActiveStage }),
|
|
|
|
|
}).toMatchSnapshot();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('W7 snapshots - heat at canonical inputs', () => {
|
feat(audit-cleanup): finish all 15 outstanding items from verified backlog
Audit cleanup completion plan, all tiers shipped:
Tier 1 (security + data integrity)
- A.7 RTBF true wipe: redact email_messages body/subject/addresses for
threads owned by deleted client; redact document_sends.recipient_email;
collect file storage keys + delete blobs post-commit.
- A.8 user_permission_overrides FK: documented inline why cascade is
correct (not set-null as audit suggested) — overrides have no value
without their user.
- W2.14 PII redaction: camelCase normalization in audit.ts +
error-events.service.ts isSensitiveKey; added city/postal/country/
birth fragments. firstName/lastName/dateOfBirth/postalCode etc. now
caught in BOTH masker paths. 12 new test cases lock the coverage.
Tier 2 (Documenso completion + refactor)
- C.2: documentEvents.recipient_email column + partial unique index for
per-recipient webhook dedup (migration 0075). handleDocumentSigned
now sets recipient_email on insert.
- Phase 2: completion_cc_emails distribution. handleDocumentCompleted
reads documents.completionCcEmails, filters out signer-duplicates
case-insensitively, fans signed PDF out to non-signer recipients.
- C.4: extracted createPublicInterest() service from the 346-line
api/public/interests route. Route becomes a thin shell (rate-limit,
port resolution, audit log, email fan-out). The trio creation logic
is now unit-testable without an HTTP fixture.
- Phase 4: POST /api/v1/document-templates/[id]/detect-fields wired
to document-field-detector.detectFields(). Sparkles "Auto-detect"
button added to template-editor.tsx — maps DetectedField → marker
with best-guess merge token (DATE / NAME / EMAIL); user retags.
Tier 3 (reporting + recommender snapshot lockfiles)
- W7.reports: extracted rollupStageRevenue / rollupStageCounts /
computeTotalForecast / computeOccupancyRate / rollupBerthStatusCounts
into src/lib/services/report-math.ts (pure functions). 16 new tests
including an inline-snapshot lockfile on a representative 7-stage
forecast. report-generators.ts now delegates.
- W7.recommender: 18 new toMatchSnapshot tripwires on classifyTier
boundaries + computeHeat at canonical input points.
Tier 4 (rolling)
- W6.attach: fixed outdated CLAUDE.md claim — threshold banner is
informational and never depended on IMAP; bounce monitoring (the
IMAP poller) is separate.
- D.1 + D.2: documented deferral inline with full why-not-build-it
reasoning so a future engineer sees the rationale.
- G.1: representative formatDate sweep (audit-log-list, user-list,
document-templates merge tokens, document-signing email). Rest of
the ~100 sites stay rolling.
Quality gates: 1420/1420 vitest (46 new tests above baseline of 1374),
tsc clean, 0 lint errors.
Plan: docs/superpowers/plans/2026-05-18-audit-cleanup-completion.md
Migration: 0075_c2_document_events_recipient_email.sql (applied to dev DB).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 18:22:36 +02:00
|
|
|
const NOW = new Date('2026-05-05T00:00:00Z');
|
|
|
|
|
const w = DEFAULT_RECOMMENDER_SETTINGS;
|
|
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
|
// [label, fallthroughDaysAgo|null, totalInterestCount, eoiSignedCount, fallthroughMaxStage]
|
|
|
|
|
['cold (no history)', null, 0, 0, 0],
|
|
|
|
|
['recent fallthrough at enquiry stage', 5, 1, 0, 1],
|
|
|
|
|
['recent fallthrough at eoi stage', 5, 2, 1, 3],
|
|
|
|
|
['recent fallthrough at deposit stage (deepest hurt)', 5, 5, 3, 5],
|
|
|
|
|
['old fallthrough at deposit stage (recency decayed)', 120, 5, 3, 5],
|
|
|
|
|
['no fallthrough but many interests', null, 8, 4, 0],
|
|
|
|
|
['typical mid-funnel hot lead', 14, 3, 2, 4],
|
|
|
|
|
])('heat: %s', (_label, daysAgo, totalInterestCount, eoiSignedCount, fallthroughMaxStage) => {
|
|
|
|
|
const latestFallthroughAt =
|
|
|
|
|
daysAgo === null ? null : new Date(NOW.getTime() - daysAgo * 86400 * 1000);
|
|
|
|
|
const h = computeHeat(
|
|
|
|
|
{ latestFallthroughAt, totalInterestCount, eoiSignedCount, fallthroughMaxStage },
|
|
|
|
|
w,
|
|
|
|
|
NOW,
|
|
|
|
|
);
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
// Snapshot the rounded breakdown - exact float math (toBeCloseTo)
|
feat(audit-cleanup): finish all 15 outstanding items from verified backlog
Audit cleanup completion plan, all tiers shipped:
Tier 1 (security + data integrity)
- A.7 RTBF true wipe: redact email_messages body/subject/addresses for
threads owned by deleted client; redact document_sends.recipient_email;
collect file storage keys + delete blobs post-commit.
- A.8 user_permission_overrides FK: documented inline why cascade is
correct (not set-null as audit suggested) — overrides have no value
without their user.
- W2.14 PII redaction: camelCase normalization in audit.ts +
error-events.service.ts isSensitiveKey; added city/postal/country/
birth fragments. firstName/lastName/dateOfBirth/postalCode etc. now
caught in BOTH masker paths. 12 new test cases lock the coverage.
Tier 2 (Documenso completion + refactor)
- C.2: documentEvents.recipient_email column + partial unique index for
per-recipient webhook dedup (migration 0075). handleDocumentSigned
now sets recipient_email on insert.
- Phase 2: completion_cc_emails distribution. handleDocumentCompleted
reads documents.completionCcEmails, filters out signer-duplicates
case-insensitively, fans signed PDF out to non-signer recipients.
- C.4: extracted createPublicInterest() service from the 346-line
api/public/interests route. Route becomes a thin shell (rate-limit,
port resolution, audit log, email fan-out). The trio creation logic
is now unit-testable without an HTTP fixture.
- Phase 4: POST /api/v1/document-templates/[id]/detect-fields wired
to document-field-detector.detectFields(). Sparkles "Auto-detect"
button added to template-editor.tsx — maps DetectedField → marker
with best-guess merge token (DATE / NAME / EMAIL); user retags.
Tier 3 (reporting + recommender snapshot lockfiles)
- W7.reports: extracted rollupStageRevenue / rollupStageCounts /
computeTotalForecast / computeOccupancyRate / rollupBerthStatusCounts
into src/lib/services/report-math.ts (pure functions). 16 new tests
including an inline-snapshot lockfile on a representative 7-stage
forecast. report-generators.ts now delegates.
- W7.recommender: 18 new toMatchSnapshot tripwires on classifyTier
boundaries + computeHeat at canonical input points.
Tier 4 (rolling)
- W6.attach: fixed outdated CLAUDE.md claim — threshold banner is
informational and never depended on IMAP; bounce monitoring (the
IMAP poller) is separate.
- D.1 + D.2: documented deferral inline with full why-not-build-it
reasoning so a future engineer sees the rationale.
- G.1: representative formatDate sweep (audit-log-list, user-list,
document-templates merge tokens, document-signing email). Rest of
the ~100 sites stay rolling.
Quality gates: 1420/1420 vitest (46 new tests above baseline of 1374),
tsc clean, 0 lint errors.
Plan: docs/superpowers/plans/2026-05-18-audit-cleanup-completion.md
Migration: 0075_c2_document_events_recipient_email.sql (applied to dev DB).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 18:22:36 +02:00
|
|
|
// is covered above; this locks the relative ordering + magnitude.
|
|
|
|
|
expect({
|
|
|
|
|
total: Math.round(h.total * 1000) / 1000,
|
|
|
|
|
recency: Math.round(h.recency * 1000) / 1000,
|
|
|
|
|
furthestStage: Math.round(h.furthestStage * 1000) / 1000,
|
|
|
|
|
interestCount: Math.round(h.interestCount * 1000) / 1000,
|
|
|
|
|
eoiCount: Math.round(h.eoiCount * 1000) / 1000,
|
|
|
|
|
}).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
});
|