@kici-dev/shared 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,16 +26,6 @@ export declare function parseDatabaseUrl(databaseUrl: string): ParsedDatabaseUrl
26
26
  * Redact the password from a libpq URL for safe logging.
27
27
  */
28
28
  export declare function maskDatabaseUrl(databaseUrl: string): string;
29
- /**
30
- * DROP `dbName` (if it exists). Terminates existing backend connections
31
- * so the DROP doesn't block. Idempotent — drops are IF EXISTS.
32
- *
33
- * Used by e2e cleanup after a full-lifecycle service-deploy test tears
34
- * down its isolated database. Shares the same admin-URL + identifier-
35
- * validation + backend-termination scaffolding as dropAndCreateDatabase
36
- * so the two helpers cannot drift.
37
- */
38
- export declare function dropDatabaseDirect(databaseUrl: string): Promise<void>;
39
29
  /**
40
30
  * Drop `dbName` (if it exists), then recreate it owned by `owner`. Terminates
41
31
  * existing backend connections so the DROP doesn't block.
@@ -528,15 +518,6 @@ export declare function showExecutionRunDirect(databaseUrl: string, opts: {
528
518
  run: ExecutionRunRow;
529
519
  jobs: ExecutionJobRow[];
530
520
  }>;
531
- /**
532
- * READ-ONLY: list execution_jobs for a given execution_runs.id. Ordered by
533
- * created_at ASC so downstream diffs show timeline order.
534
- */
535
- export declare function listExecutionJobsDirect(databaseUrl: string, opts: {
536
- runId: string;
537
- }): Promise<{
538
- jobs: ExecutionJobRow[];
539
- }>;
540
521
  export interface WorkflowRegistrationRow {
541
522
  id: string;
542
523
  repo_identifier: string;
@@ -664,33 +645,6 @@ export interface EmitKiciEventOpts {
664
645
  export declare function emitKiciEventDirect(databaseUrl: string, opts: EmitKiciEventOpts): Promise<{
665
646
  eventId: string;
666
647
  }>;
667
- export interface SeedGenericWebhookSourceOpts {
668
- orgId: string;
669
- name: string;
670
- /** Pre-computed deterministic UUID (caller derives via sha256(orgId:name)) */
671
- sourceId: string;
672
- /** Pre-computed routing key (caller uses `generic:${orgId}:${name}`) */
673
- routingKey: string;
674
- verificationMethod?: string;
675
- /** 'generic' (Stripe-shaped) or 'local' (github-shaped via LocalWebhookNormalizer,
676
- * a git repo present on the agent filesystem cloned via file://). */
677
- providerType?: 'generic' | 'local';
678
- /** For `providerType='local'`: the per-source `{ repoBasePath, cloneUrlBase? }`
679
- * stored in `git_config`. The orchestrator reads `repoBasePath` from this row
680
- * at registration time to build the local provider bundle. */
681
- gitConfig?: Record<string, unknown>;
682
- }
683
- /**
684
- * Upsert a row into `generic_webhook_sources`. Uses
685
- * `ON CONFLICT (routing_key) DO UPDATE` so warm-start mode (where the source
686
- * may already exist from a prior run) is idempotent.
687
- *
688
- * IMPORTANT: callers must invoke this BEFORE the orchestrator starts, because
689
- * GenericSourceManager caches sources at boot and does not reload them later.
690
- * This helper supersedes seedGenericWebhookSource() in
691
- * e2e/helpers/local-webhook.ts.
692
- */
693
- export declare function seedGenericWebhookSourceDirect(databaseUrl: string, opts: SeedGenericWebhookSourceOpts): Promise<void>;
694
648
  /**
695
649
  * Return `{ current: true }` if the applied migration count matches the
696
650
  * provider's migration count AND the content hash in `_migration_content_hash`
@@ -717,201 +671,6 @@ export declare function isSchemaCurrent(pool: pg.Pool, provider: MigrationProvid
717
671
  export declare function purgeSecretBackendsDirect(databaseUrl: string): Promise<{
718
672
  deleted: number;
719
673
  }>;
720
- /**
721
- * Check if an API key exists in the Platform DB (api_keys table — orchestrator-
722
- * managed, NOT user_api_keys). Returns true when a row matches the hashed key.
723
- */
724
- export declare function apiKeyExistsDirect(databaseUrl: string, apiKey: string): Promise<boolean>;
725
- /**
726
- * Insert an api_keys row (Platform-side orchestrator credential). Used by
727
- * e2e setup to seed an orchestrator authentication token. Returns the id.
728
- */
729
- export declare function seedApiKeyInlineDirect(databaseUrl: string, opts: {
730
- keyName: string;
731
- orgId: string;
732
- fullKey: string;
733
- }): Promise<{
734
- keyId: string;
735
- }>;
736
- /**
737
- * Lookup a `platform_connections` row by connection_id. Returns true when
738
- * present. Used by the orphan-sweeper e2e test.
739
- */
740
- export declare function platformConnectionExistsDirect(databaseUrl: string, connectionId: string): Promise<boolean>;
741
- /**
742
- * Count `webhook_sources` rows for a given orchestrator_connection_id.
743
- * Used by the orphan-sweeper e2e test to assert the FK CASCADE introduced
744
- * by Platform migration 017 actually fires when the parent
745
- * `platform_connections` row is deleted.
746
- */
747
- /**
748
- * Look up a Platform-side `webhook_sources` row by routing key. Returns the
749
- * row (org_id + provider + connection) or null. Used by E2E to assert that a
750
- * source added at runtime on the orchestrator propagated to the Platform's
751
- * `webhook_sources` table (the dashboard-visible source list) without a
752
- * restart.
753
- */
754
- export declare function getWebhookSourceByRoutingKeyDirect(databaseUrl: string, routingKey: string): Promise<{
755
- routing_key: string;
756
- org_id: string;
757
- provider: string;
758
- } | null>;
759
- export declare function countWebhookSourcesByConnectionIdDirect(databaseUrl: string, connectionId: string): Promise<number>;
760
- /**
761
- * Find a `user_api_keys.id` preferring rows scoped to `preferredOrgId`, else
762
- * any row in the table. Used by orphan-sweeper test to get a realistic
763
- * `key_id` for platform_connections seeding.
764
- */
765
- export declare function findAnyUserApiKeyIdDirect(databaseUrl: string, preferredOrgId: string): Promise<string | null>;
766
- /**
767
- * Seed or refresh a synthetic GitHub webhook source on the Platform DB.
768
- * Used by HMAC E2E tests that post to `/webhook/:orgId/github`.
769
- * Idempotent — refreshes the secret/org_id via ON CONFLICT DO UPDATE,
770
- * and clears stale rows with a different routing_key under the same
771
- * (org_id, provider, connection_id) triple.
772
- */
773
- export declare function seedSyntheticGithubSourceDirect(databaseUrl: string, opts: {
774
- routingKey: string;
775
- orgId: string;
776
- /** Display name pushed by the orchestrator on register. Optional. */
777
- name?: string;
778
- /** Fine-grained subtype (e.g. 'github_app'). Optional. */
779
- subtype?: string;
780
- /** GitHub App slug. Optional. */
781
- slug?: string;
782
- }): Promise<void>;
783
- /**
784
- * Seed a webhook secret into the orchestrator's `scoped_secrets` table,
785
- * encrypted with the caller-supplied key. Ensures a `sources` row exists
786
- * for the routing_key. Used by e2e setup on the orchestrator DB side.
787
- *
788
- * encryptFn takes plaintext + AAD and returns ciphertext bytes. The
789
- * caller owns the crypto primitive so this helper stays decoupled from
790
- * the orchestrator's PgSecretStore crypto module.
791
- */
792
- export declare function seedWebhookSecretDirect(databaseUrl: string, opts: {
793
- routingKey: string;
794
- webhookSecret: string;
795
- encryptFn: (plaintext: string, aad: string) => string | Buffer;
796
- }): Promise<{
797
- sourceId: string;
798
- }>;
799
- /**
800
- * Seed a source private key into the orchestrator's `scoped_secrets` table.
801
- * encryptFn signature matches seedWebhookSecretDirect. Returns null if the
802
- * sources row is missing (matches legacy warning-and-skip behaviour).
803
- */
804
- export declare function seedSourcePrivateKeyDirect(databaseUrl: string, opts: {
805
- routingKey: string;
806
- privateKey: string;
807
- encryptFn: (plaintext: string, aad: string) => string | Buffer;
808
- }): Promise<{
809
- sourceId: string;
810
- } | null>;
811
- /**
812
- * Bump `registry_versions.version` for the default registry and return the
813
- * new value. Used by cron-scheduler e2e to retrigger index after a manual
814
- * workflow change.
815
- */
816
- export declare function bumpRegistryVersionDirect(databaseUrl: string): Promise<number>;
817
- /**
818
- * Poll `kici_events` for an event matching `eventName` created after `since`.
819
- * Returns the newest match, or throws on timeout. Used by e2e event-routing tests.
820
- */
821
- export declare function pollKiciEventsDirect(databaseUrl: string, opts: {
822
- eventName: string;
823
- since: Date;
824
- timeoutMs?: number;
825
- pollIntervalMs?: number;
826
- payloadFilter?: {
827
- key: string;
828
- value: string;
829
- };
830
- }): Promise<Record<string, unknown>>;
831
- /**
832
- * Ping a PostgreSQL database; retries until `SELECT 1` succeeds or the
833
- * timeout expires. Used by e2e startup to wait for Postgres readiness.
834
- */
835
- export declare function waitForPostgresDirect(databaseUrl: string, opts?: {
836
- timeoutMs?: number;
837
- intervalMs?: number;
838
- }): Promise<void>;
839
- /**
840
- * Wait for a specific execution_runs row to reach a terminal status.
841
- * Used by test-pipeline e2e to gate on run completion. Terminal statuses
842
- * are success / failed / cancelled / timed_out_stale.
843
- */
844
- export declare function waitForRunCompletionDirect(databaseUrl: string, runId: string, opts?: {
845
- timeoutMs?: number;
846
- intervalMs?: number;
847
- }): Promise<{
848
- status: string;
849
- }>;
850
- /**
851
- * DELETE from execution_jobs + execution_runs where started_at > since.
852
- * Used by e2e cleanup for tests that want explicit post-test row cleanup.
853
- */
854
- export declare function cleanupExecutionRowsDirect(databaseUrl: string, since: Date): Promise<{
855
- runs: number;
856
- jobs: number;
857
- }>;
858
- /**
859
- * Check whether the schema is "current" by comparing applied migration count
860
- * and content hash against a caller-supplied set of migration files.
861
- * Returns false if the migration table is missing, counts mismatch, or the
862
- * stored hash differs from the caller-supplied hash. Used by e2e warm-start.
863
- */
864
- export declare function isSchemaCurrentFromFilesDirect(databaseUrl: string, opts: {
865
- tableName?: string;
866
- expectedCount: number;
867
- expectedContentHash: string;
868
- }): Promise<boolean>;
869
- /**
870
- * Store a migration content hash in the `_migration_content_hash` marker
871
- * table. Creates the table if missing. Used by e2e freshDatabase() after
872
- * migrations run so warm-start detection can compare on next run.
873
- */
874
- export declare function storeMigrationContentHashInTableDirect(databaseUrl: string, opts: {
875
- tableName?: string;
876
- contentHash: string;
877
- }): Promise<void>;
878
- /**
879
- * Insert a join_tokens row (orchestrator DB) for cluster peer auth.
880
- * Used by cluster e2e helpers to provision a shared secret the second
881
- * orchestrator will use when joining the cluster.
882
- */
883
- export declare function createJoinTokenDirect(databaseUrl: string, opts: {
884
- id: string;
885
- tokenHash: string;
886
- routingInfo: Record<string, unknown>;
887
- role: string;
888
- createdBy: string;
889
- expiresAt: Date;
890
- }): Promise<void>;
891
- /**
892
- * Delete join_tokens rows by `created_by` (orchestrator DB). Used by cluster
893
- * E2E tests to clean up test-provisioned tokens between runs.
894
- */
895
- export declare function deleteJoinTokensByCreatedByDirect(databaseUrl: string, opts: {
896
- createdBy: string;
897
- }): Promise<void>;
898
- /**
899
- * Update the routing_key on `sources` rows for a given provider. Used by
900
- * cluster e2e to swap the staging routing key for an isolated test key
901
- * (and to restore it on teardown).
902
- *
903
- * `whereRoutingKey`: optional filter on the current routing_key. When
904
- * present only rows matching it are updated; when absent the provider
905
- * filter alone is used (with an implicit `!= newRoutingKey` guard so the
906
- * update is idempotent).
907
- */
908
- export declare function updateSourceRoutingKeyDirect(databaseUrl: string, opts: {
909
- provider: string;
910
- newRoutingKey: string;
911
- whereRoutingKey?: string;
912
- }): Promise<{
913
- updated: number;
914
- }>;
915
674
  /**
916
675
  * Delete peer_credentials rows whose instance_id does NOT match a pattern.
917
676
  * Used by cluster e2e to wipe stale staging peer credentials while leaving
@@ -922,553 +681,6 @@ export declare function prunePeerCredentialsDirect(databaseUrl: string, opts: {
922
681
  }): Promise<{
923
682
  deleted: number;
924
683
  }>;
925
- /**
926
- * Poll Platform until at least `minRegistrations` distinct orchestrator
927
- * connections are BOTH registered for the routing key (row in webhook_sources)
928
- * AND live (row in platform_connections with status='connected'). The live-
929
- * connection join is critical — Platform's webhook_sources rows persist after
930
- * a connection disconnects (the orphan sweeper eventually reaps them), so a
931
- * naive COUNT(DISTINCT) on webhook_sources alone would inflate the number
932
- * and mask a missing coordinator registration.
933
- */
934
- export declare function waitForPlatformRegistrationsDirect(platformDbUrl: string, routingKey: string, opts?: {
935
- minRegistrations?: number;
936
- timeoutMs?: number;
937
- intervalMs?: number;
938
- }): Promise<void>;
939
- /**
940
- * Seed a generic_webhook_sources row with a custom `event_type_header` and
941
- * `git_config` payload. Used by universal-git e2e (Forgejo) to register
942
- * an ingest endpoint that extracts the event type from Gitea-style headers.
943
- */
944
- export interface SeedUniversalGitSourceOpts {
945
- orgId: string;
946
- sourceId: string;
947
- sourceName: string;
948
- routingKey: string;
949
- gitConfig: Record<string, unknown>;
950
- eventTypeHeader?: string;
951
- }
952
- export declare function seedUniversalGitSourceDirect(databaseUrl: string, opts: SeedUniversalGitSourceOpts): Promise<void>;
953
- /**
954
- * Seed the ci-security orchestrator fixtures expected by the security
955
- * pipeline e2e: sources row for dashboard orgId resolution, context,
956
- * two execution_runs (unknown + trusted), two execution_jobs, and a
957
- * security held_run for the unknown contributor.
958
- *
959
- * Returns the ids so the caller can assert downstream.
960
- */
961
- export interface SeedCiSecurityFixturesOpts {
962
- orgId: string;
963
- contextName?: string;
964
- sourceName?: string;
965
- sourceRoutingKey?: string;
966
- runsRoutingKey: string;
967
- unknownRunId: string;
968
- unknownDeliveryId: string;
969
- unknownJobId: string;
970
- trustedRunId: string;
971
- trustedDeliveryId: string;
972
- trustedJobId: string;
973
- /**
974
- * Second PR on the SAME repo (`repo_identifier='.'`, `pr_number=2`) with its
975
- * own pending security hold. Seeded so PR-scoping tests can prove that a
976
- * `/kici approve` on the first PR (pr_number=1) leaves this one held.
977
- */
978
- secondPrRunId: string;
979
- secondPrDeliveryId: string;
980
- secondPrJobId: string;
981
- /**
982
- * Hold on a DIFFERENT repo (`repo_identifier='other/repo'`, `pr_number=1`) —
983
- * same PR number as the first hold but a different repo, proving the scoping
984
- * isolates on repo as well as PR number.
985
- */
986
- otherRepoRunId: string;
987
- otherRepoDeliveryId: string;
988
- otherRepoJobId: string;
989
- /**
990
- * Workflow-modification hold (`repo_identifier='.'`, `pr_number=3`,
991
- * `reason='workflow_modification'`) — the hold a non-trusted contributor's
992
- * workflow-editing PR produces. Seeded so the PR-scoped `/kici approve`
993
- * (which joins on `pr_number`) can find and resolve it.
994
- */
995
- wfModRunId: string;
996
- wfModDeliveryId: string;
997
- wfModJobId: string;
998
- /**
999
- * Fork-PR hold (`repo_identifier='.'`, `pr_number=4`, `reason='fork_pr'`) —
1000
- * the hold the org trust policy's fork arm produces. Reachable only since the
1001
- * policy became enforced, so it is seeded to prove PR-scoped selection and
1002
- * approval work for it exactly as they do for the workflow-modification hold.
1003
- */
1004
- forkPrRunId: string;
1005
- forkPrDeliveryId: string;
1006
- forkPrJobId: string;
1007
- }
1008
- export interface SeedCiSecurityFixturesResult {
1009
- /**
1010
- * The context name the fixture seeded (the `contextName` option, or its
1011
- * default). Assertions build the expected `held_runs.reason` from this rather
1012
- * than re-deriving the name, so an override cannot desync them.
1013
- */
1014
- contextName: string;
1015
- envId: string;
1016
- /** Held run for the unknown contributor (repo `.`, pr_number 1). */
1017
- heldRunId: string;
1018
- /** Held run for the same-repo second PR (repo `.`, pr_number 2). */
1019
- secondHeldRunId: string;
1020
- /** Held run for the different-repo run (repo `other/repo`, pr_number 1). */
1021
- otherRepoHeldRunId: string;
1022
- /** Held run for the workflow-modification PR (repo `.`, pr_number 3). */
1023
- wfModHeldRunId: string;
1024
- /** Held run for the fork PR (repo `.`, pr_number 4). */
1025
- forkPrHeldRunId: string;
1026
- }
1027
- /** repo_identifier used for the different-repo isolation hold. */
1028
- export declare const CI_SECURITY_OTHER_REPO = "other/repo";
1029
- export declare function seedCiSecurityFixturesDirect(databaseUrl: string, opts: SeedCiSecurityFixturesOpts): Promise<SeedCiSecurityFixturesResult>;
1030
- /**
1031
- * Poll `execution_runs` for the newest run started since `since` whose status
1032
- * is in `statuses`, returning that status. Resolves `{ status: null }` if the
1033
- * deadline passes before any run reaches a target status.
1034
- *
1035
- * Callers wanting "did the run finish?" pass the terminal status set and read
1036
- * the landed status — a terminal failure is reported immediately rather than
1037
- * indistinguishable from a timeout. Used by the cluster reroute tests to gate
1038
- * on a workflow reaching a terminal state after a webhook trigger.
1039
- */
1040
- export declare function waitForExecutionRunReachesStatusSinceDirect(databaseUrl: string, opts: {
1041
- since: Date;
1042
- statuses: readonly string[];
1043
- timeoutMs?: number;
1044
- intervalMs?: number;
1045
- }): Promise<{
1046
- status: string | null;
1047
- }>;
1048
- /**
1049
- * Fetch the most recent `execution_runs` row matching `status`, plus its
1050
- * `execution_jobs`. Used by cluster reroute tests to confirm the run +
1051
- * its jobs completed successfully.
1052
- */
1053
- export interface LatestExecutionRunResult {
1054
- run: {
1055
- run_id: string;
1056
- workflow_name: string;
1057
- status: string;
1058
- };
1059
- jobs: Array<{
1060
- job_id: string;
1061
- job_name: string;
1062
- status: string;
1063
- }>;
1064
- }
1065
- export declare function latestExecutionRunByStatusDirect(databaseUrl: string, opts: {
1066
- status: string;
1067
- }): Promise<LatestExecutionRunResult | null>;
1068
- /**
1069
- * Wait for a `execution_jobs` row joined against the most recent
1070
- * `execution_runs` for a given workflow name with started_at >= since,
1071
- * returning the job's status + error + run_id. Used by secrets-pipeline
1072
- * to gate on terminal job status.
1073
- */
1074
- export interface WaitForLatestJobResult {
1075
- status: string | null;
1076
- errorMessage: string | null;
1077
- runId: string | null;
1078
- }
1079
- export declare function waitForLatestExecutionJobStatusDirect(databaseUrl: string, opts: {
1080
- workflowName: string;
1081
- since: Date;
1082
- terminalStatuses?: readonly string[];
1083
- timeoutMs?: number;
1084
- intervalMs?: number;
1085
- }): Promise<WaitForLatestJobResult>;
1086
- /**
1087
- * READ-ONLY: return information_schema column names for `tableName`,
1088
- * ordered by ordinal_position. Used by e2e tests to verify migrations
1089
- * produced expected schema shape. Returns empty array if the table
1090
- * doesn't exist.
1091
- */
1092
- export interface ColumnInfo {
1093
- name: string;
1094
- dataType: string;
1095
- }
1096
- export declare function describeTableColumnsDirect(databaseUrl: string, opts: {
1097
- tableName: string;
1098
- }): Promise<ColumnInfo[]>;
1099
- /**
1100
- * READ-ONLY: return true if a table exists in the public schema.
1101
- */
1102
- export declare function tableExistsDirect(databaseUrl: string, opts: {
1103
- tableName: string;
1104
- schema?: string;
1105
- }): Promise<boolean>;
1106
- /**
1107
- * Raw INSERT into kici_events with custom chain_depth + expiry window.
1108
- * Used by event-routing e2e to test circuit-breaker + TTL behavior
1109
- * beyond what `emitKiciEventDirect` exposes (which hardcodes depth=0
1110
- * and 1h expiry). Returns the inserted id.
1111
- */
1112
- export interface InsertKiciEventRawOpts {
1113
- eventName: string;
1114
- payload: Record<string, unknown>;
1115
- sourceRoutingKey?: string;
1116
- chainDepth?: number;
1117
- /** ISO string or relative '1 hour' / '-1 hour'. Use negative for expired. */
1118
- expiresIn?: string;
1119
- }
1120
- export declare function insertKiciEventRawDirect(databaseUrl: string, opts: InsertKiciEventRawOpts): Promise<{
1121
- id: string;
1122
- }>;
1123
- /**
1124
- * READ-ONLY: return a kici_events row by id, or null. Callers decode
1125
- * `payload` as they need. Used by event-routing e2e after an INSERT.
1126
- */
1127
- export interface KiciEventRow {
1128
- id: string;
1129
- event_name: string;
1130
- payload: Record<string, unknown>;
1131
- chain_depth: number;
1132
- source_routing_key: string | null;
1133
- source_repo: string | null;
1134
- processed: boolean | null;
1135
- expires_at: string;
1136
- created_at: string;
1137
- }
1138
- export declare function showKiciEventDirect(databaseUrl: string, opts: {
1139
- id: string;
1140
- }): Promise<KiciEventRow | null>;
1141
- /**
1142
- * READ-ONLY: list kici_events with filter hooks used by e2e tests:
1143
- * by `event_name`, minimum `chain_depth`, expiry window. Returns the
1144
- * rows with chain_depth ordered ascending. Callers apply assertions.
1145
- */
1146
- export declare function listKiciEventsDirect(databaseUrl: string, opts?: {
1147
- eventName?: string;
1148
- minChainDepth?: number;
1149
- /** When true, return only rows past their expires_at. */
1150
- onlyExpired?: boolean;
1151
- /** When set, cap to this many rows. */
1152
- limit?: number;
1153
- }): Promise<KiciEventRow[]>;
1154
- /**
1155
- * DELETE kici_events by id or event_name. Returns the number of rows
1156
- * deleted. Used by event-routing teardown.
1157
- */
1158
- export declare function deleteKiciEventsDirect(databaseUrl: string, opts: {
1159
- id?: string;
1160
- eventName?: string;
1161
- }): Promise<{
1162
- deleted: number;
1163
- }>;
1164
- /**
1165
- * INSERT a kici_events row with an explicit created_at. Lets a test place
1166
- * many events on the exact same timestamp so the catch-up keyset cursor's
1167
- * same-created_at tie handling is genuinely exercised (the default-NOW insert
1168
- * path cannot force ties deterministically). Returns the inserted id.
1169
- */
1170
- export declare function insertKiciEventAtDirect(databaseUrl: string, opts: {
1171
- eventName: string;
1172
- createdAt: Date;
1173
- payload?: Record<string, unknown>;
1174
- chainDepth?: number;
1175
- sourceRoutingKey?: string | null;
1176
- expiresIn?: string;
1177
- }): Promise<{
1178
- id: string;
1179
- }>;
1180
- /**
1181
- * Page through unprocessed, non-DLQ kici_events for a given event_name using
1182
- * the same composite `(created_at, id)` keyset cursor + `ORDER BY created_at
1183
- * ASC, id ASC` that EventStore.getUnprocessedSince runs. Keep this SQL in sync
1184
- * with `packages/orchestrator/src/events/event-store.ts`.
1185
- *
1186
- * Returns every id seen across all pages in traversal order (with duplicates
1187
- * preserved so the caller can assert none occur) plus the page count. This is
1188
- * the real-Postgres guard that the keyset cursor pages the entire backlog —
1189
- * including same-created_at ties across a page boundary — with no skip and no
1190
- * duplicate.
1191
- */
1192
- export declare function paginateUnprocessedEventsKeysetDirect(databaseUrl: string, opts: {
1193
- eventName: string;
1194
- batchSize?: number;
1195
- }): Promise<{
1196
- ids: string[];
1197
- pages: number;
1198
- }>;
1199
- /**
1200
- * Simulate a NOTIFY on `kici_event_channel` and verify a LISTEN client
1201
- * receives it. Used by event-routing e2e to prove the infrastructure
1202
- * the EventRouter uses for real-time delivery is functional. Owns the
1203
- * pool for the full test to keep the listen/notify correlated.
1204
- */
1205
- export declare function verifyKiciEventNotifyDirect(databaseUrl: string, opts: {
1206
- payload: string;
1207
- waitMs?: number;
1208
- }): Promise<{
1209
- received: string[];
1210
- }>;
1211
- export interface CrossRepoTrustRow {
1212
- id: string;
1213
- source_repo: string;
1214
- source_routing_key: string;
1215
- target_repo: string;
1216
- target_routing_key: string;
1217
- allowed_events: string[] | null;
1218
- }
1219
- /**
1220
- * INSERT a cross_repo_trust row. Returns the new id and allowed_events
1221
- * array. Used by generic-webhook + event-routing e2e until a proper
1222
- * `kici-admin trust` CLI ships.
1223
- */
1224
- export declare function seedCrossRepoTrustDirect(databaseUrl: string, opts: {
1225
- sourceRepo: string;
1226
- sourceRoutingKey: string;
1227
- targetRepo: string;
1228
- targetRoutingKey: string;
1229
- allowedEvents?: string[];
1230
- }): Promise<{
1231
- id: string;
1232
- allowedEvents: string[] | null;
1233
- }>;
1234
- /**
1235
- * READ-ONLY: list cross_repo_trust rows by source_routing_key. Used by
1236
- * generic-webhook e2e to find a trust row it just inserted.
1237
- */
1238
- export declare function listCrossRepoTrustBySourceRoutingKeyDirect(databaseUrl: string, opts: {
1239
- sourceRoutingKey: string;
1240
- }): Promise<CrossRepoTrustRow[]>;
1241
- /**
1242
- * DELETE cross_repo_trust rows. Deletes by id, or asserts uniqueness
1243
- * check error on duplicate INSERT (handled by caller). Returns row count.
1244
- */
1245
- export declare function deleteCrossRepoTrustDirect(databaseUrl: string, opts: {
1246
- id: string;
1247
- }): Promise<{
1248
- deleted: number;
1249
- }>;
1250
- /**
1251
- * Direct INSERT with duplicate-key detection. Used by event-routing
1252
- * e2e to verify the unique constraint enforces. Throws on duplicate;
1253
- * caller asserts the error message matches /unique/i.
1254
- */
1255
- export declare function insertCrossRepoTrustStrictDirect(databaseUrl: string, opts: {
1256
- sourceRepo: string;
1257
- sourceRoutingKey: string;
1258
- targetRepo: string;
1259
- targetRoutingKey: string;
1260
- }): Promise<void>;
1261
- /**
1262
- * Cleanup helper for workflow_registrations. Accepts id, routingKey,
1263
- * or repoIdentifier filter (exactly one). Returns delete count.
1264
- */
1265
- export declare function deleteWorkflowRegistrationsDirect(databaseUrl: string, opts: {
1266
- id?: string;
1267
- routingKey?: string;
1268
- repoIdentifier?: string;
1269
- }): Promise<{
1270
- deleted: number;
1271
- }>;
1272
- /**
1273
- * READ-ONLY: workflow_registrations by id — returns null when missing.
1274
- * Pulls the full row so tests can assert lock_entry contents + trigger_types.
1275
- */
1276
- export interface WorkflowRegistrationFullRow extends WorkflowRegistrationRow {
1277
- lock_entry: unknown;
1278
- }
1279
- export declare function getWorkflowRegistrationByIdDirect(databaseUrl: string, opts: {
1280
- id: string;
1281
- }): Promise<WorkflowRegistrationFullRow | null>;
1282
- /**
1283
- * READ-ONLY: return the count + optional rows + latest updated_at for
1284
- * workflow_registrations scoped to a routing key. Used by forgejo e2e
1285
- * to wait for extraction + verify re-extraction bumped updated_at.
1286
- */
1287
- export interface RegistrationsScopedResult {
1288
- count: number;
1289
- latestUpdatedAt: Date | null;
1290
- rows: Array<{
1291
- workflow_name: string;
1292
- is_global: boolean;
1293
- }>;
1294
- }
1295
- export declare function listRegistrationsByRoutingKeyDirect(databaseUrl: string, opts: {
1296
- routingKey: string;
1297
- onlyGlobal?: boolean;
1298
- }): Promise<RegistrationsScopedResult>;
1299
- /**
1300
- * Poll `workflow_registrations` for at least `minCount` rows for a
1301
- * routing key. Returns the rows or throws on timeout (keeps parity with
1302
- * the forgejo helper pattern it replaces).
1303
- */
1304
- export declare function waitForRegistrationsByRoutingKeyDirect(databaseUrl: string, opts: {
1305
- routingKey: string;
1306
- minCount?: number;
1307
- onlyGlobal?: boolean;
1308
- timeoutMs?: number;
1309
- intervalMs?: number;
1310
- }): Promise<Array<{
1311
- workflow_name: string;
1312
- is_global: boolean;
1313
- }>>;
1314
- /**
1315
- * Wait for `workflow_registrations.updated_at` for a routing key to
1316
- * exceed `baselineUpdatedAt`. Used by forgejo rotated-PAT e2e.
1317
- */
1318
- export declare function waitForRegistrationsUpdatedAtAdvanceDirect(databaseUrl: string, opts: {
1319
- routingKey: string;
1320
- baselineUpdatedAt: Date | null;
1321
- timeoutMs?: number;
1322
- intervalMs?: number;
1323
- }): Promise<{
1324
- advanced: boolean;
1325
- latestUpdatedAt: Date | null;
1326
- }>;
1327
- /**
1328
- * UPDATE a workflow_registrations row's commit_sha. Used by cron-scheduler
1329
- * e2e where the manual-schedule handler rejects null commit SHAs.
1330
- */
1331
- export declare function updateWorkflowRegistrationCommitShaDirect(databaseUrl: string, opts: {
1332
- id: string;
1333
- commitSha: string;
1334
- }): Promise<void>;
1335
- /**
1336
- * Lock-entry seeding for the admin-API e2e, which uses a custom
1337
- * shape (cron schedule). Returns the inserted id.
1338
- */
1339
- export declare function insertWorkflowRegistrationRawDirect(databaseUrl: string, opts: {
1340
- routingKey: string;
1341
- repoIdentifier: string;
1342
- workflowName: string;
1343
- lockEntry: Record<string, unknown>;
1344
- triggerTypes: string[];
1345
- customerId: string;
1346
- isGlobal?: boolean;
1347
- disabled?: boolean;
1348
- commitSha?: string;
1349
- id?: string;
1350
- }): Promise<{
1351
- id: string;
1352
- }>;
1353
- /**
1354
- * INSERT with a STRICT shape (no ON CONFLICT). Used by registration-schema
1355
- * e2e to prove the unique constraint rejects duplicates. Throws the raw
1356
- * DB error (caller matches /unique/i).
1357
- */
1358
- export declare function insertWorkflowRegistrationStrictDirect(databaseUrl: string, opts: {
1359
- routingKey: string;
1360
- repoIdentifier: string;
1361
- workflowName: string;
1362
- lockEntryJson?: string;
1363
- triggerTypes: readonly string[];
1364
- customerId: string;
1365
- }): Promise<{
1366
- id: string | null;
1367
- }>;
1368
- /**
1369
- * READ-ONLY: latest registry_versions.version, or null if the default
1370
- * row is missing. Used by registration-admin-api e2e to bracket a
1371
- * refresh call.
1372
- */
1373
- export declare function getRegistryVersionDirect(databaseUrl: string, opts?: {
1374
- id?: string;
1375
- }): Promise<number | null>;
1376
- /**
1377
- * UPDATE `registry_versions.version = version + 1` WHERE id (default).
1378
- * Simpler than `bumpRegistryVersionDirect` — used by global-workflow
1379
- * e2e which wants the side-effect (force index refresh) without the
1380
- * return value.
1381
- */
1382
- export declare function bumpRegistryVersionSimpleDirect(databaseUrl: string, opts?: {
1383
- id?: string;
1384
- }): Promise<void>;
1385
- /**
1386
- * Seed cron_last_fired for a registration with an `-INTERVAL` offset so
1387
- * the scheduler fires on the next evaluation. Upsert via ON CONFLICT.
1388
- */
1389
- export declare function upsertCronLastFiredDirect(databaseUrl: string, opts: {
1390
- registrationId: string;
1391
- agoInterval: string;
1392
- scheduleKey: string;
1393
- }): Promise<void>;
1394
- /**
1395
- * READ-ONLY: count cron_last_fired rows for a registration. Used by
1396
- * registration-schema e2e to assert the FK cascade deletes the row.
1397
- */
1398
- export declare function countCronLastFiredDirect(databaseUrl: string, opts: {
1399
- registrationId: string;
1400
- }): Promise<number>;
1401
- /**
1402
- * INSERT a cron_last_fired row with an explicit timestamp. Used by
1403
- * registration-schema e2e to set up the FK cascade test.
1404
- */
1405
- export declare function insertCronLastFiredNowDirect(databaseUrl: string, opts: {
1406
- registrationId: string;
1407
- scheduleKey: string;
1408
- }): Promise<void>;
1409
- /**
1410
- * DELETE cron_last_fired rows for a registration. Teardown helper.
1411
- */
1412
- export declare function deleteCronLastFiredDirect(databaseUrl: string, opts: {
1413
- registrationId: string;
1414
- }): Promise<void>;
1415
- /**
1416
- * DELETE execution_runs by workflow_name. Teardown helper for
1417
- * manual-schedule e2e.
1418
- */
1419
- export declare function deleteExecutionRunsByWorkflowNameDirect(databaseUrl: string, opts: {
1420
- workflowName: string;
1421
- }): Promise<{
1422
- deleted: number;
1423
- }>;
1424
- /**
1425
- * READ-ONLY: SELECT generic_webhook_sources by routing_key.
1426
- * Used by forgejo e2e to assert the source exists with correct git_config.
1427
- */
1428
- export declare function getGenericWebhookSourceByRoutingKeyDirect(databaseUrl: string, opts: {
1429
- routingKey: string;
1430
- }): Promise<{
1431
- id: string;
1432
- git_config: unknown;
1433
- customer_id: string | null;
1434
- } | null>;
1435
- /**
1436
- * READ-ONLY: list active (enabled=true) generic_webhook_sources.
1437
- * Used by cluster-leader-failover e2e to prove the seeded source exists
1438
- * before a leader crash.
1439
- */
1440
- export declare function listActiveGenericWebhookSourcesDirect(databaseUrl: string): Promise<Array<{
1441
- id: string;
1442
- customer_id: string | null;
1443
- routing_key: string;
1444
- }>>;
1445
- /**
1446
- * UPDATE generic_webhook_sources.verification_config for a source by
1447
- * name + customer_id. Used by the generic-webhook-auth e2e which seeds
1448
- * sources and then writes custom auth configs.
1449
- */
1450
- export declare function updateGenericWebhookVerificationConfigDirect(databaseUrl: string, opts: {
1451
- name: string;
1452
- customerId: string;
1453
- verificationConfig: Record<string, unknown>;
1454
- }): Promise<void>;
1455
- /**
1456
- * DELETE generic_webhook_sources by name list. Teardown for the auth
1457
- * e2e, which seeded 3 sources by name.
1458
- */
1459
- export declare function deleteGenericWebhookSourcesByNameDirect(databaseUrl: string, opts: {
1460
- names: readonly string[];
1461
- }): Promise<{
1462
- deleted: number;
1463
- }>;
1464
- /**
1465
- * UPDATE generic_webhook_sources.deleted_at = NULL for a row by id.
1466
- * Used by the generic-webhook e2e to restore a soft-deleted source
1467
- * after the soft-delete test ran — there is no CLI-level undelete.
1468
- */
1469
- export declare function restoreSoftDeletedGenericWebhookSourceDirect(databaseUrl: string, opts: {
1470
- id: string;
1471
- }): Promise<void>;
1472
684
  /**
1473
685
  * One entry in any of the three repo-pattern lists stored on `org_settings`.
1474
686
  * `routingKey` is the source-qualifier; when absent, the entry applies to
@@ -1478,124 +690,6 @@ export interface OrgSettingsRepoPatternEntry {
1478
690
  routingKey?: string;
1479
691
  pattern: string;
1480
692
  }
1481
- /**
1482
- * UPSERT org_settings for a customer/org id. `globalWorkflowsEnabled` is
1483
- * required; the three list fields are each optional. Each list is a jsonb
1484
- * array of `{routingKey?, pattern}` entries. Pass `null` to clear a list.
1485
- */
1486
- export interface UpsertOrgSettingsOpts {
1487
- customerId: string;
1488
- globalWorkflowsEnabled: boolean;
1489
- allowedRepos?: OrgSettingsRepoPatternEntry[] | null;
1490
- deniedRepos?: OrgSettingsRepoPatternEntry[] | null;
1491
- elevatedRepos?: OrgSettingsRepoPatternEntry[] | null;
1492
- }
1493
- export declare function upsertOrgSettingsGlobalWorkflowsDirect(databaseUrl: string, opts: UpsertOrgSettingsOpts): Promise<void>;
1494
- /**
1495
- * UPDATE org_settings.global_workflow_denied_repos for a customer/org id.
1496
- * Assumes the row exists (upsertOrgSettingsGlobalWorkflowsDirect was
1497
- * called earlier in the test).
1498
- */
1499
- export declare function updateOrgSettingsDeniedReposDirect(databaseUrl: string, opts: {
1500
- customerId: string;
1501
- deniedRepos: OrgSettingsRepoPatternEntry[] | null;
1502
- }): Promise<void>;
1503
- /**
1504
- * DELETE org_settings by customer/org id. Teardown helper.
1505
- */
1506
- export declare function deleteOrgSettingsByCustomerIdDirect(databaseUrl: string, opts: {
1507
- customerId: string;
1508
- }): Promise<{
1509
- deleted: number;
1510
- }>;
1511
- /**
1512
- * READ-ONLY: fetch an execution_runs row by run_id, returning the
1513
- * security-relevant columns the ci-security e2e asserts on. Throws
1514
- * when the row is missing.
1515
- */
1516
- export interface ExecutionRunSecurityRow {
1517
- run_id: string;
1518
- trust_tier: string | null;
1519
- lock_file_source: string | null;
1520
- contributor_username: string | null;
1521
- status: string;
1522
- }
1523
- export declare function getExecutionRunSecurityDirect(databaseUrl: string, opts: {
1524
- runId: string;
1525
- }): Promise<ExecutionRunSecurityRow>;
1526
- /**
1527
- * READ-ONLY: fetch a held_runs row by id (with the security columns).
1528
- * Returns null if missing.
1529
- */
1530
- export interface HeldRunSecurityRow {
1531
- id: string;
1532
- run_id: string;
1533
- hold_type: string;
1534
- queue_type: string;
1535
- status: string;
1536
- reason: string | null;
1537
- expires_at: string | null;
1538
- approved_by: string | null;
1539
- resolved_at: string | null;
1540
- }
1541
- export declare function getHeldRunByIdDirect(databaseUrl: string, opts: {
1542
- id: string;
1543
- }): Promise<HeldRunSecurityRow | null>;
1544
- /** One recorded approver decision for a held run (`held_run_approvals` row). */
1545
- export interface HeldRunApprovalRow {
1546
- id: string;
1547
- held_run_id: string;
1548
- approver_user_id: string;
1549
- decision: string;
1550
- created_at: Date;
1551
- }
1552
- /**
1553
- * READ-ONLY: list the recorded approver decisions for a held run, newest
1554
- * first. Approver attribution lives in `held_run_approvals` (one row per
1555
- * decision), not on the `held_runs` row — used by ci-security e2e to prove
1556
- * an approval was stamped with the approving user's sub.
1557
- */
1558
- export declare function listHeldRunApprovalsDirect(databaseUrl: string, opts: {
1559
- heldRunId: string;
1560
- }): Promise<HeldRunApprovalRow[]>;
1561
- /**
1562
- * READ-ONLY: count held_runs rows matching run_id + queue_type.
1563
- * Used by ci-security e2e to prove no security hold exists for a
1564
- * trusted contributor PR.
1565
- */
1566
- export declare function countHeldRunsByRunIdDirect(databaseUrl: string, opts: {
1567
- runId: string;
1568
- queueType?: string;
1569
- }): Promise<number>;
1570
- /**
1571
- * Wait for Platform-side `execution_runs.status = <status>` where
1572
- * `created_at > since`. Returns the final status + failure_reason or
1573
- * null if the timeout elapsed. Used by webhook-pipeline (failed) and
1574
- * orchestrator-never-reconnects (timed_out_stale).
1575
- */
1576
- export declare function waitForPlatformExecutionRunStatusDirect(databaseUrl: string, opts: {
1577
- status: string;
1578
- since: Date;
1579
- timeoutMs?: number;
1580
- intervalMs?: number;
1581
- }): Promise<{
1582
- status: string;
1583
- failure_reason: string | null;
1584
- } | null>;
1585
- /**
1586
- * Wait for Platform `event_log` to show at least `minDistinctRouted`
1587
- * distinct `routed_to` values since a given timestamp. Used by
1588
- * cluster-round-robin to prove at least 2 orchestrators received
1589
- * deliveries. Returns the observed count (0 if timed out).
1590
- */
1591
- export declare function waitForPlatformEventLogDistinctRoutedDirect(databaseUrl: string, opts: {
1592
- since: Date;
1593
- minDistinctRouted: number;
1594
- timeoutMs?: number;
1595
- intervalMs?: number;
1596
- }): Promise<{
1597
- distinctRouted: number;
1598
- }>;
1599
693
  /**
1600
694
  * Wait for an orchestrator `event_log` row keyed by `delivery_id`.
1601
695
  * Returns the full row (the webhook-pipeline e2e asserts many
@@ -1615,114 +709,5 @@ export interface EventLogRow {
1615
709
  matched_count: number;
1616
710
  run_id: string | null;
1617
711
  }
1618
- export declare function waitForEventLogRowByDeliveryIdDirect(databaseUrl: string, opts: {
1619
- deliveryId: string;
1620
- timeoutMs?: number;
1621
- intervalMs?: number;
1622
- }): Promise<EventLogRow | null>;
1623
- /**
1624
- * Resolve a Platform `webhook_sources.routing_key` for an org.
1625
- *
1626
- * - With `routingKeyLikePrefix` only: returns the newest match. Note that
1627
- * this picks whichever generic source was registered most recently — if
1628
- * tests have created additional generic sources (e.g. universal-git-forgejo
1629
- * creating `stg-universal-git-forgejo`), the newest may NOT be the
1630
- * `stg-generic` default seeded by `pnpm deploy:stg`.
1631
- * - With `orchDbUrl` + `nameInOrchDb`: looks up the source by name in the
1632
- * orchestrator's `generic_webhook_sources` table, then verifies the
1633
- * resulting routing key is registered in Platform's `webhook_sources`.
1634
- * This is the disambiguating path Bucket-B tests should use when other
1635
- * generic sources may exist alongside the default.
1636
- */
1637
- export declare function resolvePlatformWebhookSourceRoutingKeyDirect(platformDbUrl: string, opts: {
1638
- orgId: string;
1639
- routingKeyLikePrefix: string;
1640
- orchDbUrl?: string;
1641
- nameInOrchDb?: string;
1642
- }): Promise<string | null>;
1643
- /**
1644
- * Idempotent seeding of an E2E regular user + org membership + owner
1645
- * role on the Platform DB. Used by stg-ha-smoke before seeding a user
1646
- * API key. Requires the org to already have an owner role.
1647
- */
1648
- export declare function ensureOrgOwnerMemberDirect(platformDbUrl: string, opts: {
1649
- orgId: string;
1650
- idpSub: string;
1651
- email: string;
1652
- displayName: string;
1653
- }): Promise<{
1654
- ownerRoleId: string;
1655
- }>;
1656
- /**
1657
- * Cleanup peer_credentials by instance_id LIKE pattern. Used by the
1658
- * cluster-peer-credentials e2e before/after each test to wipe its
1659
- * own seeded rows without touching real cluster credentials.
1660
- */
1661
- export declare function deletePeerCredentialsByInstanceIdLikeDirect(databaseUrl: string, opts: {
1662
- pattern: string;
1663
- }): Promise<{
1664
- deleted: number;
1665
- }>;
1666
- /**
1667
- * Insert a peer_credentials row with an explicit expires_at. Used by
1668
- * the "expired credential is not returned" e2e — the store's save()
1669
- * always computes a future expiry, so tests that need a pre-expired
1670
- * row must bypass it.
1671
- */
1672
- export declare function insertPeerCredentialExpiredDirect(databaseUrl: string, opts: {
1673
- instanceId: string;
1674
- credentialHash: string;
1675
- role: string;
1676
- routingKeys: readonly string[];
1677
- expiresAt: Date;
1678
- }): Promise<void>;
1679
- /**
1680
- * READ-ONLY: `revoked_at` for a peer_credentials row by hash. Used
1681
- * by the "save revokes old credential" e2e to assert revocation.
1682
- * Returns null when the row is missing entirely (distinct from
1683
- * "present but not revoked").
1684
- */
1685
- export declare function getPeerCredentialRevokedAtDirect(databaseUrl: string, opts: {
1686
- credentialHash: string;
1687
- }): Promise<{
1688
- present: boolean;
1689
- revokedAt: Date | null;
1690
- }>;
1691
- /**
1692
- * READ-ONLY: list active peer_credentials ids EXCLUDING a
1693
- * `instance_id LIKE` pattern. Used by revokeAll e2e to snapshot
1694
- * real cluster credentials it will restore later.
1695
- */
1696
- export declare function listActivePeerCredentialsExcludingDirect(databaseUrl: string, opts: {
1697
- excludeInstanceIdPattern: string;
1698
- }): Promise<{
1699
- ids: string[];
1700
- }>;
1701
- /**
1702
- * Clear revoked_at on a set of peer_credentials ids. Used by revokeAll
1703
- * e2e to restore real cluster credentials after the destructive test.
1704
- */
1705
- export declare function clearPeerCredentialsRevokedAtByIdsDirect(databaseUrl: string, opts: {
1706
- ids: readonly string[];
1707
- }): Promise<{
1708
- updated: number;
1709
- }>;
1710
- /**
1711
- * READ-ONLY: count currently-active (non-revoked, non-expired)
1712
- * peer_credentials rows for a given instance_id. Used by the
1713
- * concurrent-save e2e to assert 1 <= count <= 2.
1714
- */
1715
- export declare function countActivePeerCredentialsByInstanceDirect(databaseUrl: string, opts: {
1716
- instanceId: string;
1717
- }): Promise<number>;
1718
- /**
1719
- * Terminate every idle backend of the connecting user except our own
1720
- * connection. Mirrors what a Postgres leader demotion does to idle pooled
1721
- * connections — used by resilience tests to verify the pg pool error
1722
- * handlers absorb the termination without a process restart.
1723
- *
1724
- * Returns the number of backends terminated.
1725
- */
1726
- export declare function terminateIdleDbBackendsDirect(databaseUrl: string): Promise<number>;
1727
712
  export {};
1728
713
  //# sourceMappingURL=db-admin.d.ts.map