Files
miti99bot/tests/modules/twentyq/seeds.test.js
T
tiennm99 5b12650906 feat(twentyq): add reverse-Akinator yes/no game module powered by Workers AI
- seeded 54 objects across 6 categories (instrument, animal, food, vehicle, sport, household)
- @cf/google/gemma-4-26b-a4b-it judges via function calling; returns {is_guess, answer, hint}
- pre-AI validator rejects open-ended questions; handler dedups exact repeats
- secret-redacting hint filter as defense-in-depth
- 86 new vitest tests (seeds, state, validator, ai-client, handlers, render)
2026-04-24 14:37:23 +07:00

47 lines
1.4 KiB
JavaScript

import { describe, expect, it } from "vitest";
import { SEEDS, getRandomSeed } from "../../../src/modules/twentyq/seeds.js";
describe("twentyq/seeds", () => {
it("every seed has non-empty category, target, initialHint", () => {
for (const s of SEEDS) {
expect(s.category).toBeTruthy();
expect(s.target).toBeTruthy();
expect(s.initialHint).toBeTruthy();
expect(typeof s.category).toBe("string");
expect(typeof s.target).toBe("string");
expect(typeof s.initialHint).toBe("string");
}
});
it("all targets are lowercase", () => {
for (const s of SEEDS) {
expect(s.target).toBe(s.target.toLowerCase());
}
});
it("initialHint never contains the target word", () => {
for (const s of SEEDS) {
const hintLower = s.initialHint.toLowerCase();
const re = new RegExp(`\\b${s.target}\\b`, "i");
expect(re.test(hintLower)).toBe(false);
}
});
it("getRandomSeed returns a member of SEEDS", () => {
const s = getRandomSeed(() => 0.5);
expect(SEEDS).toContain(s);
});
it("getRandomSeed deterministic with stub rng", () => {
const a = getRandomSeed(() => 0);
const b = getRandomSeed(() => 0);
expect(a).toBe(b);
expect(a).toBe(SEEDS[0]);
});
it("rng returning 0.999... still indexes within bounds", () => {
const s = getRandomSeed(() => 0.99999);
expect(s).toBe(SEEDS[SEEDS.length - 1]);
});
});