test(frontend): add unit tests for @agenta/shared and @agenta/annotation packages#4539
test(frontend): add unit tests for @agenta/shared and @agenta/annotation packages#4539bekossy wants to merge 6 commits into
Conversation
- Created unit tests for data transformation utilities including error extraction, response status preservation, and metadata stripping. - Added tests for formatting utilities covering number, currency, latency, and percentage formatting. - Implemented tests for path utilities to validate object navigation and manipulation. - Developed tests for slug generation and validation functions. - Added tests for template variable validation and extraction. - Included tests for various validators including UUID and HTTP URL validation. - Configured Vitest for running tests with coverage reporting and JUnit output.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds Vitest configs, package script/devDependency updates, a lightweight ChangesTest Infrastructure Setup
Annotation Package Unit Tests
Shared Package Utilities Unit Tests
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f15b7fb2c
ℹ️ 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".
…annotation packages Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
web/packages/agenta-annotation/test-results/junit.xml (1)
1-164:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDo not commit generated test result files.
JUnit XML test reports are runtime artifacts produced during test execution and should not be committed to version control. These files:
- Change on every test run with new timestamps and execution times
- Are automatically regenerated in CI/CD pipelines
- Pollute the repository history with ephemeral data
Please add
test-results/to your.gitignoreand remove this file from the commit.🔧 Recommended action
- Remove the file from git:
git rm web/packages/agenta-annotation/test-results/junit.xml
- Add to
.gitignore(if not already present):# Test artifacts **/test-results/
- The file will be regenerated locally when running tests and in CI/CD as needed.
web/packages/agenta-shared/test-results/junit.xml (1)
1-390:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDo not commit generated test result files.
JUnit XML test reports are runtime artifacts produced during test execution and should not be committed to version control. These files:
- Change on every test run with new timestamps and execution times
- Are automatically regenerated in CI/CD pipelines
- Pollute the repository history with ephemeral data
Please add
test-results/to your.gitignoreand remove this file from the commit.🔧 Recommended action
- Remove the file from git:
git rm web/packages/agenta-shared/test-results/junit.xml
- Add to
.gitignore(if not already present):# Test artifacts **/test-results/
- The file will be regenerated locally when running tests and in CI/CD as needed.
🧹 Nitpick comments (1)
web/packages/agenta-shared/tests/unit/slug.test.ts (1)
69-73: ⚡ Quick winMake random-suffix tests deterministic to avoid future flakiness.
Line 69 and Line 135 currently rely on probabilistic behavior. If
Math.randomis stubbed globally in another test, these can become brittle. Prefer mocking randomness in this suite and asserting exact outputs.Proposed deterministic test pattern
import {describe, expect, it} from "vitest" +import {vi} from "vitest" describe("generateSlugWithSuffix", () => { - it("produces different slugs on repeated calls (randomness)", () => { - const slugs = new Set(Array.from({length: 10}, () => generateSlugWithSuffix("app"))) - // With 36^4 = ~1.7M possibilities, collision probability over 10 draws is negligible - expect(slugs.size).toBeGreaterThan(1) + it("produces expected format with deterministic random source", () => { + const spy = vi.spyOn(Math, "random").mockReturnValue(0.123456) + const slug = generateSlugWithSuffix("app") + expect(slug).toMatch(/^app-[a-z0-9]{4}$/) + spy.mockRestore() }) })Also applies to: 135-140
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ca32a0b2-ecee-442d-b886-84dda4dcadbb
⛔ Files ignored due to path filters (1)
web/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (15)
web/packages/agenta-annotation/package.jsonweb/packages/agenta-annotation/test-results/junit.xmlweb/packages/agenta-annotation/tests/__mocks__/agenta-ui.tsweb/packages/agenta-annotation/tests/unit/annotation-form-helpers.test.tsweb/packages/agenta-annotation/tests/unit/testset-sync.test.tsweb/packages/agenta-annotation/vitest.config.tsweb/packages/agenta-shared/package.jsonweb/packages/agenta-shared/test-results/junit.xmlweb/packages/agenta-shared/tests/unit/data-transforms.test.tsweb/packages/agenta-shared/tests/unit/formatters.test.tsweb/packages/agenta-shared/tests/unit/path-utils.test.tsweb/packages/agenta-shared/tests/unit/slug.test.tsweb/packages/agenta-shared/tests/unit/template-variable.test.tsweb/packages/agenta-shared/tests/unit/validators-and-ids.test.tsweb/packages/agenta-shared/vitest.config.ts
…verage, template-variable alignment - Replace `as any` fixture casts with `as unknown as T` in annotation tests - Fix incorrect Annotation import source in testset-sync (now from @agenta/entities/annotation) - Add Testcase type import and remove all as-any call-site casts in testset-sync - Add falsy-root short-circuit tests for getValueAtPath (0, false, "", null) - Realign template-variable tests to the strict envelope-slot behavior on main Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Railway Preview Environment
|
…notation-packages
…SONPath policy The release/v0.102.0 merge updated validateTemplateVariable to accept any well-formed $.x expression without checking against known envelope slots (post-mustache QA: slot mismatches surface as API errors, not UI errors). Five tests still asserted the old strict behavior and were failing. Updated them to match the intentional permissive policy documented in the source. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Context
@agenta/sharedand@agenta/annotationhad no unit test infrastructure. Pure utility functions — formatters, validators, slug helpers, path traversal — and annotation state helpers were only exercised end-to-end, making regressions invisible until they hit the UI.Changes
Adds Vitest with coverage reporting to both packages and 267 unit tests covering their core pure functions.
@agenta/shared(189 tests): validators and UUID converters, slug generation and parsing, number/latency/token formatters,getValueAtPath/setValueAtPath/deleteValueAtPath(including JSON-string traversal),validateTemplateVariable/extractTemplateExpression, and API error / metadata stripping utilities.@agenta/annotation(78 tests): queue-scoped annotation selection, testcase tag merging, testset sync preview, row remapping and export helpers, and annotation form field extraction.The
@agenta/annotationvitest config stubs@agenta/uiso tests run in a fast Node environment — the real package pulls in antd and causes the transformer to time out.The
template-variabletests reflect the post-mustache QA decision: any well-formed$.xis valid in the playground; the root becomes a testcase column and slot mismatches surface as API errors at runtime rather than UI validation errors.Tests
pnpm --filter @agenta/shared test:unit— 189/189 passpnpm --filter @agenta/annotation test:unit— 78/78 pass🤖 Generated with Claude Code