genaicode 0.0.35 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/bin/genaicode-dev.js +11 -0
- package/bin/genaicode.cjs +8 -1
- package/dist/ai-service/ai-studio.d.ts +5 -0
- package/dist/ai-service/ai-studio.js +135 -0
- package/dist/ai-service/ai-studio.js.map +1 -0
- package/dist/ai-service/anthropic.d.ts +5 -0
- package/dist/ai-service/anthropic.js +133 -0
- package/dist/ai-service/anthropic.js.map +1 -0
- package/dist/ai-service/chat-gpt.d.ts +5 -0
- package/dist/ai-service/chat-gpt.js +131 -0
- package/dist/ai-service/chat-gpt.js.map +1 -0
- package/dist/ai-service/common.d.ts +57 -0
- package/dist/ai-service/common.js +38 -0
- package/dist/ai-service/common.js.map +1 -0
- package/dist/ai-service/common.test.d.ts +1 -0
- package/dist/ai-service/common.test.js +85 -0
- package/dist/ai-service/common.test.js.map +1 -0
- package/dist/ai-service/dall-e.d.ts +14 -0
- package/dist/ai-service/dall-e.js +47 -0
- package/dist/ai-service/dall-e.js.map +1 -0
- package/dist/ai-service/vertex-ai-claude.d.ts +5 -0
- package/dist/ai-service/vertex-ai-claude.js +93 -0
- package/dist/ai-service/vertex-ai-claude.js.map +1 -0
- package/dist/ai-service/vertex-ai-imagen.d.ts +14 -0
- package/dist/ai-service/vertex-ai-imagen.js +74 -0
- package/dist/ai-service/vertex-ai-imagen.js.map +1 -0
- package/dist/ai-service/vertex-ai.d.ts +7 -0
- package/dist/ai-service/vertex-ai.js +147 -0
- package/dist/ai-service/vertex-ai.js.map +1 -0
- package/dist/cli/cli-options.d.ts +10 -0
- package/dist/cli/cli-options.js +124 -0
- package/dist/cli/cli-options.js.map +1 -0
- package/dist/cli/cli-options.test.d.ts +1 -0
- package/dist/cli/cli-options.test.js +34 -0
- package/dist/cli/cli-options.test.js.map +1 -0
- package/dist/cli/cli-params.d.ts +29 -0
- package/dist/cli/cli-params.js +103 -0
- package/dist/cli/cli-params.js.map +1 -0
- package/dist/cli/cli-params.test.d.ts +1 -0
- package/dist/cli/cli-params.test.js +38 -0
- package/dist/cli/cli-params.test.js.map +1 -0
- package/dist/cli/service-autodetect.d.ts +2 -0
- package/dist/cli/service-autodetect.js +17 -0
- package/dist/cli/service-autodetect.js.map +1 -0
- package/dist/cli/service-autodetect.test.d.ts +1 -0
- package/dist/cli/service-autodetect.test.js +38 -0
- package/dist/cli/service-autodetect.test.js.map +1 -0
- package/dist/cli/validate-cli-params.d.ts +18 -0
- package/dist/cli/validate-cli-params.js +128 -0
- package/dist/cli/validate-cli-params.js.map +1 -0
- package/dist/cli/validate-cli-params.test.d.ts +1 -0
- package/dist/cli/validate-cli-params.test.js +106 -0
- package/dist/cli/validate-cli-params.test.js.map +1 -0
- package/dist/files/file-utils.d.ts +2 -0
- package/dist/files/file-utils.js +7 -0
- package/dist/files/file-utils.js.map +1 -0
- package/dist/files/file-utils.test.d.ts +1 -0
- package/dist/files/file-utils.test.js +18 -0
- package/dist/files/file-utils.test.js.map +1 -0
- package/dist/files/find-files.d.ts +8 -0
- package/dist/files/find-files.js +76 -0
- package/dist/files/find-files.js.map +1 -0
- package/dist/files/read-files.d.ts +13 -0
- package/dist/files/read-files.js +61 -0
- package/dist/files/read-files.js.map +1 -0
- package/dist/files/read-files.test.d.ts +1 -0
- package/dist/files/read-files.test.js +89 -0
- package/dist/files/read-files.test.js.map +1 -0
- package/dist/files/temp-buffer.d.ts +2 -0
- package/dist/files/temp-buffer.js +12 -0
- package/dist/files/temp-buffer.js.map +1 -0
- package/dist/files/update-files.d.ts +5 -0
- package/dist/files/update-files.js +197 -0
- package/dist/files/update-files.js.map +1 -0
- package/dist/images/ensure-alpha.d.ts +1 -0
- package/dist/images/ensure-alpha.js +5 -0
- package/dist/images/ensure-alpha.js.map +1 -0
- package/dist/images/imgly-remove-background.d.ts +2 -0
- package/dist/images/imgly-remove-background.js +21 -0
- package/dist/images/imgly-remove-background.js.map +1 -0
- package/dist/images/resize-image.d.ts +19 -0
- package/dist/images/resize-image.js +22 -0
- package/dist/images/resize-image.js.map +1 -0
- package/dist/images/split-image.d.ts +18 -0
- package/dist/images/split-image.js +25 -0
- package/dist/images/split-image.js.map +1 -0
- package/dist/main/codegen.d.ts +2 -0
- package/dist/main/codegen.js +101 -0
- package/dist/main/codegen.js.map +1 -0
- package/dist/main/codegen.test.d.ts +2 -0
- package/dist/main/codegen.test.js +259 -0
- package/dist/main/codegen.test.js.map +1 -0
- package/dist/main/config-lib.d.ts +8 -0
- package/dist/main/config-lib.js +28 -0
- package/dist/main/config-lib.js.map +1 -0
- package/dist/main/config-lib.test.d.ts +1 -0
- package/dist/main/config-lib.test.js +64 -0
- package/dist/main/config-lib.test.js.map +1 -0
- package/dist/main/config.d.ts +5 -0
- package/{src → dist}/main/config.js +16 -22
- package/dist/main/config.js.map +1 -0
- package/dist/prompt/function-calling-validate.d.ts +3 -0
- package/dist/prompt/function-calling-validate.js +27 -0
- package/dist/prompt/function-calling-validate.js.map +1 -0
- package/dist/prompt/function-calling.d.ts +5 -0
- package/dist/prompt/function-calling.js +48 -0
- package/dist/prompt/function-calling.js.map +1 -0
- package/dist/prompt/function-defs/ask-question.d.ts +31 -0
- package/dist/prompt/function-defs/ask-question.js +32 -0
- package/dist/prompt/function-defs/ask-question.js.map +1 -0
- package/dist/prompt/function-defs/codegen-summary.d.ts +63 -0
- package/dist/prompt/function-defs/codegen-summary.js +80 -0
- package/dist/prompt/function-defs/codegen-summary.js.map +1 -0
- package/dist/prompt/function-defs/create-directory.d.ts +21 -0
- package/dist/prompt/function-defs/create-directory.js +22 -0
- package/dist/prompt/function-defs/create-directory.js.map +1 -0
- package/dist/prompt/function-defs/create-file.d.ts +25 -0
- package/dist/prompt/function-defs/create-file.js +26 -0
- package/dist/prompt/function-defs/create-file.js.map +1 -0
- package/dist/prompt/function-defs/delete-file.d.ts +21 -0
- package/dist/prompt/function-defs/delete-file.js +22 -0
- package/dist/prompt/function-defs/delete-file.js.map +1 -0
- package/dist/prompt/function-defs/download-file.d.ts +25 -0
- package/dist/prompt/function-defs/download-file.js +26 -0
- package/dist/prompt/function-defs/download-file.js.map +1 -0
- package/dist/prompt/function-defs/explanation.d.ts +17 -0
- package/dist/prompt/function-defs/explanation.js +18 -0
- package/dist/prompt/function-defs/explanation.js.map +1 -0
- package/dist/prompt/function-defs/generate-image.d.ts +48 -0
- package/dist/prompt/function-defs/generate-image.js +49 -0
- package/dist/prompt/function-defs/generate-image.js.map +1 -0
- package/dist/prompt/function-defs/get-image-assets.d.ts +20 -0
- package/dist/prompt/function-defs/get-image-assets.js +21 -0
- package/dist/prompt/function-defs/get-image-assets.js.map +1 -0
- package/dist/prompt/function-defs/get-source-code.d.ts +20 -0
- package/dist/prompt/function-defs/get-source-code.js +21 -0
- package/dist/prompt/function-defs/get-source-code.js.map +1 -0
- package/dist/prompt/function-defs/imgly-remove-background.d.ts +25 -0
- package/dist/prompt/function-defs/imgly-remove-background.js +26 -0
- package/dist/prompt/function-defs/imgly-remove-background.js.map +1 -0
- package/dist/prompt/function-defs/move-file.d.ts +25 -0
- package/dist/prompt/function-defs/move-file.js +26 -0
- package/dist/prompt/function-defs/move-file.js.map +1 -0
- package/dist/prompt/function-defs/patch-file.d.ts +25 -0
- package/dist/prompt/function-defs/patch-file.js +39 -0
- package/dist/prompt/function-defs/patch-file.js.map +1 -0
- package/dist/prompt/function-defs/resize-image.d.ts +36 -0
- package/dist/prompt/function-defs/resize-image.js +37 -0
- package/dist/prompt/function-defs/resize-image.js.map +1 -0
- package/dist/prompt/function-defs/split-image.d.ts +57 -0
- package/dist/prompt/function-defs/split-image.js +46 -0
- package/dist/prompt/function-defs/split-image.js.map +1 -0
- package/dist/prompt/function-defs/update-file.d.ts +25 -0
- package/dist/prompt/function-defs/update-file.js +26 -0
- package/dist/prompt/function-defs/update-file.js.map +1 -0
- package/dist/prompt/limits.d.ts +3 -0
- package/dist/prompt/limits.js +19 -0
- package/dist/prompt/limits.js.map +1 -0
- package/dist/prompt/limits.test.d.ts +1 -0
- package/dist/prompt/limits.test.js +35 -0
- package/dist/prompt/limits.test.js.map +1 -0
- package/dist/prompt/prompt-codegen.d.ts +4 -0
- package/dist/prompt/prompt-codegen.js +81 -0
- package/dist/prompt/prompt-codegen.js.map +1 -0
- package/dist/prompt/prompt-codegen.test.d.ts +1 -0
- package/dist/prompt/prompt-codegen.test.js +94 -0
- package/dist/prompt/prompt-codegen.test.js.map +1 -0
- package/dist/prompt/prompt-consts.d.ts +1 -0
- package/{src → dist}/prompt/prompt-consts.js +1 -0
- package/dist/prompt/prompt-consts.js.map +1 -0
- package/dist/prompt/prompt-service-ask-question.test.d.ts +3 -0
- package/dist/prompt/prompt-service-ask-question.test.js +146 -0
- package/dist/prompt/prompt-service-ask-question.test.js.map +1 -0
- package/dist/prompt/prompt-service.d.ts +13 -0
- package/dist/prompt/prompt-service.js +278 -0
- package/dist/prompt/prompt-service.js.map +1 -0
- package/dist/prompt/prompt-service.test.d.ts +1 -0
- package/dist/prompt/prompt-service.test.js +511 -0
- package/dist/prompt/prompt-service.test.js.map +1 -0
- package/dist/prompt/systemprompt.d.ts +2 -0
- package/dist/prompt/systemprompt.js +43 -0
- package/dist/prompt/systemprompt.js.map +1 -0
- package/dist/prompt/systemprompt.test.d.ts +2 -0
- package/dist/prompt/systemprompt.test.js +47 -0
- package/dist/prompt/systemprompt.test.js.map +1 -0
- package/package.json +15 -5
- package/bin/genaicode.js +0 -5
- package/src/ai-service/anthropic.js +0 -95
- package/src/ai-service/chat-gpt.js +0 -99
- package/src/ai-service/common.js +0 -40
- package/src/ai-service/common.test.js +0 -107
- package/src/ai-service/dall-e.js +0 -50
- package/src/ai-service/vertex-ai-claude.js +0 -99
- package/src/ai-service/vertex-ai-imagen.js +0 -78
- package/src/ai-service/vertex-ai.js +0 -156
- package/src/cli/cli-options.js +0 -120
- package/src/cli/cli-options.test.js +0 -50
- package/src/cli/cli-params.js +0 -99
- package/src/cli/cli-params.test.js +0 -43
- package/src/cli/service-autodetect.js +0 -11
- package/src/cli/service-autodetect.test.js +0 -43
- package/src/cli/validate-cli-params.js +0 -117
- package/src/cli/validate-cli-params.test.js +0 -134
- package/src/files/file-utils.js +0 -7
- package/src/files/file-utils.test.js +0 -21
- package/src/files/find-files.js +0 -86
- package/src/files/read-files.js +0 -60
- package/src/files/read-files.test.js +0 -102
- package/src/files/temp-buffer.js +0 -13
- package/src/files/update-files.js +0 -205
- package/src/images/ensure-alpha.js +0 -5
- package/src/images/imgly-remove-background.js +0 -23
- package/src/images/resize-image.js +0 -23
- package/src/images/split-image.js +0 -26
- package/src/main/codegen.js +0 -120
- package/src/main/codegen.test.js +0 -334
- package/src/main/config-lib.js +0 -33
- package/src/main/config-lib.test.js +0 -80
- package/src/prompt/function-calling-validate.js +0 -25
- package/src/prompt/function-calling.js +0 -454
- package/src/prompt/limits.js +0 -23
- package/src/prompt/limits.test.js +0 -40
- package/src/prompt/prompt-codegen.js +0 -106
- package/src/prompt/prompt-codegen.test.js +0 -116
- package/src/prompt/prompt-service.js +0 -287
- package/src/prompt/prompt-service.test.js +0 -601
- package/src/prompt/systemprompt.js +0 -32
- package/src/prompt/systemprompt.test.js +0 -63
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
/*eslint-disable no-import-assign*/
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
4
|
-
import { promptService } from './prompt-service.js';
|
|
5
|
-
import * as vertexAi from '../ai-service/vertex-ai.js';
|
|
6
|
-
import * as chatGpt from '../ai-service/chat-gpt.js';
|
|
7
|
-
import * as anthropic from '../ai-service/anthropic.js';
|
|
8
|
-
import * as cliParams from '../cli/cli-params.js';
|
|
9
|
-
import fs from 'fs';
|
|
10
|
-
import * as diff from 'diff';
|
|
11
|
-
import mime from 'mime-types';
|
|
12
|
-
import { getImageAssets } from '../files/read-files.js';
|
|
13
|
-
import '../files/find-files.js';
|
|
14
|
-
import * as dalleService from '../ai-service/dall-e.js';
|
|
15
|
-
|
|
16
|
-
vi.mock('../ai-service/vertex-ai.js', () => ({ generateContent: vi.fn() }));
|
|
17
|
-
vi.mock('../ai-service/chat-gpt.js', () => ({ generateContent: vi.fn() }));
|
|
18
|
-
vi.mock('../ai-service/anthropic.js', () => ({ generateContent: vi.fn() }));
|
|
19
|
-
vi.mock('../cli/cli-params.js', () => ({
|
|
20
|
-
requireExplanations: false,
|
|
21
|
-
considerAllFiles: false,
|
|
22
|
-
dependencyTree: false,
|
|
23
|
-
explicitPrompt: false,
|
|
24
|
-
allowFileCreate: false,
|
|
25
|
-
allowFileDelete: false,
|
|
26
|
-
allowDirectoryCreate: false,
|
|
27
|
-
allowFileMove: false,
|
|
28
|
-
verbosePrompt: false,
|
|
29
|
-
disableContextOptimization: false,
|
|
30
|
-
vision: false,
|
|
31
|
-
imagen: false,
|
|
32
|
-
temperature: 0.7,
|
|
33
|
-
cheap: false,
|
|
34
|
-
}));
|
|
35
|
-
vi.mock('fs');
|
|
36
|
-
vi.mock('diff');
|
|
37
|
-
vi.mock('mime-types');
|
|
38
|
-
vi.mock('../ai-service/dall-e.js', () => ({ generateImage: vi.fn() }));
|
|
39
|
-
|
|
40
|
-
// Mock find-files module
|
|
41
|
-
vi.mock('../files/find-files.js', () => ({
|
|
42
|
-
getSourceFiles: () => [],
|
|
43
|
-
getImageAssetFiles: () => [],
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
// Mock read-files module
|
|
47
|
-
vi.mock('../files/read-files.js', () => ({
|
|
48
|
-
getSourceCode: () => ({}),
|
|
49
|
-
getImageAssets: vi.fn(() => ({})),
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
vi.mock('../main/config.js', () => ({
|
|
53
|
-
rootDir: '/mocked/root/dir',
|
|
54
|
-
rcConfig: {
|
|
55
|
-
rootDir: '.',
|
|
56
|
-
extensions: ['.js', '.ts', '.tsx', '.jsx'],
|
|
57
|
-
},
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
describe('promptService', () => {
|
|
61
|
-
beforeEach(() => {
|
|
62
|
-
vi.resetAllMocks();
|
|
63
|
-
cliParams.anthropic = false;
|
|
64
|
-
cliParams.chatGpt = false;
|
|
65
|
-
cliParams.vertexAi = false;
|
|
66
|
-
cliParams.dryRun = false;
|
|
67
|
-
cliParams.vision = false;
|
|
68
|
-
cliParams.imagen = false;
|
|
69
|
-
cliParams.disableContextOptimization = false;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should process the codegen summary and return the result with Vertex AI', async () => {
|
|
73
|
-
cliParams.vertexAi = true;
|
|
74
|
-
const mockFunctionCalls = [
|
|
75
|
-
{ name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Hello");' } },
|
|
76
|
-
];
|
|
77
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
|
|
78
|
-
|
|
79
|
-
const result = await promptService(vertexAi.generateContent);
|
|
80
|
-
|
|
81
|
-
expect(result).toEqual(mockFunctionCalls);
|
|
82
|
-
expect(vertexAi.generateContent).toHaveBeenCalled();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should process the codegen summary and return the result with ChatGPT', async () => {
|
|
86
|
-
cliParams.chatGpt = true;
|
|
87
|
-
const mockFunctionCalls = [{ name: 'createFile', args: { filePath: 'new.js', newContent: 'const x = 5;' } }];
|
|
88
|
-
chatGpt.generateContent.mockResolvedValueOnce(mockFunctionCalls);
|
|
89
|
-
|
|
90
|
-
const result = await promptService(chatGpt.generateContent);
|
|
91
|
-
|
|
92
|
-
expect(result).toEqual(mockFunctionCalls);
|
|
93
|
-
expect(chatGpt.generateContent).toHaveBeenCalled();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should process the codegen summary and return the result with Anthropic', async () => {
|
|
97
|
-
cliParams.anthropic = true;
|
|
98
|
-
const mockFunctionCalls = [{ name: 'deleteFile', args: { filePath: 'obsolete.js' } }];
|
|
99
|
-
anthropic.generateContent.mockResolvedValueOnce(mockFunctionCalls);
|
|
100
|
-
|
|
101
|
-
const result = await promptService(anthropic.generateContent);
|
|
102
|
-
|
|
103
|
-
expect(result).toEqual(mockFunctionCalls);
|
|
104
|
-
expect(anthropic.generateContent).toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should not update files in dry run mode', async () => {
|
|
108
|
-
cliParams.vertexAi = true;
|
|
109
|
-
cliParams.dryRun = true;
|
|
110
|
-
const mockFunctionCalls = [
|
|
111
|
-
{ name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Dry run");' } },
|
|
112
|
-
];
|
|
113
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
|
|
114
|
-
|
|
115
|
-
const result = await promptService(vertexAi.generateContent);
|
|
116
|
-
|
|
117
|
-
expect(result).toEqual(mockFunctionCalls);
|
|
118
|
-
expect(vertexAi.generateContent).toHaveBeenCalled();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should handle invalid patchFile call and retry without patchFile function', async () => {
|
|
122
|
-
cliParams.vertexAi = true;
|
|
123
|
-
const mockCodegenSummary = [
|
|
124
|
-
{
|
|
125
|
-
name: 'codegenSummary',
|
|
126
|
-
args: {
|
|
127
|
-
fileUpdates: [{ path: 'test.js', updateToolName: 'patchFile' }],
|
|
128
|
-
contextPaths: [],
|
|
129
|
-
explanation: 'Mock summary',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
];
|
|
133
|
-
const mockInvalidPatchCall = [
|
|
134
|
-
{
|
|
135
|
-
name: 'patchFile',
|
|
136
|
-
args: {
|
|
137
|
-
filePath: 'test.js',
|
|
138
|
-
patch: 'invalid patch',
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
];
|
|
142
|
-
const mockValidUpdateCall = [
|
|
143
|
-
{
|
|
144
|
-
name: 'updateFile',
|
|
145
|
-
args: {
|
|
146
|
-
filePath: 'test.js',
|
|
147
|
-
newContent: 'console.log("Updated content");',
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
// Mock the first call to return the codegen summary
|
|
153
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockCodegenSummary);
|
|
154
|
-
// Mock the second call to return an invalid patch
|
|
155
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockInvalidPatchCall);
|
|
156
|
-
// Mock the third call (retry) to return a valid update
|
|
157
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockValidUpdateCall);
|
|
158
|
-
|
|
159
|
-
// Mock fs.readFileSync to return some content
|
|
160
|
-
fs.readFileSync.mockReturnValue('Original content');
|
|
161
|
-
|
|
162
|
-
// Mock diff.applyPatch to fail for the invalid patch
|
|
163
|
-
diff.applyPatch.mockReturnValue(false);
|
|
164
|
-
|
|
165
|
-
const result = await promptService(vertexAi.generateContent);
|
|
166
|
-
|
|
167
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(3);
|
|
168
|
-
expect(fs.readFileSync).toHaveBeenCalledWith('test.js', 'utf-8');
|
|
169
|
-
expect(diff.applyPatch).toHaveBeenCalledWith('Original content', 'invalid patch');
|
|
170
|
-
expect(result).toEqual(mockValidUpdateCall);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should include image assets when vision flag is true', async () => {
|
|
174
|
-
cliParams.chatGpt = true;
|
|
175
|
-
cliParams.vision = true;
|
|
176
|
-
const mockImageAssets = {
|
|
177
|
-
'/path/to/image1.png': { width: 100, height: 100 },
|
|
178
|
-
'/path/to/image2.jpg': { width: 200, height: 200 },
|
|
179
|
-
};
|
|
180
|
-
const mockFunctionCalls = [
|
|
181
|
-
{ name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Vision test");' } },
|
|
182
|
-
];
|
|
183
|
-
|
|
184
|
-
getImageAssets.mockReturnValue(mockImageAssets);
|
|
185
|
-
chatGpt.generateContent.mockResolvedValueOnce(mockFunctionCalls);
|
|
186
|
-
|
|
187
|
-
await promptService(chatGpt.generateContent);
|
|
188
|
-
|
|
189
|
-
expect(chatGpt.generateContent).toHaveBeenCalled();
|
|
190
|
-
const calls = chatGpt.generateContent.mock.calls[0];
|
|
191
|
-
expect(calls[0]).toEqual(
|
|
192
|
-
expect.arrayContaining([
|
|
193
|
-
expect.objectContaining({
|
|
194
|
-
type: 'user',
|
|
195
|
-
text: expect.stringContaining('I should also provide you with a summary of application image assets'),
|
|
196
|
-
}),
|
|
197
|
-
expect.objectContaining({
|
|
198
|
-
type: 'assistant',
|
|
199
|
-
text: expect.stringContaining('Please provide summary of application image assets.'),
|
|
200
|
-
}),
|
|
201
|
-
expect.objectContaining({
|
|
202
|
-
type: 'user',
|
|
203
|
-
functionResponses: [{ name: 'getImageAssets', content: JSON.stringify(mockImageAssets) }],
|
|
204
|
-
}),
|
|
205
|
-
]),
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('should include image data in the prompt when processing files with vision', async () => {
|
|
210
|
-
cliParams.chatGpt = true;
|
|
211
|
-
cliParams.vision = true;
|
|
212
|
-
const mockCodegenSummary = [
|
|
213
|
-
{
|
|
214
|
-
name: 'codegenSummary',
|
|
215
|
-
args: {
|
|
216
|
-
fileUpdates: [
|
|
217
|
-
{
|
|
218
|
-
path: 'test.js',
|
|
219
|
-
updateToolName: 'updateFile',
|
|
220
|
-
contextImageAssets: ['/path/to/image1.png', '/path/to/image2.jpg'],
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
contextPaths: [],
|
|
224
|
-
explanation: 'Mock summary',
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
];
|
|
228
|
-
const mockUpdateCall = [
|
|
229
|
-
{
|
|
230
|
-
name: 'updateFile',
|
|
231
|
-
args: {
|
|
232
|
-
filePath: 'test.js',
|
|
233
|
-
newContent: 'console.log("Updated with vision");',
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
|
-
];
|
|
237
|
-
|
|
238
|
-
chatGpt.generateContent.mockResolvedValueOnce(mockCodegenSummary);
|
|
239
|
-
chatGpt.generateContent.mockResolvedValueOnce(mockUpdateCall);
|
|
240
|
-
|
|
241
|
-
fs.readFileSync.mockImplementation((path) => `mock-base64-data-for-${path}`);
|
|
242
|
-
mime.lookup.mockImplementation((path) => (path.endsWith('.png') ? 'image/png' : 'image/jpeg'));
|
|
243
|
-
|
|
244
|
-
await promptService(chatGpt.generateContent);
|
|
245
|
-
|
|
246
|
-
expect(chatGpt.generateContent).toHaveBeenCalledTimes(2);
|
|
247
|
-
const secondCall = chatGpt.generateContent.mock.calls[1];
|
|
248
|
-
expect(secondCall[0]).toEqual(
|
|
249
|
-
expect.arrayContaining([
|
|
250
|
-
expect.objectContaining({
|
|
251
|
-
type: 'user',
|
|
252
|
-
text: expect.stringContaining('suggest changes for the `test.js` file'),
|
|
253
|
-
images: [
|
|
254
|
-
{
|
|
255
|
-
path: '/path/to/image1.png',
|
|
256
|
-
base64url: 'mock-base64-data-for-/path/to/image1.png',
|
|
257
|
-
mediaType: 'image/png',
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
path: '/path/to/image2.jpg',
|
|
261
|
-
base64url: 'mock-base64-data-for-/path/to/image2.jpg',
|
|
262
|
-
mediaType: 'image/jpeg',
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
}),
|
|
266
|
-
]),
|
|
267
|
-
);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('should not include image assets when vision flag is false', async () => {
|
|
271
|
-
cliParams.chatGpt = true;
|
|
272
|
-
cliParams.vision = false;
|
|
273
|
-
const mockFunctionCalls = [
|
|
274
|
-
{ name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("No vision test");' } },
|
|
275
|
-
];
|
|
276
|
-
|
|
277
|
-
chatGpt.generateContent.mockResolvedValueOnce(mockFunctionCalls);
|
|
278
|
-
|
|
279
|
-
await promptService(chatGpt.generateContent);
|
|
280
|
-
|
|
281
|
-
expect(chatGpt.generateContent).toHaveBeenCalled();
|
|
282
|
-
const calls = chatGpt.generateContent.mock.calls[0];
|
|
283
|
-
expect(calls[0]).not.toEqual(
|
|
284
|
-
expect.arrayContaining([
|
|
285
|
-
expect.objectContaining({
|
|
286
|
-
type: 'user',
|
|
287
|
-
text: expect.stringContaining('I should also provide you with a summary of application image assets'),
|
|
288
|
-
}),
|
|
289
|
-
]),
|
|
290
|
-
);
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('should handle context optimization', async () => {
|
|
294
|
-
cliParams.vertexAi = true;
|
|
295
|
-
const mockCodegenSummary = [
|
|
296
|
-
{
|
|
297
|
-
name: 'codegenSummary',
|
|
298
|
-
args: {
|
|
299
|
-
fileUpdates: [{ path: 'test.js', updateToolName: 'updateFile' }],
|
|
300
|
-
contextPaths: ['context1.js', 'context2.js'],
|
|
301
|
-
explanation: 'Mock summary with context',
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
];
|
|
305
|
-
const mockUpdateCall = [
|
|
306
|
-
{
|
|
307
|
-
name: 'updateFile',
|
|
308
|
-
args: {
|
|
309
|
-
filePath: 'test.js',
|
|
310
|
-
newContent: 'console.log("Updated with context");',
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
];
|
|
314
|
-
|
|
315
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockCodegenSummary);
|
|
316
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockUpdateCall);
|
|
317
|
-
|
|
318
|
-
await promptService(vertexAi.generateContent);
|
|
319
|
-
|
|
320
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(2);
|
|
321
|
-
const firstCall = vertexAi.generateContent.mock.calls[0];
|
|
322
|
-
expect(firstCall[0]).toEqual(
|
|
323
|
-
expect.arrayContaining([
|
|
324
|
-
expect.objectContaining({
|
|
325
|
-
type: 'user',
|
|
326
|
-
functionResponses: [
|
|
327
|
-
expect.objectContaining({
|
|
328
|
-
name: 'getSourceCode',
|
|
329
|
-
content: expect.any(String),
|
|
330
|
-
}),
|
|
331
|
-
],
|
|
332
|
-
}),
|
|
333
|
-
]),
|
|
334
|
-
);
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('should handle disableContextOptimization flag', async () => {
|
|
338
|
-
cliParams.vertexAi = true;
|
|
339
|
-
cliParams.disableContextOptimization = true;
|
|
340
|
-
const mockCodegenSummary = [
|
|
341
|
-
{
|
|
342
|
-
name: 'codegenSummary',
|
|
343
|
-
args: {
|
|
344
|
-
fileUpdates: [{ path: 'test.js', updateToolName: 'updateFile' }],
|
|
345
|
-
contextPaths: ['context1.js', 'context2.js'],
|
|
346
|
-
explanation: 'Mock summary without context optimization',
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
];
|
|
350
|
-
const mockUpdateCall = [
|
|
351
|
-
{
|
|
352
|
-
name: 'updateFile',
|
|
353
|
-
args: {
|
|
354
|
-
filePath: 'test.js',
|
|
355
|
-
newContent: 'console.log("Updated without context optimization");',
|
|
356
|
-
},
|
|
357
|
-
},
|
|
358
|
-
];
|
|
359
|
-
|
|
360
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockCodegenSummary);
|
|
361
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockUpdateCall);
|
|
362
|
-
|
|
363
|
-
await promptService(vertexAi.generateContent);
|
|
364
|
-
|
|
365
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(2);
|
|
366
|
-
const firstCall = vertexAi.generateContent.mock.calls[0];
|
|
367
|
-
expect(firstCall[0]).not.toEqual(
|
|
368
|
-
expect.arrayContaining([
|
|
369
|
-
expect.objectContaining({
|
|
370
|
-
type: 'user',
|
|
371
|
-
functionResponses: [
|
|
372
|
-
expect.objectContaining({
|
|
373
|
-
name: 'getSourceCode',
|
|
374
|
-
content: expect.stringContaining('context1.js'),
|
|
375
|
-
}),
|
|
376
|
-
],
|
|
377
|
-
}),
|
|
378
|
-
]),
|
|
379
|
-
);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
it('should handle image generation requests', async () => {
|
|
383
|
-
cliParams.vertexAi = true;
|
|
384
|
-
cliParams.imagen = true;
|
|
385
|
-
const mockCodegenSummary = [
|
|
386
|
-
{
|
|
387
|
-
name: 'codegenSummary',
|
|
388
|
-
args: {
|
|
389
|
-
fileUpdates: [{ path: 'test.js', updateToolName: 'updateFile' }],
|
|
390
|
-
contextPaths: [],
|
|
391
|
-
explanation: 'Mock summary with image generation',
|
|
392
|
-
},
|
|
393
|
-
},
|
|
394
|
-
];
|
|
395
|
-
const mockGenerateImageCall = [
|
|
396
|
-
{
|
|
397
|
-
name: 'generateImage',
|
|
398
|
-
args: {
|
|
399
|
-
prompt: 'A test image',
|
|
400
|
-
filePath: '/path/to/generated/image.png',
|
|
401
|
-
size: { width: 256, height: 256 },
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
];
|
|
405
|
-
const mockDownloadFileCall = [
|
|
406
|
-
{
|
|
407
|
-
name: 'downloadFile',
|
|
408
|
-
args: {
|
|
409
|
-
filePath: '/path/to/generated/image.png',
|
|
410
|
-
explanation: 'Downloading generated image',
|
|
411
|
-
downloadUrl: 'https://example.com/generated-image.png',
|
|
412
|
-
},
|
|
413
|
-
},
|
|
414
|
-
];
|
|
415
|
-
|
|
416
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockCodegenSummary);
|
|
417
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockGenerateImageCall);
|
|
418
|
-
dalleService.generateImage.mockResolvedValue('https://example.com/generated-image.png');
|
|
419
|
-
|
|
420
|
-
const result = await promptService(vertexAi.generateContent, dalleService.generateImage);
|
|
421
|
-
|
|
422
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(2);
|
|
423
|
-
expect(dalleService.generateImage).toHaveBeenCalledWith(
|
|
424
|
-
'A test image',
|
|
425
|
-
undefined,
|
|
426
|
-
{ width: 256, height: 256 },
|
|
427
|
-
false,
|
|
428
|
-
);
|
|
429
|
-
expect(result).toEqual(expect.arrayContaining(mockDownloadFileCall));
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
it('should handle image generation failure', async () => {
|
|
433
|
-
cliParams.vertexAi = true;
|
|
434
|
-
cliParams.imagen = true;
|
|
435
|
-
const mockCodegenSummary = [
|
|
436
|
-
{
|
|
437
|
-
name: 'codegenSummary',
|
|
438
|
-
args: {
|
|
439
|
-
fileUpdates: [{ path: 'test.js', updateToolName: 'updateFile' }],
|
|
440
|
-
contextPaths: [],
|
|
441
|
-
explanation: 'Mock summary with image generation failure',
|
|
442
|
-
},
|
|
443
|
-
},
|
|
444
|
-
];
|
|
445
|
-
const mockGenerateImageCall = [
|
|
446
|
-
{
|
|
447
|
-
name: 'generateImage',
|
|
448
|
-
args: {
|
|
449
|
-
prompt: 'A test image',
|
|
450
|
-
filePath: '/path/to/generated/image.png',
|
|
451
|
-
size: { width: 256, height: 256 },
|
|
452
|
-
},
|
|
453
|
-
},
|
|
454
|
-
];
|
|
455
|
-
|
|
456
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockCodegenSummary);
|
|
457
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockGenerateImageCall);
|
|
458
|
-
dalleService.generateImage.mockRejectedValue(new Error('Image generation failed'));
|
|
459
|
-
|
|
460
|
-
const result = await promptService(vertexAi.generateContent, dalleService.generateImage);
|
|
461
|
-
|
|
462
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(2);
|
|
463
|
-
expect(dalleService.generateImage).toHaveBeenCalledWith(
|
|
464
|
-
'A test image',
|
|
465
|
-
undefined,
|
|
466
|
-
{ width: 256, height: 256 },
|
|
467
|
-
false,
|
|
468
|
-
);
|
|
469
|
-
expect(result).toEqual(
|
|
470
|
-
expect.arrayContaining([
|
|
471
|
-
expect.objectContaining({
|
|
472
|
-
name: 'explanation',
|
|
473
|
-
args: {
|
|
474
|
-
text: expect.stringContaining('Failed to generate image: Image generation failed'),
|
|
475
|
-
},
|
|
476
|
-
}),
|
|
477
|
-
]),
|
|
478
|
-
);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
it('should handle unexpected response without codegen summary', async () => {
|
|
482
|
-
cliParams.vertexAi = true;
|
|
483
|
-
const mockUnexpectedResponse = [
|
|
484
|
-
{
|
|
485
|
-
name: 'updateFile',
|
|
486
|
-
args: {
|
|
487
|
-
filePath: 'test.js',
|
|
488
|
-
newContent: 'console.log("Unexpected response");',
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
|
-
];
|
|
492
|
-
|
|
493
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockUnexpectedResponse);
|
|
494
|
-
|
|
495
|
-
const result = await promptService(vertexAi.generateContent);
|
|
496
|
-
|
|
497
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(1);
|
|
498
|
-
expect(result).toEqual(mockUnexpectedResponse);
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
describe('validateAndRecoverSingleResult', () => {
|
|
502
|
-
it('should successfully recover from an invalid function call', async () => {
|
|
503
|
-
cliParams.vertexAi = true;
|
|
504
|
-
const mockInvalidCall = [
|
|
505
|
-
{
|
|
506
|
-
name: 'codegenSummary',
|
|
507
|
-
args: {
|
|
508
|
-
files: [{ path: 'test.js', updateToolName: 'patchFile' }],
|
|
509
|
-
contextPaths: [],
|
|
510
|
-
explanation: 'Mock summary',
|
|
511
|
-
},
|
|
512
|
-
},
|
|
513
|
-
];
|
|
514
|
-
const mockValidCall = [
|
|
515
|
-
{
|
|
516
|
-
name: 'codegenSummary',
|
|
517
|
-
args: {
|
|
518
|
-
fileUpdates: [{ path: 'test.js', updateToolName: 'patchFile' }],
|
|
519
|
-
contextPaths: [],
|
|
520
|
-
explanation: 'Mock summary',
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
|
-
];
|
|
524
|
-
|
|
525
|
-
vertexAi.generateContent
|
|
526
|
-
.mockResolvedValueOnce(mockInvalidCall)
|
|
527
|
-
.mockResolvedValueOnce(mockValidCall)
|
|
528
|
-
.mockResolvedValueOnce([
|
|
529
|
-
{
|
|
530
|
-
name: 'updateFile',
|
|
531
|
-
args: {
|
|
532
|
-
filePath: 'test.js',
|
|
533
|
-
newContent: 'console.log("Unexpected response");',
|
|
534
|
-
},
|
|
535
|
-
},
|
|
536
|
-
]);
|
|
537
|
-
|
|
538
|
-
const result = await promptService(vertexAi.generateContent);
|
|
539
|
-
|
|
540
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(3);
|
|
541
|
-
expect(result).toEqual([
|
|
542
|
-
{
|
|
543
|
-
args: {
|
|
544
|
-
filePath: 'test.js',
|
|
545
|
-
newContent: 'console.log("Unexpected response");',
|
|
546
|
-
},
|
|
547
|
-
name: 'updateFile',
|
|
548
|
-
},
|
|
549
|
-
]);
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
it('should handle unsuccessful recovery', async () => {
|
|
553
|
-
cliParams.vertexAi = true;
|
|
554
|
-
const mockInvalidCall = [
|
|
555
|
-
{
|
|
556
|
-
name: 'updateFile',
|
|
557
|
-
args: { filePath: 'test.js', invalidArg: 'This should not be here' },
|
|
558
|
-
},
|
|
559
|
-
];
|
|
560
|
-
|
|
561
|
-
vertexAi.generateContent
|
|
562
|
-
.mockResolvedValueOnce([
|
|
563
|
-
{
|
|
564
|
-
name: 'codegenSummary',
|
|
565
|
-
args: {
|
|
566
|
-
fileUpdates: [{ path: 'test.js', updateToolName: 'patchFile' }],
|
|
567
|
-
contextPaths: [],
|
|
568
|
-
explanation: 'Mock summary',
|
|
569
|
-
},
|
|
570
|
-
},
|
|
571
|
-
])
|
|
572
|
-
.mockResolvedValueOnce(mockInvalidCall)
|
|
573
|
-
.mockResolvedValueOnce(mockInvalidCall); // Second call also returns invalid result
|
|
574
|
-
|
|
575
|
-
await expect(promptService(vertexAi.generateContent)).rejects.toThrow('Recovery failed');
|
|
576
|
-
|
|
577
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(3);
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
it('should not attempt recovery for multiple valid function calls', async () => {
|
|
581
|
-
cliParams.vertexAi = true;
|
|
582
|
-
const mockValidCalls = [
|
|
583
|
-
{
|
|
584
|
-
name: 'updateFile',
|
|
585
|
-
args: { filePath: 'test1.js', newContent: 'console.log("File 1");' },
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
name: 'updateFile',
|
|
589
|
-
args: { filePath: 'test2.js', newContent: 'console.log("File 2");' },
|
|
590
|
-
},
|
|
591
|
-
];
|
|
592
|
-
|
|
593
|
-
vertexAi.generateContent.mockResolvedValueOnce(mockValidCalls);
|
|
594
|
-
|
|
595
|
-
const result = await promptService(vertexAi.generateContent);
|
|
596
|
-
|
|
597
|
-
expect(vertexAi.generateContent).toHaveBeenCalledTimes(1);
|
|
598
|
-
expect(result).toEqual(mockValidCalls);
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { CODEGEN_TRIGGER } from './prompt-consts.js';
|
|
2
|
-
import { verbosePrompt } from '../cli/cli-params.js';
|
|
3
|
-
import { verifySystemPromptLimit } from './limits.js';
|
|
4
|
-
import { rcConfig } from '../main/config.js';
|
|
5
|
-
|
|
6
|
-
/** Generates a system prompt */
|
|
7
|
-
export function getSystemPrompt() {
|
|
8
|
-
console.log('Generate system prompt');
|
|
9
|
-
|
|
10
|
-
let systemPrompt = `
|
|
11
|
-
You are a code generation assistant. I want you to help me generate code for my ideas in my application source code.
|
|
12
|
-
|
|
13
|
-
You can generate new code, or modify the existing one. You will receive instructions on what is the goal of requested code modification.
|
|
14
|
-
|
|
15
|
-
Instructions will be passed to you either directly via message, with a file, or using the ${CODEGEN_TRIGGER} comment in the code.
|
|
16
|
-
|
|
17
|
-
You should parse my application source code and then suggest changes using appropriate tools.
|
|
18
|
-
|
|
19
|
-
The root directory of my application is \`${rcConfig.rootDir}\` and you should limit the changes only to this path.
|
|
20
|
-
|
|
21
|
-
When suggesting changes always use absolute file paths.
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
if (verbosePrompt) {
|
|
25
|
-
console.log('System prompt:');
|
|
26
|
-
console.log(systemPrompt);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
verifySystemPromptLimit(systemPrompt);
|
|
30
|
-
|
|
31
|
-
return systemPrompt;
|
|
32
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { getSystemPrompt } from './systemprompt.js';
|
|
3
|
-
import * as cliParams from '../cli/cli-params.js';
|
|
4
|
-
import '../files/find-files.js';
|
|
5
|
-
import '../main/config.js';
|
|
6
|
-
|
|
7
|
-
vi.mock('../cli/cli-params.js', () => ({
|
|
8
|
-
requireExplanations: false,
|
|
9
|
-
considerAllFiles: false,
|
|
10
|
-
dependencyTree: false,
|
|
11
|
-
explicitPrompt: false,
|
|
12
|
-
allowFileCreate: false,
|
|
13
|
-
allowFileDelete: false,
|
|
14
|
-
allowDirectoryCreate: false,
|
|
15
|
-
allowFileMove: false,
|
|
16
|
-
verbosePrompt: false,
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
vi.mock('../files/find-files.js', () => ({
|
|
20
|
-
getSourceFiles: vi.fn(),
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
vi.mock('../main/config.js', () => ({
|
|
24
|
-
rcConfig: { rootDir: '/mocked/root/dir' },
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
describe('getSystemPrompt', () => {
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
vi.clearAllMocks();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('generates correct system prompt', () => {
|
|
33
|
-
const systemPrompt = getSystemPrompt();
|
|
34
|
-
|
|
35
|
-
expect(systemPrompt).toContain(
|
|
36
|
-
'You are a code generation assistant. I want you to help me generate code for my ideas in my application source code.',
|
|
37
|
-
);
|
|
38
|
-
expect(systemPrompt).toContain('You can generate new code, or modify the existing one.');
|
|
39
|
-
expect(systemPrompt).toContain(
|
|
40
|
-
'Instructions will be passed to you either directly via message, with a file, or using the ' +
|
|
41
|
-
'@' +
|
|
42
|
-
'CODEGEN comment in the code.',
|
|
43
|
-
);
|
|
44
|
-
expect(systemPrompt).toContain(
|
|
45
|
-
'The root directory of my application is `/mocked/root/dir` and you should limit the changes only to this path.',
|
|
46
|
-
);
|
|
47
|
-
expect(systemPrompt).toContain('When suggesting changes always use absolute file paths.');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('verifies system prompt limit', () => {
|
|
51
|
-
vi.spyOn(cliParams, 'verbosePrompt', 'get').mockReturnValue(true);
|
|
52
|
-
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
53
|
-
|
|
54
|
-
getSystemPrompt();
|
|
55
|
-
|
|
56
|
-
expect(consoleSpy).toHaveBeenCalledWith('System prompt:');
|
|
57
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
58
|
-
expect.stringContaining('You are a code generation assistant. I want you to help me generate code for my ideas'),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
consoleSpy.mockRestore();
|
|
62
|
-
});
|
|
63
|
-
});
|