diff --git a/actions/setup/js/close_entity_helpers.test.cjs b/actions/setup/js/close_entity_helpers.test.cjs index f97439fdeb4..38b275acce4 100644 --- a/actions/setup/js/close_entity_helpers.test.cjs +++ b/actions/setup/js/close_entity_helpers.test.cjs @@ -1,6 +1,7 @@ import { describe, it, expect, beforeEach, vi } from "vitest"; import fs from "fs"; import path from "path"; +import { fileURLToPath } from "url"; const mockCore = { debug: vi.fn(), info: vi.fn(), warning: vi.fn(), error: vi.fn(), setFailed: vi.fn(), setOutput: vi.fn(), summary: { addRaw: vi.fn().mockReturnThis(), write: vi.fn().mockResolvedValue() } }, mockContext = { eventName: "issues", runId: 12345, repo: { owner: "testowner", repo: "testrepo" }, payload: { issue: { number: 42 }, pull_request: { number: 100 }, repository: { html_url: "https://github.com/testowner/testrepo" } } }; ((global.core = mockCore), (global.context = mockContext)); @@ -14,6 +15,10 @@ describe("close_entity_helpers", () => { delete process.env.GH_AW_CLOSE_PR_REQUIRED_LABELS, delete process.env.GH_AW_CLOSE_PR_REQUIRED_TITLE_PREFIX, delete process.env.GH_AW_CLOSE_PR_TARGET, + // Point GH_AW_PROMPTS_DIR to the source md/ directory so getPromptPath() + // resolves template files from the source tree in test environments where + // RUNNER_TEMP is set but the runtime prompts directory is not populated. + (process.env.GH_AW_PROMPTS_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "../md")), (global.context.eventName = "issues"), (global.context.payload.issue = { number: 42 }), (global.context.payload.pull_request = { number: 100 })); diff --git a/actions/setup/js/messages.test.cjs b/actions/setup/js/messages.test.cjs index 40e13e77e7f..5e096f9ce88 100644 --- a/actions/setup/js/messages.test.cjs +++ b/actions/setup/js/messages.test.cjs @@ -10,6 +10,8 @@ * - Run status messages (started, success, failure) */ import { describe, it, expect, beforeEach, vi } from "vitest"; +import path from "path"; +import { fileURLToPath } from "url"; // Mock core for GitHub Actions environment const mockCore = { @@ -36,6 +38,10 @@ describe("messages.cjs", () => { delete process.env.GH_AW_EFFECTIVE_TOKENS; delete process.env.GH_AW_DETECTION_CONCLUSION; delete process.env.GH_AW_DETECTION_REASON; + // Point GH_AW_PROMPTS_DIR to the source md/ directory so getPromptPath() + // resolves template files from the source tree in test environments where + // RUNNER_TEMP is set but the runtime prompts directory is not populated. + process.env.GH_AW_PROMPTS_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "../md"); // Clear cache by reimporting vi.resetModules(); }); diff --git a/actions/setup/js/messages_footer.cjs b/actions/setup/js/messages_footer.cjs index 08a23cf1887..92a58e31bbb 100644 --- a/actions/setup/js/messages_footer.cjs +++ b/actions/setup/js/messages_footer.cjs @@ -8,8 +8,7 @@ * for safe-output workflows. */ -const path = require("path"); -const { getMessages, renderTemplate, renderTemplateFromFile, toSnakeCase } = require("./messages_core.cjs"); +const { getMessages, renderTemplate, renderTemplateFromFile, toSnakeCase, getPromptPath } = require("./messages_core.cjs"); const { getMissingInfoSections } = require("./missing_messages_helper.cjs"); const { getBlockedDomains, generateBlockedDomainsSection } = require("./firewall_blocked_domains.cjs"); const { getDifcFilteredEvents, generateDifcFilteredSection } = require("./gateway_difc_filtered.cjs"); @@ -132,7 +131,7 @@ function getFooterInstallMessage(ctx) { // Create context with both camelCase and snake_case keys, including computed agentic_workflow_url const templateContext = toSnakeCase({ ...ctx, agenticWorkflowUrl }); - const defaultInstallTemplatePath = path.join(__dirname, "../md/workflow_install_note.md"); + const defaultInstallTemplatePath = getPromptPath("workflow_install_note.md"); // Use custom installation message if configured return messages?.footerInstall ? renderTemplate(messages.footerInstall, templateContext) : renderTemplateFromFile(defaultInstallTemplatePath, templateContext); diff --git a/actions/setup/js/pr_review_buffer.test.cjs b/actions/setup/js/pr_review_buffer.test.cjs index a6a21e2ee23..d4630a816f3 100644 --- a/actions/setup/js/pr_review_buffer.test.cjs +++ b/actions/setup/js/pr_review_buffer.test.cjs @@ -1,4 +1,6 @@ import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; +import path from "path"; +import { fileURLToPath } from "url"; const mockCore = { debug: vi.fn(), @@ -28,6 +30,7 @@ const { createReviewBuffer } = require("./pr_review_buffer.cjs"); describe("pr_review_buffer (factory pattern)", () => { let buffer; let originalMessages; + let originalPromptsDir; beforeEach(() => { vi.clearAllMocks(); @@ -36,6 +39,12 @@ describe("pr_review_buffer (factory pattern)", () => { originalMessages = process.env.GH_AW_SAFE_OUTPUT_MESSAGES; delete process.env.GH_AW_SAFE_OUTPUT_MESSAGES; + // Point GH_AW_PROMPTS_DIR to the source md/ directory so getPromptPath() + // resolves template files from the source tree in test environments where + // RUNNER_TEMP is set but the runtime prompts directory is not populated. + originalPromptsDir = process.env.GH_AW_PROMPTS_DIR; + process.env.GH_AW_PROMPTS_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "../md"); + // Default: return empty file list so path filtering is skipped unless explicitly mocked mockGithub.rest.pulls.listFiles.mockResolvedValue({ data: [] }); @@ -50,6 +59,11 @@ describe("pr_review_buffer (factory pattern)", () => { } else { delete process.env.GH_AW_SAFE_OUTPUT_MESSAGES; } + if (originalPromptsDir !== undefined) { + process.env.GH_AW_PROMPTS_DIR = originalPromptsDir; + } else { + delete process.env.GH_AW_PROMPTS_DIR; + } }); it("should create independent buffer instances", () => {