Skip to content

fix: validate external prompt-template schema deeply (BA-083) - #737

Merged
MaryammAli merged 2 commits into
BlockDash-Studios:mainfrom
Tim4evar:fix/651-deep-prompt-template-validation
Aug 28, 2026
Merged

fix: validate external prompt-template schema deeply (BA-083)#737
MaryammAli merged 2 commits into
BlockDash-Studios:mainfrom
Tim4evar:fix/651-deep-prompt-template-validation

Conversation

@Tim4evar

@Tim4evar Tim4evar commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

External prompt-template configs are now validated deeply before activation. Previously only top-level field types were checked; malformed templates and invalid versions could slip through.

Issue

Closes #651

Changes

  • schemaVersion and every template version must be valid semver.
  • Template names must match a safe identifier pattern (^[a-zA-Z][a-zA-Z0-9_-]*$).
  • description and systemPrompt must be non-empty (required text).
  • Each template's version array must be non-empty with unique versions (array contents).
  • Nested approval/rollback metadata is structurally validated.
  • Added 8 tests covering schema, name, version format, required text, duplicate versions, and invalid approval/metadata.

Validation

  • npx jest --config jest.config.ts --runInBand src/ai → 35 passed.
  • Note: one pre-existing test in this file (keeps the last valid templates when a later reload is malformed) fails on main already (unrelated; tied to BA-085 — Add prompt-template approval and audit metadata #653 approval gating), so it is not introduced by this PR.

Notes

  • Lint is not run by the BackendAcademy CI workflow; a local ESLint plugin mismatch (@typescript-eslint/eslint-plugin missing) is a pre-existing environment issue and does not affect CI.

Known CI note

The Learner journey & AI tests job is currently red on main for an unrelated reason: src/integration/learner-journey.spec.ts calls new JwtTutorGuard(jwt) but JwtTutorGuard's constructor now requires authSessionService (see src/auth/guards/jwt-tutor.guard.ts:27). This is a pre-existing break in main, not introduced by this PR. The src/ai suite (this PR's scope) passes.

Enforce deep validation of externally supplied prompt templates before activation: schema version and per-template version must be semver, template names must match a safe identifier pattern, required text fields (description, systemPrompt) must be non-empty, version arrays must be non-empty with unique versions, and nested approval/rollback metadata is structurally validated.
@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Tim4evar Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…#653 approval gating

The 'keeps the last valid templates' spec loaded a template with no approval, but getActiveTemplate (added in BlockDash-Studios#653) requires approval.status === 'approved', so the template was never active and the test failed on main. Adding an approval makes it active under current behaviour and turns the CI (src/ai) green.

@MaryammAli MaryammAli 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.

LGTM

@MaryammAli
MaryammAli merged commit 058bd60 into BlockDash-Studios:main Aug 28, 2026
1 of 2 checks passed
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.

BA-083 — Validate external prompt-template schema deeply

2 participants