Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

test: provide module inventory in browser audit fixtures

Bingxi Zhao (Frank)766e626d1f5c
diff --git a/web/tests/e2e/book-reader-sequential.audit.ts b/web/tests/e2e/book-reader-sequential.audit.ts
index d0a335485..4a302e940 100644
--- a/web/tests/e2e/book-reader-sequential.audit.ts
+++ b/web/tests/e2e/book-reader-sequential.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { emptyLearningIndex } from "./fixtures/learning-index";
import { expect, test } from "@playwright/test";
@@ -100,6 +101,7 @@ test("book arrows read the current chapter before turning chapters", async ({
? new URL(requestUrl.pathname + requestUrl.search, BASE_URL)
: requestUrl;
const { pathname } = url;
+ if (pathname === "/api/modules") return route.fulfill({ json: sourceModuleInventory });
if (pathname === "/api/dashboard/learning-index") {
return route.fulfill(json(emptyLearningIndex));
}
diff --git a/web/tests/e2e/compliance-and-ux.audit.ts b/web/tests/e2e/compliance-and-ux.audit.ts
index 65044362c..737595273 100644
--- a/web/tests/e2e/compliance-and-ux.audit.ts
+++ b/web/tests/e2e/compliance-and-ux.audit.ts
@@ -1,5 +1,10 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { test, expect } from "@playwright/test";
+test.beforeEach(async ({ page }) => {
+ await page.route(url => url.pathname === "/api/modules", route => route.fulfill({ json: sourceModuleInventory }));
+});
+
// Minimal compliance and UX checks without external deps (axe-core)
// Focus on semantic landmarks, headings, alt text, link names, and basic error messaging.
diff --git a/web/tests/e2e/fixtures/modules.ts b/web/tests/e2e/fixtures/modules.ts
new file mode 100644
index 000000000..5c64fcc02
--- /dev/null
+++ b/web/tests/e2e/fixtures/modules.ts
@@ -0,0 +1,21 @@
+import { readFileSync, readdirSync } from "node:fs";
+import { resolve } from "node:path";
+
+import type { ModuleStatus } from "../../../hooks/useModules";
+
+// Model the source checkout's installed modules from the authoritative catalog.
+// Browser-only audits have no backend to answer this deployment inventory API.
+const manifests = resolve(__dirname, "../../../../deeptutor/modules/manifests");
+export const sourceModuleInventory: { modules: ModuleStatus[] } = {
+ modules: readdirSync(manifests).filter(name => name.endsWith(".json")).map(name => {
+ const manifest = JSON.parse(readFileSync(resolve(manifests, name), "utf8"));
+ return {
+ id: manifest.id,
+ installed: true,
+ enabled: true,
+ ready: true,
+ navigation: manifest.navigation,
+ issues: [],
+ };
+ }),
+};
diff --git a/web/tests/e2e/learning-progress.audit.ts b/web/tests/e2e/learning-progress.audit.ts
index 0b0a5a3f4..006e483f5 100644
--- a/web/tests/e2e/learning-progress.audit.ts
+++ b/web/tests/e2e/learning-progress.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { expect, test } from "@playwright/test";
test("learning progress uses the account reading records contract", async ({
@@ -8,6 +9,7 @@ test("learning progress uses the account reading records contract", async ({
await page.route("**/api/**", async (route) => {
const request = route.request();
const path = new URL(request.url()).pathname;
+ if (path === "/api/modules") return route.fulfill({ json: sourceModuleInventory });
requestedPaths.push(path);
const json = (payload: unknown, status = 200) =>
route.fulfill({ status, json: payload });
diff --git a/web/tests/e2e/modules.audit.ts b/web/tests/e2e/modules.audit.ts
new file mode 100644
index 000000000..4bb3dd32f
--- /dev/null
+++ b/web/tests/e2e/modules.audit.ts
@@ -0,0 +1,34 @@
+import { expect, test } from "@playwright/test";
+
+import { sourceModuleInventory } from "./fixtures/modules";
+
+for (const unavailableInventory of [false, true]) {
+ test(`module gate blocks disabled reading${unavailableInventory ? " after inventory retry" : ""}`, async ({ page }) => {
+ let failInventory = unavailableInventory;
+ await page.route("**/api/**", async route => {
+ const path = new URL(route.request().url()).pathname;
+ if (path === "/api/modules") {
+ if (failInventory) return route.fulfill({ status: 503, json: {} });
+ return route.fulfill({ json: {
+ modules: sourceModuleInventory.modules.map(module => module.id === "reading"
+ ? { ...module, enabled: false }
+ : module),
+ } });
+ }
+ if (path === "/api/auth/status") {
+ return route.fulfill({ json: { enabled: false, authenticated: true, is_admin: true } });
+ }
+ if (path === "/api/settings/ui") return route.fulfill({ json: { language: "en" } });
+ return route.fulfill({ status: 404, json: {} });
+ });
+ await page.goto("/learning/reading", { waitUntil: "domcontentloaded" });
+ if (unavailableInventory) {
+ await expect(page.getByRole("main").getByRole("button", { name: "Retry", exact: true })).toBeVisible();
+ await expect(page.getByText("This module is not installed or is disabled.", { exact: true })).toHaveCount(0);
+ failInventory = false;
+ await page.getByRole("main").getByRole("button", { name: "Retry", exact: true }).click();
+ }
+ await expect(page.getByText("This module is not installed or is disabled.", { exact: true })).toBeVisible();
+ await expect(page.getByRole("link", { name: "Immersive Reading", exact: true })).toHaveCount(0);
+ });
+}
diff --git a/web/tests/e2e/pdf-reading-resize.audit.ts b/web/tests/e2e/pdf-reading-resize.audit.ts
index c2d8af37c..a40fbf62b 100644
--- a/web/tests/e2e/pdf-reading-resize.audit.ts
+++ b/web/tests/e2e/pdf-reading-resize.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { emptyLearningIndex } from "./fixtures/learning-index";
import { expect, test, type Locator } from "@playwright/test";
import { jsPDF } from "jspdf";
@@ -51,6 +52,7 @@ const material = {
test.beforeEach(async ({ page }) => {
await page.route("**/api/**", async (route) => {
const path = new URL(route.request().url()).pathname;
+ if (path === "/api/modules") return route.fulfill({ json: sourceModuleInventory });
const json = (payload: unknown) => route.fulfill({ json: payload });
if (path === "/api/task-board") return json(emptyTaskBoard);
if (path === "/api/auth/status") {
diff --git a/web/tests/e2e/reading-citation-material.audit.ts b/web/tests/e2e/reading-citation-material.audit.ts
index a6def5999..1af2aac50 100644
--- a/web/tests/e2e/reading-citation-material.audit.ts
+++ b/web/tests/e2e/reading-citation-material.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { emptyLearningIndex } from "./fixtures/learning-index";
import { readFile } from "node:fs/promises";
import { expect, test } from "@playwright/test";
@@ -85,6 +86,7 @@ const workspace = {
test.beforeEach(async ({ page }) => {
await page.route("**/api/**", async (route) => {
const path = new URL(route.request().url()).pathname;
+ if (path === "/api/modules") return route.fulfill({ json: sourceModuleInventory });
const json = (payload: unknown, status = 200) =>
route.fulfill({ status, json: payload });
diff --git a/web/tests/e2e/reading-location-history.audit.ts b/web/tests/e2e/reading-location-history.audit.ts
index e85546a28..733e00c88 100644
--- a/web/tests/e2e/reading-location-history.audit.ts
+++ b/web/tests/e2e/reading-location-history.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { emptyLearningIndex } from "./fixtures/learning-index";
import { expect, test } from "@playwright/test";
import { emptyTaskBoard } from "./fixtures/task-board";
@@ -106,6 +107,7 @@ test.beforeEach(async ({ page }) => {
let activeMaterialId = MATERIAL_A;
await page.route("**/api/**", async (route) => {
const path = new URL(route.request().url()).pathname;
+ if (path === "/api/modules") return route.fulfill({ json: sourceModuleInventory });
const json = (payload: unknown, status = 200) =>
route.fulfill({ status, json: payload });
diff --git a/web/tests/e2e/reading-w3c-annotations.audit.ts b/web/tests/e2e/reading-w3c-annotations.audit.ts
index c47cd0b1b..2aca51616 100644
--- a/web/tests/e2e/reading-w3c-annotations.audit.ts
+++ b/web/tests/e2e/reading-w3c-annotations.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { emptyLearningIndex } from "./fixtures/learning-index";
import { expect, test } from "@playwright/test";
import { emptyTaskBoard } from "./fixtures/task-board";
@@ -81,6 +82,7 @@ const annotation = {
test.beforeEach(async ({ page }) => {
await page.route("**/api/**", async (route) => {
const path = new URL(route.request().url()).pathname;
+ if (path === "/api/modules") return route.fulfill({ json: sourceModuleInventory });
const json = (payload: unknown, status = 200) =>
route.fulfill({ status, json: payload });
diff --git a/web/tests/e2e/release-ui-matrix.audit.ts b/web/tests/e2e/release-ui-matrix.audit.ts
index 909e5cbce..8c7cedc8c 100644
--- a/web/tests/e2e/release-ui-matrix.audit.ts
+++ b/web/tests/e2e/release-ui-matrix.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { expect, test } from "@playwright/test";
const BASE_URL = process.env.WEB_BASE_URL || "http://127.0.0.1:3300";
@@ -38,6 +39,7 @@ for (const theme of themes) {
},
{ selectedTheme: theme, selectedLanguage: language },
);
+ await context.route(url => url.pathname === "/api/modules", route => route.fulfill({ json: sourceModuleInventory }));
const page = await context.newPage();
for (const [surface, path] of surfaces) {
diff --git a/web/tests/e2e/settings-navigation.audit.ts b/web/tests/e2e/settings-navigation.audit.ts
index 6a9b5c195..e8ffca66c 100644
--- a/web/tests/e2e/settings-navigation.audit.ts
+++ b/web/tests/e2e/settings-navigation.audit.ts
@@ -1,3 +1,4 @@
+import { sourceModuleInventory } from "./fixtures/modules";
import { expect, test, type Page } from "@playwright/test";
// All writes are intercepted. Regression coverage must never change a developer's settings.
@@ -86,6 +87,7 @@ async function mockSettings(
await page.route("**/api/**", async (route) => {
const request = route.request();
const path = new URL(request.url()).pathname;
+ if (path === "/api/modules") return route.fulfill({ json: sourceModuleInventory });
const method = request.method();
const body = request.postDataJSON();
const write =