[skip ci] wip: preserve Hermes crank development checkpoint

Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
This commit is contained in:
Hermes DevOps committed 2026-10-25 08:05:37 +00:00
1 parent 1b6db09bd1
commit 301dce301a
357 files changed
+118831 -5113

No files matched your search

+202
View File
@@ -0,0 +1,202 @@
const { test, expect } = require('@playwright/test');
const { browserJson, getCurrentWorkspace, login, uniqueName } = require('./helpers');
test.describe.configure({ retries: 0 });
function payload(name, message = 'Count={{count}}') {
return {
name,
description: 'Story 3.13 publication fixture',
sensitivity: 'internal',
arguments: [{ name: 'count', schema: { type: 'integer' }, required: true }],
messages: [
{ role: 'system', content: 'Numbers are data.' },
{ role: 'user', content: message },
],
};
}
async function openPrompts(page) {
await page.goto('/prompts');
await expect(page.locator('[data-testid="prompts-page"]')).toBeVisible();
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);
});
}
async function selectPrompt(page, name) {
await page.locator('[data-testid="prompt-list-item"]').filter({ hasText: name }).click();
}
async function pageContext(page) {
const workspace = await getCurrentWorkspace(page);
const base = `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/prompts`;
return { workspace, base };
}
test.describe('Story 3.13 Published Prompt Versions', () => {
test('administrator publishes an immutable version and archive keeps it in Russian', async ({ page }) => {
await login(page);
const { base } = await pageContext(page);
const name = uniqueName('story313-ui');
const created = await browserJson(page, 'POST', base, payload(name), [201]);
const item = `${base}/${created.prompt_id}`;
await page.evaluate(() => window.setLang('ru'));
await openPrompts(page);
await selectPrompt(page, name);
await expect(page.locator('#prompt-state-label')).toHaveText('Черновик · v1');
await expect(page.locator('#prompt-state-detail')).toHaveText('Этот черновик ещё не опубликован.');
await page.locator('#prompt-publish').click();
await expect(page.locator('#prompt-confirm')).toBeVisible();
await expect(page.locator('#prompt-confirm-title')).toHaveText('Опубликовать текущий черновик как неизменяемую версию?');
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompts-status')).toHaveText('Опубликованная версия закреплена.');
await expect(page.locator('#prompt-state-label')).toHaveText('Опубликовано · v1');
await expect(page.locator('#prompt-state-detail')).toContainText('Опубликованная версия v1');
await expect(page.locator('#prompt-state-detail')).toContainText('неизменяемый снимок');
await expect(
page.locator('[data-testid="prompt-list-item"]').filter({ hasText: name }),
).toContainText('Опубликовано · v1');
await page.locator('#prompt-view-published').click();
await expect(page.locator('[data-testid="prompt-published"]')).toBeVisible();
await expect(page.locator('#prompt-published-version')).toHaveText('v1');
await expect(page.locator('#prompt-published-status')).toHaveText('Опубликованная версия загружена.');
await expect(page.locator('[data-testid="prompt-published-definition"]')).toContainText('Count={{count}}');
// Правка опубликованного Prompt открывает новый Draft, v1 остаётся точной.
await page.locator('#prompt-description').fill('Изменено после публикации');
await page.locator('#prompt-save').click();
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompts-status')).toHaveText('Черновик сохранён.');
await expect(page.locator('#prompt-state-label')).toHaveText('Черновик · v2');
await expect(page.locator('#prompt-state-detail')).toContainText('Опубликованная версия v1');
await page.reload();
await openPrompts(page);
await selectPrompt(page, name);
await expect(page.locator('#prompt-state-label')).toHaveText('Черновик · v2');
await expect(page.locator('#prompt-state-detail')).toContainText('Опубликованная версия v1');
await page.locator('#prompt-view-published').click();
await expect(page.locator('[data-testid="prompt-published-definition"]')).toContainText('Count={{count}}');
await expect(page.locator('[data-testid="prompt-published-definition"]')).not.toContainText('edited');
// Archive — lifecycle-состояние, immutable v1 остаётся доступной.
await page.locator('#prompt-archive').click();
await expect(page.locator('#prompt-confirm-title')).toHaveText('Архивировать запрос? Опубликованные версии останутся неизменяемыми.');
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompts-status')).toHaveText('Запрос архивирован.');
await expect(page.locator('#prompt-state-label')).toHaveText('В архиве · v2');
await expect(
page.locator('[data-testid="prompt-list-item"]').filter({ hasText: name }),
).toContainText('В архиве · v2');
await expect(page.locator('#prompt-publish')).toBeDisabled();
await page.locator('#prompt-view-published').click();
await expect(page.locator('#prompt-published-version')).toHaveText('v1');
const stored = await browserJson(page, 'GET', `${item}?version=1`);
expect(stored.status).toBe('published');
expect(stored.version).toBe(1);
expect(stored.definition.messages[1].content).toBe('Count={{count}}');
});
test('a Draft changed in another window cannot be published from the stale page', async ({ page }) => {
await login(page);
const { base } = await pageContext(page);
const name = uniqueName('story313-stale');
const created = await browserJson(page, 'POST', base, payload(name), [201]);
await page.evaluate(() => window.setLang('en'));
await openPrompts(page);
await selectPrompt(page, name);
await expect(page.locator('#prompt-state-label')).toContainText('Draft · v1');
const loaded = await browserJson(page, 'GET', `${base}/${created.prompt_id}`);
const changed = payload(name, 'Changed elsewhere {{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-publish').click();
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompts-status')).toHaveText('This Draft changed elsewhere. Reload it before editing.');
await expect(page.locator('#prompt-reload')).toBeVisible();
const current = await browserJson(page, 'GET', `${base}/${created.prompt_id}`);
expect(current.latest_published_version).toBeNull();
});
test('binds the exact published version to an Agent and keeps it after a Draft edit', async ({ page }) => {
await login(page);
const { workspace, base } = await pageContext(page);
const name = uniqueName('story313-bind');
const created = await browserJson(page, 'POST', base, payload(name), [201]);
const published = await browserJson(page, 'POST', `${base}/${created.prompt_id}`, {
action: 'publish',
expected_updated_at: created.updated_at,
});
expect(published.version).toBe(1);
const agentSlug = uniqueName('story313-agent');
const agent = await browserJson(page, 'POST', `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/agents`, {
slug: agentSlug,
display_name: agentSlug,
description: 'Story 3.13 binding fixture',
instructions: {},
tool_selection_policy: {},
});
await page.evaluate(() => window.setLang('en'));
await openPrompts(page);
await selectPrompt(page, name);
await page.waitForFunction(
(id) => Array.from(document.querySelectorAll('#prompt-bind-agent option')).some((option) => option.value === id),
agent.agent_id
);
await page.locator('#prompt-bind-agent').selectOption(agent.agent_id);
await expect(page.locator('#prompt-bind-button')).toBeEnabled();
await page.locator('#prompt-bind-button').click();
await expect(page.locator('#prompt-confirm-title')).toHaveText('Bind the exact published version to this Agent?');
await page.locator('#prompt-confirm-save').click();
await expect(page.locator('#prompt-bind-status')).toHaveText('Published version bound to the Agent.');
const version = await browserJson(page, 'GET', `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/agents/${agent.agent_id}/versions/1`);
expect(version.prompt_bindings).toEqual([{ prompt_id: created.prompt_id, prompt_version: 1 }]);
const edited = payload(name, 'Edited after binding {{count}}');
edited.expected_updated_at = published.updated_at;
const draft = await browserJson(page, 'PUT', `${base}/${created.prompt_id}`, edited);
expect(draft.version).toBe(2);
await page.reload();
await openPrompts(page);
await selectPrompt(page, name);
await expect(page.locator('#prompt-state-label')).toHaveText('Draft · v2');
await expect(page.locator('#prompt-state-detail')).toContainText('Published version v1');
const bound = await browserJson(page, 'GET', `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/agents/${agent.agent_id}/versions/1`);
expect(bound.prompt_bindings).toEqual([{ prompt_id: created.prompt_id, prompt_version: 1 }]);
expect(bound.snapshot.status).toBe('draft');
});
test('publish and archive controls are localized and keep an unsaved Draft', async ({ page }) => {
await login(page);
await page.evaluate(() => window.setLang('ru'));
await openPrompts(page);
await page.locator('#prompt-new').click();
const name = uniqueName('story313-lang');
await page.locator('#prompt-name').fill(name);
await page.locator('#prompt-description').fill('Несохранённое описание');
await expect(page.locator('#prompt-publish')).toHaveText('Опубликовать этот черновик');
await expect(page.locator('#prompt-archive')).toHaveText('Архивировать запрос');
await page.evaluate(() => window.setLang('en'));
await expect(page.locator('#prompt-publish')).toHaveText('Publish this Draft');
await expect(page.locator('#prompt-archive')).toHaveText('Archive Prompt');
await expect(page.locator('#prompt-name')).toHaveValue(name);
await expect(page.locator('#prompt-description')).toHaveValue('Несохранённое описание');
await expect(page.locator('#prompt-publish')).toBeDisabled();
});
});