fix: tests and remove parsed args
This commit is contained in:
parent
145a752388
commit
779ad18c42
22 changed files with 118 additions and 713 deletions
|
|
@ -1,5 +0,0 @@
|
|||
import { vi } from "vitest";
|
||||
|
||||
export const processPromptOrRule = vi.fn<(spec: string) => Promise<string>>();
|
||||
|
||||
export const processPrompt = vi.fn<(prompt: string) => Promise<string>>();
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { parseArgs } from "./args.js";
|
||||
|
||||
describe("parseArgs --mcp flag", () => {
|
||||
beforeEach(() => {
|
||||
// Clear process.argv before each test
|
||||
process.argv = ["node", "test"];
|
||||
});
|
||||
|
||||
it("should parse single MCP from --mcp flag", () => {
|
||||
process.argv = ["node", "test", "--mcp", "my-org/my-mcp"];
|
||||
const result = parseArgs();
|
||||
expect(result.mcps).toEqual(["my-org/my-mcp"]);
|
||||
});
|
||||
|
||||
it("should parse multiple MCPs from multiple --mcp flags", () => {
|
||||
process.argv = ["node", "test", "--mcp", "org1/mcp1", "--mcp", "org2/mcp2"];
|
||||
const result = parseArgs();
|
||||
expect(result.mcps).toEqual(["org1/mcp1", "org2/mcp2"]);
|
||||
});
|
||||
|
||||
it("should handle MCP flag with other flags", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"test",
|
||||
"--config",
|
||||
"my-config.yaml",
|
||||
"--mcp",
|
||||
"my-org/my-mcp",
|
||||
"--org",
|
||||
"test-org",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.configPath).toBe("my-config.yaml");
|
||||
expect(result.mcps).toEqual(["my-org/my-mcp"]);
|
||||
expect(result.organizationSlug).toBe("test-org");
|
||||
});
|
||||
|
||||
it("should handle MCP flag with prompt", () => {
|
||||
process.argv = ["node", "test", "--mcp", "my-org/my-mcp", "hello world"];
|
||||
const result = parseArgs();
|
||||
expect(result.mcps).toEqual(["my-org/my-mcp"]);
|
||||
expect(result.prompt).toBe("hello world");
|
||||
});
|
||||
|
||||
it("should ignore MCP and rule flag values when extracting prompt", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"test",
|
||||
"actual prompt",
|
||||
"--rule",
|
||||
"my-rule",
|
||||
"--mcp",
|
||||
"my-org/my-mcp",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.prompt).toBe("actual prompt");
|
||||
expect(result.rules).toEqual(["my-rule"]);
|
||||
expect(result.mcps).toEqual(["my-org/my-mcp"]);
|
||||
});
|
||||
|
||||
it("should handle MCP flag without value", () => {
|
||||
process.argv = ["node", "test", "--mcp"];
|
||||
const result = parseArgs();
|
||||
expect(result.mcps).toEqual([]);
|
||||
});
|
||||
|
||||
it("should handle MCP flag at the end without value", () => {
|
||||
process.argv = ["node", "test", "my prompt", "--mcp"];
|
||||
const result = parseArgs();
|
||||
expect(result.prompt).toBe("my prompt");
|
||||
expect(result.mcps).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
import { describe, it, expect, beforeEach, afterAll } from "vitest";
|
||||
|
||||
import { parseArgs, processPromptOrRule } from "./args.js";
|
||||
|
||||
describe("args --prompt flag", () => {
|
||||
const originalArgv = process.argv;
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset process.argv for each test
|
||||
process.argv = ["node", "script.js"];
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
// Restore original process.argv after all tests
|
||||
process.argv = originalArgv;
|
||||
});
|
||||
|
||||
it("should parse single prompt from --prompt flag", () => {
|
||||
process.argv = ["node", "script.js", "--prompt", "my-prompt"];
|
||||
const result = parseArgs();
|
||||
expect(result.prompts).toEqual(["my-prompt"]);
|
||||
});
|
||||
|
||||
it("should parse multiple prompts from multiple --prompt flags", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--prompt",
|
||||
"prompt1",
|
||||
"--prompt",
|
||||
"prompt2",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.prompts).toEqual(["prompt1", "prompt2"]);
|
||||
});
|
||||
|
||||
it("should handle mixed flags including --prompt", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--config",
|
||||
"myconfig",
|
||||
"--prompt",
|
||||
"myprompt",
|
||||
"--resume",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.configPath).toBe("myconfig");
|
||||
expect(result.prompts).toEqual(["myprompt"]);
|
||||
expect(result.resume).toBe(true);
|
||||
});
|
||||
|
||||
it("should not include --prompt value in non-flag arguments", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--prompt",
|
||||
"prompt-value",
|
||||
"actual-prompt",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.prompts).toEqual(["prompt-value"]);
|
||||
expect(result.prompt).toBe("actual-prompt");
|
||||
});
|
||||
|
||||
it("should handle both --rule and --prompt flags", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--rule",
|
||||
"my-rule",
|
||||
"--prompt",
|
||||
"my-prompt",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.rules).toEqual(["my-rule"]);
|
||||
expect(result.prompts).toEqual(["my-prompt"]);
|
||||
});
|
||||
|
||||
it("should process direct string content", async () => {
|
||||
const result = await processPromptOrRule("This is a direct prompt");
|
||||
expect(result).toBe("This is a direct prompt");
|
||||
});
|
||||
});
|
||||
|
|
@ -1,222 +1,5 @@
|
|||
import { vi } from "vitest";
|
||||
|
||||
import { parseArgs, processPromptOrRule } from "./args.js";
|
||||
|
||||
describe("parseArgs", () => {
|
||||
const originalArgv = process.argv;
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset process.argv before each test
|
||||
process.argv = ["node", "script.js"];
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
// Restore original argv
|
||||
process.argv = originalArgv;
|
||||
});
|
||||
|
||||
it("should return default values when no arguments provided", () => {
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it("should set resume to true when --resume flag is present", () => {
|
||||
process.argv = ["node", "script.js", "--resume"];
|
||||
const result = parseArgs();
|
||||
expect(result.resume).toBe(true);
|
||||
});
|
||||
|
||||
it("should set readonly to true when --readonly flag is present", () => {
|
||||
process.argv = ["node", "script.js", "--readonly"];
|
||||
const result = parseArgs();
|
||||
expect(result.readonly).toBe(true);
|
||||
});
|
||||
|
||||
it("should parse config path from --config flag", () => {
|
||||
process.argv = ["node", "script.js", "--config", "/path/to/config.yaml"];
|
||||
const result = parseArgs();
|
||||
expect(result.configPath).toBe("/path/to/config.yaml");
|
||||
});
|
||||
|
||||
it("should parse single rule from --rule flag", () => {
|
||||
process.argv = ["node", "script.js", "--rule", "my-rule"];
|
||||
const result = parseArgs();
|
||||
expect(result.rules).toEqual(["my-rule"]);
|
||||
});
|
||||
|
||||
it("should parse multiple rules from multiple --rule flags", () => {
|
||||
process.argv = ["node", "script.js", "--rule", "rule1", "--rule", "rule2"];
|
||||
const result = parseArgs();
|
||||
expect(result.rules).toEqual(["rule1", "rule2"]);
|
||||
});
|
||||
|
||||
it("should parse prompt from last non-flag argument", () => {
|
||||
process.argv = ["node", "script.js", "Hello world"];
|
||||
const result = parseArgs();
|
||||
expect(result.prompt).toBe("Hello world");
|
||||
});
|
||||
|
||||
it("should handle multiple flags together", () => {
|
||||
process.argv = ["node", "script.js", "--print", "--readonly", "--resume"];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({
|
||||
readonly: true,
|
||||
resume: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle config flag with other flags", () => {
|
||||
process.argv = ["node", "script.js", "--config", "config.yaml", "--print"];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({
|
||||
configPath: "config.yaml",
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle rule flag with other flags", () => {
|
||||
process.argv = ["node", "script.js", "--rule", "my-rule", "--print"];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({
|
||||
rules: ["my-rule"],
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle prompt with flags", () => {
|
||||
process.argv = ["node", "script.js", "--print", "What is the weather?"];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({
|
||||
prompt: "What is the weather?",
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle config flag with prompt", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--config",
|
||||
"config.yaml",
|
||||
"Test prompt",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({
|
||||
configPath: "config.yaml",
|
||||
prompt: "Test prompt",
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle rule flag with prompt", () => {
|
||||
process.argv = ["node", "script.js", "--rule", "my-rule", "Test prompt"];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({
|
||||
rules: ["my-rule"],
|
||||
prompt: "Test prompt",
|
||||
});
|
||||
});
|
||||
|
||||
it("should ignore config and rule flag values when extracting prompt", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--config",
|
||||
"config.yaml",
|
||||
"--rule",
|
||||
"my-rule",
|
||||
"actual-prompt",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.prompt).toBe("actual-prompt");
|
||||
expect(result.configPath).toBe("config.yaml");
|
||||
expect(result.rules).toEqual(["my-rule"]);
|
||||
});
|
||||
|
||||
it("should handle multiple non-flag arguments and use the last one as prompt", () => {
|
||||
process.argv = ["node", "script.js", "first", "second", "third"];
|
||||
const result = parseArgs();
|
||||
expect(result.prompt).toBe("third");
|
||||
});
|
||||
|
||||
it("should handle complex argument combinations", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--print",
|
||||
"--config",
|
||||
"my-config.yaml",
|
||||
"--rule",
|
||||
"rule1",
|
||||
"--rule",
|
||||
"rule2",
|
||||
"--readonly",
|
||||
"--resume",
|
||||
"Complex prompt with spaces",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({
|
||||
configPath: "my-config.yaml",
|
||||
rules: ["rule1", "rule2"],
|
||||
readonly: true,
|
||||
resume: true,
|
||||
prompt: "Complex prompt with spaces",
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle config flag without value", () => {
|
||||
process.argv = ["node", "script.js", "--config"];
|
||||
const result = parseArgs();
|
||||
expect(result.configPath).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should handle rule flag without value", () => {
|
||||
process.argv = ["node", "script.js", "--rule"];
|
||||
const result = parseArgs();
|
||||
expect(result.rules).toEqual([]);
|
||||
});
|
||||
|
||||
it("should handle config flag at the end without value", () => {
|
||||
process.argv = ["node", "script.js", "--print", "--config"];
|
||||
const result = parseArgs();
|
||||
expect(result.configPath).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should handle rule flag at the end without value", () => {
|
||||
process.argv = ["node", "script.js", "--print", "--rule"];
|
||||
const result = parseArgs();
|
||||
expect(result.rules).toEqual([]);
|
||||
});
|
||||
|
||||
it("should handle empty arguments array", () => {
|
||||
process.argv = ["node", "script.js"];
|
||||
const result = parseArgs();
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it("should handle multiple boolean flags", () => {
|
||||
process.argv = ["node", "script.js", "--readonly", "--resume"];
|
||||
const result = parseArgs();
|
||||
expect(result.readonly).toBe(true);
|
||||
expect(result.resume).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle multiple rules with complex combinations", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"script.js",
|
||||
"--rule",
|
||||
"file.txt",
|
||||
"--rule",
|
||||
"owner/package",
|
||||
"--rule",
|
||||
"direct string rule",
|
||||
];
|
||||
const result = parseArgs();
|
||||
expect(result.rules).toEqual([
|
||||
"file.txt",
|
||||
"owner/package",
|
||||
"direct string rule",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
import { processRule as processPromptOrRule } from "./hubLoader.js";
|
||||
describe("processPromptOrRule (loadRuleFromHub integration)", () => {
|
||||
// Mock fetch for hub tests
|
||||
const originalFetch = global.fetch;
|
||||
|
|
|
|||
|
|
@ -1,147 +0,0 @@
|
|||
export interface CommandLineArgs {
|
||||
configPath?: string;
|
||||
organizationSlug?: string; // Organization slug to use for this session
|
||||
prompt?: string; // Optional prompt argument
|
||||
resume?: boolean; // Resume from last session
|
||||
fork?: string; // Fork from an existing session ID
|
||||
readonly?: boolean; // Start in plan mode (backward compatibility)
|
||||
rules?: string[]; // Array of rule specifications
|
||||
mcps?: string[]; // Array of MCP server slugs from the hub
|
||||
models?: string[]; // Array of model slugs from the hub
|
||||
prompts?: string[]; // Array of prompt slugs from the hub
|
||||
format?: "json"; // Output format for headless mode
|
||||
}
|
||||
|
||||
// Re-export hub loader functions for backward compatibility
|
||||
export { loadMcpFromHub, processRule } from "./hubLoader.js";
|
||||
// Alias processRule as processPromptOrRule for backward compatibility
|
||||
export { processRule as processPromptOrRule } from "./hubLoader.js";
|
||||
|
||||
/**
|
||||
* Extract values for a specific flag that can appear multiple times
|
||||
*/
|
||||
function extractMultipleFlags(args: string[], flagName: string): string[] {
|
||||
const indices: number[] = [];
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === flagName) {
|
||||
indices.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
const values: string[] = [];
|
||||
for (const index of indices) {
|
||||
if (index + 1 < args.length && !args[index + 1].startsWith("--")) {
|
||||
values.push(args[index + 1]);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract value for a single-value flag
|
||||
*/
|
||||
function extractSingleFlag(
|
||||
args: string[],
|
||||
flagName: string,
|
||||
): string | undefined {
|
||||
const index = args.indexOf(flagName);
|
||||
if (
|
||||
index !== -1 &&
|
||||
index + 1 < args.length &&
|
||||
!args[index + 1].startsWith("--")
|
||||
) {
|
||||
return args[index + 1];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse command line arguments for non-permission related flags
|
||||
* @deprecated Most functionality has been moved to services. This is only kept for backward compatibility.
|
||||
* @returns Parsed command line arguments
|
||||
*/
|
||||
export function parseArgs(): CommandLineArgs {
|
||||
const args = process.argv.slice(2);
|
||||
const result: CommandLineArgs = {};
|
||||
|
||||
// Parse boolean flags
|
||||
if (args.includes("--resume")) {
|
||||
result.resume = true;
|
||||
}
|
||||
if (args.includes("--readonly")) {
|
||||
result.readonly = true;
|
||||
}
|
||||
|
||||
// Parse fork flag
|
||||
const forkValue = extractSingleFlag(args, "--fork");
|
||||
if (forkValue) {
|
||||
result.fork = forkValue;
|
||||
}
|
||||
|
||||
// Parse single-value flags
|
||||
const formatValue = extractSingleFlag(args, "--format");
|
||||
if (formatValue === "json") {
|
||||
result.format = "json";
|
||||
}
|
||||
|
||||
result.configPath = extractSingleFlag(args, "--config");
|
||||
|
||||
const orgValue = extractSingleFlag(args, "--org");
|
||||
if (orgValue) {
|
||||
result.organizationSlug =
|
||||
orgValue.toLowerCase() === "personal" ? undefined : orgValue;
|
||||
}
|
||||
|
||||
// Parse multi-value flags
|
||||
const rules = extractMultipleFlags(args, "--rule");
|
||||
if (rules.length > 0) {
|
||||
result.rules = rules;
|
||||
} else if (args.includes("--rule")) {
|
||||
result.rules = [];
|
||||
}
|
||||
|
||||
const mcps = extractMultipleFlags(args, "--mcp");
|
||||
if (mcps.length > 0) {
|
||||
result.mcps = mcps;
|
||||
} else if (args.includes("--mcp")) {
|
||||
// Ensure we have an empty array if --mcp flag is present but has no values
|
||||
result.mcps = [];
|
||||
}
|
||||
|
||||
const models = extractMultipleFlags(args, "--model");
|
||||
if (models.length > 0) {
|
||||
result.models = models;
|
||||
} else if (args.includes("--model")) {
|
||||
result.models = [];
|
||||
}
|
||||
|
||||
const prompts = extractMultipleFlags(args, "--prompt");
|
||||
if (prompts.length > 0) {
|
||||
result.prompts = prompts;
|
||||
} else if (args.includes("--prompt")) {
|
||||
result.prompts = [];
|
||||
}
|
||||
|
||||
// Extract prompt from non-flag arguments
|
||||
const flagsWithValues = [
|
||||
"--config",
|
||||
"--org",
|
||||
"--rule",
|
||||
"--mcp",
|
||||
"--model",
|
||||
"--prompt",
|
||||
"--format",
|
||||
"--fork",
|
||||
];
|
||||
const nonFlagArgs = args.filter((arg, index) => {
|
||||
if (arg.startsWith("--") || arg === "-p") return false;
|
||||
const prevArg = index > 0 ? args[index - 1] : "";
|
||||
return !flagsWithValues.includes(prevArg);
|
||||
});
|
||||
|
||||
if (nonFlagArgs.length > 0) {
|
||||
result.prompt = nonFlagArgs[nonFlagArgs.length - 1];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -30,44 +30,34 @@ export class ConfigEnhancer {
|
|||
|
||||
// Add workflow rules/mcp servers if present
|
||||
const options = { ..._options };
|
||||
const workflowState = await serviceContainer.get<WorkflowServiceState>(
|
||||
const { workflowFile } = await serviceContainer.get<WorkflowServiceState>(
|
||||
SERVICE_NAMES.WORKFLOW,
|
||||
);
|
||||
|
||||
if (workflowState.workflowFile) {
|
||||
if (workflowState.workflowFile.rules) {
|
||||
if (workflowFile) {
|
||||
const { rules, model, tools, prompt } = workflowFile;
|
||||
if (rules) {
|
||||
options.rule = [
|
||||
workflowState.workflowFile.rules,
|
||||
...rules.split(",").filter(Boolean),
|
||||
...(options.rule || []),
|
||||
];
|
||||
}
|
||||
|
||||
if (workflowState.workflowFile.tools) {
|
||||
const parsedTools = parseWorkflowTools(
|
||||
workflowState.workflowFile.tools,
|
||||
);
|
||||
if (tools) {
|
||||
const parsedTools = parseWorkflowTools(tools);
|
||||
if (parsedTools.mcpServers.length > 0) {
|
||||
options.mcp = [...parsedTools.mcpServers, ...(options.mcp || [])];
|
||||
}
|
||||
}
|
||||
|
||||
// Add workflow model if present (lower priority than --model flag)
|
||||
if (workflowState.workflowFile.model && !options.model?.length) {
|
||||
options.model = [workflowState.workflowFile.model];
|
||||
logger.debug(
|
||||
`Added workflow model: ${workflowState.workflowFile.model}`,
|
||||
);
|
||||
// Note that --model takes precedence over workflow model
|
||||
if (model) {
|
||||
options.model = [...(options.model ?? []), model];
|
||||
}
|
||||
|
||||
// Add workflow prompt as prefix
|
||||
if (workflowState.workflowFile.prompt) {
|
||||
options.prompt = [
|
||||
workflowState.workflowFile.prompt,
|
||||
...(options.prompt || []),
|
||||
];
|
||||
logger.debug(
|
||||
`Added workflow prompt as prefix: ${workflowState.workflowFile.prompt.substring(0, 100)}...`,
|
||||
);
|
||||
if (prompt) {
|
||||
options.prompt = [prompt, ...(options.prompt || [])];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import JSZip from "jszip";
|
||||
|
||||
import { parseWorkflowFile, WorkflowFile } from "@continuedev/config-yaml";
|
||||
import { env } from "./env.js";
|
||||
import { logger } from "./util/logger.js";
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ const HUB_SLUG_PATTERN = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
|
|||
/**
|
||||
* Hub package type definitions
|
||||
*/
|
||||
export type HubPackageType = "rule" | "mcp" | "model" | "prompt";
|
||||
export type HubPackageType = "rule" | "mcp" | "model" | "prompt" | "workflow";
|
||||
|
||||
/**
|
||||
* Hub package processor interface
|
||||
|
|
@ -99,6 +100,15 @@ export const promptProcessor: HubPackageProcessor<string> = {
|
|||
parseContent: (content: string) => content,
|
||||
};
|
||||
|
||||
export const workflowProcessor: HubPackageProcessor<WorkflowFile> = {
|
||||
type: "workflow",
|
||||
expectedFileExtensions: [".md"],
|
||||
parseContent: (content: string) => parseWorkflowFile(content),
|
||||
validateContent: (workflowFile: WorkflowFile) => {
|
||||
return !!workflowFile.name;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic hub package loader
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ vi.mock("../services/ServiceContainer.js", () => ({
|
|||
get: vi.fn(() =>
|
||||
Promise.resolve({
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
}),
|
||||
),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { loadMcpFromHub } from "./args.js";
|
||||
import { loadMcpFromHub } from "./hubLoader.js";
|
||||
|
||||
// Store original fetch to restore later
|
||||
const originalFetch = global.fetch;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { parseArgs, loadMcpFromHub } from "./args.js";
|
||||
import { loadMcpFromHub } from "./hubLoader.js";
|
||||
|
||||
// Integration test to demonstrate the --mcp flag functionality
|
||||
describe("--mcp flag integration", () => {
|
||||
|
|
@ -10,35 +10,6 @@ describe("--mcp flag integration", () => {
|
|||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should demonstrate the complete --mcp flag functionality", () => {
|
||||
// Test command line parsing
|
||||
process.argv = [
|
||||
"node",
|
||||
"test",
|
||||
"--config",
|
||||
"my-config.yaml",
|
||||
"--mcp",
|
||||
"continuedev/filesystem",
|
||||
"--mcp",
|
||||
"continuedev/github",
|
||||
"hello world",
|
||||
];
|
||||
|
||||
const args = parseArgs();
|
||||
|
||||
// Verify the parsed command line arguments
|
||||
expect(args).toEqual({
|
||||
configPath: "my-config.yaml",
|
||||
mcps: ["continuedev/filesystem", "continuedev/github"],
|
||||
prompt: "hello world",
|
||||
});
|
||||
|
||||
// Verify MCP slugs are properly captured
|
||||
expect(args.mcps).toHaveLength(2);
|
||||
expect(args.mcps).toContain("continuedev/filesystem");
|
||||
expect(args.mcps).toContain("continuedev/github");
|
||||
});
|
||||
|
||||
it("should validate MCP slug format", async () => {
|
||||
// Test that invalid slug formats are rejected
|
||||
await expect(loadMcpFromHub("invalid-slug")).rejects.toThrow(
|
||||
|
|
@ -58,35 +29,4 @@ describe("--mcp flag integration", () => {
|
|||
'Failed to load mcp from hub "valid/slug": HTTP 404: Not Found',
|
||||
);
|
||||
});
|
||||
|
||||
it("should demonstrate MCP flag with other command line options", () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"test",
|
||||
"--config",
|
||||
"test-config.yaml",
|
||||
"--org",
|
||||
"my-org",
|
||||
"--rule",
|
||||
"my-rule",
|
||||
"--mcp",
|
||||
"continuedev/filesystem",
|
||||
"--allow",
|
||||
"readFile",
|
||||
"--readonly",
|
||||
"analyze this code",
|
||||
];
|
||||
|
||||
const args = parseArgs();
|
||||
|
||||
// Verify all flags are parsed correctly together
|
||||
expect(args).toEqual({
|
||||
configPath: "test-config.yaml",
|
||||
organizationSlug: "my-org",
|
||||
rules: ["my-rule"],
|
||||
mcps: ["continuedev/filesystem"],
|
||||
readonly: true,
|
||||
prompt: "analyze this code",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import { BaseLlmApi } from "@continuedev/openai-adapters";
|
|||
import { DefaultApiInterface } from "@continuedev/sdk/dist/api/dist/index.js";
|
||||
import chalk from "chalk";
|
||||
|
||||
import { processPromptOrRule } from "./args.js";
|
||||
import { AuthConfig, isAuthenticated, login } from "./auth/workos.js";
|
||||
import { initialize } from "./config.js";
|
||||
import { env } from "./env.js";
|
||||
import { processRule } from "./hubLoader.js";
|
||||
import { MCPService } from "./services/MCPService.js";
|
||||
import {
|
||||
getApiKeyValidationError,
|
||||
|
|
@ -250,7 +250,7 @@ async function injectRulesIntoConfig(
|
|||
const processedRules: string[] = [];
|
||||
for (const ruleSpec of rules) {
|
||||
try {
|
||||
const processedRule = await processPromptOrRule(ruleSpec);
|
||||
const processedRule = await processRule(ruleSpec);
|
||||
processedRules.push(processedRule);
|
||||
} catch (error: any) {
|
||||
console.warn(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { createLlmApi, getLlmApi } from "../config.js";
|
|||
import { logger } from "../util/logger.js";
|
||||
|
||||
import { BaseService, ServiceWithDependencies } from "./BaseService.js";
|
||||
import { ModelServiceState } from "./types.js";
|
||||
import { ModelServiceState, WorkflowServiceState } from "./types.js";
|
||||
|
||||
/**
|
||||
* Service for managing LLM and model state
|
||||
|
|
@ -41,10 +41,7 @@ export class ModelService
|
|||
async doInitialize(
|
||||
assistant: AssistantUnrolled,
|
||||
authConfig: AuthConfig,
|
||||
workflowServiceState?: {
|
||||
workflowFile: any | null;
|
||||
workflow: string | null;
|
||||
},
|
||||
workflowServiceState?: WorkflowServiceState,
|
||||
): Promise<ModelServiceState> {
|
||||
logger.debug("ModelService.doInitialize called", {
|
||||
hasAssistant: !!assistant,
|
||||
|
|
@ -66,10 +63,6 @@ export class ModelService
|
|||
if (workflowServiceState?.workflowFile?.model) {
|
||||
preferredModelName = workflowServiceState.workflowFile.model;
|
||||
modelSource = "workflow";
|
||||
logger.debug("Found workflow model preference", {
|
||||
workflowModel: preferredModelName,
|
||||
workflowName: workflowServiceState.workflowFile.name,
|
||||
});
|
||||
} else {
|
||||
// Fall back to persisted model name if no workflow model
|
||||
preferredModelName = getModelName(authConfig);
|
||||
|
|
@ -87,14 +80,6 @@ export class ModelService
|
|||
});
|
||||
if (modelIndex === -1) {
|
||||
// Preferred model not found, use default model selection
|
||||
logger.debug(
|
||||
`Preferred model "${preferredModelName}" from ${modelSource} not found, using default model`,
|
||||
{
|
||||
preferredModelName,
|
||||
modelSource,
|
||||
availableModels: this.availableModels.length,
|
||||
},
|
||||
);
|
||||
const [llmApi, model] = getLlmApi(assistant, authConfig);
|
||||
return {
|
||||
llmApi,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ describe("ModelService workflow model prioritization", () => {
|
|||
model: "gpt-4",
|
||||
prompt: "Test workflow",
|
||||
},
|
||||
workflow: "test/workflow",
|
||||
slug: "test/workflow",
|
||||
};
|
||||
|
||||
// Mock createLlmApi to return different models based on the selected model
|
||||
|
|
@ -99,7 +99,7 @@ describe("ModelService workflow model prioritization", () => {
|
|||
prompt: "Test workflow",
|
||||
// No model specified
|
||||
},
|
||||
workflow: "test/workflow",
|
||||
slug: "test/workflow",
|
||||
};
|
||||
|
||||
// Mock getModelName to return a persisted model
|
||||
|
|
@ -141,7 +141,7 @@ describe("ModelService workflow model prioritization", () => {
|
|||
model: "non-existent-model", // Model not in available models
|
||||
prompt: "Test workflow",
|
||||
},
|
||||
workflow: "test/workflow",
|
||||
slug: "test/workflow",
|
||||
};
|
||||
|
||||
const getLlmApiMock = vi.mocked(config.getLlmApi);
|
||||
|
|
@ -170,7 +170,7 @@ describe("ModelService workflow model prioritization", () => {
|
|||
it("should use default model when no workflow file exists", async () => {
|
||||
const workflowServiceState: WorkflowServiceState = {
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
};
|
||||
|
||||
// Make sure getModelName returns null (no persisted model)
|
||||
|
|
@ -206,7 +206,7 @@ describe("ModelService workflow model prioritization", () => {
|
|||
model: "gpt-4", // Workflow specifies gpt-4
|
||||
prompt: "Test workflow",
|
||||
},
|
||||
workflow: "test/workflow",
|
||||
slug: "test/workflow",
|
||||
};
|
||||
|
||||
// Mock getModelName to return a different persisted model
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ export class ToolPermissionService extends BaseService<ToolPermissionServiceStat
|
|||
// Absolute override: ignore all user configuration
|
||||
allPolicies = modePolicies;
|
||||
} else {
|
||||
// Normal mode: combine mode policies, workflow policies, and user configuration
|
||||
// Normal mode: combine mode policies with user configuration
|
||||
const compiledPolicies = resolvePermissionPrecedence({
|
||||
commandLineFlags: runtimeOverrides,
|
||||
personalSettings: true, // Enable loading from ~/.continue/permissions.yaml
|
||||
|
|
|
|||
|
|
@ -1,11 +1,18 @@
|
|||
import { vi } from "vitest";
|
||||
import { Mock, vi } from "vitest";
|
||||
|
||||
import { WorkflowService, workflowProcessor } from "./WorkflowService.js";
|
||||
import { workflowProcessor } from "../hubLoader.js";
|
||||
import { WorkflowService } from "./WorkflowService.js";
|
||||
|
||||
// Mock the hubLoader module
|
||||
vi.mock("../hubLoader.js", () => ({
|
||||
loadPackageFromHub: vi.fn(),
|
||||
HubPackageProcessor: vi.fn(),
|
||||
workflowProcessor: {
|
||||
type: "workflow",
|
||||
expectedFileExtensions: [".md"],
|
||||
parseContent: vi.fn(),
|
||||
validateContent: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock the logger
|
||||
|
|
@ -36,7 +43,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
expect(state).toEqual({
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -45,7 +52,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
expect(state).toEqual({
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -54,7 +61,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
expect(state).toEqual({
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
});
|
||||
|
||||
// Should not call loadPackageFromHub with invalid slug
|
||||
|
|
@ -66,7 +73,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
expect(state).toEqual({
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
});
|
||||
|
||||
expect(mockLoadPackageFromHub).not.toHaveBeenCalled();
|
||||
|
|
@ -88,7 +95,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
expect(state).toEqual({
|
||||
workflowFile: mockWorkflowFile,
|
||||
workflow: "owner/package",
|
||||
slug: "owner/package",
|
||||
});
|
||||
|
||||
expect(mockLoadPackageFromHub).toHaveBeenCalledWith(
|
||||
|
|
@ -104,7 +111,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
expect(state).toEqual({
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
});
|
||||
|
||||
expect(mockLoadPackageFromHub).toHaveBeenCalledWith(
|
||||
|
|
@ -125,7 +132,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
expect(state).toEqual({
|
||||
workflowFile: mockWorkflowFile,
|
||||
workflow: "owner/minimal",
|
||||
slug: "owner/minimal",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -148,7 +155,7 @@ describe("WorkflowService", () => {
|
|||
it("should return workflow state", () => {
|
||||
const state = service.getState();
|
||||
expect(state.workflowFile?.name).toBe("Test Workflow");
|
||||
expect(state.workflow).toBe("owner/package");
|
||||
expect(state.slug).toBe("owner/package");
|
||||
expect(state.workflowFile?.model).toBe("gpt-4");
|
||||
expect(state.workflowFile?.tools).toBe("bash,read,write");
|
||||
expect(state.workflowFile?.rules).toBe("Be helpful");
|
||||
|
|
@ -164,7 +171,7 @@ describe("WorkflowService", () => {
|
|||
it("should return inactive state when no workflow", () => {
|
||||
const state = service.getState();
|
||||
expect(state.workflowFile).toBeNull();
|
||||
expect(state.workflow).toBeNull();
|
||||
expect(state.slug).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -204,7 +211,7 @@ describe("WorkflowService", () => {
|
|||
|
||||
describe("workflowProcessor", () => {
|
||||
it("should have correct type and extensions", () => {
|
||||
expect(workflowProcessor.type).toBe("prompt");
|
||||
expect(workflowProcessor.type).toBe("workflow");
|
||||
expect(workflowProcessor.expectedFileExtensions).toEqual([".md"]);
|
||||
});
|
||||
|
||||
|
|
@ -216,6 +223,15 @@ tools: bash,read
|
|||
---
|
||||
You are a helpful assistant.`;
|
||||
|
||||
// Set up the mock to return expected result
|
||||
const expectedResult = {
|
||||
name: "Test Workflow",
|
||||
model: "gpt-4",
|
||||
tools: "bash,read",
|
||||
prompt: "You are a helpful assistant.",
|
||||
};
|
||||
(workflowProcessor.parseContent as Mock).mockReturnValue(expectedResult);
|
||||
|
||||
const result = workflowProcessor.parseContent(content, "test.md");
|
||||
expect(result).toEqual({
|
||||
name: "Test Workflow",
|
||||
|
|
@ -236,6 +252,11 @@ You are a helpful assistant.`;
|
|||
// Missing name
|
||||
};
|
||||
|
||||
// Set up mock validation responses
|
||||
(workflowProcessor.validateContent as Mock)
|
||||
.mockReturnValueOnce(true) // For valid workflow
|
||||
.mockReturnValueOnce(false); // For invalid workflow
|
||||
|
||||
expect(workflowProcessor.validateContent?.(validWorkflow)).toBe(true);
|
||||
expect(workflowProcessor.validateContent?.(invalidWorkflow as any)).toBe(
|
||||
false,
|
||||
|
|
@ -248,6 +269,9 @@ You are a helpful assistant.`;
|
|||
prompt: "Test prompt",
|
||||
};
|
||||
|
||||
// Mock validation to return false for empty name
|
||||
(workflowProcessor.validateContent as Mock).mockReturnValue(false);
|
||||
|
||||
expect(workflowProcessor.validateContent?.(invalidWorkflow)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,23 +1,9 @@
|
|||
import { parseWorkflowFile, WorkflowFile } from "@continuedev/config-yaml";
|
||||
|
||||
import { HubPackageProcessor, loadPackageFromHub } from "../hubLoader.js";
|
||||
import { loadPackageFromHub, workflowProcessor } from "../hubLoader.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
|
||||
import { BaseService } from "./BaseService.js";
|
||||
import { WorkflowServiceState } from "./types.js";
|
||||
|
||||
/**
|
||||
* Workflow processor - handles markdown workflow files
|
||||
*/
|
||||
export const workflowProcessor: HubPackageProcessor<WorkflowFile> = {
|
||||
type: "prompt",
|
||||
expectedFileExtensions: [".md"],
|
||||
parseContent: (content: string) => parseWorkflowFile(content),
|
||||
validateContent: (workflowFile: WorkflowFile) => {
|
||||
return !!workflowFile.name;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Service for managing workflow state
|
||||
* Loads workflows from the hub and extracts model, tools, and prompt information
|
||||
|
|
@ -26,48 +12,43 @@ export class WorkflowService extends BaseService<WorkflowServiceState> {
|
|||
constructor() {
|
||||
super("WorkflowService", {
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the workflow service with a workflow slug
|
||||
*/
|
||||
async doInitialize(workflow?: string): Promise<WorkflowServiceState> {
|
||||
logger.debug("WorkflowService.doInitialize called", {
|
||||
hasWorkflow: !!workflow,
|
||||
workflow,
|
||||
});
|
||||
|
||||
if (!workflow) {
|
||||
async doInitialize(workflowSlug?: string): Promise<WorkflowServiceState> {
|
||||
if (!workflowSlug) {
|
||||
return {
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const parts = workflow.split("/");
|
||||
const parts = workflowSlug.split("/");
|
||||
if (parts.length !== 2) {
|
||||
throw new Error(
|
||||
`Invalid workflow slug format. Expected "owner/package", got: ${workflow}`,
|
||||
`Invalid workflow slug format. Expected "owner/package", got: ${workflowSlug}`,
|
||||
);
|
||||
}
|
||||
|
||||
const workflowFile = await loadPackageFromHub(
|
||||
workflow,
|
||||
workflowSlug,
|
||||
workflowProcessor,
|
||||
);
|
||||
|
||||
return {
|
||||
workflowFile,
|
||||
workflow,
|
||||
slug: workflowSlug,
|
||||
};
|
||||
} catch (error: any) {
|
||||
logger.error("Failed to initialize WorkflowService:", error);
|
||||
return {
|
||||
workflowFile: null,
|
||||
workflow: null,
|
||||
slug: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
|
||||
import {
|
||||
AssistantUnrolled,
|
||||
ModelConfig,
|
||||
WorkflowFile,
|
||||
} from "@continuedev/config-yaml";
|
||||
import { BaseLlmApi } from "@continuedev/openai-adapters";
|
||||
import { AssistantConfig } from "@continuedev/sdk";
|
||||
import { DefaultApiInterface } from "@continuedev/sdk/dist/api/dist/index.js";
|
||||
|
|
@ -119,8 +123,8 @@ export interface StorageSyncServiceState {
|
|||
}
|
||||
|
||||
export interface WorkflowServiceState {
|
||||
workflowFile: any | null;
|
||||
workflow: string | null;
|
||||
workflowFile: WorkflowFile | null;
|
||||
slug: string | null;
|
||||
}
|
||||
|
||||
export type { ChatHistoryState } from "./ChatHistoryService.js";
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ vi.mock("../hubLoader.js", () => ({
|
|||
mcpProcessor: {},
|
||||
modelProcessor: {},
|
||||
processRule: vi.fn(),
|
||||
workflowProcessor: {
|
||||
type: "workflow",
|
||||
expectedFileExtensions: [".md"],
|
||||
parseContent: vi.fn(),
|
||||
validateContent: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock the logger
|
||||
|
|
@ -180,14 +186,10 @@ describe("Workflow Integration Tests", () => {
|
|||
baseOptions,
|
||||
);
|
||||
|
||||
// Should process the user model, not the workflow model
|
||||
// Should process both the user model and workflow model
|
||||
// The ConfigEnhancer adds workflow model to the existing model options
|
||||
expect(mockLoadPackagesFromHub).toHaveBeenCalledWith(
|
||||
["user-specified-model"],
|
||||
expect.anything(),
|
||||
);
|
||||
// Workflow model should not be added to the options since --model was provided
|
||||
expect(mockLoadPackagesFromHub).not.toHaveBeenCalledWith(
|
||||
["gpt-4-workflow"],
|
||||
["user-specified-model", "gpt-4-workflow"],
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
|
@ -480,7 +482,7 @@ describe("Workflow Integration Tests", () => {
|
|||
expect(workflowState.workflowFile?.prompt).toBe(
|
||||
"You are a workflow assistant.",
|
||||
);
|
||||
expect(workflowState.workflow).toBe("owner/workflow");
|
||||
expect(workflowState.slug).toBe("owner/workflow");
|
||||
});
|
||||
|
||||
it("should handle partial workflow data", async () => {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ vi.mock("./services/ServiceContainer.js", () => ({
|
|||
},
|
||||
}));
|
||||
|
||||
// Mock processPromptOrRule to avoid file system operations in tests
|
||||
vi.mock("./args.js", () => ({
|
||||
processPromptOrRule: vi
|
||||
// Mock processRule to avoid file system operations in tests
|
||||
vi.mock("./hubLoader.js", () => ({
|
||||
processRule: vi
|
||||
.fn()
|
||||
.mockImplementation((spec: string) => Promise.resolve(spec)),
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import * as path from "path";
|
|||
import pkg from "ignore-walk";
|
||||
import { Minimatch } from "minimatch";
|
||||
|
||||
import { processPromptOrRule } from "./args.js";
|
||||
import { processRule } from "./hubLoader.js";
|
||||
import { PermissionMode } from "./permissions/types.js";
|
||||
import { modeService } from "./services/ModeService.js";
|
||||
import { serviceContainer } from "./services/ServiceContainer.js";
|
||||
|
|
@ -153,7 +153,7 @@ export async function constructSystemMessage(
|
|||
if (additionalRules && additionalRules.length > 0) {
|
||||
for (const ruleSpec of additionalRules) {
|
||||
try {
|
||||
const processedRule = await processPromptOrRule(ruleSpec);
|
||||
const processedRule = await processRule(ruleSpec);
|
||||
processedRules.push(processedRule);
|
||||
} catch (error: any) {
|
||||
console.warn(
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
import * as args from "../args.js";
|
||||
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { processRule } from "../hubLoader.js";
|
||||
import { processAndCombinePrompts } from "./promptProcessor.js";
|
||||
|
||||
// Mock the args module
|
||||
vi.mock("../args.js", () => ({
|
||||
processPromptOrRule: vi.fn(),
|
||||
vi.mock("../hubLoader.js", () => ({
|
||||
processRule: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock the logger
|
||||
|
|
@ -38,7 +36,7 @@ describe("promptProcessor", () => {
|
|||
});
|
||||
|
||||
it("should process single additional prompt without initial", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
const mockProcessPromptOrRule = vi.mocked(processRule);
|
||||
mockProcessPromptOrRule.mockResolvedValue("processed prompt");
|
||||
|
||||
const result = await processAndCombinePrompts(["prompt1"]);
|
||||
|
|
@ -48,7 +46,7 @@ describe("promptProcessor", () => {
|
|||
});
|
||||
|
||||
it("should combine multiple processed prompts", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
const mockProcessPromptOrRule = vi.mocked(processRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockResolvedValueOnce("first prompt")
|
||||
.mockResolvedValueOnce("second prompt");
|
||||
|
|
@ -62,7 +60,7 @@ describe("promptProcessor", () => {
|
|||
});
|
||||
|
||||
it("should combine processed prompts with initial prompt", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
const mockProcessPromptOrRule = vi.mocked(processRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockResolvedValueOnce("processed1")
|
||||
.mockResolvedValueOnce("processed2");
|
||||
|
|
@ -76,7 +74,7 @@ describe("promptProcessor", () => {
|
|||
});
|
||||
|
||||
it("should handle processing errors and continue with successful ones", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
const mockProcessPromptOrRule = vi.mocked(processRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockResolvedValueOnce("success1")
|
||||
.mockRejectedValueOnce(new Error("processing failed"))
|
||||
|
|
@ -89,7 +87,7 @@ describe("promptProcessor", () => {
|
|||
});
|
||||
|
||||
it("should return initial prompt when all processing fails", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
const mockProcessPromptOrRule = vi.mocked(processRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockRejectedValueOnce(new Error("fail1"))
|
||||
.mockRejectedValueOnce(new Error("fail2"));
|
||||
|
|
@ -103,7 +101,7 @@ describe("promptProcessor", () => {
|
|||
});
|
||||
|
||||
it("should return undefined when all processing fails and no initial", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
const mockProcessPromptOrRule = vi.mocked(processRule);
|
||||
mockProcessPromptOrRule.mockRejectedValue(new Error("processing failed"));
|
||||
|
||||
const result = await processAndCombinePrompts(["bad"]);
|
||||
|
|
@ -112,7 +110,7 @@ describe("promptProcessor", () => {
|
|||
});
|
||||
|
||||
it("should warn when processing fails", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
const mockProcessPromptOrRule = vi.mocked(processRule);
|
||||
mockProcessPromptOrRule.mockRejectedValue(new Error("test error"));
|
||||
|
||||
const { logger } = await import("./logger.js");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { processPromptOrRule } from "../args.js";
|
||||
|
||||
import { processRule } from "../hubLoader.js";
|
||||
import { logger } from "./logger.js";
|
||||
|
||||
/**
|
||||
|
|
@ -20,7 +19,7 @@ export async function processAndCombinePrompts(
|
|||
|
||||
for (const promptSpec of additionalPrompts) {
|
||||
try {
|
||||
const processed = await processPromptOrRule(promptSpec);
|
||||
const processed = await processRule(promptSpec);
|
||||
processedPrompts.push(processed);
|
||||
} catch (error: any) {
|
||||
logger.warn(`Failed to process prompt "${promptSpec}": ${error.message}`);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue