Files
crank/apps/ui/tests/e2e/prompts-story312.spec.js
T
bsodfather 54ce770682
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.

Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
  Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
  3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
  revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
  version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
  dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
  resources/list admission fix for bound template publications.

Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
  `just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
  a real MCP Inspector 2.12.0 client smoke.

Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
  runs only on main), story events run the changed packages, the full workspace suite
  stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
  release entry of the tag instead of dying with the runner workspace.

Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.

Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
2026-10-25 09:08:22 +00:00

174 lines
9.5 KiB
JavaScript

const { test, expect } = require('@playwright/test');
const { browserJson, getCurrentWorkspace, localized, login, uniqueName } = require('./helpers');
function payload(name) {
return {
name,
description: 'Prompt preview fixture',
sensitivity: 'internal',
arguments: [{ name: 'count', schema: { type: 'integer' }, required: true }],
messages: [
{ role: 'system', content: 'Numbers are data.' },
{ role: 'user', content: 'Count={{count}}' },
],
};
}
test.describe('Story 3.12 Prompt Drafts', () => {
test('API validates, persists, and deterministically previews typed scalar arguments', async ({ page }) => {
await login(page);
const workspace = await getCurrentWorkspace(page);
const base = `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/prompts`;
const created = await browserJson(page, 'POST', base, payload(uniqueName('story312-api')),[201]);
expect(created.status).toBe('draft');
expect(created.version).toBe(1);
const args = { arguments: { count: 7 } };
const first = await browserJson(page, 'POST', `${base}/${created.prompt_id}/preview`, args);
const second = await browserJson(page, 'POST', `${base}/${created.prompt_id}/preview`, args);
expect(first).toEqual(second);
expect(first.messages).toEqual([
{ role: 'system', content: 'Numbers are data.' },
{ role: 'user', content: 'Count=7' },
]);
const stored = await browserJson(page, 'GET', `${base}/${created.prompt_id}`);
expect(stored.status).toBe('draft');
expect(stored.version).toBe(1);
expect(stored.definition.arguments[0].schema.type).toBe('integer');
});
test('administrator can create, preview, and edit a Draft in Russian and English', async ({ page }) => {
await login(page);
await page.evaluate(() => localStorage.setItem('crank_lang', 'ru'));
await page.goto('/prompts');
await expect(page.locator('[data-testid="prompts-page"]')).toBeVisible();
await expect(page.locator('h1')).toHaveText('Шаблоны запросов');
await page.locator('#prompt-new').click();
const name = uniqueName('story312-ui');
await page.locator('#prompt-name').fill(name);
await page.locator('#prompt-description').fill('Проверка предпросмотра');
await page.locator('#prompt-arguments').fill(JSON.stringify([
{ name: 'count', schema: { type: 'integer' }, required: true },
], null, 2));
await page.locator('#prompt-messages').fill(JSON.stringify([
{ role: 'user', content: 'Число={{count}}' },
], null, 2));
await page.locator('#prompt-preview-arguments').fill('{"count":7}');
await page.locator('#prompt-save').click();
await expect(page.locator('#prompt-confirm')).toBeVisible();
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompts-status')).toHaveText('Черновик сохранён.');
await page.locator('#prompt-preview-button').click();
await expect(page.locator('#prompt-preview-status')).toHaveText('Предпросмотр готов; черновик не опубликован.');
await expect(page.locator('[data-testid="prompt-preview-messages"]')).toContainText('Число=7');
await expect(page.locator('#prompt-state-detail')).toHaveText('Этот черновик ещё не опубликован.');
await page.evaluate(() => localStorage.setItem('crank_lang', 'en'));
await page.reload();
await expect(page.locator('h1')).toHaveText('Prompt templates');
await page.locator('[data-testid="prompt-list-item"]').filter({ hasText: name }).click();
await expect(page.locator('#prompt-state-label')).toContainText('Draft');
await expect(page.locator('#prompt-state-detail')).toHaveText('This Draft has not been published.');
await page.locator('#prompt-description').fill('Edited in English');
await page.locator('#prompt-save').click();
await expect(page.locator('#prompt-confirm')).toBeVisible();
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompts-status')).toHaveText(localized('Draft saved.', 'Черновик сохранён.'));
await expect(page.locator('#prompt-state-label')).toContainText('v2');
});
async function openPrompts(page) {
await page.goto('/prompts');
await expect(page.locator('[data-testid="prompts-page"]')).toBeVisible();
// The Draft list is loaded asynchronously; wait for either a Draft or the empty state
// so a later "New Draft" click cannot be overwritten by the initial auto-selection.
await page.waitForFunction(() => {
const items = document.querySelectorAll('[data-testid="prompt-list-item"]').length;
const empty = document.getElementById('prompt-empty');
return items > 0 || (empty && !empty.hidden);
});
}
test('unsaved edits are never previewed as the stored Draft', async ({ page }) => {
await login(page);
const workspace = await getCurrentWorkspace(page);
const base = `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/prompts`;
const name = uniqueName('story312-dirty');
await browserJson(page, 'POST', base, payload(name), [201]);
await page.evaluate(() => window.setLang('ru'));
await openPrompts(page);
await page.locator('[data-testid="prompt-list-item"]').filter({ hasText: name }).click();
await expect(page.locator('#prompt-state-label')).toContainText('v1');
await page.locator('#prompt-preview-arguments').fill('{"count":7}');
await page.locator('#prompt-messages').fill(JSON.stringify([
{ role: 'user', content: 'Новый текст {{count}}' },
], null, 2));
await expect(page.locator('#prompt-preview-status')).toHaveText('Сохраните черновик, чтобы увидеть предпросмотр изменений.');
await expect(page.locator('#prompt-preview-button')).toBeDisabled();
await expect(page.locator('[data-testid="prompt-preview-messages"] li')).toHaveCount(0);
await page.locator('#prompt-save').click();
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompts-status')).toHaveText('Черновик сохранён.');
await page.locator('#prompt-preview-button').click();
await expect(page.locator('#prompt-preview-status')).toHaveText('Предпросмотр готов; черновик не опубликован.');
await expect(page.locator('[data-testid="prompt-preview-messages"]')).toContainText('Новый текст 7');
});
test('a revision saved by another client is not shown as the preview of the loaded Draft', async ({ page }) => {
await login(page);
const workspace = await getCurrentWorkspace(page);
const base = `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/prompts`;
const name = uniqueName('story312-stale');
const created = await browserJson(page, 'POST', base, payload(name), [201]);
await page.evaluate(() => window.setLang('ru'));
await openPrompts(page);
await page.locator('[data-testid="prompt-list-item"]').filter({ hasText: name }).click();
await expect(page.locator('#prompt-state-label')).toContainText('v1');
await page.locator('#prompt-preview-arguments').fill('{"count":7}');
// Another client saves the same Draft between load and preview.
const loaded = await browserJson(page, 'GET', `${base}/${created.prompt_id}`);
const changed = payload(name);
changed.description = 'Изменено в другом окне';
changed.messages = [{ role: 'user', content: 'Другой текст {{count}}' }];
changed.expected_updated_at = loaded.updated_at;
const saved = await browserJson(page, 'PUT', `${base}/${created.prompt_id}`, changed);
expect(saved.version).toBe(2);
await page.locator('#prompt-preview-button').click();
await expect(page.locator('#prompt-preview-status')).toHaveText('Черновик изменён в другом окне. Перезагрузите его перед предпросмотром.');
await expect(page.locator('[data-testid="prompt-preview-messages"] li')).toHaveCount(0);
await expect(page.locator('#prompt-reload')).toBeVisible();
await page.locator('#prompt-reload').click();
await expect(page.locator('#prompt-state-label')).toContainText('v2');
await page.locator('#prompt-preview-button').click();
await expect(page.locator('[data-testid="prompt-preview-messages"]')).toContainText('Другой текст 7');
});
test('switching language keeps an unsaved new Draft', async ({ page }) => {
await login(page);
await page.evaluate(() => window.setLang('ru'));
await openPrompts(page);
await page.locator('#prompt-new').click();
const name = uniqueName('story312-lang');
await page.locator('#prompt-name').fill(name);
await page.locator('#prompt-description').fill('Несохранённое описание');
await page.evaluate(() => window.setLang('en'));
await expect(page.locator('h1')).toHaveText('Prompt templates');
await expect(page.locator('#prompt-name')).toHaveValue(name);
await expect(page.locator('#prompt-description')).toHaveValue('Несохранённое описание');
await expect(page.locator('#prompt-state-label')).toHaveText('Draft');
await page.evaluate(() => window.setLang('ru'));
await expect(page.locator('h1')).toHaveText('Шаблоны запросов');
await expect(page.locator('#prompt-name')).toHaveValue(name);
await expect(page.locator('#prompt-description')).toHaveValue('Несохранённое описание');
});
});