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
22 changes: 22 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,25 @@ After the workflow has run, the repository owner should add these exact status c
Select GitHub Actions as their source. Do not make the negative-control failure itself a required
failed check: its job succeeds only when it observes the specific expected regression. Workflow
changes do not change branch protection automatically.

### Isolated-process invalidation tests

The concurrency suite forks real Node processes with separate cache runtimes and controls render
completion through IPC. Memory runs deliver invalidations to each process explicitly; Redis runs
write the invalidation once and require peer reads to observe it. The suite covers full and postponed
page shells, build output, local and remote data, request timestamps, implicit path tags, delayed
invalidation and lifetime boundaries. These are handler-contract tests, not browser tests.

```bash
CACHE_TEST_REDIS_URL=redis://localhost:6390 \
pnpm --filter @mrjasonroy/cache-components-cache-handler exec vitest run \
--no-file-parallelism --maxWorkers=1 \
src/integration/concurrency.redis.test.ts src/data-cache/expiry-boundary.test.ts
```

Without `CACHE_TEST_REDIS_URL`, only the memory lane runs. The existing Redis integration CI matrix
runs both lanes. Six model tests exercise 180 deterministic seeds each (1,080 scenarios), varying
render start/completion order and invalidation placement across two processes. A failed assertion
includes the seed, handler, lane, process and operation trace. Reads allow the documented 100 ms local
tag-sync interval to elapse and assert the first result, without polling until fresh. Child processes,
temporary compiled modules, build fixtures and the test's uniquely prefixed Redis keys are cleaned up.
4 changes: 2 additions & 2 deletions implementation/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
> or "the 16.5 path" is the legacy `createCacheHandler` data stack and the `redis: RedisOptions`
> form. The headings of DEC-1 and DEC-2 keep the numbers those releases had.

## DEC-17: CI runs on `ubuntu-24.04`, not `ubuntu-latest`
## DEC-18: CI runs on `ubuntu-24.04`, not `ubuntu-latest`

On 31 Oct 2026 `ubuntu-latest` moved to Ubuntu 26.04, and the locked Playwright (1.56.1) refuses
to install Chromium there (`Playwright does not support chromium on ubuntu26.04-x64`). The daily
Expand All @@ -16,7 +16,7 @@ no version bump. Every job now names `ubuntu-24.04`, so a runner image change ca
the release loop unannounced. Move to a newer image deliberately, with a Playwright that supports
it, in one PR that CI proves.

## DEC-16: Opt-in Redis storage for plain `"use cache"`
## DEC-17: Opt-in Redis storage for plain `"use cache"`

Restore `withCache`'s `useCache: "memory" | "redis"` with `"memory"` as the default. This
supersedes DEC-13's removal of that option only. Applications can share existing plain cache
Expand Down
62 changes: 62 additions & 0 deletions packages/cache-handler/src/data-cache/expiry-boundary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { asClient, resetCacheState } from "../testing/env.js";
import { FakeRedis } from "../testing/fake-redis.js";
import { createRemoteCacheHandler } from "./remote.js";
import type { DataCacheEntry } from "./types.js";

describe("remote data entry render-start expiry", () => {
beforeEach(async () => {
await resetCacheState();
vi.useFakeTimers({ toFake: ["Date"] });
vi.setSystemTime(1_800_000_000_000);
});

afterEach(async () => {
vi.useRealTimers();
vi.restoreAllMocks();
await resetCacheState();
});

describe.each(["memory", "redis", "outage"] as const)("%s", (lane) => {
test("never serves past expire when rendering finishes between whole seconds", async () => {
const redis = new FakeRedis();
const handler = createRemoteCacheHandler(
lane === "memory" ? {} : { client: asClient(redis) },
);
if (lane === "outage") {
vi.spyOn(console, "error").mockImplementation(() => {});
vi.spyOn(console, "warn").mockImplementation(() => {});
// Establish the connection before taking it down mid-render.
await handler.get("entry", []);
}
const started = Date.now();
let finish!: (entry: DataCacheEntry) => void;
const writing = handler.set(
"entry",
new Promise<DataCacheEntry>((resolve) => {
finish = resolve;
}),
);
vi.setSystemTime(started + 250);
if (lane === "outage") redis.goDown();
finish({
value: new Response("rendered before expiry").body as ReadableStream<Uint8Array>,
timestamp: started,
tags: [],
stale: 0,
revalidate: 1,
expire: 2,
});
await writing;

// SWR remains allowed after revalidate, but only until the render's hard deadline.
vi.setSystemTime(started + 1_999);
const stale = await handler.get("entry", []);
expect(stale?.timestamp).toBe(started);
expect(await new Response(stale?.value).text()).toBe("rendered before expiry");

vi.setSystemTime(started + 2_001);
expect(await handler.get("entry", [])).toBeUndefined();
});
});
});
Loading
Loading