mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 19:20:02 +01:00
* feat(course): every stored record names its course, and today's progress is the Zurich course's A course registry (lib/course/registry.ts) lists the one course there is; lib/variety/active.ts resolves its pack. Browser stores that hold course progress move to an envelope keyed by course under .v2 keys, and a value under the old .v1 key is read as the default course without being rewritten. progress_devices, certificates and entitlements gain a course column that defaults to the Zurich course. Item ids are unique across courses, and the default course's ids are unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * refactor(variety): the pack declares its articles, persons, respellings, voices and prompt lines Article, FormLabel and VocabularyGroup were closed unions of the Zurich values, the answer comparison folded Zurich respellings for every language, word distance lower-cased as German, the voice ranking named two German tags and the prompt builder carried Swiss spelling advice. Each is now a field of the pack, read by the engine; a contract test over every pack refuses a value the pack did not declare, and the leak test also looks for the taught language's own words in engine code. The Ukrainian pack gains one verb with its own pronouns and no articles. The 2,956 published items and the system prompt are byte-identical. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * refactor(practice): an item's level comes from a source the course chooses A course entered from a sibling language measures each item's distance from that language, exactly as before; a course entered from zero reads a declared CEFR band on the word, the line or the topic. levels.ts exposes both as LevelSource and picks by Course.entry. Every published item keeps its level. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * feat(meaning): a meaning can be shown in the learner's language A meaning is the bridge form plus an optional gloss in the interface language. One pure rule (lib/domain/meaning/meaning.ts) decides what is printed from the learner's answer to «Wie gut ist dein Deutsch?»: good shows German only, as before and by default; some shows German and the gloss; none shows the gloss; without a gloss German is always shown. Every exercise, the word list and the scene pages print meanings through one component. The answer is a course store, set in the settings and asked once after the start card, only in an interface language that has glosses. Gloss sets are one file per course and language, loaded on demand. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * content(glosses): English and Russian meanings for every word and scene line; French and Italian for every word Machine drafts from the Zurich form and its German meaning together, marked unreviewed in the data. One file per language beside the pack, keyed by the German the course gives. Tests refuse a key no entry carries, an empty gloss and two glosses for one German form; pnpm run glosses:coverage prints what is covered. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * content(glosses): French and Italian meanings for every scene line Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * docs: courses, pack-declared forms, level sources and glosses, as they now are Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * refactor(variety): the pack says which grammatical person each of its labels is The gloss check and the prompt's auxiliary table, both new on main, matched the Zurich labels «ich» and «er» by name. The forms pass of the leak test caught it on rebase. The pack now declares personOf, and both read it; the system prompt and the published items are unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T --------- Co-authored-by: Claude <noreply@anthropic.com>
131 lines
6.3 KiB
TypeScript
131 lines
6.3 KiB
TypeScript
import { test, describe } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { FORM_CATEGORIES, formLabelsOf, spellingOf, type VarietyPack } from "./pack.ts";
|
|
import { ZURICH_GERMAN } from "./packs/gsw-zh.ts";
|
|
import { UKRAINIAN } from "./packs/uk.ts";
|
|
import { VARIETY } from "./active.ts";
|
|
import { getDictionary, LOCALES } from "../i18n/index.ts";
|
|
import { articleItems, formItems } from "../domain/practice/kinds/vocabulary.ts";
|
|
|
|
/**
|
|
* WHAT A PACK USES, IT DECLARES.
|
|
*
|
|
* `Article`, `FormLabel` and `VocabularyGroup` were closed unions of the
|
|
* Zurich values, which made a wrong article a type error and made the
|
|
* contract for every variety Zurich-shaped. They are open now, and these
|
|
* tests are what the unions were for: over EVERY pack, a value an entry uses
|
|
* that the pack did not declare fails the build.
|
|
*/
|
|
const PACKS: readonly VarietyPack[] = [ZURICH_GERMAN, UKRAINIAN];
|
|
|
|
for (const pack of PACKS) {
|
|
describe(`${pack.name}: forms, articles and groups are the pack's own`, () => {
|
|
const words = pack.vocabulary ?? [];
|
|
|
|
test("every article used is one the pack declares", () => {
|
|
const target = pack.articles?.target ?? [];
|
|
const bridge = Object.keys(pack.articles?.fromBridge ?? {});
|
|
for (const word of words) {
|
|
if (word.article) assert.ok(target.includes(word.article), `${word.target}: "${word.article}" is not an article of ${pack.name}`);
|
|
if (word.bridgeArticle) assert.ok(bridge.includes(word.bridgeArticle), `${word.target}: "${word.bridgeArticle}" is not a bridge article`);
|
|
}
|
|
for (const [from, to] of Object.entries(pack.articles?.fromBridge ?? {})) {
|
|
assert.ok(target.includes(to), `${from} maps to "${to}", which is not declared`);
|
|
}
|
|
if (pack.articles) assert.equal(new Set(target).size, target.length);
|
|
});
|
|
|
|
test("every form label is one of the pack's persons or a grammatical category", () => {
|
|
const allowed = formLabelsOf(pack);
|
|
for (const word of words) {
|
|
for (const form of word.forms ?? []) {
|
|
assert.ok(allowed.includes(form.label), `${word.target}: the label "${form.label}" is not declared`);
|
|
}
|
|
}
|
|
for (const label of Object.keys(pack.subjects ?? {})) {
|
|
assert.ok((pack.persons ?? []).includes(label), `a subject is given for "${label}", which is not a person of the pack`);
|
|
}
|
|
for (const label of Object.keys(pack.personOf ?? {})) {
|
|
assert.ok((pack.persons ?? []).includes(label), `a grammatical person is given for "${label}", which is not a person of the pack`);
|
|
}
|
|
for (const category of FORM_CATEGORIES) {
|
|
assert.ok(!(pack.persons ?? []).includes(category), `"${category}" is a category, not a person`);
|
|
}
|
|
});
|
|
|
|
test("every group used is declared, in the order the list shows them", () => {
|
|
const groups = pack.vocabularyGroups ?? [];
|
|
assert.equal(new Set(groups).size, groups.length);
|
|
for (const word of words) assert.ok(groups.includes(word.group), `${word.target}: the group "${word.group}" is not declared`);
|
|
});
|
|
|
|
test("the case-folding locale is a real one, and respellings exist only without a standard", () => {
|
|
assert.doesNotThrow(() => Intl.getCanonicalLocales(pack.orthography.locale));
|
|
assert.ok(pack.orthography.locale.trim());
|
|
if (pack.orthography.standardised) {
|
|
assert.equal(pack.orthography.respellings, undefined, "a standardised spelling has no free respellings");
|
|
}
|
|
for (const [from, to] of spellingOf(pack).respellings) {
|
|
assert.ok(from && from !== to, "a respelling must change something");
|
|
assert.equal(from, from.toLocaleLowerCase(pack.orthography.locale), "respellings are applied to lower-cased text");
|
|
}
|
|
});
|
|
|
|
test("the voices are ranked so that a narrower language is never shadowed by a wider one", () => {
|
|
const ranks = pack.speech.voices;
|
|
assert.ok(ranks.length > 0, "a pack that lists no voice can never be read aloud, and should say so by choice");
|
|
ranks.forEach((rank, i) => {
|
|
assert.equal(rank.lang, rank.lang.toLowerCase());
|
|
assert.ok(rank.claim.trim());
|
|
for (const earlier of ranks.slice(0, i)) {
|
|
assert.ok(
|
|
rank.lang !== earlier.lang && !rank.lang.startsWith(`${earlier.lang}-`),
|
|
`${rank.lang} can never match: ${earlier.lang} comes first and already covers it`,
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
test("the questions generated from the list use only what the pack declared", () => {
|
|
for (const item of articleItems(pack)) {
|
|
assert.deepEqual(item.options, pack.articles!.target);
|
|
assert.ok(item.answer >= 0 && item.answer < item.options.length);
|
|
}
|
|
const persons = pack.persons ?? [];
|
|
for (const item of formItems(pack)) assert.ok(persons.includes(item.label), `${item.id} asks about "${item.label}"`);
|
|
});
|
|
});
|
|
}
|
|
|
|
describe("the contract is not shaped like its first pack", () => {
|
|
test("a variety without articles asks no article question, and its paradigm uses its own pronouns", () => {
|
|
assert.equal(UKRAINIAN.articles, undefined);
|
|
assert.deepEqual(articleItems(UKRAINIAN), []);
|
|
const asked = formItems(UKRAINIAN);
|
|
assert.deepEqual(asked.map((i) => i.label), ["я", "ти", "він"]);
|
|
assert.deepEqual(asked[0]!.options, ["роблю", "робиш", "робить"]);
|
|
});
|
|
|
|
test("the Zurich article questions are the ones that were asked before the pack declared its articles", () => {
|
|
const items = articleItems(ZURICH_GERMAN);
|
|
assert.ok(items.length >= 5);
|
|
for (const item of items) {
|
|
assert.deepEqual(item.options, ["de", "d", "s"]);
|
|
const entry = ZURICH_GERMAN.vocabulary!.find((w) => w.target === item.noun)!;
|
|
const same = { der: "de", die: "d", das: "s" }[entry.bridgeArticle as "der" | "die" | "das"];
|
|
assert.notEqual(same, entry.article, `${item.noun} follows the mapping and should not be asked`);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("the taught pack's keys are words in every interface language", () => {
|
|
test("every person and category label has a translation", () => {
|
|
for (const locale of LOCALES) {
|
|
const persons: Record<string, string> = getDictionary(locale).practice.persons;
|
|
for (const label of formLabelsOf(VARIETY)) {
|
|
assert.ok(persons[label]?.trim(), `${locale} has no word for the form label "${label}"`);
|
|
}
|
|
}
|
|
});
|
|
});
|