DEV Community

Cover image for Test the npm Package, Not Just the Monorepo

Test the npm Package, Not Just the Monorepo

Raju Dandigam on November 21, 2026

A tracing adapter can pass its internal tests while capturing nothing in an installed application. The imports resolve. The tool executes. No exce...
Collapse
 
prascli profile image
Indra Prasetya •

The npm package test gap is real. In agent-inspect@6.31.35, the monorepo's internal vitest suite passes, but npm pack && npm install -g followed by the same fixture shows the file-writer serializer drops error.code on the manual inspectRun() path — a field the instance-based createInspector() + fileWriter() path retains. The difference is visible in the schema version: manual path writes schema 0.1, instance path writes schema 1.0. Running the probe suite against the installed tarball catches this; running only against the monorepo source does not.

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@prascli Thanks for the precise reproduction. I haven’t verified the packed 6.31.35 behavior yet, so I won’t call it fixed or dismiss it. The manual inspectRun() versus createInspector() schema difference is exactly the installed-package boundary this article argues for. I’ll reproduce both paths from the tarball and add a regression if confirmed.

Collapse
 
gautamtalksdev profile image
Gautam K •

"Passes its internal tests while capturing nothing in an installed application" is such a common trap. Testing the packed tarball in a clean project is the only test that matches what users actually install. Good write up.

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@gautamtalksdev Exactly. The useful assertion is the combination of an independent SDK call counter and persisted trace readback; a green tool result alone can hide a missing span. I’m keeping the matrix explicit about which package, Node, module-system, and transport cells were actually exercised.

Collapse
 
innokentyb profile image
Kent Bodrov •

The independent server counter makes missing spans visible. A further case I’d test is two concurrent runs with distinct run IDs and distinct echo values: both server calls should happen once, and each persisted trace should contain only its own run’s calls. That checks context isolation, not just total span count—a wrapper could capture both calls but attach one to the wrong run. Does the current fixture exercise overlapping runs?

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@innokentyb Good catch. The fixture shown here has one inspectRun, so it does not establish overlapping-run isolation. Two distinct run IDs and echo values, followed by per-trace assertions, would catch misattribution even when the total span count looks right. That is a valuable next matrix cell.

Collapse
 
aheadkit profile image
AheadKit •

This one hit a nerve. I once shipped something where the monorepo tests were all green and the installed package silently did nothing, because two copies of the same context module were living side by side and neither one complained. The independent server counter is the part I'd copy, honestly, because "the trace has a span" proves nothing if you never counted the real calls. Do you run this consumer test on every release, or only when the adapter itself changes?

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@aheadkit That failure mode is exactly why the handler counter sits outside the adapter. This article shows an installed-package consumer test, but I don’t want to imply it currently runs on every release. It belongs in a publish gate, since bundling can change even when the adapter source does not.

Collapse
 
ademisler profile image
Adem İşler •

the independent server counter is the strongest assertion here. i'd add a negative fixture that intentionally loads a second bundled run-context singleton: callTool still returns fixture-ok and the handler count stays at 1, while one of the two expected spans disappears. that would prove the test catches silent capture loss, not just a healthy package. do you also run a clean npm pack -> install-from-tarball smoke test before publishing?

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@ademisler The example installs the published 6.31.35 packages through a lockfile; that is different from saying a clean npm pack tarball test is already a prepublish gate on every release. Your deliberately duplicated run-context singleton is a strong negative control because the tool can still succeed while capture drops out. Thanks for sharpening that distinction.

Collapse
 
kate_astrid profile image
kate astrid •

Saving this as my release checklist:

  • npm pack
  • clean install in a fresh project
  • ESM and CommonJS consumers
  • an independent call counter
  • untested cells visible in the matrix

Thanks for writing it up so clearly, Raju! 🧪

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@kate_astrid Thanks for turning it into a checklist. I would keep trace readback and the independent server count side by side, so the test catches silent missing capture. If Docker becomes a CI claim, pin the image digest as well as the package lockfile.

Collapse
 
parasraju profile image
Paras •

Testing both ESM and CommonJS is a smart move.

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@parasraju Yes—ESM and CommonJS can resolve different build outputs even when the source tests are green. Exercising both through the public package entry points is a small check with a lot of value.