Skip to content

fix(freshness): bundle-fallback for renderDirectivesAsText import (unblocks CI + CF runtime) - #3029

Merged
jung-thomas merged 1 commit into
DEVfrom
fix/freshness-directives-bundle
Nov 6, 2026
Merged

jung-thomas merged 1 commit into
DEVfrom
fix/freshness-directives-bundle

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

What & why

Fixes a runtime-import bug introduced by the directive-grammar foundation (#3021) that is currently failing the unit CI job on every open fan-out PR (#3024–#3028) and would also break at CF runtime.

srv/lib/freshness-detector.js statically imported ../../scripts/parsers/directives.js for renderDirectivesAsText. Only directives.ts exists on disk, so:

  1. CI/test: test/unit/freshness-actions.test.js boots a real CAP HTTP server; Node's native ESM loader resolves the static import outside Vitest's transform and throws ERR_MODULE_NOT_FOUND. This landed on DEV with feat(directives): generic tutorial directive grammar foundation (openspec: tutorial-directive-grammar) #3021 and every PR's merge-ref CI inherits it.
  2. CF runtime: cds build --production copies only srv/ into gen/srv/ — scripts/parsers/ is never included, so the import would fail in production too.

Fix

Adopts the repo's existing workspace-first / bundle-fallback pattern (same as srv/lib/tutorial-step-slicer.js):

  • scripts/bundle-shared.cjs — add a parsers.bundle.mjs target (direct file-path entry, since scripts/parsers isn't a workspace package) to the main targets array only → srv/lib/_shared/parsers.bundle.mjs. (Not added to QA/MCP target arrays — freshness-detector.js is only used by the srv app.)
  • srv/lib/freshness-detector.js — replace the static top-level import with a lazy await import() inside the already-async detectFreshness(): try the workspace ../../scripts/parsers/directives.js (resolves in dev/test), catch to ./_shared/parsers.bundle.mjs (generated at build, present in gen/srv/ on CF).

The generated bundle is not committed — srv/lib/_shared/ is gitignored and prebuild:shared-bundle regenerates it before cds build (same as the existing *.bundle.mjs). Verified: prebuild → prebuild:shared-bundle fires before build:cds.

How tested

  • npx vitest run test/unit/freshness-actions.test.js → 3/3 pass
  • npx vitest run test/unit/freshness-detector.test.js → 3/3 pass
  • Verified prebuild:shared-bundle runs in the CF build chain before cds build --production, so parsers.bundle.mjs exists in gen/srv/srv/lib/_shared/ at runtime.
  • Both edited files LF-clean.

Type of change

  • Bug fix

Deploy scope

  • Backend only (srv/**, scripts/**) — no content, no UI.

Notes for reviewers

Checklist

  • Branched from DEV
  • No secrets committed
  • cds.ql/CQL only (no raw SQL) — n/a, no DB change

…blocks CI + CF runtime)

- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant