-
Notifications
You must be signed in to change notification settings - Fork 368
Fix comment-memory disclosure template lookup in safe_outputs #27989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cb266a7
15155e3
f61b850
a0e16d2
e6c0800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| /// <reference types="@actions/github-script" /> | ||
| require("./shim.cjs"); | ||
|
|
||
| const path = require("path"); | ||
| const { sanitizeContent } = require("./sanitize_content.cjs"); | ||
| const { getErrorMessage } = require("./error_helpers.cjs"); | ||
| const { SAFE_OUTPUT_E001 } = require("./error_codes.cjs"); | ||
|
|
@@ -20,7 +19,14 @@ const { COMMENT_MEMORY_TAG, COMMENT_MEMORY_MAX_SCAN_PAGES } = require("./comment | |
| // that happen to contain a matching comment-memory tag. | ||
| const MANAGED_COMMENT_PROVENANCE_MARKER = "<!-- gh-aw-agentic-workflow:"; | ||
| const MANAGED_COMMENT_HEADER = "### Comment Memory"; | ||
| const MANAGED_COMMENT_DISCLOSURE_NOTE_PATH = path.join(__dirname, "../md/comment_memory_disclosure_note.md"); | ||
|
|
||
| function renderManagedCommentDisclosureNote() { | ||
| const promptsDir = process.env.GH_AW_PROMPTS_DIR || `${process.env.RUNNER_TEMP}/gh-aw/prompts`; | ||
| const templatePath = `${promptsDir}/comment_memory_disclosure_note.md`; | ||
| return renderTemplateFromFile(templatePath, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
| comment_memory_tag: COMMENT_MEMORY_TAG, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Smoke Test Review: The |
||
| }); | ||
| } | ||
|
|
||
| function sanitizeMemoryID(memoryID) { | ||
| const normalized = String(memoryID || "default").trim(); | ||
|
|
@@ -32,7 +38,7 @@ function sanitizeMemoryID(memoryID) { | |
| } | ||
|
|
||
| function buildManagedMemoryBody(rawBody, memoryID, options) { | ||
| const { includeFooter, runUrl, workflowName, workflowSource, workflowSourceURL, historyUrl, triggeringIssueNumber, triggeringPRNumber, disclosureNote } = options; | ||
| const { includeFooter, runUrl, workflowName, workflowSource, workflowSourceURL, historyUrl, triggeringIssueNumber, triggeringPRNumber } = options; | ||
| if (!/^[a-zA-Z0-9_-]+$/.test(memoryID)) { | ||
| throw new Error(`${SAFE_OUTPUT_E001}: memory_id must contain only alphanumeric characters, hyphens, and underscores`); | ||
| } | ||
|
|
@@ -48,11 +54,7 @@ function buildManagedMemoryBody(rawBody, memoryID, options) { | |
|
|
||
| if (includeFooter) { | ||
| core.info(`comment_memory: footer enabled for memory_id='${memoryID}'`); | ||
| const resolvedDisclosureNote = | ||
| disclosureNote ?? | ||
| renderTemplateFromFile(MANAGED_COMMENT_DISCLOSURE_NOTE_PATH, { | ||
| comment_memory_tag: COMMENT_MEMORY_TAG, | ||
| }); | ||
| const resolvedDisclosureNote = renderManagedCommentDisclosureNote(); | ||
| body += "\n\n" + resolvedDisclosureNote; | ||
|
Comment on lines
55
to
58
|
||
| body += "\n\n" + generateFooterWithMessages(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringIssueNumber, triggeringPRNumber, undefined, historyUrl).trimEnd(); | ||
| } else { | ||
|
|
@@ -118,7 +120,6 @@ async function main(config = {}) { | |
| core.info(`comment_memory: initialized with max=${maxCount}, defaultMemoryID='${defaultMemoryID}', target='${target}', footer=${includeFooter}, staged=${staged}`); | ||
|
|
||
| let processedCount = 0; | ||
| let cachedDisclosureNote = null; | ||
|
|
||
| return async message => { | ||
| if (!message || message.type !== "comment_memory") { | ||
|
|
@@ -175,12 +176,6 @@ async function main(config = {}) { | |
| serverUrl: context.serverUrl, | ||
| }) || undefined; | ||
|
|
||
| if (cachedDisclosureNote === null) { | ||
| cachedDisclosureNote = renderTemplateFromFile(MANAGED_COMMENT_DISCLOSURE_NOTE_PATH, { | ||
| comment_memory_tag: COMMENT_MEMORY_TAG, | ||
| }); | ||
| } | ||
|
|
||
| const managedBody = buildManagedMemoryBody(message.body || "", memoryID, { | ||
| includeFooter, | ||
| runUrl, | ||
|
|
@@ -190,7 +185,6 @@ async function main(config = {}) { | |
| historyUrl, | ||
| triggeringIssueNumber, | ||
| triggeringPRNumber, | ||
| disclosureNote: cachedDisclosureNote, | ||
| }); | ||
| try { | ||
| enforceCommentLimits(managedBody); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,24 @@ | ||
| // @ts-check | ||
| import { describe, it, expect } from "vitest"; | ||
| import { describe, it, expect, beforeAll, afterAll } from "vitest"; | ||
| import path from "path"; | ||
| import { fileURLToPath } from "url"; | ||
|
|
||
| describe("comment_memory", () => { | ||
| let originalPromptsDir; | ||
|
|
||
| beforeAll(() => { | ||
| originalPromptsDir = process.env.GH_AW_PROMPTS_DIR; | ||
| process.env.GH_AW_PROMPTS_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "../md"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Smoke Test Review: The |
||
| }); | ||
|
|
||
| afterAll(() => { | ||
| if (originalPromptsDir === undefined) { | ||
| delete process.env.GH_AW_PROMPTS_DIR; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good addition of |
||
| return; | ||
| } | ||
| process.env.GH_AW_PROMPTS_DIR = originalPromptsDir; | ||
| }); | ||
|
|
||
| it("sanitizes valid memory IDs", async () => { | ||
| const module = await import("./comment_memory.cjs"); | ||
| expect(module.sanitizeMemoryID("Session_1")).toBe("Session_1"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renderManagedCommentDisclosureNote()falls back to${process.env.RUNNER_TEMP}/gh-aw/promptswhenGH_AW_PROMPTS_DIRis unset, but ifRUNNER_TEMPis missing this produces a path starting withundefined/...and the ensuingreadFileSyncfailure can be confusing to diagnose. Consider adding an explicit guard that throws/logs a clear error when neitherGH_AW_PROMPTS_DIRnorRUNNER_TEMPis available.