8000 Test suite phase 2: clock, variant corpus, and the parser bugs it found by irfan-dahir · Pull Request #643 · jikan-me/jikan · GitHub
[go: up one dir, main page]

Skip to content

Test suite phase 2: clock, variant corpus, and the parser bugs it found - #643

Merged
irfan-dahir merged 7 commits into
masterfrom
v5/test-suite-phase-2
Oct 14, 2026
Merged

irfan-dahir merged 7 commits into
masterfrom
v5/test-suite-phase-2

Conversation

@irfan-dahir
Copy link
Copy Markdown
Collaborator

Stacked on #642 (v5/hardening-and-performance). Retarget to master once #642 merges. Depends on the jikan-fixtures Phase 2 PR, which must merge first.

Phase 2 of the test plan in PLAN.md, plus the parser bugs it found.

Deterministic dates

  • One time source. About 20 sites built dates from scraped text with new DateTimeImmutable($text) or date('Y'). They now go through Jikan\Helper\Time, which uses the PSR-20 clock from symfony/clock (new runtime dependency).
  • No behaviour change by default: it uses the system clock. Consumers can pin it with Clock::set(new MockClock(...)).
  • Verified equivalent on all 928 distinct date texts the suite parses: identical to the microsecond, with the same exceptions.
  • Tests freeze the clock, so all 15 date masks and 6 tolerance comparisons are gone.

Variant corpus

  • test/unit/Corpus/variants.json: 99 variants covering all 76 MalClient methods (previously 6 were called by tests), plus page 2s, zero-result searches, airing/upcoming/movie/light-novel/author pages, old and future seasons, a 404 and id 0.
  • RecordedPages serves each page with its recorded HTTP status and sets the clock to its recording time.
  • CorpusTest runs each variant through MalClient and checks the model invariants, a named snapshot, and that a second call builds an equal model.
  • scripts/record_variants.php (--dry-run, --live, --only, --force) records exactly what each method requests.

Bugs found and fixed

  • Zero-result searches:
    • Anime and manga search threw BadResponseException, because MAL returns a 404.
    • Person search threw ParserException.
    • Character and person search turned 429/500 errors into a TypeError.
  • Pagination:
    • Genre lists always said one page (now 20 for Action).
    • News, featured-article and user-update lists had hasNextPage=false hard-coded.
  • HTML5 <tbody>: Person::publishedManga was always empty (14 for Miyazaki now), and the manga related-entries table was skipped.
  • Card fields: anime/manga card type and manga card authors/serialization had been stubbed to null and are back. Seasonal cards take their type from the section header.
  • Top lists: character and person nameKanji was always null.
  • Profile: Profile::about is null, not "", when empty.

Breaking

