Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/render-check-escapes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudhal/mcp-server": patch
---

render_page's long-line and input-label checks handle whitespace correctly again. A plain template literal ate the backslash, so the in-page script received `/s/` and `/s+/` instead of `/\s/` and `/\s+/`. As a result, long-line counted the letter "s" as blank and every real space and indentation run as text. input-label split `aria-labelledby` on the letter "s" and reported labelled inputs as unlabelled. The check parts are now `String.raw` templates.
8 changes: 8 additions & 0 deletions .changeset/testing-subpath-ships.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@cloudhal/storage": patch
"@cloudhal/analytics": patch
"@cloudhal/comments": patch
"@cloudhal/schedules": patch
---

The `./testing` subpath now ships. The published packages pointed `./testing` at `dist/src/testing.js` and `.d.ts`, but the build left those files out, so importing `@cloudhal/{storage,analytics,comments,schedules}/testing` failed with ERR_MODULE_NOT_FOUND. The suites run on your own vitest, 3 or later, which is an optional peer dependency. `@cloudhal/storage`'s Miniflare helpers also load your own `miniflare`, an optional peer of any version. The ranges are wide on purpose. When a direct dependency's optional peer does not match the copy in your project, npm stops with ERESOLVE, even if nothing imports `./testing`. No semver range matches the prerelease miniflare that wrangler currently brings in, so with a narrower range npm would install a second miniflare beside it.
1 change: 1 addition & 0 deletions .github/workflows/npm-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
pull_request:
paths:
- "scripts/build-packages.ts"
- "scripts/verify-exports.ts"
- "scripts/smoke-pack.ts"
- "packages/*/package.json"
- "packages/cli/src/assets.ts"
Expand Down
6 changes: 6 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
"max": 4
}
}
},
"suspicious": {
"noUselessEscapeInString": {
"level": "error",
"fix": "none"
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Everything here is **Worker-safe** (AGENTS.md rule 5): SQLite is reached only th
| `@cloudhal/analytics/rollup` | `runRollups`, `RollupReader`, `collectDailyRows`, `writeDailyRows` |
| `@cloudhal/analytics/reader` | `CompositeReader` (rollups for complete days, the rest live), `mergeResults` |
| `@cloudhal/analytics/service` | `AnalyticsService` (one per deployment: composite reads, settings with the salt and purge rules, rollups, status, CSV export of rollups), `presetRange`, `rangeFromParams`, `parseFilterParam`, `ANALYTICS_OFF` |
| `@cloudhal/analytics/testing` | conformance, bot-traffic, state and rollup suites; `FIXTURE_EVENTS`, `CONFORMANCE_CASES` |
| `@cloudhal/analytics/testing` | conformance, bot-traffic, state and rollup suites; `FIXTURE_EVENTS`, `CONFORMANCE_CASES` (vitest 3 or later, an optional peer) |
| `@cloudhal/analytics/client` | the browser sources (`pageview.browser.js`, `vitals.browser.js` with `web-vitals`) and their names; build input for the `cloudhal()` integration, which ships them as `/_cloudhal/p.<hash>.js` (≤ `PAGEVIEW_GZIP_BUDGET`, 1 KB gzipped) and `/_cloudhal/v.<hash>.js`. Node only (build time) |

The site side (`POST /__cloudhal/e`, the script tag, render events) lives in `@cloudhal/astro-renderer` (`SiteAnalytics` in `./analytics`, used by the Site Worker entry and the `cloudhal dev` middleware).
Expand Down
8 changes: 8 additions & 0 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
"@cloudhal/storage": "workspace:*",
"web-vitals": "catalog:"
},
"peerDependencies": {
"vitest": ">=3.0.0"
},
"peerDependenciesMeta": {
"vitest": {
"optional": true
}
},
"devDependencies": {
"@cloudflare/workers-types": "catalog:",
"@types/better-sqlite3": "catalog:",
Expand Down
54 changes: 53 additions & 1 deletion packages/cli/test/packaging.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/** What makes the published packages installable (ADR-0013). */
import { readFile, realpath } from "node:fs/promises";
import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import {
exportedSources,
PACKAGES,
publishConfigFor,
publishExports,
rewriteSpecifiers,
shipsFile,
} from "../../../scripts/build-packages.ts";
import { verifyPublishTargets } from "../../../scripts/verify-exports.ts";
import {
assetDir,
materializeDependencies,
Expand Down Expand Up @@ -75,6 +79,54 @@ describe("build: specifiers and exports", () => {
expect(pkg.private, name).toBeUndefined();
}
});

it("ships every source a package exports; tests and unexported testing.ts stay out", async () => {
for (const name of PACKAGES) {
const pkg = JSON.parse(
await readFile(path.join(ROOT, "packages", name, "package.json"), "utf8"),
);
const exported = exportedSources(pkg);
for (const rel of exported) {
if (rel.includes("*") || !/\.tsx?$/.test(rel)) continue;
expect(shipsFile(name, rel, exported), `${name}/${rel}`).toBe(true);
}
}
expect(shipsFile("core-ts", "src/testing.ts", new Set())).toBe(false);
expect(shipsFile("storage", "src/a.test.ts", new Set(["src/a.test.ts"]))).toBe(false);
expect(shipsFile("core-ts", "scripts/gen-icons.ts", new Set(["scripts/gen-icons.ts"]))).toBe(
false,
);
});

it("reports published exports/bin targets outside files or missing from dist", async () => {
const dir = await mkdtemp(path.join(os.tmpdir(), "cloudhal-exports-"));
try {
await mkdir(path.join(dir, "dist/src/c"), { recursive: true });
for (const file of ["dist/src/index.js", "dist/src/index.d.ts", "dist/src/c/a.js"])
await writeFile(path.join(dir, file), "");
const pkg = {
name: "fixture",
files: ["dist"],
publishConfig: {
exports: {
".": { types: "./dist/src/index.d.ts", default: "./dist/src/index.js" },
"./testing": { types: "./dist/src/testing.d.ts", default: "./dist/src/testing.js" },
"./c/*": "./dist/src/c/*",
"./schemas/*": "./schemas/*",
},
bin: { y: "./dist/bin/y.js" },
},
};
expect(await verifyPublishTargets(dir, pkg)).toEqual([
"fixture: ./testing (types) → ./dist/src/testing.d.ts: missing",
"fixture: ./testing (default) → ./dist/src/testing.js: missing",
"fixture: ./schemas/* → ./schemas/*: outside files",
"fixture: bin (y) → ./dist/bin/y.js: missing",
]);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
});

describe("starter dependencies outside the monorepo", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/render-chrome-text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ${linkRule}</style></head><body><main><h1>Post</h1><div class="ch-richtext"><p>R
dir ??= await mkdtemp(path.join(os.tmpdir(), "cloudhal-render-test-"));
// A monospace font: every character is as wide as the next, so a column's measure is exact.
const para = (chars: number) =>
`<p>${"abcd "
`<p>${"miss "
.repeat(Math.ceil(chars / 5))
.slice(0, chars)
.trim()}</p>`;
Expand Down
8 changes: 8 additions & 0 deletions packages/comments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
"@cloudhal/core-ts": "workspace:*",
"@cloudhal/storage": "workspace:*"
},
"peerDependencies": {
"vitest": ">=3.0.0"
},
"peerDependenciesMeta": {
"vitest": {
"optional": true
}
},
"devDependencies": {
"@cloudflare/workers-types": "catalog:",
"@types/better-sqlite3": "catalog:",
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/src/render/checks/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* In-page checks, part of `RENDER_CHECK_SCRIPT`: carousel-label / -lcp / -focus / -autoplay, image-fit, overlay-open; ends at the top of the page.
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
*/
export const COMPONENT_CHECKS = ` // A static preview runs no scripts (its CSP), so checks of what a module does wait for the site.
export const COMPONENT_CHECKS = String.raw` // A static preview runs no scripts (its CSP), so checks of what a module does wait for the site.
const staticPreview = !!document.querySelector('meta[name="generator"][content="Cloudhal preview"]');
// carousel-label and carousel-lcp: named carousels and slides; a hero's first slide not lazy.
for (const c of document.querySelectorAll('[aria-roledescription="carousel"], [aria-roledescription="kaydırmalı alan"]')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/mcp-server/src/render/checks/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* In-page checks, part of `RENDER_CHECK_SCRIPT`: empty-section, tap-target, input-label, chart-empty, long-line.
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
*/
export const CONTENT_CHECKS = ` // empty-section
export const CONTENT_CHECKS = String.raw` // empty-section
for (const s of document.querySelectorAll("[data-section-id]")) {
if (getComputedStyle(s).display === "none") continue;
const text = (s.innerText || "").trim();
Expand Down Expand Up @@ -41,7 +41,7 @@ export const CONTENT_CHECKS = ` // empty-section
if (!visible(el) && !(el.type === "radio" || el.type === "checkbox")) continue;
const named = [...(el.labels || [])].some((l) => (l.innerText || l.textContent || "").trim()) ||
(el.getAttribute("aria-label") || "").trim() ||
(el.getAttribute("aria-labelledby") || "").split(/s+/).some((id) => id && (document.getElementById(id)?.textContent || "").trim());
(el.getAttribute("aria-labelledby") || "").split(/\s+/).some((id) => id && (document.getElementById(id)?.textContent || "").trim());
if (!named) add("input-label", el, "no label a screen reader can announce");
}

Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/src/render/checks/contrast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* In-page checks, part of `RENDER_CHECK_SCRIPT`: contrast: text against what is painted beneath it, band by band.
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
*/
export const CONTRAST_CHECKS = ` // contrast: text against what is painted beneath it (elementsFromPoint), band by band.
export const CONTRAST_CHECKS = String.raw` // contrast: text against what is painted beneath it (elementsFromPoint), band by band.
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 1;
const g = canvas.getContext("2d", { willReadFrequently: true });
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/src/render/checks/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* In-page checks, part of `RENDER_CHECK_SCRIPT`: font-fallback.
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
*/
export const FONT_CHECKS = ` // font-fallback (RFC-0023 §2): text set in a web font whose stack has no metric-matched fallback
export const FONT_CHECKS = String.raw` // font-fallback (RFC-0023 §2): text set in a web font whose stack has no metric-matched fallback
// right after it (a face with size-adjust or ascent-override). Without one, the text is first
// drawn in a system font of another size and moves when the web font arrives.
if (document.fonts) {
Expand Down
4 changes: 4 additions & 0 deletions packages/mcp-server/src/render/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* prelude defines the helpers (`add`, `describe`, `visible`, `imgs`, `W`, `H`); the motion part
* scrolls the page once and defines `frame`, which the navigation and component parts use; the
* component part ends back at the top. Keep the order.
*
* Every part is a `String.raw` template, so a backslash in the page's code (`/\s/`) reaches the
* page as written: in a plain template `\s` arrives as `s` and `\b` as a control character, and
* Biome's useless-escape fix deleted the backslash (test/render-script.test.ts checks this).
*/
import { COMPONENT_CHECKS } from "./components.ts";
import { CONTENT_CHECKS } from "./content.ts";
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/src/render/checks/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* In-page checks, part of `RENDER_CHECK_SCRIPT`: overflow-x, img-alt / img-broken, heading-order.
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
*/
export const LAYOUT_CHECKS = ` // overflow-x: the outermost elements that stick out past the screen's right edge.
export const LAYOUT_CHECKS = String.raw` // overflow-x: the outermost elements that stick out past the screen's right edge.
const sw = document.documentElement.scrollWidth;
if (sw > W + 1) {
const clipped = (el) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/src/render/checks/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* In-page checks, part of `RENDER_CHECK_SCRIPT`: The reader's scroll pass, then motion-cls, reduced-motion, motion-budget, flash; defines `frame`.
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
*/
export const MOTION_CHECKS = ` // RFC-0024 §8: scroll through the page once, as a reader would, so reveals play, then measure.
export const MOTION_CHECKS = String.raw` // RFC-0024 §8: scroll through the page once, as a reader would, so reveals play, then measure.
let shift = 0;
let po;
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/src/render/checks/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* In-page checks, part of `RENDER_CHECK_SCRIPT`: skip-link, landmarks, header-contrast, focus-obscured.
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
*/
export const NAVIGATION_CHECKS = ` // skip-link: the first focusable element is a link to the main content (or inside it).
export const NAVIGATION_CHECKS = String.raw` // skip-link: the first focusable element is a link to the main content (or inside it).
const shown = (e) => e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden";
const focusables = [...document.querySelectorAll('a[href],button,input,select,textarea,summary,[tabindex]:not([tabindex="-1"])')]
.filter((e) => !e.disabled && !e.closest("[inert],dialog:not([open]),[popover]:not(:popover-open)") && shown(e));
Expand Down
6 changes: 3 additions & 3 deletions packages/mcp-server/src/render/checks/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { RENDER_CHECK_IDS } from "../types.ts";

export const PRELUDE = ` const W = document.documentElement.clientWidth || window.innerWidth, H = window.innerHeight, MAX = 5;
export const PRELUDE = String.raw` const W = document.documentElement.clientWidth || window.innerWidth, H = window.innerHeight, MAX = 5;
const ids = ${JSON.stringify(RENDER_CHECK_IDS)};
const out = Object.fromEntries(ids.map((id) => [id, { id, count: 0, examples: [] }]));
const clip = (s, n) => (s.length > n ? s.slice(0, n - 1) + "…" : s);
Expand All @@ -22,9 +22,9 @@ export const PRELUDE = ` const W = document.documentElement.clientWidth || wind
let tag = el.tagName.toLowerCase();
if (el.id) tag += "#" + el.id;
else if (typeof el.className === "string" && el.className.trim())
tag += "." + el.className.trim().split(/\\s+/).slice(0, 2).join(".");
tag += "." + el.className.trim().split(/\s+/).slice(0, 2).join(".");
parts.push(tag);
const text = ((el.innerText || "").trim() || el.getAttribute("alt") || el.getAttribute("src") || "").replace(/\\s+/g, " ");
const text = ((el.innerText || "").trim() || el.getAttribute("alt") || el.getAttribute("src") || "").replace(/\s+/g, " ");
if (text) parts.push(JSON.stringify(clip(text, 48)));
return parts.join(" ");
};
Expand Down
4 changes: 2 additions & 2 deletions packages/mcp-server/src/render/checks/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* keeps the Content-Security-Policy violations the page raises while it loads, which the
* `script-blocked` check reads. Report-only ones (`cloudhal dev`) are kept too.
*/
export const CSP_LISTENER = `(() => {
export const CSP_LISTENER = String.raw`(() => {
const seen = (window.__chCsp = []);
window.addEventListener("securitypolicyviolation", (e) => {
if (seen.length < 50)
seen.push({ directive: e.effectiveDirective || e.violatedDirective || "", blocked: e.blockedURI || "", sample: e.sample || "", line: e.lineNumber || 0, report: e.disposition === "report", el: e.target instanceof Element ? e.target : null });
}, true);
})();`;

export const SCRIPT_CHECKS = ` // surface-broken: a body surface the preview could not draw (RFC-0020 §5), or a component in one
export const SCRIPT_CHECKS = String.raw` // surface-broken: a body surface the preview could not draw (RFC-0020 §5), or a component in one
// with an unknown block type or props that do not fit it. Theme blocks the preview leaves to the
// site are fine.
for (const el of document.querySelectorAll(".ch-surface-problem")) {
Expand Down
Loading
Loading