Skip to content

[TST] Fix vacuous-pass assertions in add.collections tests (rejects.toThrow) - #7508

Open
Nimra3261 wants to merge 2 commits into
chroma-core:mainfrom
Nimra3261:idiomatic-jest-add-collections
Open

Nimra3261 wants to merge 2 commits into
chroma-core:mainfrom
Nimra3261:idiomatic-jest-add-collections

Conversation

@Nimra3261

Copy link
Copy Markdown
Contributor

Two tests in add.collections.test.ts wrapped the assertion inside the catch block:

try {
  await collection.add({ ids, embeddings, metadatas });
} catch (e: any) {
  expect(e.message).toMatch("duplicates");
}

If collection.add() didn't throw, the catch body (and its expect()) never ran and the test passed vacuously instead of failing - not just a style issue, a real gap in coverage.

Rewritten as await expect(...).rejects.toThrow(...), matching the pattern the file already uses two tests above ("should error on non existing collection") and the fix #2135 proposed for the old clients/js client before it was replaced by clients/new-js.

Scoped to this one file rather than the full sweep in #2135, which was closed for being too large to review - happy to follow up with more files in separate PRs if this pattern is welcome.

Addresses #2801

Two tests in add.collections.test.ts wrapped the assertion inside the
catch block: if collection.add() didn't throw, the catch body (and its
expect()) never ran and the test passed vacuously instead of failing.
Rewritten as await expect(...).rejects.toThrow(...), matching the
pattern the file already uses two tests above (should error on non
existing collection) and the fix suggested in chroma-core#2135.

Scoped to this one file rather than the full sweep in chroma-core#2135, which was
closed for being too large to review.

Addresses chroma-core#2801

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions

Copy link
Copy Markdown

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@ErenAta16 ErenAta16 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct, and worth doing. The diagnosis holds exactly as written: with the assertion inside catch, a non-throwing add() skips the block entirely and the test reports green having asserted nothing. Both of these were in that state, so the "should error on duplicate ids" case would not have caught a regression that stopped rejecting duplicates, which is the one thing it exists to catch.

rejects.toThrow(...) is the right replacement rather than adding expect.assertions(1) to the existing shape. expect.assertions would have made the vacuous pass fail, but it fails with "expected 1 assertion, received 0" rather than saying the call didn't reject, so the new form is both stricter and clearer at failure time.

Semantics are preserved: expect(e.message).toMatch("duplicates") with a string argument is a substring check, and rejects.toThrow("duplicates") is also a substring check against the message, so neither test got looser or tighter. Passing an async arrow to expect() and unwrapping with .rejects is supported in Jest 29 (this package is on jest ^29.5.0), so the function form is fine.

Only cosmetic thing: #7509 passes the promise directly (expect(promise).rejects...) while this one wraps in async () => {}. Both work, and lining them up would be nice if you touch these again, but not worth a round trip on its own.

Pass the promise directly to expect() instead of wrapping in an async
arrow, matching the style used in chroma-core#7509. Purely cosmetic - same
assertions, same behavior - per review feedback on this PR.
danielenricocahall pushed a commit to danielenricocahall/chroma that referenced this pull request Aug 3, 2026
New library + binary crate at rust/foundation-api/. Hosts the future
foundation HTTP route surface as a sibling to chroma-frontend, per the
"Foundation API: Long-Term Home" ADR.

Depends on frontend-core (chroma-core#7070) for Axum scaffolding, middleware, the
AuthenticateAndAuthorize trait, config primitives, error types, and OTEL
bootstrap. Does NOT depend on chroma-frontend and does NOT register any
Chroma CRUD routes. The /api/foundation/* handlers will land via chroma-core#7442,
chroma-core#7507, chroma-core#7508, chroma-core#7509 by registering on the empty routes module.

## Description of changes

_Summarize the changes made by this PR._

- Improvements & Bug fixes
  - ...
- New functionality
  - ...

## Test plan

_How are these changes tested?_

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Migration plan

_Are there any migrations, or any forwards/backwards compatibility
changes needed in order to make sure this change deploys reliably?_

## Observability plan

_What is the plan to instrument and monitor this change?_

## Documentation Changes

_Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
section](https://github.com/chroma-core/chroma/tree/main/docs/docs.trychroma.com)?_
@Nimra3261 Nimra3261 changed the title Fix vacuous-pass assertions in add.collections tests (rejects.toThrow) [TST] Fix vacuous-pass assertions in add.collections tests (rejects.toThrow) Aug 30, 2026

This branch has not been deployed

No deployments
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