MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / attachAndStore

Function attachAndStore

__tests__/liveness-watchdog-projects.test.ts:298–320  ·  view source on GitHub ↗

* Arm the watchdog for project A, as the daemon keyed on A arms it, attach * project B through the project lifecycle the daemon opens every * `projectPath` with, then store into B's index synchronously on the main * thread for 3s, as a long sync of B does. The graph object stands in for

(a: { db: string }, b: { root: string; db: string }, opts: { release?: boolean } = {})

Source from the content-addressed store, hash-verified

296 * CodeGraph: the lifecycle only watches, syncs and closes it.
297 */
298 function attachAndStore(a: { db: string }, b: { root: string; db: string }, opts: { release?: boolean } = {}): Promise<Outcome> {
299 return runChild(`
300 const { installMainThreadWatchdog } = require(${JSON.stringify(WATCHDOG)});
301 const { acquireProject } = require(${JSON.stringify(LIFECYCLE)});
302 const { DatabaseSync } = require('node:sqlite');
303 const graph = { watch: () => true, sync: async () => ({}), close() {}, isIndexing: () => false };
304 installMainThreadWatchdog({ progressPaths: [${JSON.stringify(a.db)}, ${JSON.stringify(`${a.db}-wal`)}] });
305 const lease = acquireProject(${JSON.stringify(b.root)}, () => graph, {});
306 lease.ready().then(async () => {
307 if (${opts.release ? 'true' : 'false'}) {
308 await lease.release();
309 await new Promise((resolve) => setTimeout(resolve, 50)); // dropped files re-arm on the next turn
310 }
311 require('fs').writeSync(1, 'BLOCKING\\n');
312 const db = new DatabaseSync(${JSON.stringify(b.db)});
313 db.exec('CREATE TABLE IF NOT EXISTS store_2404 (x BLOB)');
314 const end = Date.now() + 3000;
315 while (Date.now() < end) db.exec('INSERT INTO store_2404 VALUES (randomblob(2048))');
316 db.close();
317 process.exit(5);
318 });
319 `, 1000);
320 }
321
322 it('lets a long store into another project it now writes run to completion', async () => {
323 const a = makeProject();

Calls 1

runChildFunction · 0.70

Tested by

no test coverage detected