// Regression tests for the client-navigation response shape. // // A client-side navigation re-renders the page from __PYLON_DATA__, so the // markup the server built for it is parsed and thrown away. Measured on a real // route, that was 16442 bytes of HTML to deliver a 374-byte payload. The nav // response carries the head metadata and the data, and nothing else. import { describe, expect, it } from "bun:test"; import { buildHydrationTail, isNavRequest } from "./ssr-runtime"; describe("isNavRequest", () => { it("recognizes the header the client sends", () => { expect(isNavRequest({ "x-pylon-nav": "1" })).toBe(true); }); it("tolerates surrounding whitespace", () => { expect(isNavRequest({ "x-pylon-nav": " 1 " })).toBe(true); }); it("treats a document load as a document load", () => { expect(isNavRequest({})).toBe(false); expect(isNavRequest(undefined)).toBe(false); expect(isNavRequest({ accept: "text/html" })).toBe(false); }); it("refuses any value other than 1", () => { // Fail closed: an unrecognized value serves the full page, which is // always correct, rather than a payload the caller can't use. expect(isNavRequest({ "x-pylon-nav": "0" })).toBe(false); expect(isNavRequest({ "x-pylon-nav": "true" })).toBe(false); expect(isNavRequest({ "x-pylon-nav": "" })).toBe(false); }); }); const TAIL_ARGS = { component: "app/dashboard/page", layouts: ["app/layout"], props: { url: "/dashboard", params: {}, auth: { user_id: "u_1" } }, ssrData: { "list:[\"Todo\"]": [{ id: "t1" }] }, manifestRoute: { file: "entry-a1.js", imports: ["chunks/s.js"], css: [] }, publicPrefix: "/_pylon/build/", manifestErr: null, }; describe("hydration tail, dataOnly", () => { it("carries the same payload as a full page tail", () => { const data = (html: string) => html.match(/