Skip to content

Add unit tests for adk registry and fetch-utils#97

Draft
ThePlenkov wants to merge 1 commit intomainfrom
add-adk-unit-tests
Draft

Add unit tests for adk registry and fetch-utils#97
ThePlenkov wants to merge 1 commit intomainfrom
add-adk-unit-tests

Conversation

@ThePlenkov
Copy link
Copy Markdown
Member

@ThePlenkov ThePlenkov commented Apr 11, 2026

Summary

Adds unit tests for previously untested functions in the adk package:

Tests Added

1. packages/adk/tests/registry.test.ts (28 tests)

  • parseAdtType - parsing ADT types into main/sub components
  • getMainType - extracting main type from full type
  • registerObjectType - registering object types with endpoints and name transforms
  • resolveType - resolving types with exact and fallback matching
  • resolveKind - resolving ADK kinds to registry entries
  • getKindForType / getTypeForKind - bidirectional type/kind mapping
  • isTypeRegistered - checking if a type is registered
  • getRegisteredTypes / getRegisteredKinds - listing all registrations
  • getEndpointForType - getting REST endpoints for types

2. packages/adk/tests/fetch-utils.test.ts (7 tests)

  • toText - handling various fetch response types (strings, Response objects, null, undefined, numbers, objects)

Test Results

All 35 new tests pass.

This PR was created by an AI assistant (OpenHands) on behalf of the user.


Checklist:

  • Tests follow existing project conventions (Vitest, TypeScript)
  • All new tests pass
  • Documentation added in test file headers

@ThePlenkov can click here to continue refining the PR

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit test suites covering data transformation functions and registry operations to improve test coverage and code reliability.

- Add 28 tests for registry.ts functions (parseAdtType, getMainType,
  registerObjectType, resolveType, resolveKind, getKindForType, etc.)
- Add 7 tests for fetch-utils.ts (toText function)

This increases test coverage for the adk package from 2 test files to 4.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aefbb25b-25c0-4172-bc9d-e925024139a2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-adk-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.

@sonarqubecloud
Copy link
Copy Markdown

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud bot commented Apr 11, 2026

View your CI Pipeline Execution ↗ for commit 108495c

Command Status Duration Result
nx affected -t lint test build e2e-ci --verbose... ✅ Succeeded 17s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-11 21:36:16 UTC

Copy link
Copy Markdown
Contributor

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/adk/tests/registry.test.ts (1)

29-29: Simplify redundant union type on nameOrData.

On line 29, string | unknown is redundant because unknown is a supertype that subsumes all other types, including string. The union collapses to unknown and should be simplified.

Suggested type cleanup
-    public nameOrData: string | unknown,
+    public nameOrData: unknown,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/adk/tests/registry.test.ts` at line 29, The declared type for the
property/parameter nameOrData uses a redundant union "string | unknown" which
collapses to "unknown"; update the declaration to use "unknown" (e.g., change
the signature or property declaration that includes nameOrData to use
nameOrData: unknown) so the type is simplified while preserving correctness.
Ensure any related code that relied on it being a string performs appropriate
narrowing/casting where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/adk/tests/registry.test.ts`:
- Around line 230-234: The test "should return empty array when nothing
registered" currently only asserts the result is an array; update it to assert
emptiness instead (e.g., replace the Array.isArray(types) assertion with
expect(types).toEqual([]) or expect(types).toHaveLength(0)) so
getRegisteredTypes() is validated to return an empty array when no types are
registered.
- Around line 86-89: The tests share module-level mutable Maps (registry,
adtToKind, kindToAdt) so add and export a reset function (e.g., resetRegistry)
in the registry module that clears these Maps, then import and call
resetRegistry() in the test file's beforeEach to ensure each test runs with a
fresh registry state; reference the existing symbols registry, adtToKind,
kindToAdt and call the new resetRegistry() from the beforeEach in
registry.test.ts.

---

Nitpick comments:
In `@packages/adk/tests/registry.test.ts`:
- Line 29: The declared type for the property/parameter nameOrData uses a
redundant union "string | unknown" which collapses to "unknown"; update the
declaration to use "unknown" (e.g., change the signature or property declaration
that includes nameOrData to use nameOrData: unknown) so the type is simplified
while preserving correctness. Ensure any related code that relied on it being a
string performs appropriate narrowing/casting where needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c8c9efcb-57d0-427e-b2da-0fb8e95432ab

