Answer stability round 1: 1 🔴, 4 🟡 (0 misread); assetHref in the test fakes, one shared buildContext option set, default pinned, upgrade note and AGENTS.md corrected
This commit is contained in:
+3
-3
@@ -268,9 +268,9 @@ export function createApp(options: AppOptions = {}): Server {
|
||||
|
||||
// Base context (no route params), for the built-in routes. Every plugin-owned render — a
|
||||
// landing slot, a hook short-circuit, a plugin route — gets `contextFor(id)` instead.
|
||||
const ctx = buildContext(req, res, { assetHref: assets.href, chrome, declaredPermissions: permissionCatalog, declaredSettings: settingsCatalog, user, ...i18nFor(), log: reqLog, verifyCsrf, ...(system ? { system } : {}) });
|
||||
const contextFor = (pluginId: string, params?: Record<string, string>): RequestContext =>
|
||||
buildContext(req, res, { assetHref: assets.href, chrome, declaredPermissions: permissionCatalog, declaredSettings: settingsCatalog, user, ...i18nFor(pluginId), log: reqLog, ...(params ? { params } : {}), verifyCsrf, ...(system ? { system } : {}) });
|
||||
const shared = { assetHref: assets.href, chrome, declaredPermissions: permissionCatalog, declaredSettings: settingsCatalog, log: reqLog, user, verifyCsrf, ...(system ? { system } : {}) };
|
||||
const ctx = buildContext(req, res, { ...shared, ...i18nFor() });
|
||||
const contextFor = (pluginId: string, params?: Record<string, string>): RequestContext => buildContext(req, res, { ...shared, ...i18nFor(pluginId), ...(params ? { params } : {}) });
|
||||
renderPage = viewsFor(ctx);
|
||||
|
||||
// Plugin onRequest hooks run before routing and may short-circuit the request.
|
||||
|
||||
@@ -25,6 +25,7 @@ test("buildContext parses the URL, exposes query, and defaults to an anonymous u
|
||||
assert.equal(ctx.user, null);
|
||||
assert.deepEqual(ctx.permissions, []);
|
||||
assert.deepEqual(ctx.params, {});
|
||||
assert.equal(ctx.assetHref("/public/x.css"), "/public/x.css");
|
||||
});
|
||||
|
||||
test("buildContext threads path params supplied by the router", () => {
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ export interface User {
|
||||
|
||||
export interface RequestContext {
|
||||
// A /public/ href with `?v=<content hash>`, so the browser caches the file for a year; any other
|
||||
// href, or one already carrying a query or fragment, comes back unchanged. The same function is
|
||||
// the `assetHref` view local, for hrefs a handler builds into `data`.
|
||||
// href, or one already carrying a query or fragment, comes back unchanged. Views get the same
|
||||
// function as the `assetHref` local; this one is for hrefs a handler builds into `data`.
|
||||
assetHref(href: string): string;
|
||||
// Page chrome (brand/global-nav/user/theme/csrf) a plugin view hands to partials/shell so its
|
||||
// page renders the native app shell; the host builds it per request (anonymous default otherwise).
|
||||
|
||||
+1
-2
@@ -50,8 +50,7 @@ export function routePublic(restPath: string, publicDir: string, pluginsDir: str
|
||||
return { dir: publicDir, subPath: restPath };
|
||||
}
|
||||
|
||||
// Caching: every /public/ href rendered through assetHref (the host's, and a plugin's through the view
|
||||
// local or ctx.assetHref) gets `?v=<hash of the file's content>`. A request whose `v` is the current
|
||||
// Caching: every /public/ href rendered through assetHref gets `?v=<hash of the file's content>`. A request whose `v` is the current
|
||||
// hash is cached for a year as immutable, so a repeat page view downloads no asset; a changed file gets
|
||||
// a new hash, and with it a new URL. Any other request — an unwrapped href, a stale `v` mid-deploy — is
|
||||
// cached for five minutes, then revalidated against the ETag (that same hash) or Last-Modified.
|
||||
|
||||
Reference in New Issue
Block a user