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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Format: [Keep a Changelog](https://keepachangelog.com/); versioning: [SemVer](ht
- Cloudinary asset index: tags and contextual metadata on each session's asset, synced from the Studio and read back with the Search API (Phase 19)

### Fixed
- `/search` (Find and Ask results) crashed with "Something went wrong" since the data saver release: `ResultCard` called a client hook without `"use client"`. Fixed, with a unit test that fails the build for any hook used outside a client file
- Phone header: Studio, data saver and the theme switch were off-screen below ~560 px. Header, Studio and /try now fit 360 px (Phase 23)

## [1.0.0] — 2026-10-03
Expand Down
3 changes: 3 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Against the **deployed** `APP_URL`: home → search a known phrase → result op
- `revision.spec.ts`: a wrong quiz answer appears under Weak spots with a revision reel and clears; study notes carry timestamp links and download as Markdown
- `mobile.spec.ts`: at 360 px the header's Studio, data saver and theme controls are on screen and no page scrolls sideways

### Client boundary guard
`tests/unit/client-boundary.test.ts` fails if any file under `src` calls a React or Pravaha hook without `"use client"`. A hook in a Server Component crashes the page at request time and neither `tsc` nor ESLint notices (it broke `/search` in production once). After every deploy, also run the smoke spec: `APP_URL=<url> npx playwright test tests/e2e/smoke.spec.ts`.

## AI Eval (`pnpm eval:ask`)

10 questions (7 answerable, 3 not) against the demo library; results recorded in `AI_EVALUATION.md`.
Expand Down
2 changes: 2 additions & 0 deletions src/components/ResultCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import Image from "next/image";
import Link from "next/link";

Expand Down
37 changes: 37 additions & 0 deletions tests/unit/client-boundary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";

// A React hook called from a Server Component crashes the page at request time, and neither the type checker
// nor the linter notices (the /search page broke in production this way when a hook was added to a component
// that had no "use client"). This guard fails the build instead: every file that calls a hook must be a client file.
const HOOK_CALL = /\buse(State|Effect|LayoutEffect|Ref|Memo|Callback|Reducer|SyncExternalStore|Router|Pathname|SearchParams|LiteUrl|DataSaver|SavedMoments|RecentQuestions|WatchProgress|WeakSpots)\s*\(/;

function files(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((e) => {
const path = join(dir, e.name);
return e.isDirectory() ? files(path) : /\.(ts|tsx)$/.test(e.name) ? [path] : [];
});
}

const code = (source: string) =>
source
.split("\n")
.filter((line) => !/^\s*(\/\/|\*|\/\*)/.test(line))
.join("\n");

describe("client boundary", () => {
const all = files(join(process.cwd(), "src"));

it("finds the source files", () => {
expect(all.length).toBeGreaterThan(50);
});

it("marks every file that calls a hook with \"use client\"", () => {
const offenders = all.filter((path) => {
const source = readFileSync(path, "utf8");
return HOOK_CALL.test(code(source)) && !/^\s*(["'])use client\1/.test(source);
});
expect(offenders.map((p) => p.replace(process.cwd(), ""))).toEqual([]);
});
});
Loading