Skip to content

fix(metascraper-author): make strict guard await its rule - #888

Merged
Kikobeats merged 1 commit into
masterfrom
Kikobeats/author-strict-guard
Oct 15, 2026
Merged

Kikobeats merged 1 commit into
masterfrom
Kikobeats/author-strict-guard

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Closes #887.

Problem

strict in packages/metascraper-author/src/index.js wraps rules built by toRule, which are async. It called them without await, so REGEX_STRICT.test(value) was testing "[object Promise]". That string has two words, so the test always passed and the guard never rejected anything. Single-word matches from the five class/path heuristics (for example <span class="author">Newsvilla</span>) came through as the author.

Fix

const strict = rule => async $ => {
  const value = await rule($)
  return REGEX_STRICT.test(value) ? value : undefined
}

On rejection the guard returns undefined, not false, which is where this differs from the fix suggested in the issue. findRule stops at the first value that passes has(), and has(false) is true. Returning false would therefore end the rule chain at the first strict rule that doesn't match, and author would come out as false on most pages. With that variant, this package's existing twitter:creator test fails.

Behavior change

  • Single-word matches from the strict rules are now rejected, and resolution moves on to the next rule.
  • Two snapshots in packages/metascraper change, and both results improve:
    • sfstandard: lsariasfstandard.com becomes Lauren Saria.
    • learnnode: HackerYou becomes wesbos.
  • Single-word authors are still found through JSON-LD, meta tags, itemprop, rel="author", screenname and twitter:creator. None of those rules has the two-word check.

Tests

  • packages/metascraper-author: added 3 tests: a single word is rejected, two words are kept, and a strict rule that doesn't match falls through to the next rule. The new tests run against metascraper-author alone, because metascraper-readability finds bylines independently.
    • Old code: 2 of the new tests fail.
    • The issue's && value variant: 4 tests fail (the 3 new ones plus the twitter:creator test).
    • This branch: all 5 pass.
  • packages/metascraper (TZ=UTC npx ava): 120 passed after updating the two snapshots above.
  • An adversarial review probed edge inputs (whitespace-only, tabs, newlines, unicode spaces, zero-width space, rules that throw). It found nothing that breaks the fix.

🤖 Generated with Claude Code


Note

Low Risk
Narrow fix to author heuristic filtering in metascraper-author with added tests; no auth, security, or data-handling changes.

Overview
Fixes a bug where the strict author guard never ran its two-word check because it called async rules without await, so REGEX_STRICT was applied to a Promise string and always passed.

strict is now async, awaits the wrapped rule, and returns undefined (not false) when the value fails the regex so findRule can fall through to later rules such as twitter:creator.

Behavior: single-word hits from class/path/byline heuristics are dropped; multi-word names are kept. Integration snapshots improve author extraction on learnnode and sfstandard. Three unit tests cover rejection, acceptance, and fall-through.

Reviewed by Cursor Bugbot for commit aa4d50a. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Author extraction now correctly applies strict matching rules, rejecting single-word matches while retaining valid multi-word author names.
    • When a strict match is unavailable, author details can fall back to the Twitter creator value.
    • Updated extracted author names for supported pages, including LearnNode and SF Standard.

`strict` called async `toRule` rules synchronously, so the two-word
regex tested "[object Promise]" and never rejected anything. Await the
rule and return `undefined` on rejection: `findRule` treats `false` as
a found value (`has(false)` is true), which would end the rule chain.

Closes #887

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 175d1003-0842-49dd-acd6-444a3384d6c7
📥 Commits

Reviewing files that changed from the base of the PR and between 999e1ed and aa4d50a.

⛔ Files ignored due to path filters: 2
  • packages/metascraper/test/integration/learnnode/snapshots/index.js.snap is excluded by !**/*.snap
  • packages/metascraper/test/integration/sfstandard/snapshots/index.js.snap is excluded by !**/*.snap
📒 Files selected for processing: 4
  • packages/metascraper-author/src/index.js
  • packages/metascraper-author/test/index.js
  • packages/metascraper/test/integration/learnnode/snapshots/index.js.md
  • packages/metascraper/test/integration/sfstandard/snapshots/index.js.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The author plugin now awaits each strict-wrapped rule before applying the two-word check. Tests cover single-word rejection, multi-word acceptance, and fallback to the Twitter creator. Two integration snapshots record changed author values.

Changes: Author strict-rule behavior

Layer / File(s) Summary
Await strict-rule results and validate author extraction
packages/metascraper-author/src/index.js, packages/metascraper-author/test/index.js, packages/metascraper/test/integration/learnnode/snapshots/index.js.md, packages/metascraper/test/integration/sfstandard/snapshots/index.js.md
The strict wrapper awaits the rule result before testing it. Tests cover single-word rejection, multi-word acceptance, and fallback to the Twitter creator. Integration snapshots change the author values to wesbos and Lauren Saria.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to aa4d5

The strict author-rule change has no identified merge-blocking issue; merge after normal checks.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: making the strict guard await its rule.
Linked Issues check Passed The PR satisfies the coding requirements in directly linked issue #887. packages/metascraper-author/src/index.js makes strict asynchronous, awaits the wrapped rule, and returns undefined when th…
Out of Scope Changes check Passed The changes remain within issue #887. The unit tests verify the strict guard and rule-chain behavior. The two integration snapshot updates record the expected author-selection changes caused by the fi…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 95.004% — Kikobeats/author-strict-guard into master. No base build found for master.

@Kikobeats
Kikobeats merged commit c1188fc into master Oct 15, 2026
67 checks passed
@Kikobeats
Kikobeats deleted the Kikobeats/author-strict-guard branch October 15, 2026 07:49
markharding pushed a commit to futo-org/Harbor that referenced this pull request Oct 20, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [metascraper](https://metascraper.js.org) ([source](https://github.com/microlinkhq/metascraper)) | [`5.58.4` → `5.58.5`](https://renovatebot.com/diffs/npm/metascraper/5.58.4/5.58.5) | ![age](https://developer.mend.io/api/mc/badges/age/npm/metascraper/5.58.5?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/metascraper/5.58.4/5.58.5?slim=true) |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/99) for more information.

---

### Release Notes

<details>
<summary>microlinkhq/metascraper (metascraper)</summary>

### [`v5.58.5`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5585-2026-10-15)

[Compare Source](microlinkhq/metascraper@v5.58.4...v5.58.5)

##### Bug Fixes

- **metascraper-author:** make strict guard await its rule ([#&#8203;888](microlinkhq/metascraper#888)) ([c1188fc](microlinkhq/metascraper@c1188fc)), closes [#&#8203;887](microlinkhq/metascraper#887)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNjcuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE2Ny4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1931
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.

metascraper-author issue: strict regex check always passes

2 participants