Skip to content

test: add validation tests for esbuild and eslint config#27068

Closed
gaurav0107 wants to merge 5 commits into
google-gemini:mainfrom
gaurav0107:fix/16114-missing-validation-for-critical-configur
Closed

test: add validation tests for esbuild and eslint config#27068
gaurav0107 wants to merge 5 commits into
google-gemini:mainfrom
gaurav0107:fix/16114-missing-validation-for-critical-configur

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

Summary

Adds unit tests for esbuild.config.js and eslint.config.js covering the invariants called out in #16114: native-module externalization, WASM plugin resolution, and the security / license-header / node: protocol rules in the ESLint flat config.

This is a deliberately narrow, additive PR. It does not refactor esbuild.config.js into a helpers file, it does not touch unrelated subsystems, and it does not change runtime behavior of node esbuild.config.js.

Details

esbuild.config.js (4 line-touches)

Prepends export to four existing declarations so a test can reach them:

  • external, baseConfig, commonAliases
  • createWasmPlugins()

No other changes. The script's top-level Promise.allSettled([esbuild.build(cliConfig), esbuild.build(a2aServerConfig)]) trailer still runs on node esbuild.config.js. The test short-circuits it by mocking the esbuild module so esbuild.build() becomes a no-op that returns { metafile: { inputs: {}, outputs: {} } } — the module can be safely imported from a test without kicking off a real build.

scripts/tests/esbuild.config.test.ts (new, 13 tests)

Asserts:

  • external contains node-pty, @lydell/node-pty (plus every platform-specific prebuild), @github/keytar, and @google/gemini-cli-devtools.
  • baseConfig targets node, emits esm, has bundle: true, write: true, and routes .node through the file loader.
  • baseConfig.external is the same reference as the exported external array (single source of truth).
  • commonAliases.punycode === 'punycode/' — the trailing slash is load-bearing (without it, Node's built-in punycode module shadows the npm package).
  • createWasmPlugins() returns two plugins: a named 'wasm-binary' plugin plus the esbuild-plugin-wasm loader.
  • The wasm-binary plugin registers an onResolve handler with a \.wasm\?binary$ filter that correctly strips the ?binary suffix for absolute and relative paths and returns them in the wasm-embedded namespace.

scripts/tests/eslint-config.test.ts (new, 8 tests)

Imports the real eslint.config.js (it already export defaults a flat-config array) and asserts structural invariants:

  • A global-ignores entry covers **/node_modules/**, bundle/**, dist/**, **/coverage/**.
  • no-restricted-imports blocks node:os with importNames: ['homedir', 'tmpdir'], and separately blocks the bare os specifier for the same imports (defense in depth).
  • no-debugger and no-console are enforced as errors.
  • headers/header-format requires SPDX-License-Identifier: Apache-2.0.
  • import/enforce-node-protocol-usage is set to ['error', 'always'].

No linter actually runs during the test — these are pure configuration-shape assertions.

Related Issues

Fixes #16114

How to Validate

npm ci
npm run lint
npm run test:scripts -- scripts/tests/esbuild.config.test.ts scripts/tests/eslint-config.test.ts

Expected: 21 tests pass (13 in esbuild.config.test.ts, 8 in eslint-config.test.ts).

Regression probe — prove the tests catch real breakage:

# Temporarily remove a platform prebuild from `external` in esbuild.config.js
# and rerun the tests. `marks node-pty and its platform-specific prebuilds as external`
# should fail.

# Temporarily lower 'no-debugger' to 'warn' in eslint.config.js and rerun.
# `enforces no-debugger as an error somewhere in the config` should fail.

Two pre-existing failures on main in scripts/tests/generate-settings-doc.test.ts and scripts/tests/generate-settings-schema.test.ts are unrelated to this change and reproduce on main prior to the diff.

Pre-Merge Checklist

  • npm run lint passes on the full repository (exit 0, no warnings with --max-warnings 0).
  • npm run test:scripts runs; the two new test files add 21 passing tests. Pre-existing failures in generate-settings-* are unrelated and reproduce on main.
  • esbuild.config.js runtime behavior is unchanged — only export keywords added to four existing declarations; no reordering, no side-effect changes, no new imports.
  • New test files include the Apache-2.0 license header and pass the repo's headers/header-format rule.
  • No unrelated files touched — the diff is 3 files: 1 modified, 2 added.
  • Context: the prior PR (test: add validation tests for esbuild and eslint config files #19866) attempting this was closed for branch-sync scope bleed (1,867 files, 1M+ deletions), not on technical merit. Reviewer feedback explicitly suggested splitting into a focused, tests-only PR; this PR follows that advice.
  • CLA signed (flagged for the contributor to sign at https://cla.developers.google.com/).

Adds unit tests covering the invariants called out in google-gemini#16114:

- esbuild.config.js: native modules (node-pty, @github/keytar) and
  @google/gemini-cli-devtools remain external; baseConfig targets
  node+ESM+bundle with the .node file loader; commonAliases preserves
  the trailing slash on the userland punycode remap; createWasmPlugins()
  returns a wasm-binary plugin plus the esbuild-plugin-wasm loader and
  resolves absolute/relative .wasm?binary paths.
- eslint.config.js: global ignores cover build outputs; no-restricted-
  imports blocks node:os and bare os homedir/tmpdir; no-debugger and
  no-console are enforced as errors; headers/header-format requires
  Apache-2.0; import/enforce-node-protocol-usage is set to 'always'.

esbuild.config.js gains named exports (external, baseConfig,
commonAliases, createWasmPlugins) so the test can reach them without
running the top-level Promise.allSettled build trailer, which is
short-circuited in the test by mocking the esbuild module. Runtime
behavior of `node esbuild.config.js` is unchanged.

Fixes google-gemini#16114
@gaurav0107 gaurav0107 marked this pull request as ready for review May 14, 2026 19:15
@gaurav0107 gaurav0107 requested a review from a team as a code owner May 14, 2026 19:15
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a suite of unit tests to validate the integrity of the project's build and linting configurations. By asserting structural and functional invariants, these tests help prevent regressions in esbuild settings and ESLint rules, ensuring that security, license compliance, and module resolution policies remain strictly enforced.

Highlights

  • Configuration Validation: Added comprehensive unit tests for esbuild and ESLint configurations to ensure critical invariants are maintained.
  • Test Coverage: Implemented 21 new tests covering native-module externalization, WASM plugin resolution, and ESLint security/license-header rules.
  • Codebase Minimal Changes: Exported necessary constants and functions from esbuild.config.js to facilitate testing without altering runtime behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request exports key configuration objects from esbuild.config.js and introduces comprehensive unit tests for both the esbuild and ESLint configurations. The new tests verify bundling settings, external module exclusions, path aliasing, and various linting rules including security restrictions, production safety, and license header requirements. I have no feedback to provide.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels May 14, 2026
@sehoon38

Copy link
Copy Markdown
Contributor

As we are re-prioritizing our works, we are going to close issues that are not high priority for now. Thanks for understanding!

@sehoon38 sehoon38 closed this May 29, 2026
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing validation for critical configuration files could lead to broken bundles

4 participants