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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ on this repository's Security tab.
backup (`internal/tenantbackup`) and the Doctor (`internal/doctor`) are in the tree and tested in CI, but no open
issue extends them.
- **Vietnamese first, English on the demo path.** `?lang=en`, or a browser that lists English and no Vietnamese,
picks English. The English catalog holds 974 of the 6,830 keys in `nexus-web/lib/i18n`: the 421 the demo loop
renders ([#6](https://github.com/doxuta/nexus/issues/6) measured them), the sign-in page, the assistant panel's
keys and its cards, the shell's menus and a few neighbours; other screens fall back to Vietnamese.
picks English. The English catalog holds 1,012 of the 6,868 keys in `nexus-web/lib/i18n`: the 421 the demo loop
renders ([#6](https://github.com/doxuta/nexus/issues/6) measured them), the sign-in page, the landing page, the
assistant panel's keys and its cards, the shell's menus and a few neighbours; other screens fall back to Vietnamese.
Still Vietnamese in English mode:
- in the assistant: the words of a changed path on an update card, and the approval, work-queue and sample-data
summary lines (`lib/aiBuilder.ts`);
Expand Down
7 changes: 4 additions & 3 deletions nexus-web/app/(marketing)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { Landing } from "@/components/screens/Landing";
// — không asset bịa). metadataBase resolve URL tương đối; set NEXT_PUBLIC_SITE_URL ở môi
// trường deploy (fallback localhost chỉ để build/dev không cảnh báo thiếu base).
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000";
const TITLE = "Nexus — Nền tảng metadata-driven của Nexus";
const TITLE = "Nexus: nền tảng ứng dụng nghiệp vụ dành cho agent";
// Metadata is rendered on the server, which renders Vietnamese (the default language; see Landing.tsx).
const DESCRIPTION =
"Nhà máy nội bộ Nexus dựng ứng dụng nghiệp vụ (CRM, LMS, Ticketing…) từ metadata — 90% engine, 10% custom.";
"Agent không viết code ứng dụng: nó sửa một mô hình có kiểu, có phiên bản, có phân quyền. Người duyệt từng thay đổi, xuất bản và quay lại được.";
const OG_IMAGE = {
url: "/landing/og.png",
width: 1200,
height: 630,
alt: "Giao diện Nexus — ứng dụng CRM với danh sách cơ hội bán hàng",
alt: "Giao diện Nexus: ứng dụng CRM với danh sách cơ hội bán hàng",
};

export const metadata: Metadata = {
Expand Down
84 changes: 84 additions & 0 deletions nexus-web/components/screens/Landing.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Landing "/" (issue #8): the agent-native copy, in the reader's language, hydrated without a mismatch (React #418).
import { afterEach, describe, expect, it, vi } from "vitest";
import { act } from "react";
import { render, screen } from "@testing-library/react";
import { renderToString } from "react-dom/server";
import { hydrateRoot } from "react-dom/client";
import viCatalog from "@/lib/i18n/vi";
import enCatalog from "@/lib/i18n/en";
import { Landing } from "./Landing";

vi.mock("next/navigation", () => ({ useRouter: () => ({ replace: vi.fn() }) }));
// next/image needs Next's loader; the test only reads the alt text.
// eslint-disable-next-line @next/next/no-img-element
vi.mock("next/image", () => ({ default: ({ alt }: { alt: string }) => <img alt={alt} /> }));

const prefer = (locale: "vi" | "en") => localStorage.setItem("nexus.prefs.v1", JSON.stringify({ locale }));
const landingKeys = Object.keys(viCatalog).filter((k) => k.startsWith("landing.")) as (keyof typeof viCatalog)[];
const en = enCatalog as Record<string, string>;

afterEach(() => localStorage.clear());

describe("Landing", () => {
it("renders the Vietnamese copy by default, with the demo, repo, README and write-up links", () => {
render(<Landing />);
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe(viCatalog["landing.hero.title"]);
const hrefs = screen.getAllByRole("link").map((a) => a.getAttribute("href"));
expect(hrefs).toEqual(expect.arrayContaining([
"/login",
"https://github.com/doxuta/nexus",
"https://github.com/doxuta/nexus#readme",
"https://github.com/doxuta/nexus/blob/main/docs/writeup/turning-the-lights-back-on.md",
]));
});

it("renders English for a reader who chose English", () => {
prefer("en");
render(<Landing />);
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe(en["landing.hero.title"]);
expect(screen.getByText(en["landing.diff.measured.title"])).toBeTruthy();
});

// The three ways a reader gets English (lib/i18n getLocale): a saved preference, ?lang=en, an English browser.
it.each([
["a saved preference", () => prefer("en")],
["?lang=en", () => window.history.replaceState(null, "", "/?lang=en")],
["an English browser", () => vi.spyOn(navigator, "languages", "get").mockReturnValue(["en-US", "en"])],
])("hydrates the server's Vietnamese without a mismatch, then switches to English for %s", async (_, englishReader) => {
// The server knows nothing about the reader: it renders Vietnamese.
const html = renderToString(<Landing />);
expect(html).toContain(viCatalog["landing.hero.title"]);
englishReader();

const container = document.createElement("div");
container.innerHTML = html;
document.body.appendChild(container);
const recoverable: unknown[] = [];
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
await act(async () => {
hydrateRoot(container, <Landing />, { onRecoverableError: (e) => recoverable.push(e) });
});
const logged = consoleError.mock.calls.map((c) => String(c[0]));
consoleError.mockRestore();

expect(recoverable).toEqual([]);
expect(logged.filter((m) => /hydrat|did not match|#418/i.test(m))).toEqual([]);
expect(container.querySelector("h1")?.textContent).toBe(en["landing.hero.title"]);
container.remove();
window.history.replaceState(null, "", "/");
vi.restoreAllMocks();
});

it("every landing string has English", () => {
expect(landingKeys.length).toBeGreaterThan(30);
expect(landingKeys.filter((k) => !en[k])).toEqual([]);
});

// Verifier round 1 (#64): isolation is "a convention plus tests" (ADR 0005), so no "safe by construction"; no
// unmeasured number.
it("the copy drops the internal-factory framing, claims nothing the README does not, and has no em dash", () => {
const framing = /nội bộ|nhà máy|bàn giao|factory|handover|DOTB|90\/10|—|by construction|theo cấu tạo|2[.,]000/i;
const values = landingKeys.flatMap((k) => [viCatalog[k], en[k]]);
expect(values.filter((v) => framing.test(v))).toEqual([]);
});
});
Loading
Loading