| 1 | import { spawnSync } from "node:child_process"; |
| 2 | import { readFileSync } from "node:fs"; |
| 3 | import { join } from "node:path"; |
| 4 | import { fileURLToPath } from "node:url"; |
| 5 | import { describe, expect, it } from "vitest"; |
| 6 | import { getChrome, getDocsGuide, getHome } from "./dictionaries"; |
| 7 | |
| 8 | const webRoot = fileURLToPath(new URL("../..", import.meta.url)); |
| 9 | |
| 10 | function runGtSite(command: string, extraEnv: Record<string, string> = {}) { |
| 11 | return spawnSync(process.execPath, [join(webRoot, "scripts", "gt-site.mjs"), command], { |
| 12 | cwd: webRoot, |
| 13 | encoding: "utf8", |
| 14 | env: { |
| 15 | ...process.env, |
| 16 | GT_API_KEY: "", |
| 17 | GT_PROJECT_ID: "", |
| 18 | ...extraEnv, |
| 19 | }, |
| 20 | }); |
| 21 | } |
| 22 | |
| 23 | describe("website GT catalog pipeline", () => { |
| 24 | // `check` spawns node and transpiles every dictionary stem through the |
| 25 | // TypeScript compiler; with the per-page stems that now exceeds vitest's |
| 26 | // default 5 s on a loaded host, so give the subprocess a real budget. |
| 27 | it("keeps local catalogs in sync with the dictionary runtime", { timeout: 30_000 }, () => { |
| 28 | const check = runGtSite("check"); |
| 29 | expect(check.status, check.stderr || check.stdout).toBe(0); |
| 30 | expect(check.stdout).toContain("TUI packs untouched"); |
| 31 | |
| 32 | const zh = JSON.parse(readFileSync(join(webRoot, "gt-catalog", "zh.json"), "utf8")); |
| 33 | expect(zh.chrome.navDocs).toBe(getChrome("zh").navDocs); |
| 34 | expect(zh.home.heroTitle).toBe(getHome("zh").heroTitle); |
| 35 | expect(zh["docs-guide"].overviewTitle).toBe(getDocsGuide("zh").overviewTitle); |
| 36 | |
| 37 | const config = readFileSync(join(webRoot, "gt.config.json"), "utf8"); |
| 38 | expect(config).toContain("gt-catalog/[locale].json"); |
| 39 | expect(config).not.toContain("crates/tui"); |
| 40 | expect(config).not.toContain("prompts/text.rs"); |
| 41 | }); |
| 42 | |
| 43 | it("fails closed when translate is asked to call the GT API without BYOK env", () => { |
| 44 | const translate = runGtSite("translate"); |
| 45 | expect(translate.status).not.toBe(0); |
| 46 | expect(`${translate.stderr}${translate.stdout}`).toMatch(/fail-closed|GT_API_KEY/); |
| 47 | }); |
| 48 | }); |
| 49 |