Initial commit of Descrybe v2 without local scratch artifacts.

Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
greeneclipse committed 2026-08-09 22:47:43 +02:00
commit 8580c996c3
1285 files changed
+325780

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
DEFAULT_PAGE_SIZE,
MAX_PAGE_LIMIT,
MAX_OFFSET_WITHOUT_CURSOR,
RECENT_JOBS_LIMIT,
isAbortError,
mapPool,
OFFSET_SAFE_MAX_PAGES,
bookmarkForPage,
preferSequentialPagination,
recordPageBookmark,
resetPageBookmarks,
sequentialNextQuery,
offsetOrNullForPage,
clampPageForOffset,
maxOffsetSafePage
} from "./list.ts";
describe("preferSequentialPagination", () => {
it("always prefers keyset for the products UI (API offset>5000 gate)", () => {
assert.equal(preferSequentialPagination(0, 25), true);
assert.equal(preferSequentialPagination(200, 25), true);
assert.equal(preferSequentialPagination(100_000, 25), true);
assert.equal(OFFSET_SAFE_MAX_PAGES, 0);
assert.equal(MAX_OFFSET_WITHOUT_CURSOR, 5000);
});
});
describe("page bookmarks", () => {
it("records and resolves sequential next bookmarks", () => {
let stack = resetPageBookmarks();
assert.equal(bookmarkForPage(stack, 1), null);
assert.equal(bookmarkForPage(stack, 2), undefined);
const next = sequentialNextQuery("cur-a", null);
assert.ok(next && "cursor" in next);
stack = recordPageBookmark(stack, 2, next);
assert.deepEqual(bookmarkForPage(stack, 2), { cursor: "cur-a" });
stack = recordPageBookmark(stack, 3, { after_id: "id-b" });
assert.deepEqual(bookmarkForPage(stack, 3), { after_id: "id-b" });
stack = recordPageBookmark(stack, 2, next);
assert.equal(stack.length, 2);
assert.equal(bookmarkForPage(stack, 3), undefined);
});
});
describe("perf helpers", () => {
it("uses a tight default page size under the API max", () => {
assert.equal(DEFAULT_PAGE_SIZE, 25);
assert.ok(DEFAULT_PAGE_SIZE < MAX_PAGE_LIMIT);
assert.equal(RECENT_JOBS_LIMIT, 10);
});
it("isAbortError recognizes AbortError shapes", () => {
assert.equal(isAbortError(new DOMException("Aborted", "AbortError")), true);
assert.equal(isAbortError(Object.assign(new Error("x"), { name: "AbortError" })), true);
assert.equal(isAbortError(new Error("nope")), false);
assert.equal(isAbortError(null), false);
});
it("mapPool respects concurrency and preserves order", async () => {
let active = 0;
let peak = 0;
const out = await mapPool([1, 2, 3, 4, 5], 2, async (n) => {
active += 1;
peak = Math.max(peak, active);
await new Promise((r) => setTimeout(r, 5));
active -= 1;
return n * 10;
});
assert.deepEqual(out, [10, 20, 30, 40, 50]);
assert.ok(peak <= 2);
});
});
describe("offset API gate", () => {
it("mirrors catalog MaxOffsetWithoutCursor and clamps deep pages", () => {
assert.equal(MAX_OFFSET_WITHOUT_CURSOR, 5000);
assert.equal(offsetOrNullForPage(1, 25), 0);
assert.equal(offsetOrNullForPage(201, 25), 5000);
assert.equal(offsetOrNullForPage(202, 25), null);
assert.equal(clampPageForOffset(202, 25), 1);
assert.equal(clampPageForOffset(10, 25), 10);
assert.ok(maxOffsetSafePage(25) >= 201);
});
it("always returns true (products keyset-first)", () => {
assert.equal(preferSequentialPagination(OFFSET_SAFE_MAX_PAGES * 25, 25), true);
assert.equal(preferSequentialPagination(3000, 200), true);
assert.equal(preferSequentialPagination(MAX_OFFSET_WITHOUT_CURSOR + 1, 200), true);
});
});