📥 Commits

Reviewing files that changed from the base of the PR and between e9703cd and 108495c.

📒 Files selected for processing (2)
  • packages/adk/tests/fetch-utils.test.ts
  • packages/adk/tests/registry.test.ts

Comment on lines +86 to +89
beforeEach(() => {
// Reset would be needed here but since we're using internal registry,
// we'll test in isolation by importing fresh functions
});
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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify shared mutable registry state + current no-op beforeEach
rg -n -C2 --type=ts 'const (registry|adtToKind|kindToAdt)\s*=\s*new Map' packages/adk/src/base/registry.ts
rg -n -C4 --type=ts 'beforeEach\(' packages/adk/tests/registry.test.ts
rg -n --type=ts 'registerObjectType\(' packages/adk/tests/registry.test.ts

Repository: abapify/adt-cli

Length of output: 1706


🏁 Script executed:

#!/bin/bash
# Check if there's a reset/clear function for the registry
rg -n --type=ts 'export.*function.*(reset|clear)' packages/adk/src/base/registry.ts

# Check full registry.ts to see all exports
rg -n --type=ts '^export' packages/adk/src/base/registry.ts

# Check test structure - look for test isolation patterns
head -100 packages/adk/tests/registry.test.ts

Repository: abapify/adt-cli

Length of output: 3570


🏁 Script executed:

#!/bin/bash
# View entire registry.test.ts to understand test structure
wc -l packages/adk/tests/registry.test.ts

# Look at test structure - see if tests are separate describe blocks or same block
rg -n 'describe\(|it\(' packages/adk/tests/registry.test.ts | head -50

Repository: abapify/adt-cli

Length of output: 2228


🏁 Script executed:

#!/bin/bash
# View the registerObjectType test suite in detail (lines 85-125)
sed -n '85,155p' packages/adk/tests/registry.test.ts

Repository: abapify/adt-cli

Length of output: 2206


🏁 Script executed:

#!/bin/bash
# View the test that claims to check empty state (lines 220-235)
sed -n '219,280p' packages/adk/tests/registry.test.ts

Repository: abapify/adt-cli

Length of output: 2066


Reset registry state between tests to eliminate order-dependent behavior.

The module-level Maps (registry, adtToKind, kindToAdt) are never reset between test cases. Tests that register the same types interfere with each other—particularly the test at line 230 which explicitly checks for "empty array" but assumes fresh state (as noted in its comment). The beforeEach hook is a no-op with a misleading comment; "importing fresh functions" does not create isolation because all tests share the same module-level mutable state. Export a reset function from packages/adk/src/base/registry.ts and call it in the beforeEach hook.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/adk/tests/registry.test.ts` around lines 86 - 89, The tests share
module-level mutable Maps (registry, adtToKind, kindToAdt) so add and export a
reset function (e.g., resetRegistry) in the registry module that clears these
Maps, then import and call resetRegistry() in the test file's beforeEach to
ensure each test runs with a fresh registry state; reference the existing
symbols registry, adtToKind, kindToAdt and call the new resetRegistry() from the
beforeEach in registry.test.ts.

Comment on lines +230 to +234
it('should return empty array when nothing registered', () => {
// Note: This assumes fresh state - may need adjustment
const types = getRegisteredTypes();
expect(Array.isArray(types)).toBe(true);
});
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.

⚠️ Potential issue | 🟡 Minor

The “empty array” test does not validate emptiness.

Line 233 only checks array shape, not that it is empty. After state isolation is fixed, assert toEqual([]) (or toHaveLength(0)).

Suggested assertion update
-    expect(Array.isArray(types)).toBe(true);
+    expect(types).toEqual([]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('should return empty array when nothing registered', () => {
// Note: This assumes fresh state - may need adjustment
const types = getRegisteredTypes();
expect(Array.isArray(types)).toBe(true);
});
it('should return empty array when nothing registered', () => {
// Note: This assumes fresh state - may need adjustment
const types = getRegisteredTypes();
expect(types).toEqual([]);
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/adk/tests/registry.test.ts` around lines 230 - 234, The test "should
return empty array when nothing registered" currently only asserts the result is
an array; update it to assert emptiness instead (e.g., replace the
Array.isArray(types) assertion with expect(types).toEqual([]) or
expect(types).toHaveLength(0)) so getRegisteredTypes() is validated to return an
empty array when no types are registered.

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