Compare commits

...
6 Commits
Author SHA1 Message Date
jesse-ux e6dab80aa0 docs: record issue 311 verification after staging update
Independent Staging Quality Gate / publish (pull_request) Blocked by required conditions
Independent Staging Quality Gate / validate-python (pull_request) In progress
Independent Staging Quality Gate / validate-frontend (pull_request) In progress
2026-11-17 13:29:57 +08:00
jesse-ux 5b94e7635d merge: retain staging bug records for issue 311 2026-11-17 13:24:19 +08:00
jesse-ux f41f8209f9 test: verify aggregate v3 on migrated PostgreSQL 2026-11-17 13:22:58 +08:00
jesse-ux 90bc15679a feat: add read-only rectification aggregate v3 coverage 2026-11-17 13:16:31 +08:00
jesse-ux 29876630e4 Merge remote-tracking branch 'origin/codex/rect-p0-aggregate-v3-20261117' into codex/rect-p0-aggregate-v3-20261117 2026-11-17 13:09:35 +08:00
ClaudeandClaude Fable 5.2 3f45759737 docs: brief for rectification P0 aggregate v3 coverage (BUG-1957)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
2026-11-17 12:13:14 +08:00
7 changed files with 820 additions and 0 deletions
+4
View File
@@ -1,5 +1,9 @@
# 印度占星 Skill 更新日志
## 2026-11-17 · 生时纠正聚合统计补齐覆盖缺口
- 内部只读 v3 单列缺回执、悬空引用、新旧选边与未覆盖产物,保留 v2。Skill 版本沿用(BUG-1957)。
## 2026-11-17 · 生时范围用途扫描补充覆盖依据
- 离线扫描为 Arudha、Vimshottari 和 Narayana 回执记录经校验的覆盖依据(BUG-1938)。Skill 版本沿用。
+11
View File
@@ -26287,3 +26287,14 @@
- 验证与防复发:`tests/test_d2_hora_leftovers_1955.py` 三条、`frontend/tests/consult-d2-hora-leftovers-1955.test.ts` 三条;`tests/test_reading_facts_v3_20261112.py` 与 `tests/test_reading_status_axes_20261112.py` 被钉住的断言按原值、新值、原因更新。公开测试盘财富题判断表改前改后已对比。没有调用模型。
- 关联记录:BUG-1907、BUG-1954、BUG-1852。
- 修复版本:`claude/d2-house-leftovers-1955`,未推送。
## BUG-1957 | 生时纠正聚合统计遗漏无回执或无绑定产物
- 状态:fixed-pending-verify(待独立验收)。
- 首次发现 / 最近更新:2026-11-17 / 2026-11-17。
- 触发与现象:用 v2 审核现存旧产物时,无历史回执的采用档案、无双主体绑定的旧独立合盘、悬空引用和白名单外报告没有独立输出。新增自选可沿用旧手选分组。
- 根因:历史统计以已有回执为入口,产物关联假定绑定有效。旧手选规则不区分新自选的依据字段。
- 修复:保留 v2,另加只读 v3。绑定检查纳入所有者和主体,新增缺回执、悬空、旧选边、新自选、白名单外和未绑定总量。所有计数沿用屏蔽,覆盖说明单列。
- 验证与防复发:用仓内迁移和隔离 PostgreSQL 验证空库、其他人物、错绑、双边去重、同秒换来源和模糊组屏蔽,详见 [#311 进度](tasks/PROGRESS-rect-p0-aggregate-v3-20261117.md)。
- 关联记录:#311、#296、BUG-1931、BUG-1890、BUG-1936。
- 修复版本:`codex/rect-p0-aggregate-v3-20261117`,待独立验收。
@@ -0,0 +1,387 @@
-- Rectification P0 aggregate v3, 2026-11-17. Internal authorized audit only.
-- Schema: staging 1c921c956. Check the actual columns and status constraints
-- before any audit. Record the script SHA-256, migration version, execution
-- time, and the audit role's effective row visibility.
-- Use an authorized read-only audit identity with verified cross-account
-- visibility. A caller restricted by RLS can see zero while other rows exist.
-- Do not use a superuser. The execution tool sets timeouts, for example
-- SET LOCAL statement_timeout = '30s';
-- SET LOCAL lock_timeout = '3s';
-- SET LOCAL idle_in_transaction_session_timeout = '30s';
-- On timeout or error, roll back, disconnect, and leave retries to the owner.
-- Zero is visible; 1–4 is masked. Potentially revealing unknown and conflict
-- totals are suppressed. Groups and features overlap and must not be added.
-- Even has_any exposes whether a small group exists. Keep results internal.
-- Neither these counts nor has_any = no authorize bulk withdrawal or establish
-- that legacy artifacts are safe. An old receipt does not date a report's input.
--
-- Added metric sections: provenance_without_history, artifacts_without_subject,
-- legacy_chart_side, self_choice_20261116, reports_outside_whitelist,
-- standalone_synastry_unbound, coverage_notes.
-- 20260806010000_personal_reports.sql and 20261019010000_synastry_full_report.sql
-- use plain subject UUID/text columns. The current delete_chart_subject RPC
-- (20261101010000_rectification_chart_subject.sql) removes referenced personal,
-- annual and full synastry reports. Direct person deletion can leave those
-- plain references dangling. The 20261018010000_synastry_reports_marriage_match.sql
-- trigger removes referenced standalone rows on person deletion. A prior
-- missing reference is still measurable. No subject-column FK sets IDs to null.
-- Bare nulls cannot establish prior binding; artifacts_subject_nulled has
-- no defensible count and appears in coverage_notes, never as an asserted zero.
-- The standalone unbound metric is only a total; attribution is unavailable.
-- V1 explicit side picks are user_override/override with before/after. In the
-- old engine, event evidence is evidence/event; majority, strong_override,
-- tie_keeps_reported and reported_kept come from answers or the reported side.
-- Exclude those and chart_answers. A matched old side pick remains auditable
-- independently of the withdrawal categories.
begin transaction isolation level repeatable read read only;
with subjects as (
select id as owner_id, null::uuid as subject_id, birth_time_status, birth_date,
active_birth_date, active_birth_time, active_birth_provenance as provenance
from public.profiles
union all
select user_id, id, birth_time_status, birth_date,
active_birth_date, active_birth_time, active_birth_provenance
from public.chart_profiles
where role = 'other'
), record_evidence as (
select r.id, r.user_id, r.chart_profile_id, r.saved_date, r.saved_time, r.chosen_side, r.rule,
p.provenance, p.decision, p.contract,
coalesce(p.provenance ->> 'basis', p.decision ->> 'basis')
is not distinct from 'self_choice_20261116' as is_self_choice,
coalesce(p.decision ->> 'rule', p.provenance ->> 'rule', r.rule) as receipt_rule,
coalesce(p.decision ->> 'decided_by', p.provenance ->> 'decided_by') as decided_by
from public.chart_choice_records r
join subjects s on s.owner_id = r.user_id and s.subject_id is not distinct from r.chart_profile_id
cross join lateral (
select r.detail -> 'provenance' as provenance, r.detail -> 'decision' as decision,
coalesce(r.detail #>> '{provenance,contract}',
case when jsonb_typeof(r.detail -> 'decision') = 'object'
and r.detail #> '{decision,segment}' is null
then 'chart-choice-v1' end) as contract
) p
), active as (
select s.*, r.id as receipt_id,
coalesce(jsonb_typeof(r.provenance) = 'object' or jsonb_typeof(r.decision) = 'object', false) as has_receipt,
s.provenance ->> 'basis' is not distinct from 'self_choice_20261116' as self_choice_basis,
(s.provenance ->> 'basis' is not distinct from 'self_choice_20261116'
or coalesce(r.is_self_choice, false)) as is_self_choice,
exists (
select 1 from record_evidence h
where h.user_id = s.owner_id and h.chart_profile_id is not distinct from s.subject_id
) as has_history
from subjects s
left join record_evidence r
on r.user_id = s.owner_id and r.chart_profile_id is not distinct from s.subject_id
and r.saved_date = coalesce(s.active_birth_date, s.birth_date)
and r.saved_time = s.active_birth_time
and r.id = case when s.provenance ->> 'record_id' ~* '^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$'
then (s.provenance ->> 'record_id')::uuid end
where s.active_birth_time is not null and s.birth_time_status in ('accepted', 'confirmed')
), legacy_side_receipts as (
select id, user_id as owner_id, chart_profile_id as subject_id
from record_evidence r
where r.contract = 'chart-choice-v1' and not r.is_self_choice
and r.chosen_side in ('before', 'after')
and (r.receipt_rule = 'user_override' or r.decided_by = 'override')
and coalesce(r.decided_by, 'override') = 'override'
and r.receipt_rule not in ('evidence', 'chart_answers', 'majority', 'strong_override', 'tie_keeps_reported', 'reported_kept')
and r.provenance ->> 'source' is distinct from 'user_choice_from_answers'
), legacy_side_active as (
select a.owner_id, a.subject_id
from active a
where not a.is_self_choice
and (
exists (select 1 from legacy_side_receipts r where r.id = a.receipt_id)
or (a.provenance ->> 'contract' = 'chart-choice-v1'
and a.provenance ->> 'chosen_side' in ('before', 'after')
and (a.provenance ->> 'rule' = 'user_override' or a.provenance ->> 'decided_by' = 'override')
and coalesce(a.provenance ->> 'decided_by', 'override') = 'override'
and coalesce(a.provenance ->> 'rule', 'user_override')
not in ('evidence', 'chart_answers', 'majority', 'strong_override', 'tie_keeps_reported', 'reported_kept')
and a.provenance ->> 'source' is distinct from 'user_choice_from_answers')
)
), evidence as (
-- Keep recorded, decision and active rules independent so one cannot mask another.
select 'history' as scope, r.user_id as owner_id, r.chart_profile_id as subject_id,
r.contract, r.provenance ->> 'source' as source, facts.rule, facts.decided_by, facts.rounds
from record_evidence r
cross join lateral (
values (r.provenance ->> 'rule', r.provenance ->> 'decided_by', r.provenance -> 'rounds'),
(r.decision ->> 'rule', r.decision ->> 'decided_by', r.decision -> 'rounds'),
(r.rule, coalesce(r.decision ->> 'decided_by', r.provenance ->> 'decided_by'),
coalesce(r.decision -> 'rounds', r.provenance -> 'rounds'))
) facts(rule, decided_by, rounds)
where not r.is_self_choice
union all
select 'active', a.owner_id, a.subject_id, facts.contract, facts.source, facts.rule, facts.decided_by, facts.rounds
from active a
left join record_evidence r on r.id = a.receipt_id
cross join lateral (
values (a.provenance ->> 'contract', a.provenance ->> 'source', a.provenance ->> 'rule',
a.provenance ->> 'decided_by', a.provenance -> 'rounds'),
(r.contract, r.provenance ->> 'source', r.provenance ->> 'rule',
r.provenance ->> 'decided_by', r.provenance -> 'rounds'),
(coalesce(r.contract, a.provenance ->> 'contract'), null, r.decision ->> 'rule',
r.decision ->> 'decided_by', r.decision -> 'rounds'),
(coalesce(r.contract, a.provenance ->> 'contract'), null, r.rule,
coalesce(r.decision ->> 'decided_by', r.provenance ->> 'decided_by'),
coalesce(r.decision -> 'rounds', r.provenance -> 'rounds'))
) facts(contract, source, rule, decided_by, rounds)
where not a.is_self_choice
), signals as (
select scope, owner_id, subject_id,
coalesce(bool_or(source = 'user_choice_from_answers' or rule = 'chart_answers'), false) as old_questionnaire,
coalesce(bool_or(contract = 'chart-choice-v1' and rule = 'evidence' and decided_by = 'event'), false) as old_event,
coalesce(bool_or(contract = 'segment-v1' or source = 'server_segment_midpoint'), false) as old_segment,
coalesce(bool_or(rule = 'user_override'), false) as manual_choice,
coalesce(bool_or(contract = 'chart-choice-v2' and jsonb_typeof(rounds) = 'array' and rounds <> '[]'::jsonb),
false) as chart_side,
coalesce(bool_or(source in ('reported_time_default', 'window_midpoint_default')), false) as declared_default
from evidence
group by scope, owner_id, subject_id
), active_features as (
select a.owner_id, a.subject_id, a.provenance, a.has_history, a.has_receipt,
s.old_questionnaire or (s.manual_choice and coalesce(h.old_questionnaire, false)) as old_questionnaire,
s.old_event or (s.manual_choice and coalesce(h.old_event, false)) as old_event,
s.old_segment or (s.manual_choice and coalesce(h.old_segment, false)) as old_segment,
s.chart_side or (s.manual_choice and coalesce(h.chart_side, false)) as chart_side,
s.manual_choice, s.declared_default
from active a
join signals s on s.scope = 'active' and s.owner_id = a.owner_id and s.subject_id is not distinct from a.subject_id
-- Old traces on the same subject leave a manual choice open to review even
-- without an active receipt. An audit conflict does not establish causality.
left join signals h on h.scope = 'history' and h.owner_id = a.owner_id and h.subject_id is not distinct from a.subject_id
), active_signals as (
select f.*,
(old_questionnaire::int + old_event::int + old_segment::int
+ manual_choice::int + chart_side::int + declared_default::int) as matches
from active_features f
), features as (
select f.category, count(*) filter (where f.matched) as n
from (values (true)) as zero_fill(dummy)
left join active_signals a on true
cross join lateral (
values ('old_questionnaire', a.old_questionnaire),
('old_event', a.old_event),
('segment-v1', a.old_segment),
('explicit_manual_choice', a.manual_choice and a.matches = 1),
('issue_229_chart_side', a.chart_side),
('declared_default', a.declared_default),
('conflict', a.matches >= 2),
('conflict_manual_and_old', a.matches >= 2 and a.manual_choice
and (a.old_questionnaire or a.old_event or a.old_segment or a.chart_side)),
('conflict_other', a.matches >= 2 and not (a.manual_choice
and (a.old_questionnaire or a.old_event or a.old_segment or a.chart_side))),
('unknown', a.matches = 0)
) f(category, matched)
group by f.category
), provenance_groups as (
select case when provenance ->> 'contract' in ('segment-v1', 'chart-choice-v1', 'chart-choice-v2', 'agentic-rectification-v1')
then provenance ->> 'contract' when provenance ->> 'contract' is null then 'missing' else 'other' end as contract,
case when provenance ->> 'source' in ('user_choice', 'user_choice_from_answers', 'server_segment_midpoint',
'reported_time_default', 'window_midpoint_default', 'certain')
then provenance ->> 'source' when provenance ->> 'source' is null then 'missing' else 'other' end as source,
case when provenance ->> 'rule' in ('chart_answers', 'evidence', 'user_override', 'reused_record', 'reported_time_default',
'window_midpoint_default', 'majority', 'tie_keeps_reported', 'strong_override',
'reported_kept', 'stopped', 'round_limit', 'no_line_in_range')
then provenance ->> 'rule' when provenance ->> 'rule' is null then 'missing' else 'other' end as rule
from active_signals
), active_retired as (
select owner_id, subject_id
from active_signals
where provenance ->> 'retired_reason' = 'BUG-1890' or old_questionnaire or old_event or old_segment
), historical_subjects as (
select q.owner_id, q.subject_id
from signals q
where q.scope = 'history' and (q.old_questionnaire or q.old_event or q.old_segment or q.chart_side)
and exists (
select 1 from subjects s where s.owner_id = q.owner_id and s.subject_id is not distinct from q.subject_id
)
), report_statuses(status) as (
values ('generating'), ('ready'), ('failed')
), report_types(report_type) as (
values ('personal_full'), ('personal_thematic'), ('annual_full'), ('synastry_full')
), artifacts as (
select r.id, r.user_id as owner_id,
case when r.report_type in (select report_type from report_types) then r.report_type else 'other' end as report_type,
case when r.report_type = 'synastry_full'
then array[r.chart_profile_id::text, r.partner_chart_profile_id::text, r.subject_low, r.subject_high]
else array[coalesce(r.chart_profile_id::text, 'self')] end as refs
from public.personal_reports r
union all
select r.id, r.user_id, 'legacy_synastry', array[r.subject_low, r.subject_high]
from public.synastry_reports r
where r.rules_version is null
), artifact_refs as (
select a.id, a.owner_id, a.report_type, lower(p.ref) as ref, binding.subject_id
from artifacts a
cross join lateral unnest(a.refs) p(ref)
cross join lateral (
select case when p.ref ~* '^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$'
then p.ref::uuid end as subject_id
) binding
where p.ref = 'self' or binding.subject_id is not null
), legacy_pairs as (
select id
from artifact_refs
where report_type = 'legacy_synastry'
group by id
having count(distinct ref) = 2
), current_without_history as (
select exists (
select 1 from artifact_refs ar
where ar.owner_id = s.owner_id and ar.ref = coalesce(s.subject_id::text, 'self')
and (ar.report_type <> 'legacy_synastry' or exists (select 1 from legacy_pairs p where p.id = ar.id))
) as has_artifact
from subjects s
where (s.provenance is not null and s.provenance not in ('null'::jsonb, '{}'::jsonb, '[]'::jsonb)
or (s.birth_time_status in ('accepted', 'confirmed') and s.active_birth_time is not null))
and not exists (
select 1 from record_evidence r
where r.user_id = s.owner_id and r.chart_profile_id is not distinct from s.subject_id
)
), missing_subject_artifacts as (
select distinct ar.report_type, ar.id
from artifact_refs ar
where ar.subject_id is not null
and not exists (select 1 from public.chart_profiles c where c.id = ar.subject_id)
and (ar.report_type <> 'legacy_synastry' or exists (select 1 from legacy_pairs p where p.id = ar.id))
), outside_report_counts as (
select case when r.report_type in (select report_type from report_types) then r.report_type else 'other' end as report_type,
case when r.status in (select status from report_statuses) then 'listed' else 'outside' end as status_group,
count(*) as n
from public.personal_reports r
where (r.report_type in (select report_type from report_types)) is not true
or (r.status in (select status from report_statuses)) is not true
group by 1, 2
), artifact_types(report_type) as (
select report_type from report_types union all values ('legacy_synastry'), ('other')
), outside_report_groups(report_type, status_group) as (
select report_type, 'outside' from report_types
union all values ('other', 'listed'), ('other', 'outside')
), coverage_notes(note) as (
values ('browser_downloads_outside_server'),
('delivered_chat_text_not_covered'),
('exports_outside_server'),
('artifacts_subject_nulled_cannot_be_distinguished'),
('unbound_standalone_synastry_has_no_subject_attribution')
), statuses_by_type as (
select t.report_type, s.status from report_types t cross join report_statuses s
union all select 'legacy_synastry', 'not_recorded'
), ready_reports as (
select r.report_type
from public.personal_reports r
where r.status = 'ready' and r.report_type in (select report_type from report_types)
and exists (
select 1 from active_retired s where s.owner_id = r.user_id
and (s.subject_id is not distinct from r.chart_profile_id
or (r.report_type = 'synastry_full' and r.partner_chart_profile_id = s.subject_id))
)
), historical_reports as (
select r.report_type, r.status
from public.personal_reports r
where r.report_type in (select report_type from report_types)
and exists (
select 1 from historical_subjects s where s.owner_id = r.user_id
and (s.subject_id is not distinct from r.chart_profile_id
or (r.report_type = 'synastry_full' and r.partner_chart_profile_id = s.subject_id))
)
union all
select 'legacy_synastry', 'not_recorded'
from public.synastry_reports r
where (r.rules_version is not null or exists (select 1 from legacy_pairs p where p.id = r.id))
and exists (
select 1 from historical_subjects s where s.owner_id = r.user_id
and coalesce(s.subject_id::text, 'self') in (r.subject_low, r.subject_high)
)
), presence(flag) as (
values (true), (false)
), unknown_counts as (
select h.flag as has_history, r.flag as has_receipt, m.flag as missing_contract, count(a.owner_id) as n
from presence h cross join presence r cross join presence m
left join active_signals a on a.matches = 0 and a.has_history = h.flag and a.has_receipt = r.flag
and (a.provenance ->> 'contract' is null) = m.flag
group by h.flag, r.flag, m.flag
), counts as (
select 'provenance' as metric, null::text as category, contract, source, rule,
null::text as report_type, null::text as report_status, null::boolean as has_history,
null::boolean as has_receipt, null::boolean as missing_contract, count(*) as n
from provenance_groups
group by contract, source, rule
union all
select 'provenance', null, 'missing', 'missing', 'missing', null, null, null, null, null, 0
where not exists (select 1 from provenance_groups)
union all
select 'provenance_without_history', g.category, null, null, null, null, null, null, null, null, count(s.has_artifact)
from (values ('has_artifact', true), ('no_artifact', false)) g(category, has_artifact)
left join current_without_history s using (has_artifact)
group by g.category
union all
select 'artifacts_without_subject', null, null, null, null, t.report_type, null, null, null, null, count(r.id)
from artifact_types t left join missing_subject_artifacts r using (report_type)
group by t.report_type
union all
select 'legacy_chart_side', 'active', null, null, null, null, null, null, null, null, count(*)
from legacy_side_active
union all
select 'legacy_chart_side', 'history_only', null, null, null, null, null, null, null, null, count(*)
from subjects s
where exists (select 1 from legacy_side_receipts r where r.owner_id = s.owner_id
and r.subject_id is not distinct from s.subject_id)
and not exists (select 1 from legacy_side_active a where a.owner_id = s.owner_id
and a.subject_id is not distinct from s.subject_id)
union all
select 'self_choice_20261116', 'active', null, null, null, null, null, null, null, null, count(*)
from active where self_choice_basis
union all
select 'self_choice_20261116', 'history', null, null, null, null, null, null, null, null, count(*)
from subjects s
where exists (select 1 from record_evidence r where r.user_id = s.owner_id
and r.chart_profile_id is not distinct from s.subject_id and r.is_self_choice)
union all
select 'reports_outside_whitelist', case when g.report_type = 'other' then 'outside' else 'listed' end,
null, null, null, g.report_type, g.status_group, null, null, null, coalesce(r.n, 0)
from outside_report_groups g left join outside_report_counts r using (report_type, status_group)
union all
select 'standalone_synastry_unbound', null, null, null, null, null, null, null, null, null, count(*)
from artifacts a
where a.report_type = 'legacy_synastry'
and not exists (select 1 from legacy_pairs p where p.id = a.id)
union all
select 'coverage_notes', note, null, null, null, null, null, null, null, null, null
from coverage_notes
union all
select 'feature', category, null, null, null, null, null, null, null, null, f.n
from features f
where (f.category <> 'unknown' or not exists (select 1 from unknown_counts u where u.n between 1 and 4))
and (f.category <> 'conflict' or not exists (
select 1 from features child where child.category in ('conflict_manual_and_old', 'conflict_other')
and child.n between 1 and 4
))
union all
select 'unknown_breakdown', null, null, null, null, null, null, has_history, has_receipt, missing_contract, n
from unknown_counts
union all
select 'active_retired', null, null, null, null, null, null, null, null, null, count(*) from active_retired
union all
select 'ready_reports_on_retired', null, null, null, null, t.report_type, 'ready', null, null, null, count(r.report_type)
from report_types t left join ready_reports r using (report_type)
group by t.report_type
union all
select 'reports_on_historical_sources', null, null, null, null, t.report_type, t.status, null, null, null, count(r.report_type)
from statuses_by_type t left join historical_reports r on r.report_type = t.report_type and r.status = t.status
group by t.report_type, t.status
)
select metric, category, contract, source, rule, report_type, report_status,
case has_history when true then 'yes' when false then 'no' end as has_history,
case has_receipt when true then 'yes' when false then 'no' end as has_receipt,
case missing_contract when true then 'yes' when false then 'no' end as missing_contract,
case when n is null then null when n = 0 then 'no' else 'yes' end as has_any,
case when n between 1 and 4 then '<5' else n::text end as count_display
from counts
order by metric, category, contract, source, rule, report_type, report_status,
has_history, has_receipt, missing_contract;
commit;
@@ -0,0 +1,32 @@
# #311 生时纠正 P0 聚合统计 v3
执行方 Codex。任务书基线 `3d53d6d4`,执行基线 `1c921c95`。关联 BUG-1957。
## 输出段对照
| v2 | v3 | 口径 |
| --- | --- | --- |
| `provenance`、`feature`、`unknown_breakdown` | 沿用,按主体所有者筛回执 | 查当前回执还要同主体、同有效日期、同有效时刻、同记录标识。新自选单列,空库保留零值。 |
| `active_retired`、`ready_reports_on_retired`、`reports_on_historical_sources` | 沿用 | 当前新自选与旧逐线选边按各自来源分类。无双主体绑定的旧独立合盘只进入独立总量。 |
| 无独立输出 | `provenance_without_history` | 按是否有现存产物分组。覆盖有非空来源或有已采用时刻、却没有本人名下有效历史关系的主体。 |
| 无独立输出 | `artifacts_without_subject` | 按产物类型计有悬空引用的报告。完整合盘两侧任一缺失即命中,同一份最多计一次。 |
| V1 手选混在手选特征 | `legacy_chart_side` | V1 显式 `user_override` / `override` 的线前线后,分当前使用和仅有历史。事件和问卷决策排除,不自动纳入撤回。 |
| 无独立输出 | `self_choice_20261116` | 当前来源、历史出现按主体计。单条新自选证据不进旧分类。同一主体可以保留不同阶段的独立历史记录。 |
| 白名单外不输出 | `reports_outside_whitelist` | 类型与状态是否在原白名单双轴分组。未知类型归为 `other`,未知状态只显示 `outside`。 |
| 未绑定行无法归因 | `standalone_synastry_unbound` | 统计无两份有效主体引用、且无规则版本的旧独立合盘总量。 |
| 限制分散在注释 | `coverage_notes` | 固定说明浏览器下载、已交付聊天、离开服务器的导出,以及无法回溯的空绑定。 |
各计数组可重叠。显示零,屏蔽 1–4。覆盖说明只有固定词表,关联产物、档案、报告内容、实际时刻、未知字段值均不进入输出。
## 删除与空绑定
- 个人报告及年运的 `chart_profile_id`,完整合盘的 `partner_chart_profile_id` 与文本双方引用,在当前迁移中都是普通列。正常的 `delete_chart_subject` RPC 清理相关报告。直接删除人物可留下悬空引用,隔离 PostgreSQL 复现。
- 旧独立合盘使用文本双方引用。`20261018010000_synastry_reports_marriage_match.sql` 的人物删除触发器清理命中的行。仍可用审计语句扫描已存在的历史悬空引用。
- 隔离库 `pg_constraint` 核对两类产物表均无指向 `chart_profiles` 的外键。当前结构没有 `SET NULL` 计数来源。无绑定的历史行也无法从 `NULL` 推断过去的绑定,因此以 `coverage_notes` 披露该缺口。
## 验证
- `tsx --test --test-concurrency=1` 运行 v2 与 v3 两个测试文件。两个数据库套件都在独立 PostgreSQL 17 容器中应用仓内迁移并执行合成数据。v2 包含事务检查与 1 个数据库用例。v3 包含事务检查及数据库套件,库内覆盖 5 个子用例。总计 9 通过,0 失败、0 取消、0 跳过。
- Linux `python scripts/run_quality_gate.py --profile quick --skip-frontend-runtime` 通过。TypeScript `--noEmit` 通过。ESLint 0 错误、63 条既有警告。
- 本轮只连本地隔离库。正式审计须由负责人核对角色跨账号可见性、脚本校验值和迁移版本。已下载文件、已交付聊天、脱离服务器的导出及历史空绑定仍无法追溯。
- 合入 staging 的 0ee6b7c7 并保留双方 Bug 历史后,数据库定向、Linux 快速门、TypeScript 和 ESLint 均复验通过。v3 SQL 的本次文件 SHA-256 为 e20c786e64621fe1359805849e64c269c3e7b327740ee8fc3ffe7a6e72f0f9fd。
+1
View File
@@ -7,6 +7,7 @@
- 被环境或依赖挡住的事项写进根目录 `BLOCKED.md`;Bug 事实写进 `docs/BUG_HISTORY.md`;两者不在这里重复。
- 纯文档改动不触发 staging 门禁(见 `deploy/gated-paths.txt`)。
- [生时纠正 P0 聚合统计 v3(#311)](PROGRESS-rect-p0-aggregate-v3-20261117.md) — 输出段、绑定行为及 PostgreSQL 验证。
- [生时纠正开发集复验(#272)](PROGRESS-rect-repro-20261114.md) — 配对重跑、三项消融和逐例数据。
- [上游私人案例与本机路径清理](PROGRESS-owner-case-purge-20260919.md) — 2026-09-19,执行分支已创建;删除依赖与全仓扫描口径发现任务范围冲突,未交付。
- [侧栏导航注册循环修复与验收](PROGRESS-sidebar-navigation-loop-20260919.md) — 2026-09-19,修复/回归已完成,完整验收与 staging 交付状态见记录。
@@ -0,0 +1,66 @@
# 生时纠正 P0 聚合统计 v3:补占星师指出的覆盖缺口(2026-11-17,Claude)
Bug 编号:BUG-1957。关联 BUG-1931(#296)、BUG-1890、BUG-1936。
## 背景
占星师 11-17 审了 `docs/operations/rect-p0-aggregate-20261116-v2.sql`:允许负责人拿它在生产库做一次内部只读摸底,但不能用它证明「旧产物已清零」,因为有几类情况它数不到。本单出 v3,把这些情况数出来,并补齐测试。**v2 文件不动**(负责人可能已按 v2 执行过,要能对照)。
新文件:`docs/operations/rect-p0-aggregate-20261117-v3.sql`,从 v2 复制后修改。沿用 v2 的全部约束:`repeatable read read only` 事务、固定词表、不输出任何个人明细、0 可见、1–4 屏蔽、各 feature 可重叠不可相加。
## 一、要补的统计
每项都作为独立的输出段(`section` 名固定,写进文件头注释),互相可重叠:
1. **有当前来源但没有历史回执的主体**(`provenance_without_history`):`active_birth_provenance` 非空(或 `birth_time_status in ('accepted','confirmed')` 且有 `active_birth_time`),但 `chart_choice_records` 里没有这个主体的任何记录。v2 的 `historical_subjects` 只从 `chart_choice_records` 出发,这类主体不在里面。再按「该主体名下是否有现存报告/年运/合盘」分两组计数。
2. **主体已删除但产物还在**(`artifacts_without_subject`):`personal_reports`(含年运)、完整合盘、旧独立合盘中,`chart_profile_id` 指向已不存在的 `chart_profiles` 行的产物数;按产物类型分组。若外键是 `on delete cascade` 或 `set null`,先查迁移确认实际行为,把结论写进文件头注释和 PROGRESS:级联删除则此项恒为 0 并说明依据;置空则这些产物会被算成「本人」——这种情况要单独数出来(`artifacts_subject_nulled`,若无法区分就写明无法区分,不要猜)。
3. **单独的旧选边记录**(`legacy_chart_side`):历史或当前来源是旧版逐条线选边(`chart-choice-v1` 且 `rule`/`decided_by` 为选边而非事件证据、非问卷)的主体数,分「当前仍在用」和「仅历史出现」。**不把它并入 `active_retired`**:是否属于撤回集合由产品和占星师另行冻结,本单只把数给出来。先读 `frontend/src/lib/retired-birth-window.ts::birthWindowRetired` 和 `scripts/chart_choice/service.py`,把「旧选边」对应的字段取值写准,写进注释。
4. **新自选**(`self_choice_20261116`):当前来源 `basis = 'self_choice_20261116'` 的主体数,以及历史上出现过的主体数。它不得落入任何旧分类(`explicit_manual_choice`、`active_retired`、旧选边);v3 的分类 `CASE`/条件要显式把它排出去,并有测试。
5. **白名单之外的报告**(`reports_outside_whitelist`):`personal_reports` 中报告类型或状态不在 v2 统计白名单里的行数,按(类型是否在白名单、状态是否在白名单)分组,不输出具体类型名以外的任何内容;类型名属于固定词表可以输出,未知类型统一记为 `other`。
6. **无主体绑定的旧独立合盘**(`standalone_synastry_unbound`):`synastry_reports` 中 `rules_version` 为空、没有双主体绑定的行数。v2 注释里说这类「无法归因」,v3 要把总量数出来,输出段注明「无法归因到主体,只有总量」。
7. 在输出里新增一段 `coverage_notes`(固定文本行,不含数据):列出本脚本**仍然数不到**的东西——浏览器已下载的文件、已交付的聊天正文、已离开服务器的导出。让拿到结果的人不会把「没列出」读成「没有」。
## 二、执行条件写进文件头
把占星师要求的运行条件写成文件头注释(不改变 SQL 的事务语句本身):
- 用受权的只读审计身份执行,并先确认它能看到跨账号的行;普通用户在 RLS 下得到的 0 不是全库的 0;不要为了方便换超级用户。
- 执行前核对生产 schema、字段和状态枚举与脚本基线一致;记录脚本 sha256、数据库迁移版本、执行时间、审计身份的可见范围。
- 由执行工具设置 `statement_timeout`、`lock_timeout`、`idle_in_transaction_session_timeout`(给出示例 `set local` 语句,放在注释里);超时或出错即回滚并断开,不自动重试。
- 结果仅限内部审核;`has_any` 会暴露「是否存在少量记录」,不是匿名数据。
- 本脚本的任何结果都不能作为自动批量撤回的依据,`has_any = no` 不证明旧产物已安全。
## 三、测试
新文件 `frontend/tests/rectification-p0-aggregate-v3-20261117.test.ts`,沿用 v2 测试的建库方式和夹具写法(全部合成数据)。v2 的测试文件不动、照旧通过。
每个新增输出段至少一条命中和一条不命中,另加占星师点名的边界:
- `role = 'other'` 的主体(v2 测试主要是本人档案):每个新增段都要有 other 主体的用例。
- 合盘:任一侧命中、双方同时命中只计一次。
- 错误绑定:回执的 `user_id` 与主体所有者不同、`record_id` 指向别人的记录——不得被算成有效回执。
- 空库:所有段输出 0,不报错,`coverage_notes` 照常输出。
- 来源撤回但时刻不变:分类跟随来源,不跟随时刻。
- 无回执、主体已删除两类边界(对应第一节 1、2)。
- 新自选不落入任何旧分类(第一节 4)。
- 屏蔽规则对新增段同样生效(1–4 屏蔽、0 可见)。
**这些是需要 PostgreSQL 的测试。** 本机 Docker 不可用时现有写法会跳过。PROGRESS 里必须写明:哪次运行真正连了数据库、跑了几条、结果如何(staging 质量门里跑到的也算,写明 run 号);没有真正跑过的写「未执行」,不把跳过写成通过。
## 四、文档
- `docs/BUG_HISTORY.md` 新增 BUG-1957(只在自己那一节内编辑;不写姓名、出生资料、邮箱、ID)。
- `CHANGELOG.md` 一行;`docs/tasks/PROGRESS-rect-p0-aggregate-v3-20261117.md`,含 v2→v3 的输出段对照表,和第一节第 2 项的外键行为结论。
- `docs/research/rect-p0-artifact-checklist-20261116.md` 不改(BUG-1956 那一单会追加),避免冲突。
## 五、不做的事
- 不连接、不查询任何生产或 staging 的真实数据;不写任何会修改数据的语句。
- 不改 v2 的 SQL 和测试;不改应用代码、迁移、`scripts/`。
- 不把任何一类自动并入「应撤回」。
## 验收
- `PATH=<venv>/bin:$PATH python scripts/run_quality_gate.py --profile quick --skip-frontend-runtime` 通过;
- `cd frontend && npx eslint .` 0 错误;v2、v3 两个测试文件在有数据库的环境里全部通过(验收看 staging 质量门的记录);
- diff 只含新 SQL、新测试、文档。
@@ -0,0 +1,319 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { randomUUID } from "node:crypto";
import { readFileSync } from "node:fs";
import test from "node:test";
import { fileURLToPath } from "node:url";
import { Client, type QueryResult } from "pg";
import { runMigrations } from "../scripts/db-migrate.mjs";
import { startPostgresFixture } from "./helpers/postgres-fixture.ts";
const script = readFileSync(
new URL("../../docs/operations/rect-p0-aggregate-20261117-v3.sql", import.meta.url),
"utf8",
);
const docker = spawnSync("docker", ["version"], { stdio: "ignore" }).status === 0;
test("BUG-1957 aggregate SQL is a single read-only repeatable-read transaction", () => {
const sql = script.replace(/^--.*$/gm, "").trim();
assert.match(sql, /^begin transaction isolation level repeatable read read only;/i);
assert.match(sql, /\bcommit;$/i);
assert.equal((sql.match(/\b(?:begin transaction|commit)\b/gi) ?? []).length, 2);
assert.doesNotMatch(sql, /\b(?:insert|update|delete|create|alter|truncate|copy)\b/i);
});
type Row = {
metric: string;
category: string | null;
contract: string | null;
source: string | null;
rule: string | null;
report_type: string | null;
report_status: string | null;
has_history: string | null;
has_receipt: string | null;
missing_contract: string | null;
has_any: string | null;
count_display: string | null;
};
const coverageNotes = [
"artifacts_subject_nulled_cannot_be_distinguished",
"browser_downloads_outside_server",
"delivered_chat_text_not_covered",
"exports_outside_server",
"unbound_standalone_synastry_has_no_subject_attribution",
];
function expectCount(rows: Row[], scope: Partial<Row>, n: "0" | "<5" | "5") {
const matches = rows.filter((row) => Object.entries(scope).every(([key, value]) => row[key as keyof Row] === value));
assert.deepEqual(matches.map(({ has_any, count_display }) => [has_any, count_display]),
[[n === "0" ? "no" : "yes", n]], JSON.stringify(scope));
}
const date = "2042-05-06";
const time = "07:08:09";
const oldSide = { contract: "chart-choice-v1", source: "user_choice", rule: "user_override", decided_by: "override", chosen_side: "before" };
const selfChoice = { contract: "chart-choice-v2", source: "user_choice", rule: "user_override", basis: "self_choice_20261116", chosen_side: "before" };
const event = { contract: "chart-choice-v1", rule: "evidence", decided_by: "event", chosen_side: "before" };
const questionnaire = { contract: "chart-choice-v1", source: "user_choice_from_answers", rule: "majority", decided_by: "supplement", chosen_side: "before" };
test("BUG-1957 checks v3 coverage and masking in synthetic PostgreSQL", {
skip: !docker && "docker unavailable",
}, async (t) => {
const fixture = startPostgresFixture();
const url = fixture.connectionUrl("schema_owner", "schema-owner-test-password");
const db = new Client({ connectionString: url });
const privateValues = [date, time, "synthetic-report-body", "synthetic-extra-type", "synthetic-extra-status"];
const newId = () => {
const id = randomUUID();
privateValues.push(id);
return id;
};
async function audit() {
const results = await db.query<Row>(script) as unknown as QueryResult<Row>[];
assert.equal(results.length, 3);
const [begin, aggregate, commit] = results;
assert.equal(begin.command, "BEGIN");
assert.equal(commit.command, "COMMIT");
assert.deepEqual(aggregate.fields.map((field) => field.name), [
"metric", "category", "contract", "source", "rule", "report_type", "report_status",
"has_history", "has_receipt", "missing_contract", "has_any", "count_display",
]);
const output = JSON.stringify(aggregate.rows);
for (const value of privateValues) assert.equal(output.includes(value), false, "aggregate leaked fixture data");
return aggregate.rows;
}
function addOwner() {
const id = newId();
fixture.psqlAs("identity_runtime", "identity-runtime-test-password",
"insert into identity.users(id,name,email,email_verified) values ('" + id
+ "','Fictional Aggregate Fixture','" + id + "@example.invalid',true)");
return id;
}
async function addPerson(owner: string) {
const id = newId();
await db.query(
"insert into public.chart_profiles (id,user_id,role,name,profile,birth_date,reported_birth_time,birth_time_status) "
+ "values ($1,$2,'other','Fictional Fixture','{}',$3,$4,'reported')",
[id, owner, date, time],
);
return id;
}
async function adopt(person: string, provenance: object | null) {
// Synthetic historical states include malformed receipts. Seed them under
// the same transaction-local trusted-write flag used by the adoption RPC.
await db.query("begin");
try {
await db.query("select set_config('jyotisha.rectification_subject_write',$1,true)", [person]);
await db.query(
"update public.chart_profiles set active_birth_date=$2, active_birth_time=$3, "
+ "birth_time_status='accepted', active_birth_provenance=$4 where id=$1",
[person, date, time, provenance],
);
await db.query("commit");
} catch (error) {
await db.query("rollback");
throw error;
}
}
async function receipt(owner: string, person: string, provenance: typeof oldSide | typeof selfChoice | typeof event | typeof questionnaire) {
const id = newId();
await db.query(
"insert into public.chart_choice_records (id,user_id,chart_profile_id,saved_date,saved_time,timezone_offset,"
+ "chosen_side,rule,declaration,detail) values ($1,$2,$3,$4,$5,0,'before',$6,'{}',$7)",
[id, owner, person, date, time, provenance.rule, { provenance }],
);
return id;
}
async function report(owner: string, type: string, primary: string | null, partner: string | null = null, status = "failed") {
const id = newId();
const schema = type === "annual_full" ? "annual_report.v1"
: type === "synastry_full" ? "synastry_report.v1" : "report_document.v2";
await db.query(
"insert into public.personal_reports (id,user_id,request_id,request_fingerprint,report_type,status,schema_version,"
+ "presentation_mode,skill_snapshot_sha256,failure_code,chart_profile_id,partner_chart_profile_id,subject_low,subject_high) "
+ "values ($1,$2,$3,repeat('a',64),$4,$5,$6,'default',repeat('b',64),$7,$8,$9,$10,$11)",
[id, owner, newId(), type, status, schema, status === "failed" ? "report_guard_rejected" : null,
primary, partner, type === "synastry_full" ? primary : null, type === "synastry_full" ? partner : null],
);
return id;
}
async function standalone(owner: string, low: string | null, high: string | null, version: string | null = null) {
const id = newId();
await db.query(
"insert into public.synastry_reports (id,user_id,report,subject_low,subject_high,rules_version) values ($1,$2,$3,$4,$5,$6)",
[id, owner, { preview: "synthetic-report-body" }, low, high, version],
);
return id;
}
try {
assert.equal(await runMigrations({
connectionString: url,
migrationsDirectory: undefined,
migrationsDirectories: ["../db/migrations", "../supabase/migrations"].map(
(directory) => fileURLToPath(new URL(directory, import.meta.url)),
),
}), 0);
await db.connect();
await t.test("empty database produces explicit zeros and data-free coverage notes", async () => {
const rows = await audit();
assert.deepEqual([...new Set(rows.map(({ metric }) => metric))].sort(), [
"active_retired", "artifacts_without_subject", "coverage_notes", "feature", "legacy_chart_side",
"provenance", "provenance_without_history", "ready_reports_on_retired", "reports_on_historical_sources",
"reports_outside_whitelist", "self_choice_20261116", "standalone_synastry_unbound", "unknown_breakdown",
].sort());
assert.ok(rows.filter(({ metric }) => metric !== "coverage_notes")
.every(({ has_any, count_display }) => has_any === "no" && count_display === "0"));
const notes = rows.filter(({ metric }) => metric === "coverage_notes");
assert.deepEqual(notes.map(({ category }) => category), coverageNotes);
assert.ok(notes.every(({ has_any, count_display }) => has_any === null && count_display === null));
});
const owner = addOwner();
const stranger = addOwner();
await t.test("owner-bound receipts and current sources distinguish other subjects with and without artifacts", async () => {
const a = await addPerson(owner);
const b = await addPerson(owner);
const c = await addPerson(owner);
const d = await addPerson(owner);
const correctId = await receipt(owner, d, event);
const mismatchedId = await receipt(stranger, c, oldSide);
await adopt(a, null);
await adopt(b, { source: "certain" });
await adopt(c, { record_id: mismatchedId });
await adopt(d, { ...event, record_id: correctId });
await standalone(owner, c, "self");
expectCount(await audit(), { metric: "provenance_without_history", category: "has_artifact" }, "<5");
await report(owner, "annual_full", a);
await report(owner, "synastry_full", a, b);
const rows = await audit();
expectCount(rows, { metric: "provenance_without_history", category: "has_artifact" }, "<5");
expectCount(rows, { metric: "legacy_chart_side", category: "active" }, "0");
expectCount(rows, { metric: "legacy_chart_side", category: "history_only" }, "0");
await adopt(await addPerson(owner), { source: "certain" });
expectCount(await audit(), { metric: "provenance_without_history", category: "no_artifact" }, "<5");
const receiptForDifferentPerson = await receipt(owner, await addPerson(owner), oldSide);
await adopt(c, { record_id: receiptForDifferentPerson });
const wrongPerson = await audit();
expectCount(wrongPerson, { metric: "legacy_chart_side", category: "active" }, "0");
expectCount(wrongPerson, { metric: "legacy_chart_side", category: "history_only" }, "<5");
});
await t.test("legacy side picks and new self choices follow provenance at the same clock", async () => {
const p = await addPerson(stranger);
const oldRecord = await receipt(stranger, p, oldSide);
await adopt(p, { ...oldSide, record_id: oldRecord });
const questionPerson = await addPerson(stranger);
const questionId = await receipt(stranger, questionPerson, questionnaire);
await adopt(questionPerson, { ...questionnaire, record_id: questionId });
// Four legitimate retirements are masked. Treating the new self choice
// as retired would expose five, so the mask itself proves the exclusion.
for (let index = 0; index < 2; index += 1) await adopt(await addPerson(stranger), event);
const before = await audit();
expectCount(before, { metric: "legacy_chart_side", category: "active" }, "<5");
expectCount(before, { metric: "legacy_chart_side", category: "history_only" }, "<5");
expectCount(before, { metric: "feature", category: "explicit_manual_choice" }, "<5");
expectCount(before, { metric: "self_choice_20261116", category: "active" }, "0");
const newRecord = await receipt(stranger, p, selfChoice);
await adopt(p, { ...selfChoice, record_id: newRecord, retired_reason: "BUG-1890" });
const after = await audit();
expectCount(after, { metric: "legacy_chart_side", category: "active" }, "0");
expectCount(after, { metric: "legacy_chart_side", category: "history_only" }, "<5");
expectCount(after, { metric: "feature", category: "explicit_manual_choice" }, "0");
expectCount(after, { metric: "self_choice_20261116", category: "active" }, "<5");
expectCount(after, { metric: "self_choice_20261116", category: "history" }, "<5");
expectCount(after, { metric: "active_retired" }, "<5"); // Four pre-existing retirements.
await db.query("update public.chart_profiles set active_birth_provenance=null, active_birth_time=null, active_birth_date=null, active_birth_timezone_offset=null, birth_time_status='reported' where id=$1", [p]);
expectCount(await audit(), { metric: "self_choice_20261116", category: "active" }, "0");
expectCount(await audit(), { metric: "self_choice_20261116", category: "history" }, "<5");
});
await t.test("dangling report refs count each artifact once and deletion mechanisms remain distinct", async () => {
const foreignKeys = await db.query(
"select conname from pg_constraint where contype='f' and confrelid='public.chart_profiles'::regclass "
+ "and conrelid in ('public.personal_reports'::regclass, 'public.synastry_reports'::regclass)",
);
assert.equal(foreignKeys.rowCount, 0);
const left = await addPerson(owner);
const right = await addPerson(owner);
await report(owner, "personal_full", left);
await report(owner, "annual_full", right);
await standalone(owner, left, right);
await db.query("delete from public.chart_profiles where id=$1", [left]);
expectCount(await audit(), { metric: "artifacts_without_subject", report_type: "legacy_synastry" }, "0");
await db.query("delete from public.chart_profiles where id=$1", [right]);
const live = await addPerson(owner);
const normalDelete = await report(owner, "personal_thematic", live);
const app = new Client({ connectionString: fixture.connectionUrl("app_runtime", "app-runtime-test-password") });
await app.connect();
try {
await app.query("begin");
await app.query("select set_config('request.jwt.claim.sub',$1,true)", [owner]);
await app.query("set local role authenticated");
await app.query("select public.delete_chart_subject($1)", [live]);
await app.query("commit");
} finally {
await app.end();
}
assert.equal((await db.query("select id from public.personal_reports where id=$1", [normalDelete])).rowCount, 0);
// A pair with both references missing is still one artifact. On top of
// four pairs missing one side, a double count would reach six.
const stillHere = await addPerson(owner);
await report(owner, "synastry_full", left, right);
for (let index = 0; index < 4; index += 1) await report(owner, "synastry_full", left, stillHere);
await standalone(owner, "self", left); // Simulates a legacy dangling text ref.
await report(owner, "personal_full", null); // Bare null is not evidence of deletion.
const rows = await audit();
for (const type of ["personal_full", "annual_full", "legacy_synastry"]) {
expectCount(rows, { metric: "artifacts_without_subject", report_type: type }, "<5");
}
expectCount(rows, { metric: "artifacts_without_subject", report_type: "synastry_full" }, "5");
expectCount(rows, { metric: "artifacts_without_subject", report_type: "personal_thematic" }, "0");
assert.ok(!rows.some(({ metric }) => metric === "artifacts_subject_nulled"));
});
await t.test("unknown types and statuses stay in fixed groups, unbound legacy pairs have no attribution", async () => {
expectCount(await audit(), { metric: "reports_outside_whitelist", report_type: "other", report_status: "listed" }, "0");
// Only the synthetic fixture loses these constraints so the audit can
// simulate drift while exercising the rest of the migrated schema.
await db.query("alter table public.personal_reports drop constraint personal_reports_report_type_check, "
+ "drop constraint personal_reports_status_check");
const other = await addPerson(stranger);
await report(stranger, "synthetic-extra-type", other);
await report(stranger, "annual_full", other, null, "synthetic-extra-status");
await report(stranger, "synthetic-extra-type", other, null, "synthetic-extra-status");
await standalone(stranger, null, null);
await standalone(stranger, other, null);
await standalone(stranger, "self", "self");
await standalone(stranger, null, other, "modern-fixture");
await standalone(stranger, other, "self");
const rows = await audit();
expectCount(rows, { metric: "reports_outside_whitelist", category: "outside", report_type: "other", report_status: "listed" }, "<5");
expectCount(rows, { metric: "reports_outside_whitelist", category: "outside", report_type: "other", report_status: "outside" }, "<5");
expectCount(rows, { metric: "reports_outside_whitelist", category: "listed", report_type: "annual_full", report_status: "outside" }, "<5");
expectCount(rows, { metric: "reports_outside_whitelist", category: "listed", report_type: "personal_full", report_status: "outside" }, "0");
expectCount(rows, { metric: "standalone_synastry_unbound", report_type: null }, "<5");
await standalone(stranger, null, "self");
await standalone(stranger, "not-a-binding", "self");
expectCount(await audit(), { metric: "standalone_synastry_unbound", report_type: null }, "5");
});
} finally {
try {
await db.end();
} finally {
fixture.stop();
}
}
});