feat: extend enterprise gateway policies billing protocols and operations
This commit is contained in:
1 parent
1528b71882
commit
af43947b5d
67 files changed
+1822
-69
No files matched your search
@@ -0,0 +1,68 @@
|
||||
"""Acceptance check on unique expiring Redis keys; no production keys are read or changed."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import ssl
|
||||
import subprocess
|
||||
import uuid
|
||||
|
||||
container = 'moyi-test-moyi-api-1'
|
||||
config = json.loads(subprocess.check_output(['docker', 'inspect', container]))[0]
|
||||
env = dict(item.split('=', 1) for item in config['Config']['Env'] if '=' in item)
|
||||
sock = socket.create_connection((env['MOYI_REDIS_HOST'], int(env.get('MOYI_REDIS_PORT', 6379))), 10)
|
||||
if env.get('MOYI_REDIS_SSL', '').lower() == 'true':
|
||||
sock = ssl.create_default_context().wrap_socket(sock, server_hostname=env['MOYI_REDIS_HOST'])
|
||||
reader = sock.makefile('rb')
|
||||
|
||||
def response():
|
||||
line = reader.readline()
|
||||
if not line:
|
||||
raise RuntimeError('Redis closed connection')
|
||||
kind, text = line[:1], line[1:-2]
|
||||
if kind == b'-':
|
||||
raise RuntimeError('Redis rejected acceptance command')
|
||||
if kind == b'+':
|
||||
return text.decode()
|
||||
if kind == b':':
|
||||
return int(text)
|
||||
if kind == b'$':
|
||||
size = int(text)
|
||||
if size < 0:
|
||||
return None
|
||||
value = reader.read(size)
|
||||
reader.read(2)
|
||||
return value
|
||||
if kind == b'*':
|
||||
return [response() for _ in range(int(text))]
|
||||
raise RuntimeError('Unexpected Redis response')
|
||||
|
||||
def command(*parts):
|
||||
values = [str(p).encode() for p in parts]
|
||||
sock.sendall(b'*' + str(len(values)).encode() + b'\r\n' + b''.join(b'$' + str(len(v)).encode() + b'\r\n' + v + b'\r\n' for v in values))
|
||||
return response()
|
||||
|
||||
if env.get('MOYI_REDIS_PASSWORD'):
|
||||
args = ['AUTH']
|
||||
if env.get('MOYI_REDIS_USERNAME'):
|
||||
args.append(env['MOYI_REDIS_USERNAME'])
|
||||
command(*args, env['MOYI_REDIS_PASSWORD'])
|
||||
command('SELECT', int(env.get('MOYI_REDIS_DATABASE', 0)))
|
||||
root = Path(__file__).resolve().parent
|
||||
script = (root / 'acquire-slot.lua').read_text()
|
||||
rate = (root / 'rate-limit.lua').read_text()
|
||||
prefix = 'moyi:acceptance:' + uuid.uuid4().hex + ':'
|
||||
keys = [prefix + 'user', prefix + 'rate']
|
||||
try:
|
||||
assert command('EVAL', script, 1, keys[0], 2, 60000, 'long-task') == 1
|
||||
assert command('EVAL', script, 1, keys[0], 2, 1000, 'short-chat') == 1
|
||||
assert command('PTTL', keys[0]) > 50000, 'Short chat shortened async lease'
|
||||
assert command('EVAL', script, 1, keys[0], 2, 1000, 'third') == 0
|
||||
assert command('ZREM', keys[0], 'short-chat') == 1
|
||||
assert command('EVAL', script, 1, keys[0], 2, 1000, 'third') == 1
|
||||
assert command('EVAL', rate, 1, keys[1], 1, 60000) == 0
|
||||
assert command('EVAL', rate, 1, keys[1], 1, 60000) > 0
|
||||
print('PASS: shared user concurrency, async lease lifetime, release and RPM on isolated keys')
|
||||
finally:
|
||||
command('DEL', *keys)
|
||||
reader.close()
|
||||
sock.close()
|
||||
@@ -30,7 +30,7 @@ New-Item -ItemType Directory -Force -Path $artifactRoot | Out-Null
|
||||
$staging = Join-Path $artifactRoot ('moyi-test-' + $releaseId)
|
||||
New-Item -ItemType Directory -Path $staging | Out-Null
|
||||
# Copy tracked deployment files only, never .env, certificates or .git.
|
||||
$tracked = @(git ls-files infra/moyi scripts/live-gateway-smoke.py docs/11-server-test-deployment.md docs/13-model-groups-registration-credit.md docs/14-lifecycle-usage-credit-adjustments.md docs/15-relay-onboarding.md docs/16-streaming-chat-billing.md docs/17-catalog-and-key-selection.md docs/18-pricing-currency-and-discounts.md)
|
||||
$tracked = @(git ls-files infra/moyi scripts/live-gateway-smoke.py docs/11-server-test-deployment.md docs/13-model-groups-registration-credit.md docs/14-lifecycle-usage-credit-adjustments.md docs/15-relay-onboarding.md docs/16-streaming-chat-billing.md docs/17-catalog-and-key-selection.md docs/18-pricing-currency-and-discounts.md docs/19-enterprise-gateway-increment.md)
|
||||
foreach ($relative in $tracked) {
|
||||
if ($relative -match '(^|/)(\.env\.cloud|\.deploy-mode|certs)(/|$)') { throw 'Sensitive path in release allowlist.' }
|
||||
$destination = Join-Path $staging $relative
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"""Run all Java tests against a fresh, local-only PostgreSQL cluster; never production."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
repo = Path(__file__).resolve().parent.parent
|
||||
pg = Path(r'C:\Program Files\PostgreSQL\17\bin')
|
||||
folder = Path(tempfile.mkdtemp(prefix='enterprise-test-', dir=repo / '.tools'))
|
||||
with socket.socket() as sock:
|
||||
sock.bind(('127.0.0.1', 0))
|
||||
port = sock.getsockname()[1]
|
||||
env = os.environ.copy()
|
||||
env['JAVA_HOME'] = str(repo / '.tools/jdk-build-22')
|
||||
env['MOYI_AUTH_TEST_JDBC_URL'] = f'jdbc:postgresql://127.0.0.1:{port}/postgres'
|
||||
|
||||
def run(command, name, timeout=120):
|
||||
with (folder / name).open('wb') as output:
|
||||
result = subprocess.run([str(x) for x in command], cwd=repo, env=env, stdout=output,
|
||||
stderr=subprocess.STDOUT, timeout=timeout,
|
||||
creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0))
|
||||
if result.returncode:
|
||||
print((folder / name).read_text(encoding='utf-8', errors='replace')[-14000:])
|
||||
raise RuntimeError(f'{name} failed ({result.returncode})')
|
||||
|
||||
run([pg / 'initdb.exe', '-D', folder / 'data', '-U', 'moyi_role_test', '-A', 'trust', '--encoding=UTF8', '--locale=C'], 'init.log')
|
||||
try:
|
||||
run([pg / 'pg_ctl.exe', '-D', folder / 'data', '-l', folder / 'postgres.log', '-o', f'-p {port} -h 127.0.0.1', '-w', 'start'], 'start.log')
|
||||
print(f'Isolated PostgreSQL ready on 127.0.0.1:{port}; logs: {folder}', flush=True)
|
||||
run([repo / '.tools/apache-maven-3.9.9/bin/mvn.cmd', '-B', '-ntp', '-Dmaven.repo.local=.tools/m2', '-f', 'control-plane-java/pom.xml', 'test'], 'tests.log', 600)
|
||||
print((folder / 'tests.log').read_text(encoding='utf-8', errors='replace')[-3500:])
|
||||
finally:
|
||||
run([pg / 'pg_ctl.exe', '-D', folder / 'data', '-w', 'stop', '-m', 'fast'], 'stop.log')
|
||||
Reference in new issue
Block a user