Skip to content

Port the BannerManager to HH3#8021

Merged
alcuadrado merged 5 commits intomainfrom
hh3-banner-manager
Mar 3, 2026
Merged

Port the BannerManager to HH3#8021
alcuadrado merged 5 commits intomainfrom
hh3-banner-manager

Conversation

@alcuadrado
Copy link
Copy Markdown
Member

No description provided.

@alcuadrado alcuadrado requested review from Copilot and schaable March 2, 2026 19:26
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 2, 2026

🦋 Changeset detected

Latest commit: 926f0a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the BannerManager functionality into Hardhat v-next (HH3), enabling the CLI to fetch a remote banner configuration, cache it locally, and conditionally print banner messages.

Changes:

  • Added a new BannerManager implementation that fetches banner-config-v3.json, caches it, and throttles requests/displays.
  • Integrated banner display into the main CLI flow (post-task) and into init.
  • Added a dedicated test suite covering banner fetch/caching/throttling behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
v-next/hardhat/src/internal/cli/banner-manager.ts New BannerManager implementation with remote fetch + caching + throttling.
v-next/hardhat/src/internal/cli/main.ts Shows banner after task execution in interactive non-CI environments with a short timeout.
v-next/hardhat/src/internal/cli/init/init.ts Shows banner after init flow completes (currently without a timeout / environment gating).
v-next/hardhat/test/internal/cli/banner-manager.ts New tests for BannerManager behavior (currently contains an intercept path issue).
Comments suppressed due to low confidence (6)

v-next/hardhat/src/internal/cli/init/init.ts:141

  • showBanner() is called without a timeout here, which means the underlying getRequest can block for the default request timeout (300s) if the network is slow/unreachable. This can unnecessarily stall hardhat --init flows. Consider passing a small timeout (similar to main.ts) and/or gating banner display behind the same interactive-environment check (!isCi() and process.stdout.isTTY).
    try {
      const { BannerManager } = await import("../banner-manager.js");
      const bannerManager = await BannerManager.getInstance();
      await bannerManager.showBanner();
    } catch (bannerError) {
      log("Error showing banner", bannerError);
    }

v-next/hardhat/src/internal/cli/banner-manager.ts:177

  • #isBannerConfig requires Object.getOwnPropertyNames(value).length === 4, which will reject otherwise-valid configs if the remote JSON ever adds new fields (forward-compat break), causing banners to silently stop working. Prefer validating only the required properties and ignoring additional ones.
    return (
      Object.getOwnPropertyNames(value).length === 4 &&
      "enabled" in value &&

v-next/hardhat/src/internal/cli/banner-manager.ts:204

  • readCache() trusts the on-disk JSON shape (including bannerConfig, lastDisplayTime, and lastRequestTime) without runtime validation/sanitization. A corrupted/hand-edited cache can lead to runtime exceptions (e.g. formattedMessages not being an array) or NaN time math. Consider validating the parsed cache object and discarding/repairing invalid fields before constructing the BannerManager.
async function readCache(): Promise<BannerCache> {
  const cacheDir = await getCacheDir();
  const bannerCacheFilePath = path.join(cacheDir, BANNER_CACHE_FILE_NAME);

  try {
    return await readJsonFile<BannerCache>(bannerCacheFilePath);
  } catch (error) {

v-next/hardhat/src/internal/cli/banner-manager.ts:187

  • The numeric fields in the banner config are only checked with typeof ... === "number". This allows NaN, Infinity, and negative values, which can result in unexpected throttling behavior (comparisons with NaN always being false, negative intervals effectively disabling throttling, etc.). Consider enforcing Number.isFinite(...) and >= 0 for the interval fields.
      "minSecondsBetweenDisplays" in value &&
      typeof value.minSecondsBetweenDisplays === "number" &&
      "minSecondsBetweenRequests" in value &&
      typeof value.minSecondsBetweenRequests === "number"

v-next/hardhat/src/internal/cli/banner-manager.ts:14

  • The debug namespace here (hardhat:util:banner-manager) doesn't match the surrounding CLI namespaces (e.g. hardhat:core:cli:main, hardhat:cli:init, hardhat:cli:telemetry:*). Consider renaming to a hardhat:cli:*/hardhat:core:cli:* prefix to keep debug filtering consistent across the CLI.
const log = debug("hardhat:util:banner-manager");

v-next/hardhat/test/internal/cli/banner-manager.ts:155

  • Test name has a grammatical typo: should's display should be shouldn't display (or similar).
    it("should's display the banner more often than minSecondsBetweenDisplays", async () => {
      // Store a cache file with recent lastDisplayTime and high
      // minSecondsBetweenDisplays
      await writeJsonFile(path.join(cacheDir, BANNER_CACHE_FILE_NAME), {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread v-next/hardhat/test/internal/cli/banner-manager.ts Outdated
@alcuadrado alcuadrado added no docs needed This PR doesn't require links to documentation no peer bump needed labels Mar 2, 2026
Copy link
Copy Markdown
Member

@schaable schaable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I left two minor comments, feel free to apply them if you agree.

Comment thread v-next/hardhat/src/internal/cli/banner-manager.ts
Comment thread v-next/hardhat/src/internal/cli/banner-manager.ts Outdated
alcuadrado and others added 5 commits March 3, 2026 18:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Luis Schaab <schaable@gmail.com>
@alcuadrado alcuadrado force-pushed the hh3-banner-manager branch from c75614b to 926f0a1 Compare March 3, 2026 18:38
@alcuadrado alcuadrado enabled auto-merge March 3, 2026 18:39
@alcuadrado alcuadrado added this pull request to the merge queue Mar 3, 2026
Merged via the queue into main with commit 2e9b075 Mar 3, 2026
213 checks passed
@alcuadrado alcuadrado deleted the hh3-banner-manager branch March 3, 2026 18:51
This was referenced Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants