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