Skip to content

test: remove --proxyquire-shim from logging and pubsub packages - #9644

Merged
danieljbruce merged 16 commits into
mainfrom
fix/remove-proxyquire-shim-logging-pubsub
Oct 30, 2026
Merged

danieljbruce merged 16 commits into
mainfrom
fix/remove-proxyquire-shim-logging-pubsub

Conversation

@danieljbruce

@danieljbruce danieljbruce commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Replaces the global --proxyquire-shim in handwritten/logging, handwritten/logging-bunyan, handwritten/logging-winston, and handwritten/pubsub using the centralized proxyquire helper from google-test-utils (Path 1B).

Impact

Removes --proxyquire-shim from logging, logging-bunyan, logging-winston, and pubsub test scripts without duplicating per-package test/proxyquire.ts helpers.

Changes

Testing

  • Executed pnpm test under both Node.js and Bun (JS_RUNTIME=bun) in handwritten/logging, handwritten/logging-bunyan, handwritten/logging-winston, and handwritten/pubsub.
  • Verified strict lint and type checks pass via bin/linter.mjs --strict.

Alternatives

  • Per-package test/proxyquire.ts files (Path 1A) were replaced with the centralized google-test-utils helper (Path 1B) per review discussion in b/570091189.

@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 replaces the global proxyquire dependency with a custom local proxyquire.ts implementation across multiple packages (logging-bunyan, logging-winston, logging, and pubsub), updating the corresponding test scripts and imports. Feedback on the changes highlights two main areas of improvement: first, in the new proxyquire.ts files, wrapping individual property assignments in a try...catch block inside the loop would prevent the entire copy process from aborting if a single property assignment fails; second, across several test files, replacing the .then(noop, ...) promise rejection pattern with assert.rejects would make the tests more robust and prevent silent passes on unexpected promise resolutions.

Comment thread handwritten/logging/test/proxyquire.ts Resolved
Comment thread handwritten/pubsub/test/proxyquire.ts Resolved
Comment thread handwritten/logging/test/index.ts Resolved
Comment thread handwritten/logging/test/index.ts Resolved
Comment thread handwritten/logging/test/index.ts Resolved
Comment thread handwritten/logging/test/index.ts Resolved
Comment thread handwritten/logging/test/index.ts Resolved
Comment thread handwritten/logging/test/index.ts Resolved
@danieljbruce
danieljbruce added this pull request to stack #9647 October 15, 2026 21:18
@danieljbruce

Copy link
Copy Markdown
Contributor Author

This seems to just create a localized shim which is better and acceptable, but adjustments to the exact tests would likely be ideal.

