Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Stop builds and tests from rewriting files other tasks read (#5346)
Nick Gomezade78ed3fd67
diff --git a/.gitignore b/.gitignoreindex 5d2af1385..24ee8e468 100644--- a/.gitignore+++ b/.gitignore@@ -3,6 +3,7 @@ dist/packages/desktop/out/packages/desktop/dist-desktop/packages/desktop/dev-app-update.yml+packages/desktop/electron.vite.config.*.mjs.turbo/turbo-cache-key.jsontmp/diff --git a/biome.jsonc b/biome.jsoncindex 86a3f576f..ffcd9c792 100644--- a/biome.jsonc+++ b/biome.jsonc@@ -158,6 +158,7 @@"!**/tests/perf/playwright-results","!packages/desktop/out","!packages/desktop/dist-desktop",+ "!packages/desktop/electron.vite.config.*.mjs",// Self-contained internal unit with its own tsconfig, conventions, and// test entry points; never OK-biome-formatted, so it stays out of the// format scan.diff --git a/knip.config.ts b/knip.config.tsindex d3638888e..65f0e8807 100644--- a/knip.config.ts+++ b/knip.config.ts@@ -147,15 +147,11 @@ export default {'packages/server': {entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],project: 'src/**',- ignoreDependencies: [- '@types/shell-quote',- ],+ ignoreDependencies: ['@types/shell-quote'],},'packages/cli': {entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],- ignoreDependencies: [- 'yjs',- ],+ ignoreDependencies: ['yjs'],},'packages/desktop': {entry: [diff --git a/packages/app/lingui.config.ts b/packages/app/lingui.config.tsindex 0daa03ce2..0809122f8 100644--- a/packages/app/lingui.config.ts+++ b/packages/app/lingui.config.ts@@ -15,8 +15,7 @@ import { formatter } from '@lingui/format-po';* Compiled catalogs (`messages.json`) are committed alongside the `.po` sources* so the same import path resolves under Vite dev, the production build, the* Electron renderer, and the test runtime without a per-entrypoint compile- * step. `i18n:compile` is also wired into `predev` / `build` to keep them- * fresh and Biome-formatted; run `pnpm run i18n` after adding strings.+ * step.** `locales` is `SUPPORTED_LOCALES` from `@inkeep/open-knowledge-core` plus the* generated `pseudo`. It is spelled out literally rather than imported: thediff --git a/packages/app/package.json b/packages/app/package.jsonindex be0c2d03a..7715dd9a5 100644--- a/packages/app/package.json+++ b/packages/app/package.json@@ -15,7 +15,7 @@"scripts": {"predev": "turbo run build --filter=@inkeep/open-knowledge-core --filter=@inkeep/open-knowledge-server && sh scripts/i18n-compile-unless-skipped.sh && node scripts/copy-excalidraw-assets.mjs","dev": "vite",- "build": "pnpm run i18n:compile && node scripts/copy-excalidraw-assets.mjs && tsc --noEmit && vite build && pnpm run check:no-dev-harness",+ "build": "node scripts/copy-excalidraw-assets.mjs && tsc --noEmit && vite build && pnpm run check:no-dev-harness","check:no-dev-harness": "node scripts/check-dev-harness-absent.mjs","typecheck": "tsc --noEmit","i18n": "lingui extract --clean && pnpm run i18n:compile",diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.tsindex a28cc2b18..8a60e5826 100644--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts@@ -1,4 +1,3 @@-import { readFileSync } from 'node:fs';import { join } from 'node:path';import { setTimeout as wait } from 'node:timers/promises';diff --git a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts b/packages/app/tests/integration/indented-jsx-byte-sacred.test.tsindex 4fc2c11f9..6fcdc23f2 100644--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { normalizeBridge } from '@inkeep/open-knowledge-core';import { updateYFragment } from '@tiptap/y-tiptap';diff --git a/packages/app/tests/integration/interior-edit-freshness.test.ts b/packages/app/tests/integration/interior-edit-freshness.test.tsindex 9f2f6feb6..40b5cdfd6 100644--- a/packages/app/tests/integration/interior-edit-freshness.test.ts+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts b/packages/app/tests/integration/keystroke-cadence-danger-space.test.tsindex 2a085742b..93666af70 100644--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/producer-guard-wiring.test.ts b/packages/app/tests/integration/producer-guard-wiring.test.tsindex 878d5196b..867598d34 100644--- a/packages/app/tests/integration/producer-guard-wiring.test.ts+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.tsindex 4ada3cf26..0970ac12f 100644--- a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts+++ b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts@@ -1,4 +1,3 @@-import { randomUUID } from 'node:crypto';import { afterEach, describe, expect, test } from 'vitest';import { agentWriteMd, createTestServer, type TestServer } from './test-harness';diff --git a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts b/packages/app/tests/integration/qa-045-restore-after-gc.test.tsindex cbe2b705f..b632185e1 100644--- a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts+++ b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts@@ -1,4 +1,3 @@-import { execFileSync } from 'node:child_process';import { randomUUID } from 'node:crypto';import { join } from 'node:path';diff --git a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.tsindex 89bc9b4d9..c530ce4ba 100644--- a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts+++ b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts@@ -1,4 +1,3 @@-import { randomUUID } from 'node:crypto';import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';import type * as Y from 'yjs';diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.tsindex a78aeb0e4..d3767adc9 100644--- a/packages/app/tests/integration/undo-after-rollback.test.ts+++ b/packages/app/tests/integration/undo-after-rollback.test.ts@@ -1,4 +1,3 @@-import { ROLLBACK_ORIGIN } from '@inkeep/open-knowledge-server';import { afterAll, beforeAll, describe, expect, test } from 'vitest';import * as Y from 'yjs';diff --git a/packages/app/tests/integration/undo-recycle-reset.test.ts b/packages/app/tests/integration/undo-recycle-reset.test.tsindex e7cc69c3f..b076f955c 100644--- a/packages/app/tests/integration/undo-recycle-reset.test.ts+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts@@ -1,4 +1,3 @@-import { writeFileSync } from 'node:fs';import { join } from 'node:path';import { setTimeout as wait } from 'node:timers/promises';diff --git a/packages/app/tests/integration/undo-rederive-survival.test.ts b/packages/app/tests/integration/undo-rederive-survival.test.tsindex 9ddcd0730..7935e35f8 100644--- a/packages/app/tests/integration/undo-rederive-survival.test.ts+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts@@ -1,4 +1,3 @@-import { prependFrontmatter } from '@inkeep/open-knowledge-core';import { Plugin, PluginKey } from '@tiptap/pm/state';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';diff --git a/packages/app/tests/meta/build-reads-committed-catalogs.test.ts b/packages/app/tests/meta/build-reads-committed-catalogs.test.tsnew file mode 100644index 000000000..5147ae816--- /dev/null+++ b/packages/app/tests/meta/build-reads-committed-catalogs.test.ts@@ -0,0 +1,80 @@+import { readFileSync } from 'node:fs';+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';+import { describe, expect, test } from 'vitest';++const APP_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');+const CATALOG_COMPILE = /\blingui compile\b|i18n-compile-unless-skipped/;+const SCRIPT_REFERENCE = /\b(pnpm|npm|yarn|turbo)(?=\s|$)(?: run)?(?: ([^\s;&|]+))?[^;&|]*/g;++const scripts = (+ JSON.parse(readFileSync(join(APP_ROOT, 'package.json'), 'utf8')) as {+ scripts: Record<string, string>;+ }+).scripts;++function scriptsRunBy(entry: string): { reached: Map<string, string>; unfollowed: string[] } {+ const reached = new Map<string, string>();+ const unfollowed: string[] = [];+ const pending = [entry];+ while (pending.length > 0) {+ const name = pending.shift() as string;+ for (const candidate of [`pre${name}`, name, `post${name}`]) {+ const command = scripts[candidate];+ if (command === undefined || reached.has(candidate)) continue;+ reached.set(candidate, command);+ for (const [call, runner, referenced] of command.matchAll(SCRIPT_REFERENCE)) {+ if (runner !== 'turbo' && referenced !== undefined && Object.hasOwn(scripts, referenced)) {+ pending.push(referenced);+ } else {+ unfollowed.push(`"${candidate}": ${call.trim()}`);+ }+ }+ }+ }+ return { reached, unfollowed };+}++function catalogCompilesRunBy(entry: string): string[] {+ return [...scriptsRunBy(entry).reached]+ .filter(([, command]) => CATALOG_COMPILE.test(command))+ .map(([name, command]) => `"${name}": ${command}`);+}++describe('the app build reads the committed catalogs', () => {+ test.each(['i18n', 'dev'])('the %s script reaches the catalog compile', (entry) => {+ expect(+ catalogCompilesRunBy(entry),+ `packages/app/package.json "${entry}" no longer reaches a command matching ${CATALOG_COMPILE}, so the build check below may be looking for a compile spelled some other way. Update the pattern to the current compile command.`,+ ).not.toEqual([]);+ });++ test.each([+ ['dev', 'turbo run'],+ ['check', 'pnpm -w run'],+ ])('the %s script reaches a `%s` call this test cannot follow', (entry, form) => {+ const reported = scriptsRunBy(entry).unfollowed.filter((call) => call.includes(form));+ expect(+ reported,+ `packages/app/package.json "${entry}" reaches no \`${form}\` call that this test reports as one it cannot follow. Either the walk stopped reporting calls of that form, so the build check below can pass while the build makes one, or the manifest no longer makes that call: then point this control at another call of that form.`,+ ).not.toEqual([]);+ });++ test('the build calls only scripts this test can follow', () => {+ expect(scripts.build, 'packages/app/package.json has no "build" script').toBeDefined();+ const { unfollowed } = scriptsRunBy('build');+ expect(+ unfollowed,+ `packages/app/package.json "build" reaches a call this test cannot follow to a script in this manifest (${unfollowed.join('; ')}), so it cannot tell whether that call compiles the i18n catalogs. Call the script as \`pnpm run <name>\`, or extend this test to follow the new form.`,+ ).toEqual([]);+ });++ test('the build runs no catalog compile', () => {+ expect(scripts.build, 'packages/app/package.json has no "build" script').toBeDefined();+ const compiles = catalogCompilesRunBy('build');+ expect(+ compiles,+ `packages/app/package.json "build" reaches the i18n catalog compile (${compiles.join('; ')}). The compile rewrites the tracked src/locales/*/messages.json, which other tasks in the same turbo run read, so one of them can read a catalog mid-rewrite. The build ships the committed catalogs: compile them with \`pnpm run i18n\` and commit them.`,+ ).toEqual([]);+ });+});diff --git a/packages/app/tests/meta/i18n-freshness-gate-wiring.uncached.test.ts b/packages/app/tests/meta/i18n-freshness-gate-wiring.uncached.test.tsindex 45e011c9c..191aaf4fb 100644--- a/packages/app/tests/meta/i18n-freshness-gate-wiring.uncached.test.ts+++ b/packages/app/tests/meta/i18n-freshness-gate-wiring.uncached.test.ts@@ -11,6 +11,8 @@ const FRESHNESS_GLOBAL_SETUP = './tests/stress/_helpers/i18n-catalog-freshness.tconst TURBO_DRY_RUN_TIMEOUT_MS = 120_000;const TURBO_DRY_RUN_MAX_BUFFER_BYTES = 64 * 1024 * 1024;const TURBO_OUTPUT_HEAD_CHARS = 400;+const BUILD_EDGE_REASON =+ 'The edge keeps the ordering associated with a recorded CI failure: the app build, scheduled beside the e2e tier, could not resolve @inkeep/open-knowledge-core while Vite loaded its config. Concurrency is the most-supported explanation for that failure rather than a reproduced one.';const PLAYWRIGHT_TIERS = {e2e: {@@ -92,7 +94,7 @@ function turboResolvedGraph(): Map<string, string[]> {});if (dryRun.error || dryRun.status !== 0) {throw new Error(- `could not resolve turbo's task graph, so this run cannot tell whether a Playwright tier races the app build that rewrites src/locales/*/messages.json — ${turboBin} exited ${String(dryRun.status)}${dryRun.signal ? ` on ${dryRun.signal}` : ''}${dryRun.error ? ` (${String(dryRun.error)})` : ''}:\n${dryRun.stderr ?? ''}${dryRun.stdout ?? ''}`,+ `could not resolve turbo's task graph, so this run cannot tell whether every Playwright tier is ordered behind the app build — ${turboBin} exited ${String(dryRun.status)}${dryRun.signal ? ` on ${dryRun.signal}` : ''}${dryRun.error ? ` (${String(dryRun.error)})` : ''}:\n${dryRun.stderr ?? ''}${dryRun.stdout ?? ''}`,);}const parsed = parseTurboDryRun(@@ -140,9 +142,9 @@ function declaredGlobalSetups(globalSetup: string | string[] | undefined): strinreturn Array.isArray(globalSetup) ? [...globalSetup] : [globalSetup];}-describe('i18n catalog freshness gate wiring', () => {+describe('Playwright tiers wait for the app build', () => {test.each(TIER_NAMES)(- 'turbo orders the %s tier behind the app build that rewrites the catalogs',+ 'turbo orders the %s tier behind the app build',(tier) => {const { turboTask } = PLAYWRIGHT_TIERS[tier];const taskId = `${APP_PACKAGE_NAME}#${turboTask}`;@@ -153,12 +155,14 @@ describe('i18n catalog freshness gate wiring', () => {).toBeDefined();expect(dependencies,- `${taskId} does not depend on ${APP_PACKAGE_NAME}#build, so turbo may run the app build concurrently with the ${tier} tier. That build runs "pnpm run i18n:compile", which truncates and rewrites all 13 src/locales/*/messages.json, and the ${tier} tier's globalSetup JSON.parses those same files. Add "build" to turbo.json "${turboTask}".dependsOn.`,+ `${taskId} does not depend on ${APP_PACKAGE_NAME}#build, so turbo may run the app build concurrently with the ${tier} tier. ${BUILD_EDGE_REASON} Add "build" to turbo.json "${turboTask}".dependsOn.`,).toContain(`${APP_PACKAGE_NAME}#build`);},TURBO_DRY_RUN_TIMEOUT_MS,);+});+describe('i18n catalog freshness gate wiring', () => {test.each(TIER_NAMES)('the %s tier declares the catalog freshness globalSetup', async (tier) => {const { configFile, load } = PLAYWRIGHT_TIERS[tier];const declared = declaredGlobalSetups((await load()).default.globalSetup);@@ -260,7 +264,7 @@ describe('scoped turbo overrides stay aligned with the global entries they replaconst scopedDependsOn = (scoped as TurboTaskDefinition).dependsOn as string[];expect(scopedDependsOn,- `the scoped override exists to add the app build edge that keeps this tier from reading src/locales/*/messages.json while the build rewrites them, so dropping "build" from it silently restores the race`,+ `the scoped override exists to give this tier the "build" edge test:e2e has, so dropping "build" from it lets turbo run the app build concurrently with this tier. ${BUILD_EDGE_REASON}`,).toContain('build');},);diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex 5ce6b47cb..822ff8e3d 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -49,7 +49,7 @@"build:schema": "node --import tsx --conditions=development scripts/build-config-schema.mjs","build:assets": "pnpm run build:app && pnpm run build:skill-asset && pnpm run build:notices && pnpm run build:license && pnpm run build:native && pnpm run build:schema","build": "pnpm run build:cli && pnpm run build:assets",- "test": "pnpm run build:schema && vitest run",+ "test": "vitest run","test:e2e:cli": "vitest run --config vitest.e2e.config.ts","typecheck": "tsc --noEmit","check:dts": "node scripts/check-published-dts.mjs",diff --git a/packages/cli/src/content/published-schema.test.ts b/packages/cli/src/content/published-schema.test.tsindex d39788218..af3568722 100644--- a/packages/cli/src/content/published-schema.test.ts+++ b/packages/cli/src/content/published-schema.test.ts@@ -3,7 +3,7 @@ import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import Ajv from 'ajv';import addFormats from 'ajv-formats';-import { beforeEach, describe, expect, test, vi } from 'vitest';+import { beforeAll, describe, expect, test } from 'vitest';const here = dirname(fileURLToPath(import.meta.url));const DIST = resolve(here, '..', '..', 'dist');@@ -14,18 +14,13 @@ const VERSIONED_USER_PATH = resolve(VERSIONED_DIR, 'config.user.schema.json');const ALIAS_PROJECT_PATH = resolve(DIST, 'config.project.schema.json');const ALIAS_USER_PATH = resolve(DIST, 'config.user.schema.json');-async function ensurePublishedSchemas(): Promise<void> {- vi.resetModules();- await import('../../scripts/build-config-schema.mjs');-}-describe('published dist/config-schema.json', () => {- beforeEach(async () => {- await ensurePublishedSchemas();- });-- test('artifact exists at the path npm ships via files:["dist"]', () => {- expect(existsSync(PUBLISHED_SCHEMA_PATH)).toBe(true);+ beforeAll(() => {+ if (!existsSync(PUBLISHED_SCHEMA_PATH)) {+ throw new Error(+ `${PUBLISHED_SCHEMA_PATH} is absent: these tests read the schema files the CLI build publishes, so generate them with pnpm run build:schema in packages/cli (the CLI build includes that step, and turbo runs the CLI build before this package's tests).`,+ );+ }});test('versioned per-scope artifacts exist at dist/schemas/v0/ (canonical URLs)', () => {diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.tsindex 2a597ec3d..f4cc8a286 100644--- a/packages/core/src/bridge/compose.ts+++ b/packages/core/src/bridge/compose.ts@@ -1,4 +1,3 @@-import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.tsindex 01ef76a9f..8fb428b90 100644--- a/packages/core/src/bridge/doc-boundary-space.ts+++ b/packages/core/src/bridge/doc-boundary-space.ts@@ -1,4 +1,3 @@-import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.tsindex fb0ba5a7c..fc267cbea 100644--- a/packages/core/src/markdown/comment-promoter.ts+++ b/packages/core/src/markdown/comment-promoter.ts@@ -1,4 +1,3 @@-import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.tsindex fa3cfcd86..bfd7e3109 100644--- a/packages/core/src/markdown/merged-walker.ts+++ b/packages/core/src/markdown/merged-walker.ts@@ -1,4 +1,3 @@-import type { Nodes, Parent, Root } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.tsindex 8be632ba4..4d3250d3a 100644--- a/packages/core/src/markdown/safe-url.ts+++ b/packages/core/src/markdown/safe-url.ts@@ -1,4 +1,3 @@-export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');