From 781c0b839c4c8b7d400d984fe3a6cc1007451dca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 05:38:53 +0000 Subject: [PATCH 1/3] Initial plan From 2c6713f8ae0594e6267ba13b2513491f12cb292a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 05:49:53 +0000 Subject: [PATCH 2/3] fix: make invalid temporary_id a warning and support underscores - Update isTemporaryId regex to allow underscores (A-Za-z0-9_) so IDs like 'aw_pr_testfix' are now valid - Update TEMPORARY_ID_PATTERN and TEMPORARY_ID_CANDIDATE_PATTERN to include underscores for consistent matching - Change getOrGenerateTemporaryId to warn + auto-generate instead of returning an error when format is invalid - Change create_pull_request.cjs inline validation to warn + auto-generate instead of failing the whole PR creation - Update error messages throughout to mention underscore support - Update tests to reflect new behavior and new error messages Agent-Logs-Url: https://github.com/github/gh-aw/sessions/8933463a-4aa4-485a-9e85-9ac4a4294ed4 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- actions/setup/js/create_pull_request.cjs | 15 +++---- actions/setup/js/temporary_id.cjs | 30 ++++++++----- actions/setup/js/temporary_id.test.cjs | 56 +++++++++++++++++++++++- actions/setup/js/update_project.cjs | 4 +- actions/setup/js/update_project.test.cjs | 4 +- 5 files changed, 84 insertions(+), 25 deletions(-) diff --git a/actions/setup/js/create_pull_request.cjs b/actions/setup/js/create_pull_request.cjs index 8670a3d8a97..242f5538a9f 100644 --- a/actions/setup/js/create_pull_request.cjs +++ b/actions/setup/js/create_pull_request.cjs @@ -11,7 +11,7 @@ const { getTrackerID } = require("./get_tracker_id.cjs"); const { removeDuplicateTitleFromDescription } = require("./remove_duplicate_title.cjs"); const { sanitizeTitle, applyTitlePrefix } = require("./sanitize_title.cjs"); const { getErrorMessage } = require("./error_helpers.cjs"); -const { replaceTemporaryIdReferences, isTemporaryId } = require("./temporary_id.cjs"); +const { replaceTemporaryIdReferences, isTemporaryId, generateTemporaryId } = require("./temporary_id.cjs"); const { resolveTargetRepoConfig, resolveAndValidateRepo } = require("./repo_helpers.cjs"); const { addExpirationToFooter } = require("./ephemerals.cjs"); const { generateWorkflowIdMarker } = require("./generate_footer.cjs"); @@ -261,16 +261,15 @@ async function main(config = {}) { const normalized = rawTemporaryId.startsWith("#") ? rawTemporaryId.substring(1).trim() : rawTemporaryId; if (!isTemporaryId(normalized)) { + // Warn and auto-generate rather than failing - an invalid temporary_id is a minor issue + const autoGenerated = generateTemporaryId(); core.warning( - `Skipping create_pull_request: Invalid temporary_id format: '${pullRequestItem.temporary_id}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric characters (A-Za-z0-9). Example: 'aw_abc' or 'aw_Test123'` + `Invalid temporary_id format: '${pullRequestItem.temporary_id}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric or underscore characters (A-Za-z0-9_). Example: 'aw_abc' or 'aw_pr_fix'. Using auto-generated ID: '${autoGenerated}'` ); - return { - success: false, - error: `Invalid temporary_id format: '${pullRequestItem.temporary_id}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric characters (A-Za-z0-9). Example: 'aw_abc' or 'aw_Test123'`, - }; + temporaryId = autoGenerated; + } else { + temporaryId = normalized.toLowerCase(); } - - temporaryId = normalized.toLowerCase(); } core.info(`Processing create_pull_request: title=${pullRequestItem.title || "No title"}, bodyLength=${pullRequestItem.body?.length || 0}`); diff --git a/actions/setup/js/temporary_id.cjs b/actions/setup/js/temporary_id.cjs index 54d435344a8..e9c35220f50 100644 --- a/actions/setup/js/temporary_id.cjs +++ b/actions/setup/js/temporary_id.cjs @@ -25,15 +25,15 @@ const crypto = require("crypto"); /** * Regex pattern for matching temporary ID references in text - * Format: #aw_XXX to #aw_XXXXXXXXXXXX (aw_ prefix + 3 to 12 alphanumeric characters) + * Format: #aw_XXX to #aw_XXXXXXXXXXXX (aw_ prefix + 3 to 12 alphanumeric or underscore characters) */ -const TEMPORARY_ID_PATTERN = /#(aw_[A-Za-z0-9]{3,12})\b/gi; +const TEMPORARY_ID_PATTERN = /#(aw_[A-Za-z0-9_]{3,12})\b/gi; /** * Regex pattern for detecting candidate #aw_ references (any length, word-boundary delimited) * Used to identify malformed temporary ID references that don't match TEMPORARY_ID_PATTERN */ -const TEMPORARY_ID_CANDIDATE_PATTERN = /#aw_([A-Za-z0-9]+)\b/gi; +const TEMPORARY_ID_CANDIDATE_PATTERN = /#aw_([A-Za-z0-9_]+)\b/gi; /** * @typedef {Object} RepoIssuePair @@ -57,13 +57,13 @@ function generateTemporaryId() { } /** - * Check if a value is a valid temporary ID (aw_ prefix + 3 to 12 alphanumeric characters) + * Check if a value is a valid temporary ID (aw_ prefix + 3 to 12 alphanumeric or underscore characters) * @param {any} value - The value to check * @returns {boolean} True if the value is a valid temporary ID */ function isTemporaryId(value) { if (typeof value === "string") { - return /^aw_[A-Za-z0-9]{3,12}$/i.test(value); + return /^aw_[A-Za-z0-9_]{3,12}$/i.test(value); } return false; } @@ -92,7 +92,7 @@ function replaceTemporaryIdReferences(text, tempIdMap, currentRepo) { while ((candidate = TEMPORARY_ID_CANDIDATE_PATTERN.exec(text)) !== null) { const tempId = `aw_${candidate[1]}`; if (!isTemporaryId(tempId)) { - core.warning(`Malformed temporary ID reference '${candidate[0]}' found in body text. Temporary IDs must be in format '#aw_' followed by 3 to 12 alphanumeric characters (A-Za-z0-9). Example: '#aw_abc' or '#aw_Test123'`); + core.warning(`Malformed temporary ID reference '${candidate[0]}' found in body text. Temporary IDs must be in format '#aw_' followed by 3 to 12 alphanumeric or underscore characters (A-Za-z0-9_). Example: '#aw_abc' or '#aw_pr_fix'`); } } @@ -132,7 +132,8 @@ function replaceTemporaryIdReferencesLegacy(text, tempIdMap) { /** * Validate and process a temporary_id from a message - * Auto-generates a temporary ID if not provided, or validates and normalizes if provided + * Auto-generates a temporary ID if not provided, or validates and normalizes if provided. + * If the format is invalid, emits a warning and auto-generates a new ID instead of failing. * * @param {Object} message - The message object that may contain a temporary_id field * @param {string} entityType - Type of entity (e.g., "issue", "discussion", "project") for error messages @@ -160,9 +161,16 @@ function getOrGenerateTemporaryId(message, entityType = "item") { const normalized = rawTemporaryId.startsWith("#") ? rawTemporaryId.substring(1).trim() : rawTemporaryId; if (!isTemporaryId(normalized)) { + // Warn and auto-generate rather than failing - an invalid temporary_id is a minor issue + const autoGenerated = generateTemporaryId(); + if (typeof core !== "undefined") { + core.warning( + `Invalid temporary_id format: '${message.temporary_id}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric or underscore characters (A-Za-z0-9_). Example: 'aw_abc' or 'aw_pr_fix'. Using auto-generated ID: '${autoGenerated}'` + ); + } return { - temporaryId: null, - error: `Invalid temporary_id format: '${message.temporary_id}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric characters (A-Za-z0-9). Example: 'aw_abc' or 'aw_Test123'`, + temporaryId: autoGenerated, + error: null, }; } @@ -298,14 +306,14 @@ function resolveIssueNumber(value, temporaryIdMap) { return { resolved: null, wasTemporaryId: false, - errorMessage: `Invalid temporary ID format: '${valueStr}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric characters (A-Za-z0-9). Example: 'aw_abc' or 'aw_abc12345'`, + errorMessage: `Invalid temporary ID format: '${valueStr}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric or underscore characters (A-Za-z0-9_). Example: 'aw_abc' or 'aw_pr_fix'`, }; } // It's a real issue number - use context repo as default const issueNumber = typeof value === "number" ? value : parseInt(valueWithoutHash, 10); if (isNaN(issueNumber) || issueNumber <= 0) { - return { resolved: null, wasTemporaryId: false, errorMessage: `Invalid issue number: ${value}. Expected either a valid temporary ID (format: aw_ followed by 3-12 alphanumeric characters) or a numeric issue number.` }; + return { resolved: null, wasTemporaryId: false, errorMessage: `Invalid issue number: ${value}. Expected either a valid temporary ID (format: aw_ followed by 3-12 alphanumeric or underscore characters) or a numeric issue number.` }; } const contextRepo = typeof context !== "undefined" ? `${context.repo.owner}/${context.repo.repo}` : ""; diff --git a/actions/setup/js/temporary_id.test.cjs b/actions/setup/js/temporary_id.test.cjs index ac7b18cf585..cf474540745 100644 --- a/actions/setup/js/temporary_id.test.cjs +++ b/actions/setup/js/temporary_id.test.cjs @@ -52,13 +52,19 @@ describe("temporary_id.cjs", () => { expect(isTemporaryId("aw_123456789abc")).toBe(true); // 12 chars - at the limit }); + it("should return true for valid aw_ prefixed strings with underscores", async () => { + const { isTemporaryId } = await import("./temporary_id.cjs"); + expect(isTemporaryId("aw_id_123")).toBe(true); // Contains underscore - now valid + expect(isTemporaryId("aw_pr_fix")).toBe(true); // Underscore-separated words + expect(isTemporaryId("aw_pr_testfix")).toBe(true); // From the original issue + }); + it("should return false for invalid strings", async () => { const { isTemporaryId } = await import("./temporary_id.cjs"); expect(isTemporaryId("abc123def456")).toBe(false); // Missing aw_ prefix expect(isTemporaryId("aw_ab")).toBe(false); // Too short (2 chars) expect(isTemporaryId("aw_1234567890abc")).toBe(false); // Too long (13 chars) expect(isTemporaryId("aw_test-id")).toBe(false); // Contains hyphen - expect(isTemporaryId("aw_id_123")).toBe(false); // Contains underscore expect(isTemporaryId("")).toBe(false); expect(isTemporaryId("temp_abc123")).toBe(false); // Wrong prefix }); @@ -173,6 +179,52 @@ describe("temporary_id.cjs", () => { }); }); + describe("getOrGenerateTemporaryId", () => { + it("should auto-generate a temporary ID when not provided", async () => { + const { getOrGenerateTemporaryId } = await import("./temporary_id.cjs"); + const result = getOrGenerateTemporaryId({ title: "Test" }); + expect(result.error).toBeNull(); + expect(result.temporaryId).toMatch(/^aw_[A-Za-z0-9]{8}$/); + }); + + it("should return valid temporary ID when provided", async () => { + const { getOrGenerateTemporaryId } = await import("./temporary_id.cjs"); + const result = getOrGenerateTemporaryId({ temporary_id: "aw_abc123" }); + expect(result.error).toBeNull(); + expect(result.temporaryId).toBe("aw_abc123"); + }); + + it("should accept temporary ID with underscores", async () => { + const { getOrGenerateTemporaryId } = await import("./temporary_id.cjs"); + const result = getOrGenerateTemporaryId({ temporary_id: "aw_pr_fix" }); + expect(result.error).toBeNull(); + expect(result.temporaryId).toBe("aw_pr_fix"); + }); + + it("should accept the aw_pr_testfix format from the original issue", async () => { + const { getOrGenerateTemporaryId } = await import("./temporary_id.cjs"); + const result = getOrGenerateTemporaryId({ temporary_id: "aw_pr_testfix" }); + expect(result.error).toBeNull(); + expect(result.temporaryId).toBe("aw_pr_testfix"); + }); + + it("should warn and auto-generate when format is invalid instead of failing", async () => { + const { getOrGenerateTemporaryId } = await import("./temporary_id.cjs"); + const result = getOrGenerateTemporaryId({ temporary_id: "aw_toolongidentifier123" }); + expect(result.error).toBeNull(); + expect(result.temporaryId).toMatch(/^aw_[A-Za-z0-9]{8}$/); + expect(mockCore.warning).toHaveBeenCalledOnce(); + expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("aw_toolongidentifier123")); + }); + + it("should return error when temporary_id is not a string", async () => { + const { getOrGenerateTemporaryId } = await import("./temporary_id.cjs"); + const result = getOrGenerateTemporaryId({ temporary_id: 123 }); + expect(result.error).toContain("temporary_id must be a string"); + expect(result.temporaryId).toBeNull(); + }); + }); + describe("replaceTemporaryIdReferencesLegacy", () => { it("should replace #aw_ID with issue numbers", async () => { const { replaceTemporaryIdReferencesLegacy } = await import("./temporary_id.cjs"); @@ -323,7 +375,7 @@ describe("temporary_id.cjs", () => { expect(result.wasTemporaryId).toBe(false); expect(result.errorMessage).toContain("Invalid temporary ID format"); expect(result.errorMessage).toContain("aw_test-id"); - expect(result.errorMessage).toContain("3 to 12 alphanumeric characters"); + expect(result.errorMessage).toContain("3 to 12 alphanumeric or underscore characters"); }); it("should return specific error for malformed temporary ID (too short)", async () => { diff --git a/actions/setup/js/update_project.cjs b/actions/setup/js/update_project.cjs index 162bf69be8e..f7d70362c17 100644 --- a/actions/setup/js/update_project.cjs +++ b/actions/setup/js/update_project.cjs @@ -762,11 +762,11 @@ async function updateProject(output, temporaryIdMap = new Map(), githubClient = // Validate IDs used for draft chaining. // Draft issue chaining must use strict temporary IDs to match the unified handler manager. if (temporaryId && !isTemporaryId(temporaryId)) { - throw new Error(`${ERR_VALIDATION}: Invalid temporary_id format: "${temporaryId}". Expected format: aw_ followed by 3 to 12 alphanumeric characters (e.g., "aw_abc", "aw_Test123").`); + throw new Error(`${ERR_VALIDATION}: Invalid temporary_id format: "${temporaryId}". Expected format: aw_ followed by 3 to 12 alphanumeric or underscore characters (e.g., "aw_abc", "aw_pr_fix").`); } if (draftIssueId && !isTemporaryId(draftIssueId)) { - throw new Error(`${ERR_VALIDATION}: Invalid draft_issue_id format: "${draftIssueId}". Expected format: aw_ followed by 3 to 12 alphanumeric characters (e.g., "aw_abc", "aw_Test123").`); + throw new Error(`${ERR_VALIDATION}: Invalid draft_issue_id format: "${draftIssueId}". Expected format: aw_ followed by 3 to 12 alphanumeric or underscore characters (e.g., "aw_abc", "aw_pr_fix").`); } const draftTitle = typeof output.draft_title === "string" ? output.draft_title.trim() : ""; diff --git a/actions/setup/js/update_project.test.cjs b/actions/setup/js/update_project.test.cjs index 98d358350eb..10151ca3fb0 100644 --- a/actions/setup/js/update_project.test.cjs +++ b/actions/setup/js/update_project.test.cjs @@ -891,7 +891,7 @@ describe("updateProject", () => { queueResponses([repoResponse(), viewerResponse(), orgProjectV2Response(projectUrl, 60, "project-draft")]); - await expect(updateProject(output)).rejects.toThrow(/Invalid temporary_id format.*aw_ followed by 3 to 12 alphanumeric characters/); + await expect(updateProject(output)).rejects.toThrow(/Invalid temporary_id format.*aw_ followed by 3 to 12 alphanumeric or underscore characters/); }); it("rejects malformed auto-generated draft_issue_id with aw_ prefix", async () => { @@ -906,7 +906,7 @@ describe("updateProject", () => { queueResponses([repoResponse(), viewerResponse(), orgProjectV2Response(projectUrl, 60, "project-draft")]); - await expect(updateProject(output, temporaryIdMap)).rejects.toThrow(/Invalid draft_issue_id format.*aw_ followed by 3 to 12 alphanumeric characters/); + await expect(updateProject(output, temporaryIdMap)).rejects.toThrow(/Invalid draft_issue_id format.*aw_ followed by 3 to 12 alphanumeric or underscore characters/); }); it("rejects draft_issue without title when creating (no draft_issue_id)", async () => { From bf2a8a1e019c718a2b084336bee096788247bebb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 10:20:09 +0000 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20address=20review=20comments=20?= =?UTF-8?q?=E2=80=94=20fix=20candidate=20pattern=20for=20hyphens,=20use=20?= =?UTF-8?q?shared=20helper=20in=20create=5Fpull=5Frequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - TEMPORARY_ID_CANDIDATE_PATTERN now uses [A-Za-z0-9_-]+ (no \b) so #aw_test-id captures the full token 'test-id' instead of just 'test', triggering a warning as expected - create_pull_request.cjs now uses getOrGenerateTemporaryId() shared helper instead of duplicating the validation/fallback logic - Added test for hyphen-containing malformed temp ID reference Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a6bd2d2f-d14b-45b6-b5aa-61ea6b64360c Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- actions/setup/js/create_pull_request.cjs | 30 +++++------------------- actions/setup/js/temporary_id.cjs | 8 ++++--- actions/setup/js/temporary_id.test.cjs | 10 ++++++++ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/actions/setup/js/create_pull_request.cjs b/actions/setup/js/create_pull_request.cjs index 242f5538a9f..07cf883f82f 100644 --- a/actions/setup/js/create_pull_request.cjs +++ b/actions/setup/js/create_pull_request.cjs @@ -11,7 +11,7 @@ const { getTrackerID } = require("./get_tracker_id.cjs"); const { removeDuplicateTitleFromDescription } = require("./remove_duplicate_title.cjs"); const { sanitizeTitle, applyTitlePrefix } = require("./sanitize_title.cjs"); const { getErrorMessage } = require("./error_helpers.cjs"); -const { replaceTemporaryIdReferences, isTemporaryId, generateTemporaryId } = require("./temporary_id.cjs"); +const { replaceTemporaryIdReferences, getOrGenerateTemporaryId } = require("./temporary_id.cjs"); const { resolveTargetRepoConfig, resolveAndValidateRepo } = require("./repo_helpers.cjs"); const { addExpirationToFooter } = require("./ephemerals.cjs"); const { generateWorkflowIdMarker } = require("./generate_footer.cjs"); @@ -247,30 +247,12 @@ async function main(config = {}) { const pullRequestItem = message; - let temporaryId; - if (pullRequestItem.temporary_id !== undefined && pullRequestItem.temporary_id !== null) { - if (typeof pullRequestItem.temporary_id !== "string") { - core.warning(`Skipping create_pull_request: temporary_id must be a string (got ${typeof pullRequestItem.temporary_id})`); - return { - success: false, - error: `temporary_id must be a string (got ${typeof pullRequestItem.temporary_id})`, - }; - } - - const rawTemporaryId = pullRequestItem.temporary_id.trim(); - const normalized = rawTemporaryId.startsWith("#") ? rawTemporaryId.substring(1).trim() : rawTemporaryId; - - if (!isTemporaryId(normalized)) { - // Warn and auto-generate rather than failing - an invalid temporary_id is a minor issue - const autoGenerated = generateTemporaryId(); - core.warning( - `Invalid temporary_id format: '${pullRequestItem.temporary_id}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric or underscore characters (A-Za-z0-9_). Example: 'aw_abc' or 'aw_pr_fix'. Using auto-generated ID: '${autoGenerated}'` - ); - temporaryId = autoGenerated; - } else { - temporaryId = normalized.toLowerCase(); - } + const tempIdResult = getOrGenerateTemporaryId(pullRequestItem, "pull request"); + if (tempIdResult.error) { + core.warning(`Skipping create_pull_request: ${tempIdResult.error}`); + return { success: false, error: tempIdResult.error }; } + const temporaryId = tempIdResult.temporaryId; core.info(`Processing create_pull_request: title=${pullRequestItem.title || "No title"}, bodyLength=${pullRequestItem.body?.length || 0}`); diff --git a/actions/setup/js/temporary_id.cjs b/actions/setup/js/temporary_id.cjs index e9c35220f50..e72ee40d294 100644 --- a/actions/setup/js/temporary_id.cjs +++ b/actions/setup/js/temporary_id.cjs @@ -30,10 +30,12 @@ const crypto = require("crypto"); const TEMPORARY_ID_PATTERN = /#(aw_[A-Za-z0-9_]{3,12})\b/gi; /** - * Regex pattern for detecting candidate #aw_ references (any length, word-boundary delimited) - * Used to identify malformed temporary ID references that don't match TEMPORARY_ID_PATTERN + * Regex pattern for detecting candidate #aw_ references (any alphanumeric, underscore, or hyphen content) + * Used to identify malformed temporary ID references that don't match TEMPORARY_ID_PATTERN. + * Uses a broader character set (including hyphens) than the valid pattern to capture the full token + * and warn about references like #aw_test-id where the hyphen makes the whole token invalid. */ -const TEMPORARY_ID_CANDIDATE_PATTERN = /#aw_([A-Za-z0-9_]+)\b/gi; +const TEMPORARY_ID_CANDIDATE_PATTERN = /#aw_([A-Za-z0-9_-]+)/gi; /** * @typedef {Object} RepoIssuePair diff --git a/actions/setup/js/temporary_id.test.cjs b/actions/setup/js/temporary_id.test.cjs index cf474540745..045098957a5 100644 --- a/actions/setup/js/temporary_id.test.cjs +++ b/actions/setup/js/temporary_id.test.cjs @@ -177,6 +177,16 @@ describe("temporary_id.cjs", () => { expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("#aw_ab")); expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("#aw_toolongname123")); }); + + it("should warn about malformed temporary ID reference containing a hyphen", async () => { + const { replaceTemporaryIdReferences } = await import("./temporary_id.cjs"); + const map = new Map(); + const text = "Check #aw_test-id for details"; + const result = replaceTemporaryIdReferences(text, map, "owner/repo"); + expect(result).toBe("Check #aw_test-id for details"); + expect(mockCore.warning).toHaveBeenCalledOnce(); + expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("#aw_test-id")); + }); }); describe("getOrGenerateTemporaryId", () => {