{"record":{"id":"c86670cb497050bf","repo":"windmill-labs/windmill","slug":"no-script-code-available-to-test-please-ensure-yo","errorCode":null,"errorMessage":"No script code available to test. Please ensure you have a script open in the editor.","messagePattern":"No script code available to test\\. Please ensure you have a script open in the editor\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/chat/script/core.ts","lineNumber":900,"sourceCode":"\t\t\t\tcontent: 'Failed to apply code changes',\n\t\t\t\terror: errorMessage\n\t\t\t})\n\t\t\tthrow new Error(`Failed to apply code changes: ${errorMessage}`)\n\t\t}\n\t}\n}\n\nexport const testRunScriptTool: Tool<ScriptChatHelpers> = {\n\tdef: TEST_RUN_SCRIPT_TOOL,\n\tfn: async function ({ args, workspace, helpers, toolCallbacks, toolId }) {\n\t\tconst scriptOptions = helpers.getScriptOptions()\n\n\t\tif (!scriptOptions) {\n\t\t\ttoolCallbacks.setToolStatus(toolId, {\n\t\t\t\tcontent: 'No script available to test',\n\t\t\t\terror: 'No script found in current context'\n\t\t\t})\n\t\t\tthrow new Error(\n\t\t\t\t'No script code available to test. Please ensure you have a script open in the editor.'\n\t\t\t)\n\t\t}\n\n\t\tconst parsedArgs = await buildTestRunArgs(args, this.def)\n\n\t\treturn executeTestRun({\n\t\t\tjobStarter: () =>\n\t\t\t\tJobService.runScriptPreview({\n\t\t\t\t\tworkspace: workspace,\n\t\t\t\t\trequestBody: {\n\t\t\t\t\t\tpath: scriptOptions.path,\n\t\t\t\t\t\tcontent: scriptOptions.code,\n\t\t\t\t\t\targs: parsedArgs,\n\t\t\t\t\t\tlanguage: scriptOptions.lang as ScriptLang\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\tworkspace,","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/chat/script/core.ts#L882-L918","documentation":"The test-run tool for scripts requires script options (code/path) to be present in the current chat context before it can build and execute a test run. When none are found it throws this message telling the user to open a script in the editor first. It also sets a tool status so the model knows no script was available.","triggerScenarios":"testRunScriptTool.fn was invoked while scriptOptions was null/undefined — i.e. the chat context contains no script (no open editor tab, or the helpers could not resolve a script path/hash for the current context).","commonSituations":"User opened the AI chat from a contextless view (e.g. an empty editor tab or a non-script page) and asked the model to 'test it'; the editor tab was closed mid-chat; the chat was started before any script was loaded so helpers had nothing to bind to.","solutions":["Open a script in the editor so the chat context has script code/path, then ask the model to test again.","Start the copilot chat from within a script editor rather than a global/dashboard page.","If a script should be in context, check that the editor tab is focused/saved so helpers can resolve its path and hash.","For flow-related testing, switch the chat to flow mode where the test-run tool can target flow steps instead."],"exampleFix":"// before\n// chat opened with no editor content; tool throws\n// after\nconst code = editor.getValue()\nif (code.trim()) {\n  await chat.testRun({ path: scriptPath })\n} else {\n  openScript('scripts/foo.py')\n}","handlingStrategy":"validation","validationCode":"const scriptOptions = getScriptChatOptions()\nif (!scriptOptions?.path || !scriptOptions?.code?.trim()) {\n  // do not call the tool; open a script first\n  return 'Open a script in the editor before asking the assistant to test it.'\n}","typeGuard":"function hasScriptContext(opts: unknown): opts is { path: string; code: string } {\n  return !!opts && typeof opts === 'object' &&\n    typeof (opts as any).path === 'string' && (opts as any).path.length > 0 &&\n    typeof (opts as any).code === 'string' && (opts as any).code.trim().length > 0\n}","tryCatchPattern":"try {\n  await testRunScriptTool.fn({ args, workspace, helpers, toolCallbacks, toolId })\n} catch (e) {\n  if (e instanceof Error && e.message.includes('No script code available to test')) {\n    // prompt user to open a script, then retry\n  }\n}","preventionTips":["Open the target script in the editor before starting the copilot chat.","Verify the chat header shows the script path before asking for test runs.","Don't close the editor tab mid-conversation.","For non-script artifacts, switch the chat to the matching mode (flow/app)."],"tags":["copilot","test-run","missing-context"],"backgroundTag":"missing-context","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}