From c9d867b3d12779b5bfa563894f78565bfa5f95b6 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 5 Jan 2026 12:32:31 +0800 Subject: [PATCH] Enhance Script Resolution Logic and Validation - Updated the ResolveScript function to support an additional script format, allowing for sub-agent paths in the input. - Improved error messaging for invalid script paths to clarify expected formats. - Refactored path building logic to accommodate both standard and sub-agent script structures, enhancing flexibility in script resolution. - Modified the test runner to validate results using an asserter that includes the response for tool_called assertions, improving test accuracy. --- agent/test/runner.go | 4 ++-- agent/test/script.go | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/agent/test/runner.go b/agent/test/runner.go index 9159df4d..5fc9b242 100644 --- a/agent/test/runner.go +++ b/agent/test/runner.go @@ -502,8 +502,8 @@ func (r *Executor) runSingleTest(ast *assistant.Assistant, tc *Case, agentID str // Extract output result.Output = extractOutput(response) - // Validate result using asserter - asserter := NewAsserter() + // Validate result using asserter (with response for tool_called assertions) + asserter := NewAsserter().WithResponse(response) passed, errMsg := asserter.Validate(tc, result.Output) if passed { result.Status = StatusPassed diff --git a/agent/test/script.go b/agent/test/script.go index 6f048c17..fc99674c 100644 --- a/agent/test/script.go +++ b/agent/test/script.go @@ -28,29 +28,43 @@ func NewScriptRunner(opts *Options) *ScriptRunner { } } -// ResolveScript resolves the script path from scripts.xxx.yyy format +// ResolveScript resolves the script path from scripts.xxx.yyy or scripts.xxx.yyy.zzz format func ResolveScript(input string) (*ScriptInfo, error) { // Remove "scripts." prefix path := strings.TrimPrefix(input, "scripts.") - // Split into parts: "expense.setup" -> ["expense", "setup"] + // Split into parts: + // "expense.setup" -> ["expense", "setup"] + // "expense.submission.validation" -> ["expense", "submission", "validation"] parts := strings.Split(path, ".") if len(parts) < 2 { - return nil, fmt.Errorf("invalid script path: %s (expected format: scripts.assistant.module)", input) + return nil, fmt.Errorf("invalid script path: %s (expected format: scripts.assistant.module or scripts.assistant.sub_agent.module)", input) } - // Build paths - // assistantDir: expense - // moduleName: setup - // scriptPath: expense/src/setup.ts (or assistants/expense/src/setup.ts) - // testPath: expense/src/setup_test.ts - assistantDir := parts[0] - moduleName := parts[1] + // Build paths based on number of parts + var basePaths []string + var assistantDir, moduleName string - // Try different path patterns - basePaths := []string{ - filepath.Join("assistants", assistantDir, "src"), - filepath.Join(assistantDir, "src"), + if len(parts) == 2 { + // Format: scripts.expense.setup + // assistantDir: expense + // moduleName: setup + assistantDir = parts[0] + moduleName = parts[1] + basePaths = []string{ + filepath.Join("assistants", assistantDir, "src"), + filepath.Join(assistantDir, "src"), + } + } else { + // Format: scripts.expense.submission.validation (sub-agent) + // assistantDir: expense/submission (or expense.submission) + // moduleName: validation + assistantDir = strings.Join(parts[:len(parts)-1], "/") + moduleName = parts[len(parts)-1] + basePaths = []string{ + filepath.Join("assistants", assistantDir, "src"), + filepath.Join(assistantDir, "src"), + } } var scriptPath, testPath string