Files
noitu/web/tests/dictionary-source.test.js
T
tiennm99 557de1af94 refactor: remove unused knobs, strings and stale text
Drop what nothing uses any more: the --max-syllables flag with its
sourceSpec field, meta row and reject reason; the store's clearRejection;
the --gap CSS token; three orphaned i18n strings; two exports with no
importer; the preview npm script; the proto.yml "baseline exists" step
that has been unconditionally true since the schema landed on main; and
two root-level .gitignore entries for paths Playwright never writes.

Correct text that outlived its subject: NOTICE named a tools/ directory
that never existed, the README still pointed at the first plan and
carried a migration note for retired sources, and a few comments still
said "release" for an upstream that is a weekly export. The pin test
header now says three copies and also holds README and ATTRIBUTION to
the same URL; the Make-targets table lists clean and help.

Wire fixtures regenerated so client_hello uses the ProtocolVersion
constant and server_game_started carries the 30s turn limit.
builder_version becomes 4 for the dropped meta row.
2026-09-08 18:01:37 +07:00

62 lines
2.5 KiB
JavaScript

// The upstream dictionary URL lives in three places: the Makefile, which
// builds it for a developer, the Dockerfile, which builds it for the image, and
// the builder, which stamps it into the database. They have to agree, or the
// container ships a wordlist nobody tested against. The docs that quote the
// URL are held to the same copy.
//
// This lives in the JavaScript suite for no better reason than that it is the
// suite that already reads other files in the repository. It is checking build
// files and docs, not the frontend.
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
const makefile = readFileSync(fileURLToPath(new URL('../../Makefile', import.meta.url)), 'utf8');
const dockerfile = readFileSync(fileURLToPath(new URL('../../Dockerfile', import.meta.url)), 'utf8');
/**
* @param {string} source
* @param {RegExp} pattern
* @param {string} what
*/
function pin(source, pattern, what) {
const match = source.match(pattern);
expect(match, `${what} not found`).not.toBeNull();
return match?.[1].trim();
}
describe('the upstream dictionary export', () => {
const makeUrl = pin(makefile, /DICT_URL\s*:?=\s*(\S+)/, 'DICT_URL in the Makefile');
const dockerUrl = pin(dockerfile, /ARG DICT_URL=(\S+)/, 'DICT_URL in the Dockerfile');
it('is the same file in both build files', () => {
expect(dockerUrl).toBe(makeUrl);
});
it('is the Vietnamese-language file of the Vietnamese Wiktionary edition', () => {
// The path carries a space, so it must stay percent-encoded or make and
// sh will split it; and it must be the vi edition, not the English one.
expect(makeUrl).toMatch(/^https:\/\/kaikki\.org\/viwiktionary\/Ti%E1%BA%BFng%20Vi%E1%BB%87t\/[^\s/]+\.jsonl$/);
});
it('is the URL the builder stamps into the database', () => {
// The builder records the source URL in the meta table from its own
// constant. The three copies must agree or the attribution record names
// a file nobody downloaded.
const builder = readFileSync(
fileURLToPath(new URL('../../server/cmd/build-dictionary/kaikki_list.go', import.meta.url)),
'utf8'
);
const builderUrl = pin(builder, /kaikkiSourceURL\s*=\s*"([^"]+)"/, 'kaikkiSourceURL in the builder');
expect(builderUrl).toBe(makeUrl);
});
it('is the URL the docs quote', () => {
for (const rel of ['../../README.md', '../../data/ATTRIBUTION.md']) {
const doc = readFileSync(fileURLToPath(new URL(rel, import.meta.url)), 'utf8');
expect(doc, `${rel} does not quote DICT_URL`).toContain(makeUrl);
}
});
});