Extensibility: Gemini.md files (#944)

This commit is contained in:
matt korwel 2025-06-11 13:34:35 -07:00 committed by GitHub
parent 24c61147b8
commit 4160d904da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 139 additions and 27 deletions

View file

@ -41,28 +41,47 @@ describe('loadExtensions', () => {
fs.rmSync(tempHomeDir, { recursive: true, force: true });
});
it('should deduplicate extensions, prioritizing the workspace directory', () => {
// Create extensions in the workspace
it('should load context file path when gemini.md is present', () => {
const workspaceExtensionsDir = path.join(
tempWorkspaceDir,
EXTENSIONS_DIRECTORY_NAME,
);
fs.mkdirSync(workspaceExtensionsDir, { recursive: true });
createExtension(workspaceExtensionsDir, 'ext1', '1.0.0');
createExtension(workspaceExtensionsDir, 'ext1', '1.0.0', true);
createExtension(workspaceExtensionsDir, 'ext2', '2.0.0');
// Create extensions in the home directory
const homeExtensionsDir = path.join(tempHomeDir, EXTENSIONS_DIRECTORY_NAME);
fs.mkdirSync(homeExtensionsDir, { recursive: true });
createExtension(homeExtensionsDir, 'ext1', '1.1.0'); // Duplicate that should be ignored
createExtension(homeExtensionsDir, 'ext3', '3.0.0');
const extensions = loadExtensions(tempWorkspaceDir);
expect(extensions).toHaveLength(3);
expect(extensions.find((e) => e.name === 'ext1')?.version).toBe('1.0.0'); // Workspace version should be kept
expect(extensions.find((e) => e.name === 'ext2')?.version).toBe('2.0.0');
expect(extensions.find((e) => e.name === 'ext3')?.version).toBe('3.0.0');
expect(extensions).toHaveLength(2);
const ext1 = extensions.find((e) => e.name === 'ext1');
const ext2 = extensions.find((e) => e.name === 'ext2');
expect(ext1?.contextFileName).toBe(
path.join(workspaceExtensionsDir, 'ext1', 'gemini.md'),
);
expect(ext2?.contextFileName).toBeUndefined();
});
it('should load context file path from the extension config', () => {
const workspaceExtensionsDir = path.join(
tempWorkspaceDir,
EXTENSIONS_DIRECTORY_NAME,
);
fs.mkdirSync(workspaceExtensionsDir, { recursive: true });
createExtension(
workspaceExtensionsDir,
'ext1',
'1.0.0',
false,
'my-context.md',
);
const extensions = loadExtensions(tempWorkspaceDir);
expect(extensions).toHaveLength(1);
const ext1 = extensions.find((e) => e.name === 'ext1');
expect(ext1?.contextFileName).toBe(
path.join(workspaceExtensionsDir, 'ext1', 'my-context.md'),
);
});
});
@ -70,11 +89,21 @@ function createExtension(
extensionsDir: string,
name: string,
version: string,
addContextFile = false,
contextFileName?: string,
): void {
const extDir = path.join(extensionsDir, name);
fs.mkdirSync(extDir);
fs.writeFileSync(
path.join(extDir, EXTENSIONS_CONFIG_FILENAME),
JSON.stringify({ name, version }),
JSON.stringify({ name, version, contextFileName }),
);
if (addContextFile) {
fs.writeFileSync(path.join(extDir, 'gemini.md'), 'context');
}
if (contextFileName) {
fs.writeFileSync(path.join(extDir, contextFileName), 'context');
}
}