Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Fix TypeScript checks under deep temporary directories (#5601)

Nick Gomeza05d6a719cb4
diff --git a/docs/package.json b/docs/package.json
index 7003f82f3..c5c02c822 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -12,10 +12,10 @@
"test": "vitest run src && pnpm run test:real-source",
"test:real-source": "vitest run --config vitest.real-source.config.mts",
"typecheck": "next typegen && fumadocs-mdx && tsc --noEmit",
- "validate-link": "tsx scripts/validate-link.ts",
- "generate:og-wordmark": "tsx scripts/generate-og-wordmark.ts",
- "generate:brand-assets": "tsx scripts/generate-brand-assets.ts",
- "generate:component-docs": "tsx scripts/generate-component-docs.ts",
+ "validate-link": "node --import tsx scripts/validate-link.ts",
+ "generate:og-wordmark": "node --import tsx scripts/generate-og-wordmark.ts",
+ "generate:brand-assets": "node --import tsx scripts/generate-brand-assets.ts",
+ "generate:component-docs": "node --import tsx scripts/generate-component-docs.ts",
"postinstall": "fumadocs-mdx"
},
"dependencies": {
diff --git a/package.json b/package.json
index e3d046f1a..54ff24eda 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"postinstall": "node scripts/create-turbo-cache-key.mjs",
"knip": "turbo run build --filter=@inkeep/open-knowledge-server --filter=@inkeep/open-knowledge-core --output-logs=errors-only && knip",
"notices": "node scripts/generate-third-party-notices.mjs",
- "schema:dump": "tsx packages/core/scripts/dump-schema.ts",
+ "schema:dump": "node --import tsx packages/core/scripts/dump-schema.ts",
"build": "turbo run build",
"build:desktop": "turbo run build:desktop",
"build:desktop:dir": "turbo run build:desktop:dir",
diff --git a/packages/app/package.json b/packages/app/package.json
index f4d916e50..524733040 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -32,7 +32,7 @@
"test:integration:shard3": "vitest run --config vitest.integration.config.ts --shard=3/3",
"test:perf:sessions": "vitest run --config vitest.config.ts tests/integration/per-session-um-perf.test.ts --testTimeout 60000",
"test:conversion": "vitest run --config vitest.config.ts tests/conversion/",
- "test:stress:api": "tsx tests/stress/stress-api.ts",
+ "test:stress:api": "node --import tsx tests/stress/stress-api.ts",
"measure:fuzz": "bash scripts/measure-fuzz.sh",
"measure:stress": "bash scripts/measure-stress.sh",
"measure:sweep": "bash scripts/measure-sweep.sh",
@@ -43,14 +43,14 @@
"test:visual:update": "playwright test --config playwright.visual.config.ts --update-snapshots",
"test:perf": "vitest run tests/stress/component-blocks.perf.test.ts",
"test:a11y": "playwright test --config playwright.a11y.config.ts",
- "perf:fixtures": "tsx tests/perf/fixtures/generate.ts",
- "perf:profile": "tsx tests/perf/profile.ts",
- "sweep:cache-regime": "tsx tests/perf/profile.ts --scenario=sweep-cache-regime",
- "sweep:convention-cap-graduation": "tsx tests/perf/profile.ts --scenario=sweep-convention-cap-graduation",
- "probe:tiptap-leak": "tsx tests/perf/probes/tiptap-destroy-leak.ts",
- "gen:color-themes": "tsx scripts/gen-color-themes.ts",
- "audit:strings": "tsx scripts/audit-strings/extract.ts",
- "audit:strings:casing": "tsx scripts/audit-strings/check-casing.ts",
+ "perf:fixtures": "node --import tsx tests/perf/fixtures/generate.ts",
+ "perf:profile": "node --import tsx tests/perf/profile.ts",
+ "sweep:cache-regime": "node --import tsx tests/perf/profile.ts --scenario=sweep-cache-regime",
+ "sweep:convention-cap-graduation": "node --import tsx tests/perf/profile.ts --scenario=sweep-convention-cap-graduation",
+ "probe:tiptap-leak": "node --import tsx tests/perf/probes/tiptap-destroy-leak.ts",
+ "gen:color-themes": "node --import tsx scripts/gen-color-themes.ts",
+ "audit:strings": "node --import tsx scripts/audit-strings/extract.ts",
+ "audit:strings:casing": "node --import tsx scripts/audit-strings/check-casing.ts",
"size": "turbo run build --filter=@inkeep/open-knowledge-app && size-limit"
},
"size-limit": [
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 4a57dd698..7899896ef 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -42,7 +42,7 @@
"scripts": {
"build:cli": "rm -rf dist && tsdown",
"build:app": "cp -r ../app/dist dist/public",
- "build:skill-asset": "tsx scripts/build-skill-assets.ts",
+ "build:skill-asset": "node --import tsx scripts/build-skill-assets.ts",
"build:notices": "mkdir -p dist && cp ../../THIRD_PARTY_NOTICES.md dist/THIRD_PARTY_NOTICES.md",
"build:license": "mkdir -p dist && cp ../../LICENSE dist/LICENSE",
"build:native": "mkdir -p dist/native && cp ../native-config/index.js ../native-config/index.d.ts ../native-config/package.json ../native-config/*.node dist/native/",
diff --git a/packages/cli/scripts/build-skill-assets.test.ts b/packages/cli/scripts/build-skill-assets.test.ts
index b28669730..6bc6a76e9 100644
--- a/packages/cli/scripts/build-skill-assets.test.ts
+++ b/packages/cli/scripts/build-skill-assets.test.ts
@@ -1,4 +1,6 @@
+import { spawnSync } from 'node:child_process';
import {
+ copyFileSync,
cpSync,
existsSync,
mkdirSync,
@@ -6,12 +8,16 @@ import {
readdirSync,
readFileSync,
rmSync,
+ symlinkSync,
+ writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import { BUNDLE_IDS } from '@inkeep/open-knowledge-server';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
+import { createSocketPathOverflowingTempDir } from '../../../test-support/temp-dir.test-helper.ts';
+import { okVitestBase } from '../../../test-support/vitest.base';
import { composeSkillAssets, resolveSkillAssetPaths } from './build-skill-assets.ts';
const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
@@ -20,6 +26,7 @@ const SOURCE_SKILLS = join(SERVER_ROOT, 'assets', 'skills');
const SOURCE_PACKS = join(SOURCE_SKILLS, 'packs');
const SHIPPED_SKILLS = join(PACKAGE_ROOT, 'dist', 'assets', 'skills');
const DECOMPOSED_MEMBER = join('packs', 'software-lifecycle', 'write-a-spec', 'SKILL.md');
+const commandFixtures: string[] = [];
let scratchServerRoot: string;
let scratchCliRoot: string;
@@ -33,6 +40,66 @@ function sourcePackIds(): string[] {
.sort();
}
+function runSkillAssetCommand(depth: string) {
+ const root = mkdtempSync(join(tmpdir(), 'ca-'));
+ commandFixtures.push(root);
+ const cliRoot = join(root, 'cli');
+ const serverRoot = join(root, 'server');
+ for (const [sourceRoot, targetRoot, files] of [
+ [PACKAGE_ROOT, cliRoot, ['scripts/build-skill-assets.ts']],
+ [
+ SERVER_ROOT,
+ serverRoot,
+ [
+ 'scripts/build-skill-bundles.ts',
+ 'src/skill-bundles.ts',
+ 'src/skill-pack-sources.ts',
+ 'src/build-skill-zip.ts',
+ ],
+ ],
+ ] as const) {
+ for (const file of files) {
+ const target = join(targetRoot, file);
+ mkdirSync(dirname(target), { recursive: true });
+ copyFileSync(join(sourceRoot, file), target);
+ }
+ }
+ cpSync(SOURCE_SKILLS, join(serverRoot, 'assets', 'skills'), {
+ recursive: true,
+ dereference: true,
+ });
+ const { packageManager } = JSON.parse(
+ readFileSync(join(PACKAGE_ROOT, '../../package.json'), 'utf8'),
+ ) as { packageManager: string };
+ const manifest = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf8')) as {
+ scripts: Record<string, string>;
+ };
+ writeFileSync(
+ join(cliRoot, 'package.json'),
+ JSON.stringify({
+ private: true,
+ type: 'module',
+ packageManager,
+ scripts: { 'build:skill-asset': manifest.scripts['build:skill-asset'] },
+ }),
+ );
+ writeFileSync(
+ join(serverRoot, 'package.json'),
+ JSON.stringify({ private: true, type: 'module' }),
+ );
+ symlinkSync(join(PACKAGE_ROOT, '../../node_modules'), join(root, 'node_modules'), 'junction');
+ symlinkSync(join(SERVER_ROOT, 'node_modules'), join(serverRoot, 'node_modules'), 'junction');
+ const temporary = depth === 'deep' ? createSocketPathOverflowingTempDir(root) : join(root, 'tmp');
+ mkdirSync(temporary, { recursive: true });
+ const result = spawnSync('pnpm', ['run', 'build:skill-asset'], {
+ cwd: cliRoot,
+ env: { ...process.env, TMPDIR: temporary, TMP: temporary, TEMP: temporary },
+ encoding: 'utf8',
+ timeout: okVitestBase.test.testTimeout,
+ });
+ return { result, cliRoot, serverRoot };
+}
+
beforeAll(() => {
scratchRoot = mkdtempSync(join(tmpdir(), 'ok-cli-skill-assets-'));
scratchServerRoot = join(scratchRoot, 'server');
@@ -46,6 +113,7 @@ beforeAll(() => {
afterAll(() => {
if (scratchRoot) rmSync(scratchRoot, { recursive: true, force: true });
+ for (const root of commandFixtures) rmSync(root, { recursive: true, force: true });
});
describe('composing skill assets for a cli package root', () => {
@@ -88,11 +156,29 @@ describe('the default skill-asset paths', () => {
});
describe('the shipped build:skill-asset step', () => {
- it('runs the cli composer and nothing else', () => {
- const manifest = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf-8')) as {
- scripts: Record<string, string>;
- };
- expect(manifest.scripts['build:skill-asset']).toBe('tsx scripts/build-skill-assets.ts');
+ it.each(['ordinary', 'deep'])('runs the cli composer and nothing else (%s TMPDIR)', (depth) => {
+ const { result, cliRoot, serverRoot } = runSkillAssetCommand(depth);
+ const assets = join(cliRoot, 'dist', 'assets', 'skills');
+ const expectedFiles = [
+ ...BUNDLE_IDS.map((bundle) => join(assets, bundle, 'SKILL.md')),
+ ...sourcePackIds().map((pack) => join(assets, 'packs', pack, 'SKILL.md')),
+ join(assets, DECOMPOSED_MEMBER),
+ ];
+ const member = join(assets, DECOMPOSED_MEMBER);
+ expect(
+ {
+ status: result.status,
+ files: expectedFiles.filter((file) => existsSync(file)),
+ memberHasContent: existsSync(member) && readFileSync(member, 'utf8').length > 0,
+ serverDistExists: existsSync(join(serverRoot, 'dist')),
+ },
+ result.stderr,
+ ).toEqual({
+ status: 0,
+ files: expectedFiles,
+ memberHasContent: true,
+ serverDistExists: false,
+ });
});
it('leaves every bundle, pack and decomposed member in the built cli dist', () => {
diff --git a/packages/core/package.json b/packages/core/package.json
index fa7bbe896..170072d08 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -883,11 +883,11 @@
"test": "vitest run src/ tests/contract/ scripts/",
"test:perf:bench": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --expose-gc\" RUN_BENCH=1 vitest run tests/perf/markdown-bench.test.ts",
"test:perf:regression:unit": "vitest run tests/perf/regression-gate.test.ts",
- "test:perf:regression": "tsx tests/perf/run-regression-gate.ts",
+ "test:perf:regression": "node --import tsx tests/perf/run-regression-gate.ts",
"test:health:unit": "vitest run tests/health/parse-health-gate.test.ts",
- "test:health": "tsx tests/health/parse-health-gate.ts tests/health/baseline.json",
- "generate:lint-catalog": "tsx scripts/generate-markdownlint-catalog.ts && biome check --write src/markdown/lint/rule-catalog.generated.ts",
- "regen-schema-snapshot": "tsx scripts/regen-schema-snapshot.ts"
+ "test:health": "node --import tsx tests/health/parse-health-gate.ts tests/health/baseline.json",
+ "generate:lint-catalog": "node --import tsx scripts/generate-markdownlint-catalog.ts && biome check --write src/markdown/lint/rule-catalog.generated.ts",
+ "regen-schema-snapshot": "node --import tsx scripts/regen-schema-snapshot.ts"
},
"devDependencies": {
"@standard-schema/spec": "^1.1.0",
@@ -910,6 +910,7 @@
"micromark-util-symbol": "^2.0.1",
"tsdown": "^0.22.14",
"typescript": "~7.0.2",
+ "vitest": "^5.0.3",
"y-prosemirror": "1.3.7"
}
}
diff --git a/packages/core/tests/perf/regression-gate.test.ts b/packages/core/tests/perf/regression-gate.test.ts
index c82ca57c1..9499e6f2d 100644
--- a/packages/core/tests/perf/regression-gate.test.ts
+++ b/packages/core/tests/perf/regression-gate.test.ts
@@ -2,7 +2,10 @@ import { spawnSync } from 'node:child_process';
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { afterAll, describe, expect, test } from 'vitest';
-import { createTempDirFactory } from '../../../../test-support/temp-dir.test-helper.ts';
+import {
+ createSocketPathOverflowingTempDir,
+ createTempDirFactory,
+} from '../../../../test-support/temp-dir.test-helper.ts';
import { withForcedGc } from './gc.ts';
import {
ACCEPT_MISMATCH_FLAG,
@@ -30,7 +33,7 @@ import {
const makeTempDir = createTempDirFactory(afterAll);
function comparatorEnv(): NodeJS.ProcessEnv {
- const temporary = makeTempDir('ok-perf-cli-');
+ const temporary = createSocketPathOverflowingTempDir(makeTempDir('ok-perf-comparator-'));
return { ...process.env, TMPDIR: temporary, TMP: temporary, TEMP: temporary };
}
@@ -752,7 +755,16 @@ describe('the standalone comparator CLI surfaces methodology warnings and refuse
);
const result = spawnSync(
'pnpm',
- ['exec', 'tsx', join(PERF_DIR, script), COMMITTED_BASELINE_PATH, freshPath, ...extraArgs],
+ [
+ 'exec',
+ 'node',
+ '--import',
+ 'tsx',
+ join(PERF_DIR, script),
+ COMMITTED_BASELINE_PATH,
+ freshPath,
+ ...extraArgs,
+ ],
{ cwd: join(PERF_DIR, '..', '..'), encoding: 'utf8', env: comparatorEnv(), timeout: 30_000 },
);
if (result.error) {
@@ -780,7 +792,7 @@ describe('the standalone comparator CLI surfaces methodology warnings and refuse
);
const result = spawnSync(
'pnpm',
- ['exec', 'tsx', join(PERF_DIR, 'regression-gate.ts'), badPath, freshPath],
+ ['exec', 'node', '--import', 'tsx', join(PERF_DIR, 'regression-gate.ts'), badPath, freshPath],
{ cwd: join(PERF_DIR, '..', '..'), encoding: 'utf8', env: comparatorEnv(), timeout: 30_000 },
);
expect(result.status).toBe(EXIT_DATA);
@@ -791,7 +803,15 @@ describe('the standalone comparator CLI surfaces methodology warnings and refuse
function runComparator(baselinePath: string, freshPath: string) {
const result = spawnSync(
'pnpm',
- ['exec', 'tsx', join(PERF_DIR, 'regression-gate.ts'), baselinePath, freshPath],
+ [
+ 'exec',
+ 'node',
+ '--import',
+ 'tsx',
+ join(PERF_DIR, 'regression-gate.ts'),
+ baselinePath,
+ freshPath,
+ ],
{ cwd: join(PERF_DIR, '..', '..'), encoding: 'utf8', env: comparatorEnv(), timeout: 30_000 },
);
if (result.error) throw result.error;
@@ -882,7 +902,15 @@ describe('the standalone comparator CLI surfaces methodology warnings and refuse
writeFileSync(freshPath, JSON.stringify(freshFromBaseline(baseline)));
const result = spawnSync(
'pnpm',
- ['exec', 'tsx', join(PERF_DIR, 'regression-gate.ts'), baselinePath, freshPath],
+ [
+ 'exec',
+ 'node',
+ '--import',
+ 'tsx',
+ join(PERF_DIR, 'regression-gate.ts'),
+ baselinePath,
+ freshPath,
+ ],
{ cwd: join(PERF_DIR, '..', '..'), encoding: 'utf8', env: comparatorEnv(), timeout: 30_000 },
);
expect(result.stderr).not.toContain('INCONCLUSIVE');
diff --git a/packages/server/package.json b/packages/server/package.json
index 5699bcef8..9b06a2ba4 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -72,7 +72,7 @@
},
"scripts": {
"build": "tsdown && pnpm run build:skill-bundles",
- "build:skill-bundles": "tsx scripts/build-skill-bundles.ts",
+ "build:skill-bundles": "node --import tsx scripts/build-skill-bundles.ts",
"typecheck": "pnpm run typecheck:bash && pnpm run typecheck:test-helper-callers && tsc",
"test": "vitest run",
"test:network": "vitest run --config vitest.network.config.ts",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 24a34bb10..d0e3c8c94 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1155,6 +1155,9 @@ importers:
typescript:
specifier: ~7.0.2
version: 7.0.2
+ vitest:
+ specifier: ^5.0.3
y-prosemirror:
specifier: 1.3.7
version: 1.3.7(patch_hash=b77fc38bdf246f08f73b6bc5d12ec24d29408b663f0a4224758d3f776ef124e7)([email protected])([email protected])([email protected])([email protected]([email protected]))([email protected])
diff --git a/scripts/check-schema-snapshot-clean.sh b/scripts/check-schema-snapshot-clean.sh
index 59e1b527d..40178862d 100755
--- a/scripts/check-schema-snapshot-clean.sh
+++ b/scripts/check-schema-snapshot-clean.sh
@@ -6,4 +6,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$REPO_ROOT"
-pnpm exec tsx packages/core/scripts/dump-schema.ts --check
+pnpm exec node --import tsx packages/core/scripts/dump-schema.ts --check
diff --git a/test-support/temp-dir.test-helper.ts b/test-support/temp-dir.test-helper.ts
index b4b8ca72c..09da501cd 100644
--- a/test-support/temp-dir.test-helper.ts
+++ b/test-support/temp-dir.test-helper.ts
@@ -1,8 +1,11 @@
-import { mkdtempSync } from 'node:fs';
+import { Buffer } from 'node:buffer';
+import { mkdirSync, mkdtempSync } from 'node:fs';
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+const LARGEST_UNIX_SOCKET_PATH_BYTES = 108;
+
export async function withTempDir<T>(
prefix: string,
fn: (dir: string) => T | Promise<T>,
@@ -35,3 +38,12 @@ export function createTempDirFactory(
return path;
};
}
+
+export function createSocketPathOverflowingTempDir(parent: string): string {
+ let dir = join(parent, 'temporary-files-with-a-long-inherited-path');
+ while (Buffer.byteLength(dir) <= LARGEST_UNIX_SOCKET_PATH_BYTES) {
+ dir = join(dir, 'nested-directory-beyond-unix-socket-path-capacity');
+ }
+ mkdirSync(dir, { recursive: true });
+ return dir;
+}