forked from r.muellner/velum-raycast
Analyze UTF-8 text files as bounded batches of complete lines and reassemble only approved spans without loading entire files. Preserve line endings, BOM, Unicode offsets and source-change checks. Scope capability checks to selected file types, report missing features and HTTP failures, and retain the required Office image-policy handling. Cover large files, chunk boundaries, mappings and failure cleanup with regression tests.
43 lines
2.7 KiB
TypeScript
43 lines
2.7 KiB
TypeScript
import { expect, it } from "bun:test";
|
|
import { checkProjectCapabilities, requiredProjectCapabilities } from "../src/lib/project-capabilities";
|
|
const url = "https://velum.invalid/api/project-capabilities";
|
|
const reply = (value: unknown) => async () => Response.json(value);
|
|
it("reproduziert die alte Meldung: Textprojekt benötigt keine Office-Fähigkeiten", async () => {
|
|
const olderBackend = { request_force_masks: true, document_hit_review: true, document_restoration: true };
|
|
await checkProjectCapabilities(url, false, reply(olderBackend));
|
|
await expect(checkProjectCapabilities(url, true, reply(olderBackend))).rejects.toThrow("document_review_mapping");
|
|
});
|
|
it("prüft jede Office-Schutzfunktion strikt, einschließlich Bilder und Autoren", async () => {
|
|
const complete = Object.fromEntries(requiredProjectCapabilities(true).map((key) => [key, true]));
|
|
await checkProjectCapabilities(url, true, reply(complete));
|
|
for (const key of Object.keys(complete)) {
|
|
const missing = { ...complete }; delete missing[key];
|
|
await expect(checkProjectCapabilities(url, true, reply(missing))).rejects.toThrow(key);
|
|
await expect(checkProjectCapabilities(url, true, reply({ ...complete, [key]: "true" }))).rejects.toThrow(key);
|
|
}
|
|
});
|
|
it("unterscheidet fehlende Endpunkte, Anmeldung, Größenlimits und Gateway-Fehler", async () => {
|
|
for (const status of [401, 403, 404, 405, 413, 502, 504]) {
|
|
await expect(checkProjectCapabilities(url, false, async () => new Response("", { status })))
|
|
.rejects.toThrow(`HTTP ${status}`);
|
|
}
|
|
await expect(checkProjectCapabilities(url, false, async () => new Response("Login", {
|
|
headers: { "content-type": "text/html" },
|
|
}))).rejects.toThrow("Keine JSON-Antwort");
|
|
});
|
|
it("meldet URL, fehlende Fähigkeit, ungültige Antwort und Zeitlimit", async () => {
|
|
await expect(checkProjectCapabilities(url, false, reply({}))).rejects.toThrow("request_force_masks");
|
|
for (const value of [null, [], true]) await expect(checkProjectCapabilities(url, false, reply(value)))
|
|
.rejects.toThrow("Ungültige Projektfähigkeiten");
|
|
await expect(checkProjectCapabilities(url, false, async (_url, init) => {
|
|
expect(init.signal).toBeDefined(); throw new DOMException("Deadline", "TimeoutError");
|
|
})).rejects.toThrow("Zeitlimit");
|
|
});
|
|
|
|
it("reproduziert die Live-API vom 8. November ohne document_image_policy", async () => {
|
|
const live = { request_force_masks: true, document_hit_review: true, document_review_mapping: true,
|
|
document_restoration: true, comment_author_review: true, revision_author_review: true };
|
|
await checkProjectCapabilities(url, false, reply(live));
|
|
await expect(checkProjectCapabilities(url, true, reply(live))).rejects.toThrow("document_image_policy");
|
|
});
|