diff --git a/apps/server/agent/accounts/usage.ts b/apps/server/agent/accounts/usage.ts index 9e70400..2f30372 100644 --- a/apps/server/agent/accounts/usage.ts +++ b/apps/server/agent/accounts/usage.ts @@ -221,7 +221,7 @@ export async function checkAccountHealth( // Ensure DB credentials are written to disk so file-based checks can find them if (account.configJson && account.credentials) { try { - setupAccountConfigDir(configDir, { + await setupAccountConfigDir(configDir, { configJson: JSON.parse(account.configJson), credentials: account.credentials, }); diff --git a/apps/server/agent/file-io.test.ts b/apps/server/agent/file-io.test.ts index 62d1b5e..42a66b9 100644 --- a/apps/server/agent/file-io.test.ts +++ b/apps/server/agent/file-io.test.ts @@ -147,7 +147,7 @@ describe('writeInputFiles', () => { }); describe('readSummary', () => { - it('reads SUMMARY.md with frontmatter', () => { + it('reads SUMMARY.md with frontmatter', async () => { const outputDir = join(testDir, '.cw', 'output'); mkdirSync(outputDir, { recursive: true }); @@ -163,29 +163,29 @@ Task completed successfully. Refactored the module. 'utf-8', ); - const summary = readSummary(testDir); + const summary = await readSummary(testDir); expect(summary).not.toBeNull(); expect(summary!.body).toBe('Task completed successfully. Refactored the module.'); expect(summary!.filesModified).toEqual(['src/foo.ts', 'src/bar.ts']); }); - it('returns null when SUMMARY.md does not exist', () => { - const summary = readSummary(testDir); + it('returns null when SUMMARY.md does not exist', async () => { + const summary = await readSummary(testDir); expect(summary).toBeNull(); }); - it('handles SUMMARY.md without frontmatter', () => { + it('handles SUMMARY.md without frontmatter', async () => { const outputDir = join(testDir, '.cw', 'output'); mkdirSync(outputDir, { recursive: true }); writeFileSync(join(outputDir, 'SUMMARY.md'), 'Just plain text\n', 'utf-8'); - const summary = readSummary(testDir); + const summary = await readSummary(testDir); expect(summary).not.toBeNull(); expect(summary!.body).toBe('Just plain text'); expect(summary!.filesModified).toBeUndefined(); }); - it('handles empty files_modified', () => { + it('handles empty files_modified', async () => { const outputDir = join(testDir, '.cw', 'output'); mkdirSync(outputDir, { recursive: true }); writeFileSync( @@ -198,13 +198,13 @@ Done. 'utf-8', ); - const summary = readSummary(testDir); + const summary = await readSummary(testDir); expect(summary!.filesModified).toEqual([]); }); }); describe('readPhaseFiles', () => { - it('reads phase files from phases/ directory', () => { + it('reads phase files from phases/ directory', async () => { const phasesDir = join(testDir, '.cw', 'output', 'phases'); mkdirSync(phasesDir, { recursive: true }); @@ -220,7 +220,7 @@ Create the user tables and auth schema. 'utf-8', ); - const phases = readPhaseFiles(testDir); + const phases = await readPhaseFiles(testDir); expect(phases).toHaveLength(1); expect(phases[0].id).toBe('abc123'); expect(phases[0].title).toBe('Database Schema'); @@ -228,12 +228,12 @@ Create the user tables and auth schema. expect(phases[0].body).toBe('Create the user tables and auth schema.'); }); - it('returns empty array when directory does not exist', () => { - const phases = readPhaseFiles(testDir); + it('returns empty array when directory does not exist', async () => { + const phases = await readPhaseFiles(testDir); expect(phases).toEqual([]); }); - it('handles phases with no dependencies', () => { + it('handles phases with no dependencies', async () => { const phasesDir = join(testDir, '.cw', 'output', 'phases'); mkdirSync(phasesDir, { recursive: true }); @@ -247,13 +247,13 @@ Set up the base. 'utf-8', ); - const phases = readPhaseFiles(testDir); + const phases = await readPhaseFiles(testDir); expect(phases[0].dependencies).toEqual([]); }); }); describe('readTaskFiles', () => { - it('reads task files from tasks/ directory', () => { + it('reads task files from tasks/ directory', async () => { const tasksDir = join(testDir, '.cw', 'output', 'tasks'); mkdirSync(tasksDir, { recursive: true }); @@ -271,7 +271,7 @@ Build the login form and submit handler. 'utf-8', ); - const tasks = readTaskFiles(testDir); + const tasks = await readTaskFiles(testDir); expect(tasks).toHaveLength(1); expect(tasks[0].id).toBe('task-1'); expect(tasks[0].title).toBe('Implement login'); @@ -281,23 +281,23 @@ Build the login form and submit handler. expect(tasks[0].body).toBe('Build the login form and submit handler.'); }); - it('defaults category and type when missing', () => { + it('defaults category and type when missing', async () => { const tasksDir = join(testDir, '.cw', 'output', 'tasks'); mkdirSync(tasksDir, { recursive: true }); writeFileSync(join(tasksDir, 't1.md'), `---\ntitle: Minimal\n---\nDo it.\n`, 'utf-8'); - const tasks = readTaskFiles(testDir); + const tasks = await readTaskFiles(testDir); expect(tasks[0].category).toBe('execute'); expect(tasks[0].type).toBe('auto'); }); - it('returns empty array when directory does not exist', () => { - expect(readTaskFiles(testDir)).toEqual([]); + it('returns empty array when directory does not exist', async () => { + expect(await readTaskFiles(testDir)).toEqual([]); }); }); describe('readDecisionFiles', () => { - it('reads decision files from decisions/ directory', () => { + it('reads decision files from decisions/ directory', async () => { const decisionsDir = join(testDir, '.cw', 'output', 'decisions'); mkdirSync(decisionsDir, { recursive: true }); @@ -313,7 +313,7 @@ Additional context about the decision. 'utf-8', ); - const decisions = readDecisionFiles(testDir); + const decisions = await readDecisionFiles(testDir); expect(decisions).toHaveLength(1); expect(decisions[0].id).toBe('d1'); expect(decisions[0].topic).toBe('Authentication'); @@ -322,13 +322,13 @@ Additional context about the decision. expect(decisions[0].body).toBe('Additional context about the decision.'); }); - it('returns empty array when directory does not exist', () => { - expect(readDecisionFiles(testDir)).toEqual([]); + it('returns empty array when directory does not exist', async () => { + expect(await readDecisionFiles(testDir)).toEqual([]); }); }); describe('readPageFiles', () => { - it('reads page files from pages/ directory', () => { + it('reads page files from pages/ directory', async () => { const pagesDir = join(testDir, '.cw', 'output', 'pages'); mkdirSync(pagesDir, { recursive: true }); @@ -345,7 +345,7 @@ New content for the page. 'utf-8', ); - const pages = readPageFiles(testDir); + const pages = await readPageFiles(testDir); expect(pages).toHaveLength(1); expect(pages[0].pageId).toBe('page-abc'); expect(pages[0].title).toBe('Architecture Overview'); @@ -353,17 +353,17 @@ New content for the page. expect(pages[0].body).toBe('# Architecture\n\nNew content for the page.'); }); - it('returns empty array when directory does not exist', () => { - expect(readPageFiles(testDir)).toEqual([]); + it('returns empty array when directory does not exist', async () => { + expect(await readPageFiles(testDir)).toEqual([]); }); - it('ignores non-.md files', () => { + it('ignores non-.md files', async () => { const pagesDir = join(testDir, '.cw', 'output', 'pages'); mkdirSync(pagesDir, { recursive: true }); writeFileSync(join(pagesDir, 'readme.txt'), 'not a page', 'utf-8'); writeFileSync(join(pagesDir, 'page1.md'), '---\ntitle: Page 1\n---\nContent.\n', 'utf-8'); - const pages = readPageFiles(testDir); + const pages = await readPageFiles(testDir); expect(pages).toHaveLength(1); }); });