Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Run cross-package server tests in an uncached tier (#5070)

Nick Gomez6683262918de
diff --git a/.github/scripts/release-cascade-shape.test.mjs b/.github/scripts/release-cascade-shape.test.mjs
index a76c05290..2f524d060 100644
--- a/.github/scripts/release-cascade-shape.test.mjs
+++ b/.github/scripts/release-cascade-shape.test.mjs
@@ -664,6 +664,15 @@ describe('the bug lane verifies the synthetic tree at the same bar as main', ()
expect(retry).not.toContain('--force');
});
+ test('both attempts run every package, so server#test and the uncached tier it brings run on the verified tree', () => {
+ const commands = verify
+ .replace(/\\\n\s*/g, ' ')
+ .split('\n')
+ .filter((l) => l.includes('pnpm exec turbo run typecheck test'));
+ expect(commands).toHaveLength(2);
+ for (const command of commands) expect(command).not.toMatch(/\s(--filter|-F)[\s=]/);
+ });
+
test('only a second consecutive failure mints a refusing verdict', () => {
const installGuardAt = verify.indexOf('verdict=fail');
const retryAt = verify.indexOf('| tee "$RETRY_LOG"');
diff --git a/knip.config.ts b/knip.config.ts
index f4ca69517..9cf70e257 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -103,6 +103,7 @@ export default {
workspaces: {
'.': {
entry: ['test-support/fixtures/no-net-connect/no-net-connect.fixture.ts'],
+ vitest: { entry: ['**/*.uncached.test.{ts,tsx,mjs}'] },
},
'packages/app': {
entry: [
diff --git a/lint-plugins/ok-rules/README.md b/lint-plugins/ok-rules/README.md
index 4ef884dfa..d6a31c4a6 100644
--- a/lint-plugins/ok-rules/README.md
+++ b/lint-plugins/ok-rules/README.md
@@ -168,7 +168,7 @@ The rule does NOT catch:
Included: `packages/server/src/server-observers.ts`, `lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx`.
-Rule: [`lint-plugins/ok-rules/rules/path-conditional-map-driven-origin.mjs`](rules/path-conditional-map-driven-origin.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx`](__fixtures__/path-conditional-map-driven-origin.fixture.tsx). Test: [`packages/server/src/path-conditional-map-driven-origin.test.ts`](../../packages/server/src/path-conditional-map-driven-origin.test.ts).
+Rule: [`lint-plugins/ok-rules/rules/path-conditional-map-driven-origin.mjs`](rules/path-conditional-map-driven-origin.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx`](__fixtures__/path-conditional-map-driven-origin.fixture.tsx). Test: [`lint-plugins/ok-rules/tests/path-conditional-map-driven-origin.uncached.test.mjs`](tests/path-conditional-map-driven-origin.uncached.test.mjs).
### `cst-pm-handler-todo-stub`
@@ -429,7 +429,7 @@ The rule does NOT catch: bare `exec(...)` (the identifier is too commonly shadow
Included: `packages/server/src/**/*.ts`, `packages/cli/src/**/*.ts`, `packages/desktop/src/**/*.ts`, `lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx`. Excluded: `**/*.test.ts`, `**/*.test-helper.ts`.
-Rule: [`lint-plugins/ok-rules/rules/require-windowshide-on-spawn.mjs`](rules/require-windowshide-on-spawn.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx`](__fixtures__/require-windowshide-on-spawn.fixture.tsx). Test: [`packages/server/src/lint-plugins/require-windowshide-on-spawn.test.ts`](../../packages/server/src/lint-plugins/require-windowshide-on-spawn.test.ts). See [PRECEDENTS.md #42](../../PRECEDENTS.md#custom-lint-enforcement-precedent-42) for the custom-rule convention.
+Rule: [`lint-plugins/ok-rules/rules/require-windowshide-on-spawn.mjs`](rules/require-windowshide-on-spawn.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx`](__fixtures__/require-windowshide-on-spawn.fixture.tsx). Test: [`lint-plugins/ok-rules/tests/require-windowshide-on-spawn.uncached.test.mjs`](tests/require-windowshide-on-spawn.uncached.test.mjs). See [PRECEDENTS.md #42](../../PRECEDENTS.md#custom-lint-enforcement-precedent-42) for the custom-rule convention.
### `require-utf8-multipart-parser`
@@ -456,7 +456,7 @@ The rule does NOT catch: member calls (`parsers.busboy(...)` — a different AST
Included: `**/*.ts`, `**/*.tsx`, `**/*.mts`, `lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx`. Excluded: `**/node_modules/**`, `**/dist/**`, `**/*.test.ts`, `**/*.test.tsx`, `**/*.test.mts`, `**/*.test-helper.ts`, `packages/server/src/multipart.ts`.
-Rule: [`lint-plugins/ok-rules/rules/require-utf8-multipart-parser.mjs`](rules/require-utf8-multipart-parser.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx`](__fixtures__/require-utf8-multipart-parser.fixture.tsx). Test: [`packages/server/src/lint-plugins/require-utf8-multipart-parser.test.ts`](../../packages/server/src/lint-plugins/require-utf8-multipart-parser.test.ts). See [PRECEDENTS.md #42](../../PRECEDENTS.md#custom-lint-enforcement-precedent-42) for the custom-rule convention.
+Rule: [`lint-plugins/ok-rules/rules/require-utf8-multipart-parser.mjs`](rules/require-utf8-multipart-parser.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx`](__fixtures__/require-utf8-multipart-parser.fixture.tsx). Test: [`lint-plugins/ok-rules/tests/require-utf8-multipart-parser.uncached.test.mjs`](tests/require-utf8-multipart-parser.uncached.test.mjs). See [PRECEDENTS.md #42](../../PRECEDENTS.md#custom-lint-enforcement-precedent-42) for the custom-rule convention.
### `no-blind-agent-host-fanout`
@@ -664,7 +664,7 @@ The rule does NOT catch:
**Opting out.** There is no legitimate sentinel signal target. A liveness probe is already exempt by its signal argument; anything else is fixed at the source, not suppressed.
-Rule: [`lint-plugins/ok-rules/rules/no-sentinel-signal-target.mjs`](rules/no-sentinel-signal-target.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/no-sentinel-signal-target.fixture.tsx`](__fixtures__/no-sentinel-signal-target.fixture.tsx). Test: [`packages/server/src/lint-plugins/no-sentinel-signal-target.test.ts`](../../packages/server/src/lint-plugins/no-sentinel-signal-target.test.ts). See [PRECEDENTS.md #42](../../PRECEDENTS.md#custom-lint-enforcement-precedent-42) for the custom-rule convention.
+Rule: [`lint-plugins/ok-rules/rules/no-sentinel-signal-target.mjs`](rules/no-sentinel-signal-target.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/no-sentinel-signal-target.fixture.tsx`](__fixtures__/no-sentinel-signal-target.fixture.tsx). Test: [`lint-plugins/ok-rules/tests/no-sentinel-signal-target.uncached.test.mjs`](tests/no-sentinel-signal-target.uncached.test.mjs). See [PRECEDENTS.md #42](../../PRECEDENTS.md#custom-lint-enforcement-precedent-42) for the custom-rule convention.
## Suppression
@@ -751,14 +751,14 @@ Drop `<rule-name>.fixture.tsx` in `__fixtures__/`, pairing positive cases (must
### 5. Author the fixture-file test
-Shell out to oxlint against the fixture config and assert an exact count:
+Put it at `lint-plugins/ok-rules/tests/<rule-name>.uncached.test.mjs`, not in a package. The `.uncached.test` suffix runs it in the uncached cross-package tier (`vitest.uncached.config.ts`): every agent round, CI's `lint` job, and beside every `turbo run test` that runs `server#test`. A package's cached test tier would replay a stale pass when only the rule or `oxlint.config.ts` changed, unless that package's Turbo key hashed both. Write it as plain JavaScript. Shell out to oxlint against the fixture config and assert an exact count:
-```ts
+```js
import { spawnSync } from 'node:child_process';
-import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
-const REPO_ROOT = join(__dirname, '..', '..', '..', '..');
+const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
const FIXTURE = 'lint-plugins/ok-rules/__fixtures__/<rule-name>.fixture.tsx';
const CONFIG = 'lint-plugins/ok-rules/__fixtures__/oxlint.fixtures.json';
@@ -787,8 +787,8 @@ Exact equality is the point: it catches false-negative regressions (count drops
# 1. Rule loads and the main lint stays clean:
pnpm run lint:oxlint
-# 2. Fixture test fires the diagnostic on positive cases:
-pnpm --dir packages/<host> exec vitest run <rule-name>
+# 2. Fixture test fires the diagnostic on positive cases (from the Open Knowledge root):
+pnpm exec vitest run --config vitest.uncached.config.ts <rule-name>
# 3. Mutation check (manual, one-time during dev):
# Temporarily break the rule's predicate; re-run the test; confirm it FAILS;
diff --git a/lint-plugins/ok-rules/__fixtures__/no-sentinel-signal-target.fixture.tsx b/lint-plugins/ok-rules/__fixtures__/no-sentinel-signal-target.fixture.tsx
index 286e35fb1..513c65d97 100644
--- a/lint-plugins/ok-rules/__fixtures__/no-sentinel-signal-target.fixture.tsx
+++ b/lint-plugins/ok-rules/__fixtures__/no-sentinel-signal-target.fixture.tsx
@@ -1,4 +1,4 @@
-// FIXTURE — drives `no-sentinel-signal-target.test.ts` via shell-out to
+// FIXTURE — drives `no-sentinel-signal-target.uncached.test.mjs` via shell-out to
// `pnpm exec oxlint`. Not part of the main lint: `__fixtures__/` is in
// `oxlint.config.ts#ignorePatterns`; `__fixtures__/oxlint.fixtures.json`
// re-enables the rules for the test.
diff --git a/lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx b/lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx
index 70577a6b5..62e03b571 100644
--- a/lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx
+++ b/lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx
@@ -1,4 +1,4 @@
-// FIXTURE — drives `path-conditional-map-driven-origin.test.ts` via shell-out
+// FIXTURE — drives `path-conditional-map-driven-origin.uncached.test.mjs` via shell-out
// to `pnpm exec oxlint`. Not part of the main lint: `__fixtures__/` is in
// `oxlint.config.ts#ignorePatterns`, and `__fixtures__/oxlint.fixtures.json`
// re-enables the rules for the test.
diff --git a/lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx b/lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx
index 050141bcb..cf57310f2 100644
--- a/lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx
+++ b/lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx
@@ -1,4 +1,4 @@
-// FIXTURE — drives `require-utf8-multipart-parser.test.ts` via shell-out to
+// FIXTURE — drives `require-utf8-multipart-parser.uncached.test.mjs` via shell-out to
// `pnpm exec oxlint`. The rule's scope entry self-includes this fixture, so the
// rule DOES apply here; what keeps the 3 fires below out of a normal
// `pnpm run lint` is that `__fixtures__/` is in `oxlint.config.ts#ignorePatterns`,
diff --git a/lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx b/lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx
index 8b8fd004a..41316434a 100644
--- a/lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx
+++ b/lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx
@@ -1,4 +1,4 @@
-// FIXTURE — drives `require-windowshide-on-spawn.test.ts` via shell-out to
+// FIXTURE — drives `require-windowshide-on-spawn.uncached.test.mjs` via shell-out to
// `pnpm exec oxlint`. Not part of the main lint: `__fixtures__/` is in
// `oxlint.config.ts#ignorePatterns`; the fixture is named in the rule's scope
// entry, and `__fixtures__/oxlint.fixtures.json` re-enables the rules for the test.
diff --git a/packages/server/src/lint-plugins/no-sentinel-signal-target.test.ts b/lint-plugins/ok-rules/tests/no-sentinel-signal-target.uncached.test.mjs
similarity index 94%
rename from packages/server/src/lint-plugins/no-sentinel-signal-target.test.ts
rename to lint-plugins/ok-rules/tests/no-sentinel-signal-target.uncached.test.mjs
index ddaa489f6..9448cac12 100644
--- a/packages/server/src/lint-plugins/no-sentinel-signal-target.test.ts
+++ b/lint-plugins/ok-rules/tests/no-sentinel-signal-target.uncached.test.mjs
@@ -1,6 +1,7 @@
import { spawnSync } from 'node:child_process';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
import {
oxlintFixtureArgs,
@@ -8,9 +9,9 @@ import {
readEnabledRuleIds,
readRegisteredRuleNames,
readRuleScope,
-} from '../../../../test-support/read-ok-rules-config.test-helper';
+} from '../../../test-support/read-ok-rules-config.test-helper.ts';
-const REPO_ROOT = join(__dirname, '..', '..', '..', '..');
+const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
const RULE = 'no-sentinel-signal-target';
const FIXTURE_REL = `lint-plugins/ok-rules/__fixtures__/${RULE}.fixture.tsx`;
const README_REL = 'lint-plugins/ok-rules/README.md';
@@ -70,7 +71,7 @@ describe('no-sentinel-signal-target oxlint rule', () => {
const source = readFileSync(join(REPO_ROOT, FIXTURE_REL), 'utf8').split('\n');
const firedLines = lintFixture()
.map((d) => d.labels?.[0]?.span?.line)
- .filter((line): line is number => typeof line === 'number');
+ .filter((line) => typeof line === 'number');
expect(firedLines.length).toBe(20);
for (const line of firedLines) {
expect(source[line - 1]).toMatch(/^export const p\d+ = /);
diff --git a/packages/server/src/path-conditional-map-driven-origin.test.ts b/lint-plugins/ok-rules/tests/path-conditional-map-driven-origin.uncached.test.mjs
similarity index 90%
rename from packages/server/src/path-conditional-map-driven-origin.test.ts
rename to lint-plugins/ok-rules/tests/path-conditional-map-driven-origin.uncached.test.mjs
index 4ccee3c2d..b5fe57a1e 100644
--- a/packages/server/src/path-conditional-map-driven-origin.test.ts
+++ b/lint-plugins/ok-rules/tests/path-conditional-map-driven-origin.uncached.test.mjs
@@ -1,14 +1,14 @@
import { spawnSync } from 'node:child_process';
-import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
import {
oxlintFixtureArgs,
readEnabledRuleIds,
readRegisteredRuleNames,
readRuleScope,
-} from '../../../test-support/read-ok-rules-config.test-helper';
+} from '../../../test-support/read-ok-rules-config.test-helper.ts';
-const REPO_ROOT = join(__dirname, '..', '..', '..');
+const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
const FIXTURE_REL =
'lint-plugins/ok-rules/__fixtures__/path-conditional-map-driven-origin.fixture.tsx';
diff --git a/packages/server/src/lint-plugins/require-utf8-multipart-parser.test.ts b/lint-plugins/ok-rules/tests/require-utf8-multipart-parser.uncached.test.mjs
similarity index 93%
rename from packages/server/src/lint-plugins/require-utf8-multipart-parser.test.ts
rename to lint-plugins/ok-rules/tests/require-utf8-multipart-parser.uncached.test.mjs
index f93fdf690..4863bc968 100644
--- a/packages/server/src/lint-plugins/require-utf8-multipart-parser.test.ts
+++ b/lint-plugins/ok-rules/tests/require-utf8-multipart-parser.uncached.test.mjs
@@ -1,14 +1,14 @@
import { spawnSync } from 'node:child_process';
-import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
import {
oxlintFixtureArgs,
readEnabledRuleIds,
readRegisteredRuleNames,
readRuleScope,
-} from '../../../../test-support/read-ok-rules-config.test-helper';
+} from '../../../test-support/read-ok-rules-config.test-helper.ts';
-const REPO_ROOT = join(__dirname, '..', '..', '..', '..');
+const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
const FIXTURE_REL = 'lint-plugins/ok-rules/__fixtures__/require-utf8-multipart-parser.fixture.tsx';
describe('require-utf8-multipart-parser oxlint rule', () => {
diff --git a/packages/server/src/lint-plugins/require-windowshide-on-spawn.test.ts b/lint-plugins/ok-rules/tests/require-windowshide-on-spawn.uncached.test.mjs
similarity index 91%
rename from packages/server/src/lint-plugins/require-windowshide-on-spawn.test.ts
rename to lint-plugins/ok-rules/tests/require-windowshide-on-spawn.uncached.test.mjs
index ec1458a60..04a3201f0 100644
--- a/packages/server/src/lint-plugins/require-windowshide-on-spawn.test.ts
+++ b/lint-plugins/ok-rules/tests/require-windowshide-on-spawn.uncached.test.mjs
@@ -1,14 +1,14 @@
import { spawnSync } from 'node:child_process';
-import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
import {
oxlintFixtureArgs,
readEnabledRuleIds,
readRegisteredRuleNames,
readRuleScope,
-} from '../../../../test-support/read-ok-rules-config.test-helper';
+} from '../../../test-support/read-ok-rules-config.test-helper.ts';
-const REPO_ROOT = join(__dirname, '..', '..', '..', '..');
+const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
const FIXTURE_REL = 'lint-plugins/ok-rules/__fixtures__/require-windowshide-on-spawn.fixture.tsx';
describe('require-windowshide-on-spawn oxlint rule', () => {
diff --git a/package.json b/package.json
index 4fa99fde1..7511c93ff 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"check:drift:guards": "bash scripts/check-husky-prepare-guard.sh && bash scripts/check-knip-clean.sh && bash scripts/check-notices-clean.sh && bash scripts/check-schema-snapshot-clean.sh && bash scripts/check-i18n-drift.sh && node scripts/check-i18n-new-string-translations.mjs && node scripts/check-i18n-picker-completeness.mjs && bash scripts/check-no-major-changeset.sh && node scripts/check-override-floors.mjs && node scripts/check-typescript-resolution.mjs",
"typecheck": "turbo run typecheck",
"test": "turbo run test",
+ "test:uncached": "vitest run --config vitest.uncached.config.ts",
"test:vitest-selftest": "vitest run",
"smoke:share-v2": "node --import tsx --conditions=development packages/server/share-v2-smoke.ts",
"lint": "pnpm run lint:biome && pnpm run lint:oxlint",
diff --git a/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts b/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts
index b1fb3cca6..6265ca6d5 100644
--- a/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts
+++ b/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts
@@ -13,16 +13,11 @@ const CORPUS_DIRS = [
'lint-plugins/ok-rules',
'packages/app/tests/lint-plugins',
'packages/app/src/lint-plugins',
- 'packages/server/src/lint-plugins',
'packages/md-conformance/src/lint-plugins',
'packages/md-conformance/src/contracts',
];
-const TEST_DIRS = [
- 'packages/app/tests/integration',
- 'packages/server/src',
- 'packages/desktop/tests/integration',
-];
+const TEST_DIRS = ['packages/app/tests/integration', 'packages/desktop/tests/integration'];
const RETIRED = /gritql|\.grit\b|biome-plugins|bun run/i;
diff --git a/packages/server/src/agent-plugins-conformance.test.ts b/packages/server/src/agent-plugins-conformance.uncached.test.ts
similarity index 100%
rename from packages/server/src/agent-plugins-conformance.test.ts
rename to packages/server/src/agent-plugins-conformance.uncached.test.ts
diff --git a/packages/server/src/agent-write-spine-walk-root-coverage-contract.test.ts b/packages/server/src/agent-write-spine-walk-root-coverage-contract.uncached.test.ts
similarity index 100%
rename from packages/server/src/agent-write-spine-walk-root-coverage-contract.test.ts
rename to packages/server/src/agent-write-spine-walk-root-coverage-contract.uncached.test.ts
diff --git a/packages/server/src/error-log-discipline.test.ts b/packages/server/src/error-log-discipline.uncached.test.ts
similarity index 98%
rename from packages/server/src/error-log-discipline.test.ts
rename to packages/server/src/error-log-discipline.uncached.test.ts
index f23881774..37611303a 100644
--- a/packages/server/src/error-log-discipline.test.ts
+++ b/packages/server/src/error-log-discipline.uncached.test.ts
@@ -140,7 +140,7 @@ describe('error-log payload discipline (server + cli + desktop main)', () => {
`name/message/stack; \`err.message\` / \`String(err)\` discard the stack the JSONL ` +
`bundle needs. For a site where a string copy is genuinely intended, suffix the line ` +
`with \`// ${MARKER} <why>\` or add a FILE_ALLOWLIST entry in ` +
- `error-log-discipline.test.ts:\n${violations.join('\n')}`,
+ `error-log-discipline.uncached.test.ts:\n${violations.join('\n')}`,
);
}
});
diff --git a/packages/server/src/init-project-dogfood.uncached.test.ts b/packages/server/src/init-project-dogfood.uncached.test.ts
new file mode 100644
index 000000000..6660f92cb
--- /dev/null
+++ b/packages/server/src/init-project-dogfood.uncached.test.ts
@@ -0,0 +1,61 @@
+import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join, resolve } from 'node:path';
+import { OK_DIR } from '@inkeep/open-knowledge-core';
+import { describe, expect, it } from 'vitest';
+import { initContent, OK_OKIGNORE_TEMPLATE } from './init-project.ts';
+
+function findCommittedDogfoodFile(relativePath: string): string | null {
+ let dir = import.meta.dirname;
+ while (dir !== '/' && !existsSync(join(dir, relativePath))) {
+ dir = dirname(dir);
+ }
+ return dir === '/' ? null : join(dir, relativePath);
+}
+
+const COMMITTED_OK_GITIGNORE = findCommittedDogfoodFile(join('.ok', '.gitignore'));
+const COMMITTED_OKIGNORE = findCommittedDogfoodFile('.okignore');
+
+describe.runIf(COMMITTED_OK_GITIGNORE !== null)(
+ 'committed .ok/.gitignore matches scaffold output',
+ () => {
+ it('matches OK_GITIGNORE_CONTENT byte-for-byte', () => {
+ const tmp = resolve(
+ tmpdir(),
+ `gitignore-mirror-${Date.now()}-${Math.random().toString(36).slice(2)}`,
+ );
+ mkdirSync(tmp, { recursive: true });
+ try {
+ initContent(tmp);
+ const scaffolded = readFileSync(join(tmp, OK_DIR, '.gitignore'), 'utf-8');
+ const committed = readFileSync(COMMITTED_OK_GITIGNORE as string, 'utf-8');
+ expect(committed).toBe(scaffolded);
+ } finally {
+ rmSync(tmp, { recursive: true, force: true });
+ }
+ });
+ },
+);
+
+describe.runIf(COMMITTED_OKIGNORE !== null)('committed .okignore matches scaffold output', () => {
+ it('starts with OK_OKIGNORE_TEMPLATE byte-for-byte', () => {
+ const tmp = resolve(
+ tmpdir(),
+ `okignore-mirror-${Date.now()}-${Math.random().toString(36).slice(2)}`,
+ );
+ mkdirSync(tmp, { recursive: true });
+ try {
+ initContent(tmp);
+ const scaffolded = readFileSync(join(tmp, '.okignore'), 'utf-8');
+ expect(scaffolded).toBe(OK_OKIGNORE_TEMPLATE);
+ const committed = readFileSync(COMMITTED_OKIGNORE as string, 'utf-8');
+ expect(
+ committed.startsWith(OK_OKIGNORE_TEMPLATE),
+ `committed .okignore (${COMMITTED_OKIGNORE}) must start with OK_OKIGNORE_TEMPLATE ` +
+ 'byte-for-byte; repo-local exclusions may only be appended below the scaffold block',
+ ).toBe(true);
+ } finally {
+ rmSync(tmp, { recursive: true, force: true });
+ }
+ });
+});
diff --git a/packages/server/src/init-project.test.ts b/packages/server/src/init-project.test.ts
index 07a28b59e..d90e4c348 100644
--- a/packages/server/src/init-project.test.ts
+++ b/packages/server/src/init-project.test.ts
@@ -10,7 +10,7 @@ import {
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
-import { dirname, join, resolve } from 'node:path';
+import { join, resolve } from 'node:path';
import {
OK_DIR,
OK_MACHINE_LOCAL_ROOT_DIRS,
@@ -20,7 +20,6 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import {
buildConfigYmlContent,
initContent,
- OK_OKIGNORE_TEMPLATE,
packageVersionMajorMinor,
ROOT_GITIGNORE_TEMPLATE,
removeProjectSkillGitignoreBlock,
@@ -245,61 +244,6 @@ describe('initContent', () => {
});
});
-function findCommittedDogfoodFile(relativePath: string): string | null {
- let dir = import.meta.dirname;
- while (dir !== '/' && !existsSync(join(dir, relativePath))) {
- dir = dirname(dir);
- }
- return dir === '/' ? null : join(dir, relativePath);
-}
-
-const COMMITTED_OK_GITIGNORE = findCommittedDogfoodFile(join('.ok', '.gitignore'));
-const COMMITTED_OKIGNORE = findCommittedDogfoodFile('.okignore');
-
-describe.runIf(COMMITTED_OK_GITIGNORE !== null)(
- 'committed .ok/.gitignore matches scaffold output',
- () => {
- it('matches OK_GITIGNORE_CONTENT byte-for-byte', () => {
- const tmp = resolve(
- tmpdir(),
- `gitignore-mirror-${Date.now()}-${Math.random().toString(36).slice(2)}`,
- );
- mkdirSync(tmp, { recursive: true });
- try {
- initContent(tmp);
- const scaffolded = readFileSync(join(tmp, OK_DIR, '.gitignore'), 'utf-8');
- const committed = readFileSync(COMMITTED_OK_GITIGNORE as string, 'utf-8');
- expect(committed).toBe(scaffolded);
- } finally {
- rmSync(tmp, { recursive: true, force: true });
- }
- });
- },
-);
-
-describe.runIf(COMMITTED_OKIGNORE !== null)('committed .okignore matches scaffold output', () => {
- it('starts with OK_OKIGNORE_TEMPLATE byte-for-byte', () => {
- const tmp = resolve(
- tmpdir(),
- `okignore-mirror-${Date.now()}-${Math.random().toString(36).slice(2)}`,
- );
- mkdirSync(tmp, { recursive: true });
- try {
- initContent(tmp);
- const scaffolded = readFileSync(join(tmp, '.okignore'), 'utf-8');
- expect(scaffolded).toBe(OK_OKIGNORE_TEMPLATE);
- const committed = readFileSync(COMMITTED_OKIGNORE as string, 'utf-8');
- expect(
- committed.startsWith(OK_OKIGNORE_TEMPLATE),
- `committed .okignore (${COMMITTED_OKIGNORE}) must start with OK_OKIGNORE_TEMPLATE ` +
- 'byte-for-byte; repo-local exclusions may only be appended below the scaffold block',
- ).toBe(true);
- } finally {
- rmSync(tmp, { recursive: true, force: true });
- }
- });
-});
-
describe('writeRootGitignoreForNewRepo', () => {
let testDir: string;
diff --git a/packages/server/src/mcp/tools/cross-level-move-contract.test.ts b/packages/server/src/mcp/tools/cross-level-move-contract.uncached.test.ts
similarity index 100%
rename from packages/server/src/mcp/tools/cross-level-move-contract.test.ts
rename to packages/server/src/mcp/tools/cross-level-move-contract.uncached.test.ts
diff --git a/packages/server/src/mermaid-version-alignment.test.ts b/packages/server/src/mermaid-version-alignment.uncached.test.ts
similarity index 100%
rename from packages/server/src/mermaid-version-alignment.test.ts
rename to packages/server/src/mermaid-version-alignment.uncached.test.ts
diff --git a/packages/server/src/normalize-write-sink-gate.test.ts b/packages/server/src/normalize-write-sink-gate.uncached.test.ts
similarity index 100%
rename from packages/server/src/normalize-write-sink-gate.test.ts
rename to packages/server/src/normalize-write-sink-gate.uncached.test.ts
diff --git a/packages/server/src/package-exports.test.ts b/packages/server/src/package-exports.uncached.test.ts
similarity index 100%
rename from packages/server/src/package-exports.test.ts
rename to packages/server/src/package-exports.uncached.test.ts
diff --git a/packages/server/src/parse-pool.test.ts b/packages/server/src/parse-pool.test.ts
index 3140f37eb..202014490 100644
--- a/packages/server/src/parse-pool.test.ts
+++ b/packages/server/src/parse-pool.test.ts
@@ -288,55 +288,3 @@ describe('prepareAgentMarkdownParse end-to-end', () => {
expect(result).toBeUndefined();
});
});
-
-describe('worker entry ships in every bundle shape', () => {
- test('server tsdown config emits the parse-worker entry', () => {
- const config = readFileSync(resolve(__dirname, '../tsdown.config.ts'), 'utf8');
- expect(config).toMatch(/'parse-worker':\s*'src\/parse-worker\.ts'/);
- });
-
- test('cli tsdown config emits the parse-worker entry next to dist/cli.mjs', () => {
- const config = readFileSync(resolve(__dirname, '../../cli/tsdown.config.ts'), 'utf8');
- expect(config).toMatch(/'parse-worker':\s*'src\/parse-worker\.ts'/);
- });
-
- test('server package.json exports the parse-worker subpath for both conditions', () => {
- const pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8')) as {
- exports: Record<string, Record<string, string>>;
- };
- expect(pkg.exports['./parse-worker']).toEqual({
- '@inkeep/source': './src/parse-worker.ts',
- development: './src/parse-worker.ts',
- types: './dist/parse-worker.d.mts',
- default: './dist/parse-worker.mjs',
- });
- });
-
- test.each([
- ['@inkeep/open-knowledge-server', '../package.json'],
- ['@inkeep/open-knowledge-core', '../../core/package.json'],
- ])(
- '%s keeps every export subpath on the same four conditions in the same order',
- (_name, rel) => {
- const pkg = JSON.parse(readFileSync(resolve(__dirname, rel), 'utf8')) as {
- exports: Record<string, Record<string, string>>;
- };
- const subpaths = Object.entries(pkg.exports);
- expect(subpaths.length).toBeGreaterThan(0);
- for (const [subpath, entry] of subpaths) {
- expect(Object.keys(entry), `${rel} ${subpath} condition order`).toEqual([
- '@inkeep/source',
- 'development',
- 'types',
- 'default',
- ]);
- expect(entry['@inkeep/source'], `${rel} ${subpath} source vs development`).toBe(
- entry.development,
- );
- expect(entry.types, `${rel} ${subpath} types must resolve to a declaration`).toMatch(
- /\.d\.mts$/,
- );
- }
- },
- );
-});
diff --git a/packages/server/src/parse-worker-bundle.uncached.test.ts b/packages/server/src/parse-worker-bundle.uncached.test.ts
new file mode 100644
index 000000000..816599982
--- /dev/null
+++ b/packages/server/src/parse-worker-bundle.uncached.test.ts
@@ -0,0 +1,58 @@
+import { readFileSync } from 'node:fs';
+import { dirname, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { describe, expect, test } from 'vitest';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+
+describe('worker entry ships in every bundle shape', () => {
+ test('server tsdown config emits the parse-worker entry', () => {
+ const config = readFileSync(resolve(__dirname, '../tsdown.config.ts'), 'utf8');
+ expect(config).toMatch(/'parse-worker':\s*'src\/parse-worker\.ts'/);
+ });
+
+ test('cli tsdown config emits the parse-worker entry next to dist/cli.mjs', () => {
+ const config = readFileSync(resolve(__dirname, '../../cli/tsdown.config.ts'), 'utf8');
+ expect(config).toMatch(/'parse-worker':\s*'src\/parse-worker\.ts'/);
+ });
+
+ test('server package.json exports the parse-worker subpath for both conditions', () => {
+ const pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8')) as {
+ exports: Record<string, Record<string, string>>;
+ };
+ expect(pkg.exports['./parse-worker']).toEqual({
+ '@inkeep/source': './src/parse-worker.ts',
+ development: './src/parse-worker.ts',
+ types: './dist/parse-worker.d.mts',
+ default: './dist/parse-worker.mjs',
+ });
+ });
+
+ test.each([
+ ['@inkeep/open-knowledge-server', '../package.json'],
+ ['@inkeep/open-knowledge-core', '../../core/package.json'],
+ ])(
+ '%s keeps every export subpath on the same four conditions in the same order',
+ (_name, rel) => {
+ const pkg = JSON.parse(readFileSync(resolve(__dirname, rel), 'utf8')) as {
+ exports: Record<string, Record<string, string>>;
+ };
+ const subpaths = Object.entries(pkg.exports);
+ expect(subpaths.length).toBeGreaterThan(0);
+ for (const [subpath, entry] of subpaths) {
+ expect(Object.keys(entry), `${rel} ${subpath} condition order`).toEqual([
+ '@inkeep/source',
+ 'development',
+ 'types',
+ 'default',
+ ]);
+ expect(entry['@inkeep/source'], `${rel} ${subpath} source vs development`).toBe(
+ entry.development,
+ );
+ expect(entry.types, `${rel} ${subpath} types must resolve to a declaration`).toMatch(
+ /\.d\.mts$/,
+ );
+ }
+ },
+ );
+});
diff --git a/packages/server/src/producer-origin-gate.test.ts b/packages/server/src/producer-origin-gate.uncached.test.ts
similarity index 100%
rename from packages/server/src/producer-origin-gate.test.ts
rename to packages/server/src/producer-origin-gate.uncached.test.ts
diff --git a/packages/server/src/skill-linking-contract.test.ts b/packages/server/src/skill-linking-contract.uncached.test.ts
similarity index 100%
rename from packages/server/src/skill-linking-contract.test.ts
rename to packages/server/src/skill-linking-contract.uncached.test.ts
diff --git a/packages/server/src/validation-coverage-contract.test.ts b/packages/server/src/validation-coverage-contract.uncached.test.ts
similarity index 100%
rename from packages/server/src/validation-coverage-contract.test.ts
rename to packages/server/src/validation-coverage-contract.uncached.test.ts
diff --git a/scripts/check-server-test-inputs.mjs b/scripts/check-server-test-inputs.mjs
index f506fdfe9..050050283 100644
--- a/scripts/check-server-test-inputs.mjs
+++ b/scripts/check-server-test-inputs.mjs
@@ -2,6 +2,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
+import { isUncachedTestFile } from '../test-support/uncached-tier.ts';
const OK_ROOT = fileURLToPath(new URL('..', import.meta.url));
const PKG_REL = 'packages/server';
@@ -15,14 +16,8 @@ const QUOTED_SEGMENT = /'([^'\n]*)'|"([^"\n]*)"/g;
const DEPENDENCY_CLOSURE_PREFIXES = ['packages/core/'];
export const KNOWN_UNSWEPT = {
- '../../oxlint.config.ts':
- 'read inside test-support/read-ok-rules-config.test-helper.ts, which the walk does not enter',
- '../../lint-plugins/**':
- 'same helper, plus fixture paths built from a bare root-relative constant',
'../app/src/editor/observers.ts':
'bridge-no-wallclock.test.ts reaches it via a lowercase repoRoot and a root-relative literal',
- '../../AGENTS.md':
- 'no-sentinel-signal-target.test.ts reaches it through join(REPO_ROOT, AGENTS_REL), a named constant the sweep cannot resolve',
};
function walkTestFiles(dir, out = []) {
@@ -30,7 +25,7 @@ function walkTestFiles(dir, out = []) {
if (entry.name === 'node_modules' || entry.name === 'dist') continue;
const full = join(dir, entry.name);
if (entry.isDirectory()) walkTestFiles(full, out);
- else if (entry.name.endsWith('.test.ts')) out.push(full);
+ else if (entry.name.endsWith('.test.ts') && !isUncachedTestFile(entry.name)) out.push(full);
}
return out;
}
@@ -186,13 +181,17 @@ function main() {
`dependency closure. A change confined to one of them yields a cached PASS that\n` +
`executed nothing, and the remote cache shares that answer with every cell.\n\n` +
`${detail}\n\n` +
- `Fix: add a matching glob to \`${TASK}\`.inputs in public/open-knowledge/turbo.json.\n`,
+ `Fix: a test that reads files outside its package's key takes the \`.uncached.test\`\n` +
+ `suffix. Rename each reader to <name>.uncached.test.ts, and the uncached tier runs it\n` +
+ `every round, in CI's lint job and beside every \`turbo run test\` of this package.\n` +
+ `Add a matching glob to \`${TASK}\`.inputs in public/open-knowledge/turbo.json\n` +
+ `instead only if the whole server tier should re-run whenever that path changes.\n`,
);
process.exit(1);
}
console.log(
`check:server-test-inputs: OK - ${swept} cross-package path(s) DERIVED from ` +
- `packages/server/**/*.test.ts (quoted '../' literals and statically resolvable ` +
+ `packages/server/**/*.test.ts outside the uncached tier (quoted '../' literals and statically resolvable ` +
`join(<*ROOT*>, ...) calls) are declared inputs, plus ` +
`${Object.keys(KNOWN_UNSWEPT).length} pinned by name because their readers use ` +
`shapes this sweep does not recognise.`,
diff --git a/scripts/check-server-test-inputs.test.mjs b/scripts/check-server-test-inputs.test.mjs
index 8d7745c80..1869acd91 100644
--- a/scripts/check-server-test-inputs.test.mjs
+++ b/scripts/check-server-test-inputs.test.mjs
@@ -44,20 +44,43 @@ describe('check-server-test-inputs', () => {
expect(uncoveredReads()).toEqual([]);
});
- test('the sweep finds a non-trivial corpus, so a green is not vacuous', () => {
- expect(escapingReads().size).toBeGreaterThan(5);
+ test('the sweep finds a corpus, so a green is not vacuous', () => {
+ expect(escapingReads().size).toBeGreaterThan(0);
});
- test.each([
- ['../../docs/content/**', 'docs/content/'],
- ['../*/package.json', 'packages/app/package.json'],
- ['../cli/tsdown.config.ts', 'packages/cli/tsdown.config.ts'],
- ['../plugin/**', 'packages/plugin'],
- ['../../plugins/ok/**', 'plugins/ok'],
- ])('reds when %s is dropped from the task inputs', (glob, expectedTarget) => {
- const uncovered = uncoveredReads(fixtureRootWithout(glob));
- expect(uncovered.length).toBeGreaterThan(0);
- expect(uncovered.map((entry) => entry.target).join('\n')).toContain(expectedTarget);
+ test.each([['../../test-support/*.ts', 'test-support/']])(
+ 'reds when %s is dropped from the task inputs',
+ (glob, expectedTarget) => {
+ const uncovered = uncoveredReads(fixtureRootWithout(glob));
+ expect(uncovered.length).toBeGreaterThan(0);
+ expect(uncovered.map((entry) => entry.target).join('\n')).toContain(expectedTarget);
+ },
+ );
+
+ function fixtureRootReading(testFile) {
+ const root = mkdtempSync(join(tmpdir(), 'ok-server-inputs-'));
+ mkdirSync(join(root, 'packages/server/src'), { recursive: true });
+ mkdirSync(join(root, 'docs'), { recursive: true });
+ writeFileSync(join(root, 'docs/guide.md'), '');
+ writeFileSync(
+ join(root, 'packages/server/src', testFile),
+ "const guide = join(REPO_ROOT, 'docs', 'guide.md');\n",
+ );
+ writeFileSync(
+ join(root, 'turbo.json'),
+ JSON.stringify({ tasks: { [TASK]: { inputs: ['$TURBO_DEFAULT$'] } } }),
+ );
+ return root;
+ }
+
+ test('a read composed through join(<*ROOT*>, ...) is derived, not only a quoted ../ literal', () => {
+ expect(uncoveredReads(fixtureRootReading('reads-docs.test.ts'))).toEqual([
+ { target: 'docs/guide.md', readers: ['src/reads-docs.test.ts'] },
+ ]);
+ });
+
+ test('a test with the .uncached.test suffix is outside the sweep, because the uncached tier runs it', () => {
+ expect(uncoveredReads(fixtureRootReading('reads-docs.uncached.test.ts'))).toEqual([]);
});
test.each(Object.keys(KNOWN_UNSWEPT))(
@@ -111,17 +134,17 @@ describe('check-server-test-inputs', () => {
});
test('a KNOWN_UNSWEPT pin is satisfied by coverage, not by its exact spelling', () => {
- const root = fixtureRootWithout('../../lint-plugins/**');
+ const root = fixtureRootWithout('../app/src/editor/observers.ts');
const turboPath = join(root, 'turbo.json');
const turbo = JSON.parse(readFileSync(turboPath, 'utf-8'));
- turbo.tasks[TASK].inputs.push('../../**');
+ turbo.tasks[TASK].inputs.push('../app/src/**');
writeFileSync(turboPath, JSON.stringify(turbo, null, 2));
expect(missingKnownUnswept(root)).toEqual([]);
});
test('a KNOWN_UNSWEPT pin whose coverage is actually gone still reds', () => {
- expect(missingKnownUnswept(fixtureRootWithout('../../lint-plugins/**'))).toEqual([
- '../../lint-plugins/**',
+ expect(missingKnownUnswept(fixtureRootWithout('../app/src/editor/observers.ts'))).toEqual([
+ '../app/src/editor/observers.ts',
]);
});
@@ -137,3 +160,13 @@ describe('check-server-test-inputs', () => {
expect(run.stdout).toMatch(/check:server-test-inputs: OK/);
});
});
+
+describe('the uncached tier runs wherever server#test runs', () => {
+ test('server#test brings the uncached tier as its with sibling, and that tier is never cached', () => {
+ const turbo = JSON.parse(readFileSync(join(OK_ROOT, 'turbo.json'), 'utf-8'));
+ expect(turbo.tasks[TASK].with ?? []).toContain('//#test:uncached');
+ expect(turbo.tasks['//#test:uncached']).toMatchObject({ cache: false });
+ const pkg = JSON.parse(readFileSync(join(OK_ROOT, 'package.json'), 'utf-8'));
+ expect(pkg.scripts['test:uncached']).toBe('vitest run --config vitest.uncached.config.ts');
+ });
+});
diff --git a/test-support/setup-files-contract.test.ts b/test-support/setup-files-contract.test.ts
index 6e6c1af4f..aa416352c 100644
--- a/test-support/setup-files-contract.test.ts
+++ b/test-support/setup-files-contract.test.ts
@@ -29,6 +29,7 @@ const KNOWN_TEST_PROJECTS = [
'test-support/fixtures/no-net-connect/vitest.no-net-connect-fixture.config.ts',
'vitest.config.ts',
'vitest.scripts.config.ts',
+ 'vitest.uncached.config.ts',
];
const KNOWN_BUILD_CONFIGS = [
@@ -55,14 +56,31 @@ function findConfigs(): string[] {
.sort();
}
-async function resolveSetupFiles(relPath: string): Promise<string[]> {
+type TestOptions = { name?: unknown; setupFiles?: unknown; projects?: unknown };
+
+function setupFileList(setupFiles: unknown): string[] {
+ if (setupFiles === undefined) return [];
+ return (Array.isArray(setupFiles) ? setupFiles : [setupFiles]).map(String);
+}
+
+async function resolveSetupFiles(
+ relPath: string,
+): Promise<Array<{ project: string; setupFiles: string[] }>> {
const loaded: unknown = await import(pathToFileURL(join(REPO_ROOT, relPath)).href);
const exported = (loaded as { default?: unknown }).default ?? loaded;
const config =
typeof exported === 'function' ? await exported({ command: 'serve', mode: 'test' }) : exported;
- const setupFiles = (config as { test?: { setupFiles?: unknown } }).test?.setupFiles;
- if (setupFiles === undefined) return [];
- return (Array.isArray(setupFiles) ? setupFiles : [setupFiles]).map(String);
+ const test = (config as { test?: TestOptions }).test;
+ if (!Array.isArray(test?.projects)) {
+ return [{ project: relPath, setupFiles: setupFileList(test?.setupFiles) }];
+ }
+ return test.projects.map((project: unknown, index: number) => {
+ const inline = (project as { test?: TestOptions } | null)?.test;
+ return {
+ project: `${relPath} project ${String(inline?.name ?? index)}`,
+ setupFiles: setupFileList(inline?.setupFiles),
+ };
+ });
}
const configs = findConfigs();
@@ -105,14 +123,15 @@ describe('vitest setupFiles contract', () => {
test.each(configs.filter(isTestConfig))(
'%s resolves setupFiles containing every entry the shared base installs',
async (relPath) => {
- const setupFiles = await resolveSetupFiles(relPath);
- const missing = okVitestBase.test.setupFiles.filter((entry) => !setupFiles.includes(entry));
- expect(
- missing,
- `${relPath} omits ${missing.length} shared setup file(s); it resolves ` +
- `[${setupFiles.join(', ')}]. Build it from okVitestBase.test.setupFiles ` +
- 'rather than listing entries by hand.',
- ).toEqual([]);
+ for (const { project, setupFiles } of await resolveSetupFiles(relPath)) {
+ const missing = okVitestBase.test.setupFiles.filter((entry) => !setupFiles.includes(entry));
+ expect(
+ missing,
+ `${project} omits ${missing.length} shared setup file(s); it resolves ` +
+ `[${setupFiles.join(', ')}]. Build it from okVitestBase.test.setupFiles ` +
+ 'rather than listing entries by hand.',
+ ).toEqual([]);
+ }
},
);
});
diff --git a/test-support/uncached-tier-reconcile.test.ts b/test-support/uncached-tier-reconcile.test.ts
new file mode 100644
index 000000000..e16ae5ac2
--- /dev/null
+++ b/test-support/uncached-tier-reconcile.test.ts
@@ -0,0 +1,244 @@
+import { spawnSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join, resolve, win32 } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { afterEach, describe, expect, onTestFinished, test, vi } from 'vitest';
+import { createVitest, type TestProject } from 'vitest/node';
+import { gitCleanEnv } from '../scripts/git-clean-env.mjs';
+import tierConfig from '../vitest.uncached.config';
+import { listUncachedTestFiles, uncachedTierProblems } from './uncached-tier-reconcile';
+
+const roots: string[] = [];
+
+afterEach(() => {
+ while (roots.length > 0) rmSync(roots.pop() as string, { recursive: true, force: true });
+});
+
+function workspace(files: Record<string, string>): string {
+ const root = mkdtempSync(join(tmpdir(), 'ok-uncached-tier-'));
+ roots.push(root);
+ for (const [path, body] of Object.entries(files)) {
+ mkdirSync(dirname(join(root, path)), { recursive: true });
+ writeFileSync(join(root, path), body);
+ }
+ return root;
+}
+
+function git(root: string, args: string[]): void {
+ const result = spawnSync('git', args, {
+ cwd: root,
+ encoding: 'utf8',
+ env: {
+ ...gitCleanEnv(),
+ GIT_AUTHOR_NAME: 'fixture',
+ GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'fixture',
+ GIT_COMMITTER_EMAIL: '[email protected]',
+ },
+ });
+ expect(result.status, result.stderr).toBe(0);
+}
+
+const SERVER = 'packages/server/src/reads-app.uncached.test.ts';
+const server = (collected: string[]) => ({
+ name: 'packages/server/vitest.config.ts',
+ dir: 'packages/server',
+ collected,
+});
+const scripts = (collected: string[]) => ({
+ name: 'vitest.scripts.config.ts',
+ dir: '.',
+ collected,
+});
+const packages = () =>
+ workspace({
+ 'package.json': '{}',
+ 'packages/server/package.json': '{}',
+ 'packages/core/package.json': '{}',
+ });
+
+describe('the uncached tier reconciles the suffixed files git lists against what its projects collect', () => {
+ test('a listed file one project collects passes', () => {
+ expect(uncachedTierProblems(packages(), [SERVER], [server([SERVER]), scripts([])])).toEqual([]);
+ });
+
+ test('a listed file its covering project does not collect names that project config', () => {
+ expect(uncachedTierProblems(packages(), [SERVER], [server([]), scripts([])])).toEqual([
+ expect.stringContaining(
+ `${SERVER} takes the .uncached.test suffix and sits under packages/server, but that project's include and exclude do not collect it, so no tier would run it. Fix packages/server/vitest.config.ts's include or exclude`,
+ ),
+ ]);
+ });
+
+ test('a listed file in a package no project covers is misplaced', () => {
+ const misplaced = 'packages/core/src/reads-server.uncached.test.ts';
+ expect(
+ uncachedTierProblems(packages(), [SERVER, misplaced], [server([SERVER]), scripts([])]),
+ ).toEqual([
+ expect.stringContaining(
+ `${misplaced} takes the .uncached.test suffix, but no project here covers its package`,
+ ),
+ ]);
+ });
+
+ test('a file two projects collect runs twice, and fails', () => {
+ expect(
+ uncachedTierProblems(packages(), [SERVER], [server([SERVER]), scripts([SERVER])]),
+ ).toEqual([expect.stringContaining(`${SERVER} is collected by more than one project`)]);
+ });
+
+ test('a file the tier collects but git does not list fails, because CI would never see it', () => {
+ const ignored = 'packages/server/src/scratch/local.uncached.test.ts';
+ expect(
+ uncachedTierProblems(packages(), [SERVER], [server([SERVER, ignored]), scripts([])]),
+ ).toEqual([
+ expect.stringContaining(
+ `${ignored} takes the .uncached.test suffix and the tier collects it, but git ignores it`,
+ ),
+ ]);
+ });
+
+ test('an empty listing fails rather than passing having run nothing', () => {
+ expect(uncachedTierProblems(packages(), [], [server([]), scripts([])])).toEqual([
+ 'git lists no file with the .uncached.test suffix, so the tier would pass having run nothing.',
+ ]);
+ });
+});
+
+describe('reconcile() under win32 path semantics, where relative() emits backslashes', () => {
+ test('a listed file its covering project leaves uncollected is the only problem, and names that project', async () => {
+ const root = fileURLToPath(new URL('..', import.meta.url));
+ const listed = listUncachedTestFiles(root);
+ const inServer = (path: string) => path.startsWith('packages/server/');
+ const uncollected = listed.find(inServer);
+ expect(uncollected).toBeDefined();
+ const project = (name: string, dir: string, files: string[]) => ({
+ name,
+ config: { root: resolve(root, dir) },
+ globTestFiles: async () => ({ testFiles: files.map((file) => resolve(root, file)) }),
+ });
+ vi.doMock('node:path', () => {
+ const onWindows = { ...win32, join };
+ return { ...onWindows, default: onWindows };
+ });
+ onTestFinished(() => {
+ vi.doUnmock('node:path');
+ vi.resetModules();
+ });
+ vi.resetModules();
+ const { default: reconcile } = await import('./uncached-tier-reconcile');
+ const tier = {
+ vitest: {
+ projects: [
+ project(
+ 'packages/server/vitest.config.ts',
+ 'packages/server',
+ listed.filter((path) => inServer(path) && path !== uncollected),
+ ),
+ project(
+ 'vitest.scripts.config.ts',
+ '.',
+ listed.filter((path) => !inServer(path)),
+ ),
+ ],
+ config: {
+ projects: [
+ { test: { name: 'packages/server/vitest.config.ts' } },
+ { test: { name: 'vitest.scripts.config.ts' } },
+ ],
+ },
+ },
+ } as unknown as TestProject;
+ const failure = await reconcile(tier).catch((error: Error) => error);
+ expect(failure instanceof Error ? failure.message.split('\n ') : failure).toEqual([
+ 'vitest.uncached.config.ts:',
+ expect.stringContaining(
+ `${uncollected} takes the .uncached.test suffix and sits under packages/server, but that project's include and exclude do not collect it, so no tier would run it. Fix packages/server/vitest.config.ts's include or exclude`,
+ ),
+ ]);
+ });
+});
+
+describe('reconcile() over the real tier config, as Vitest resolves it under a --project filter', () => {
+ const root = fileURLToPath(new URL('..', import.meta.url));
+ const SERVER_PROJECT = 'packages/server/vitest.config.ts';
+ const SCRIPTS_PROJECT = 'vitest.scripts.config.ts';
+
+ async function reconcileUnder(project: string[] | undefined) {
+ const vitest = await createVitest('test', {
+ root,
+ config: 'vitest.uncached.config.ts',
+ watch: false,
+ ...(project === undefined ? {} : { project }),
+ });
+ try {
+ const resolved = vitest.projects.map(({ name }) => name).sort();
+ expect(resolved.length).toBeGreaterThan(0);
+ Reflect.deleteProperty(globalThis, Symbol.for('open-knowledge.uncached-tier.reconciled'));
+ const { default: reconcile } = await import('./uncached-tier-reconcile');
+ const failure = await reconcile(vitest.projects[0] as TestProject).then(
+ () => undefined,
+ (error: Error) => error,
+ );
+ return { resolved, failure };
+ } finally {
+ await vitest.close();
+ }
+ }
+
+ test.each([
+ { filter: [SCRIPTS_PROJECT], kept: [SCRIPTS_PROJECT] },
+ { filter: [`!${SCRIPTS_PROJECT}`], kept: [SERVER_PROJECT] },
+ ])(
+ 'a run narrowed by --project=$filter refuses once, naming the filter rather than SOURCES',
+ async ({ filter, kept }) => {
+ const { resolved, failure } = await reconcileUnder(filter);
+ expect(resolved).toEqual(kept);
+ expect(failure).toBeInstanceOf(Error);
+ const message = failure instanceof Error ? failure.message : '';
+ expect(message).toContain('--project');
+ expect(message).not.toContain('SOURCES');
+ expect(listUncachedTestFiles(root).filter((path) => message.includes(path))).toEqual([]);
+ },
+ );
+
+ test.each([
+ { filter: undefined },
+ { filter: ['*'] },
+ { filter: [SCRIPTS_PROJECT, SERVER_PROJECT] },
+ ])(
+ 'a run whose filter ($filter) keeps every declared project reconciles cleanly',
+ async ({ filter }) => {
+ const { resolved, failure } = await reconcileUnder(filter);
+ expect(resolved).toEqual([SERVER_PROJECT, SCRIPTS_PROJECT]);
+ expect(failure).toBeUndefined();
+ },
+ );
+});
+
+describe("the tier's discovery domain: what git lists, and what every project excludes", () => {
+ test('git lists tracked and untracked suffixed files, never an ignored one or one under node_modules', () => {
+ const root = workspace({
+ '.gitignore': 'node_modules/\nscratch/\n',
+ 'packages/server/src/tracked.uncached.test.ts': '',
+ 'packages/server/src/untracked.uncached.test.ts': '',
+ 'packages/server/src/scratch/ignored.uncached.test.ts': '',
+ 'packages/server/node_modules/vendored/vendored.uncached.test.ts': '',
+ 'packages/server/src/cached.test.ts': '',
+ });
+ git(root, ['init', '-q']);
+ git(root, ['add', '.gitignore', 'packages/server/src/tracked.uncached.test.ts']);
+ git(root, ['commit', '-qm', 'base']);
+ expect(listUncachedTestFiles(root).sort()).toEqual([
+ 'packages/server/src/tracked.uncached.test.ts',
+ 'packages/server/src/untracked.uncached.test.ts',
+ ]);
+ });
+
+ test('every tier project excludes node_modules, so a vendored suffixed file is in neither view', () => {
+ const projects = (tierConfig.test?.projects ?? []) as Array<{ test?: { exclude?: string[] } }>;
+ expect(projects.length).toBeGreaterThan(0);
+ for (const project of projects) expect(project.test?.exclude).toContain('**/node_modules/**');
+ });
+});
diff --git a/test-support/uncached-tier-reconcile.ts b/test-support/uncached-tier-reconcile.ts
new file mode 100644
index 000000000..0b5cf3511
--- /dev/null
+++ b/test-support/uncached-tier-reconcile.ts
@@ -0,0 +1,112 @@
+import { spawnSync } from 'node:child_process';
+import { existsSync } from 'node:fs';
+import { dirname, join, relative, sep } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import type { TestProject } from 'vitest/node';
+import { gitCleanEnv } from '../scripts/git-clean-env.mjs';
+import { UNCACHED_TEST_GLOBS } from './uncached-tier';
+
+const OK_ROOT = fileURLToPath(new URL('..', import.meta.url));
+const TIER = 'vitest.uncached.config.ts';
+const RECONCILED = Symbol.for('open-knowledge.uncached-tier.reconciled');
+
+export type UncachedTierProject = { name: string; dir: string; collected: string[] };
+
+export function listUncachedTestFiles(root: string): string[] {
+ const listed = spawnSync(
+ 'git',
+ [
+ 'ls-files',
+ '-z',
+ '--cached',
+ '--others',
+ '--exclude-standard',
+ '--',
+ ...UNCACHED_TEST_GLOBS.map((glob) => `:(glob)${glob}`),
+ ],
+ { cwd: root, encoding: 'utf8', env: gitCleanEnv(), windowsHide: true },
+ );
+ if (listed.error || listed.status !== 0) {
+ throw new Error(
+ `${TIER}: git ls-files could not list the suffixed test files (${listed.error?.message ?? listed.stderr.trim()}), so the tier cannot show that it runs every one of them. Run it from a git work tree.`,
+ );
+ }
+ return listed.stdout.split('\0').filter((path) => path !== '' && existsSync(join(root, path)));
+}
+
+function owningPackage(root: string, path: string): string {
+ let dir = dirname(path);
+ while (dir !== '.' && !existsSync(join(root, dir, 'package.json'))) dir = dirname(dir);
+ return dir;
+}
+
+export function uncachedTierProblems(
+ root: string,
+ listed: string[],
+ projects: UncachedTierProject[],
+): string[] {
+ const collectors = new Map<string, string[]>();
+ for (const { name, collected } of projects) {
+ for (const path of collected) collectors.set(path, [...(collectors.get(path) ?? []), name]);
+ }
+ const problems: string[] = [];
+ if (listed.length === 0) {
+ problems.push(
+ 'git lists no file with the .uncached.test suffix, so the tier would pass having run nothing.',
+ );
+ }
+ for (const path of listed) {
+ const names = collectors.get(path) ?? [];
+ if (names.length > 1) {
+ problems.push(
+ `${path} is collected by more than one project (${names.join(', ')}), so it runs twice. Narrow the include of all but one of those configs.`,
+ );
+ }
+ if (names.length > 0) continue;
+ const covering = projects.find(({ dir }) => dir === owningPackage(root, path));
+ problems.push(
+ covering === undefined
+ ? `${path} takes the .uncached.test suffix, but no project here covers its package, so no tier would run it (every cached tier excludes the suffix through test-support/vitest.base.ts). Add that package's Vitest config to SOURCES in ${TIER}, or drop the suffix if the test reads only files inside its package's key.`
+ : `${path} takes the .uncached.test suffix and sits under ${covering.dir}, but that project's include and exclude do not collect it, so no tier would run it. Fix ${covering.name}'s include or exclude so the uncached project collects it.`,
+ );
+ }
+ for (const path of collectors.keys()) {
+ if (!listed.includes(path)) {
+ problems.push(
+ `${path} takes the .uncached.test suffix and the tier collects it, but git ignores it, so it would run only locally and CI would never see it. Move it out of the ignored path, or drop the suffix.`,
+ );
+ }
+ }
+ return problems;
+}
+
+function gitPath(root: string, path: string): string {
+ return relative(root, path).split(sep).join('/');
+}
+
+export default async function reconcile(project: TestProject): Promise<void> {
+ const state = globalThis as unknown as Record<symbol, boolean | undefined>;
+ if (state[RECONCILED]) return;
+ state[RECONCILED] = true;
+ const declared = project.vitest.config.projects.length;
+ if (project.vitest.projects.length < declared) {
+ throw new Error(
+ `${TIER}: the --project filter (${project.vitest.config.project.join(', ')}) keeps ${project.vitest.projects.length} of the tier's ${declared} projects, so the tier cannot show that it runs every suffixed file git lists. Drop --project, and narrow the run with a file filter instead.`,
+ );
+ }
+ const listed = listUncachedTestFiles(OK_ROOT);
+ const projects = await Promise.all(
+ project.vitest.projects.map(async (each) => ({
+ name: each.name,
+ dir: gitPath(OK_ROOT, each.config.root) || '.',
+ collected: (await each.globTestFiles()).testFiles.map((file) => gitPath(OK_ROOT, file)),
+ })),
+ );
+ const problems = uncachedTierProblems(OK_ROOT, listed, projects);
+ console.log(
+ `uncached tier: ${listed.length} suffixed test files listed by git, ${new Set(projects.flatMap(({ collected }) => collected)).size} collected (${projects
+ .map(({ name, collected }) => `${name}: ${collected.length}`)
+ .join(', ')})`,
+ );
+ if (problems.length > 0) throw new Error(`${TIER}:\n ${problems.join('\n ')}`);
+}
diff --git a/test-support/uncached-tier.ts b/test-support/uncached-tier.ts
new file mode 100644
index 000000000..c0d671683
--- /dev/null
+++ b/test-support/uncached-tier.ts
@@ -0,0 +1,7 @@
+const EXTENSIONS = ['ts', 'tsx', 'mjs'];
+
+export const UNCACHED_TEST_GLOBS = EXTENSIONS.map((extension) => `**/*.uncached.test.${extension}`);
+
+export function isUncachedTestFile(path: string): boolean {
+ return EXTENSIONS.some((extension) => path.endsWith(`.uncached.test.${extension}`));
+}
diff --git a/test-support/vitest.base.ts b/test-support/vitest.base.ts
index 678bc4d99..3c5979d77 100644
--- a/test-support/vitest.base.ts
+++ b/test-support/vitest.base.ts
@@ -1,6 +1,7 @@
import { availableParallelism } from 'node:os';
import { fileURLToPath } from 'node:url';
import { configDefaults, type Plugin, type ViteUserConfig } from 'vitest/config';
+import { UNCACHED_TEST_GLOBS } from './uncached-tier';
const cpuCount = availableParallelism();
const boundedMaxForks =
@@ -41,7 +42,13 @@ export const okVitestBase = {
env: { DO_NOT_TRACK: '1' },
setupFiles: [bunGlobalShimPath, noNetConnectPath],
include: ['**/*.test.ts?(x)'],
- exclude: [...configDefaults.exclude, '**/*.spec.*', '**/*.e2e.*', '**/*.dom.test.ts?(x)'],
+ exclude: [
+ ...configDefaults.exclude,
+ '**/*.spec.*',
+ '**/*.e2e.*',
+ '**/*.dom.test.ts?(x)',
+ ...UNCACHED_TEST_GLOBS,
+ ],
...(boundedMaxForks === undefined ? {} : { minWorkers: 1, maxWorkers: boundedMaxForks }),
},
} satisfies ViteUserConfig;
diff --git a/turbo.json b/turbo.json
index 428e04481..093eebc14 100644
--- a/turbo.json
+++ b/turbo.json
@@ -52,6 +52,10 @@
"tsconfig.json"
]
},
+ "//#test:uncached": {
+ "cache": false,
+ "inputs": []
+ },
"@inkeep/open-knowledge#check:dts": {
"dependsOn": ["build"],
"inputs": [
@@ -122,26 +126,13 @@
"@inkeep/open-knowledge-server#test": {
"dependsOn": ["^build"],
"cache": true,
+ "with": ["//#test:uncached"],
"inputs": [
"$TURBO_DEFAULT$",
"!CHANGELOG.md",
"!README.md",
"../../test-support/*.ts",
- "../../oxlint.config.ts",
- "../../AGENTS.md",
- "../../lint-plugins/**",
- "../plugin/**",
- "../../plugins/ok/**",
- "../app/src/editor/observers.ts",
- "../cli/src/**",
- "!../cli/src/**/*.test.ts",
- "!../cli/src/**/*.test-helper.ts",
- "../cli/tsdown.config.ts",
- "../desktop/src/main/**",
- "!../desktop/src/main/**/*.test.ts",
- "!../desktop/src/main/**/*.test-helper.ts",
- "../*/package.json",
- "../../docs/content/**"
+ "../app/src/editor/observers.ts"
]
},
"@inkeep/open-knowledge#test": {
diff --git a/vitest.uncached.config.ts b/vitest.uncached.config.ts
new file mode 100644
index 000000000..ee11dfff0
--- /dev/null
+++ b/vitest.uncached.config.ts
@@ -0,0 +1,48 @@
+import { fileURLToPath } from 'node:url';
+import { defineConfig } from 'vitest/config';
+import serverConfig from './packages/server/vitest.config';
+import { UNCACHED_TEST_GLOBS } from './test-support/uncached-tier';
+import scriptsConfig from './vitest.scripts.config';
+
+const SOURCES = [
+ { name: 'packages/server/vitest.config.ts', dir: 'packages/server', config: serverConfig },
+ { name: 'vitest.scripts.config.ts', dir: '.', config: scriptsConfig },
+];
+
+const reconcile = fileURLToPath(
+ new URL('./test-support/uncached-tier-reconcile.ts', import.meta.url),
+);
+
+export default defineConfig({
+ test: {
+ projects: SOURCES.map(({ name, dir, config }) => {
+ const include = config.test?.include ?? [];
+ const exclude = config.test?.exclude ?? [];
+ const missing = UNCACHED_TEST_GLOBS.filter((glob) => !exclude.includes(glob));
+ if (missing.length > 0) {
+ throw new Error(
+ `vitest.uncached.config.ts: ${name} does not exclude ${missing.join(', ')}, so its cached tier would run the suffixed files too and could replay a stale pass. Spread okVitestBase.test.exclude into its exclude.`,
+ );
+ }
+ const suffixed = include.map((glob) => glob.replace(/\.test\.(?=[^/]*$)/, '.uncached.test.'));
+ const unsuffixed = suffixed.filter((glob) => !glob.includes('.uncached.test.'));
+ if (unsuffixed.length > 0) {
+ throw new Error(
+ `vitest.uncached.config.ts: ${name} includes ${unsuffixed.join(', ')}, which names no .test. segment, so the tier cannot derive the suffixed form of it. Name test files by their .test. segment in that include.`,
+ );
+ }
+ const globalSetup = config.test?.globalSetup ?? [];
+ return {
+ ...config,
+ root: fileURLToPath(new URL(`./${dir}/`, import.meta.url)),
+ test: {
+ ...config.test,
+ name,
+ include: suffixed,
+ exclude: exclude.filter((glob) => !UNCACHED_TEST_GLOBS.includes(glob)),
+ globalSetup: [reconcile, ...(Array.isArray(globalSetup) ? globalSetup : [globalSetup])],
+ },
+ };
+ }),
+ },
+});