* refactor(pbl): retire v1 write path and dead UI (#1058) Remove the legacy generator, renderer branches, chat API, and compatibility mirror writes. Keep stored v1 scenes readable through documented legacy adapters, and surface ordinary PBL planner double failures instead of degrading. * fix(pbl): contain planner failure to the scene, support legacy scenes in action regeneration, tighten legacy guards - Contain typed planner failures per scene while preserving retry and skip behavior. - Upgrade legacy PBL content before regenerating scene actions. - Apply video-export import boundaries to legacy readers. - Harden legacy rendering and empty-state handling. - Restore legacy upgrade compatibility coverage. - Remove retired translations and refresh fallback narration and legacy cover documentation. * fix(pbl): keep tolerant legacy configs renderable, guard invalid chat timestamps * chore(dsl): bump to 0.6.3 for README accuracy fix The README no longer references the deleted PBLProjectConfig symbol; the version gate requires a bump for any publishable package input change. * fix(pbl): harden legacy upgrade and persistence contract * fix(pbl): align action prompt with v2 workflow and validate project containers * fix(i18n): remove retired PBL v1 keys from the new fr-FR locale The fr-FR locale landed on main after this branch removed the v1 UI key families; prune the same 38 keys so all 10 locales align with en-US. * fix(generation): sync packaged pbl-actions template with the v2 wording The generation package that landed on main carries a byte-identical copy of the app's pbl-actions template; sync the v2 rewording and bump the package version. * fix(pbl): normalize legacy content and preserve planner status * fix(pbl): propagate provider status and ground action prompts * fix(pbl): classify planner failures for retry, default the project summary prompt input * fix(pbl): fall back to legacy data when v2 payloads are damaged, harden summary building * refactor(pbl): resolve hybrid content through a validity-aware resolver * fix(pbl): keep one v2 acceptance criterion across validator, resolver and persistence Persistence gates on the same container predicate as the validator and the renderer's resolver: payloads the renderer will not treat as v2 are inert bytes everywhere, avoiding runtime side effects for documents the write barrier would reject. An explicit null proficiencyAssessment stays processable. * fix(pbl): require runnable projects and harden legacy fallback * test(pbl): exercise the real save reload and hydration chain * fix(pbl): require an instructor and usable microtasks before v2 takes precedence * fix(pbl): fall back to the loop planner unless the provider failed or the user cancelled * fix(pbl): require role and task identities before v2 takes precedence Runtime normalization can repair status and create the instructor thread, but it cannot synthesize the role id that binds the thread, the microtask ids used by lookup and update paths, or the labels the workspace renders. The runnable predicate and its video-export mirror now require them, so identity-less payloads fall back to usable legacy data.
134 lines
4.7 KiB
TypeScript
134 lines
4.7 KiB
TypeScript
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
import { describe, expect, test } from 'vitest';
|
|
import {
|
|
PROMPT_IDS,
|
|
buildPrompt,
|
|
interpolateVariables,
|
|
loadPrompt,
|
|
processConditionalBlocks,
|
|
processSnippets,
|
|
} from '@openmaic/generation';
|
|
|
|
function createPromptsFixture(): string {
|
|
const promptsDir = mkdtempSync(join(tmpdir(), 'openmaic-generation-prompts-'));
|
|
mkdirSync(join(promptsDir, 'snippets'));
|
|
mkdirSync(join(promptsDir, 'templates'));
|
|
return promptsDir;
|
|
}
|
|
|
|
describe('loader semantics', () => {
|
|
test('loads and interpolates a known prompt', () => {
|
|
const result = buildPrompt(PROMPT_IDS.SLIDE_ACTIONS, {
|
|
title: 'Test Slide',
|
|
keyPoints: '1. point one',
|
|
description: 'desc',
|
|
elements: '[]',
|
|
courseContext: '',
|
|
agents: '',
|
|
userProfile: '',
|
|
languageDirective: 'en',
|
|
});
|
|
|
|
expect(result).not.toBeNull();
|
|
expect(result!.system.length).toBeGreaterThan(100);
|
|
expect(result!.user).toContain('Test Slide');
|
|
});
|
|
|
|
test('defaults the project summary for the previous pbl-actions variable set', () => {
|
|
const result = buildPrompt(PROMPT_IDS.PBL_ACTIONS, {
|
|
title: 'Resilient Systems',
|
|
projectTopic: 'Retry handling',
|
|
projectDescription: 'Practice resilient generation',
|
|
keyPoints: '1. Classify failures',
|
|
description: 'Build a retry-aware workflow',
|
|
courseContext: '',
|
|
agents: '',
|
|
languageDirective: 'en',
|
|
});
|
|
|
|
expect(result).not.toBeNull();
|
|
expect(result!.system).toContain(
|
|
'(No generated milestones are available; introduce the project topic without inventing any.)',
|
|
);
|
|
expect(`${result!.system}\n${result!.user}`).not.toMatch(/\{\{\w[\w-]*\}\}/);
|
|
});
|
|
|
|
test('inlines a snippet exactly once', () => {
|
|
const promptsDir = createPromptsFixture();
|
|
writeFileSync(join(promptsDir, 'snippets', 'example.md'), 'inlined content\n');
|
|
|
|
expect(processSnippets('Before {{snippet:example}} after', promptsDir)).toBe(
|
|
'Before inlined content after',
|
|
);
|
|
});
|
|
|
|
test('returns null for an unknown prompt', () => {
|
|
// @ts-expect-error -- exercise the runtime failure path.
|
|
expect(loadPrompt('does-not-exist')).toBeNull();
|
|
});
|
|
|
|
test('throws when a referenced snippet is missing', () => {
|
|
expect(() => processSnippets('{{snippet:does-not-exist}}')).toThrow(/Snippet not found/);
|
|
});
|
|
|
|
test('does not recursively process snippet markers inside snippets', () => {
|
|
const promptsDir = createPromptsFixture();
|
|
writeFileSync(join(promptsDir, 'snippets', 'outer.md'), 'outer {{snippet:inner}}\n');
|
|
writeFileSync(join(promptsDir, 'snippets', 'inner.md'), 'inner\n');
|
|
|
|
expect(processSnippets('{{snippet:outer}}', promptsDir)).toBe('outer {{snippet:inner}}');
|
|
});
|
|
|
|
test('propagates a missing snippet referenced by user.md', () => {
|
|
const promptsDir = createPromptsFixture();
|
|
const promptDir = join(promptsDir, 'templates', 'fixture');
|
|
mkdirSync(promptDir);
|
|
writeFileSync(join(promptDir, 'system.md'), 'system prompt\n');
|
|
writeFileSync(join(promptDir, 'user.md'), '{{snippet:not-packaged}}\n');
|
|
|
|
// @ts-expect-error -- fixture is intentionally outside the public PromptId union.
|
|
expect(() => loadPrompt('fixture', promptsDir)).toThrow(/Snippet not found: not-packaged/);
|
|
});
|
|
|
|
test('keeps conditional content when its condition is truthy', () => {
|
|
expect(processConditionalBlocks('A {{#if enabled}}kept{{/if}} B', { enabled: true })).toBe(
|
|
'A kept B',
|
|
);
|
|
});
|
|
|
|
test('drops conditional content when its condition is falsey', () => {
|
|
expect(processConditionalBlocks('A {{#if enabled}}dropped{{/if}} B', { enabled: false })).toBe(
|
|
'A B',
|
|
);
|
|
});
|
|
|
|
test('does not recursively process nested conditional blocks', () => {
|
|
const template = '{{#if outer}}outer {{#if inner}}inner{{/if}}{{/if}}';
|
|
expect(processConditionalBlocks(template, { outer: true, inner: true })).toBe(
|
|
'outer {{#if inner}}inner{{/if}}',
|
|
);
|
|
});
|
|
|
|
test('interpolates string variables', () => {
|
|
expect(interpolateVariables('Hello {{name}}', { name: 'Ada' })).toBe('Hello Ada');
|
|
});
|
|
|
|
test('interpolates object variables as two-space JSON', () => {
|
|
expect(interpolateVariables('{{payload}}', { payload: { nested: true } })).toBe(
|
|
'{\n "nested": true\n}',
|
|
);
|
|
});
|
|
|
|
test('preserves placeholders whose variable is undefined', () => {
|
|
expect(interpolateVariables('{{missing}}', { missing: undefined })).toBe('{{missing}}');
|
|
});
|
|
|
|
test('leaves kebab-case placeholders untouched', () => {
|
|
expect(interpolateVariables('{{next-agent}}', { 'next-agent': 'ignored' })).toBe(
|
|
'{{next-agent}}',
|
|
);
|
|
});
|
|
});
|