From f12cf2e3691a82fdebd58c8246aa759c2a04d1a9 Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Fri, 6 Nov 2026 01:47:04 -0500 Subject: [PATCH] fix(freshness): bundle-fallback for renderDirectivesAsText import (unblocks CI + CF runtime) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add parsers/directives.ts entry to scripts/bundle-shared.cjs → outputs srv/lib/_shared/parsers.bundle.mjs (gitignored, generated by prebuild:shared-bundle) - Replace static top-level import in srv/lib/freshness-detector.js with a lazy try/catch inside detectFreshness(): workspace path first (dev/CI), _shared/parsers.bundle.mjs fallback (CF runtime where scripts/ is absent) --- scripts/bundle-shared.cjs | 4 ++++ srv/lib/freshness-detector.js | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/bundle-shared.cjs b/scripts/bundle-shared.cjs index 5535116d7..454271676 100644 --- a/scripts/bundle-shared.cjs +++ b/scripts/bundle-shared.cjs @@ -48,6 +48,10 @@ const CHANNELS_CJS = [ ]; const targets = [ + { + entry: path.resolve(__dirname, 'parsers', 'directives.ts'), + out: path.join(outDir, 'parsers.bundle.mjs'), + }, { entry: require.resolve('@tutorials/core'), out: path.join(outDir, 'core.bundle.mjs'), diff --git a/srv/lib/freshness-detector.js b/srv/lib/freshness-detector.js index 4cd9618ea..665273435 100644 --- a/srv/lib/freshness-detector.js +++ b/srv/lib/freshness-detector.js @@ -25,7 +25,6 @@ import { extractCodeBlocks, extractTutorialContext } from './freshness-extract.j import { groundCodeBlock } from './freshness-grounding.js'; import { resolveChatLlmSettings } from './chat-settings-resolver.js'; import { tokensToCents } from './_token-cost.js'; -import { renderDirectivesAsText } from '../../scripts/parsers/directives.js'; const LOG = cds.log('freshness-detector'); const TOOL_NAME = 'submit_freshness_findings'; @@ -286,6 +285,13 @@ export async function detectFreshness({ db, tutorialId }) { // Strip directive syntax (:::details, :kbd[, etc.) so the model sees // plain prose rather than raw CommonMark directive fences. + // Workspace-first / bundle fallback: directives.ts is not compiled to .js; + // the CF deploy copies only srv/ (not scripts/parsers/), so we fall back to + // the pre-built bundle at _shared/parsers.bundle.mjs. + let _directivesMod; + try { _directivesMod = await import('../../scripts/parsers/directives.js'); } + catch { _directivesMod = await import('./_shared/parsers.bundle.mjs'); } + const renderDirectivesAsText = _directivesMod.renderDirectivesAsText; const markdown = renderDirectivesAsText(src.markdown); // Feed whole-tutorial markdown as ONE pseudo-step so extractCodeBlocks