Skip to content

chore(entities): Layer 1 unit tests for @agenta/entities molecules#4339

Open
bekossy wants to merge 5 commits into
mainfrom
chore/entities-layer1-unit-tests
Open

chore(entities): Layer 1 unit tests for @agenta/entities molecules#4339
bekossy wants to merge 5 commits into
mainfrom
chore/entities-layer1-unit-tests

Conversation

@bekossy
Copy link
Copy Markdown
Member

@bekossy bekossy commented May 15, 2026

Summary

Adds a complete Layer 1 (pure Jotai, no backend) unit test suite for the @agenta/entities package. All tests run in a Node environment via Vitest with a plain createStore() per test for full isolation.

327 tests across 12 files, passing in < 6 s.

What's covered

File Tests Entity
molecule.test.ts 35 createMolecule factory (draft, isDirty, lifecycle, cleanup)
local-molecule.test.ts 35 createLocalMolecule factory (inline entities, isNew)
draft-state.test.ts 32 Low-level draft atom family
normalize.test.ts 27 normalizeValueForComparison utility
loadable-store.test.ts 29 loadableStore atoms and actions
port-helpers.test.ts 31 Port extraction helpers
revision-table-state.test.ts 35 Column/row pending-op reducers
testset-molecule.test.ts 35 testsetMolecule (filters, draft, null-safe selectors)
testcase-molecule.test.ts 39 testcaseMolecule (add/delete/create, selection draft)
trace-span-molecule.test.ts 38 traceSpanMolecule (local.set seeding, derived atoms, getAgDataPath)
environment-molecule.test.ts 27 environmentMolecule (deployments, revisionsList, lifecycle)
__smoke__/entity-imports.test.ts 4 Import smoke tests for all four molecules