danieljbruce added a commit that referenced this pull request Oct 20, 2026
…translate (#9642)

## Description

Replaces proxyquire with sinon and direct stubs across four packages.

## Impact

Removes --proxyquire-shim from gax, googleapis-common, error-reporting,
and translate unit tests.

## Changes

- **Part 1 of 5 in stacked PR series**: **#9642** -> #9643 -> #9644 ->
#9645 -> #9646 (b/570680750).
- `core/packages/gax`: Replace `proxyquire` in `test/unit/grpc.ts` with
`sinon.stub(fs, 'existsSync')` and remove `--proxyquire-shim` from
`package.json`.
- `core/packages/nodejs-googleapis-common`: Replace `proxyquire` in
`test/test.authplus.ts` and `test/test.http2.ts` with
`sinon.stub(auth.GoogleAuth.prototype, 'getClient')` and
`sinon.stub(coreHttp2, 'connect')`, and remove `--proxyquire-shim` from
`package.json`.
- `handwritten/error-reporting`: Stub
`util.makeAuthenticatedRequestFactory` and
`RequestHandler.prototype.request` directly in
`test/unit/google-apis/auth-client.ts` and remove `--proxyquire-shim`
from `package.json`.
- `packages/google-cloud-translate`: Intercept
`Module.prototype.require` directly in `test/index.ts` `before()` hook
and remove `--proxyquire-shim` from `package.json`.

## Testing

- Executed `pnpm test` under both Node.js and Bun (`JS_RUNTIME=bun`) in
`core/packages/gax`, `core/packages/nodejs-googleapis-common`,
`handwritten/error-reporting`, and `packages/google-cloud-translate`.
- Verified strict lint and type checks pass via `bin/linter.mjs
--strict`.

## Alternatives

- Not merging this pull request was considered, which would leave these
four packages dependent on the global `bin/proxyquire-bun-shim.cjs`
preload shim.
@danieljbruce
danieljbruce force-pushed the fix/remove-proxyquire-shim-logging-pubsub branch from 0e7ca7c to 3ab8240 Compare October 20, 2026 14:27
…re-shim-core-dns-ds-bq

# Conflicts:
#	core/common/test/util.ts
#	handwritten/datastore/package.json
#	pnpm-lock.yaml
…ove-proxyquire-shim-logging-pubsub

# Conflicts:
#	handwritten/logging/package.json
#	handwritten/pubsub/package.json
#	pnpm-lock.yaml
@danieljbruce

Copy link
Copy Markdown
Contributor Author

[Generated] Per #9643 (comment), we opened #9759 (feat(test-utils): add createProxyquire and proxyquire helper) to add createProxyquire and proxyquire to core/test-utils (google-test-utils) in a standalone PR first.

We are waiting for #9759 to be merged and a new release of google-test-utils to be published before removing the extra --filter "./core/test-utils" --ignore-scripts, pnpm --dir core/test-utils run compile, ensureWorkspacePackagesLinked(), and run prepare --if-present flags in the .yaml files (cloudbuild.yaml and .github/actions/pnpm-lockfile-check/action.yaml).

danieljbruce added a commit that referenced this pull request Oct 28, 2026
## Description

Adds runtime-agnostic `createProxyquire` and `proxyquire` helpers to
`google-test-utils`.

## Impact

Releasing `createProxyquire` in `google-test-utils` avoids extra YAML
flags across stacked PRs.

## Changes

- Per
#9643 (comment),
extracts just the `createProxyquire` and `proxyquire` implementation in
`core/test-utils` (`google-test-utils`) into a standalone PR.
- We want to merge and release `google-test-utils` (`core/test-utils`)
with `createProxyquire` first so that the rest of the stacked PRs
(#9643, #9644, #9645, #9646) can consume the published
`google-test-utils` package and do not need the extra `--filter
"./core/test-utils" --ignore-scripts`, `pnpm --dir core/test-utils run
compile`, `ensureWorkspacePackagesLinked()`, and `run prepare
--if-present` flags in the `.yaml` files (`cloudbuild.yaml` and
`.github/actions/pnpm-lockfile-check/action.yaml`).
- `core/test-utils/src/proxyquire.ts`: Adds `createProxyquire`,
`proxyquire`, `Proxyquire`, and `ProxyquireStubs` built on
`Module.prototype.require` and `require.cache` with automatic caller
path resolution (`Error.prepareStackTrace`) for Node.js and Bun
(`JS_RUNTIME=bun`).
- `core/test-utils/src/index.ts`: Exports `createProxyquire`,
`proxyquire`, `Proxyquire`, and `ProxyquireStubs`.
- `core/test-utils/test/proxyquire.test.ts`: Adds unit tests covering
direct/transitive `@global` stubbing, `@noCallThru` / `noCallThru()` /
`callThru()`, `noPreserveCache()` / `preserveCache()`, `null` stub
`MODULE_NOT_FOUND` handling, and bare module stubs.

## Testing

- Executed `pnpm --dir core/test-utils test` 5x on Node.js and
`JS_RUNTIME=bun MOCHA_PARALLEL=false bun --bun run --cwd core/test-utils
test` 5x on Bun ($\ge 95\%$ confidence, 25/25 unit tests passing).
- Verified strict lint and TypeScript checks pass via `node
./bin/linter.mjs --strict` and `ci/run_conditional_tests.sh --strict`.

## Alternatives

- Including `createProxyquire` directly inside #9643 alongside the
`common`, `bigquery`, `datastore`, and `google-cloud-dns` migrations was
considered, but because `.npmrc` sets `link-workspace-packages=false`
and `enable-pre-post-scripts=true`, doing so before releasing
`google-test-utils` requires extra `--filter "./core/test-utils"
--ignore-scripts` and workspace-linking flags across the YAML files in
the stack.
- Not merging this PR would leave those temporary YAML workarounds in
the stack PRs.

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@danieljbruce danieljbruce left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

@danieljbruce
danieljbruce marked this pull request as ready for review October 29, 2026 15:46
@danieljbruce
danieljbruce requested a review from a team as a code owner October 29, 2026 15:46
@github-actions
github-actions Bot requested a review from shivanee-p October 29, 2026 15:46
@danieljbruce
danieljbruce requested a review from quirogas October 29, 2026 15:50

after(() => {
sdk.shutdown();
return sdk.shutdown();

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.

Nice catch returning sdk.shutdown() here (and on line 506) as well as returning assert.rejects(...) in test/index.ts and test/sink.ts so Mocha properly awaits teardown and rejection assertions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

Base automatically changed from fix/remove-proxyquire-shim-core-dns-ds-bq to main October 30, 2026 19:09
@danieljbruce
danieljbruce requested a review from a team as a code owner October 30, 2026 19:09
danieljbruce added a commit that referenced this pull request Oct 30, 2026
…dns (#9643)

## Description

Centralizes the runtime-agnostic `proxyquire` helper in
`core/test-utils` (`google-test-utils`, Path 1B) and replaces the global
`--proxyquire-shim` in `core/common`, `handwritten/bigquery`,
`handwritten/datastore`, and `handwritten/google-cloud-dns`.

## Impact

Removes `--proxyquire-shim` from `common`, `bigquery`, `datastore`, and
`google-cloud-dns` test scripts while eliminating per-package
`test/proxyquire.ts` duplication by exporting `proxyquire` and
`createProxyquire` from `google-test-utils`.

## Changes

- **Part 2 of 5 in stacked PR series**: #9642 -> **#9643** -> #9644 ->
#9645 -> #9646 (b/570091189).
- `core/test-utils`: Add runtime-agnostic `src/proxyquire.ts` helper
(`proxyquire`, `createProxyquire`, `Proxyquire`, `ProxyquireStubs`)
built on `Module.prototype.require` and `require.cache` with automatic
caller path resolution (`Error.prepareStackTrace`) and unit tests in
`test/proxyquire.test.ts`.
- `core/common`, `handwritten/bigquery`, `handwritten/datastore`,
`handwritten/google-cloud-dns`: Import `{proxyquire}` from
`'google-test-utils'`, remove per-package `test/proxyquire.ts` shims,
and remove `--proxyquire-shim` from `package.json` test scripts.

## Testing

- Executed `pnpm test` in `core/test-utils` and under both Node.js and
Bun (`JS_RUNTIME=bun`) in `core/common`, `handwritten/bigquery`,
`handwritten/datastore`, and `handwritten/google-cloud-dns`.
- Verified strict lint and type checks pass via `bin/linter.mjs
--strict`.

## Alternatives

- Per-package `test/proxyquire.ts` files (Path 1A) were replaced with a
single centralized implementation in `core/test-utils`
(`google-test-utils`, Path 1B) per review discussion in b/570091189.
@danieljbruce
danieljbruce merged commit cae33e8 into main Oct 30, 2026
49 of 68 checks passed
@danieljbruce
danieljbruce deleted the fix/remove-proxyquire-shim-logging-pubsub branch October 30, 2026 19:24
danieljbruce added a commit that referenced this pull request Oct 30, 2026
…9645)

## Description

Replaces the global `--proxyquire-shim` in `handwritten/bigtable`,
`handwritten/spanner`, and `handwritten/storage` using the centralized
`proxyquire` helper from `google-test-utils` (Path 1B).

## Impact

Removes `--proxyquire-shim` from `bigtable`, `spanner`, and `storage`
unit test scripts without duplicating per-package `test/proxyquire.ts`
helpers.

## Changes

- **Part 4 of 5 in stacked PR series**: #9642 -> #9643 -> #9644 ->
**#9645** -> #9646 (b/570091189).
- Stacked on #9644.
- `handwritten/bigtable`, `handwritten/spanner`, `handwritten/storage`:
Import `{proxyquire}` from `'google-test-utils'`, remove per-package
`test/proxyquire.ts` helpers, and remove `--proxyquire-shim` from
`package.json` test scripts.
- `handwritten/bigtable/test/base64keymap.ts`: Remove unused
`proxyquire` import.
- `handwritten/spanner/observability-test/helper.ts` & `spanner.ts`:
Call `context.disable()` in `setGlobalContextManager` and re-register
the active context manager in `EndToEnd` `beforeEach` so OpenTelemetry
context propagation remains isolated across test suites.

## Testing

- Executed `pnpm test` under both Node.js and Bun (`JS_RUNTIME=bun`) in
`handwritten/bigtable`, `handwritten/spanner`, and
`handwritten/storage`.
- Verified strict lint and type checks pass via `bin/linter.mjs
--strict`.

## Alternatives

- Per-package `test/proxyquire.ts` files (Path 1A) were replaced with
the centralized `google-test-utils` helper (Path 1B) per review
discussion in b/570091189.
danieljbruce added a commit that referenced this pull request Oct 30, 2026
## Description

Removes bin/proxyquire-bun-shim.cjs and all remaining Mocha and runner
shim configuration.

## Impact

Eliminates the global Bun proxyquire preload shim from the test runner.

## Changes

- **Part 5 of 5 in stacked PR series**: #9642 -> #9643 -> #9644 -> #9645
-> **#9646** (b/570680750).
- Stacked on #9645.
- Delete `bin/proxyquire-bun-shim.cjs`.
- Remove `--proxyquire-shim`, `BUN_ENABLE_PROXYQUIRE_SHIM`, and
`proxyquire-bun-shim.cjs` preloading from `bin/run-test.cjs`.
- Remove `proxyquire-bun-shim.cjs` from `.mocharc.cjs` and all 11
`core/packages/*/.mocharc.js` configuration files.

## Testing

- Verified unit tests across all migrated packages pass under both
Node.js and Bun (`JS_RUNTIME=bun`) without
`bin/proxyquire-bun-shim.cjs`.
- Verified strict lint and type checks pass via `bin/linter.mjs
--strict`.

## Alternatives

- Not merging this pull request was considered, which would leave dead
shim code and unused `--proxyquire-shim` runner flags in the repository.
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.

2 participants