fix(phase-lifecycle): handle project-code-prefixed dirs in phaseAdd fallback scan
Filesystem fallback regex /^(\d+)-/ missed directories like CK-45-foundation when project_code is configured. Updated to /^(?:[A-Z][A-Z0-9]*-)?(\d+)-/i. Addresses coderabbit finding on PR #2737.
This commit is contained in:
@@ -316,6 +316,29 @@ describe('phaseAdd', () => {
|
||||
// Should detect phases 45 and 46 on disk, so new phase = 47
|
||||
expect(data.phase_number).toBe(47);
|
||||
});
|
||||
|
||||
it('filesystem fallback handles project-code-prefixed phase directories (regression coderabbit)', async () => {
|
||||
const { phaseAdd } = await import('./phase-lifecycle.js');
|
||||
|
||||
const roadmap = '# Roadmap\n\n## Current Milestone: v5.0\n\nSome content\n';
|
||||
|
||||
await setupTestProject(tmpDir, {
|
||||
roadmap,
|
||||
state: MINIMAL_STATE,
|
||||
phases: [],
|
||||
});
|
||||
|
||||
// Create prefixed directories manually (project_code = "CK" scenario)
|
||||
const phasesDir = join(tmpDir, '.planning', 'phases');
|
||||
await mkdir(join(phasesDir, 'CK-45-legacy-phase'), { recursive: true });
|
||||
await mkdir(join(phasesDir, 'CK-46-another-phase'), { recursive: true });
|
||||
|
||||
const result = await phaseAdd(['new-feature'], tmpDir);
|
||||
const data = result.data as Record<string, unknown>;
|
||||
|
||||
// Should detect CK-45 and CK-46, so new phase = 47
|
||||
expect(data.phase_number).toBe(47);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── phaseAddBatch ─────────────────────────────────────────────────────
|
||||
|
||||
@@ -209,7 +209,7 @@ export const phaseAdd: QueryHandler = async (args, projectDir, workstream) => {
|
||||
const entries = await readdir(phasesDir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const dirMatch = /^(\d+)[A-Z]?(?:\.\d+)*-/.exec(entry.name);
|
||||
const dirMatch = /^(?:[A-Z][A-Z0-9]*-)?(\d+)[A-Z]?(?:\.\d+)*-/i.exec(entry.name);
|
||||
if (dirMatch) {
|
||||
const num = parseInt(dirMatch[1], 10);
|
||||
if (num >= 999) continue;
|
||||
|
||||
Reference in New Issue
Block a user