Infrastructure added

  • vitest.config.ts — Node environment, JUnit reporter, v8 coverage
  • tests/__mocks__/agenta-ui.ts — Lightweight stub that prevents the antd transform timeout (antd pulls in a large ESM tree that Vitest can't transform in time; this stub redirects @agenta/ui imports without touching the real package)
  • web/packages/agenta-entities/.gitignore — Excludes generated test-results/ and coverage/ from git

Bug fix included

src/testset/state/paginatedStore.tstestsetsExportFormatAtom used atomWithStorage without a custom storageAdapter, which accessed localStorage at module scope and threw in Node. Fixed by passing stringStorage from @agenta/shared/state as the third argument.

Test plan

  • cd web/packages/agenta-entities && pnpm vitest run — all 327 tests pass
  • pnpm vitest run --coverage — coverage report generated under coverage/
  • Confirm test-results/ and coverage/ are not committed (excluded by .gitignore)
  • No regressions in existing entity behavior (only new test files and one bug fix)

🤖 Generated with Claude Code

bekossy and others added 4 commits May 14, 2026 10:43
…ion functions

- Implement unit tests for createEntityDraftState in draft-state.test.ts, covering initial state, updates, draft clearing, and custom isDirty functionality.
- Add tests for loadable store functionality in loadable-store.test.ts, including default state, mode switching, connected source updates, and instance isolation.
- Create tests for normalizeValueForComparison in normalize.test.ts, ensuring correct handling of various data types and structures.
- Configure Vitest to output test results in JUnit format and set up coverage reporting in vitest.config.ts.
- Generate initial JUnit test results file for CI integration.
…et molecule

- Implemented unit tests for revision table state atoms and reducers, covering initial state, column and row operations, and pending changes.
- Created unit tests for testcase molecule, validating molecule shape, ID tracking, actions, and selection draft operations.
- Added unit tests for testset molecule, focusing on filter atoms, draft operations, local entity creation, and null-safe selectors.
- Updated Vitest configuration to include path aliasing for @agenta/ui to avoid unnecessary transformations during testing.
- Implement comprehensive unit tests for environmentMolecule covering molecule shape, isNewEntity, draft operations, null-safe selectors, and lifecycle.
- Introduce unit tests for traceSpanMolecule focusing on molecule shape, local data API, derived atoms, draft operations, isNew detection, and lifecycle management.
…lts and coverage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment May 15, 2026 11:02am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Tests

    • Added comprehensive unit test suite for entity state management, including draft state handling, molecule lifecycle, local entity creation, and utility functions.
    • Configured Vitest testing framework with coverage reporting and isolated test environments.
  • Chores

    • Updated project configuration for test artifact management and added development testing dependencies.

Walkthrough

This pull request adds a comprehensive Vitest unit testing infrastructure for the agenta-entities package, including test framework configuration, 12 new unit test files covering draft state, molecule implementations, state management, and utility functions, plus package dependencies and supporting mocks.

Changes

Test Suite Implementation

Layer / File(s) Summary
Test Framework & Dependencies
web/packages/agenta-entities/vitest.config.ts, package.json, .gitignore, tests/__mocks__/agenta-ui.ts, tests/unit/__smoke__/entity-imports.test.ts
Vitest configuration routes @agenta/ui imports to a local mock, sets Node environment for atom tests, configures coverage and JUnit reporters, and defines test scripts. Development dependencies add vitest, jotai, and jotai-family. Import smoke test validates that entity molecule modules import without errors.
Persistent Storage Configuration
src/testset/state/paginatedStore.ts
Import and use stringStorage explicitly in testsetsExportFormatAtom to ensure consistent persistence of testset export format (csv / json) in browser storage.
Draft State & Base Molecule Framework
tests/unit/draft-state.test.ts, tests/unit/molecule.test.ts
Comprehensive tests for createEntityDraftState covering initial state, draft merging, dirty tracking, discard behavior, field exclusion, and custom dirty detection; and foundational createMolecule tests for server data exposure, draft reducers, soft-delete semantics, local entity creation, lifecycle hooks (onMount/onUnmount), and imperative APIs.
Local Molecule Implementation
tests/unit/local-molecule.test.ts
Tests for createLocalMolecule covering CRUD operations (create/createWithId/update/delete/clear), local ID prefixing, transform and validate hooks, derived atoms (isDirty, isNew, serverData, query), and imperative getters.
Domain-Specific Molecule Tests
tests/unit/environment-molecule.test.ts, tests/unit/testset-molecule.test.ts, tests/unit/testcase-molecule.test.ts, tests/unit/trace-span-molecule.test.ts
Molecule-specific tests validating public API shape, draft operations with per-ID isolation, isNew detection (environment always false; testset/trace-span prefix-based; testcase local prefixed), null-safe selectors, batch entity creation (testcase), selection draft workflow (testcase), and lifecycle tracking tied to server data access.
State Management & Utility Testing
tests/unit/loadable-store.test.ts, tests/unit/revision-table-state.test.ts, tests/unit/normalize.test.ts, tests/unit/port-helpers.test.ts
Tests for loadable-store atom defaults and mode switching based on connection state; revision-table reducers for column/row operations with deduplication and per-revision isolation; normalizeValueForComparison across nullish, string, JSON, and primitive inputs; and port helper functions for schema reference resolution, type detection, path extraction, and variable grouping.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding Layer 1 unit tests for @agenta/entities molecules via Vitest.
Description check ✅ Passed The description is thorough and directly related to the changeset, detailing all 327 tests across 12 files, infrastructure additions, a bug fix, and the test plan.
Docstring Coverage ✅ Passed Docstring coverage is 76.92% which is sufficient. The required threshold is 60.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/entities-layer1-unit-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. tests typescript labels May 15, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
web/packages/agenta-entities/tests/unit/draft-state.test.ts (1)

22-26: ⚡ Quick win

Use interface for the Note object shape.

Replace the type Note = { ... } declaration with an interface Note { ... } to match repository TypeScript conventions.

As per coding guidelines, **/*.{ts,tsx}: Prefer interface for defining object shapes in TypeScript.

web/packages/agenta-entities/tests/unit/molecule.test.ts (1)

24-28: ⚡ Quick win

Use interface for the Post object shape.

Switch type Post = { ... } to interface Post { ... } to align with the project’s TypeScript style rule.

As per coding guidelines, **/*.{ts,tsx}: Prefer interface for defining object shapes in TypeScript.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 61bbb062-768e-4316-aab6-7f03a8e42c31

📥 Commits

Reviewing files that changed from the base of the PR and between 50c42b1 and af09aaa.

⛔ Files ignored due to path filters (1)
  • web/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • web/packages/agenta-entities/.gitignore
  • web/packages/agenta-entities/package.json
  • web/packages/agenta-entities/src/testset/state/paginatedStore.ts
  • web/packages/agenta-entities/tests/__mocks__/agenta-ui.ts
  • web/packages/agenta-entities/tests/unit/__smoke__/entity-imports.test.ts
  • web/packages/agenta-entities/tests/unit/draft-state.test.ts
  • web/packages/agenta-entities/tests/unit/environment-molecule.test.ts
  • web/packages/agenta-entities/tests/unit/loadable-store.test.ts
  • web/packages/agenta-entities/tests/unit/local-molecule.test.ts
  • web/packages/agenta-entities/tests/unit/molecule.test.ts
  • web/packages/agenta-entities/tests/unit/normalize.test.ts
  • web/packages/agenta-entities/tests/unit/port-helpers.test.ts
  • web/packages/agenta-entities/tests/unit/revision-table-state.test.ts
  • web/packages/agenta-entities/tests/unit/testcase-molecule.test.ts
  • web/packages/agenta-entities/tests/unit/testset-molecule.test.ts
  • web/packages/agenta-entities/tests/unit/trace-span-molecule.test.ts
  • web/packages/agenta-entities/vitest.config.ts

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af09aaae77

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -29,6 +29,7 @@ export const testsetsSearchTermAtom = atom<string>("")
export const testsetsExportFormatAtom = atomWithStorage<"csv" | "json">(
"agenta:testsets:export-format",
"csv",
stringStorage as Parameters<typeof atomWithStorage>[2],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve JSON-encoded export preferences

When a browser already has agenta:testsets:export-format from the previous atomWithStorage implementation, the stored value is JSON-encoded (for example, "json"). Switching this atom to raw stringStorage returns that raw quoted string instead of json, so the persisted preference no longer matches the expected "csv" | "json" values and downstream export calls can send an invalid file_type until the user reselects a format. Please either migrate/parse existing JSON values here or keep the JSON storage for this key.

Useful? React with 👍 / 👎.

"test": "pnpm run types:check && pnpm run lint"
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add Vitest's coverage provider dependency

test:coverage now invokes vitest run --coverage, and vitest.config.ts selects the v8 provider, but this package only adds vitest and not @vitest/coverage-v8. Vitest's coverage guide says the v8/istanbul support packages are optional and shows installing @vitest/coverage-v8 manually; in non-interactive CI this script will fail when the provider is missing instead of producing coverage.

Useful? React with 👍 / 👎.

@bekossy bekossy requested a review from ardaerzin May 15, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files. tests typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant