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
11 changes: 5 additions & 6 deletions src/core/artifact-graph/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ export function isGlobPattern(pattern: string): boolean {
* Returns absolute file paths. Glob matches are sorted for deterministic output.
*/
export function resolveArtifactOutputs(changeDir: string, generates: string): string[] {
const fullPattern = path.join(changeDir, generates);

if (!isGlobPattern(generates)) {
const fullPath = path.join(changeDir, generates);
try {
return fs.statSync(fullPattern).isFile()
? [FileSystemUtils.canonicalizeExistingPath(fullPattern)]
return fs.statSync(fullPath).isFile()
? [FileSystemUtils.canonicalizeExistingPath(fullPath)]
: [];
} catch {
return [];
}
}

const normalizedPattern = FileSystemUtils.toPosixPath(fullPattern);
const normalizedPattern = FileSystemUtils.toPosixPath(generates);
const matches = fg
.sync(normalizedPattern, { onlyFiles: true })
.sync(normalizedPattern, { cwd: changeDir, onlyFiles: true, absolute: true })
.map((match) => FileSystemUtils.canonicalizeExistingPath(path.normalize(match)));

return Array.from(new Set(matches)).sort();
Expand Down
66 changes: 66 additions & 0 deletions test/core/artifact-graph/outputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,70 @@ describe('artifact-graph/outputs', () => {
expect(resolveArtifactOutputs(tempDir, 'specs/*/spec.md')).toEqual([]);
expect(artifactOutputExists(tempDir, 'specs/*/spec.md')).toBe(false);
});

describe('glob-special characters in directory paths', () => {
it('resolves glob patterns when directory contains parentheses', () => {
const dirWithParens = path.join(tempDir, 'project (work)');
const specDir = path.join(dirWithParens, 'specs', 'cap-a');
const specFile = path.join(specDir, 'spec.md');
fs.mkdirSync(specDir, { recursive: true });
fs.writeFileSync(specFile, 'content');

expect(resolveArtifactOutputs(dirWithParens, 'specs/*/spec.md')).toEqual([
canonical(specFile),
]);
expect(artifactOutputExists(dirWithParens, 'specs/*/spec.md')).toBe(true);
});

it('resolves glob patterns when directory contains square brackets', () => {
const dirWithBrackets = path.join(tempDir, '[projects]');
const specDir = path.join(dirWithBrackets, 'specs', 'cap-a');
const specFile = path.join(specDir, 'spec.md');
fs.mkdirSync(specDir, { recursive: true });
fs.writeFileSync(specFile, 'content');

expect(resolveArtifactOutputs(dirWithBrackets, 'specs/*/spec.md')).toEqual([
canonical(specFile),
]);
expect(artifactOutputExists(dirWithBrackets, 'specs/*/spec.md')).toBe(true);
});

it('resolves glob patterns when directory contains curly braces', () => {
const dirWithBraces = path.join(tempDir, '{workspace}');
const specDir = path.join(dirWithBraces, 'specs', 'cap-a');
const specFile = path.join(specDir, 'spec.md');
fs.mkdirSync(specDir, { recursive: true });
fs.writeFileSync(specFile, 'content');

expect(resolveArtifactOutputs(dirWithBraces, 'specs/*/spec.md')).toEqual([
canonical(specFile),
]);
expect(artifactOutputExists(dirWithBraces, 'specs/*/spec.md')).toBe(true);
});

it('resolves glob patterns when directory contains brace expansion syntax', () => {
const dirWithBraceExpansion = path.join(tempDir, 'project {a,b}');
const specDir = path.join(dirWithBraceExpansion, 'specs', 'cap-a');
const specFile = path.join(specDir, 'spec.md');
fs.mkdirSync(specDir, { recursive: true });
fs.writeFileSync(specFile, 'content');

expect(resolveArtifactOutputs(dirWithBraceExpansion, 'specs/*/spec.md')).toEqual([
canonical(specFile),
]);
expect(artifactOutputExists(dirWithBraceExpansion, 'specs/*/spec.md')).toBe(true);
});

it('resolves non-glob generates when directory contains special characters', () => {
const dirWithParens = path.join(tempDir, 'project (work)');
const proposalFile = path.join(dirWithParens, 'proposal.md');
fs.mkdirSync(dirWithParens, { recursive: true });
fs.writeFileSync(proposalFile, 'content');

expect(resolveArtifactOutputs(dirWithParens, 'proposal.md')).toEqual([
canonical(proposalFile),
]);
expect(artifactOutputExists(dirWithParens, 'proposal.md')).toBe(true);
});
});
});
Loading