From 0f1ff22ca3bb4487735eb2016dffde35f0eea4e0 Mon Sep 17 00:00:00 2001 From: Oleg Solomko Date: Thu, 13 Mar 2025 15:40:38 -0700 Subject: [PATCH] working on unit tests --- src/vs/platform/prompts/common/config.ts | 7 +- .../promptSyntax/utils/promptFilesLocator.ts | 231 ++- .../utils/promptFilesLocator.test.ts | 1270 ++++++++++------- 3 files changed, 1014 insertions(+), 494 deletions(-) diff --git a/src/vs/platform/prompts/common/config.ts b/src/vs/platform/prompts/common/config.ts index 4ea1187b61e..d448c2f0df7 100644 --- a/src/vs/platform/prompts/common/config.ts +++ b/src/vs/platform/prompts/common/config.ts @@ -115,9 +115,12 @@ export namespace PromptsConfig { // copy all the enabled paths to the result list for (const [path, enabled] of Object.entries(value)) { - if (enabled && path !== DEFAULT_SOURCE_FOLDER) { - paths.push(path); + // we already added the default source folder, so skip it + if ((enabled === false) || (path === DEFAULT_SOURCE_FOLDER)) { + continue; } + + paths.push(path); } return paths; diff --git a/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.ts b/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.ts index 7f8bc285c82..0d365d6ee3b 100644 --- a/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.ts +++ b/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.ts @@ -4,13 +4,16 @@ *--------------------------------------------------------------------------------------------*/ import { URI } from '../../../../../../base/common/uri.js'; +import { match } from '../../../../../../base/common/glob.js'; +import { assert } from '../../../../../../base/common/assert.js'; +import { isAbsolute } from '../../../../../../base/common/path.js'; import { ResourceSet } from '../../../../../../base/common/map.js'; import { dirname, extUri } from '../../../../../../base/common/resources.js'; import { IFileService } from '../../../../../../platform/files/common/files.js'; import { PromptsConfig } from '../../../../../../platform/prompts/common/config.js'; -import { isPromptFile } from '../../../../../../platform/prompts/common/constants.js'; import { IWorkspaceContextService } from '../../../../../../platform/workspace/common/workspace.js'; import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js'; +import { isPromptFile, PROMPT_FILE_EXTENSION } from '../../../../../../platform/prompts/common/constants.js'; /** * Utility class to locate prompt files. @@ -153,4 +156,230 @@ export class PromptFilesLocator { return files; } + + /** + * TODO: @lego + * + * @throws if any of the provided locations is not an `absolute path`. + */ + public async findAllMatchingPromptFiles( + // configuredLocations: readonly string[], + // fileService: IFileService, + // workspaceService: IWorkspaceContextService, + ): Promise { + const configuredLocations = PromptsConfig.promptSourceFolders(this.configService); + // convert locations from settings to absolute paths based on the current workspace folders + const absoluteLocations = toAbsoluteLocations(configuredLocations, this.workspaceService); + + // find all prompt files in the provided locations, then match + // the found file paths against (possible) glob patterns + const paths = new ResourceSet(); + for (const absoluteLocation of absoluteLocations) { + // assert( + // isAbsolute(location), + // `Provided location must be an absolute path, got '${location}'.`, + // ); + + // normalize the glob pattern to always end with "any prompt file" pattern + const location = (absoluteLocation.path.endsWith(PROMPT_FILE_EXTENSION)) + ? absoluteLocation + : extUri.joinPath(absoluteLocation, `*${PROMPT_FILE_EXTENSION}`); + + // find all prompt files in entire file tree, starting from + // a first parent folder that does not contain a glob pattern + const promptFiles = await findAllPromptFiles( + firstNonGlobParent(location), + this.fileService, + ); + + // filter out found prompt files to only include those that match + // the original glob pattern specified in the settings (if any) + for (const file of promptFiles) { + if (match(location.path, file.path)) { + paths.add(file); + } + } + } + + return [...paths]; + } } + +/** + * Checks if the provided `pattern` could be a valid glob pattern. + */ +export const isValidGlob = (pattern: string): boolean => { + let squareBrackets = false; + let squareBracketsCount = 0; + + let curlyBrackets = false; + let curlyBracketsCount = 0; + + for (const char of pattern) { + if (char === '*') { + return true; + } + + if (char === '?') { + return true; + } + + // TODO: @lego - check that these are not escaped? + if (char === '[') { + squareBrackets = true; + + squareBracketsCount++; + } + + if (char === ']') { + squareBrackets = true; + + // if there are no matching opening square brackets, this is an `invalid glob` + if (squareBracketsCount % 2 === 0) { + return false; + } + + squareBracketsCount--; + } + + if (char === '{') { + curlyBrackets = true; + + curlyBracketsCount++; + } + + if (char === '}') { + curlyBrackets = true; + + // if there are no matching opening curly brackets, this is an `invalid glob` + if (curlyBracketsCount % 2 === 0) { + return false; + } + + curlyBracketsCount--; + } + } + + // if square brackets exist and are in pairs, this is a `valid glob` + if (squareBrackets && squareBracketsCount === 0) { + return true; + } + + // if curly brackets exist and are in pairs, this is a `valid glob` + if (curlyBrackets && curlyBracketsCount === 0) { + return true; + } + + return false; +}; + +/** + * TODO: @lego - notes + * - if path `starts with a glob`, it must be relative to current workspace folders, otherwise we would need to scan through entire filesystem of the machine + * - likewise if a `relative path`, it must be relative to current workspace folders + * - only if path is `absolute`, we can try to resolve all prompt files in it and its subfolders, and then try to match the files against a glob pattern + */ + +/** + * Finds the first parent of the provided location that does not contain a `glob pattern`. + * + * @throws if the provided location is not an `absolute path`. + */ +// TODO: @lego - add examples? +export const firstNonGlobParent = ( + location: URI, +): URI => { + // sanity check of the provided location + assert( + isAbsolute(location.path), + `Provided location must be an absolute path, got '${location.path}'.`, + ); + + // note! if though the folder name can be `invalid glob` here, it is still OK to + // use it as we don't really known if that is a glob pattern, or the folder + // name contains characters that can also be used in a glob pattern + if (isValidGlob(location.path) === false) { + return location; + } + + // if location is the root of the filesystem, we are done + const parent = dirname(location); + if (extUri.isEqual(parent, location)) { + return location; + } + + // otherwise, try again starting with the parent folder + return firstNonGlobParent(parent); +}; + +/** + * TODO: @lego + */ +const findAllPromptFiles = async ( + location: URI, + fileService: IFileService, +): Promise => { + const result: URI[] = []; + const info = await fileService.resolve(location); + + if (info.isFile && isPromptFile(info.resource)) { + result.push(info.resource); + + return result; + } + + if (info.isDirectory && info.children) { + for (const child of info.children) { + if (child.isFile && isPromptFile(child.resource)) { + result.push(child.resource); + + continue; + } + + if (child.isDirectory) { + const promptFiles = await findAllPromptFiles(child.resource, fileService); + result.push(...promptFiles); + + continue; + } + } + + return result; + } + + return result; +}; + +/** + * Converts locations from settings to absolute paths + * based on the current workspace folders. + */ +const toAbsoluteLocations = ( + configuredLocations: readonly string[], + workspaceService: IWorkspaceContextService, +): readonly URI[] => { + const { folders } = workspaceService.getWorkspace(); + + const result: URI[] = []; + for (const configuredLocation of configuredLocations) { + if (isAbsolute(configuredLocation)) { + result.push(URI.file(configuredLocation)); + + continue; + } + + for (const workspaceFolder of folders) { + const absolutePath = extUri.resolvePath(workspaceFolder.uri, configuredLocation); + + // a sanity check on the expected outcome of the `resolvePath()` call + assert( + isAbsolute(absolutePath.path), + `Provided location must be an absolute path, got '${absolutePath.path}'.`, + ); + + result.push(absolutePath); + } + } + + return result; +}; diff --git a/src/vs/workbench/contrib/chat/test/common/promptSyntax/utils/promptFilesLocator.test.ts b/src/vs/workbench/contrib/chat/test/common/promptSyntax/utils/promptFilesLocator.test.ts index 973eedbfadf..b7fd7a6bb95 100644 --- a/src/vs/workbench/contrib/chat/test/common/promptSyntax/utils/promptFilesLocator.test.ts +++ b/src/vs/workbench/contrib/chat/test/common/promptSyntax/utils/promptFilesLocator.test.ts @@ -220,152 +220,268 @@ suite('PromptFilesLocator', () => { }); suite('• single-root workspace', () => { - suite('• non-empty filesystem', () => { - suite('• object config value', () => { - test('• core logic', async () => { - const locator = await createPromptsLocator( + suite('• findAllMatchingPromptFiles', () => { + test('• relative glob pattern', async () => { + const locator = await createPromptsLocator( + { + '.github/prompts': false, + '/Users/legomushroom/repos/prompts': false, + // - + '.copilot/prompts/**': true, + '**/my-prompts/': true, + '.github/prompts/nested/specific.prompt.md': true, + '.github/prompts/nested/unspecific*.prompt.md': true, + // '.github/prompts/nested/unspecific': true, + // '.github/prompts/nested/unspecific*': true, + // '.github/prompts/nested/unspecific*-prompt': true, + // '.github/prompts/nested/*unspecific*-prompt': true, + // '.github/prompts/nested/*.prompt.md': true, + // '.github/**/nested/*.prompt.md': true, + // '.github/prompts/**/*.prompt.md': true, + }, + [ + '/Users/legomushroom/repos/vscode', + ], + [ { - '/Users/legomushroom/repos/prompts': true, - '/tmp/prompts/': true, - '/absolute/path/prompts': false, - '.copilot/prompts': true, + name: '/Users/legomushroom/repos/prompts', + children: [ + { + name: 'test.prompt.md', + contents: 'Hello, World!', + }, + { + name: 'refactor-tests.prompt.md', + contents: 'some file content goes here', + }, + ], }, - [ - '/Users/legomushroom/repos/vscode', + { + name: '/tmp/prompts', + children: [ + { + name: 'translate.to-rust.prompt.md', + contents: 'some more random file contents', + }, + ], + }, + { + name: '/absolute/path/prompts', + children: [ + { + name: 'some-prompt-file.prompt.md', + contents: 'hey hey hey', + }, + ], + }, + { + name: '/Users/legomushroom/repos/vscode', + children: [ + { + name: '.copilot/prompts', + children: [ + { + name: 'default.prompt.md', + contents: 'oh hi, robot!', + }, + { + name: 'misc', + children: [ + { + name: 'child.prompt.md', + contents: 'contents', + }, + ], + } + ], + }, + { + name: '.github/prompts', + children: [ + { + name: 'my.prompt.md', + contents: 'oh hi, bot!', + }, + { + name: 'nested', + children: [ + { + name: 'specific.prompt.md', + contents: 'oh hi, bot!', + }, + { + name: 'unspecific1.prompt.md', + contents: 'oh hi, bot!', + }, + { + name: 'unspecific2.prompt.md', + contents: 'oh hi, bot!', + }, + ], + } + ], + }, + { + name: 'deps/text', + children: [ + { + name: 'my.prompt.md', + contents: 'oh hi, bot!', + }, + { + name: 'my-prompts', + children: [ + { + name: 'your.prompt.md', + contents: 'oh hi, bot!', + }, + ], + }, + ], + }, + ], + }, + ]); + + assert.deepStrictEqual( + (await locator.findAllMatchingPromptFiles()) + .map((file) => file.fsPath), + [ + // createURI('/Users/legomushroom/repos/vscode/.github/prompts/my.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), + createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/default.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/misc/child.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/deps/text/my-prompts/your.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.github/prompts/nested/specific.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.github/prompts/nested/unspecific1.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.github/prompts/nested/unspecific2.prompt.md').fsPath, + ], + 'Must find correct prompts.', + ); + }); + }); + + test('• relative glob pattern #2', async () => { + const locator = await createPromptsLocator( + { + '.github/prompts': false, + '/Users/legomushroom/repos/prompts': false, + // - + '.copilot/prompts/**': true, + '**/my-prompts/': true, + '.github/prompts/nested/specific.prompt.md': true, + // '.github/prompts/nested/unspecific*.prompt.md': true, + // '.github/prompts/nested/unspecific': true, + '.github/prompts/nested/unspecific*': true, + // '.github/prompts/nested/unspecific*-prompt': true, + // '.github/prompts/nested/*unspecific*-prompt': true, + // '.github/prompts/nested/*.prompt.md': true, + // '.github/**/nested/*.prompt.md': true, + // '.github/prompts/**/*.prompt.md': true, + }, + [ + '/Users/legomushroom/repos/vscode', + ], + [ + { + name: '/Users/legomushroom/repos/prompts', + children: [ + { + name: 'test.prompt.md', + contents: 'Hello, World!', + }, + { + name: 'refactor-tests.prompt.md', + contents: 'some file content goes here', + }, ], - [ + }, + { + name: '/tmp/prompts', + children: [ { - name: '/Users/legomushroom/repos/prompts', - children: [ - { - name: 'test.prompt.md', - contents: 'Hello, World!', - }, - { - name: 'refactor-tests.prompt.md', - contents: 'some file content goes here', - }, - ], + name: 'translate.to-rust.prompt.md', + contents: 'some more random file contents', }, + ], + }, + { + name: '/absolute/path/prompts', + children: [ { - name: '/tmp/prompts', - children: [ - { - name: 'translate.to-rust.prompt.md', - contents: 'some more random file contents', - }, - ], + name: 'some-prompt-file.prompt.md', + contents: 'hey hey hey', }, + ], + }, + { + name: '/Users/legomushroom/repos/vscode', + children: [ { - name: '/absolute/path/prompts', + name: '.copilot/prompts', children: [ { - name: 'some-prompt-file.prompt.md', - contents: 'hey hey hey', + name: 'default.prompt.md', + contents: 'oh hi, robot!', }, - ], - }, - { - name: '/Users/legomushroom/repos/vscode', - children: [ { - name: '.copilot/prompts', + name: 'misc', children: [ { - name: 'default.prompt.md', - contents: 'oh hi, robot!', + name: 'child.prompt.md', + contents: 'contents', }, ], + } + ], + }, + { + name: '.github/prompts', + children: [ + { + name: 'my.prompt.md', + contents: 'oh hi, bot!', }, { - name: '.github/prompts', + name: 'nested', children: [ { - name: 'my.prompt.md', + name: 'specific.prompt.md', contents: 'oh hi, bot!', }, - ], - }, - ], - }, - ]); - - assert.deepStrictEqual( - await locator.listFiles(), - [ - createURI('/Users/legomushroom/repos/vscode/.github/prompts/my.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), - createURI('/tmp/prompts/translate.to-rust.prompt.md'), - createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/default.prompt.md'), - ], - 'Must find correct prompts.', - ); - }); - - test('• with disabled `.github/prompts` location', async () => { - const locator = await createPromptsLocator( - { - '/Users/legomushroom/repos/prompts': true, - '/tmp/prompts/': true, - '/absolute/path/prompts': false, - '.copilot/prompts': true, - '.github/prompts': false, - }, - [ - '/Users/legomushroom/repos/vscode', - ], - [ - { - name: '/Users/legomushroom/repos/prompts', - children: [ - { - name: 'test.prompt.md', - contents: 'Hello, World!', - }, - { - name: 'refactor-tests.prompt.md', - contents: 'some file content goes here', - }, - ], - }, - { - name: '/tmp/prompts', - children: [ - { - name: 'translate.to-rust.prompt.md', - contents: 'some more random file contents', - }, - ], - }, - { - name: '/absolute/path/prompts', - children: [ - { - name: 'some-prompt-file.prompt.md', - contents: 'hey hey hey', - }, - ], - }, - { - name: '/Users/legomushroom/repos/vscode', - children: [ - { - name: '.copilot/prompts', - children: [ { - name: 'default.prompt.md', - contents: 'oh hi, robot!', + name: 'unspecific1', + children: [ + { + name: 'file.prompt.md', + contents: 'oh hi, bot!', + }, + ], + }, + { + name: 'unspecific2', + children: [ + { + name: 'file.prompt.md', + contents: 'oh hi, bot!', + }, + ], }, ], + } + ], + }, + { + name: 'deps/text', + children: [ + { + name: 'my.prompt.md', + contents: 'oh hi, bot!', }, { - name: '.github/prompts', + name: 'my-prompts', children: [ - { - name: 'my.prompt.md', - contents: 'oh hi, bot!', - }, { name: 'your.prompt.md', contents: 'oh hi, bot!', @@ -374,386 +490,558 @@ suite('PromptFilesLocator', () => { }, ], }, - ]); - - assert.deepStrictEqual( - await locator.listFiles(), - [ - createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), - createURI('/tmp/prompts/translate.to-rust.prompt.md'), - createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/default.prompt.md'), ], - 'Must find correct prompts.', - ); - }); - }); + }, + ]); + + assert.deepStrictEqual( + (await locator.findAllMatchingPromptFiles()) + .map((file) => file.fsPath), + [ + // createURI('/Users/legomushroom/repos/vscode/.github/prompts/my.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), + createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/default.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/misc/child.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/deps/text/my-prompts/your.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.github/prompts/nested/specific.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.github/prompts/nested/unspecific1/file.prompt.md').fsPath, + createURI('/Users/legomushroom/repos/vscode/.github/prompts/nested/unspecific2/file.prompt.md').fsPath, + ], + 'Must find correct prompts.', + ); }); + + // test('• core logic', async () => { + // const locator = await createPromptsLocator( + // { + // '/Users/legomushroom/repos/prompts': true, + // '/tmp/prompts/': true, + // '/absolute/path/prompts': false, + // '.copilot/prompts': true, + // }, + // [ + // '/Users/legomushroom/repos/vscode', + // ], + // [ + // { + // name: '/Users/legomushroom/repos/prompts', + // children: [ + // { + // name: 'test.prompt.md', + // contents: 'Hello, World!', + // }, + // { + // name: 'refactor-tests.prompt.md', + // contents: 'some file content goes here', + // }, + // ], + // }, + // { + // name: '/tmp/prompts', + // children: [ + // { + // name: 'translate.to-rust.prompt.md', + // contents: 'some more random file contents', + // }, + // ], + // }, + // { + // name: '/absolute/path/prompts', + // children: [ + // { + // name: 'some-prompt-file.prompt.md', + // contents: 'hey hey hey', + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/vscode', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'default.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'my.prompt.md', + // contents: 'oh hi, bot!', + // }, + // ], + // }, + // ], + // }, + // ]); + + // assert.deepStrictEqual( + // await locator.listFiles(), + // [ + // createURI('/Users/legomushroom/repos/vscode/.github/prompts/my.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), + // createURI('/tmp/prompts/translate.to-rust.prompt.md'), + // createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/default.prompt.md'), + // ], + // 'Must find correct prompts.', + // ); + // }); + + // test('• with disabled `.github/prompts` location', async () => { + // const locator = await createPromptsLocator( + // { + // '/Users/legomushroom/repos/prompts': true, + // '/tmp/prompts/': true, + // '/absolute/path/prompts': false, + // '.copilot/prompts': true, + // '.github/prompts': false, + // }, + // [ + // '/Users/legomushroom/repos/vscode', + // ], + // [ + // { + // name: '/Users/legomushroom/repos/prompts', + // children: [ + // { + // name: 'test.prompt.md', + // contents: 'Hello, World!', + // }, + // { + // name: 'refactor-tests.prompt.md', + // contents: 'some file content goes here', + // }, + // ], + // }, + // { + // name: '/tmp/prompts', + // children: [ + // { + // name: 'translate.to-rust.prompt.md', + // contents: 'some more random file contents', + // }, + // ], + // }, + // { + // name: '/absolute/path/prompts', + // children: [ + // { + // name: 'some-prompt-file.prompt.md', + // contents: 'hey hey hey', + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/vscode', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'default.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'my.prompt.md', + // contents: 'oh hi, bot!', + // }, + // { + // name: 'your.prompt.md', + // contents: 'oh hi, bot!', + // }, + // ], + // }, + // ], + // }, + // ]); + + // assert.deepStrictEqual( + // await locator.listFiles(), + // [ + // createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), + // createURI('/tmp/prompts/translate.to-rust.prompt.md'), + // createURI('/Users/legomushroom/repos/vscode/.copilot/prompts/default.prompt.md'), + // ], + // 'Must find correct prompts.', + // ); + // }); }); - suite('• multi-root workspace', () => { - suite('• non-empty filesystem', () => { - suite('• object config value', () => { - test('• without top-level `.github` folder', async () => { - const locator = await createPromptsLocator( - { - '/Users/legomushroom/repos/prompts': true, - '/tmp/prompts/': true, - '/absolute/path/prompts': false, - '.copilot/prompts': false, - }, - [ - '/Users/legomushroom/repos/vscode', - '/Users/legomushroom/repos/node', - ], - [ - { - name: '/Users/legomushroom/repos/prompts', - children: [ - { - name: 'test.prompt.md', - contents: 'Hello, World!', - }, - { - name: 'refactor-tests.prompt.md', - contents: 'some file content goes here', - }, - ], - }, - { - name: '/tmp/prompts', - children: [ - { - name: 'translate.to-rust.prompt.md', - contents: 'some more random file contents', - }, - ], - }, - { - name: '/absolute/path/prompts', - children: [ - { - name: 'some-prompt-file.prompt.md', - contents: 'hey hey hey', - }, - ], - }, - { - name: '/Users/legomushroom/repos/vscode', - children: [ - { - name: '.copilot/prompts', - children: [ - { - name: 'prompt1.prompt.md', - contents: 'oh hi, robot!', - }, - ], - }, - { - name: '.github/prompts', - children: [ - { - name: 'default.prompt.md', - contents: 'oh hi, bot!', - }, - ], - }, - ], - }, - { - name: '/Users/legomushroom/repos/node', - children: [ - { - name: '.copilot/prompts', - children: [ - { - name: 'prompt5.prompt.md', - contents: 'oh hi, robot!', - }, - ], - }, - { - name: '.github/prompts', - children: [ - { - name: 'refactor-static-classes.prompt.md', - contents: 'file contents', - }, - ], - }, - ], - }, - // note! this folder is not part of the workspace, so prompt files are `ignored` - { - name: '/Users/legomushroom/repos/.github/prompts', - children: [ - { - name: 'prompt-name.prompt.md', - contents: 'oh hi, robot!', - }, - { - name: 'name-of-the-prompt.prompt.md', - contents: 'oh hi, raw bot!', - }, - ], - }, - ]); + // suite('• multi-root workspace', () => { + // suite('• non-empty filesystem', () => { + // suite('• object config value', () => { + // test('• without top-level `.github` folder', async () => { + // const locator = await createPromptsLocator( + // { + // '/Users/legomushroom/repos/prompts': true, + // '/tmp/prompts/': true, + // '/absolute/path/prompts': false, + // '.copilot/prompts': false, + // }, + // [ + // '/Users/legomushroom/repos/vscode', + // '/Users/legomushroom/repos/node', + // ], + // [ + // { + // name: '/Users/legomushroom/repos/prompts', + // children: [ + // { + // name: 'test.prompt.md', + // contents: 'Hello, World!', + // }, + // { + // name: 'refactor-tests.prompt.md', + // contents: 'some file content goes here', + // }, + // ], + // }, + // { + // name: '/tmp/prompts', + // children: [ + // { + // name: 'translate.to-rust.prompt.md', + // contents: 'some more random file contents', + // }, + // ], + // }, + // { + // name: '/absolute/path/prompts', + // children: [ + // { + // name: 'some-prompt-file.prompt.md', + // contents: 'hey hey hey', + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/vscode', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'prompt1.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'default.prompt.md', + // contents: 'oh hi, bot!', + // }, + // ], + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/node', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'prompt5.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'refactor-static-classes.prompt.md', + // contents: 'file contents', + // }, + // ], + // }, + // ], + // }, + // // note! this folder is not part of the workspace, so prompt files are `ignored` + // { + // name: '/Users/legomushroom/repos/.github/prompts', + // children: [ + // { + // name: 'prompt-name.prompt.md', + // contents: 'oh hi, robot!', + // }, + // { + // name: 'name-of-the-prompt.prompt.md', + // contents: 'oh hi, raw bot!', + // }, + // ], + // }, + // ]); - assert.deepStrictEqual( - await locator.listFiles(), - [ - createURI('/Users/legomushroom/repos/vscode/.github/prompts/default.prompt.md'), - createURI('/Users/legomushroom/repos/node/.github/prompts/refactor-static-classes.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), - createURI('/tmp/prompts/translate.to-rust.prompt.md'), - ], - 'Must find correct prompts.', - ); - }); + // assert.deepStrictEqual( + // await locator.listFiles(), + // [ + // createURI('/Users/legomushroom/repos/vscode/.github/prompts/default.prompt.md'), + // createURI('/Users/legomushroom/repos/node/.github/prompts/refactor-static-classes.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), + // createURI('/tmp/prompts/translate.to-rust.prompt.md'), + // ], + // 'Must find correct prompts.', + // ); + // }); - test('• with top-level `.github` folder', async () => { - const locator = await createPromptsLocator( - { - '/Users/legomushroom/repos/prompts': true, - '/tmp/prompts/': true, - '/absolute/path/prompts': false, - '.copilot/prompts': false, - }, - [ - '/Users/legomushroom/repos/vscode', - '/Users/legomushroom/repos/node', - '/var/shared/prompts/.github', - ], - [ - { - name: '/Users/legomushroom/repos/prompts', - children: [ - { - name: 'test.prompt.md', - contents: 'Hello, World!', - }, - { - name: 'refactor-tests.prompt.md', - contents: 'some file content goes here', - }, - ], - }, - { - name: '/tmp/prompts', - children: [ - { - name: 'translate.to-rust.prompt.md', - contents: 'some more random file contents', - }, - ], - }, - { - name: '/absolute/path/prompts', - children: [ - { - name: 'some-prompt-file.prompt.md', - contents: 'hey hey hey', - }, - ], - }, - { - name: '/Users/legomushroom/repos/vscode', - children: [ - { - name: '.copilot/prompts', - children: [ - { - name: 'prompt1.prompt.md', - contents: 'oh hi, robot!', - }, - ], - }, - { - name: '.github/prompts', - children: [ - { - name: 'default.prompt.md', - contents: 'oh hi, bot!', - }, - ], - }, - ], - }, - { - name: '/Users/legomushroom/repos/node', - children: [ - { - name: '.copilot/prompts', - children: [ - { - name: 'prompt5.prompt.md', - contents: 'oh hi, robot!', - }, - ], - }, - { - name: '.github/prompts', - children: [ - { - name: 'refactor-static-classes.prompt.md', - contents: 'file contents', - }, - ], - }, - ], - }, - // note! this folder is part of the workspace, so prompt files are `included` - { - name: '/var/shared/prompts/.github/prompts', - children: [ - { - name: 'prompt-name.prompt.md', - contents: 'oh hi, robot!', - }, - { - name: 'name-of-the-prompt.prompt.md', - contents: 'oh hi, raw bot!', - }, - ], - }, - ]); + // test('• with top-level `.github` folder', async () => { + // const locator = await createPromptsLocator( + // { + // '/Users/legomushroom/repos/prompts': true, + // '/tmp/prompts/': true, + // '/absolute/path/prompts': false, + // '.copilot/prompts': false, + // }, + // [ + // '/Users/legomushroom/repos/vscode', + // '/Users/legomushroom/repos/node', + // '/var/shared/prompts/.github', + // ], + // [ + // { + // name: '/Users/legomushroom/repos/prompts', + // children: [ + // { + // name: 'test.prompt.md', + // contents: 'Hello, World!', + // }, + // { + // name: 'refactor-tests.prompt.md', + // contents: 'some file content goes here', + // }, + // ], + // }, + // { + // name: '/tmp/prompts', + // children: [ + // { + // name: 'translate.to-rust.prompt.md', + // contents: 'some more random file contents', + // }, + // ], + // }, + // { + // name: '/absolute/path/prompts', + // children: [ + // { + // name: 'some-prompt-file.prompt.md', + // contents: 'hey hey hey', + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/vscode', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'prompt1.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'default.prompt.md', + // contents: 'oh hi, bot!', + // }, + // ], + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/node', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'prompt5.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'refactor-static-classes.prompt.md', + // contents: 'file contents', + // }, + // ], + // }, + // ], + // }, + // // note! this folder is part of the workspace, so prompt files are `included` + // { + // name: '/var/shared/prompts/.github/prompts', + // children: [ + // { + // name: 'prompt-name.prompt.md', + // contents: 'oh hi, robot!', + // }, + // { + // name: 'name-of-the-prompt.prompt.md', + // contents: 'oh hi, raw bot!', + // }, + // ], + // }, + // ]); - assert.deepStrictEqual( - await locator.listFiles(), - [ - createURI('/Users/legomushroom/repos/vscode/.github/prompts/default.prompt.md'), - createURI('/Users/legomushroom/repos/node/.github/prompts/refactor-static-classes.prompt.md'), - createURI('/var/shared/prompts/.github/prompts/prompt-name.prompt.md'), - createURI('/var/shared/prompts/.github/prompts/name-of-the-prompt.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), - createURI('/tmp/prompts/translate.to-rust.prompt.md'), - ], - 'Must find correct prompts.', - ); - }); + // assert.deepStrictEqual( + // await locator.listFiles(), + // [ + // createURI('/Users/legomushroom/repos/vscode/.github/prompts/default.prompt.md'), + // createURI('/Users/legomushroom/repos/node/.github/prompts/refactor-static-classes.prompt.md'), + // createURI('/var/shared/prompts/.github/prompts/prompt-name.prompt.md'), + // createURI('/var/shared/prompts/.github/prompts/name-of-the-prompt.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), + // createURI('/tmp/prompts/translate.to-rust.prompt.md'), + // ], + // 'Must find correct prompts.', + // ); + // }); - test('• with disabled `.github/prompts` location', async () => { - const locator = await createPromptsLocator( - { - '/Users/legomushroom/repos/prompts': true, - '/tmp/prompts/': true, - '/absolute/path/prompts': false, - '.copilot/prompts': false, - '.github/prompts': false, - }, - [ - '/Users/legomushroom/repos/vscode', - '/Users/legomushroom/repos/node', - '/var/shared/prompts/.github', - ], - [ - { - name: '/Users/legomushroom/repos/prompts', - children: [ - { - name: 'test.prompt.md', - contents: 'Hello, World!', - }, - { - name: 'refactor-tests.prompt.md', - contents: 'some file content goes here', - }, - ], - }, - { - name: '/tmp/prompts', - children: [ - { - name: 'translate.to-rust.prompt.md', - contents: 'some more random file contents', - }, - ], - }, - { - name: '/absolute/path/prompts', - children: [ - { - name: 'some-prompt-file.prompt.md', - contents: 'hey hey hey', - }, - ], - }, - { - name: '/Users/legomushroom/repos/vscode', - children: [ - { - name: '.copilot/prompts', - children: [ - { - name: 'prompt1.prompt.md', - contents: 'oh hi, robot!', - }, - ], - }, - { - name: '.github/prompts', - children: [ - { - name: 'default.prompt.md', - contents: 'oh hi, bot!', - }, - ], - }, - ], - }, - { - name: '/Users/legomushroom/repos/node', - children: [ - { - name: '.copilot/prompts', - children: [ - { - name: 'prompt5.prompt.md', - contents: 'oh hi, robot!', - }, - ], - }, - { - name: '.github/prompts', - children: [ - { - name: 'refactor-static-classes.prompt.md', - contents: 'file contents', - }, - ], - }, - ], - }, - // note! this folder is part of the workspace, so prompt files are `included` - { - name: '/var/shared/prompts/.github/prompts', - children: [ - { - name: 'prompt-name.prompt.md', - contents: 'oh hi, robot!', - }, - { - name: 'name-of-the-prompt.prompt.md', - contents: 'oh hi, raw bot!', - }, - ], - }, - ]); + // test('• with disabled `.github/prompts` location', async () => { + // const locator = await createPromptsLocator( + // { + // '/Users/legomushroom/repos/prompts': true, + // '/tmp/prompts/': true, + // '/absolute/path/prompts': false, + // '.copilot/prompts': false, + // '.github/prompts': false, + // }, + // [ + // '/Users/legomushroom/repos/vscode', + // '/Users/legomushroom/repos/node', + // '/var/shared/prompts/.github', + // ], + // [ + // { + // name: '/Users/legomushroom/repos/prompts', + // children: [ + // { + // name: 'test.prompt.md', + // contents: 'Hello, World!', + // }, + // { + // name: 'refactor-tests.prompt.md', + // contents: 'some file content goes here', + // }, + // ], + // }, + // { + // name: '/tmp/prompts', + // children: [ + // { + // name: 'translate.to-rust.prompt.md', + // contents: 'some more random file contents', + // }, + // ], + // }, + // { + // name: '/absolute/path/prompts', + // children: [ + // { + // name: 'some-prompt-file.prompt.md', + // contents: 'hey hey hey', + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/vscode', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'prompt1.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'default.prompt.md', + // contents: 'oh hi, bot!', + // }, + // ], + // }, + // ], + // }, + // { + // name: '/Users/legomushroom/repos/node', + // children: [ + // { + // name: '.copilot/prompts', + // children: [ + // { + // name: 'prompt5.prompt.md', + // contents: 'oh hi, robot!', + // }, + // ], + // }, + // { + // name: '.github/prompts', + // children: [ + // { + // name: 'refactor-static-classes.prompt.md', + // contents: 'file contents', + // }, + // ], + // }, + // ], + // }, + // // note! this folder is part of the workspace, so prompt files are `included` + // { + // name: '/var/shared/prompts/.github/prompts', + // children: [ + // { + // name: 'prompt-name.prompt.md', + // contents: 'oh hi, robot!', + // }, + // { + // name: 'name-of-the-prompt.prompt.md', + // contents: 'oh hi, raw bot!', + // }, + // ], + // }, + // ]); - assert.deepStrictEqual( - await locator.listFiles(), - [ - createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), - createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), - createURI('/tmp/prompts/translate.to-rust.prompt.md'), - ], - 'Must find correct prompts.', - ); - }); - }); - }); - }); + // assert.deepStrictEqual( + // await locator.listFiles(), + // [ + // createURI('/Users/legomushroom/repos/prompts/test.prompt.md'), + // createURI('/Users/legomushroom/repos/prompts/refactor-tests.prompt.md'), + // createURI('/tmp/prompts/translate.to-rust.prompt.md'), + // ], + // 'Must find correct prompts.', + // ); + // }); + // }); + // }); + // }); });