AnimeCard::getLicensors() removed (and so SeasonalAnime's). Cards no longer show licensors on MAL. Anime::getLicensors() is unchanged.

The suite is at 750 tests; PHPStan baseline 429 → 424. CHANGELOG and PLAN.md are updated.

🤖 Generated with Claude Code

irfan-dahir and others added 7 commits October 14, 2026 07:29
MyAnimeList shows relative and partial dates ("Yesterday, 9:25 PM",
"5 hours ago", "Oct 13", weekdays). About 20 sites built them with
`new DateTimeImmutable($text)` or date('Y'), so results depended on the
system clock and snapshots drifted from day to day.

- Jikan\Helper\Time::parse()/now() read the time from symfony/clock
  (new runtime dependency, ^7.4 || ^8.0). Default is the system clock, so
  behaviour is unchanged; consumers can pin it with Clock::set().
  Equivalence was checked on all 928 distinct date texts the test suite
  parses: identical results to the microsecond and the same exceptions.
- Every date site goes through Time (Helper\Parser, 15 parsers, one model).
- Tests freeze the clock at 2026-10-12T12:00:00Z (JikanTest\TestCase), so
  the 15 date masks and the 6 tolerance comparisons are gone and snapshots
  hold exact dates.

The refreshed snapshots are in jikan-me/jikan-fixtures (feat/phase-2-corpus).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by the new variant corpus against live recordings:
- getAnimeSearch()/getMangaSearch() threw BadResponseException when a
  search had no matches: MyAnimeList answers those with a 404 page. They now
  return the empty model, as character and person search already did.
- getPersonSearch() threw ParserException on no matches: MAL shows a single
  "No results returned" row, which PersonSearchParser now recognises.
- getCharacterSearch()/getPersonSearch() caught every BadResponseException
  but only handled 404, so a 429 or 500 fell through to an undefined
  $crawler and a TypeError. They now rethrow it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- test/unit/Corpus: variants.json (99 variants covering all 76 MalClient
  methods plus page 2s, zero results, airing/upcoming/movie/light novel,
  old and future seasons, a 404 and id 0), RecordedPages (serves the
  recorded HTTP status and sets the clock to the recording time) and
  CorpusTest (invariants, named snapshot, second call equal, or the
  expected exception).
- scripts/record_variants.php records exactly what each MalClient method
  requests (--dry-run, --live, --only, --force; GET only, 3.5 s apart).
- PHPStan baseline shrinks by the entry the search fix removed.
- CHANGELOG (Added: the clock; Fixed: the searches) and PLAN.md (Phase 2
  status, plus the bugs the corpus found that still need a decision).

The pages and snapshots are in jikan-me/jikan-fixtures
(feat/phase-2-corpus), which must merge first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The corpus and scripts/field_witness.php showed model fields that no
recorded page ever filled. Checked one by one against the recorded HTML;
where MyAnimeList shows the data, the parser was wrong:

- Genre pagination: a positional selector (div[5]) no longer matched, so
  every genre list said one page. Parser::pagination() now reads
  div.pagination (?page=N and ?p=N, current page by class).
- News, featured-article and user-update lists returned a hard-coded
  hasNextPage=false / lastVisiblePage=1; they now read the page.
- Person published manga and the manga related-entries table expected
  <tr> directly under <table>; HTML5 parsing inserts <tbody>.
- Anime/manga card type and manga card authors/serialization had been
  stubbed to null after a layout change; MAL shows them again. Seasonal
  cards take the type from their section header.
- Top character/person kanji names moved from a span to a div.
- Profile "about" is null, not "", when empty.

Tests that asserted the broken values (null kanji, null seasonal type, two
manga relation groups) now assert the real ones. PHPStan baseline: 429 ->
425 (dead code and a string-typed page number went away).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Anime cards on genre, producer and seasonal lists no longer show licensors
on MyAnimeList (none on any recorded card page), and the getter had been
stubbed to return [] since. Removed from AnimeCard (so SeasonalAnime too)
and AnimeCardParser, with its test. Anime::getLicensors() from getAnime()
is unchanged. Recorded under Breaking in CHANGELOG.

Fields MAL left empty in the user list JSON (studios, licensors, season,
magazines, is_added_to_list) are kept for now, per owner decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- LastUpdatesParser only read "progress/total" when both were numbers, so
  "Reading 92/?" (total not known yet) lost the 92. Ongoing series in a
  profile's last anime/manga updates now keep their episode or chapter
  count; the total stays null.
- Four corpus variants recorded for fields no page had filled: explicit
  genres (High School DxD), filler/recap (Naruto's episode list), music
  videos (Bocchi the Rock!), birthday/about/manga updates (Xinil). Music
  videos, recap, birthday and about are now witnessed; the manga updates
  exposed the progress bug above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LastUpdatesParser passed numeric strings to BaseLastUpdate; the (int) casts in the previous commit fixed both baseline entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@irfan-dahir
irfan-dahir changed the base branch from v5/hardening-and-performance to master October 14, 2026 09:04
@irfan-dahir
irfan-dahir merged commit c46dfb0 into master Oct 14, 2026
6 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0