ek-ctp 0.12.4

CTP gateway for the enkeep ek ecosystem: MD/TD session drivers mapping CTP wire rows onto ek-data objects over the ek-event bus (pure-logic core; the CTP SDK ships inside this package and native bridging lands behind the optional `native` feature).
Documentation
<#
  Package-content guard (run BEFORE `cargo publish`).

  Why: since 0.2.0 the published package is expected to CONTAIN the vendored CTP SDK
  (native/sdk/**), and the packaging file set is derived from git tracking rules
  (no `exclude` any more). A partial checkout, a careless .gitignore entry, or a
  dirty tree can therefore silently produce a package that is missing the SDK --
  or, worse, that carries local secrets. This script asserts both directions.

  Usage:
    powershell -ExecutionPolicy Bypass -File scripts/check-package.ps1                 # strict (clean tree required)
    powershell -ExecutionPolicy Bypass -File scripts/check-package.ps1 -AllowDirty    # inspect a dirty work tree

  Exit code: 0 = PASS, 1 = FAIL. Never use `cargo publish --allow-dirty`.

  NOTE: ASCII-only on purpose (Windows PowerShell 5.1 decodes BOM-less .ps1 as ANSI).
#>
[CmdletBinding()]
param(
    [switch]$AllowDirty
)

$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
Push-Location $root
try {
    # ---- required: the SDK payload that downstream users rely on ----
    $required = @(
        'native/sdk/include/ThostFtdcMdApi.h',
        'native/sdk/include/ThostFtdcTraderApi.h',
        'native/sdk/include/ThostFtdcUserApiDataType.h',
        'native/sdk/include/ThostFtdcUserApiStruct.h',
        'native/sdk/win64/thostmduserapi_se.dll',
        'native/sdk/win64/thosttraderapi_se.dll',
        'native/sdk/win64/libs/thostmduserapi_se.lib',
        'native/sdk/win64/libs/thosttraderapi_se.lib',
        'native/sdk/linux/libthostmduserapi_se.so',
        'native/sdk/linux/libthosttraderapi_se.so',
        'NOTICE',
        # native feature (M1 + M2): without these the SDK in the package is useless --
        # `cargo build --features native` would fail on a fresh install.
        'build.rs',
        'native/shim/ek_ctp_shim.h',
        'native/shim/ek_ctp_shim.cpp',
        'native/shim/ek_ctp_pod.h',
        'native/shim/ek_ctp_pod.cpp',
        'src/native/mod.rs',
        'src/native/common.rs',
        'src/native/md.rs',
        'src/native/td.rs',
        'src/native/pod.rs',
        'src/native/transport.rs',
        'tests/native_smoke.rs'
    )

    # ---- forbidden: must never reach the registry ----
    $forbiddenPatterns = @(
        'simnow\.local\.env',
        '\.local\.env$',
        '(^|/)\.env$',
        '\.pfx$',
        '\.pem$',
        '\.key$'
    )

    $cargoArgs = @('package', '--list')
    if ($AllowDirty) { $cargoArgs += '--allow-dirty' }

    Write-Host "running: cargo $($cargoArgs -join ' ')"
    # Cargo prints warnings on stderr (e.g. an unused [patch.crates-io] entry in a
    # local dev checkout). Under 'Stop' PowerShell turns ANY native stderr line into
    # a terminating NativeCommandError and the script dies before the checks run.
    # Toggling to 'Continue' for the call is the fix: we judge by the exit code.
    $ErrorActionPreference = 'Continue'
    $list = & cargo @cargoArgs 2>$null
    $cargoCode = $LASTEXITCODE
    $ErrorActionPreference = 'Stop'
    if ($cargoCode -ne 0) {
        Write-Host "FAIL: 'cargo package --list' returned $cargoCode (dirty tree? pass -AllowDirty)" -ForegroundColor Red
        exit 1
    }

    $files = @($list | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' })
    Write-Host "package file count: $($files.Count)"

    $ok = $true

    # ---- required present ----
    foreach ($r in $required) {
        $norm = $r -replace '/', '\'
        $hit = @($files | Where-Object { ($_ -replace '/', '\') -eq $norm })
        if ($hit.Count -gt 0) {
            Write-Host ("  OK   " + $r)
        } else {
            Write-Host ("  MISS " + $r) -ForegroundColor Red
            $ok = $false
        }
    }

    # ---- forbidden absent ----
    foreach ($p in $forbiddenPatterns) {
        $bad = @($files | Where-Object { $_ -match $p })
        if ($bad.Count -gt 0) {
            Write-Host ("  LEAK (pattern " + $p + "): " + ($bad -join ', ')) -ForegroundColor Red
            $ok = $false
        } else {
            Write-Host ("  clean (pattern " + $p + ")")
        }
    }

    if ($ok) {
        Write-Host "PASS: package content looks correct" -ForegroundColor Green
        Write-Host "note: for the compressed size (crates.io limit 10 MiB) run 'cargo package' and check target/package/*.crate"
        exit 0
    } else {
        Write-Host "FAIL: package content is not publishable" -ForegroundColor Red
        exit 1
    }
} finally {
    Pop-Location
}