8000 Test suite phase 3: missing-field variants, mutation testing, helper property tests by irfan-dahir · Pull Request #644 · jikan-me/jikan · GitHub
[go: up one dir, main page]

Skip to content

Test suite phase 3: missing-field variants, mutation testing, helper property tests - #644

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

irfan-dahir merged 4 commits into
masterfrom
v5/test-suite-phase-3

Conversation

@irfan-dahir
Copy link
Copy Markdown
Collaborator

Stacked on #643 (v5/test-suite-phase-2), which is stacked on #642. Retarget down the chain as each merges. No fixtures change; it uses the corpus from jikan-fixtures#13.

Phase 3 of the test plan in PLAN.md.

Synthetic missing-field variants

  • What it tests: test/unit/Corpus/MissingFieldTest.php takes the 8 recorded anime/manga detail pages, removes one sidebar "Label:" row at a time through the DOM (166 cases, no requests), and checks that parsing still succeeds and only that row's fields change.

  • Two crashes found and fixed:

    • getAnime() failed when a page has no "Aired:" row.
    • getManga() failed when a page has no "Published:" row.

    Both now return the empty range that MyAnimeList itself shows as "Not available". Without the fix, the test fails 8 times.

Mutation testing (report-only)

  • infection.json5 and .github/workflows/mutation.yaml: Infection mutates src/Parser and src/Helper and reruns the tests.
  • On PRs touching src/: only the changed lines are mutated, with escaped mutants as annotations.
  • Nightly and on demand: everything, with the HTML report kept as an artifact.
  • Not enforced yet: continue-on-error for now; set minMsi from the first nightly score.
  • Local check: verified up to the coverage step locally, since this machine has no coverage driver. This PR is its first real run.

Property tests for the shared helpers

  • What they check: test/unit/Helper/HelperPropertiesTest.php runs about 400 generated inputs per helper (junk, emoji, CJK, NBSP, HTML fragments, malformed dates; fixed seed).
  • Three edge cases found and fixed:
    • parseDate() returned false (a TypeError) on text like "Unknown, 2026".
    • parseDateMDYReadable() threw on the same text.
    • stringIdFromUrl() warned on a URL with no path.
  • Documented, not changed: JString::cleanse() is not idempotent. Fixing it would change the newlines in all scraped text.

The suite is at 926 tests. CHANGELOG and PLAN.md are updated.

🤖 Generated with Claude Code

irfan-dahir and others added 4 commits October 14, 2026 12:15
MissingFieldTest takes every recorded anime/manga detail page in the corpus
(8 pages), removes one sidebar "Label:" row at a time through the DOM, and
checks that parsing still succeeds and only the fields that row feeds
change: 166 cases, no requests.

It found two crashes when a row is absent:
- AnimeParser::getAnimeAiredString() read the "Aired:" row without checking
  it exists (InvalidArgumentException from getAnime()).
- MangaParser::getPublished() passed null to DateRange when there is no
  "Published:" row (TypeError from getManga()).
Both now return the empty range MAL shows as "Not available". Without the
fix the test fails 8 times; with it, all 166 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Infection makes small deliberate changes to src/Parser and src/Helper
(flip a condition, drop a line, return early) and runs the tests against
each; a change no test notices marks code that runs but is not checked.

- infection.json5: mutates src/Parser and src/Helper with the default
  mutators; text, summary and HTML reports under build/infection.
- .github/workflows/mutation.yaml: on pull requests touching src/, only the
  changed lines (--git-diff-lines against the base branch), with escaped
  mutants as GitHub annotations; nightly and on demand, everything, with the
  HTML report as an artifact. pcov provides coverage. continue-on-error for
  now: set minMsi once the nightly score is known.
- infection/infection ^0.35.7 as a dev dependency.

Checked locally up to the coverage step (this machine's static PHP has no
coverage driver); the first real run will be in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HelperPropertiesTest checks rules over ~400 generated inputs per helper
(junk text, emoji, CJK, NBSP, HTML fragments, malformed dates; fixed seed):
cleanse() returns trimmed valid UTF-8, every date helper returns a date or
null, the id helpers accept any text and idFromUrl() reads ids back,
durations are never negative, placeholder normalisation is idempotent.

It found:
- parseDate() returned false (a TypeError for ?DateTimeImmutable) when text
  like "Unknown, 2026" matched its "Mon, YYYY" branch; it now falls through.
- parseDateMDYReadable() threw on the same text; it now returns null.
- stringIdFromUrl() warned on a URL without a path.

Left as is and documented in the test: cleanse() is not idempotent (<br>
becomes a newline, which a second pass strips); changing that would change
the newlines in all scraped text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@irfan-dahir
irfan-dahir changed the base branch from v5/test-suite-phase-2 to master October 14, 2026 09:04
@irfan-dahir
irfan-dahir merged commit 7b3b98a into master Oct 14, 2026
7 of 13 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