Skip to content

test: add unit tests for TypeScript ChainAgent and BedrockFlowsAgent#540

Open
nuthalapativarun wants to merge 1 commit into
2FastLabs:mainfrom
nuthalapativarun:test/539-ts-chain-flows-agent-tests
Open

test: add unit tests for TypeScript ChainAgent and BedrockFlowsAgent#540
nuthalapativarun wants to merge 1 commit into
2FastLabs:mainfrom
nuthalapativarun:test/539-ts-chain-flows-agent-tests

Conversation

@nuthalapativarun

Copy link
Copy Markdown

Issue Link (REQUIRED)

Fixes #539

Summary

Changes

Adds unit test coverage for two previously untested TypeScript agents:

ChainAgent.test.ts (12 tests)

  • Constructor: empty-agents guard throws, single-agent init, custom defaultOutput
  • processRequest: single-agent pass-through, multi-agent pipeline (output of agent N becomes input to agent N+1), additionalParams forwarded to every agent, default response on empty content, last-agent streaming allowed, intermediate streaming returns default response, agent error propagates

BedrockFlowsAgent.test.ts (8 tests)

  • Constructor: no-region default client, region-specific client, pre-built client bypass, enableTrace default/set
  • processRequest: happy-path flow invocation + decode, missing response stream error, custom flowInputEncoder, custom flowOutputDecoder, client-level error wrapping

Both files follow the same mock/describe/it structure as the existing LambdaAgent.test.ts.

User experience

Before: npx jest produced no output for ChainAgent or BedrockFlowsAgent.

After: 20 new assertions covering the core behaviour and error paths of both agents.

Checklist

  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented
  • I have linked this PR to an existing issue (required)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Adds ChainAgent.test.ts (12 tests) covering constructor validation, the
chaining pipeline, passthrough of additionalParams, streaming on the
last agent, error propagation, and defaultOutput fallback.

Adds BedrockFlowsAgent.test.ts (8 tests) covering constructor options,
processRequest happy path, custom encoder/decoder, missing response
stream, and client error wrapping.

Closes 2FastLabs#539
@cornelcroi

Copy link
Copy Markdown
Collaborator

Hey @nuthalapativarun, nice work — ChainAgent and BedrockFlowsAgent had zero test coverage before this, so this is a real gap being filled. Follows the existing patterns well too.

One thing that needs to be fixed before merging:

Required:

In the ChainAgent error propagation test you're using rejects.toMatch(...) instead of rejects.toThrow(...). Every other async error assertion in the codebase uses toThrow. Using toMatch on an Error object only passes by accident due to string coercion — if the thrown type ever changes this test could silently misfire. Quick fix, just swap it out.

Smaller things (non-blocking):

  • The pre-built client constructor test verifies that BedrockAgentRuntimeClient is not called, but doesn't assert that addUserAgentMiddleware was called with the injected client — easy thing to add if you want more coverage there.
  • CI hasn't run on the branch yet, need to see it pass before merging.

Otherwise this looks good to go!

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.

test: add unit tests for TypeScript ChainAgent and BedrockFlowsAgent

2 participants