Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/term-commands/dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,15 @@ describe('parseWishGroups()', () => {
const groups = parseWishGroups(SAMPLE_WISH);
expect(groups[0].dependsOn).toEqual([]);
});

it('should strip parenthetical comments from depends-on values', () => {
const content =
'### Group 1: First\n**depends-on:** none (this is the start)\n\n### Group 2: Second\n**depends-on:** 1 (must be done first)\n\n### Group 3: Third\n**depends-on:** Group 1 (setup), Group 2 (core work)';
const groups = parseWishGroups(content);
expect(groups[0].dependsOn).toEqual([]);
expect(groups[1].dependsOn).toEqual(['1']);
expect(groups[2].dependsOn).toEqual(['1', '2']);
});
});

// ============================================================================
Expand Down
11 changes: 9 additions & 2 deletions src/term-commands/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,17 @@ export function parseWishGroups(content: string): GroupDefinition[] {
let dependsOn: string[] = [];
if (depsMatch) {
const depsStr = depsMatch[1].trim();
if (depsStr.toLowerCase() !== 'none') {
const depsNormalized = depsStr.replace(/\s*\([^)]*\)/g, '').trim();
if (depsNormalized.toLowerCase() !== 'none') {
dependsOn = depsStr
.split(',')
Comment on lines 167 to 168

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip comments before splitting dependency list

When a depends-on comment contains a comma (for example Group 1 (setup, required), Group 2), this code splits on commas before removing parenthetical comments, so it produces invalid dependencies like "1 (setup" and "required)" instead of "1". That breaks dependency resolution in startGroup because those malformed IDs can never be satisfied. Removing parenthetical segments before .split(',') (or splitting only on commas outside parentheses) avoids corrupting the parsed dependency list.

Useful? React with 👍 / 👎.

.map((d) => d.trim().replace(/^group\s*/i, ''))
.map((d) =>
d
.trim()
.replace(/^group\s*/i, '')
.replace(/\s*\(.*\)\s*$/, '')
.trim(),
)
.filter(Boolean);
}
Comment on lines +165 to 177

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for stripping parenthetical comments is a bit convoluted. It first creates depsNormalized by stripping comments from depsStr just for the 'none' check. Then, it processes the original depsStr and strips comments again inside the .map() call using a different regex.

This is redundant and can be simplified by cleaning the dependency string once and using that cleaned string for all subsequent logic. This would make the code easier to read and maintain.

      const cleanedDepsStr = depsStr.replace(/\s*\([^)]*\)/g, '');
      if (cleanedDepsStr.trim().toLowerCase() !== 'none') {
        dependsOn = cleanedDepsStr
          .split(',')
          .map((d) =>
            d
              .trim()
              .replace(/^group\s*/i, '')
              .trim(),
          )
          .filter(Boolean);
      }

}
Expand Down
Loading