From cea8f8f6e8f1e8b95442d52a91c4c69dcfd7fb0e Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Sun, 27 Sep 2026 23:54:56 +0200 Subject: [PATCH 1/3] build(platform): hash the config tree and other files the tests read The platform test task still read files outside its workspace that its Turbo hash did not cover: the shipped catalog (configs/platform/system), the builtin catalog the provisioning test seeds from (configs/platform/custom), the knowledge-db migrations ddl.test.ts applies, compose.yml, compose.dev.yml, the sandbox spawner config and the sandbox runtime build script. A PR that edited only one of them replayed the platform suite from the cache. The list comes from tracing every file the server and pii projects open during a full run. The test:ui and test:browser suites read nothing outside the workspace except workspace-package sources. A new guard asks `turbo --dry=json` whether every tracked file under each declared path is hashed, and that the workspace itself still is. The repo contract now names the guard, and records that sources of a workspace package the task depends on stay unhashed, because no test task depends on `^...`. --- .agents/repo.md | 11 +- .../tests/guards/turbo-inputs.guard.test.ts | 162 ++++++++++++++++++ services/platform/turbo.json | 8 +- 3 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 services/platform/tests/guards/turbo-inputs.guard.test.ts diff --git a/.agents/repo.md b/.agents/repo.md index 05377de268..8d4b20f819 100644 --- a/.agents/repo.md +++ b/.agents/repo.md @@ -110,9 +110,14 @@ beside the task; `--force` re-runs it locally. A task whose result depends on an declared inputs — test file ordering, wall-clock, a shared browser page — is not safely cacheable, and the fix is the determinism, not the cache. A test that reads a file outside its workspace declares that file in the workspace's `turbo.json` `test.inputs` (`$TURBO_EXTENDS$`, -`$TURBO_DEFAULT$`, then `$TURBO_ROOT$/`), as `services/platform/turbo.json` does for the -root `.env.example`, `knip.config.ts` and the tale-db init scripts; without it, an edit to that -file alone replays the cached verdict. +`$TURBO_DEFAULT$`, then `$TURBO_ROOT$/`); without it, an edit to that file alone replays +the cached verdict. `services/platform/turbo.json` declares what the platform's `test` task +reads (`configs/platform/`, the compose files, the tale-db init scripts and knowledge-db +migrations, among others), and `services/platform/tests/guards/turbo-inputs.guard.test.ts` asks +`turbo --dry=json` whether each of those paths is hashed; a suite that starts reading another +outside file adds it to both. The sources of a workspace package the task depends on +(`packages/*`) are a separate gap: no `test` task depends on `^…`, so an edit there alone +replays the consumers' cached verdicts too. ## Skills index diff --git a/services/platform/tests/guards/turbo-inputs.guard.test.ts b/services/platform/tests/guards/turbo-inputs.guard.test.ts new file mode 100644 index 0000000000..61b947b716 --- /dev/null +++ b/services/platform/tests/guards/turbo-inputs.guard.test.ts @@ -0,0 +1,162 @@ +// @vitest-environment node + +import { spawnSync } from 'node:child_process'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { beforeAll, describe, expect, it } from 'vitest'; +import { z } from 'zod'; + +import { findRepoSystemConfigRoot } from '../../lib/shared/config/system-root'; +import { ENSURE_SANDBOX_RUNTIME_SCRIPT } from '../../scripts/dev-sandbox-runtime'; + +/** + * Turbo keys the `test` task's cache on the files of this workspace, so a + * suite that reads a file outside `services/platform/` replays its last + * verdict when only that file changes — a PR that edits nothing but a + * shipped `connector.yml` would pass CI without the catalog tests running. + * `services/platform/turbo.json` lists every such file as a `$TURBO_ROOT$` + * input; this asks turbo itself (`--dry=json`) which files the task hashes, + * so an input list that drops one fails here instead of replaying green. + * + * A suite that starts reading another file outside the workspace adds it to + * `turbo.json` and to `OUTSIDE_READS`. The sources of the workspace packages + * the platform depends on (`@tale/ui`, `@tale/shared`, `@tale/e2e`) are not + * outside reads in this sense: turbo would need a `^` dependency to hash them, + * which `.agents/repo.md` records as a gap of its own. + */ + +const PLATFORM_ROOT = path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + '../..', +); +const REPO_ROOT = path.resolve(PLATFORM_ROOT, '../..'); + +function toRepoPath(absolute: string): string { + return path.relative(REPO_ROOT, absolute).split(path.sep).join('/'); +} + +/** Every repo path outside the workspace the `test` task reads, and who reads it. */ +const OUTSIDE_READS = [ + { + path: '.env.example', + readers: 'tests/guards/env-example-scope.guard.test.ts', + }, + { path: 'compose.yml', readers: 'scripts/dev-sandbox-runtime.test.ts' }, + { path: 'compose.dev.yml', readers: 'scripts/dev-secrets.test.ts' }, + { + path: 'configs/platform/custom', + readers: 'backend/core/provisioning/provision_default_automations.test.ts', + }, + { + path: 'configs/platform/system', + readers: + 'the shipped connector, model, provider, harness and PII catalog suites', + }, + { + path: 'knip.config.ts', + readers: 'tests/guards/frontend-entry-discovery.guard.test.ts', + }, + { + path: ENSURE_SANDBOX_RUNTIME_SCRIPT, + readers: 'scripts/dev-sandbox-runtime.test.ts', + }, + { + path: 'services/db/init-scripts', + readers: 'tests/guards/db-init-scripts.guard.test.ts', + }, + { + path: 'services/db/migrations/knowledge-db', + readers: 'backend/core/knowledge/ddl.test.ts', + }, + { + path: 'services/sandbox/src/config.ts', + readers: 'scripts/dev-sandbox-runtime.test.ts', + }, +]; + +/** The slice of `turbo run --dry=json` this guard reads. */ +const dryRunSchema = z.object({ + tasks: z.array( + z.object({ + taskId: z.string(), + directory: z.string(), + inputs: z.record(z.string(), z.string()), + }), + ), +}); + +function run(command: string, args: string[]): string { + const result = spawnSync(command, args, { + cwd: REPO_ROOT, + encoding: 'utf8', + maxBuffer: 64 * 1024 * 1024, + }); + if (result.error) throw result.error; + if (result.status !== 0) { + throw new Error( + `${command} ${args.join(' ')} exited ${result.status}: ${result.stderr}`, + ); + } + return result.stdout; +} + +/** Repo-relative files turbo hashes for `@tale/platform#test`. */ +function hashedByTest(): Set { + const stdout = run('bunx', [ + 'turbo', + 'run', + 'test', + '--filter=@tale/platform', + '--dry=json', + '--cache=local:,remote:', + ]); + const { tasks } = dryRunSchema.parse( + JSON.parse(stdout.slice(stdout.indexOf('{'))), + ); + const task = tasks.find(({ taskId }) => taskId === '@tale/platform#test'); + if (!task) throw new Error('turbo --dry=json listed no @tale/platform#test'); + return new Set( + Object.keys(task.inputs).map((file) => + toRepoPath(path.join(REPO_ROOT, task.directory, file)), + ), + ); +} + +/** The git-tracked files at `repoPath` — a file, or every file under a directory. */ +function trackedFiles(repoPath: string): string[] { + return run('git', ['ls-files', '-z', '--', repoPath]) + .split('\0') + .filter(Boolean); +} + +describe('@tale/platform#test turbo inputs', () => { + let hashed: Set; + + beforeAll(() => { + hashed = hashedByTest(); + }, 60_000); + + it('still hashes its own workspace', () => { + // `$TURBO_DEFAULT$` stays in the list, or the suite's own sources drop out. + expect(hashed.has('services/platform/package.json')).toBe(true); + }); + + it('declares the system catalog where its readers find it', () => { + const root = findRepoSystemConfigRoot(PLATFORM_ROOT); + expect(root && toRepoPath(root)).toBe('configs/platform/system'); + }); + + for (const { path: repoPath, readers } of OUTSIDE_READS) { + it(`hashes ${repoPath} (${readers})`, () => { + const files = trackedFiles(repoPath); + // A path that no longer exists means the reader moved: follow it. + expect(files.length, `${repoPath} tracks no file`).toBeGreaterThan(0); + const missing = files.filter((file) => !hashed.has(file)); + expect( + missing.slice(0, 10), + `@tale/platform#test reads ${missing.length} file(s) under ${repoPath} that turbo does not hash — list them as \`$TURBO_ROOT$/…\` inputs in services/platform/turbo.json`, + ).toEqual([]); + }); + } +}); diff --git a/services/platform/turbo.json b/services/platform/turbo.json index f771e128ea..2ba1472c13 100644 --- a/services/platform/turbo.json +++ b/services/platform/turbo.json @@ -7,8 +7,14 @@ "$TURBO_EXTENDS$", "$TURBO_DEFAULT$", "$TURBO_ROOT$/.env.example", + "$TURBO_ROOT$/compose.yml", + "$TURBO_ROOT$/compose.dev.yml", + "$TURBO_ROOT$/configs/platform/**", "$TURBO_ROOT$/knip.config.ts", - "$TURBO_ROOT$/services/db/init-scripts/*.sql" + "$TURBO_ROOT$/scripts/ensure-sandbox-runtime-image.ts", + "$TURBO_ROOT$/services/db/init-scripts/*.sql", + "$TURBO_ROOT$/services/db/migrations/knowledge-db/**", + "$TURBO_ROOT$/services/sandbox/src/config.ts" ] } } From 4eb8496a660a790018b419470c620df08d82d541 Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Mon, 28 Sep 2026 00:04:09 +0200 Subject: [PATCH 2/3] docs: reconcile workspace cache input guidance --- .agents/repo.md | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/.agents/repo.md b/.agents/repo.md index 82a1104187..068b6d4ef4 100644 --- a/.agents/repo.md +++ b/.agents/repo.md @@ -108,26 +108,27 @@ until its inputs change, and "it passes on `main`" is not evidence the suite ran concluding that a failure is yours, open the job log and look for `cache hit, replaying logs` beside the task; `--force` re-runs it locally. A task whose result depends on anything but its declared inputs — test file ordering, wall-clock, a shared browser page — is not safely -cacheable, and the fix is the determinism, not the cache. A test that reads a file outside its -workspace declares that file in the workspace's `turbo.json` `test.inputs` (`$TURBO_EXTENDS$`, -`$TURBO_DEFAULT$`, then `$TURBO_ROOT$/`); without it, an edit to that file alone replays -the cached verdict. `services/platform/turbo.json` declares what the platform's `test` task -reads (`configs/platform/`, the compose files, the tale-db init scripts and knowledge-db -migrations, among others), and `services/platform/tests/guards/turbo-inputs.guard.test.ts` asks -`turbo --dry=json` whether each of those paths is hashed; a suite that starts reading another -outside file adds it to both. The sources of a workspace package the task depends on -(`packages/*`) are a separate gap: no `test` task depends on `^…`, so an edit there alone -replays the consumers' cached verdicts too. +cacheable, and the fix is the determinism, not the cache. -Turbo hashes only the files of a task's own workspace. A task that reads a file outside it -replays its cached verdict when only that file changes, so it lists the file as a -`$TURBO_ROOT$/…` input in its workspace's `turbo.json`. -[`services/docs/turbo.json`](../services/docs/turbo.json) gives `@tale/docs` the root `docs/` -tree (test, build), its JSON maps (typecheck, lint) and the root `README*.md` (test); -[`tools/cli/turbo.json`](../tools/cli/turbo.json) gives `@tale/cli`'s tests the CLI install -pages. Keep `$TURBO_DEFAULT$` in that list. `services/docs/tests/turbo-inputs.test.ts` and -`tools/cli/src/lib/config/platform-docs.test.ts` ask `turbo --dry=json` whether those files -are hashed. An edit under `packages/` also leaves every dependent workspace's `test`, +Turbo's default source inputs cover a task's own workspace. A task that reads a file outside +it lists the file as a `$TURBO_ROOT$/…` input in its workspace's `turbo.json`; otherwise an +edit to that file alone replays the cached verdict. Keep `$TURBO_DEFAULT$` and any inherited +inputs (`$TURBO_EXTENDS$`) in that list: + +- [`services/platform/turbo.json`](../services/platform/turbo.json) gives `@tale/platform`'s + tests the catalogs under `configs/platform/`, compose files, tale-db init scripts, + knowledge-db migrations and other outside files. Its guard is + `services/platform/tests/guards/turbo-inputs.guard.test.ts`. +- [`services/docs/turbo.json`](../services/docs/turbo.json) gives `@tale/docs` the root `docs/` + tree (test, build), its JSON maps (typecheck, lint) and the root `README*.md` (test). + Its guard is `services/docs/tests/turbo-inputs.test.ts`. +- [`tools/cli/turbo.json`](../tools/cli/turbo.json) gives `@tale/cli`'s tests the CLI install + pages. Its guard is `tools/cli/src/lib/config/platform-docs.test.ts`. + +These guards ask `turbo --dry=json` whether the files are hashed. A suite that starts reading +another outside file adds it to both the task's inputs and its guard. + +Workspace-package sources remain a separate gap. An edit under `packages/` leaves every dependent workspace's `test`, `typecheck` and `lint` hash unchanged, because none of those tasks depends on `^…` — the services' i18n tests that read the `packages/ui` catalogs included. A package change is judged only by that package's own tasks until the consumer's own files change. From 4a8e754ee8688083caf173ddcd9b35cbdf434b92 Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Mon, 28 Sep 2026 00:16:16 +0200 Subject: [PATCH 3/3] fix(docs): hash the ui i18n files the docs tests read The docs i18n suites run @tale/ui's i18n test framework (checks, per-locale rule data, glossary) and resolve docs.* keys against the packages/ui catalogs, none of which @tale/docs#test hashed: an edit there alone replayed the cached docs verdict. List both as $TURBO_ROOT$ inputs and extend the turbo-inputs guard to them. Open every workspace input list in docs and cli with $TURBO_EXTENDS$ as services/platform does, so a root task that gains inputs keeps them, and fold the two copies of the out-of-workspace input rule in .agents/repo.md into one recipe. Both guards now assert that prefix and fail clearly when turbo prints no JSON or cannot be spawned. --- .agents/repo.md | 33 +++++---- services/docs/tests/AGENTS.md | 7 +- .../docs/tests/manual/reference/automation.md | 2 +- services/docs/tests/turbo-inputs.test.ts | 73 ++++++++++++++++--- services/docs/turbo.json | 19 ++++- .../cli/src/lib/config/platform-docs.test.ts | 25 ++++++- tools/cli/turbo.json | 1 + 7 files changed, 124 insertions(+), 36 deletions(-) diff --git a/.agents/repo.md b/.agents/repo.md index d43fd06154..c243723bf4 100644 --- a/.agents/repo.md +++ b/.agents/repo.md @@ -108,24 +108,25 @@ until its inputs change, and "it passes on `main`" is not evidence the suite ran concluding that a failure is yours, open the job log and look for `cache hit, replaying logs` beside the task; `--force` re-runs it locally. A task whose result depends on anything but its declared inputs — test file ordering, wall-clock, a shared browser page — is not safely -cacheable, and the fix is the determinism, not the cache. A test that reads a file outside its -workspace declares that file in the workspace's `turbo.json` `test.inputs` (`$TURBO_EXTENDS$`, -`$TURBO_DEFAULT$`, then `$TURBO_ROOT$/`), as `services/platform/turbo.json` does for the -root `.env.example`, `knip.config.ts` and the tale-db init scripts; without it, an edit to that -file alone replays the cached verdict. +cacheable, and the fix is the determinism, not the cache. -Turbo hashes only the files of a task's own workspace. A task that reads a file outside it -replays its cached verdict when only that file changes, so it lists the file as a -`$TURBO_ROOT$/…` input in its workspace's `turbo.json`. +Turbo hashes only the files of a task's own workspace, so a task that reads a file outside it +replays its cached verdict when only that file changes. Such a task lists the file in its +workspace's `turbo.json` `inputs`: `$TURBO_EXTENDS$` (keeps the root task's inputs, which a +workspace list otherwise replaces), `$TURBO_DEFAULT$` (keeps the workspace's own files), then +`$TURBO_ROOT$/`. [`services/platform/turbo.json`](../services/platform/turbo.json) gives +`@tale/platform`'s tests the root `.env.example`, `knip.config.ts` and the tale-db init scripts; [`services/docs/turbo.json`](../services/docs/turbo.json) gives `@tale/docs` the root `docs/` -tree (test, build), its JSON maps (typecheck, lint) and the root `README*.md` (test); -[`tools/cli/turbo.json`](../tools/cli/turbo.json) gives `@tale/cli`'s tests the CLI install -pages. Keep `$TURBO_DEFAULT$` in that list. `services/docs/tests/turbo-inputs.test.ts` and -`tools/cli/src/lib/config/platform-docs.test.ts` ask `turbo --dry=json` whether those files -are hashed. An edit under `packages/` also leaves every dependent workspace's `test`, -`typecheck` and `lint` hash unchanged, because none of those tasks depends on `^…` — the -services' i18n tests that read the `packages/ui` catalogs included. A package change is judged -only by that package's own tasks until the consumer's own files change. +tree (test, build), its JSON maps (typecheck, lint), and the root `README*.md` plus `@tale/ui`'s +i18n catalogs and test framework (test); [`tools/cli/turbo.json`](../tools/cli/turbo.json) gives +`@tale/cli`'s tests the CLI install pages. `services/docs/tests/turbo-inputs.test.ts` and +`tools/cli/src/lib/config/platform-docs.test.ts` ask `turbo --dry=json` whether those files are +hashed and hold the two-entry prefix. Beyond such a declared file, an edit under `packages/` +leaves every dependent workspace's `test`, `typecheck` and `lint` hash unchanged, because none of +those tasks depends on `^…`: a package change is judged only by that package's own tasks until +the consumer's own files change. The i18n suites of `services/platform`, `services/web`, +`services/ui-docs`, `services/ai-gateway` and `packages/marketing-ui` are still in that gap: they +run `@tale/ui`'s i18n test framework (the first three also read the package catalogs) unhashed. ## Skills index diff --git a/services/docs/tests/AGENTS.md b/services/docs/tests/AGENTS.md index 466e3e59fa..8ba78bb07c 100644 --- a/services/docs/tests/AGENTS.md +++ b/services/docs/tests/AGENTS.md @@ -15,8 +15,9 @@ Run it after renaming, moving, or deleting a page; after editing [`docs/nav.json`](../../../docs/nav.json); after adding a page in one locale; after editing any heading (heading text → slug); after translating or rewriting a page; and before opening any PR that touches `docs/` or `services/docs/` (CI runs the same suite via `bunx turbo run test`; -[`../turbo.json`](../turbo.json) hashes `docs/` and the root READMEs, so a docs-only change -re-runs it instead of replaying the cached verdict). +[`../turbo.json`](../turbo.json) hashes `docs/`, the root READMEs and `@tale/ui`'s i18n catalogs +and test framework, so a change to any of them re-runs it instead of replaying the cached +verdict). ## Run it @@ -46,7 +47,7 @@ and asserts the list is empty — the failure prints each file once with offendi | Check (`*.test.ts`) | Catches → fix | | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `walk` | Harness sanity: walker finds pages, base locales `en`/`de`/`fr` present → if it trips the harness itself is broken (check `lib/paths.ts`, the tree). | -| `turbo-inputs` | A `@tale/docs` task (test, build, typecheck, lint) that reads a file outside `services/docs/` turbo does not hash, so a docs-only change would replay its cached result → add the `$TURBO_ROOT$/…` glob to [`../turbo.json`](../turbo.json), keeping `$TURBO_DEFAULT$`. | +| `turbo-inputs` | A `@tale/docs` task (test, build, typecheck, lint) that reads a file outside `services/docs/` turbo does not hash, so a docs-only change would replay its cached result → add the `$TURBO_ROOT$/…` glob to [`../turbo.json`](../turbo.json) after `$TURBO_EXTENDS$` and `$TURBO_DEFAULT$`, which open every list. | | `navigation` | A `docs/nav.json` slug with no `.md`/`.mdx` under a locale (renamed page, untranslated page, typo) → create the file or fix/remove the nav entry. | | `locale-tree` | An `en/` page with no DE/FR mirror, or a DE/FR orphan with no `en/` source → create the mirror or delete the orphan. | | `locale-outline` | DE/FR drifting from the EN page's heading-depth sequence or fenced-code-block count → restructure the locale page to match EN's outline. | diff --git a/services/docs/tests/manual/reference/automation.md b/services/docs/tests/manual/reference/automation.md index 4947b886b2..67b54418ea 100644 --- a/services/docs/tests/manual/reference/automation.md +++ b/services/docs/tests/manual/reference/automation.md @@ -26,7 +26,7 @@ Legend: ✅ fully automated · 🔶 partially automated · ⛔ manual-only (no s | [accessibility](../suites/accessibility.md) | `A11Y-A12` (one page title) | ✅ automated | `page-header.spec.ts` (one `h1`, in the article; the trail leaf is a plain current marker) + `tests/prerender/seo.test.ts` | | [accessibility](../suites/accessibility.md) | Full-page audits (`A11Y-A1`–`A11Y-A11`) | ⛔ manual-only | — this guide (the shared `ImageZoom`/`Video` components carry `vitest-axe` in `@tale/ui`) | | [content](../suites/content.md) | `CONT-F1` (source shape) | ✅ automated | vitest `structure-code.test.ts` (every fence declares a language), `structure-headings.test.ts`, `links.test.ts` | -| [content](../suites/content.md) | A docs-only change re-runs the structural suite and the docs build in CI instead of replaying a cached result | ✅ automated | vitest `turbo-inputs.test.ts` (asks `turbo --dry=json` that every page, `nav.json`, `redirects.json` and root README these tasks read is hashed) | +| [content](../suites/content.md) | A docs-only change re-runs the structural suite and the docs build in CI instead of replaying a cached result | ✅ automated | vitest `turbo-inputs.test.ts` (asks `turbo --dry=json` that every page, `nav.json`, `redirects.json`, root README and `@tale/ui` i18n catalog and framework file these tasks read is hashed) | | [content](../suites/content.md) | Local preview keeps the article body after a content edit or regenerated frontmatter | 🔶 unit | `lib/content/reload-content.test.ts` checks client full reload and module invalidation for content paths; editing a visible page in the dev server remains manual | | [content](../suites/content.md) | `CONT-F15`–`CONT-F16` (image sources) | 🔶 partial | vitest `images.test.ts` (paths resolve, alt text, size) + `image-manifest.test.ts` (manifest entry, page reference, DPR-2 dimensions) — rendered behaviour manual | | [content](../suites/content.md) | Frame captions and keyboard image zoom | ✅ automated | `@tale/ui` `frame.test.tsx` preserves captions, child images and following content through the real Markdown parser; `markdown.spec.ts` checks visible captions, zoom and Escape/focus restoration in EN/DE/FR. | diff --git a/services/docs/tests/turbo-inputs.test.ts b/services/docs/tests/turbo-inputs.test.ts index 4968f24efd..b4a3f80053 100644 --- a/services/docs/tests/turbo-inputs.test.ts +++ b/services/docs/tests/turbo-inputs.test.ts @@ -9,12 +9,13 @@ import { walkDocs } from './lib/walk'; /** * Turbo keys a task's cache on the files of its own workspace, and neither the - * content tree (`docs/`) nor the root READMEs belong to one — so a task that - * reads them replays its last verdict when only they change, and a broken - * page passes CI (a docs-only edit replayed `@tale/docs:test` from the cache). - * `services/docs/turbo.json` declares them as `$TURBO_ROOT$` inputs; this asks - * turbo itself (`--dry=json`) which files each task hashes, so an input list - * that misses a file the task reads fails here instead of replaying green. + * content tree (`docs/`), the root READMEs nor `@tale/ui`'s i18n framework + * belong to this one — so a task that reads them replays its last verdict when + * only they change, and a broken page passes CI (a docs-only edit replayed + * `@tale/docs:test` from the cache). `services/docs/turbo.json` declares them + * as `$TURBO_ROOT$` inputs; this asks turbo itself (`--dry=json`) which files + * each task hashes, so an input list that misses a file the task reads fails + * here instead of replaying green. * * A task that starts reading another file outside `services/docs/` lists it * in `turbo.json` and here. (`@tale/cli`'s tests read the CLI install pages; @@ -23,6 +24,34 @@ import { walkDocs } from './lib/walk'; const DATA_FILES = ['docs/nav.json', 'docs/redirects.json']; +/** `@tale/ui`'s i18n folder, repo-relative. */ +const UI_I18N = 'packages/ui/src/i18n'; + +/** Every file under a repo-relative directory, repo-relative and `/`-separated. */ +function filesUnder(dir: string): string[] { + const root = path.join(REPO_ROOT, dir); + return fs + .readdirSync(root, { recursive: true, encoding: 'utf8' }) + .filter((entry) => fs.statSync(path.join(root, entry)).isFile()) + .map((entry) => toPosix(path.join(dir, entry))); +} + +/** + * What the i18n suites load from `@tale/ui`: `lib/i18n/messages.test.ts` + * resolves the service's `docs.*` keys against the package catalogs + * (`packageCatalogs`), and it and `docs.test.ts` run the shared framework + * (`@tale/ui/i18n/tests` — its checks, per-locale rule data and glossary). + */ +function uiI18nFiles(): string[] { + const catalogs = filesUnder(`${UI_I18N}/messages`).filter((file) => + file.endsWith('.yml'), + ); + const framework = filesUnder(`${UI_I18N}/tests`).filter( + (file) => !/\.test\.tsx?$/.test(file), + ); + return [...catalogs, ...framework]; +} + /** Every page the structural suite walks, plus the nav and redirect maps. */ function contentFiles(): string[] { return [ @@ -39,8 +68,8 @@ function rootReadmes(): string[] { const READERS: { task: string; why: string; reads: () => string[] }[] = [ { task: 'test', - why: 'the structural suite, the i18n docs scan and the README parity check', - reads: () => [...contentFiles(), ...rootReadmes()], + why: 'the structural suite, the i18n suites and the README parity check', + reads: () => [...contentFiles(), ...rootReadmes(), ...uiI18nFiles()], }, { task: 'build', @@ -83,10 +112,19 @@ function hashedByTask(): Map> { ], { cwd: REPO_ROOT, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }, ); + if (run.error) { + throw new Error(`turbo --dry=json did not run: ${run.error.message}`, { + cause: run.error, + }); + } if (run.status !== 0) { throw new Error(`turbo --dry=json exited ${run.status}: ${run.stderr}`); } - const { tasks } = JSON.parse(run.stdout.slice(run.stdout.indexOf('{'))) as { + const start = run.stdout.indexOf('{'); + if (start === -1) { + throw new Error(`turbo --dry=json printed no JSON: ${run.stdout}`); + } + const { tasks } = JSON.parse(run.stdout.slice(start)) as { tasks: DryRunTask[]; }; return new Map( @@ -110,6 +148,23 @@ describe('turbo inputs', () => { hashed = hashedByTask(); }, 60_000); + it('every input list keeps the root task inputs and the workspace sources', () => { + // A workspace `inputs` list replaces the root task's instead of adding to + // it; `$TURBO_EXTENDS$` keeps the root's, `$TURBO_DEFAULT$` the workspace's + // own files. + const { tasks } = JSON.parse( + fs.readFileSync(path.join(REPO_ROOT, 'services/docs/turbo.json'), 'utf8'), + ) as { tasks: Record }; + const lists = Object.entries(tasks).filter(([, { inputs }]) => inputs); + expect(lists.length).toBeGreaterThan(0); + for (const [task, { inputs }] of lists) { + expect(inputs?.slice(0, 2), `services/docs/turbo.json ${task}`).toEqual([ + '$TURBO_EXTENDS$', + '$TURBO_DEFAULT$', + ]); + } + }); + for (const { task, why, reads } of READERS) { it(`@tale/docs#${task} hashes every file it reads outside the workspace`, () => { const inputs = hashed.get(`@tale/docs#${task}`) ?? new Set(); diff --git a/services/docs/turbo.json b/services/docs/turbo.json index c37f95d364..9b9f6f15f5 100644 --- a/services/docs/turbo.json +++ b/services/docs/turbo.json @@ -4,19 +4,30 @@ "tasks": { "test": { "inputs": [ + "$TURBO_EXTENDS$", "$TURBO_DEFAULT$", "$TURBO_ROOT$/docs/**", - "$TURBO_ROOT$/README*.md" + "$TURBO_ROOT$/README*.md", + "$TURBO_ROOT$/packages/ui/src/i18n/messages/*.yml", + "$TURBO_ROOT$/packages/ui/src/i18n/tests/**" ] }, "build": { - "inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/docs/**"] + "inputs": ["$TURBO_EXTENDS$", "$TURBO_DEFAULT$", "$TURBO_ROOT$/docs/**"] }, "typecheck": { - "inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/docs/*.json"] + "inputs": [ + "$TURBO_EXTENDS$", + "$TURBO_DEFAULT$", + "$TURBO_ROOT$/docs/*.json" + ] }, "lint": { - "inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/docs/*.json"] + "inputs": [ + "$TURBO_EXTENDS$", + "$TURBO_DEFAULT$", + "$TURBO_ROOT$/docs/*.json" + ] } } } diff --git a/tools/cli/src/lib/config/platform-docs.test.ts b/tools/cli/src/lib/config/platform-docs.test.ts index a4e0c6a0dc..b0d085f3d9 100644 --- a/tools/cli/src/lib/config/platform-docs.test.ts +++ b/tools/cli/src/lib/config/platform-docs.test.ts @@ -94,9 +94,11 @@ test('turbo re-runs this suite when an install page changes', () => { ); } const stdout = run.stdout.toString(); - const { tasks } = dryRunSchema.parse( - JSON.parse(stdout.slice(stdout.indexOf('{'))), - ); + const start = stdout.indexOf('{'); + if (start === -1) { + throw new Error(`turbo --dry=json printed no JSON: ${stdout}`); + } + const { tasks } = dryRunSchema.parse(JSON.parse(stdout.slice(start))); const inputs = new Set( Object.keys( tasks.find((task) => task.taskId === '@tale/cli#test')?.inputs ?? {}, @@ -110,3 +112,20 @@ test('turbo re-runs this suite when an install page changes', () => { ).filter((page) => !inputs.has(page)); expect(unhashed).toEqual([]); }); + +/** A workspace `inputs` list replaces the root task's instead of adding to it; + * `$TURBO_EXTENDS$` keeps the root's, `$TURBO_DEFAULT$` the workspace's own. */ +test('the test input list keeps the root inputs and the workspace sources', () => { + const { tasks } = z + .object({ + tasks: z.record( + z.string(), + z.object({ inputs: z.array(z.string()).optional() }), + ), + }) + .parse(JSON.parse(readFileSync(resolve(CLI_ROOT, 'turbo.json'), 'utf8'))); + expect(tasks.test?.inputs?.slice(0, 2)).toEqual([ + '$TURBO_EXTENDS$', + '$TURBO_DEFAULT$', + ]); +}); diff --git a/tools/cli/turbo.json b/tools/cli/turbo.json index 66539aebb4..73b6eba74c 100644 --- a/tools/cli/turbo.json +++ b/tools/cli/turbo.json @@ -4,6 +4,7 @@ "tasks": { "test": { "inputs": [ + "$TURBO_EXTENDS$", "$TURBO_DEFAULT$", "$TURBO_ROOT$/docs/*/self-hosted/install/cli-install.md" ]