Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
feat(docker): runtime config fail-fast, sub-path href, gallery docs (#3736)
Igor Dykhta715d5753dcbf
diff --git a/docker/README.md b/docker/README.mdindex c9aa4a65a..584e5485e 100644--- a/docker/README.md+++ b/docker/README.md@@ -26,7 +26,7 @@ cp docker/config.example.json docker/config.json`docker/config.full-example.json` lists every supported key. Use it as a reference — do not mount it as-is (`mapUrl` boots a sample map, and `mapStyle.mapStyles` replaces the built-in basemap list).-Mount it when running (uncomment the `volumes` block in `docker-compose.yml` after creating the file). Pick **one** of these patterns — do not combine a read-only mount with `KEPLER_*` overrides (the entrypoint must write the merged file):+Mount it when running (uncomment the `volumes` block in `docker-compose.yml` after creating the file). Pick **one** of these patterns — do not combine a read-only mount with `KEPLER_*` overrides (the entrypoint must write the merged file, and the container **exits** if that write fails). Without `KEPLER_*` overrides there is nothing to write, so a read-only root filesystem still starts and serves with build-time defaults:```yaml# A) Config file only (read-only is fine)@@ -61,6 +61,13 @@ Supported `KEPLER_*` env vars (used in patterns B and C):| `KEPLER_MAP_CONFIG_URL` | `mapConfigUrl` || `KEPLER_MAP_URL` | `mapUrl` || `KEPLER_PAGE_TITLE` | `pageTitle` |+| `KEPLER_CONFIG_HREF` | Browser fetch URL for `config.json` (injected into `index.html`) |++The browser requests `/config.json` by default (origin root — same as GHCR, kepler.gl.com, and this image on port 8080). SPA routes like `/demo/:id` still hit that origin-root file, so the default needs no env. Set `KEPLER_CONFIG_HREF` only to read the config from somewhere else, for example `KEPLER_CONFIG_HREF=/shared/kepler-config.json` or an absolute URL on another host (CORS applies).++Serving the app itself at a browser-visible sub-path such as `https://host/kepler/` is **not supported**: `index.html` loads `/bundle.js` and `/bundle.css` from the origin root, the router declares its routes at `/`, `/auth`, and `/demo…` with no `basename`, and `loadSample` pushes `/demo/<id>`. A prefixed pathname therefore matches no route and renders an empty page. `KEPLER_CONFIG_HREF` relocates the config request only — it does not add sub-path support. Serve the app at the origin root; a reverse proxy in front is fine as long as it maps those root paths.++`mapConfigUrl` / `KEPLER_MAP_CONFIG_URL` replaces only the sample-gallery catalogue (`samples.json`). It does not rewrite compile-time `DATA_URL` or `ASSETS_URL`. Each catalogue row must use absolute `dataUrl`, `configUrl`, `imageUrl` (and `keplergl` / `remoteDatasetConfigUrl` when present) — the app does not prefix those paths. `ASSETS_URL` is only the "Try sample data" tab thumbnail CDN. A fully self-hosted gallery works by pointing `mapConfigUrl` at your own catalogue; see `docker/samples.example.json`.See `docker/config.full-example.json` for every key supported today (credentials, `pageTitle`, `mapConfigUrl`, `mapUrl`, reducer `mapStyle`, KeplerGl `mapStyles` / `mapStylesReplaceDefault`, and serializable `applicationConfig` fields).diff --git a/docker/docker-compose.yml b/docker/docker-compose.ymlindex d1baed1c8..6b6253a46 100644--- a/docker/docker-compose.yml+++ b/docker/docker-compose.yml@@ -36,3 +36,4 @@ services:KEPLER_MAP_CONFIG_URL: ${KEPLER_MAP_CONFIG_URL:-}KEPLER_MAP_URL: ${KEPLER_MAP_URL:-}KEPLER_PAGE_TITLE: ${KEPLER_PAGE_TITLE:-}+ KEPLER_CONFIG_HREF: ${KEPLER_CONFIG_HREF:-}diff --git a/docker/merge-runtime-config.js b/docker/merge-runtime-config.jsindex 5d2b4570e..2a9d4bd51 100644--- a/docker/merge-runtime-config.js+++ b/docker/merge-runtime-config.js@@ -21,11 +21,16 @@* KEPLER_MAP_CONFIG_URL* KEPLER_MAP_URL* KEPLER_PAGE_TITLE+ * KEPLER_CONFIG_HREF browser fetch URL; injected into index.html*/const fs = require('fs');const path = require('path');const CONFIG_PATH = process.env.KEPLER_CONFIG_PATH || path.join(__dirname, 'dist', 'config.json');+// Anchored to the directory `entrypoint.sh` serves, not to CONFIG_PATH: a custom+// KEPLER_CONFIG_PATH does not move the served index.html.+const INDEX_PATH = process.env.KEPLER_INDEX_PATH || path.join(__dirname, 'dist', 'index.html');+const CONFIG_HREF_SNIPPET_RE = /\s*<script>window\.__KEPLER_CONFIG_HREF__=.*?<\/script>/g;const ENV_CREDENTIALS = {KEPLER_MAPBOX_ACCESS_TOKEN: 'MapboxAccessToken',@@ -89,13 +94,85 @@ function mergeRuntimeConfig() {fs.writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`, 'utf8');console.log(`[kepler-entrypoint] Wrote runtime config to ${CONFIG_PATH}`);} catch (err) {- // Read-only volume mounts are expected; keep serving the mounted file.- console.warn(+ if (!changed) {+ // Nothing to persist (no env overrides), so a read-only root filesystem is+ // fine: the client treats a missing config.json as a no-op.+ console.warn(+ `[kepler-entrypoint] Could not create ${CONFIG_PATH} (${err.message}). ` ++ 'No KEPLER_* overrides were set; serving with build-time defaults.'+ );+ return;+ }+ console.error(`[kepler-entrypoint] Could not write ${CONFIG_PATH} (${err.message}). ` +- 'Using existing config as-is; KEPLER_* env overrides were not applied.'+ 'KEPLER_* env overrides were set but could not be written (read-only mount?). ' ++ 'Use a writable volume, or drop the env overrides and rely on the mounted file.');+ process.exit(1);}}}+function getConfigHrefFromEnv() {+ const href = process.env.KEPLER_CONFIG_HREF;+ return typeof href === 'string' && href.trim() ? href.trim() : '';+}++/**+ * `JSON.stringify` leaves `<` and the JS line separators as-is, so a value containing+ * `</script>` would close this inline script and corrupt index.html for every client.+ */+function toInlineScriptLiteral(value) {+ return JSON.stringify(value)+ .replace(/</g, '\\u003c')+ .replace(/\u2028/g, '\\u2028')+ .replace(/\u2029/g, '\\u2029');+}++function injectConfigHrefSnippet(html, href) {+ const snippet = `<script>window.__KEPLER_CONFIG_HREF__=${toInlineScriptLiteral(href)};</script>`;+ const withoutPrev = html.replace(CONFIG_HREF_SNIPPET_RE, '');+ if (!/<head[^>]*>/i.test(withoutPrev)) {+ throw new Error('index.html has no <head> to inject config href');+ }+ return withoutPrev.replace(/<head([^>]*)>/i, `<head$1>\n ${snippet}`);+}++function injectConfigHref() {+ const href = getConfigHrefFromEnv();+ if (!href) {+ return;+ }++ let html;+ try {+ html = fs.readFileSync(INDEX_PATH, 'utf8');+ } catch (err) {+ console.error(+ `[kepler-entrypoint] KEPLER_CONFIG_HREF is set but could not read ${INDEX_PATH} (${err.message}).`+ );+ process.exit(1);+ }++ let next;+ try {+ next = injectConfigHrefSnippet(html, href);+ } catch (err) {+ console.error(`[kepler-entrypoint] ${err.message}.`);+ process.exit(1);+ }++ try {+ fs.writeFileSync(INDEX_PATH, next, 'utf8');+ console.log(`[kepler-entrypoint] Injected KEPLER_CONFIG_HREF into ${INDEX_PATH}`);+ } catch (err) {+ console.error(+ `[kepler-entrypoint] Could not write ${INDEX_PATH} (${err.message}). ` ++ 'KEPLER_CONFIG_HREF requires a writable index.html.'+ );+ process.exit(1);+ }+}+mergeRuntimeConfig();+injectConfigHref();diff --git a/docker/samples.example.json b/docker/samples.example.jsonnew file mode 100644index 000000000..30f6f6f91--- /dev/null+++ b/docker/samples.example.json@@ -0,0 +1,13 @@+[+ {+ "id": "my-sample",+ "label": "My sample",+ "queryType": "sample",+ "visible": true,+ "size": 0,+ "description": "Point mapConfigUrl at this catalogue. Each row uses absolute URLs; the app does not prefix DATA_URL.",+ "imageUrl": "https://example.com/gallery/preview.png",+ "dataUrl": "https://example.com/gallery/data.csv",+ "configUrl": "https://example.com/gallery/config.json"+ }+]diff --git a/examples/demo-app/README.md b/examples/demo-app/README.mdindex 9f7dca0d5..ccfc921bf 100644--- a/examples/demo-app/README.md+++ b/examples/demo-app/README.md@@ -68,6 +68,6 @@ yarn start:local#### Optional: runtime `/config.json`-After a production build (`yarn build`), you can override tokens and demo-app settings without rebuilding by placing a `config.json` next to `dist/index.html` (i.e. `examples/demo-app/dist/config.json`). Copy `docker/config.example.json` as a starter; see `docker/config.full-example.json` and `docker/README.md` for the full schema, Compose mounts, and `KEPLER_*` env overrides.+After a production build (`yarn build`), you can override tokens and demo-app settings without rebuilding by placing a `config.json` next to `dist/index.html` (i.e. `examples/demo-app/dist/config.json`). The app fetches origin-root `/config.json` so SPA routes like `/demo/:id` still find it. To read the config from another location, set `window.__KEPLER_CONFIG_HREF__` (Docker: `KEPLER_CONFIG_HREF`) before `bundle.js` loads, or add a `<base href>` and `config.json` resolves against that base. Neither option hosts the app at a browser-visible sub-path — assets and router routes are root-absolute (see `docker/README.md`). Copy `docker/config.example.json` as a starter; see `docker/config.full-example.json` and `docker/README.md` for the full schema, Compose mounts, and `KEPLER_*` env overrides. `mapConfigUrl` only replaces the `samples.json` catalogue — sample rows still need absolute data/config URLs (see `docker/samples.example.json`). `ASSETS_URL` is the gallery tab thumbnail CDN and is not runtime-configurable.[yarn-install]: https://yarnpkg.com/getting-started/installdiff --git a/examples/demo-app/src/constants/default-settings.js b/examples/demo-app/src/constants/default-settings.jsindex 4624edea2..ea07b7594 100644--- a/examples/demo-app/src/constants/default-settings.js+++ b/examples/demo-app/src/constants/default-settings.js@@ -5,15 +5,19 @@and segments both use queryRunner */import keyMirror from 'keymirror';+/** Compile-time CDN for the "Try sample data" tab thumbnail only (`icon-demo-map.jpg`). */export const ASSETS_URL = 'https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/';+/** Compile-time host of the default `samples.json` catalogue (not a URL prefix for sample rows). */export const DATA_URL = 'https://raw.githubusercontent.com/keplergl/kepler.gl-data/master/';export const MAP_URI = 'demo/map?mapUrl=';-/** Override via `/config.json` `mapConfigUrl` (see runtime-config.js). */+/** Override via `config.json` `mapConfigUrl` (see runtime-config.js). */let mapConfigUrlOverride = null;/**- * Sample gallery catalogue URL. Cache-busted by default; runtime config can replace it.+ * Sample gallery catalogue URL. Cache-busted by default; `mapConfigUrl` replaces the+ * catalogue only. Rows in that JSON must use absolute `dataUrl` / `configUrl` /+ * `imageUrl` (the app does not prefix {@link DATA_URL}).* @returns {string}*/export function getMapConfigUrl() {diff --git a/examples/demo-app/src/utils/get-runtime-config-href.js b/examples/demo-app/src/utils/get-runtime-config-href.jsnew file mode 100644index 000000000..7f41a9361--- /dev/null+++ b/examples/demo-app/src/utils/get-runtime-config-href.js@@ -0,0 +1,44 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++/**+ * Resolve the runtime config URL.+ *+ * Default is origin-root `/config.json` so SPA routes (`/demo/:id`) and+ * GHCR / kepler.gl.com / Docker-at-/ still find it. A naive relative+ * `config.json` would 404 under those routes.+ *+ * `window.__KEPLER_CONFIG_HREF__` (Docker: `KEPLER_CONFIG_HREF`) reads the config+ * from another path or host; a `<base href>` resolves `config.json` against that+ * base. Neither hosts the app at a browser-visible sub-path — `index.html` assets+ * and the router routes in `main.js` are root-absolute.+ *+ * @param {Window} [win]+ * @returns {string}+ */+export function getRuntimeConfigHref(win = typeof window !== 'undefined' ? window : undefined) {+ if (!win) {+ return '/config.json';+ }++ const override = win.__KEPLER_CONFIG_HREF__;+ if (typeof override === 'string' && override.trim()) {+ return override.trim();+ }++ const doc = win.document;+ const hasBaseHref =+ doc &&+ typeof doc.querySelector === 'function' &&+ doc.querySelector('base[href]') &&+ doc.baseURI;+ if (hasBaseHref) {+ try {+ return new URL('config.json', doc.baseURI).href;+ } catch {+ // fall through to origin-root default+ }+ }++ return '/config.json';+}diff --git a/examples/demo-app/src/utils/runtime-config.js b/examples/demo-app/src/utils/runtime-config.jsindex 871bf1adf..a2ec90bb7 100644--- a/examples/demo-app/src/utils/runtime-config.js+++ b/examples/demo-app/src/utils/runtime-config.js@@ -4,9 +4,12 @@import {initApplicationConfig} from '@kepler.gl/utils';import {CLOUD_PROVIDERS_CONFIGURATION, setMapConfigUrl} from '../constants/default-settings';+import {getRuntimeConfigHref} from './get-runtime-config-href';++export {getRuntimeConfigHref};/**- * Demo-app-only runtime config loaded from `/config.json` (volume mount or+ * Demo-app-only runtime config loaded from `config.json` (volume mount or* Docker entrypoint). Kept separate from library {@link KeplerApplicationConfig}* so tokens, sample gallery URL, boot map, and branding stay out of the core type.*@@ -25,7 +28,7 @@ import {CLOUD_PROVIDERS_CONFIGURATION, setMapConfigUrl} from '../constants/defau* @property {{mapStyles?: object, styleType?: string}} [mapStyle]* @property {Array<object>} [mapStyles] KeplerGl prop form (array of styles)* @property {boolean} [mapStylesReplaceDefault]- * @property {string} [mapConfigUrl] Sample gallery `samples.json` URL+ * @property {string} [mapConfigUrl] Sample gallery catalogue URL (`samples.json` only)* @property {string} [mapUrl] Map JSON to load on boot when `?mapUrl=` is absent* @property {string} [pageTitle]*/@@ -49,7 +52,7 @@ const CREDENTIAL_TO_CLOUD_KEY = {* Built-in demo-app applicationConfig defaults (previously set in reducers/index.js).* Applied on first import so kepler.gl.com (website store/app) keeps the same* icons/flags, and again from {@link loadAndApplyRuntimeConfig} before any- * `/config.json` overlay so Docker/source builds can still override them.+ * runtime config overlay so Docker/source builds can still override them.** To enable DuckDB in a source build, also register the plugin here (or via a custom* bootstrap), e.g.:@@ -139,13 +142,13 @@ export function getRuntimeConfig() {}/**- * Fetch `/config.json` when present. Missing or invalid files are a no-op so- * local source builds and static hosting without a mount keep working.+ * Fetch runtime `config.json` when present. Missing or invalid files are a+ * no-op so local source builds and static hosting without a mount keep working.* @returns {Promise<DemoAppRuntimeConfig>}*/export async function loadRuntimeConfigJson() {try {- const response = await fetch('/config.json', {cache: 'no-store'});+ const response = await fetch(getRuntimeConfigHref(), {cache: 'no-store'});if (!response.ok) {return {};}@@ -157,7 +160,7 @@ export async function loadRuntimeConfigJson() {}/**- * Apply demo defaults, then overlay `/config.json` when available.+ * Apply demo defaults, then overlay runtime `config.json` when available.* Must run before dynamic import of the Redux store so reducer initial state* and cloud providers see runtime credentials / mapStyle.* @returns {Promise<DemoAppRuntimeConfig>}diff --git a/test/node/docker/get-runtime-config-href-test.js b/test/node/docker/get-runtime-config-href-test.jsnew file mode 100644index 000000000..609596bec--- /dev/null+++ b/test/node/docker/get-runtime-config-href-test.js@@ -0,0 +1,54 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++import test from 'tape';++import {getRuntimeConfigHref} from '../../../examples/demo-app/src/utils/get-runtime-config-href';++test('getRuntimeConfigHref defaults to origin-root /config.json', t => {+ t.equal(getRuntimeConfigHref(undefined), '/config.json');+ t.equal(getRuntimeConfigHref({}), '/config.json', 'SPA window without override or base');+ t.equal(+ getRuntimeConfigHref({+ document: {+ baseURI: 'http://localhost/demo/earthquakes',+ querySelector: () => null+ }+ }),+ '/config.json',+ 'does not follow the SPA path (would miss config.json)'+ );+ t.end();+});++test('getRuntimeConfigHref prefers window.__KEPLER_CONFIG_HREF__', t => {+ t.equal(+ getRuntimeConfigHref({+ __KEPLER_CONFIG_HREF__: '/kepler/config.json',+ document: {+ baseURI: 'http://localhost/kepler/demo/x',+ querySelector: () => ({href: '/kepler/'})+ }+ }),+ '/kepler/config.json'+ );+ t.equal(+ getRuntimeConfigHref({__KEPLER_CONFIG_HREF__: ' /other/config.json '}),+ '/other/config.json',+ 'trims override'+ );+ t.end();+});++test('getRuntimeConfigHref resolves config.json against <base href>', t => {+ t.equal(+ getRuntimeConfigHref({+ document: {+ baseURI: 'http://localhost/kepler/',+ querySelector: selector => (selector === 'base[href]' ? {href: '/kepler/'} : null)+ }+ }),+ 'http://localhost/kepler/config.json'+ );+ t.end();+});diff --git a/test/node/docker/index.js b/test/node/docker/index.jsindex 70b932ef1..df5a62107 100644--- a/test/node/docker/index.js+++ b/test/node/docker/index.js@@ -1,4 +1,5 @@// SPDX-License-Identifier: MIT// Copyright contributors to the kepler.gl project+import './get-runtime-config-href-test';import './merge-runtime-config-test';diff --git a/test/node/docker/merge-runtime-config-test.js b/test/node/docker/merge-runtime-config-test.jsindex 616832aa1..111b962b3 100644--- a/test/node/docker/merge-runtime-config-test.js+++ b/test/node/docker/merge-runtime-config-test.js@@ -10,6 +10,7 @@ import test from 'tape';const MERGE_SCRIPT = path.resolve(__dirname, '../../../docker/merge-runtime-config.js');const EXAMPLE_CONFIG = path.resolve(__dirname, '../../../docker/config.example.json');const FULL_EXAMPLE_CONFIG = path.resolve(__dirname, '../../../docker/config.full-example.json');+const SAMPLE_GALLERY_EXAMPLE = path.resolve(__dirname, '../../../docker/samples.example.json');function runMerge(env, configPath) {return spawnSync(process.execPath, [MERGE_SCRIPT], {@@ -44,6 +45,16 @@ test('docker/config.full-example.json lists supported keys', t => {t.end();});+test('docker/samples.example.json uses absolute catalogue URLs', t => {+ const samples = JSON.parse(fs.readFileSync(SAMPLE_GALLERY_EXAMPLE, 'utf8'));+ t.ok(Array.isArray(samples) && samples.length > 0, 'is a catalogue array');+ const row = samples[0];+ ['imageUrl', 'dataUrl', 'configUrl'].forEach(key => {+ t.ok(/^https?:\/\//.test(row[key]), `${key} is absolute`);+ });+ t.end();+});+test('merge-runtime-config writes env-only config when no file exists', t => {const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));const configPath = path.join(dir, 'config.json');@@ -114,3 +125,166 @@ test('merge-runtime-config writes empty credentials when nothing is set', t => {fs.rmSync(dir, {recursive: true, force: true});t.end();});++test('merge-runtime-config injects KEPLER_CONFIG_HREF into index.html', t => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));+ const configPath = path.join(dir, 'config.json');+ const indexPath = path.join(dir, 'index.html');+ fs.writeFileSync(+ indexPath,+ `<!doctype html>+<html>+ <head>+ <title>kepler.gl demo</title>+ </head>+ <body></body>+</html>+`+ );++ const result = runMerge(+ {+ KEPLER_INDEX_PATH: indexPath,+ KEPLER_CONFIG_HREF: '/kepler/config.json'+ },+ configPath+ );++ t.equal(result.status, 0, result.stderr || 'exit 0');+ const html = fs.readFileSync(indexPath, 'utf8');+ t.ok(+ html.includes('window.__KEPLER_CONFIG_HREF__="/kepler/config.json"'),+ 'injects the config href script'+ );++ const again = runMerge(+ {+ KEPLER_INDEX_PATH: indexPath,+ KEPLER_CONFIG_HREF: '/other/config.json'+ },+ configPath+ );+ t.equal(again.status, 0, again.stderr || 're-inject exit 0');+ const updated = fs.readFileSync(indexPath, 'utf8');+ t.ok(+ updated.includes('window.__KEPLER_CONFIG_HREF__="/other/config.json"'),+ 'replaces prior href'+ );+ t.equal(+ (updated.match(/window\.__KEPLER_CONFIG_HREF__/g) || []).length,+ 1,+ 'does not stack snippets'+ );++ fs.rmSync(dir, {recursive: true, force: true});+ t.end();+});++test('merge-runtime-config escapes the injected KEPLER_CONFIG_HREF', t => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));+ const configPath = path.join(dir, 'config.json');+ const indexPath = path.join(dir, 'index.html');+ fs.writeFileSync(indexPath, '<!doctype html>\n<html><head></head><body></body></html>\n');++ const result = runMerge(+ {+ KEPLER_INDEX_PATH: indexPath,+ KEPLER_CONFIG_HREF: '</script><script>alert(1)</script>'+ },+ configPath+ );++ t.equal(result.status, 0, result.stderr || 'exit 0');+ const html = fs.readFileSync(indexPath, 'utf8');+ t.notOk(html.includes('<script>alert(1)</script>'), 'does not emit a breakout script tag');+ t.ok(html.includes('\\u003c/script>'), 'escapes `<` in the injected value');+ t.equal(+ (html.match(/<script>/g) || []).length,+ 1,+ 'index.html still has a single injected script'+ );++ fs.rmSync(dir, {recursive: true, force: true});+ t.end();+});++test('merge-runtime-config anchors the default index.html to the served dist dir', t => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));+ const configPath = path.join(dir, 'config.json');++ // Custom KEPLER_CONFIG_PATH must not move the index.html lookup next to it.+ const result = runMerge({KEPLER_CONFIG_HREF: '/kepler/config.json'}, configPath);+ const output = `${result.stderr}\n${result.stdout}`;+ t.notOk(output.includes(path.join(dir, 'index.html')), 'does not look beside the config file');+ t.ok(output.includes(path.join('dist', 'index.html')), 'looks in the served dist directory');++ fs.rmSync(dir, {recursive: true, force: true});+ t.end();+});++test('merge-runtime-config skips index.html when KEPLER_CONFIG_HREF is unset', t => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));+ const configPath = path.join(dir, 'config.json');++ const result = runMerge({}, configPath);+ t.equal(result.status, 0, result.stderr || 'exit 0 without index.html');++ fs.rmSync(dir, {recursive: true, force: true});+ t.end();+});++test('merge-runtime-config exits when KEPLER_CONFIG_HREF cannot be injected', t => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));+ const configPath = path.join(dir, 'config.json');+ const indexPath = path.join(dir, 'missing-index.html');++ const result = runMerge(+ {+ KEPLER_INDEX_PATH: indexPath,+ KEPLER_CONFIG_HREF: '/kepler/config.json'+ },+ configPath+ );+ t.notEqual(result.status, 0, 'non-zero exit when index.html cannot be read');+ t.ok(+ /KEPLER_CONFIG_HREF is set but could not read/.test(`${result.stderr}\n${result.stdout}`),+ 'error explains the failed inject'+ );++ fs.rmSync(dir, {recursive: true, force: true});+ t.end();+});++test('merge-runtime-config exits when KEPLER_* cannot be written', t => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));+ const notDir = path.join(dir, 'not-a-dir');+ fs.writeFileSync(notDir, 'x');+ const configPath = path.join(notDir, 'config.json');++ const result = runMerge({KEPLER_MAPBOX_ACCESS_TOKEN: 'pk.ci-test'}, configPath);+ t.notEqual(result.status, 0, 'non-zero exit when env merge cannot be persisted');+ t.ok(+ /Could not write/.test(`${result.stderr}\n${result.stdout}`),+ 'error explains the failed write'+ );++ fs.rmSync(dir, {recursive: true, force: true});+ t.end();+});++test('merge-runtime-config serves on a read-only root when nothing is configured', t => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kepler-runtime-config-'));+ const notDir = path.join(dir, 'not-a-dir');+ fs.writeFileSync(notDir, 'x');+ const configPath = path.join(notDir, 'config.json');++ const result = runMerge({}, configPath);+ t.equal(result.status, 0, 'starts anyway so the app can use build-time defaults');+ t.ok(+ /No KEPLER_\* overrides were set/.test(`${result.stderr}\n${result.stdout}`),+ 'warns instead of failing the container'+ );++ fs.rmSync(dir, {recursive: true, force: true});+ t.end();+});