Skip to content

[code-simplifier] refactor: use shared isTruthy from is_truthy.cjs in render_template - #22184

Merged
pelikhan merged 1 commit into
mainfrom
simplify-render-template-cjs-7d4019c44d7c87d7
Mar 21, 2026
Merged

[code-simplifier] refactor: use shared isTruthy from is_truthy.cjs in render_template#22184
pelikhan merged 1 commit into
mainfrom
simplify-render-template-cjs-7d4019c44d7c87d7

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

This PR simplifies render_template.cjs to improve clarity and consistency while preserving all functionality.

Files Simplified

  • actions/setup/js/render_template.cjs — eliminated duplicate isTruthy, removed verbose guards, simplified logging
  • actions/setup/js/render_template.test.cjs — aligned with new import pattern, removed duplicate isTruthy tests

Improvements Made

Eliminated Duplicate isTruthy

render_template.cjs defined its own copy of isTruthy (with extra debug logging) while is_truthy.cjs already exists as a shared module. Both interpolate_prompt.cjs and fuzz_template_substitution_harness.cjs already import from is_truthy.cjs. This fix closes the DRY violation.

Before:

functionisTruthy(expr){constv=expr.trim().toLowerCase();constresult=!(v===""||v==="false"||v==="0"||v==="null"||v==="undefined");if(typeofcore!=="undefined"){core.info(`[isTruthy] Evaluating "\$\{expr}" (trimmed: "\$\{v}") -> \$\{result}`);}returnresult;}

After:

const{ isTruthy }=require("./is_truthy.cjs");

Removed Unnecessary typeof core Guards

Added require("./shim.cjs") (consistent with substitute_placeholders.cjs) and removed ~15 if (typeof core !== "undefined") guards. The shim ensures core is always available, so these guards were defensive noise.

Simplified main() Logging

Removed ASCII art separators (========================================), per-block body previews, first/last 200 character dumps, and error type logging — keeping only the actionable diagnostic messages.

Removed Unused Import

ERR_VALIDATION was imported but never used.

Changes Based On

Recent changes from commit 3be658504fix: \{\\{\#if ...}} in runtime-imported markdown incorrectly becomes an unresolvable placeholder (#22170)

Testing

  • ✅ All 17 tests pass (npx vitest run actions/setup/js/render_template.test.cjs)
  • ✅ Linting passes (make lint-cjs)
  • ✅ Formatting passes (make fmt-cjs)
  • ✅ No functional changes — behavior is identical

Review Focus

Please verify:

  • isTruthy from is_truthy.cjs has identical behavior to the removed local copy (it does — same logic, just without the extra debug logging)
  • The shim pattern is consistent with other standalone-runnable .cjs files like substitute_placeholders.cjs

Note

**🔒 Integrity filter blocked 2 items**

The following items were blocked because they don't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
github:
min-integrity: approved # merged | approved | unapproved | none

Generated by Code Simplifier ·

  • expires on Mar 22, 2026, 7:02 PM UTC

- Import isTruthy from is_truthy.cjs instead of duplicating it locally
- Add require('./shim.cjs') to ensure core is always available
- Remove all 'if (typeof core !== "undefined")' guards (unnecessary with shim)
- Simplify main() by removing verbose ASCII separators and redundant logging
- Remove unused ERR_VALIDATION import
- Update test to import isTruthy from is_truthy.cjs and remove duplicate isTruthy tests (already covered by is_truthy.test.cjs)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review March 21, 2026 19:03
CopilotAI review requested due to automatic review settings March 21, 2026 19:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors render_template.cjs to rely on the shared isTruthy helper and a common shim.cjs-based globals setup, reducing duplicated logic and noisy logging while keeping the rendering behavior the same.

Changes:

  • Replaced the local isTruthy implementation in render_template.cjs with an import from is_truthy.cjs and added shim.cjs initialization.
  • Simplified render_template.cjs logging by removing verbose/debug-only output and typeof core guards.
  • Updated render_template.test.cjs to remove the inlined isTruthy extraction/tests and use the shared helper.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

FileDescription
actions/setup/js/render_template.cjsImports shared isTruthy, initializes core via shim, and streamlines logging in template rendering + main flow.
actions/setup/js/render_template.test.cjsRemoves duplicate isTruthy testing/extraction and aligns the test with the shared helper usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +13
const { isTruthy } = require("./is_truthy.cjs"),
renderTemplateScript = fs.readFileSync(path.join(__dirname, "render_template.cjs"), "utf8"),
renderMarkdownTemplateMatch = renderTemplateScript.match(/function renderMarkdownTemplate\(markdown\)\s*{[\s\S]*?return result;[\s\S]*?}/);
if (!isTruthyMatch || !renderMarkdownTemplateMatch) throw new Error("Could not extract functions from render_template.cjs");
const isTruthy = eval(`(${isTruthyMatch[0]})`),
renderMarkdownTemplate = eval(`(${renderMarkdownTemplateMatch[0]})`);
(describe("isTruthy", () => {
(it("should return false for empty string", () => {
expect(isTruthy("")).toBe(!1);
if (!renderMarkdownTemplateMatch) throw new Error("Could not extract renderMarkdownTemplate function from render_template.cjs");
const renderMarkdownTemplate = eval(`(${renderMarkdownTemplateMatch[0]})`);

CopilotAIMar 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test still reads render_template.cjs as text and evals the extracted renderMarkdownTemplate, which means it does not exercise the real module loading path (including the new require("./is_truthy.cjs") and require("./shim.cjs")). A broken import path or runtime require error in render_template.cjs would not be caught by this test. Consider requiring ./render_template.cjs directly and using the exported renderMarkdownTemplate so the test validates the actual runtime wiring.

See below for a potential fix:

 { renderMarkdownTemplate } = require("./render_template.cjs");

Copilot uses AI. Check for mistakes.
@pelikhan
pelikhan merged commit 3712130 into mainMar 21, 2026
61 checks passed
@pelikhan
pelikhan deleted the simplify-render-template-cjs-7d4019c44d7c87d7 branch March 21, 2026 19:09
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@pelikhan