All source files

tests/content.test.mjs

Download raw file

import test from 'node:test';
import assert from 'node:assert/strict';
import {readFile} from 'node:fs/promises';
import {ANSWER_SCHEDULE, ALLOWED_WORDS, EXTRA_GUESSES, OFFENSIVE_WORDS, buildAllowedWords, puzzleForDate} from '../src/word-data.mjs';
import {FIVE_LETTER_WORDS} from '../src/five-letter-words.mjs';
import {PRACTICE_POOL} from '../src/practice-data.mjs';
import {applyDenylist, buildWordlist, parseFiveLetterWords} from '../scripts/generate-five-letter-wordlist.mjs';

// 90 live days (2026-12-05..2027-03-04) plus 57 days through 2027-04-30.
const MIN_SCHEDULE_DAYS = 147;
const SCHEDULE_END_TARGET = '2027-04-30';

test('at least 147 contiguous UTC days have unique reviewed answers and three hint layers', () => {
  assert.ok(ANSWER_SCHEDULE.length >= MIN_SCHEDULE_DAYS, `schedule has ${ANSWER_SCHEDULE.length} entries, expected at least ${MIN_SCHEDULE_DAYS}`);
  assert.ok(ANSWER_SCHEDULE.at(-1).date >= SCHEDULE_END_TARGET, `schedule ends ${ANSWER_SCHEDULE.at(-1).date}, expected coverage through ${SCHEDULE_END_TARGET}`);
  const words=new Set(), allowed=new Set(ALLOWED_WORDS);
  ANSWER_SCHEDULE.forEach((entry,index)=>{
    if(index){const expected=new Date(Date.parse(ANSWER_SCHEDULE[index-1].date)+86400000).toISOString().slice(0,10);assert.equal(entry.date,expected);}
    assert.match(entry.date,/^\d{4}-\d{2}-\d{2}$/);
    assert.match(entry.word,/^[a-z]{5}$/);
    assert.ok(!words.has(entry.word));words.add(entry.word);
    assert.ok(allowed.has(entry.word));
    assert.ok(entry.categoryEn && entry.categoryZh && entry.clueEn && entry.clueZh);
    assert.equal(entry.reviewed,true,`${entry.word} must be reviewed`);
  });
});

test('allowed guesses are unique and broader than the answer set', () => {
  assert.equal(new Set(ALLOWED_WORDS).size,ALLOWED_WORDS.length);
  assert.ok(ALLOWED_WORDS.length >= 1000);
  for (const word of ['angle','baker','might','house']) assert.ok(ALLOWED_WORDS.includes(word),`${word} should be accepted`);
  ALLOWED_WORDS.forEach(word=>assert.match(word,/^[a-z]{5}$/));
});

test('date selection is deterministic and refuses unscheduled dates', () => {
  const first=ANSWER_SCHEDULE[0], last=ANSWER_SCHEDULE.at(-1);
  assert.equal(puzzleForDate(new Date(first.date+'T00:00:00Z')).entry.word,first.word);
  assert.equal(puzzleForDate(new Date(first.date+'T00:00:00Z')).puzzleNumber,1);
  assert.equal(puzzleForDate(new Date(last.date+'T23:59:59Z')).entry.word,last.word);
  assert.equal(puzzleForDate(new Date('2020-01-01T00:00:00Z')),null);
  const after=new Date(Date.parse(last.date)+86400000);
  assert.equal(puzzleForDate(after),null);
});

test('D90 review day and the 2027-04-30 coverage target both resolve to puzzles', () => {
  for (const date of ['2027-03-05', '2027-04-30']) {
    const puzzle=puzzleForDate(new Date(date+'T00:00:00Z'));
    assert.ok(puzzle,`${date} must have a scheduled puzzle`);
    assert.equal(puzzle.entry.date,date);
  }
});

