From e21a5d634f9699096be38209d726283f0ac9b4a6 Mon Sep 17 00:00:00 2001 From: Dan Chen Date: Fri, 29 May 2026 23:11:07 -0700 Subject: [PATCH 1/2] test: cover nginx config generator directly --- runtime/generate-nginx-config.sh | 8 +- scripts/test-runtime-config.ts | 425 +----------------- tests/generate-nginx-config.test.ts | 642 ++++++++++++++++++++++++++++ tests/static-csp.contracts.ts | 4 +- 4 files changed, 670 insertions(+), 409 deletions(-) create mode 100644 tests/generate-nginx-config.test.ts diff --git a/runtime/generate-nginx-config.sh b/runtime/generate-nginx-config.sh index a3f5a76..c6902ff 100755 --- a/runtime/generate-nginx-config.sh +++ b/runtime/generate-nginx-config.sh @@ -98,12 +98,12 @@ encode_base64() { printf '%s' "$1" | base64 | tr -d '\n' } -runtime_root="/opt/opencode-web" +runtime_root="${OPENCODE_WEB_RUNTIME_ROOT:-/opt/opencode-web}" public_root="$runtime_root/public" runtime_config_root="$runtime_root/runtime-configs" runtime_bundle_path="$runtime_root/runtime/runtime-bundle.js" nginx_template_path="$runtime_root/config/nginx.conf.template" -nginx_config_path="/etc/nginx/conf.d/default.conf" +nginx_config_path="${OPENCODE_WEB_NGINX_CONFIG_PATH:-/etc/nginx/conf.d/default.conf}" nginx_servers_marker="# OPENCODE_WEB_GENERATED_SERVERS" nginx_listen_port="8080" @@ -220,7 +220,7 @@ server { listen $nginx_listen_port; listen [::]:$nginx_listen_port; server_name $host; - root /opt/opencode-web/public; + root $public_root; index index.html; $(write_no_store_headers) @@ -230,7 +230,7 @@ $(write_no_store_headers) } location = /runtime-config.js { - alias /opt/opencode-web/runtime-configs/$host.js; + alias $runtime_config_root/$host.js; } location ^~ /assets/ { diff --git a/scripts/test-runtime-config.ts b/scripts/test-runtime-config.ts index d8725e3..ed04f32 100755 --- a/scripts/test-runtime-config.ts +++ b/scripts/test-runtime-config.ts @@ -74,25 +74,6 @@ async function outputFor(args: string[]) { }; } -async function expectFailure( - name: string, - expectedMessage: string, - args: string[], -): Promise { - console.log(`==> ${name}`); - const result = await outputFor(args); - if (result.exitCode === 0) - throw new Error(`Expected failure, but command succeeded for: ${name}`); - - process.stdout.write(result.output); - - if (!result.output.includes(expectedMessage)) { - throw new Error( - `Expected message not found for: ${name}\nExpected: ${expectedMessage}`, - ); - } -} - async function expectSuccess(name: string, args: string[]): Promise { console.log(`==> ${name}`); await run(args); @@ -111,6 +92,11 @@ async function expectFinalImageLayout( "test -f /opt/opencode-web/config/nginx.conf.template", "test ! -e /opt/opencode-web/config/config", "test -f /opt/opencode-web/public/index.html", + "test -d /opt/opencode-web/public/assets", + "test -s /opt/opencode-web/public/opencode-web-customizations.css", + "test ! -e /opt/opencode-web/public/runtime-config.js", + '! grep -F "