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:
2026-11-08 14:41:19 +01:00
parent 80070762e7
commit 9af29ffdb9
12 changed files with 28 additions and 26 deletions
+3 -3
View File
@@ -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.
+1
View File
@@ -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
View File
@@ -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
View File
@@ -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.
+1 -1
View File
@@ -59,7 +59,7 @@ test("buildPaginationModel maps a page to the pagination partial's model, every
});
});
test("buildPaginationModel disables the step off either end, keeps ellipses, and omits what wasn't asked for", () => {
test("buildPaginationModel leaves prev/next without an href on the first/last page, keeps ellipses, and omits what wasn't asked for", () => {
const m = buildPaginationModel(paginate(100, 1, 10), (n) => `/l?page=${n}`);
assert.deepEqual(m.prev, {});
assert.deepEqual(m.pages[m.pages.length - 2], { ellipsis: true });
+6 -5
View File
@@ -1,7 +1,7 @@
// paginate: pagination math → a PageModel. Pure and URL-free (README signature
// `paginate(total, page, pageSize)`); buildPaginationModel then maps it, with the caller's
// page → href function, to the model pagination.ejs renders. Inputs are clamped/guarded so it never
// produces a broken model: page is pinned to [1, pageCount], total/pageSize coerced to sane integers.
// `paginate(total, page, pageSize)`); buildPaginationModel maps it to pagination.ejs's model. Inputs
// are clamped/guarded so it never produces a broken model: page is pinned to [1, pageCount],
// total/pageSize coerced to sane integers.
export interface PageItem {
current: boolean;
@@ -47,8 +47,9 @@ export function paginate(total: number, page: number, pageSize: number, options:
export interface PaginationModelOptions {
label?: string; // the nav's aria-label; the partial defaults it
pageParam?: string; // as parseListQuery's options (default "page")
pageSizeParam?: string; // as parseListQuery's options (default "pageSize")
// The two query params, named as parseListQuery was given them; pageSizeParam names the rows field.
pageParam?: string; // default "page"
pageSizeParam?: string; // default "pageSize"
pageSizes?: number[]; // the rows-per-page choices; omitted ⇒ no rows-per-page form
}