test('daily answers never reuse a practice word, so practice cannot leak a future answer', () => {
  const practice=new Set(PRACTICE_POOL.map(entry=>entry.word));
  const overlap=ANSWER_SCHEDULE.map(entry=>entry.word).filter(word=>practice.has(word));
  assert.deepEqual(overlap,[],`practice pool intersects daily answers: ${overlap.join(', ')}`);
});

test('every answer occurs in the stored SCOWL source and license travels with it', async () => {
  const [source,license]=await Promise.all([readFile(new URL('../data/scowl/english-words.95',import.meta.url),'utf8'),readFile(new URL('../data/scowl/Copyright',import.meta.url),'utf8')]);
  const words=new Set(source.split(/\r?\n/).map(line=>line.trim().toLowerCase()));
  ANSWER_SCHEDULE.forEach(entry=>assert.ok(words.has(entry.word),`${entry.word} missing from SCOWL source`));
  assert.match(license,/SCOWL/i);
  assert.ok(license.length>1000);
});

test('offensive-word denylist is well formed and never shadows an ordinary or scheduled word', () => {
  assert.ok(OFFENSIVE_WORDS.length>=20);
  assert.equal(new Set(OFFENSIVE_WORDS).size,OFFENSIVE_WORDS.length);
  OFFENSIVE_WORDS.forEach(word=>assert.match(word,/^[a-z]{5}$/));
  const blocked=new Set(OFFENSIVE_WORDS);
  for (const word of ['angle','baker','might','house']) assert.ok(!blocked.has(word),`${word} must stay allowed`);
  ANSWER_SCHEDULE.forEach(entry=>assert.ok(!blocked.has(entry.word),`scheduled answer ${entry.word} must not be denylisted`));
  for (const word of ['bitch','penis','whore','fagot','chink','pussy','titty']) assert.ok(blocked.has(word),`${word} must be denylisted`);
});

test('neither generated nor runtime word lists contain a denylisted word', () => {
  const blocked=new Set(OFFENSIVE_WORDS);
  FIVE_LETTER_WORDS.forEach(word=>assert.ok(!blocked.has(word),`${word} must not appear in FIVE_LETTER_WORDS`));
  ALLOWED_WORDS.forEach(word=>assert.ok(!blocked.has(word),`${word} must not appear in ALLOWED_WORDS`));
});

test('generated wordlist stays inside the stored SCOWL source and is already denylist-clean', async () => {
  const source=await readFile(new URL('../data/scowl/english-words.95',import.meta.url),'utf8');
  const words=new Set(source.split(/\r?\n/).map(line=>line.trim().toLowerCase()));
  FIVE_LETTER_WORDS.forEach(word=>assert.ok(words.has(word),`${word} missing from SCOWL source`));
  const {words:kept,removed}=applyDenylist(FIVE_LETTER_WORDS);
  assert.equal(removed.length,0);
  assert.deepEqual(kept,FIVE_LETTER_WORDS);
});

test('wordlist generation drops denylisted entries but keeps ordinary five-letter words', () => {
  const dictionary=['6','bitch/S','penis','Angle','angle','house','might','baker','sixsix'].join('\n');
  const parsed=parseFiveLetterWords(dictionary);
  assert.deepEqual(parsed,[...parsed].sort());
  assert.deepEqual(parsed,['angle','baker','bitch','house','might','penis']);
  const {words,removed}=buildWordlist(dictionary);
  assert.deepEqual(words,['angle','baker','house','might']);
  assert.deepEqual(removed,['bitch','penis']);
});

test('runtime ALLOWED_WORDS applies the denylist to every guess source', () => {
  const blocked=new Set(OFFENSIVE_WORDS);
  const union=[...new Set([...FIVE_LETTER_WORDS,...ANSWER_SCHEDULE.map(entry=>entry.word),...EXTRA_GUESSES])];
  assert.deepEqual(ALLOWED_WORDS,union.filter(word=>!blocked.has(word)));
  const poisoned=buildAllowedWords({fiveLetterWords:['angle','bitch'],answerWords:['kraut','house'],extraGuesses:['penis','might']});
  assert.deepEqual(poisoned,['angle','house','might']);
});