mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-15 16:14:26 +00:00
feat(cli): add --append-system-prompt-file support
This commit is contained in:
1 parent
efecd7c7d9
commit
45c231a717
8 files changed
+382
-34
No files matched your search
@@ -36,4 +36,34 @@ describe('appendThirdPartyImageAnalysisToolArgs', () => {
|
||||
'extra',
|
||||
]);
|
||||
});
|
||||
|
||||
// File mode: --append-system-prompt-file when user passes --append-system-prompt-file
|
||||
|
||||
it('uses --append-system-prompt-file when user passes --append-system-prompt-file', () => {
|
||||
const result = appendThirdPartyImageAnalysisToolArgs([
|
||||
'-p',
|
||||
'describe',
|
||||
'--append-system-prompt-file',
|
||||
'/tmp/user-prompt.txt',
|
||||
]);
|
||||
|
||||
expect(result).toContain('--append-system-prompt-file');
|
||||
expect(result).not.toContain('--append-system-prompt');
|
||||
const fileFlags = result.filter((arg) => arg === '--append-system-prompt-file');
|
||||
expect(fileFlags.length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
it('uses --append-system-prompt-file when user passes equals form', () => {
|
||||
const result = appendThirdPartyImageAnalysisToolArgs([
|
||||
'-p',
|
||||
'describe',
|
||||
'--append-system-prompt-file=/tmp/user-prompt.txt',
|
||||
]);
|
||||
|
||||
expect(result).not.toContain('--append-system-prompt');
|
||||
const fileFlags = result.filter(
|
||||
(arg) => arg === '--append-system-prompt-file' || arg.startsWith('--append-system-prompt-file=')
|
||||
);
|
||||
expect(fileFlags.length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import {
|
||||
detectPromptInjectionMode,
|
||||
buildInlineSteeringArg,
|
||||
buildFileSteeringArg,
|
||||
buildSteeringArg,
|
||||
PROMPT_FLAG_INLINE,
|
||||
PROMPT_FLAG_FILE,
|
||||
} from '../../../src/utils/prompt-injection-strategy';
|
||||
|
||||
describe('detectPromptInjectionMode', () => {
|
||||
it('returns inline when no prompt flags present', () => {
|
||||
expect(detectPromptInjectionMode(['-p', 'hello'])).toBe('inline');
|
||||
});
|
||||
|
||||
it('returns inline when only --append-system-prompt is present', () => {
|
||||
expect(detectPromptInjectionMode(['--append-system-prompt', 'test'])).toBe('inline');
|
||||
});
|
||||
|
||||
it('returns inline when --append-system-prompt equals form is present', () => {
|
||||
expect(detectPromptInjectionMode(['--append-system-prompt=test'])).toBe('inline');
|
||||
});
|
||||
|
||||
it('returns file when --append-system-prompt-file is present', () => {
|
||||
expect(detectPromptInjectionMode(['--append-system-prompt-file', '/tmp/p.txt'])).toBe('file');
|
||||
});
|
||||
|
||||
it('returns file when --append-system-prompt-file equals form is present', () => {
|
||||
expect(detectPromptInjectionMode(['--append-system-prompt-file=/tmp/p.txt'])).toBe('file');
|
||||
});
|
||||
|
||||
it('returns file even when --append-system-prompt is also present', () => {
|
||||
expect(
|
||||
detectPromptInjectionMode([
|
||||
'--append-system-prompt',
|
||||
'inline-text',
|
||||
'--append-system-prompt-file',
|
||||
'/tmp/p.txt',
|
||||
])
|
||||
).toBe('file');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildInlineSteeringArg', () => {
|
||||
it('returns inline flag and prompt text', () => {
|
||||
expect(buildInlineSteeringArg({promptContent: 'hello world'})).toEqual(['--append-system-prompt', 'hello world']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildFileSteeringArg', () => {
|
||||
it('returns file flag and writes temp file', () => {
|
||||
const result = buildFileSteeringArg({promptFileName: 'ccs-test-prompt.txt', promptContent: 'hello world' });
|
||||
expect(result[0]).toBe('--append-system-prompt-file');
|
||||
expect(result[1]).toContain('ccs-test-prompt.txt');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildSteeringArg', () => {
|
||||
it('delegates to inline in inline mode', () => {
|
||||
expect(buildSteeringArg({
|
||||
args: [PROMPT_FLAG_INLINE],
|
||||
promptName: 'ignored.txt',
|
||||
promptContent: 'hello',
|
||||
})).toEqual([
|
||||
'--append-system-prompt',
|
||||
'hello',
|
||||
]);
|
||||
});
|
||||
|
||||
it('delegates to file in file mode', () => {
|
||||
const result = buildSteeringArg({
|
||||
args: [PROMPT_FLAG_FILE],
|
||||
promptName: 'ccs-test',
|
||||
promptContent: 'hello',
|
||||
});
|
||||
expect(result[0]).toBe('--append-system-prompt-file');
|
||||
expect(result[1]).toContain('ccs-test.txt');
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@ const STEERING_PROMPT =
|
||||
'For web lookup or current-information requests, prefer the CCS MCP tool WebSearch instead of Bash/curl/http fetches. If the user explicitly wants shell commands, or WebSearch is unavailable or fails, you may fall back to Bash/network tools.';
|
||||
|
||||
describe('appendThirdPartyWebSearchToolArgs', () => {
|
||||
it('appends native WebSearch suppression and steering prompt when no tool flags are present', () => {
|
||||
it('appends native WebSearch suppression and inline steering prompt when no prompt flags are present', () => {
|
||||
expect(appendThirdPartyWebSearchToolArgs(['smoke'])).toEqual([
|
||||
'smoke',
|
||||
'--disallowedTools',
|
||||
@@ -129,4 +129,32 @@ describe('appendThirdPartyWebSearchToolArgs', () => {
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
// File mode: --append-system-prompt-file when user passes --append-system-prompt-file
|
||||
|
||||
it('uses --append-system-prompt-file when user passes --append-system-prompt-file', () => {
|
||||
const result = appendThirdPartyWebSearchToolArgs([
|
||||
'smoke',
|
||||
'--append-system-prompt-file',
|
||||
'/tmp/user-prompt.txt',
|
||||
]);
|
||||
expect(result).toContain('--disallowedTools');
|
||||
expect(result).toContain('WebSearch');
|
||||
const fileFlags = result.filter((arg) => arg === '--append-system-prompt-file');
|
||||
expect(fileFlags.length).toBeGreaterThanOrEqual(2);
|
||||
// No inline flag should be present
|
||||
expect(result).not.toContain('--append-system-prompt');
|
||||
});
|
||||
|
||||
it('uses --append-system-prompt-file when user passes --append-system-prompt-file= form', () => {
|
||||
const result = appendThirdPartyWebSearchToolArgs([
|
||||
'smoke',
|
||||
'--append-system-prompt-file=/tmp/user-prompt.txt',
|
||||
]);
|
||||
const fileFlags = result.filter(
|
||||
(arg) => arg === '--append-system-prompt-file' || arg.startsWith('--append-system-prompt-file=')
|
||||
);
|
||||
expect(fileFlags.length).toBeGreaterThanOrEqual(2);
|
||||
expect(result).not.toContain('--append-system-prompt');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user