# Pack Verify Drift Loop

## Round 1

Status:
- completed

Scope:
- root-cause the first batch of pack/live drift fields
- fix source-pack mistakes
- fix final-pack build downgrade logic instead of patching generated output directly

Changes:
- `packs/Salesforce-PingCAP-L2/objects/CampaignMember.json`
  - `Fax`: `string -> phone`
  - `DoNotCall`: `string -> boolean`
  - `HasOptedOutOfEmail`: `email -> boolean`
- `scripts/build_pingcap_salesforce_sample_pack.sh`
  - added active-formula allowlist entries for:
    - `Opportunity_Product__c.Product_Name__c`
    - `Order_Product__c.Product_Name__c`
    - `Quote_Product__c.Product_Name__c`

Why:
- `CampaignMember` drift was a source-pack issue. The checked-in L2 object file itself carried wrong field types.
- `*_Product__c.Product_Name__c` drift was a final-pack assembly issue. The L2 source object files were already correct (`formula`), but `sanitize_object_spec()` downgraded these relationship-traversal formulas during final-pack build.

Verification:
- rebuilt final pack with:
  - `bash scripts/build_pingcap_salesforce_sample_pack.sh --reset`
- rebuild succeeded:
  - `final pack metadata audit PASSED`
- verified final merged object spec now contains:
  - `CampaignMember.Fax = phone`
  - `CampaignMember.DoNotCall = boolean`
  - `CampaignMember.HasOptedOutOfEmail = boolean`
  - `Opportunity_Product__c.Product_Name__c = formula`
  - `Order_Product__c.Product_Name__c = formula`
  - `Quote_Product__c.Product_Name__c = formula`

Next:
- rerun local apply against the reset-derived branch
- capture the next unresolved drift set
- keep separating:
  - source-pack bugs
  - final-pack build downgrades
  - live metadata registration gaps

## Round 2

Status:
- in progress

Scope:
- land the next confirmed source-pack drift fix
- record the full next verify-failure batch for issue-driven replay and backtracking
- separate "already fixed on newer ref but not revalidated yet" from "still-open root cause"

Changes:
- `packs/Salesforce-PingCAP-L2/objects/Account.json`
  - added `required: true` to:
    - `Website`
    - `Industry`
    - `NumberOfEmployees`
    - `RecordTypeId`
    - `Region__c`
    - `Vertical__c`

Verification:
- rebuilt final pack with:
  - `bash scripts/build_pingcap_salesforce_sample_pack.sh --reset`
- rebuild succeeded:
  - `final pack metadata audit PASSED`
- verified local branch DB live metadata already expects these six fields as required:
  - `Account.Industry`
  - `Account.NumberOfEmployees`
  - `Account.RecordTypeId`
  - `Account.Region__c`
  - `Account.Vertical__c`
  - `Account.Website`

Live metadata / schema findings:
- `Opportunity_Product__c.CurrencyIsoCode`
  - physical column exists in the local branch DB
  - `_System_Field` metadata row is missing
- `Countries_Region__c.Name`
  - `_System_Field` metadata row is missing
  - `SHOW COLUMNS ... LIKE 'Name'` returned no row, so the physical column is also missing

Captured verify failure batch:
- source log:
  - `deploy-apply-rerun-20260528-debug-1c6d998e.log`
- this failing run was still on downstream ref `32c1ce19cf4fa57b9d962e5a9c8c2f4886686c65`
- therefore it does **not** yet validate:
  - Round 1 ref `fa0d8afb...`
  - Round 2 Account required-bit fix

Key failure groups from that run:
- structural / schema drift
  - missing `_System_Field` row: `Countries_Region__c.Name`
  - missing `_System_Field` row: `Opportunity_Product__c.CurrencyIsoCode`
  - missing physical column: `Countries_Region__c.Name`
  - missing physical column: `Opportunity_Product__c.CurrencyIsoCode`
  - `OpportunityLineItem.DisplayNameField = <null>, want Product2Id`
  - `OrderItem.DisplayNameField = <null>, want Product2Id`
  - extra live pack-owned field still reported undeclared:
    - `Opportunity_Product__c.Product_Name__c`
    - `Order_Product__c.Product_Name__c`
    - `Quote_Product__c.Product_Name__c`
- projection / pack content drift
  - `standard_listfields`: live `Account` has `account_allias__c`, shipped list does not
  - `record_types`: live missing `PoC__c / TiDB Cloud PoC Follow-up`
- flow drift
  - multiple standard flows reported missing or version-drifted
- action drift
  - `bootstrap_standard_actions` sort order drift
  - `convertLead` guard / internal access scope drift
- layout drift
  - several page layout wildcard-routing mismatches

Next:
- rerun local apply on the newest downstream ref so verify reflects Round 1 + Round 2
- then split the next batch into:
  - stale old-run noise
  - pack/build bugs
  - local DB registration / schema backfill gaps
