{
  "task": "HRMS_FEISHU_READONLY_SNAPSHOT_REFRESH_DRY_RUN_PREP_PACK_Z4",
  "generated_at": "2026-06-03T16:21:12+08:00",
  "db_read_status": "DB_READ_AVAILABLE",
  "checked_sources": {
    "schema_contract": "/var/www/talent-review/outputs/hrms_feishu_readonly_snapshot_schema_contract_v1.json",
    "schema_apply_summary": "/var/www/talent-review/outputs/hrms_feishu_readonly_snapshot_schema_apply_summary_v1.json",
    "token_permission_summary": "/var/www/talent-review/outputs/hrms_feishu_readonly_token_permission_check_summary_v1.json"
  },
  "endpoint_checks": [
    {
      "url": "https://hrms.yuechongjia.com/api/feishu-readonly-snapshot/readiness",
      "status": 200,
      "ok": true,
      "content_type": "application/json",
      "json_keys": [
        "can_enter_refresh_retry_approval",
        "client_handle",
        "data_write",
        "feishu_api_call",
        "hard_blocks",
        "job_created",
        "mapping_created",
        "next_gate",
        "ok",
        "production_writeback",
        "provider_installed",
        "refresh_executed",
        "safety_scan",
        "safety_scanner_installed",
        "secret_read",
        "snapshot_refreshed",
        "snapshot_schema",
        "snapshot_schema_ready",
        "token_cache_detail",
        "token_cache_status",
        "token_metadata_status",
        "token_output",
        "warnings",
        "write_endpoint_risk_status"
      ],
      "body_bytes_sampled": 4692
    },
    {
      "url": "https://hrms.yuechongjia.com/api/feishu-readonly-snapshot/contract",
      "status": 200,
      "ok": true,
      "content_type": "application/json",
      "json_keys": [],
      "body_bytes_sampled": 5000
    }
  ],
  "refresh_service_readiness": true,
  "directory_client_readiness": true,
  "token_provider_readiness": true,
  "token_cache_metadata_readiness": true,
  "required_scope_readiness": true,
  "app_install_permission_readiness": true,
  "endpoint_contract_readiness": true,
  "snapshot_schema_contract_readiness": true,
  "contract_check": {
    "contract_source": "/var/www/talent-review/outputs/hrms_feishu_readonly_snapshot_schema_contract_v1.json",
    "validation_source": "/var/www/talent-review/outputs/hrms_feishu_readonly_snapshot_schema_apply_validation_v1.json",
    "schema_contract_ready": true,
    "required_table_count": 3,
    "tables": {
      "feishu_readonly_snapshot_runs": {
        "exists": true,
        "required_columns_source": "Z3 applied schema validation / Z2 approved contract",
        "existing_columns": [
          "snapshot_run_id",
          "tenant_id",
          "company_key",
          "source_system",
          "source_run_id",
          "contract_version",
          "data_version",
          "run_status",
          "trigger_mode",
          "readonly_scope_names",
          "token_metadata",
          "requested_counts",
          "result_counts",
          "snapshot_started_at",
          "snapshot_completed_at",
          "snapshot_at",
          "error_summary",
          "downstream_staging_ref",
          "audit_id",
          "rollback_ref",
          "metadata",
          "created_by",
          "created_at",
          "updated_by",
          "updated_at"
        ],
        "missing_columns": [],
        "contract_ready": true,
        "index_count": 5
      },
      "feishu_user_snapshots": {
        "exists": true,
        "required_columns_source": "Z3 applied schema validation / Z2 approved contract",
        "existing_columns": [
          "user_snapshot_id",
          "snapshot_run_id",
          "tenant_id",
          "company_key",
          "source_system",
          "source_run_id",
          "contract_version",
          "data_version",
          "feishu_user_id",
          "feishu_open_id_private_ref",
          "feishu_union_id_private_ref",
          "employee_no",
          "user_name_masked",
          "primary_feishu_department_id",
          "manager_feishu_user_id",
          "employment_status",
          "status",
          "mapping_status",
          "raw_payload_private",
          "sanitized_payload_public",
          "counts_metadata",
          "downstream_employee_ref",
          "downstream_permission_subject_ref",
          "downstream_feishu_mapping_ref",
          "downstream_staging_ref",
          "snapshot_at",
          "audit_id",
          "rollback_ref",
          "metadata",
          "created_by",
          "created_at",
          "updated_by",
          "updated_at"
        ],
        "missing_columns": [],
        "contract_ready": true,
        "index_count": 6
      },
      "feishu_department_snapshots": {
        "exists": true,
        "required_columns_source": "Z3 applied schema validation / Z2 approved contract",
        "existing_columns": [
          "department_snapshot_id",
          "snapshot_run_id",
          "tenant_id",
          "company_key",
          "source_system",
          "source_run_id",
          "contract_version",
          "data_version",
          "feishu_department_id",
          "parent_feishu_department_id",
          "department_name_masked",
          "department_order",
          "status",
          "mapping_status",
          "raw_payload_private",
          "sanitized_payload_public",
          "counts_metadata",
          "downstream_department_ref",
          "downstream_staging_ref",
          "snapshot_at",
          "audit_id",
          "rollback_ref",
          "metadata",
          "created_by",
          "created_at",
          "updated_by",
          "updated_at"
        ],
        "missing_columns": [],
        "contract_ready": true,
        "index_count": 5
      }
    },
    "note": "Z4 contract check is reconciled against the approved Z2 contract and Z3 apply validation, not unapproved column aliases."
  },
  "snapshot_table_schema": {
    "feishu_readonly_snapshot_runs": {
      "exists": true,
      "row_count": 0,
      "columns": [
        {
          "column": "snapshot_run_id",
          "type": "text",
          "nullable": "NO",
          "default": ""
        },
        {
          "column": "tenant_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "company_key",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "source_system",
          "type": "text",
          "nullable": "NO",
          "default": "'feishu'::text"
        },
        {
          "column": "source_run_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "contract_version",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "data_version",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "run_status",
          "type": "text",
          "nullable": "NO",
          "default": ""
        },
        {
          "column": "trigger_mode",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "readonly_scope_names",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'[]'::jsonb"
        },
        {
          "column": "token_metadata",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "requested_counts",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "result_counts",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "snapshot_started_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "snapshot_completed_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "snapshot_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "error_summary",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "downstream_staging_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "audit_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "rollback_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "metadata",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "created_by",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "created_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": "now()"
        },
        {
          "column": "updated_by",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "updated_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": "now()"
        }
      ],
      "columns_ok": true,
      "indexes": [
        "feishu_readonly_snapshot_runs_pkey",
        "idx_feishu_snapshot_runs_snapshot_at",
        "idx_feishu_snapshot_runs_status",
        "idx_feishu_snapshot_runs_tenant_company",
        "ux_feishu_snapshot_runs_source_run"
      ],
      "indexes_ok": true
    },
    "feishu_user_snapshots": {
      "exists": true,
      "row_count": 0,
      "columns": [
        {
          "column": "user_snapshot_id",
          "type": "text",
          "nullable": "NO",
          "default": ""
        },
        {
          "column": "snapshot_run_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "tenant_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "company_key",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "source_system",
          "type": "text",
          "nullable": "NO",
          "default": "'feishu'::text"
        },
        {
          "column": "source_run_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "contract_version",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "data_version",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "feishu_user_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "feishu_open_id_private_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "feishu_union_id_private_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "employee_no",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "user_name_masked",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "primary_feishu_department_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "manager_feishu_user_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "employment_status",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "status",
          "type": "text",
          "nullable": "NO",
          "default": ""
        },
        {
          "column": "mapping_status",
          "type": "text",
          "nullable": "NO",
          "default": "'pending'::text"
        },
        {
          "column": "raw_payload_private",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "sanitized_payload_public",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "counts_metadata",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "downstream_employee_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "downstream_permission_subject_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "downstream_feishu_mapping_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "downstream_staging_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "snapshot_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "audit_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "rollback_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "metadata",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "created_by",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "created_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": "now()"
        },
        {
          "column": "updated_by",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "updated_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": "now()"
        }
      ],
      "columns_ok": true,
      "indexes": [
        "feishu_user_snapshots_pkey",
        "idx_feishu_user_snapshots_department",
        "idx_feishu_user_snapshots_mapping_status",
        "idx_feishu_user_snapshots_run",
        "idx_feishu_user_snapshots_tenant_company",
        "ux_feishu_user_snapshots_run_user"
      ],
      "indexes_ok": true
    },
    "feishu_department_snapshots": {
      "exists": true,
      "row_count": 0,
      "columns": [
        {
          "column": "department_snapshot_id",
          "type": "text",
          "nullable": "NO",
          "default": ""
        },
        {
          "column": "snapshot_run_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "tenant_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "company_key",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "source_system",
          "type": "text",
          "nullable": "NO",
          "default": "'feishu'::text"
        },
        {
          "column": "source_run_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "contract_version",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "data_version",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "feishu_department_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "parent_feishu_department_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "department_name_masked",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "department_order",
          "type": "integer",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "status",
          "type": "text",
          "nullable": "NO",
          "default": ""
        },
        {
          "column": "mapping_status",
          "type": "text",
          "nullable": "NO",
          "default": "'pending'::text"
        },
        {
          "column": "raw_payload_private",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "sanitized_payload_public",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "counts_metadata",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "downstream_department_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "downstream_staging_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "snapshot_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "audit_id",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "rollback_ref",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "metadata",
          "type": "jsonb",
          "nullable": "YES",
          "default": "'{}'::jsonb"
        },
        {
          "column": "created_by",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "created_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": "now()"
        },
        {
          "column": "updated_by",
          "type": "text",
          "nullable": "YES",
          "default": ""
        },
        {
          "column": "updated_at",
          "type": "timestamp with time zone",
          "nullable": "YES",
          "default": "now()"
        }
      ],
      "columns_ok": true,
      "indexes": [
        "feishu_department_snapshots_pkey",
        "idx_feishu_department_snapshots_mapping_status",
        "idx_feishu_department_snapshots_run",
        "idx_feishu_department_snapshots_tenant_company",
        "ux_feishu_department_snapshots_run_department"
      ],
      "indexes_ok": true
    }
  },
  "snapshot_tables_empty": true,
  "master_data_tables_still_empty": true,
  "readiness_blockers": [],
  "can_enter_refresh_dry_run_apply_gate": true
}
