Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
ci(share): enforce full coverage of the share code and upload it
Elian Doran76f1f1407448
diff --git a/.claude/skills/developing-share-pages/SKILL.md b/.claude/skills/developing-share-pages/SKILL.mdindex 52d35558cc..e6419c8be7 100644--- a/.claude/skills/developing-share-pages/SKILL.md+++ b/.claude/skills/developing-share-pages/SKILL.md@@ -127,6 +127,26 @@ template* page of the User Guide. So:| inline scripts | render the `.ejs`, run in a `node:vm` context | same || core renderer | shaca fixtures (`buildShareNote`), `getContent()` / `renderNoteContent()` | `pnpm --filter server test src/share` **and** `pnpm --filter standalone test src/share` |+**The share code is held at 100% coverage** (lines, branches, functions, statements), and CI fails+below it:+- the share theme package, by `packages/share-theme/vitest.config.ts` (`--coverage` in the+ `share-theme` CI step, Codecov flag `share-theme`);+- `packages/trilium-core/src/share/**` and `apps/server/src/share/**`, by the per-glob thresholds in+ `apps/server/vite.config.mts`; core's share code and `lightweight/share_provider.ts` again in+ `apps/standalone/vite.config.mts`. Each runner must reach 100% on its own;+- the merged result, by the `share` project status in `codecov.yml`.++Check a change with `--coverage` on the narrowest run, e.g. `npx vitest run share --coverage` in+`apps/server` and `apps/standalone`; the threshold errors name the glob that falls short. Other+core files print `PARSE_ERROR` noise in that run (untested files are parsed untransformed); it does+not fail the run. Cover a branch with a test; remove it only when the types or the callers rule it+out. Never delete a public `SNote`/`SAttribute`/`SAttachment` method for coverage: custom templates+can call any of them.++- The server and standalone setup files load core before a spec's `vi.mock()` runs, so a mock of a+ module core already imported (icon packs, search) never reaches the renderer or the handlers.+ Use `vi.spyOn()` on the module namespace or its default export instead, or `vi.resetModules()`+ with `vi.doMock()` and a dynamic import for a module tested in isolation (the platform adapters).- Core specs that render `page.ejs` with hand-built variables (the subpage-list helper in`content_renderer.spec.ts`) must be given every new variable, or EJS throws `ReferenceError`.Prefer full renders through `renderNoteContent()` for new page-level checks.diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.ymlindex 68ac621810..9e897020f5 100644--- a/.github/workflows/dev.yml+++ b/.github/workflows/dev.yml@@ -271,8 +271,32 @@ jobs:disable_search: truefail_ci_if_error: false+ - name: Run the share-theme tests+ id: test-share-theme+ run: pnpm run --filter=share-theme test --coverage++ - name: Upload share-theme coverage to Codecov+ uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1+ if: ${{ !cancelled() && steps.test-share-theme.outcome == 'success' }}+ with:+ files: packages/share-theme/test-output/vitest/coverage/lcov.info+ flags: share-theme+ disable_search: true+ fail_ci_if_error: false++ - name: Upload share-theme test results to Codecov+ uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1+ if: ${{ !cancelled() && steps.test-share-theme.outcome != 'skipped' }}+ with:+ report_type: test_results+ token: ${{ secrets.CODECOV_TOKEN }}+ files: packages/share-theme/test-output/vitest/junit.xml+ flags: share-theme+ disable_search: true+ fail_ci_if_error: false+- name: Run the rest of the tests- run: pnpm run --filter=\!client --filter=\!standalone --filter=\!server --filter=\!desktop --filter=\!commons --filter=\!ckeditor5 --filter=\!codemirror --filter=\!highlightjs --filter=\!pdfjs-viewer test+ run: pnpm run --filter=\!client --filter=\!standalone --filter=\!server --filter=\!desktop --filter=\!commons --filter=\!ckeditor5 --filter=\!codemirror --filter=\!highlightjs --filter=\!pdfjs-viewer --filter=\!share-theme test# The two suites below are split out of test_dev so they run concurrently with# it (and each other) rather than queueing behind the client/package suites.diff --git a/apps/server/vite.config.mts b/apps/server/vite.config.mtsindex 280c0a0baa..f4eae17638 100644--- a/apps/server/vite.config.mts+++ b/apps/server/vite.config.mts@@ -2,6 +2,9 @@import { resolve } from 'node:path';import { defineConfig } from 'vite';+const CORE_SRC = resolve(__dirname, "../../packages/trilium-core/src").replaceAll("\\", "/");+const FULL_COVERAGE = { lines: 100, functions: 100, branches: 100, statements: 100 };+export default defineConfig(() => ({root: __dirname,cacheDir: '../../node_modules/.vite/apps/server',@@ -62,8 +65,15 @@ export default defineConfig(() => ({// to the repo root so every path is unambiguous.reporter: [ "text", "html", ["lcov", { projectRoot: resolve(__dirname, '../..') }] ],allowExternal: true,- include: ["src/**/*.{ts,tsx}", "../../packages/trilium-core/src/**/*.{ts,tsx}"],- exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts"]+ // Vitest matches a file outside the root by its absolute path, which a relative+ // `../../packages/…` glob never matches.+ include: ["src/**/*.{ts,tsx}", `${CORE_SRC}/**/*.{ts,tsx}`],+ exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts"],+ // Threshold globs, unlike `include`, match paths relative to the root.+ thresholds: {+ "../../packages/trilium-core/src/share/**": FULL_COVERAGE,+ "src/share/**": FULL_COVERAGE+ }},pool: "forks",maxWorkers: 6diff --git a/apps/standalone/vite.config.mts b/apps/standalone/vite.config.mtsindex 25ccaffa2a..6eb5c3823c 100644--- a/apps/standalone/vite.config.mts+++ b/apps/standalone/vite.config.mts@@ -11,6 +11,7 @@ import { shareMermaidManifest, stripUniverEmojiData, stripUniverHyphenation } frconst clientAssets = ["assets", "stylesheets", "fonts", "translations"];const isDev = process.env.NODE_ENV === "development";+const FULL_COVERAGE = { lines: 100, functions: 100, branches: 100, statements: 100 };// Next to the share theme's own files, where `scripts.js` looks for it.const SHARE_MERMAID_MANIFEST = "share/assets/client/share_mermaid.json";@@ -485,7 +486,12 @@ export default defineConfig(() => ({// so paths would emit as bare `main.ts` / `../../../packages/trilium-core/src/…`,// which are ambiguous in this monorepo and get attributed to whichever project wins// the match. Anchor to the repo root so every path is unambiguous.- reporter: ["text", "html", ["lcov", { projectRoot: join(__dirname, "../..") }]]+ reporter: ["text", "html", ["lcov", { projectRoot: join(__dirname, "../..") }]],+ // Threshold globs match paths relative to the root, `src`.+ thresholds: {+ "../../../packages/trilium-core/src/share/**": FULL_COVERAGE,+ "lightweight/share_provider.ts": FULL_COVERAGE+ }},server: {deps: {diff --git a/codecov.yml b/codecov.ymlindex 6d6994a48e..1e72ce6a16 100644--- a/codecov.yml+++ b/codecov.yml@@ -4,6 +4,15 @@ coverage:default:target: autothreshold: 1%+ # The share code is held at full coverage by the share-theme, server and standalone suites;+ # this status checks the merged result.+ share:+ target: 100%+ paths:+ - packages/share-theme/src/+ - packages/trilium-core/src/share/+ - apps/server/src/share/+ - apps/standalone/src/lightweight/share_provider.tspatch:default:target: 80%@@ -53,6 +62,10 @@ flags:paths:- packages/pdfjs-viewer/src/carryforward: true+ share-theme:+ paths:+ - packages/share-theme/src/+ carryforward: truecomment:layout: "condensed_header, condensed_files, condensed_footer"