Skip to content

Commit 5f8354d

Browse files
committed
stop copying context templates during init/install
1 parent ab06897 commit 5f8354d

File tree

3 files changed

+20
-158
lines changed

3 files changed

+20
-158
lines changed

packages/cli/src/__tests__/lib/TemplateManager.test.ts

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('TemplateManager', () => {
2424
});
2525

2626
describe('setupSingleEnvironment', () => {
27-
it('should copy context file when it exists', async () => {
27+
it('should not copy context files', async () => {
2828
const env: EnvironmentDefinition = {
2929
code: 'test-env',
3030
name: 'Test Environment',
@@ -33,24 +33,17 @@ describe('TemplateManager', () => {
3333
isCustomCommandPath: false
3434
};
3535

36-
(mockFs.pathExists as any)
37-
.mockResolvedValueOnce(true)
38-
.mockResolvedValueOnce(true);
36+
(mockFs.pathExists as any).mockResolvedValueOnce(true);
3937

4038
(mockFs.readdir as any).mockResolvedValue(['command1.md', 'command2.toml']);
4139

4240
const result = await (templateManager as any).setupSingleEnvironment(env);
4341

44-
expect(mockFs.copy).toHaveBeenCalledWith(
45-
path.join(templateManager['templatesDir'], 'env', 'base.md'),
46-
path.join(templateManager['targetDir'], env.contextFileName)
47-
);
48-
expect(result).toContain(path.join(templateManager['targetDir'], env.contextFileName));
42+
expect(mockFs.copy).toHaveBeenCalledTimes(1);
43+
expect(result).toEqual([path.join(templateManager['targetDir'], env.commandPath, 'command1.md')]);
4944
});
5045

51-
it('should warn when context file does not exist', async () => {
52-
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
53-
46+
it('should not warn for missing context file', async () => {
5447
const env: EnvironmentDefinition = {
5548
code: 'test-env',
5649
name: 'Test Environment',
@@ -59,17 +52,14 @@ describe('TemplateManager', () => {
5952
isCustomCommandPath: false
6053
};
6154

62-
(mockFs.pathExists as any)
63-
.mockResolvedValueOnce(false)
64-
.mockResolvedValueOnce(true);
55+
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
56+
(mockFs.pathExists as any).mockResolvedValueOnce(true);
6557

6658
(mockFs.readdir as any).mockResolvedValue(['command1.md']);
6759

6860
const result = await (templateManager as any).setupSingleEnvironment(env);
6961

70-
expect(consoleWarnSpy).toHaveBeenCalledWith(
71-
expect.stringContaining('Warning: Context file not found')
72-
);
62+
expect(consoleWarnSpy).not.toHaveBeenCalled();
7363
expect(result).toEqual([path.join(templateManager['targetDir'], env.commandPath, 'command1.md')]);
7464

7565
consoleWarnSpy.mockRestore();
@@ -86,9 +76,7 @@ describe('TemplateManager', () => {
8676

8777
const mockCommandFiles = ['command1.md', 'command2.toml', 'command3.md'];
8878

89-
(mockFs.pathExists as any)
90-
.mockResolvedValueOnce(true) // context file exists
91-
.mockResolvedValueOnce(true); // commands directory exists
79+
(mockFs.pathExists as any).mockResolvedValueOnce(true); // commands directory exists
9280

9381
(mockFs.readdir as any).mockResolvedValue(mockCommandFiles);
9482

@@ -121,13 +109,11 @@ describe('TemplateManager', () => {
121109
isCustomCommandPath: true
122110
};
123111

124-
(mockFs.pathExists as any).mockResolvedValueOnce(true);
125-
126112
const result = await (templateManager as any).setupSingleEnvironment(env);
127113

128114
expect(mockFs.ensureDir).not.toHaveBeenCalled();
129-
expect(mockFs.copy).toHaveBeenCalledTimes(1);
130-
expect(result).toContain(path.join(templateManager['targetDir'], env.contextFileName));
115+
expect(mockFs.copy).not.toHaveBeenCalled();
116+
expect(result).toEqual([]);
131117
});
132118

133119
it('should handle cursor environment with special files', async () => {
@@ -142,7 +128,6 @@ describe('TemplateManager', () => {
142128
const mockRuleFiles = ['rule1.md', 'rule2.toml'];
143129

144130
(mockFs.pathExists as any)
145-
.mockResolvedValueOnce(true)
146131
.mockResolvedValueOnce(true).mockResolvedValueOnce(true);
147132

148133
(mockFs.readdir as any)
@@ -180,7 +165,6 @@ description: Test command description
180165
This is the prompt content.`;
181166

182167
(mockFs.pathExists as any)
183-
.mockResolvedValueOnce(true)
184168
.mockResolvedValueOnce(true)
185169
.mockResolvedValueOnce(true);
186170

@@ -219,7 +203,8 @@ This is the prompt content.`;
219203
};
220204

221205
const testError = new Error('Test error');
222-
(mockFs.pathExists as any).mockRejectedValue(testError);
206+
(mockFs.pathExists as any).mockResolvedValueOnce(true);
207+
(mockFs.readdir as any).mockRejectedValue(testError);
223208

224209
await expect((templateManager as any).setupSingleEnvironment(env)).rejects.toThrow('Test error');
225210

@@ -400,7 +385,7 @@ This is the prompt content.`;
400385
expect(result).toBe(false);
401386
});
402387

403-
it('should return true when context file exists', async () => {
388+
it('should return false when only context file exists', async () => {
404389
const envId: EnvironmentCode = 'cursor';
405390
const env = {
406391
code: 'cursor',
@@ -411,19 +396,14 @@ This is the prompt content.`;
411396

412397
mockGetEnvironment.mockReturnValue(env);
413398

414-
(mockFs.pathExists as any)
415-
.mockResolvedValueOnce(true) // context file exists
416-
.mockResolvedValueOnce(false); // command dir doesn't exist
399+
(mockFs.pathExists as any).mockResolvedValueOnce(false); // command dir doesn't exist
417400

418401
const result = await templateManager.checkEnvironmentExists(envId);
419402

420-
expect(mockFs.pathExists).toHaveBeenCalledWith(
421-
path.join(templateManager['targetDir'], env.contextFileName)
422-
);
423403
expect(mockFs.pathExists).toHaveBeenCalledWith(
424404
path.join(templateManager['targetDir'], env.commandPath)
425405
);
426-
expect(result).toBe(true);
406+
expect(result).toBe(false);
427407
});
428408

429409
it('should return true when command directory exists', async () => {
@@ -437,16 +417,14 @@ This is the prompt content.`;
437417

438418
mockGetEnvironment.mockReturnValue(env);
439419

440-
(mockFs.pathExists as any)
441-
.mockResolvedValueOnce(false) // context file doesn't exist
442-
.mockResolvedValueOnce(true); // command dir exists
420+
(mockFs.pathExists as any).mockResolvedValueOnce(true); // command dir exists
443421

444422
const result = await templateManager.checkEnvironmentExists(envId);
445423

446424
expect(result).toBe(true);
447425
});
448426

449-
it('should return false when neither context file nor command directory exists', async () => {
427+
it('should return false when command directory does not exist', async () => {
450428
const envId: EnvironmentCode = 'cursor';
451429
const env = {
452430
code: 'cursor',
@@ -457,9 +435,7 @@ This is the prompt content.`;
457435

458436
mockGetEnvironment.mockReturnValue(env);
459437

460-
(mockFs.pathExists as any)
461-
.mockResolvedValueOnce(false) // context file doesn't exist
462-
.mockResolvedValueOnce(false); // command dir doesn't exist
438+
(mockFs.pathExists as any).mockResolvedValueOnce(false); // command dir doesn't exist
463439

464440
const result = await templateManager.checkEnvironmentExists(envId);
465441

packages/cli/src/lib/TemplateManager.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,10 @@ export class TemplateManager {
6767
return false;
6868
}
6969

70-
const contextFilePath = path.join(this.targetDir, env.contextFileName);
71-
const contextFileExists = await fs.pathExists(contextFilePath);
72-
7370
const commandDirPath = path.join(this.targetDir, env.commandPath);
7471
const commandDirExists = await fs.pathExists(commandDirPath);
7572

76-
return contextFileExists || commandDirExists;
73+
return commandDirExists;
7774
}
7875

7976
private async setupSingleEnvironment(
@@ -82,16 +79,6 @@ export class TemplateManager {
8279
const copiedFiles: string[] = [];
8380

8481
try {
85-
const contextSource = path.join(this.templatesDir, "env", "base.md");
86-
const contextTarget = path.join(this.targetDir, env.contextFileName);
87-
88-
if (await fs.pathExists(contextSource)) {
89-
await fs.copy(contextSource, contextTarget);
90-
copiedFiles.push(contextTarget);
91-
} else {
92-
console.warn(`Warning: Context file not found: ${contextSource}`);
93-
}
94-
9582
if (!env.isCustomCommandPath) {
9683
await this.copyCommands(env, copiedFiles);
9784
}

packages/cli/templates/env/base.md

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)