fix(hosting): live probe가 하위 경로 기준 URL에서 surface를 그 아래로 요청한다

문제: `HOSTING_BASE_URL`의 경로가 `/`가 아니면 probe가 거절해, 하위 경로
(`VITE_ROUTER_BASE_PATH=/app/`)로 배포한 release는 live 확인을 쓸 수
없었다. surface 경로(`/config.json`)도 늘 origin 루트로 풀었다.

고친 것: 기준 URL은 `/`로 끝나는 경로면 받는다(query·fragment는 거절).
`config/hosting/cache-policy.json`의 surface 경로는 기준 URL 아래로 푼다
(`surfaceUrl`). 진입 script는 index.html이 적은 그대로 요청한다. 후보의
진입 script가 기준 경로 아래에 있는지(`deployment base-path`)도 보아, 다른
경로로 빌드한 후보를 잘못된 기준 URL로 재면 실패한다.

검증: desktop `node scripts/run-vitest.ts run tests/unit/hosting-probe.test.ts`
46건 통과(`/app/` 기준 요청 경로, 경로 불일치 실패, URL 분류). 기준
커밋에서는 새 시험이 실패한다.

Refs: 0929/13-06
This commit is contained in:
DongHyeonka
2026-11-13 23:29:13 +09:00
parent e657d00fbe
commit 7922592c07
4 changed files with 104 additions and 13 deletions
+6 -3
View File
@@ -130,9 +130,12 @@ probe하지 않고 `UNVERIFIED`로 끝난다. 슬롯을 채우는 방법은
**주소와 연결**
1. 앱은 HTTPS origin의 루트(`/`)에서 내보낸다. 인증서가 유효하고, 어느 surface도 그
origin 밖으로 redirect하지 않는다. — FE-GATE-019가 잰다. `HOSTING_BASE_URL`은 경로 없는
HTTPS 루트 URL이어야 하고, surface마다 최종 origin을 본다.
1. 앱은 HTTPS origin의 루트(`/`)나 빌드한 하위 경로(`VITE_ROUTER_BASE_PATH`, 예 `/app/`)에서
내보낸다. 인증서가 유효하고, 어느 surface도 그 origin 밖으로 redirect하지 않는다. —
FE-GATE-019가 잰다. `HOSTING_BASE_URL`은 release의 기준 URL(루트 또는 `/`로 끝나는 그
하위 경로, query·fragment 없음)이다. probe는 surface 경로(`config/hosting/cache-policy.json`)를
그 아래에서 요청하고, 후보의 진입 script가 그 경로 아래에 있는지와 surface마다 최종
origin을 본다.
2. TLS에서 HTTP/2를 맺는다(ALPN `h2`). — FE-GATE-019가 잰다(`transport.alpnProtocols`).
**surface별 응답** (surface: probe가 요청하는 경로 하나)
+33 -8
View File
@@ -142,9 +142,9 @@ export async function probeLiveRelease(
const negotiateAlpn = transport.negotiateAlpn ?? negotiatedAlpnProtocol;
const responses: ResponseHeaders = {};
const results: ProbeResult[] = [];
const probe = async (surface: string, pathname: string): Promise<string | null> => {
const probe = async (surface: string, target: URL): Promise<string | null> => {
try {
const response = await fetcher(new URL(pathname, base));
const response = await fetcher(target);
const finalOrigin = new URL(response.url).origin;
results.push(
{
@@ -191,11 +191,12 @@ export async function probeLiveRelease(
const bodies: Record<string, string | null> = {};
for (const [surface, pathname] of Object.entries(paths)) {
bodies[surface] = await probe(surface, pathname);
bodies[surface] = await probe(surface, surfaceUrl(pathname, base));
}
const entryScript = servedEntryScript(bodies["index"] ?? "");
if (entryScript) {
await probe("hashedAsset", entryScript);
// The served index.html names it as the build wrote it (under the base path).
await probe("hashedAsset", new URL(entryScript, base));
} else {
results.push({
surface: "hashedAsset",
@@ -226,6 +227,21 @@ export async function probeLiveRelease(
});
}
const candidateEntryScript = servedEntryScript(candidate.indexHtml);
// 0929/13-06. The candidate was built for one base path; a HOSTING_BASE_URL
// with another path probes surfaces the release does not serve.
// The build writes its scripts to `<base>assets/`, so the entry script's
// folder says which base the candidate was built for, in both directions.
const builtFor = candidateEntryScript?.startsWith(`${base.pathname}${BUILD_ASSET_DIRECTORY}`) === true;
results.push({
surface: "deployment",
header: "base-path",
expected: `${base.pathname}${BUILD_ASSET_DIRECTORY}`,
observed: candidateEntryScript,
...(builtFor
? {}
: { reason: "the candidate was built for another base path than the HOSTING_BASE_URL path (VITE_ROUTER_BASE_PATH of the build)" }),
passed: builtFor,
});
results.push({
surface: "index",
header: "candidate-entry-script",
@@ -405,10 +421,19 @@ export function checkPublicServiceWorkers(
};
}
/**
* 0929/13-06. The surfaces in config/hosting/cache-policy.json are written
* from the release's root (`/config.json`); a release served under a base
* path (`VITE_ROUTER_BASE_PATH=/app/`) serves them under that path.
*/
export function surfaceUrl(pathname: string, base: URL): URL {
return new URL(`.${pathname.startsWith("/") ? pathname : `/${pathname}`}`, base);
}
/**
* A release gate must not promote a local preview server as live hosting
* evidence.
*
* evidence. 0929/13-06: the URL is the release's base URL, the root or the
* sub-path the build was made for (`/app/`).
*/
export function classifyLiveHostingBaseUrl(value: string):
| {
@@ -467,10 +492,10 @@ export function classifyLiveHostingBaseUrl(value: string):
observedOrigin,
};
}
if (url.pathname !== "/" || url.search || url.hash) {
if (!url.pathname.endsWith("/") || url.search || url.hash) {
return {
passed: false,
reason: "HOSTING_BASE_URL must be the canonical root URL",
reason: "HOSTING_BASE_URL must be the release's base URL: a path ending in \"/\", without query or fragment",
url,
observedOrigin,
};
+1 -1
View File
@@ -121,7 +121,7 @@ if (liveTarget?.passed && !slotEmpty) {
probeResults.push({
surface: "deployment",
header: "base-url",
expected: "canonical non-loopback HTTPS root URL",
expected: "non-loopback HTTPS base URL of the release",
observed: liveTarget.observedOrigin,
reason: liveTarget.reason,
passed: false,
+64 -1
View File
@@ -73,11 +73,18 @@ describe("live hosting evidence target", () => {
});
});
// 0929/13-06. A release built for VITE_ROUTER_BASE_PATH=/app/ is served
// under /app/; the probe refused any URL but the root, so it could not be used.
it("accepts the sub-path a release is built for", () => {
expect(classifyLiveHostingBaseUrl("https://frontend.example.test/app/")).toMatchObject({ passed: true });
});
it.each([
["http://frontend.example.test/", "requires HTTPS"],
["https://localhost:4173/", "not live deployment evidence"],
["https://127.0.0.1/", "not live deployment evidence"],
["https://frontend.example.test/app/", "canonical root URL"],
["https://frontend.example.test/app", "path ending in \"/\""],
["https://frontend.example.test/?preview=1", "without query or fragment"],
["https://user:secret@frontend.example.test/", "must not contain credentials"],
])("rejects %s", (url, reason) => {
expect(classifyLiveHostingBaseUrl(url)).toMatchObject({
@@ -193,6 +200,62 @@ describe("SPA fallback and worker script surfaces (1101/13-04)", () => {
expect(await failed({ ...RELEASE, "/__probe/deep-link": [200, INDEX] })).toEqual([]);
});
// 0929/13-06. Under a base path the surfaces are requested below it.
it("probes a release built for /app/ below /app/ and passes it", async () => {
const appIndex = '<script type="module" src="/app/assets/index-A1.js"></script>';
const requested: string[] = [];
const routes: Record<string, [number, string]> = {
"/app/": [200, appIndex],
"/app/config.json": [200, CONFIG],
"/app/release-manifest.json": [200, JSON.stringify({ schemaVersion: 2, ...IDENTITY })],
"/app/__probe/deep-link": [200, appIndex],
"/app/assets/index-A1.js": [200, ""],
};
const { results } = await probeLiveRelease(
new URL("https://frontend.example.test/app/"),
PATHS,
{ ...CANDIDATE, indexHtml: appIndex },
{
fetcher: async (url) => {
requested.push(url.pathname);
return host(routes)(url);
},
negotiateAlpn: async () => "h2",
alpnProtocols: ["h2"],
},
);
expect(requested).toEqual([
"/app/",
"/app/config.json",
"/app/release-manifest.json",
"/app/__probe/deep-link",
"/app/assets/index-A1.js",
]);
expect(results.filter((result) => !result.passed)).toEqual([]);
});
it("fails a HOSTING_BASE_URL path the candidate was not built for", async () => {
expect(
(await probeLiveRelease(new URL("https://frontend.example.test/app/"), PATHS, CANDIDATE, {
fetcher: host({}),
negotiateAlpn: async () => "h2",
alpnProtocols: ["h2"],
})).results.find((result) => result.header === "base-path"),
).toMatchObject({ expected: "/app/assets/", observed: "/assets/index-A1.js", passed: false });
// And the other way: a release built for /app/ probed at the root.
expect(
(await probeLiveRelease(base, PATHS, {
...CANDIDATE,
indexHtml: '<script type="module" src="/app/assets/index-A1.js"></script>',
}, {
fetcher: host({}),
negotiateAlpn: async () => "h2",
alpnProtocols: ["h2"],
})).results.find((result) => result.header === "base-path"),
).toMatchObject({ expected: "/assets/", observed: "/app/assets/index-A1.js", passed: false });
});
it("fails a host without the fallback", async () => {
expect(await failed(RELEASE)).toEqual(["appRoute http-status", "appRoute entry-script"]);
});