-
Notifications
You must be signed in to change notification settings - Fork 99
feat(project): add LLM-as-a-judge and code-based evaluator TUI wizards #2468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f606f57
feat(project): add LLM-as-a-judge and code-based evaluator TUI wizards
tejaskash 94e5585
refactor(tui): show the line count in promptPreview instead of cuttin…
tejaskash 4656785
fix(project): validate evaluator input before any I/O
tejaskash e0454ca
Merge remote-tracking branch 'origin/refactor' into feat/project-add-…
tejaskash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
src/handlers/project/add/evaluator/code-based/code-based.screen.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import { afterEach, describe, expect, test } from "bun:test"; | ||
| import { join } from "node:path"; | ||
| import { | ||
| cleanupScreens, | ||
| flatFrame, | ||
| renderScreen, | ||
| waitForFlatText, | ||
| waitForText, | ||
| type RenderScreenResult, | ||
| } from "../../../../../testing"; | ||
| import { createGatewayProjectTestHarness } from "../../gateway-test-support"; | ||
|
|
||
| const { cleanup, inProject, projectSpec, run } = | ||
| createGatewayProjectTestHarness("add-code-based-wizard"); | ||
|
|
||
| afterEach(cleanup); | ||
| afterEach(cleanupScreens); | ||
|
|
||
| const LAMBDA_ARN = "arn:aws:lambda:us-west-2:123456789012:function:refund-policy"; | ||
|
|
||
| async function evaluatorOf(projectRoot: string, name: string) { | ||
| return ((await projectSpec(projectRoot)).evaluators ?? []).find( | ||
| (evaluator: { name: string }) => evaluator.name === name, | ||
| ); | ||
| } | ||
|
|
||
| async function reachLambdaStep(screen: RenderScreenResult, name: string): Promise<void> { | ||
| await waitForText(screen.lastFrame, "what should this evaluator be called?"); | ||
| await screen.write(name); | ||
| await screen.press("return"); | ||
| await waitForText(screen.lastFrame, "what should it score?"); | ||
| await screen.press("return"); | ||
| await waitForText(screen.lastFrame, "which Lambda should score it?"); | ||
| } | ||
|
|
||
| describe("project add evaluator code-based wizard", () => { | ||
| test("scaffolds the same managed evaluator as the flags", async () => { | ||
| const projectRoot = await inProject(); | ||
| const screen = renderScreen("/agentcore/add/evaluator/code-based"); | ||
| await reachLambdaStep(screen, "refund_policy"); | ||
|
|
||
| expect(screen.lastFrame()).toContain("❯ ● scaffold a new Lambda"); | ||
| expect(screen.lastFrame()).toContain("Python code in app/refund_policy"); | ||
| expect(screen.lastFrame()).toContain("○ timeout"); | ||
| await screen.press("return"); | ||
|
|
||
| await waitForText(screen.lastFrame, "how long may it run?"); | ||
| expect(screen.lastFrame()).toContain("60"); | ||
| await screen.press("backspace"); | ||
| await screen.press("backspace"); | ||
| await screen.write("120"); | ||
| await screen.press("return"); | ||
|
|
||
| await waitForText(screen.lastFrame, "this evaluator will be added to agentcore.json"); | ||
| const review = flatFrame(screen.lastFrame); | ||
| expect(review).toContain("evaluator refund_policy"); | ||
| expect(review).toContain("level SESSION"); | ||
| expect(review).toContain("lambda scaffolded in app/refund_policy"); | ||
| expect(review).toContain("timeout 120 seconds"); | ||
| await screen.press("return"); | ||
|
|
||
| await waitForText(screen.lastFrame, "added evaluator 'refund_policy' to 'TestProject'"); | ||
| await waitForFlatText( | ||
| screen.lastFrame, | ||
| "note: this evaluator returns Pass for every session until you implement app/refund_policy/lambda_function.py", | ||
| ); | ||
| expect( | ||
| await Bun.file(join(projectRoot, "app", "refund_policy", "lambda_function.py")).exists(), | ||
| ).toBe(true); | ||
|
|
||
| await run([ | ||
| "add", | ||
| "evaluator", | ||
| "code-based", | ||
| "--name", | ||
| "flags", | ||
| "--level", | ||
| "SESSION", | ||
| "--timeout-seconds", | ||
| "120", | ||
| ]); | ||
| const flags = await evaluatorOf(projectRoot, "flags"); | ||
| expect(await evaluatorOf(projectRoot, "refund_policy")).toEqual({ | ||
| ...flags, | ||
| name: "refund_policy", | ||
| config: { | ||
| codeBased: { | ||
| managed: { ...flags.config.codeBased.managed, codeLocation: "app/refund_policy" }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await screen.press("return"); | ||
| await waitForText(screen.lastFrame, "add a custom evaluator to the current project"); | ||
| screen.unmount(); | ||
| }, 20000); | ||
|
|
||
| test("an existing Lambda skips the timeout and writes an external config", async () => { | ||
| const projectRoot = await inProject(); | ||
| const screen = renderScreen("/agentcore/add/evaluator/code-based"); | ||
| await reachLambdaStep(screen, "refund_policy"); | ||
|
|
||
| await screen.press("down"); | ||
| await waitForText(screen.lastFrame, "❯ ● use an existing Lambda"); | ||
| expect(screen.lastFrame()).not.toContain("timeout"); | ||
| await screen.press("return"); | ||
| await waitForText(screen.lastFrame, "Lambda ARN"); | ||
| await screen.write(LAMBDA_ARN); | ||
| await screen.press("return"); | ||
|
|
||
| await waitForText(screen.lastFrame, "this evaluator will be added to agentcore.json"); | ||
| const review = flatFrame(screen.lastFrame); | ||
| expect(review.replace(/\s/g, "")).toContain(`lambda${LAMBDA_ARN}`); | ||
| expect(review).not.toContain("timeout"); | ||
| await screen.press("return"); | ||
|
|
||
| await waitForText(screen.lastFrame, "added evaluator 'refund_policy'"); | ||
| expect(screen.lastFrame()).not.toContain("returns Pass"); | ||
| expect((await evaluatorOf(projectRoot, "refund_policy")).config).toEqual({ | ||
| codeBased: { external: { lambdaArn: LAMBDA_ARN } }, | ||
| }); | ||
| expect(await Bun.file(join(projectRoot, "app", "refund_policy")).exists()).toBe(false); | ||
| screen.unmount(); | ||
| }, 20000); | ||
|
|
||
| test.each([ | ||
| [ | ||
| "a malformed Lambda ARN", | ||
| ["down", "return"], | ||
| "refund-policy", | ||
| "Must be a valid Lambda function ARN", | ||
| ], | ||
| ["a timeout past 300 seconds", ["return"], "0", "Too big: expected number to be <=300"], | ||
| ] as const)("%s keeps the wizard on its step", async (_label, moves, typed, message) => { | ||
| await inProject(); | ||
| const screen = renderScreen("/agentcore/add/evaluator/code-based"); | ||
| await reachLambdaStep(screen, "refund_policy"); | ||
| for (const move of moves) await screen.press(move); | ||
| await screen.write(typed); | ||
|
|
||
| await screen.press("return"); | ||
|
|
||
| await waitForText(screen.lastFrame, message); | ||
| expect(screen.lastFrame()).not.toContain("this evaluator will be added"); | ||
| screen.unmount(); | ||
| }); | ||
|
|
||
| test("a rejected add reports itself and hands the form back", async () => { | ||
| const projectRoot = await inProject(); | ||
| await run(["add", "evaluator", "code-based", "--name", "refund_policy", "--level", "SESSION"]); | ||
| const screen = renderScreen("/agentcore/add/evaluator/code-based"); | ||
| await reachLambdaStep(screen, "refund_policy"); | ||
| await screen.press("down"); | ||
| await screen.press("return"); | ||
| await screen.write(LAMBDA_ARN); | ||
| await screen.press("return"); | ||
| await waitForText(screen.lastFrame, "this evaluator will be added to agentcore.json"); | ||
| await screen.press("return"); | ||
|
|
||
| await waitForFlatText(screen.lastFrame, "a evaluator with name 'refund_policy' already exists"); | ||
| await screen.press("escape"); | ||
| await waitForText(screen.lastFrame, "this evaluator will be added to agentcore.json"); | ||
| expect((await projectSpec(projectRoot)).evaluators).toHaveLength(1); | ||
| screen.unmount(); | ||
| }, 20000); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add back the length cap to this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4656785. The first line is capped at 60 characters again, followed by the line count. Tests cover a long single line and a long first line.