@mycadet/gateway 0.13.0 → 0.14.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.
- package/Dockerfile +1 -0
- package/README.md +10 -10
- package/eslint.config.mjs +7 -8
- package/knip.json +2 -8
- package/node_modules/@mycadet/assistant-client/src/__tests__/assistant-client.test.ts +40 -34
- package/node_modules/@mycadet/assistant-client/src/http-client.ts +59 -8
- package/node_modules/@mycadet/assistant-client/src/index.ts +4 -0
- package/node_modules/@mycadet/assistant-client/src/proxy-forward.ts +5 -4
- package/node_modules/@mycadet/assistant-client/src/websocket-upstream.ts +21 -31
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/package.json +18 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/endpoint.test.ts +36 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/endpoint.ts +142 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/index.ts +18 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/ipc-framing.ts +295 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/listen-options.ts +3 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.test.ts +444 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.ts +236 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/tsconfig.json +20 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
- package/node_modules/@mycadet/ces-client/package.json +7 -2
- package/node_modules/@mycadet/ces-client/src/index.ts +6 -0
- package/node_modules/@mycadet/ces-client/src/ipc-credentials.ts +363 -0
- package/node_modules/@mycadet/ces-client/src/log-export.ts +187 -0
- package/node_modules/@mycadet/ces-client/src/socket-path.ts +34 -0
- package/node_modules/@mycadet/ces-client/src/test-support.ts +280 -0
- package/node_modules/@mycadet/environments/package.json +0 -1
- package/node_modules/@mycadet/environments/src/index.ts +7 -19
- package/node_modules/@mycadet/environments/src/shell.test.ts +0 -45
- package/node_modules/@mycadet/environments/src/shell.ts +0 -50
- package/node_modules/@mycadet/environments/src/test-path-guard.ts +1 -1
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
- package/node_modules/@mycadet/gateway-client/src/__tests__/gateway-client.test.ts +5 -5
- package/node_modules/@mycadet/gateway-client/src/__tests__/package-boundary.test.ts +1 -1
- package/node_modules/@mycadet/gateway-client/src/__tests__/status-contracts.test.ts +1 -20
- package/node_modules/@mycadet/gateway-client/src/admission-policy-contract.ts +1 -2
- package/node_modules/@mycadet/gateway-client/src/gateway-ipc-contracts.ts +0 -16
- package/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.test.ts +1 -1
- package/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
- package/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
- package/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
- package/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
- package/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
- package/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
- package/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
- package/package.json +15 -13
- package/scripts/generate-openapi.ts +24 -32
- package/src/__tests__/actor-token-revocation.test.ts +14 -7
- package/src/__tests__/auto-approve-conversation-thresholds.test.ts +16 -16
- package/src/__tests__/auto-approve-thresholds.test.ts +22 -20
- package/src/__tests__/binding-helpers.test.ts +9 -12
- package/src/__tests__/channel-admission-policy-routes.test.ts +20 -34
- package/src/__tests__/channel-permission-overrides-routes.test.ts +20 -26
- package/src/__tests__/channel-verification-session-proxy.test.ts +36 -22
- package/src/__tests__/cli-entry-init.test.ts +103 -0
- package/src/__tests__/config.test.ts +4 -5
- package/src/__tests__/contact-handlers.test.ts +8 -10
- package/src/__tests__/contact-prompt-submit.test.ts +3 -1
- package/src/__tests__/contact-record-submit.test.ts +3 -1
- package/src/__tests__/contact-rich-read.test.ts +11 -20
- package/src/__tests__/contact-store-bind-principal.test.ts +12 -15
- package/src/__tests__/contact-store-invites.test.ts +6 -6
- package/src/__tests__/contact-store-mark-channel-verified.test.ts +8 -10
- package/src/__tests__/contact-store-merge-contacts.test.ts +7 -10
- package/src/__tests__/contact-store-mirror-op-missing.test.ts +7 -11
- package/src/__tests__/contacts-control-plane-proxy.test.ts +3 -21
- package/src/__tests__/contacts-info-client.test.ts +6 -5
- package/src/__tests__/contacts-info-joiner.test.ts +8 -13
- package/src/__tests__/contacts-scoped-route-fallthrough.test.ts +14 -12
- package/src/__tests__/credential-cache.test.ts +1 -6
- package/src/__tests__/credential-reader.test.ts +146 -157
- package/src/__tests__/credential-requests.test.ts +1 -3
- package/src/__tests__/credential-watcher-cloud-bootstrap.test.ts +57 -104
- package/src/__tests__/data-migration-m0007-backfill-ingress-invites.test.ts +14 -17
- package/src/__tests__/data-migration-m0008-upsert-acl-columns-from-assistant.test.ts +10 -13
- package/src/__tests__/data-migration-m0009-invite-fields-backfill.test.ts +20 -19
- package/src/__tests__/data-migration-m0010-drop-assistant-ingress-invites.test.ts +12 -15
- package/src/__tests__/data-migration-m0013-verification-sessions-backfill.test.ts +20 -23
- package/src/__tests__/data-migration-m0014-drop-assistant-verification-tables.test.ts +12 -15
- package/src/__tests__/data-migration-m0015-guardian-requests-backfill.test.ts +6 -9
- package/src/__tests__/data-migration-m0016-drop-assistant-guardian-tables.test.ts +16 -19
- package/src/__tests__/data-migration-m0017-coerce-escalate-policy.test.ts +6 -10
- package/src/__tests__/db-connection-isolation.test.ts +1 -2
- package/src/__tests__/db-proxy-allowlist.test.ts +25 -16
- package/src/__tests__/desktop-stream-websocket.test.ts +34 -28
- package/src/__tests__/device-identity-text.test.ts +4 -6
- package/src/__tests__/devices-mine.test.ts +12 -11
- package/src/__tests__/devices.test.ts +60 -260
- package/src/__tests__/discord-verification-contact-upgrade.test.ts +10 -13
- package/src/__tests__/edge-auth.test.ts +10 -148
- package/src/__tests__/edge-guardian-auth.test.ts +60 -44
- package/src/__tests__/guardian-binding-channel-reuse.test.ts +16 -18
- package/src/__tests__/guardian-bootstrap-binding.test.ts +7 -8
- package/src/__tests__/guardian-bootstrap-lookups.test.ts +25 -27
- package/src/__tests__/guardian-delivery-resolver.test.ts +8 -12
- package/src/__tests__/guardian-pin.test.ts +3 -1
- package/src/__tests__/handle-inbound-admission.test.ts +3 -12
- package/src/__tests__/handle-inbound-app-context.test.ts +3 -6
- package/src/__tests__/handle-inbound-invite-intercept.test.ts +3 -6
- package/src/__tests__/handle-inbound-trust-verdict.test.ts +3 -12
- package/src/__tests__/helpers/contact-route-table.ts +53 -32
- package/src/__tests__/helpers/env.ts +19 -0
- package/src/__tests__/helpers/gateway-config.ts +32 -0
- package/src/__tests__/helpers/remote-web-pairing-fixtures.ts +1 -7
- package/src/__tests__/helpers/signing-key.ts +27 -0
- package/src/__tests__/inbound-contact-seed.test.ts +7 -8
- package/src/__tests__/invite-redemption-engine-voice.test.ts +2 -3
- package/src/__tests__/invite-route-auth.test.ts +17 -15
- package/src/__tests__/ipc-contact-routes.test.ts +11 -19
- package/src/__tests__/ipc-contact-threshold.test.ts +16 -9
- package/src/__tests__/ipc-invite-routes.test.ts +6 -5
- package/src/__tests__/ipc-server-multi-client.test.ts +8 -1
- package/src/__tests__/ipc-server-watchdog.test.ts +16 -6
- package/src/__tests__/ipc-slack-thread-routes.test.ts +1 -2
- package/src/__tests__/ipc-voice-invite-routes.test.ts +3 -5
- package/src/__tests__/live-voice-websocket.test.ts +103 -95
- package/src/__tests__/load-guards.test.ts +0 -1
- package/src/__tests__/logger-retention.test.ts +11 -9
- package/src/__tests__/lum-2783-recovery-e2e.test.ts +3 -1
- package/src/__tests__/m0006-reconcile-contacts.test.ts +10 -13
- package/src/__tests__/oauth-callback.test.ts +13 -5
- package/src/__tests__/pair-origin-allowlist.test.ts +4 -118
- package/src/__tests__/rate-limit-loopback.test.ts +1 -5
- package/src/__tests__/refresh-device-binding.test.ts +3 -1
- package/src/__tests__/remote-web-pairing-challenge.test.ts +71 -132
- package/src/__tests__/remote-web-pairing-token.test.ts +16 -140
- package/src/__tests__/remote-web-pairing-verification.test.ts +17 -1
- package/src/__tests__/remote-web-public-base-url.test.ts +79 -0
- package/src/__tests__/resolve-assistant.test.ts +0 -1
- package/src/__tests__/runtime-client.test.ts +9 -9
- package/src/__tests__/runtime-health-proxy.test.ts +19 -14
- package/src/__tests__/runtime-proxy-auth.test.ts +129 -63
- package/src/__tests__/runtime-proxy-catchall-methods.test.ts +152 -0
- package/src/__tests__/runtime-proxy-device-stamp.test.ts +31 -24
- package/src/__tests__/runtime-proxy-error-body.test.ts +28 -30
- package/src/__tests__/runtime-proxy.test.ts +66 -59
- package/src/__tests__/runtime-stream-test-utils.ts +14 -3
- package/src/__tests__/seed-admission-policy.test.ts +1 -10
- package/src/__tests__/shared-invite-redeem.test.ts +7 -20
- package/src/__tests__/shared-invite-registration.test.ts +0 -34
- package/src/__tests__/slack-control-plane-proxy.test.ts +29 -17
- package/src/__tests__/slack-display-name.test.ts +3 -6
- package/src/__tests__/slack-normalize.test.ts +0 -1
- package/src/__tests__/slack-reaction-normalize.test.ts +0 -1
- package/src/__tests__/slack-socket-mode-catchup.test.ts +1 -2
- package/src/__tests__/slack-socket-mode-group-dm.test.ts +2 -3
- package/src/__tests__/slack-socket-mode-liveness.test.ts +6 -29
- package/src/__tests__/slack-socket-mode-outbound-root.test.ts +2 -3
- package/src/__tests__/slack-socket-mode-thread-tracking.test.ts +2 -3
- package/src/__tests__/sleep-wake-detector.test.ts +52 -25
- package/src/__tests__/speech-relay-websocket.test.ts +108 -100
- package/src/__tests__/stt-stream-websocket.test.ts +62 -69
- package/src/__tests__/telegram-control-plane-proxy.test.ts +36 -19
- package/src/__tests__/telegram-normalize.test.ts +1 -1
- package/src/__tests__/telegram-webhook-drop-visibility.test.ts +2 -3
- package/src/__tests__/telegram-webhook-handler.test.ts +121 -68
- package/src/__tests__/telegram-webhook-manager.test.ts +70 -90
- package/src/__tests__/test-preload.ts +21 -3
- package/src/__tests__/text-verification-helpers.test.ts +1 -1
- package/src/__tests__/trust-rules-route-auth.test.ts +16 -26
- package/src/__tests__/trust-rules-routes.test.ts +22 -25
- package/src/__tests__/twilio-media-websocket.test.ts +61 -59
- package/src/__tests__/twilio-webhooks.test.ts +5 -6
- package/src/__tests__/unversioned-api-fallthrough.test.ts +86 -0
- package/src/__tests__/upgrade-policy.test.ts +161 -0
- package/src/__tests__/upstream-transport.test.ts +20 -15
- package/src/__tests__/vercel-route-auth.test.ts +22 -36
- package/src/__tests__/watch-stream-websocket.test.ts +84 -91
- package/src/__tests__/whatsapp-download.test.ts +0 -1
- package/src/__tests__/whatsapp-webhook.test.ts +3 -3
- package/src/attachments/ingest.test.ts +0 -1
- package/src/auth/guardian-bootstrap.ts +5 -12
- package/src/auth/guardian-refresh.ts +0 -2
- package/src/auth/token-exchange.ts +23 -57
- package/src/auth/token-service.ts +69 -22
- package/src/auth-rate-limiter.ts +6 -0
- package/src/channels/inbound-event.test.ts +54 -0
- package/src/channels/inbound-event.ts +29 -3
- package/src/channels/ingress-verification.ts +10 -3
- package/src/channels/plugin-inbound.test.ts +4 -3
- package/src/channels/types.ts +0 -2
- package/src/cli/__tests__/contacts.test.ts +83 -60
- package/src/cli/__tests__/pairing.test.ts +230 -48
- package/src/cli/contacts.ts +0 -130
- package/src/cli/index.ts +20 -34
- package/src/cli/pairing.ts +118 -59
- package/src/cli/program.ts +227 -0
- package/src/cloud-features.ts +13 -0
- package/src/cloud-identity.ts +1 -1
- package/src/config-file-cache.ts +6 -0
- package/src/config-file-utils.ts +1 -1
- package/src/config-file-watcher.ts +104 -0
- package/src/config.ts +25 -23
- package/src/credential-cache.ts +6 -0
- package/src/credential-reader.ts +53 -35
- package/src/credential-watcher.ts +219 -22
- package/src/db/__tests__/session-store.test.ts +2 -1
- package/src/db/admission-policy-store.ts +1 -2
- package/src/db/connection.ts +12 -4
- package/src/db/contact-store.ts +82 -0
- package/src/db/data-migrations/m0002-actor-token-tables-to-gateway.ts +2 -7
- package/src/db/schema.ts +15 -0
- package/src/db/seed-admission-policy.ts +1 -1
- package/src/db/seed-trust-rules.ts +1 -4
- package/src/db/session-store.ts +0 -6
- package/src/discord/admission-log-visibility.test.ts +2 -2
- package/src/discord/forward.test.ts +3 -6
- package/src/discord/forward.ts +4 -8
- package/src/discord/lifecycle.ts +104 -0
- package/src/email/normalize.ts +1 -1
- package/src/email/register-callback.test.ts +1 -2
- package/src/email/register-callback.ts +4 -11
- package/src/guardian-contract.ts +30 -0
- package/src/handlers/handle-inbound.ts +2 -2
- package/src/http/browser-auth-cookies.ts +27 -22
- package/src/http/edge-forwarded-header.ts +0 -39
- package/src/http/loopback-guard.ts +0 -47
- package/src/http/middleware/auth.ts +35 -188
- package/src/http/middleware/cors.test.ts +66 -0
- package/src/http/middleware/cors.ts +23 -2
- package/src/http/router.ts +188 -151
- package/src/http/routes/assistant-handle.test.ts +133 -0
- package/src/http/routes/assistant-handle.ts +94 -0
- package/src/http/routes/audio-proxy.ts +49 -39
- package/src/http/routes/auto-approve-thresholds.ts +308 -230
- package/src/http/routes/brain-graph-proxy.ts +61 -52
- package/src/http/routes/channel-admission-policy.ts +219 -154
- package/src/http/routes/channel-ingress.test.ts +24 -19
- package/src/http/routes/channel-ingress.ts +255 -137
- package/src/http/routes/channel-permission-overrides.ts +189 -112
- package/src/http/routes/channel-readiness-proxy.ts +66 -45
- package/src/http/routes/channel-verification-session-proxy.test.ts +33 -82
- package/src/http/routes/channel-verification-session-proxy.ts +100 -455
- package/src/http/routes/cloud-hop.ts +138 -0
- package/src/http/routes/cloud-push-proxy.test.ts +34 -33
- package/src/http/routes/cloud-push-proxy.ts +56 -127
- package/src/http/routes/contacts-control-plane-proxy.ts +0 -12
- package/src/http/routes/contacts-control-plane-route-table.ts +372 -119
- package/src/http/routes/credential-entry-page.ts +12 -0
- package/src/http/routes/credential-requests.ts +10 -4
- package/src/http/routes/desktop-setup-proxy.ts +21 -11
- package/src/http/routes/desktop-stream-websocket.ts +67 -41
- package/src/http/routes/devices-mine.ts +11 -0
- package/src/http/routes/devices.ts +7 -63
- package/src/http/routes/email-webhook.test.ts +4 -20
- package/src/http/routes/guardian-channel-create.test.ts +6 -9
- package/src/http/routes/guardian-pin.ts +1 -1
- package/src/http/routes/guardian-refresh.ts +65 -2
- package/src/http/routes/index.ts +88 -0
- package/src/http/routes/ingress-domains.test.ts +57 -2
- package/src/http/routes/ingress-domains.ts +46 -14
- package/src/http/routes/integrations-status.ts +18 -0
- package/src/http/routes/ipc-runtime-proxy.test.ts +31 -6
- package/src/http/routes/ipc-runtime-proxy.ts +6 -3
- package/src/http/routes/live-voice-websocket.ts +159 -148
- package/src/http/routes/log-export.test.ts +61 -87
- package/src/http/routes/log-export.ts +143 -150
- package/src/http/routes/log-tail.test.ts +49 -32
- package/src/http/routes/log-tail.ts +31 -21
- package/src/http/routes/migration-rollback-proxy.ts +38 -32
- package/src/http/routes/oauth-apps-proxy.ts +109 -62
- package/src/http/routes/oauth-providers-proxy.ts +60 -51
- package/src/http/routes/pair.ts +23 -346
- package/src/http/routes/plugin-webhook-websocket.test.ts +73 -77
- package/src/http/routes/plugin-webhook-websocket.ts +210 -215
- package/src/http/routes/plugin-webhook.test.ts +3 -1
- package/src/http/routes/plugin-webhook.ts +0 -3
- package/src/http/routes/ps.ts +25 -20
- package/src/http/routes/regex-to-openapi-path.ts +39 -0
- package/src/http/routes/remote-web-pairing-challenge.ts +35 -81
- package/src/http/routes/remote-web-pairing-routes.ts +39 -0
- package/src/http/routes/remote-web-pairing-token.ts +6 -11
- package/src/http/routes/remote-web-pairing-verification.ts +7 -7
- package/src/http/routes/runtime-audio-stream.ts +147 -147
- package/src/http/routes/runtime-health-proxy.ts +43 -32
- package/src/http/routes/runtime-proxy.ts +54 -20
- package/src/http/routes/shared-invite-redeem.ts +1 -7
- package/src/http/routes/slack-control-plane-proxy.ts +57 -46
- package/src/http/routes/speech-relay-websocket.ts +310 -270
- package/src/http/routes/stt-stream-websocket.ts +102 -107
- package/src/http/routes/telegram-control-plane-proxy.ts +87 -58
- package/src/http/routes/telegram-webhook.test.ts +3 -19
- package/src/http/routes/telegram-webhook.ts +3 -2
- package/src/http/routes/terminal.test.ts +165 -0
- package/src/http/routes/terminal.ts +123 -0
- package/src/http/routes/trust-rules.suggest.test.ts +14 -22
- package/src/http/routes/trust-rules.ts +432 -246
- package/src/http/routes/tunnel-status.ts +26 -13
- package/src/http/routes/twilio-control-plane-proxy.ts +105 -64
- package/src/http/routes/twilio-media-websocket.ts +157 -147
- package/src/http/routes/twilio-voice-webhook.test.ts +14 -43
- package/src/http/routes/types.ts +92 -10
- package/src/http/routes/upgrade-broadcast-proxy.ts +38 -32
- package/src/http/routes/upgrade-policy.ts +186 -0
- package/src/http/routes/user-profile.test.ts +129 -0
- package/src/http/routes/user-profile.ts +204 -0
- package/src/http/routes/vercel-control-plane-proxy.ts +74 -52
- package/src/http/routes/watch-stream-websocket.ts +99 -138
- package/src/http/routes/webhook-routes.ts +214 -0
- package/src/http/routes/whatsapp-webhook.test.ts +3 -19
- package/src/http/routes/whatsapp-webhook.ts +2 -1
- package/src/http/routes/workspace-commit-proxy.ts +38 -30
- package/src/index.ts +298 -2481
- package/src/ipc/__tests__/admission-policy-handlers.test.ts +4 -18
- package/src/ipc/__tests__/guardian-request-routes.test.ts +7 -3
- package/src/ipc/__tests__/invite-ipc-routes.test.ts +13 -5
- package/src/ipc/__tests__/verification-session-routes.test.ts +5 -3
- package/src/ipc/admission-policy-handlers.ts +2 -2
- package/src/ipc/channel-socket-health-handlers.test.ts +56 -41
- package/src/ipc/channel-socket-health-handlers.ts +41 -31
- package/src/ipc/credential-request-handlers.ts +43 -19
- package/src/ipc/log-tail-handlers.test.ts +8 -35
- package/src/ipc/log-tail-handlers.ts +8 -11
- package/src/ipc/risk-classification-handlers.test.ts +0 -3
- package/src/ipc/risk-classification-handlers.ts +4 -4
- package/src/ipc/routes.ts +37 -0
- package/src/ipc/server.ts +13 -43
- package/src/ipc/trust-rules-handlers.test.ts +1 -2
- package/src/ipc/tunnel-handlers.ts +18 -18
- package/src/ipc/webhook-route-handlers.test.ts +5 -27
- package/src/ipc/webhook-route-handlers.ts +35 -39
- package/src/logger.ts +6 -26
- package/src/paths.ts +4 -4
- package/src/remote-web/pairing-challenge-store.ts +6 -35
- package/src/remote-web/pairing-mint.ts +2 -6
- package/src/remote-web/public-base-url.ts +65 -0
- package/src/risk/admission-policy-cache.ts +5 -12
- package/src/risk/bash-risk-classifier.test.ts +5 -6
- package/src/risk/bash-risk-classifier.ts +0 -3
- package/src/risk/command-registry/commands/gateway.ts +2 -1
- package/src/risk/file-risk-classifier.test.ts +1 -8
- package/src/risk/project-boundary.test.ts +3 -1
- package/src/risk/shell-identity.ts +1 -4
- package/src/risk/shell-parser.ts +1 -5
- package/src/risk/skill-risk-classifier.ts +1 -2
- package/src/runtime/client.ts +33 -27
- package/src/schema.ts +725 -163
- package/src/slack/errors.ts +1 -2
- package/src/slack/lifecycle.ts +327 -0
- package/src/slack/message-schemas.ts +1 -1
- package/src/slack/slack-web.ts +0 -1
- package/src/slack/socket-mode.ts +1 -1
- package/src/sleep-wake-detector.ts +62 -33
- package/src/telegram/normalize.test.ts +1 -1
- package/src/telegram/normalize.ts +1 -1
- package/src/telegram/send.test.ts +3 -19
- package/src/telegram/webhook-manager.ts +16 -31
- package/src/tunnel/allowed-paths.test.ts +27 -65
- package/src/tunnel/allowed-paths.ts +2 -27
- package/src/tunnel/binary-websocket.ts +1 -2
- package/src/tunnel/bridge-utils.ts +3 -8
- package/src/tunnel/client.test.ts +80 -67
- package/src/tunnel/client.ts +36 -28
- package/src/tunnel/http-bridge.test.ts +13 -40
- package/src/tunnel/websocket-bridge.test.ts +11 -2
- package/src/tunnel/websocket-bridge.ts +3 -1
- package/src/twilio/webhook-sync-trigger.ts +4 -4
- package/src/twilio/webhook-sync.test.ts +1 -33
- package/src/twilio/webhook-sync.ts +0 -4
- package/src/verification/code-parsing.ts +0 -3
- package/src/verification/rate-limit-helpers.ts +6 -2
- package/src/verification/session-service.ts +1 -1
- package/src/verification/shared-invite-registration.ts +3 -13
- package/src/verification/text-verification.ts +1 -1
- package/src/whatsapp/normalize.ts +1 -1
- package/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -38
- package/node_modules/@mycadet/environments/src/seeds.ts +0 -99
- package/node_modules/@mycadet/environments/src/types.ts +0 -70
- package/openapi.json +0 -2325
- package/src/__tests__/feature-flag-defaults-sync.test.ts +0 -44
- package/src/__tests__/feature-flag-resolver.test.ts +0 -151
- package/src/__tests__/feature-flag-watcher-callback.test.ts +0 -63
- package/src/__tests__/feature-flags-route.test.ts +0 -764
- package/src/__tests__/guardian-init-lockfile.test.ts +0 -883
- package/src/__tests__/ipc-feature-flag-routes.test.ts +0 -240
- package/src/__tests__/pair-device-bound.test.ts +0 -296
- package/src/__tests__/remote-web-ingress-denylist.test.ts +0 -113
- package/src/__tests__/remote-web-pairing-requests.test.ts +0 -277
- package/src/__tests__/route-schema-guard.test.ts +0 -489
- package/src/cloud-user-id.ts +0 -12
- package/src/feature-flag-defaults.ts +0 -197
- package/src/feature-flag-env-overrides.test.ts +0 -166
- package/src/feature-flag-env-overrides.ts +0 -58
- package/src/feature-flag-registry.json +0 -506
- package/src/feature-flag-resolver.ts +0 -47
- package/src/feature-flag-store.ts +0 -115
- package/src/feature-flag-watcher.ts +0 -105
- package/src/http/routes/a2a-routes.test.ts +0 -146
- package/src/http/routes/a2a-routes.ts +0 -126
- package/src/http/routes/auto-approve-thresholds-routes.ts +0 -92
- package/src/http/routes/channel-admission-policy-routes.ts +0 -67
- package/src/http/routes/channel-ingress-routes.ts +0 -135
- package/src/http/routes/channel-permission-overrides-routes.ts +0 -92
- package/src/http/routes/contacts-control-plane-routes.ts +0 -278
- package/src/http/routes/feature-flags.ts +0 -185
- package/src/http/routes/remote-web-pairing-requests.ts +0 -123
- package/src/http/routes/trust-rules-routes.ts +0 -188
- package/src/ipc/feature-flag-handlers.ts +0 -63
- package/src/types.ts +0 -11
|
@@ -1,764 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
2
|
-
import {
|
|
3
|
-
readFileSync,
|
|
4
|
-
writeFileSync,
|
|
5
|
-
rmSync,
|
|
6
|
-
mkdirSync,
|
|
7
|
-
existsSync,
|
|
8
|
-
} from "node:fs";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
import { testSecurityDir } from "./test-preload.js";
|
|
11
|
-
|
|
12
|
-
const protectedDir = testSecurityDir;
|
|
13
|
-
const featureFlagStorePath = join(protectedDir, "feature-flags.json");
|
|
14
|
-
|
|
15
|
-
// Write the test registry to an isolated temp path so we never touch
|
|
16
|
-
// the committed gateway/src/feature-flag-registry.json file.
|
|
17
|
-
const defaultsPath = join(protectedDir, "feature-flag-registry.json");
|
|
18
|
-
|
|
19
|
-
const TEST_REGISTRY = {
|
|
20
|
-
version: 1,
|
|
21
|
-
flags: [
|
|
22
|
-
{
|
|
23
|
-
id: "browser",
|
|
24
|
-
scope: "assistant",
|
|
25
|
-
key: "browser",
|
|
26
|
-
label: "Browser",
|
|
27
|
-
description: "Browser skill",
|
|
28
|
-
defaultEnabled: true,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id: "a2a-channel",
|
|
32
|
-
scope: "assistant",
|
|
33
|
-
key: "a2a-channel",
|
|
34
|
-
label: "A2A Channel",
|
|
35
|
-
description: "A2A channel integration",
|
|
36
|
-
defaultEnabled: false,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: "velvet",
|
|
40
|
-
scope: "client",
|
|
41
|
-
key: "velvet",
|
|
42
|
-
label: "Velvet",
|
|
43
|
-
description: "Enable the Velvet design theme.",
|
|
44
|
-
defaultEnabled: false,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: "default-model",
|
|
48
|
-
scope: "assistant",
|
|
49
|
-
key: "default-model",
|
|
50
|
-
label: "Default Model",
|
|
51
|
-
description: "Default LLM model identifier",
|
|
52
|
-
defaultEnabled: "claude-sonnet-4-6",
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
beforeEach(() => {
|
|
58
|
-
mkdirSync(protectedDir, { recursive: true });
|
|
59
|
-
writeFileSync(defaultsPath, JSON.stringify(TEST_REGISTRY, null, 2));
|
|
60
|
-
// Point registry resolution at the isolated test file first
|
|
61
|
-
_setRegistryCandidateOverrides([defaultsPath]);
|
|
62
|
-
resetFeatureFlagDefaultsCache();
|
|
63
|
-
clearFeatureFlagStoreCache();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
afterEach(() => {
|
|
67
|
-
// Clean up fixture files but keep the directory for the next test.
|
|
68
|
-
try {
|
|
69
|
-
rmSync(protectedDir, { recursive: true, force: true });
|
|
70
|
-
mkdirSync(protectedDir, { recursive: true });
|
|
71
|
-
} catch {
|
|
72
|
-
// best effort cleanup
|
|
73
|
-
}
|
|
74
|
-
_setRegistryCandidateOverrides(null);
|
|
75
|
-
resetFeatureFlagDefaultsCache();
|
|
76
|
-
clearFeatureFlagStoreCache();
|
|
77
|
-
resetEnvOverridesCache();
|
|
78
|
-
delete process.env.CADET_FLAG_A2A_CHANNEL;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const { createFeatureFlagsGetHandler, createFeatureFlagsPatchHandler } =
|
|
82
|
-
await import("../http/routes/feature-flags.js");
|
|
83
|
-
const {
|
|
84
|
-
loadFeatureFlagDefaults,
|
|
85
|
-
resetFeatureFlagDefaultsCache,
|
|
86
|
-
_setRegistryCandidateOverrides,
|
|
87
|
-
} = await import("../feature-flag-defaults.js");
|
|
88
|
-
const { clearFeatureFlagStoreCache, readPersistedFeatureFlags } =
|
|
89
|
-
await import("../feature-flag-store.js");
|
|
90
|
-
const { resetEnvOverridesCache } =
|
|
91
|
-
await import("../feature-flag-env-overrides.js");
|
|
92
|
-
|
|
93
|
-
describe("GET /v1/feature-flags handler", () => {
|
|
94
|
-
test("returns all declared assistant-scope flags with defaults when no persisted file exists", async () => {
|
|
95
|
-
// Don't create the feature-flags.json file
|
|
96
|
-
if (existsSync(featureFlagStorePath)) {
|
|
97
|
-
rmSync(featureFlagStorePath);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const handler = createFeatureFlagsGetHandler();
|
|
101
|
-
const res = await handler(
|
|
102
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
expect(res.status).toBe(200);
|
|
106
|
-
const body = await res.json();
|
|
107
|
-
const defaults = loadFeatureFlagDefaults();
|
|
108
|
-
const declaredKeys = Object.keys(defaults);
|
|
109
|
-
|
|
110
|
-
// Should return all declared assistant-scope flags (not client-scope)
|
|
111
|
-
expect(body.flags.length).toBe(declaredKeys.length);
|
|
112
|
-
expect(body.flags.length).toBeGreaterThan(0);
|
|
113
|
-
|
|
114
|
-
// Each entry should have the expected shape including label
|
|
115
|
-
for (const flag of body.flags) {
|
|
116
|
-
expect(typeof flag.key).toBe("string");
|
|
117
|
-
expect(typeof flag.label).toBe("string");
|
|
118
|
-
expect(["boolean", "string"]).toContain(typeof flag.enabled);
|
|
119
|
-
expect(["boolean", "string"]).toContain(typeof flag.defaultEnabled);
|
|
120
|
-
expect(typeof flag.description).toBe("string");
|
|
121
|
-
expect(flag.key).toMatch(/^[a-z0-9][a-z0-9-]*$/);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Check a specific known flag
|
|
125
|
-
const browserFlag = body.flags.find(
|
|
126
|
-
(f: { key: string }) => f.key === "browser",
|
|
127
|
-
);
|
|
128
|
-
expect(browserFlag).toBeDefined();
|
|
129
|
-
expect(browserFlag.defaultEnabled).toBe(true);
|
|
130
|
-
expect(browserFlag.label).toBe("Browser");
|
|
131
|
-
// When no persisted value, enabled should equal defaultEnabled
|
|
132
|
-
expect(browserFlag.enabled).toBe(true);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test("returns label field for all flags", async () => {
|
|
136
|
-
const handler = createFeatureFlagsGetHandler();
|
|
137
|
-
const res = await handler(
|
|
138
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
expect(res.status).toBe(200);
|
|
142
|
-
const body = await res.json();
|
|
143
|
-
|
|
144
|
-
for (const flag of body.flags) {
|
|
145
|
-
expect(typeof flag.label).toBe("string");
|
|
146
|
-
expect(flag.label.length).toBeGreaterThan(0);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Verify specific labels
|
|
150
|
-
const browserFlag2 = body.flags.find(
|
|
151
|
-
(f: { key: string }) => f.key === "browser",
|
|
152
|
-
);
|
|
153
|
-
expect(browserFlag2).toBeDefined();
|
|
154
|
-
expect(browserFlag2.label).toBe("Browser");
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test("does not include non-assistant-scope flags", async () => {
|
|
158
|
-
const handler = createFeatureFlagsGetHandler();
|
|
159
|
-
const res = await handler(
|
|
160
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
expect(res.status).toBe(200);
|
|
164
|
-
const body = await res.json();
|
|
165
|
-
|
|
166
|
-
// The client-scope flag should not appear
|
|
167
|
-
const clientFlag = body.flags.find(
|
|
168
|
-
(f: { key: string }) => f.key === "velvet",
|
|
169
|
-
);
|
|
170
|
-
expect(clientFlag).toBeUndefined();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test("returns all declared flags even when store has no persisted values", async () => {
|
|
174
|
-
// Write an empty feature-flags.json store
|
|
175
|
-
writeFileSync(
|
|
176
|
-
featureFlagStorePath,
|
|
177
|
-
JSON.stringify({ version: 1, values: {} }),
|
|
178
|
-
);
|
|
179
|
-
clearFeatureFlagStoreCache();
|
|
180
|
-
|
|
181
|
-
const handler = createFeatureFlagsGetHandler();
|
|
182
|
-
const res = await handler(
|
|
183
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
expect(res.status).toBe(200);
|
|
187
|
-
const body = await res.json();
|
|
188
|
-
const defaults = loadFeatureFlagDefaults();
|
|
189
|
-
const declaredKeys = Object.keys(defaults);
|
|
190
|
-
|
|
191
|
-
expect(body.flags.length).toBe(declaredKeys.length);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test("merges persisted values from feature-flags.json with defaults", async () => {
|
|
195
|
-
writeFileSync(
|
|
196
|
-
featureFlagStorePath,
|
|
197
|
-
JSON.stringify({
|
|
198
|
-
version: 1,
|
|
199
|
-
values: {
|
|
200
|
-
browser: false,
|
|
201
|
-
},
|
|
202
|
-
}),
|
|
203
|
-
);
|
|
204
|
-
clearFeatureFlagStoreCache();
|
|
205
|
-
|
|
206
|
-
const handler = createFeatureFlagsGetHandler();
|
|
207
|
-
const res = await handler(
|
|
208
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
expect(res.status).toBe(200);
|
|
212
|
-
const body = await res.json();
|
|
213
|
-
|
|
214
|
-
const browserFlag = body.flags.find(
|
|
215
|
-
(f: { key: string }) => f.key === "browser",
|
|
216
|
-
);
|
|
217
|
-
expect(browserFlag).toBeDefined();
|
|
218
|
-
expect(browserFlag.enabled).toBe(false); // overridden from default true
|
|
219
|
-
expect(browserFlag.defaultEnabled).toBe(true);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test("accepts string values in persisted feature flags", async () => {
|
|
223
|
-
writeFileSync(
|
|
224
|
-
featureFlagStorePath,
|
|
225
|
-
JSON.stringify({
|
|
226
|
-
version: 1,
|
|
227
|
-
values: {
|
|
228
|
-
"default-model": "gpt-4",
|
|
229
|
-
},
|
|
230
|
-
}),
|
|
231
|
-
);
|
|
232
|
-
clearFeatureFlagStoreCache();
|
|
233
|
-
|
|
234
|
-
const handler = createFeatureFlagsGetHandler();
|
|
235
|
-
const res = await handler(
|
|
236
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
expect(res.status).toBe(200);
|
|
240
|
-
const body = await res.json();
|
|
241
|
-
|
|
242
|
-
const modelFlag = body.flags.find(
|
|
243
|
-
(f: { key: string }) => f.key === "default-model",
|
|
244
|
-
);
|
|
245
|
-
expect(modelFlag).toBeDefined();
|
|
246
|
-
expect(modelFlag.enabled).toBe("gpt-4");
|
|
247
|
-
expect(modelFlag.defaultEnabled).toBe("claude-sonnet-4-6");
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
test("ignores non-boolean non-string values in persisted feature flags", async () => {
|
|
251
|
-
writeFileSync(
|
|
252
|
-
featureFlagStorePath,
|
|
253
|
-
JSON.stringify({
|
|
254
|
-
version: 1,
|
|
255
|
-
values: {
|
|
256
|
-
browser: 42,
|
|
257
|
-
},
|
|
258
|
-
}),
|
|
259
|
-
);
|
|
260
|
-
clearFeatureFlagStoreCache();
|
|
261
|
-
|
|
262
|
-
const handler = createFeatureFlagsGetHandler();
|
|
263
|
-
const res = await handler(
|
|
264
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
expect(res.status).toBe(200);
|
|
268
|
-
const body = await res.json();
|
|
269
|
-
|
|
270
|
-
const browserFlag = body.flags.find(
|
|
271
|
-
(f: { key: string }) => f.key === "browser",
|
|
272
|
-
);
|
|
273
|
-
expect(browserFlag).toBeDefined();
|
|
274
|
-
expect(browserFlag.enabled).toBe(true);
|
|
275
|
-
expect(browserFlag.defaultEnabled).toBe(true);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
test("registry default used when no local override is set", async () => {
|
|
279
|
-
// No local override
|
|
280
|
-
if (existsSync(featureFlagStorePath)) {
|
|
281
|
-
rmSync(featureFlagStorePath);
|
|
282
|
-
}
|
|
283
|
-
clearFeatureFlagStoreCache();
|
|
284
|
-
|
|
285
|
-
const handler = createFeatureFlagsGetHandler();
|
|
286
|
-
const res = await handler(
|
|
287
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
expect(res.status).toBe(200);
|
|
291
|
-
const body = await res.json();
|
|
292
|
-
|
|
293
|
-
const a2aFlag = body.flags.find(
|
|
294
|
-
(f: { key: string }) => f.key === "a2a-channel",
|
|
295
|
-
);
|
|
296
|
-
expect(a2aFlag).toBeDefined();
|
|
297
|
-
// Registry default (false) applies with no local override
|
|
298
|
-
expect(a2aFlag.enabled).toBe(false);
|
|
299
|
-
expect(a2aFlag.defaultEnabled).toBe(false);
|
|
300
|
-
|
|
301
|
-
// browser has defaultEnabled: true in registry
|
|
302
|
-
const browserFlag = body.flags.find(
|
|
303
|
-
(f: { key: string }) => f.key === "browser",
|
|
304
|
-
);
|
|
305
|
-
expect(browserFlag).toBeDefined();
|
|
306
|
-
expect(browserFlag.enabled).toBe(true);
|
|
307
|
-
expect(browserFlag.defaultEnabled).toBe(true);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
test("string flag uses registry default when no override exists", async () => {
|
|
311
|
-
if (existsSync(featureFlagStorePath)) rmSync(featureFlagStorePath);
|
|
312
|
-
clearFeatureFlagStoreCache();
|
|
313
|
-
|
|
314
|
-
const handler = createFeatureFlagsGetHandler();
|
|
315
|
-
const res = await handler(
|
|
316
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
expect(res.status).toBe(200);
|
|
320
|
-
const body = await res.json();
|
|
321
|
-
|
|
322
|
-
const modelFlag = body.flags.find(
|
|
323
|
-
(f: { key: string }) => f.key === "default-model",
|
|
324
|
-
);
|
|
325
|
-
expect(modelFlag).toBeDefined();
|
|
326
|
-
expect(modelFlag.enabled).toBe("claude-sonnet-4-6");
|
|
327
|
-
expect(modelFlag.defaultEnabled).toBe("claude-sonnet-4-6");
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
test("env override takes precedence over persisted and default values", async () => {
|
|
331
|
-
// Persisted value sets a2a-channel to false
|
|
332
|
-
writeFileSync(
|
|
333
|
-
featureFlagStorePath,
|
|
334
|
-
JSON.stringify({
|
|
335
|
-
version: 1,
|
|
336
|
-
values: { "a2a-channel": false },
|
|
337
|
-
}),
|
|
338
|
-
);
|
|
339
|
-
clearFeatureFlagStoreCache();
|
|
340
|
-
|
|
341
|
-
// Env override sets it to true
|
|
342
|
-
process.env.CADET_FLAG_A2A_CHANNEL = "true";
|
|
343
|
-
resetEnvOverridesCache();
|
|
344
|
-
|
|
345
|
-
const handler = createFeatureFlagsGetHandler();
|
|
346
|
-
const res = await handler(
|
|
347
|
-
new Request("http://gateway.test/v1/feature-flags"),
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
expect(res.status).toBe(200);
|
|
351
|
-
const body = await res.json();
|
|
352
|
-
|
|
353
|
-
const a2aFlag = body.flags.find(
|
|
354
|
-
(f: { key: string }) => f.key === "a2a-channel",
|
|
355
|
-
);
|
|
356
|
-
expect(a2aFlag).toBeDefined();
|
|
357
|
-
expect(a2aFlag.enabled).toBe(true);
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
test("returns flags when invoked via assistants path without trailing slash", async () => {
|
|
361
|
-
// The macOS client sends GET /v1/assistants/<id>/feature-flags (no trailing slash).
|
|
362
|
-
// The gateway route regex must accept this path.
|
|
363
|
-
const handler = createFeatureFlagsGetHandler();
|
|
364
|
-
const res = await handler(
|
|
365
|
-
new Request(
|
|
366
|
-
"http://gateway.test/v1/assistants/some-assistant-id/feature-flags",
|
|
367
|
-
),
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
expect(res.status).toBe(200);
|
|
371
|
-
const body = await res.json();
|
|
372
|
-
|
|
373
|
-
// Should return all assistant-scope flags with expected shape
|
|
374
|
-
expect(body.flags.length).toBeGreaterThan(0);
|
|
375
|
-
for (const flag of body.flags) {
|
|
376
|
-
expect(typeof flag.key).toBe("string");
|
|
377
|
-
expect(["boolean", "string"]).toContain(typeof flag.enabled);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Verify a known flag is present
|
|
381
|
-
const browserFlag = body.flags.find(
|
|
382
|
-
(f: { key: string }) => f.key === "browser",
|
|
383
|
-
);
|
|
384
|
-
expect(browserFlag).toBeDefined();
|
|
385
|
-
expect(browserFlag.enabled).toBe(true);
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
describe("PATCH /v1/feature-flags/:flagKey handler", () => {
|
|
390
|
-
test("writes to feature-flags.json store", async () => {
|
|
391
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
392
|
-
const res = await handler(
|
|
393
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
394
|
-
method: "PATCH",
|
|
395
|
-
headers: { "content-type": "application/json" },
|
|
396
|
-
body: JSON.stringify({ enabled: false }),
|
|
397
|
-
}),
|
|
398
|
-
"browser",
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
expect(res.status).toBe(200);
|
|
402
|
-
const body = await res.json();
|
|
403
|
-
expect(body).toEqual({
|
|
404
|
-
key: "browser",
|
|
405
|
-
enabled: false,
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
// Verify persistence to the feature-flags.json store
|
|
409
|
-
clearFeatureFlagStoreCache();
|
|
410
|
-
const persisted = readPersistedFeatureFlags();
|
|
411
|
-
expect(persisted["browser"]).toBe(false);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
test("preserves existing persisted flags when writing", async () => {
|
|
415
|
-
// Pre-seed a flag value
|
|
416
|
-
writeFileSync(
|
|
417
|
-
featureFlagStorePath,
|
|
418
|
-
JSON.stringify({
|
|
419
|
-
version: 1,
|
|
420
|
-
values: {
|
|
421
|
-
"a2a-channel": true,
|
|
422
|
-
},
|
|
423
|
-
}),
|
|
424
|
-
);
|
|
425
|
-
clearFeatureFlagStoreCache();
|
|
426
|
-
|
|
427
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
428
|
-
await handler(
|
|
429
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
430
|
-
method: "PATCH",
|
|
431
|
-
headers: { "content-type": "application/json" },
|
|
432
|
-
body: JSON.stringify({ enabled: true }),
|
|
433
|
-
}),
|
|
434
|
-
"browser",
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
// Both old and new values should be persisted
|
|
438
|
-
clearFeatureFlagStoreCache();
|
|
439
|
-
const persisted = readPersistedFeatureFlags();
|
|
440
|
-
expect(persisted["a2a-channel"]).toBe(true);
|
|
441
|
-
expect(persisted["browser"]).toBe(true);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
test("creates feature-flags.json and directories when they do not exist", async () => {
|
|
445
|
-
// Remove the protected dir to test directory creation
|
|
446
|
-
rmSync(protectedDir, { recursive: true, force: true });
|
|
447
|
-
|
|
448
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
449
|
-
const res = await handler(
|
|
450
|
-
new Request("http://gateway.test/v1/feature-flags/a2a-channel", {
|
|
451
|
-
method: "PATCH",
|
|
452
|
-
headers: { "content-type": "application/json" },
|
|
453
|
-
body: JSON.stringify({ enabled: true }),
|
|
454
|
-
}),
|
|
455
|
-
"a2a-channel",
|
|
456
|
-
);
|
|
457
|
-
|
|
458
|
-
expect(res.status).toBe(200);
|
|
459
|
-
expect(existsSync(featureFlagStorePath)).toBe(true);
|
|
460
|
-
|
|
461
|
-
clearFeatureFlagStoreCache();
|
|
462
|
-
const persisted = readPersistedFeatureFlags();
|
|
463
|
-
expect(persisted["a2a-channel"]).toBe(true);
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
// Validation tests
|
|
467
|
-
test("rejects empty flag key", async () => {
|
|
468
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
469
|
-
const res = await handler(
|
|
470
|
-
new Request("http://gateway.test/v1/feature-flags/", {
|
|
471
|
-
method: "PATCH",
|
|
472
|
-
headers: { "content-type": "application/json" },
|
|
473
|
-
body: JSON.stringify({ enabled: true }),
|
|
474
|
-
}),
|
|
475
|
-
"",
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
expect(res.status).toBe(400);
|
|
479
|
-
const body = await res.json();
|
|
480
|
-
expect(body.error).toContain("non-empty");
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
test("rejects old skills.* key format", async () => {
|
|
484
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
485
|
-
|
|
486
|
-
const oldFormatKeys = [
|
|
487
|
-
"skills.browser.enabled",
|
|
488
|
-
"skills.contacts.enabled",
|
|
489
|
-
"skills.my-skill.enabled",
|
|
490
|
-
];
|
|
491
|
-
|
|
492
|
-
for (const key of oldFormatKeys) {
|
|
493
|
-
const res = await handler(
|
|
494
|
-
new Request(`http://gateway.test/v1/feature-flags/${key}`, {
|
|
495
|
-
method: "PATCH",
|
|
496
|
-
headers: { "content-type": "application/json" },
|
|
497
|
-
body: JSON.stringify({ enabled: true }),
|
|
498
|
-
}),
|
|
499
|
-
key,
|
|
500
|
-
);
|
|
501
|
-
|
|
502
|
-
expect(res.status).toBe(400);
|
|
503
|
-
const body = await res.json();
|
|
504
|
-
expect(body.error).toContain("Invalid flag key format");
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
test("rejects key not matching simple kebab-case format", async () => {
|
|
509
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
510
|
-
|
|
511
|
-
const invalidKeys = [
|
|
512
|
-
"random.key",
|
|
513
|
-
"UPPERCASE",
|
|
514
|
-
"has_underscore",
|
|
515
|
-
"has.dot",
|
|
516
|
-
"INVALID!",
|
|
517
|
-
"-starts-with-dash",
|
|
518
|
-
];
|
|
519
|
-
|
|
520
|
-
for (const key of invalidKeys) {
|
|
521
|
-
const res = await handler(
|
|
522
|
-
new Request(`http://gateway.test/v1/feature-flags/${key}`, {
|
|
523
|
-
method: "PATCH",
|
|
524
|
-
headers: { "content-type": "application/json" },
|
|
525
|
-
body: JSON.stringify({ enabled: true }),
|
|
526
|
-
}),
|
|
527
|
-
key,
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
expect(res.status).toBe(400);
|
|
531
|
-
const body = await res.json();
|
|
532
|
-
expect(body.error).toContain("Invalid flag key format");
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
test("rejects undeclared keys (not in defaults registry)", async () => {
|
|
537
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
538
|
-
|
|
539
|
-
const res = await handler(
|
|
540
|
-
new Request("http://gateway.test/v1/feature-flags/totally-unknown-flag", {
|
|
541
|
-
method: "PATCH",
|
|
542
|
-
headers: { "content-type": "application/json" },
|
|
543
|
-
body: JSON.stringify({ enabled: true }),
|
|
544
|
-
}),
|
|
545
|
-
"totally-unknown-flag",
|
|
546
|
-
);
|
|
547
|
-
|
|
548
|
-
expect(res.status).toBe(400);
|
|
549
|
-
const body = await res.json();
|
|
550
|
-
expect(body.error).toContain("not declared");
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
test("accepts valid declared kebab-case key formats", async () => {
|
|
554
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
555
|
-
|
|
556
|
-
const validKeys = ["browser", "a2a-channel"];
|
|
557
|
-
|
|
558
|
-
for (const key of validKeys) {
|
|
559
|
-
clearFeatureFlagStoreCache();
|
|
560
|
-
const res = await handler(
|
|
561
|
-
new Request(`http://gateway.test/v1/feature-flags/${key}`, {
|
|
562
|
-
method: "PATCH",
|
|
563
|
-
headers: { "content-type": "application/json" },
|
|
564
|
-
body: JSON.stringify({ enabled: true }),
|
|
565
|
-
}),
|
|
566
|
-
key,
|
|
567
|
-
);
|
|
568
|
-
|
|
569
|
-
expect(res.status).toBe(200);
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
test("accepts string enabled value", async () => {
|
|
574
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
575
|
-
|
|
576
|
-
const res = await handler(
|
|
577
|
-
new Request("http://gateway.test/v1/feature-flags/default-model", {
|
|
578
|
-
method: "PATCH",
|
|
579
|
-
headers: { "content-type": "application/json" },
|
|
580
|
-
body: JSON.stringify({ enabled: "gpt-4" }),
|
|
581
|
-
}),
|
|
582
|
-
"default-model",
|
|
583
|
-
);
|
|
584
|
-
|
|
585
|
-
expect(res.status).toBe(200);
|
|
586
|
-
const body = await res.json();
|
|
587
|
-
expect(body).toEqual({ key: "default-model", enabled: "gpt-4" });
|
|
588
|
-
|
|
589
|
-
clearFeatureFlagStoreCache();
|
|
590
|
-
const persisted = readPersistedFeatureFlags();
|
|
591
|
-
expect(persisted["default-model"]).toBe("gpt-4");
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
test("rejects non-boolean non-string enabled value", async () => {
|
|
595
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
596
|
-
|
|
597
|
-
const invalidValues = [1, null, undefined];
|
|
598
|
-
for (const value of invalidValues) {
|
|
599
|
-
const res = await handler(
|
|
600
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
601
|
-
method: "PATCH",
|
|
602
|
-
headers: { "content-type": "application/json" },
|
|
603
|
-
body: JSON.stringify({ enabled: value }),
|
|
604
|
-
}),
|
|
605
|
-
"browser",
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
expect(res.status).toBe(400);
|
|
609
|
-
const body = await res.json();
|
|
610
|
-
expect(body.error).toContain("boolean or string");
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
test("rejects invalid JSON body", async () => {
|
|
615
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
616
|
-
const res = await handler(
|
|
617
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
618
|
-
method: "PATCH",
|
|
619
|
-
headers: { "content-type": "application/json" },
|
|
620
|
-
body: "not json",
|
|
621
|
-
}),
|
|
622
|
-
"browser",
|
|
623
|
-
);
|
|
624
|
-
|
|
625
|
-
expect(res.status).toBe(400);
|
|
626
|
-
const body = await res.json();
|
|
627
|
-
expect(body.error).toContain("valid JSON");
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
test("rejects missing body", async () => {
|
|
631
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
632
|
-
const res = await handler(
|
|
633
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
634
|
-
method: "PATCH",
|
|
635
|
-
}),
|
|
636
|
-
"browser",
|
|
637
|
-
);
|
|
638
|
-
|
|
639
|
-
expect(res.status).toBe(400);
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
test("atomic write does not corrupt store on successful write", async () => {
|
|
643
|
-
// Pre-seed the store
|
|
644
|
-
writeFileSync(
|
|
645
|
-
featureFlagStorePath,
|
|
646
|
-
JSON.stringify({
|
|
647
|
-
version: 1,
|
|
648
|
-
values: { "a2a-channel": true },
|
|
649
|
-
}),
|
|
650
|
-
);
|
|
651
|
-
clearFeatureFlagStoreCache();
|
|
652
|
-
|
|
653
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
654
|
-
await handler(
|
|
655
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
656
|
-
method: "PATCH",
|
|
657
|
-
headers: { "content-type": "application/json" },
|
|
658
|
-
body: JSON.stringify({ enabled: false }),
|
|
659
|
-
}),
|
|
660
|
-
"browser",
|
|
661
|
-
);
|
|
662
|
-
|
|
663
|
-
// Verify the file is valid JSON and contains all expected data
|
|
664
|
-
const raw = readFileSync(featureFlagStorePath, "utf-8");
|
|
665
|
-
const data = JSON.parse(raw);
|
|
666
|
-
expect(data.version).toBe(1);
|
|
667
|
-
expect(data.values["a2a-channel"]).toBe(true);
|
|
668
|
-
expect(data.values["browser"]).toBe(false);
|
|
669
|
-
|
|
670
|
-
// Verify no temp files left behind
|
|
671
|
-
const { readdirSync } = await import("node:fs");
|
|
672
|
-
const files = readdirSync(protectedDir);
|
|
673
|
-
const tmpFiles = files.filter((f: string) => f.includes(".tmp"));
|
|
674
|
-
expect(tmpFiles.length).toBe(0);
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
test("concurrent writes are serialized and no flag change is lost", async () => {
|
|
678
|
-
const handler = createFeatureFlagsPatchHandler();
|
|
679
|
-
|
|
680
|
-
// Fire multiple concurrent PATCH requests at the same time
|
|
681
|
-
const flagKeys = ["browser", "a2a-channel"];
|
|
682
|
-
|
|
683
|
-
const results = await Promise.all(
|
|
684
|
-
flagKeys.map((key) =>
|
|
685
|
-
handler(
|
|
686
|
-
new Request(`http://gateway.test/v1/feature-flags/${key}`, {
|
|
687
|
-
method: "PATCH",
|
|
688
|
-
headers: { "content-type": "application/json" },
|
|
689
|
-
body: JSON.stringify({ enabled: false }),
|
|
690
|
-
}),
|
|
691
|
-
key,
|
|
692
|
-
),
|
|
693
|
-
),
|
|
694
|
-
);
|
|
695
|
-
|
|
696
|
-
// All should succeed
|
|
697
|
-
for (const res of results) {
|
|
698
|
-
expect(res.status).toBe(200);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
// All flags should be persisted — none should be lost to a race
|
|
702
|
-
clearFeatureFlagStoreCache();
|
|
703
|
-
const persisted = readPersistedFeatureFlags();
|
|
704
|
-
for (const key of flagKeys) {
|
|
705
|
-
expect(persisted[key]).toBe(false);
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
|
|
709
|
-
test("invokes onFlagChanged once after a successful write", async () => {
|
|
710
|
-
let calls = 0;
|
|
711
|
-
const handler = createFeatureFlagsPatchHandler(() => {
|
|
712
|
-
calls += 1;
|
|
713
|
-
});
|
|
714
|
-
const res = await handler(
|
|
715
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
716
|
-
method: "PATCH",
|
|
717
|
-
headers: { "content-type": "application/json" },
|
|
718
|
-
body: JSON.stringify({ enabled: false }),
|
|
719
|
-
}),
|
|
720
|
-
"browser",
|
|
721
|
-
);
|
|
722
|
-
|
|
723
|
-
expect(res.status).toBe(200);
|
|
724
|
-
expect(calls).toBe(1);
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
test("does not invoke onFlagChanged when the request is rejected", async () => {
|
|
728
|
-
let calls = 0;
|
|
729
|
-
const handler = createFeatureFlagsPatchHandler(() => {
|
|
730
|
-
calls += 1;
|
|
731
|
-
});
|
|
732
|
-
const res = await handler(
|
|
733
|
-
new Request("http://gateway.test/v1/feature-flags/totally-unknown-flag", {
|
|
734
|
-
method: "PATCH",
|
|
735
|
-
headers: { "content-type": "application/json" },
|
|
736
|
-
body: JSON.stringify({ enabled: true }),
|
|
737
|
-
}),
|
|
738
|
-
"totally-unknown-flag",
|
|
739
|
-
);
|
|
740
|
-
|
|
741
|
-
expect(res.status).toBe(400);
|
|
742
|
-
expect(calls).toBe(0);
|
|
743
|
-
});
|
|
744
|
-
|
|
745
|
-
test("a throwing onFlagChanged does not fail an already-committed write", async () => {
|
|
746
|
-
const handler = createFeatureFlagsPatchHandler(() => {
|
|
747
|
-
throw new Error("notification boom");
|
|
748
|
-
});
|
|
749
|
-
const res = await handler(
|
|
750
|
-
new Request("http://gateway.test/v1/feature-flags/browser", {
|
|
751
|
-
method: "PATCH",
|
|
752
|
-
headers: { "content-type": "application/json" },
|
|
753
|
-
body: JSON.stringify({ enabled: false }),
|
|
754
|
-
}),
|
|
755
|
-
"browser",
|
|
756
|
-
);
|
|
757
|
-
|
|
758
|
-
expect(res.status).toBe(200);
|
|
759
|
-
|
|
760
|
-
clearFeatureFlagStoreCache();
|
|
761
|
-
const persisted = readPersistedFeatureFlags();
|
|
762
|
-
expect(persisted["browser"]).toBe(false);
|
|
763
|
-
});
|
|
764
|
-
});
|