Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Fix async ownership for round child tests (#6604)
Nick Gomezc471ab8d79dc
diff --git a/knip.config.ts b/knip.config.tsindex e43118957..eb9727af8 100644--- a/knip.config.ts+++ b/knip.config.ts@@ -155,11 +155,15 @@ export default {'src/shadow-fixture-launch.test-helper.mjs',],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/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.tsindex a50b00123..4549c74b3 100644--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts@@ -1,3 +1,4 @@+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 6fcdc23f2..4fc2c11f9 100644--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts@@ -1,3 +1,4 @@+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 40b5cdfd6..9f2f6feb6 100644--- a/packages/app/tests/integration/interior-edit-freshness.test.ts+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts@@ -1,3 +1,4 @@+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 93666af70..2a085742b 100644--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts@@ -1,3 +1,4 @@+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 867598d34..878d5196b 100644--- a/packages/app/tests/integration/producer-guard-wiring.test.ts+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts@@ -1,3 +1,4 @@+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 0970ac12f..4ada3cf26 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,3 +1,4 @@+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 b632185e1..cbe2b705f 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,3 +1,4 @@+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 c530ce4ba..89bc9b4d9 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,3 +1,4 @@+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 d3767adc9..a78aeb0e4 100644--- a/packages/app/tests/integration/undo-after-rollback.test.ts+++ b/packages/app/tests/integration/undo-after-rollback.test.ts@@ -1,3 +1,4 @@+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 b076f955c..e7cc69c3f 100644--- a/packages/app/tests/integration/undo-recycle-reset.test.ts+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts@@ -1,3 +1,4 @@+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 7935e35f8..9ddcd0730 100644--- a/packages/app/tests/integration/undo-rederive-survival.test.ts+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts@@ -1,3 +1,4 @@+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/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.tsindex f4cc8a286..2a597ec3d 100644--- a/packages/core/src/bridge/compose.ts+++ b/packages/core/src/bridge/compose.ts@@ -1,3 +1,4 @@+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 e7e63f43d..ffd8fce06 100644--- a/packages/core/src/bridge/doc-boundary-space.ts+++ b/packages/core/src/bridge/doc-boundary-space.ts@@ -1,3 +1,4 @@+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 fc267cbea..fb0ba5a7c 100644--- a/packages/core/src/markdown/comment-promoter.ts+++ b/packages/core/src/markdown/comment-promoter.ts@@ -1,3 +1,4 @@+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 861003fb4..ae8cb390b 100644--- a/packages/core/src/markdown/merged-walker.ts+++ b/packages/core/src/markdown/merged-walker.ts@@ -1,3 +1,4 @@+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 4d3250d3a..8be632ba4 100644--- a/packages/core/src/markdown/safe-url.ts+++ b/packages/core/src/markdown/safe-url.ts@@ -1,3 +1,4 @@+export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');diff --git a/test-support/child-silence-bound.test-helper.ts b/test-support/child-silence-bound.test-helper.tsindex a10996003..9de7209ba 100644--- a/test-support/child-silence-bound.test-helper.ts+++ b/test-support/child-silence-bound.test-helper.ts@@ -1,14 +1,24 @@-import { spawn } from 'node:child_process';+import { type ChildProcess, spawn } from 'node:child_process';import type { EventEmitter } from 'node:events';-export type ChildRun = { status: number | null; signal: NodeJS.Signals | null; output: string };+export type ChildRun = {+ status: number | null;+ signal: NodeJS.Signals | null;+ stdout: string;+ stderr: string;+ output: string;+};export type ChildSilenceBoundOptions = {cwd: string;env: NodeJS.ProcessEnv;signal: AbortSignal;- silenceBoundMs: number;+ silenceBoundMs: number | null;outputLimitBytes: number;+ onSpawn?: (child: ChildProcess) => void;+ onClose?: (status: number | null, signal: NodeJS.Signals | null) => void;+ onStdout?: (chunk: string) => void;+ reportAbortOutput?: boolean;};export function watchForSilence(@@ -31,7 +41,17 @@ export function watchForSilence(export function runChildWithSilenceBound(file: string,args: ReadonlyArray<string>,- { cwd, env, signal, silenceBoundMs, outputLimitBytes }: ChildSilenceBoundOptions,+ {+ cwd,+ env,+ signal,+ silenceBoundMs,+ outputLimitBytes,+ onSpawn,+ onClose,+ onStdout,+ reportAbortOutput = false,+ }: ChildSilenceBoundOptions,): Promise<ChildRun> {return new Promise((resolveRun, rejectRun) => {const startedAt = performance.now();@@ -39,7 +59,7 @@ export function runChildWithSilenceBound(const stderr: string[] = [];const outputSoFar = () => `${stdout.join('')}\n${stderr.join('')}`;const describeStop = (reason: string) =>- `the harness stopped \`${[file, ...args].join(' ')}\` after ${Math.round(performance.now() - startedAt)} ms because it ${reason}; a stop by the harness is not the child's own verdict. Its output until the stop:\n${outputSoFar()}`;+ `the harness stopped \`${[file, ...args].join(' ')}\` after ${Math.round(performance.now() - startedAt)} ms because it ${reason}; a stop by the harness is not the child's own verdict. Its stdout until the stop:\n${stdout.join('')}\nIts stderr until the stop:\n${stderr.join('')}`;const stop = new AbortController();let stopReason: string | undefined;const stopChild = (reason: string) => {@@ -55,30 +75,60 @@ export function runChildWithSilenceBound(signal: AbortSignal.any([signal, stop.signal]),killSignal: 'SIGKILL',});+ onSpawn?.(child);let outputBytes = 0;- const collect = (chunks: string[]) => (chunk: string) => {+ const collect = (chunks: string[], onChunk?: (chunk: string) => void) => (chunk: string) => {chunks.push(chunk);outputBytes += Buffer.byteLength(chunk);if (outputBytes > outputLimitBytes) stopChild(`printed more than ${outputLimitBytes} bytes`);+ onChunk?.(chunk);};- child.stdout.setEncoding('utf8').on('data', collect(stdout));+ child.stdout.setEncoding('utf8').on('data', collect(stdout, onStdout));child.stderr.setEncoding('utf8').on('data', collect(stderr));- const release = watchForSilence([child.stdout, child.stderr], silenceBoundMs, () =>- stopChild(`printed nothing for ${silenceBoundMs} ms`),- );+ const release =+ silenceBoundMs === null+ ? () => {}+ : watchForSilence([child.stdout, child.stderr], silenceBoundMs, () =>+ stopChild(`printed nothing for ${silenceBoundMs} ms`),+ );+ const reportAbort = () => {+ stopChild(+ signal.reason instanceof Error+ ? `was aborted by its owner: ${signal.reason.message}`+ : 'was aborted by its owner',+ );+ };+ if (reportAbortOutput) {+ signal.addEventListener('abort', reportAbort, { once: true });+ if (signal.aborted) reportAbort();+ }child.on('error', (error) => {if (child.pid !== undefined) return;release();+ if (reportAbortOutput) signal.removeEventListener('abort', reportAbort);rejectRun(error);});child.on('close', (status, exitSignal) => {release();+ if (reportAbortOutput) signal.removeEventListener('abort', reportAbort);+ onClose?.(status, exitSignal);if (stopReason !== undefined) {- rejectRun(new Error(describeStop(stopReason)));+ rejectRun(+ new Error(+ describeStop(stopReason),+ signal.aborted ? { cause: signal.reason } : undefined,+ ),+ );} else if (signal.aborted) {rejectRun(signal.reason);} else {- resolveRun({ status, signal: exitSignal, output: outputSoFar() });+ resolveRun({+ status,+ signal: exitSignal,+ stdout: stdout.join(''),+ stderr: stderr.join(''),+ output: outputSoFar(),+ });}});});diff --git a/test-support/child-silence-bound.test.ts b/test-support/child-silence-bound.test.tsindex 7d172351f..500953949 100644--- a/test-support/child-silence-bound.test.ts+++ b/test-support/child-silence-bound.test.ts@@ -110,6 +110,8 @@ describe('runChildWithSilenceBound', () => {);expect(run.status).toBe(3);expect(run.signal).toBeNull();+ expect(run.stdout).toBe('to stdout\n');+ expect(run.stderr).toBe('to stderr\n');expect(run.output).toBe('to stdout\n\nto stderr\n');});