Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
perf(open-knowledge): cut server test-suite wall-time to clear the CI SIGTERM budget (#1888)
Nick Gomez5efe7b35a0d2
diff --git a/packages/server/src/api-rollback-rename-history.test.ts b/packages/server/src/api-rollback-rename-history.test.tsindex b9d5c505c..aa72a5f7b 100644--- a/packages/server/src/api-rollback-rename-history.test.ts+++ b/packages/server/src/api-rollback-rename-history.test.ts@@ -82,6 +82,17 @@ afterEach(() => {});describe('handleRollback — rename history mitigation (US-005)', () => {+ /** Strictly-increasing ISO commit timestamps (1s apart) so checkpoints and+ * the rename commit order deterministically without real-time ticks (git+ * committer dates are 1-second-granular). */+ function makeTick(startIso = '2026-05-05T12:00:00.000Z') {+ let t = Date.parse(startIso);+ return () => {+ t += 1000;+ return new Date(t).toISOString();+ };+ }+async function setup() {const projectDir = tmpDir;const contentDir = resolve(tmpDir, 'content');@@ -102,16 +113,18 @@ describe('handleRollback — rename history mitigation (US-005)', () => {name: 'Test',email: '[email protected]',};+ const at = makeTick();rmSync(resolve(contentDir, 'placeholder.md'));writeFileSync(resolve(contentDir, 'a.md'), '# A pre-rename\n');- const commitA = await commitWip(shadow, writer, 'content', 'WIP: a v1');- await saveVersion(shadow, 'content', [writer]);- await new Promise((r) => setTimeout(r, 1100));+ const commitA = await commitWip(shadow, writer, 'content', 'WIP: a v1', 'main', { date: at() });+ await saveVersion(shadow, 'content', [writer], 'main', undefined, { date: at() });rmSync(resolve(contentDir, 'a.md'));writeFileSync(resolve(contentDir, 'b.md'), '# B post-rename\n');- const renameCommit = await commitWip(shadow, writer, 'content', 'rename: a -> b');+ const renameCommit = await commitWip(shadow, writer, 'content', 'rename: a -> b', 'main', {+ date: at(),+ });const index = createEmptyIndex();appendRenameLogEntry(@@ -160,7 +173,7 @@ describe('handleRollback — rename history mitigation (US-005)', () => {return captured;};- return { shadow, contentDir, commitA, renameCommit, callRollback, docName, hocuspocus };+ return { shadow, contentDir, commitA, renameCommit, callRollback, docName, hocuspocus, at };}test('rollback to pre-rename commit (path a.md) → resolves via cycle bound, restores content, name unchanged', async () => {@@ -199,9 +212,8 @@ describe('handleRollback — rename history mitigation (US-005)', () => {});test('contamination case: SHA from a name-reuse cycle → 404, no shadow commit written', async () => {- const { shadow, contentDir, callRollback, docName } = await setup();+ const { shadow, contentDir, callRollback, docName, at } = await setup();- await new Promise((r) => setTimeout(r, 1100));rmSync(resolve(contentDir, 'b.md'));writeFileSync(resolve(contentDir, 'a.md'), '# A new (unrelated)\n');const writer: WriterIdentity = {@@ -209,8 +221,10 @@ describe('handleRollback — rename history mitigation (US-005)', () => {name: 'Test',email: '[email protected]',};- const newACommit = await commitWip(shadow, writer, 'content', 'WIP: new-a');- await saveVersion(shadow, 'content', [writer]);+ const newACommit = await commitWip(shadow, writer, 'content', 'WIP: new-a', 'main', {+ date: at(),+ });+ await saveVersion(shadow, 'content', [writer], 'main', undefined, { date: at() });const response = await callRollback({ docName, commitSha: newACommit });expect(response.status).toBe(404);diff --git a/packages/server/src/content/shadow-log.test.ts b/packages/server/src/content/shadow-log.test.tsindex db4c2318f..77d5c4194 100644--- a/packages/server/src/content/shadow-log.test.ts+++ b/packages/server/src/content/shadow-log.test.ts@@ -129,13 +129,17 @@ describe('readShadowLog — multi-writer merge', () => {const principal: WriterIdentity = { id: 'principal-b', name: 'B', email: '[email protected]' };writeFileSync(authPath, '# v1\n');- await commitWip(shadow, agent, contentDir, 'agent first', branch);- await wait(1100);+ await commitWip(shadow, agent, contentDir, 'agent first', branch, {+ date: '2026-05-05T12:00:01+00:00',+ });writeFileSync(authPath, '# v2\n');- await commitWip(shadow, principal, contentDir, 'principal second', branch);- await wait(1100);+ await commitWip(shadow, principal, contentDir, 'principal second', branch, {+ date: '2026-05-05T12:00:02+00:00',+ });writeFileSync(authPath, '# v3\n');- await commitWip(shadow, agent, contentDir, 'agent third', branch);+ await commitWip(shadow, agent, contentDir, 'agent third', branch, {+ date: '2026-05-05T12:00:03+00:00',+ });const { commits } = await readShadowLog(project, 'content/auth.md', 10);expect(commits.length).toBe(3);@@ -159,8 +163,9 @@ describe('readShadowLog — multi-writer merge', () => {for (let i = 0; i < 4; i++) {writeFileSync(authPath, `# v${i}\n`);- await commitWip(shadow, writer, contentDir, `edit ${i}`, branch);- await wait(1100);+ await commitWip(shadow, writer, contentDir, `edit ${i}`, branch, {+ date: `2026-05-05T12:00:0${i + 1}+00:00`,+ });}const { commits } = await readShadowLog(project, 'content/auth.md', 2);diff --git a/packages/server/src/rename-log.test.ts b/packages/server/src/rename-log.test.tsindex c3da2e25b..14ebb0764 100644--- a/packages/server/src/rename-log.test.ts+++ b/packages/server/src/rename-log.test.ts@@ -483,11 +483,23 @@ describe('rename-log read primitives (shadow-repo backed)', () => {return top;}- async function commit(text: string, file: string, msg: string): Promise<string> {+ async function commit(text: string, file: string, msg: string, date?: string): Promise<string> {const path = resolve(contentRoot, file);mkdirSync(resolve(path, '..'), { recursive: true });writeFileSync(path, text);- return commitWip(shadow, writer, 'content', msg);+ return commitWip(shadow, writer, 'content', msg, 'main', date ? { date } : undefined);+ }++ async function save(date?: string): Promise<unknown> {+ return saveVersion(shadow, 'content', [writer], 'main', undefined, date ? { date } : undefined);+ }++ function makeTick(startIso = '2026-05-05T12:00:00.000Z') {+ let t = Date.parse(startIso);+ return () => {+ t += 1000;+ return new Date(t).toISOString();+ };}beforeEach(async () => {@@ -578,18 +590,16 @@ describe('rename-log read primitives (shadow-repo backed)', () => {});test('buildSeeds — checkpoint earlier than R → included; checkpoint later than R → excluded', async () => {- await commit('# A v1\n', 'a.md', 'WIP: a v1');- await saveVersion(shadow, 'content', [writer]);- const k1 = await checkpointSha('main');-- await new Promise((r) => setTimeout(r, 1100));+ const at = makeTick();- const renameSha = await commit('# A v2 — rename\n', 'a.md', 'rename: a -> b');+ await commit('# A v1\n', 'a.md', 'WIP: a v1', at());+ await save(at());+ const k1 = await checkpointSha('main');- await new Promise((r) => setTimeout(r, 1100));+ const renameSha = await commit('# A v2 — rename\n', 'a.md', 'rename: a -> b', at());- await commit('# B v1\n', 'b.md', 'WIP: b');- await saveVersion(shadow, 'content', [writer]);+ await commit('# B v1\n', 'b.md', 'WIP: b', at());+ await save(at());const k2 = await checkpointSha('main');const seeds = await buildSeeds(shadow, renameSha, 'main');@@ -648,12 +658,12 @@ describe('rename-log read primitives (shadow-repo backed)', () => {});test('resolveDocPathAtCommit — renamed doc, sha at predecessor name → returns historical path', async () => {- const commitA = await commit('# A pre-rename\n', 'a.md', 'WIP: a');- await saveVersion(shadow, 'content', [writer]);+ const at = makeTick();- await new Promise((r) => setTimeout(r, 1100));+ const commitA = await commit('# A pre-rename\n', 'a.md', 'WIP: a', at());+ await save(at());- const renameCommit = await commit('# B post-rename\n', 'b.md', 'rename: a -> b');+ const renameCommit = await commit('# B post-rename\n', 'b.md', 'rename: a -> b', at());const index = createEmptyIndex();appendRenameLogEntry(@@ -674,18 +684,18 @@ describe('rename-log read primitives (shadow-repo backed)', () => {});test('resolveDocPathAtCommit — name-reuse contamination rejected by cycle bound', async () => {- await commit('# A old\n', 'a.md', 'WIP: a');- await saveVersion(shadow, 'content', [writer]);- await new Promise((r) => setTimeout(r, 1100));+ const at = makeTick();++ await commit('# A old\n', 'a.md', 'WIP: a', at());+ await save(at());rmSync(resolve(contentRoot, 'a.md'));- const renameCommit = await commit('# B fresh\n', 'b.md', 'rename: a -> b');- await saveVersion(shadow, 'content', [writer]);- await new Promise((r) => setTimeout(r, 1100));+ const renameCommit = await commit('# B fresh\n', 'b.md', 'rename: a -> b', at());+ await save(at());rmSync(resolve(contentRoot, 'b.md'));- const newACommit = await commit('# A new (unrelated)\n', 'a.md', 'WIP: new-a');- await saveVersion(shadow, 'content', [writer]);+ const newACommit = await commit('# A new (unrelated)\n', 'a.md', 'WIP: new-a', at());+ await save(at());const index = createEmptyIndex();appendRenameLogEntry(diff --git a/packages/server/src/server-factory.test.ts b/packages/server/src/server-factory.test.tsindex c586c592e..a8e15ac40 100644--- a/packages/server/src/server-factory.test.ts+++ b/packages/server/src/server-factory.test.ts@@ -1880,12 +1880,17 @@ describe('createServer() — phantom-doc unload', () => {expect(server.hocuspocus.documents.has(docName)).toBe(true);await conn.disconnect();- await new Promise((r) => setTimeout(r, 500));+ const controlName = 'phantom-control';+ const controlConn = await server.hocuspocus.openDirectConnection(controlName);+ await controlConn.disconnect();+ const controlUnloaded = await waitForUnload(server, controlName, 2_000);+ expect(controlUnloaded).toBe(true);+expect(server.hocuspocus.documents.has(docName)).toBe(true);} finally {await server.destroy();}- });+ }, 15_000);test('transient doc with CRDT content but no disk file stays resident', async () => {const server = createServer({diff --git a/packages/server/src/shadow-repo.ts b/packages/server/src/shadow-repo.tsindex 6fbf80d7d..e13cb19b8 100644--- a/packages/server/src/shadow-repo.ts+++ b/packages/server/src/shadow-repo.ts@@ -220,12 +220,17 @@ export async function sweepLegacyShadowRefs(shadow: ShadowHandle): Promise<numbereturn deleted;}+export interface CommitWipOptions {+ date?: string;+}+export async function commitWip(shadow: ShadowHandle,writer: WriterIdentity,contentRoot: string,message: string,branch = 'main',+ opts?: CommitWipOptions,): Promise<string> {return withSpan('shadow.commitWip',@@ -235,7 +240,7 @@ export async function commitWip('shadow.branch': branch,},},- async () => commitWipInner(shadow, writer, contentRoot, message, branch),+ async () => commitWipInner(shadow, writer, contentRoot, message, branch, opts?.date),);}@@ -245,6 +250,7 @@ async function commitWipInner(contentRoot: string,message: string,branch = 'main',+ date?: string,): Promise<string> {const tmpIndex = resolve(shadow.gitDir, `index-wip-${writer.id}`);const ref = `refs/wip/${branch}/${writer.id}`;@@ -289,17 +295,18 @@ async function commitWipInner(const args = ['commit-tree', treeSha, '-m', message];if (parentSha) args.push('-p', parentSha);- const commitSha = (- await sg- .env({- GIT_DIR: shadow.gitDir,- GIT_AUTHOR_NAME: writer.name,- GIT_AUTHOR_EMAIL: writer.email,- GIT_COMMITTER_NAME: 'openknowledge',- GIT_COMMITTER_EMAIL: '[email protected]',- })- .raw(...args)- ).trim();+ const commitEnv: Record<string, string> = {+ GIT_DIR: shadow.gitDir,+ GIT_AUTHOR_NAME: writer.name,+ GIT_AUTHOR_EMAIL: writer.email,+ GIT_COMMITTER_NAME: 'openknowledge',+ GIT_COMMITTER_EMAIL: '[email protected]',+ };+ if (date) {+ commitEnv.GIT_AUTHOR_DATE = date;+ commitEnv.GIT_COMMITTER_DATE = date;+ }+ const commitSha = (await sg.env(commitEnv).raw(...args)).trim();await sg.raw('update-ref', ref, commitSha);return commitSha;@@ -978,6 +985,7 @@ export interface SaveVersionOptions {checkpointKind?: { foldedRefs: number; trigger: AutoConsolidationTrigger };includeUpstream?: boolean;timeoutMs?: number;+ date?: string;}export async function saveVersion(@@ -1084,17 +1092,18 @@ async function saveVersionInner(checkpointArgs.push('-p', p);}- const checkpointSha = (- await sg- .env({- GIT_DIR: shadow.gitDir,- GIT_AUTHOR_NAME: 'openknowledge',- GIT_AUTHOR_EMAIL: '[email protected]',- GIT_COMMITTER_NAME: 'openknowledge',- GIT_COMMITTER_EMAIL: '[email protected]',- })- .raw(...checkpointArgs)- ).trim();+ const checkpointEnv: Record<string, string> = {+ GIT_DIR: shadow.gitDir,+ GIT_AUTHOR_NAME: 'openknowledge',+ GIT_AUTHOR_EMAIL: '[email protected]',+ GIT_COMMITTER_NAME: 'openknowledge',+ GIT_COMMITTER_EMAIL: '[email protected]',+ };+ if (options?.date) {+ checkpointEnv.GIT_AUTHOR_DATE = options.date;+ checkpointEnv.GIT_COMMITTER_DATE = options.date;+ }+ const checkpointSha = (await sg.env(checkpointEnv).raw(...checkpointArgs)).trim();const checkpointRef = `refs/checkpoints/${branch}/${checkpointSha}`;await sg.raw('update-ref', checkpointRef, checkpointSha);diff --git a/packages/server/src/timeline-query.test.ts b/packages/server/src/timeline-query.test.tsindex 29780ad41..b21e97917 100644--- a/packages/server/src/timeline-query.test.ts+++ b/packages/server/src/timeline-query.test.ts@@ -22,6 +22,7 @@ import {type ParkableDoc,parkBranch,SERVICE_WRITER,+ type ShadowHandle,saveVersion,type WriterIdentity,} from './shadow-repo';@@ -67,6 +68,19 @@ const agent: WriterIdentity = {email: '[email protected]',};+function datedCommits(shadow: ShadowHandle) {+ let t = Date.parse('2026-05-05T12:00:00.000Z');+ const next = () => {+ t += 1000;+ return new Date(t).toISOString();+ };+ return {+ cw: (message: string) =>+ commitWip(shadow, human, 'content/docs', message, 'main', { date: next() }),+ sv: () => saveVersion(shadow, 'content/docs', [human], 'main', undefined, { date: next() }),+ };+}+describe('getDocumentHistory', () => {test('returns empty result when shadow has no commits', async () => {const { shadow } = await setup();@@ -384,20 +398,19 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {test('rename a → b: timeline of `b` includes pre-rename WIP commits at path `a`', async () => {const { contentDir, shadow } = await setup();+ const { cw, sv } = datedCommits(shadow);writeFileSync(resolve(contentDir, 'a.md'), '# A v1\n');- const aWipSha = await commitWip(shadow, human, 'content/docs', 'WIP: a v1');- await saveVersion(shadow, 'content/docs', [human]);-- await new Promise((r) => setTimeout(r, 1100));+ const aWipSha = await cw('WIP: a v1');+ await sv();rmSync(resolve(contentDir, 'a.md'));writeFileSync(resolve(contentDir, 'b.md'), '# B v1\n');- const renameSha = await commitWip(shadow, human, 'content/docs', 'rename: a -> b');- await saveVersion(shadow, 'content/docs', [human]);+ const renameSha = await cw('rename: a -> b');+ await sv();writeFileSync(resolve(contentDir, 'b.md'), '# B v2\n');- const bWipSha = await commitWip(shadow, human, 'content/docs', 'WIP: b v2');+ const bWipSha = await cw('WIP: b v2');const index = createEmptyIndex();appendRenameLogEntry(shadow.gitDir, entry({ from: 'a', to: 'b', commitSha: renameSha }), index);@@ -428,20 +441,20 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {test('chained A→B→C: timeline of `c` spans all three name epochs', async () => {const { contentDir, shadow } = await setup();+ const { cw, sv } = datedCommits(shadow);+writeFileSync(resolve(contentDir, 'a.md'), '# A\n');- const aSha = await commitWip(shadow, human, 'content/docs', 'WIP: a');- await saveVersion(shadow, 'content/docs', [human]);- await new Promise((r) => setTimeout(r, 1100));+ const aSha = await cw('WIP: a');+ await sv();rmSync(resolve(contentDir, 'a.md'));writeFileSync(resolve(contentDir, 'b.md'), '# B\n');- const renameAB = await commitWip(shadow, human, 'content/docs', 'rename: a -> b');- await saveVersion(shadow, 'content/docs', [human]);- await new Promise((r) => setTimeout(r, 1100));+ const renameAB = await cw('rename: a -> b');+ await sv();rmSync(resolve(contentDir, 'b.md'));writeFileSync(resolve(contentDir, 'c.md'), '# C\n');- const renameBC = await commitWip(shadow, human, 'content/docs', 'rename: b -> c');+ const renameBC = await cw('rename: b -> c');const index = createEmptyIndex();appendRenameLogEntry(shadow.gitDir, entry({ from: 'a', to: 'b', commitSha: renameAB }), index);@@ -458,21 +471,21 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {test('name-reuse contamination: timeline of `b` does NOT include new-`a` commits', async () => {const { contentDir, shadow } = await setup();+ const { cw, sv } = datedCommits(shadow);+writeFileSync(resolve(contentDir, 'a.md'), '# A old\n');- await commitWip(shadow, human, 'content/docs', 'WIP: a old');- await saveVersion(shadow, 'content/docs', [human]);- await new Promise((r) => setTimeout(r, 1100));+ await cw('WIP: a old');+ await sv();rmSync(resolve(contentDir, 'a.md'));writeFileSync(resolve(contentDir, 'b.md'), '# B\n');- const renameSha = await commitWip(shadow, human, 'content/docs', 'rename: a -> b');- await saveVersion(shadow, 'content/docs', [human]);- await new Promise((r) => setTimeout(r, 1100));+ const renameSha = await cw('rename: a -> b');+ await sv();rmSync(resolve(contentDir, 'b.md'));writeFileSync(resolve(contentDir, 'a.md'), '# A new (unrelated)\n');- const newASha = await commitWip(shadow, human, 'content/docs', 'WIP: new-a');- await saveVersion(shadow, 'content/docs', [human]);+ const newASha = await cw('WIP: new-a');+ await sv();const index = createEmptyIndex();appendRenameLogEntry(shadow.gitDir, entry({ from: 'a', to: 'b', commitSha: renameSha }), index);@@ -585,22 +598,22 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {test('per-step error isolation: failure on one predecessor preserves others', async () => {const { contentDir, shadow } = await setup();+ const { cw, sv } = datedCommits(shadow);+writeFileSync(resolve(contentDir, 'a.md'), '# A v1\n');- const aWipSha = await commitWip(shadow, human, 'content/docs', 'WIP: a v1');- await saveVersion(shadow, 'content/docs', [human]);- await new Promise((r) => setTimeout(r, 1100));+ const aWipSha = await cw('WIP: a v1');+ await sv();rmSync(resolve(contentDir, 'a.md'));writeFileSync(resolve(contentDir, 'b.md'), '# B v1\n');- await commitWip(shadow, human, 'content/docs', 'rename: a -> b');+ await cw('rename: a -> b');writeFileSync(resolve(contentDir, 'b.md'), '# B v2\n');- const bWipSha = await commitWip(shadow, human, 'content/docs', 'WIP: b v2');- await saveVersion(shadow, 'content/docs', [human]);- await new Promise((r) => setTimeout(r, 1100));+ const bWipSha = await cw('WIP: b v2');+ await sv();rmSync(resolve(contentDir, 'b.md'));writeFileSync(resolve(contentDir, 'c.md'), '# C v1\n');- const renameBC = await commitWip(shadow, human, 'content/docs', 'rename: b -> c');+ const renameBC = await cw('rename: b -> c');const index = createEmptyIndex();const bogusSha = '0123456789abcdef0123456789abcdef01234567';@@ -629,15 +642,16 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {test('checkpoint-only fast path: pre-rename checkpoint visible after rename', async () => {const { contentDir, shadow } = await setup();+ const { cw, sv } = datedCommits(shadow);+writeFileSync(resolve(contentDir, 'a.md'), '# A pre-rename\n');- await commitWip(shadow, human, 'content/docs', 'WIP: a');- await saveVersion(shadow, 'content/docs', [human]);- await new Promise((r) => setTimeout(r, 1100));+ await cw('WIP: a');+ await sv();rmSync(resolve(contentDir, 'a.md'));writeFileSync(resolve(contentDir, 'b.md'), '# B post-rename\n');- const renameSha = await commitWip(shadow, human, 'content/docs', 'rename: a -> b');- await saveVersion(shadow, 'content/docs', [human]);+ const renameSha = await cw('rename: a -> b');+ await sv();const index = createEmptyIndex();appendRenameLogEntry(shadow.gitDir, entry({ from: 'a', to: 'b', commitSha: renameSha }), index);