v2: модульный монолит — очередь, персистентность, безопасность, SSE, тесты
Some checks failed
test / test (push) Failing after 24s
Some checks failed
test / test (push) Failing after 24s
Реализация целевого дизайна (docs/architecture/target-design.md): - src/: модульная структура (config, logger, errors, http, core: auth/history/jobs/engines/comfy/codex/images) - Очередь заданий: FIFO, кониурентность codex=1 / comfy-upscale=2, MAX_QUEUED_JOBS=5, JSONL-журнал и восстановление после рестарта (running → interrupted, upscale requeue) - Персистентные сессии (sha256-хеши токенов), scrypt-хеш пароля, rate-limit входа, Origin-проверка, magic-byte валидация аплоадов - Атомарная запись манифеста истории, каскадное удаление, URL с фактическим расширением + 302-алиас /image.jpg, миграция history/ → data/history - Даунскейл sharp до 1024px перед Codex + масштабирование области референса - SSE /api/events с фолбэком на polling, фронтенд переведён на ES-модули (public/js/) - Тесты node:test + supertest (27), CI workflow test.yml, Docker/деплой: том kadr-data - Документация: README, docs/architecture/
This commit is contained in:
72
test/prompts.test.js
Normal file
72
test/prompts.test.js
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
const { test, describe } = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const {
|
||||
buildEditPrompt,
|
||||
buildSuggestPrompt,
|
||||
parseSuggestions,
|
||||
parseRegion,
|
||||
scaleRegion,
|
||||
} = require("../src/core/codex/prompts");
|
||||
const { AppError } = require("../src/errors");
|
||||
|
||||
describe("prompts", () => {
|
||||
test("buildEditPrompt builds basic edit prompt", () => {
|
||||
const prompt = buildEditPrompt({
|
||||
prompt: "Сделай закатный свет",
|
||||
dimensions: { width: 1024, height: 768 },
|
||||
inputName: "input.jpg",
|
||||
});
|
||||
|
||||
assert.ok(prompt.includes("Перед тобой фотография input.jpg. Примени к ней следующее редактирование: «Сделай закатный свет»."));
|
||||
assert.ok(prompt.includes("Сохрани отредактированное фото в файл output.jpg"));
|
||||
assert.ok(prompt.includes("Сохрани исходный размер 1024×768."));
|
||||
});
|
||||
|
||||
test("buildEditPrompt includes reference, region and downscaled notes", () => {
|
||||
const prompt = buildEditPrompt({
|
||||
prompt: "Замени фон",
|
||||
dimensions: { width: 800, height: 600 },
|
||||
inputName: "input.jpg",
|
||||
referenceName: "reference.jpg",
|
||||
region: { x: 10, y: 20, w: 100, h: 200 },
|
||||
downscaled: true,
|
||||
});
|
||||
|
||||
assert.ok(prompt.includes("вспомогательное изображение reference.jpg"));
|
||||
assert.ok(prompt.includes("Координаты области на reference.jpg: x=10, y=20, ширина=100, высота=200"));
|
||||
assert.ok(prompt.includes("Исходное фото уменьшено для скорости обработки."));
|
||||
assert.ok(prompt.includes("Сохрани исходный размер 800×600."));
|
||||
});
|
||||
|
||||
test("parseSuggestions extracts up to 3 clean suggestions", () => {
|
||||
const raw = `
|
||||
1. Сделай теплый закатный свет
|
||||
2. Добавь легкий туман на заднем плане
|
||||
* Стилизуй под винтажное фото
|
||||
4. Четвертый вариант, который должен быть отброшен
|
||||
`;
|
||||
const parsed = parseSuggestions(raw);
|
||||
assert.equal(parsed.length, 3);
|
||||
assert.equal(parsed[0], "Сделай теплый закатный свет");
|
||||
assert.equal(parsed[1], "Добавь легкий туман на заднем плане");
|
||||
assert.equal(parsed[2], "Стилизуй под винтажное фото");
|
||||
});
|
||||
|
||||
test("parseRegion validates and parses region format", () => {
|
||||
assert.equal(parseRegion(null), null);
|
||||
assert.equal(parseRegion(""), null);
|
||||
|
||||
const fromObj = parseRegion({ x: 10.4, y: 20.8, w: 50, h: 60 });
|
||||
assert.deepEqual(fromObj, { x: 10, y: 21, w: 50, h: 60 });
|
||||
|
||||
const fromStr = parseRegion(JSON.stringify({ x: 0, y: 0, w: 100, h: 100 }));
|
||||
assert.deepEqual(fromStr, { x: 0, y: 0, w: 100, h: 100 });
|
||||
|
||||
// Invalid coordinates
|
||||
assert.throws(() => parseRegion({ x: -5, y: 0, w: 10, h: 10 }), (err) => err instanceof AppError);
|
||||
assert.throws(() => parseRegion({ x: 0, y: 0, w: 0, h: 10 }), (err) => err instanceof AppError);
|
||||
assert.throws(() => parseRegion("invalid-json"), (err) => err instanceof AppError);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user