feat: complete TASK-WP0-02 contract baseline

This commit is contained in:
suyx
2026-07-27 17:49:24 +08:00
parent ae20eaf01f
commit dbe3e73b91
28 changed files with 2540 additions and 23 deletions
+11
View File
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>WP0-02 event sync fixture</title>
</head>
<body>
<main id="status">starting</main>
<script type="module" src="/tests/e2e/fixtures/event-sync.ts"></script>
</body>
</html>
+37
View File
@@ -0,0 +1,37 @@
import { connectEventSource, createEventSyncController } from "../../../apps/web/src/event-sync.js";
interface TimelineEntry {
action: string;
detail?: string;
}
declare global {
interface Window {
wp0EventFixture: {
timeline: TimelineEntry[];
};
}
}
const timeline: TimelineEntry[] = [];
const request = async (url: string, action: string, detail?: string) => {
timeline.push({ action, ...(detail ? { detail } : {}) });
const response = await fetch(url);
if (!response.ok) throw new Error(`${action} failed`);
await response.json();
};
const controller = createEventSyncController({
bootstrap: () => request("/api/v1/bootstrap", "bootstrap"),
refetchEntity: (entityRef) =>
request(`/__test/entity?ref=${encodeURIComponent(entityRef)}`, "refetch_entity", entityRef),
refetchModels: (input) =>
request("/__test/models", "refetch_models", input.reason),
});
const source = connectEventSource("/api/v1/events", controller);
source.addEventListener("open", () => {
timeline.push({ action: "connected" });
document.getElementById("status")!.textContent = "connected";
});
window.wp0EventFixture = { timeline };