Files
OmniRoute/tests/unit/docker-ensure-base-path.test.ts
AmirHossein Rezaei bb5cb51f3e fix(docker): honor OMNIROUTE_BASE_PATH behind reverse-proxy subpaths (#8615)
* fix(docker): honor OMNIROUTE_BASE_PATH behind reverse-proxy subpaths

Next.js basePath is compile-time state; Docker now records the baked value,
forwards the env var as a build-arg, patches root-path images at container
start when needed, and probes health under the active subpath.

Hard Rule #13: scripts/docker/patch-basepath.sh and the entrypoint invoke Node
with a fixed argv; OMNIROUTE_BASE_PATH is read from process.env only — never
interpolated into sed/awk.

Closes #8600

* fix(docs): unblock CI for Docker basePath guide

Describe the build-time basePath marker as a sentinel file instead of a
fabricated env var, and replace the unsupported ```env fence with bash so
fumadocs/Shiki can compile DOCKER_GUIDE.md during DAST smoke.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(docker): add changelog fragment for #8615 basePath bundle patch

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-27 19:07:58 -03:00

48 lines
1.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { ensureDockerBasePath } from "../../scripts/docker/ensure-docker-base-path.mjs";
function makeStandaloneRoot(basePath = "") {
const appRoot = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-docker-base-"));
const distRoot = path.join(appRoot, ".build", "next");
fs.mkdirSync(path.join(distRoot, "server"), { recursive: true });
fs.writeFileSync(
path.join(distRoot, "routes-manifest.json"),
JSON.stringify({ basePath })
);
fs.writeFileSync(
path.join(distRoot, "server", "chunk.js"),
`export const config={basePath:"${basePath}"};`
);
fs.writeFileSync(path.join(appRoot, "BUILD_OMNIROUTE_BASE_PATH"), `${basePath}\n`);
return appRoot;
}
test("ensureDockerBasePath is a no-op when runtime matches the baked sentinel", () => {
const appRoot = makeStandaloneRoot("");
const result = ensureDockerBasePath({ appRoot, env: { OMNIROUTE_BASE_PATH: "" } });
assert.equal(result.action, "noop");
});
test("ensureDockerBasePath patches a root image when a subpath is configured", () => {
const appRoot = makeStandaloneRoot("");
const result = ensureDockerBasePath({ appRoot, env: { OMNIROUTE_BASE_PATH: "/omniroute" } });
assert.equal(result.action, "patched");
assert.equal(fs.readFileSync(path.join(appRoot, "BUILD_OMNIROUTE_BASE_PATH"), "utf8"), "/omniroute\n");
const manifest = JSON.parse(
fs.readFileSync(path.join(appRoot, ".build", "next", "routes-manifest.json"), "utf8")
);
assert.equal(manifest.basePath, "/omniroute");
});
test("ensureDockerBasePath rejects unset runtime on subpath images", () => {
const appRoot = makeStandaloneRoot("/omniroute");
assert.throws(
() => ensureDockerBasePath({ appRoot, env: {} }),
/built for subpath/
);
});