Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/soft-balloons-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"evalite": minor
"evalite-ui": minor
---

Ddd serve mode to the CLI and manual run button to the UI
26 changes: 26 additions & 0 deletions apps/evalite-ui/app/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
} from "@tanstack/react-router";

import { lazy } from "react";
import { Play } from "lucide-react";
import Logo from "~/components/logo";
import { getScoreState, Score, type ScoreState } from "~/components/score";
import { Button } from "~/components/ui/button";
import {
Sidebar,
SidebarContent,
Expand All @@ -31,6 +33,7 @@ import {
} from "~/data/queries";
import { useSubscribeToSocket } from "~/data/use-subscribe-to-socket";
import { useServerStateUtils } from "~/hooks/use-server-state-utils";
import { triggerRun } from "~/sdk";
import "../tailwind.css";
import type { Db } from "evalite/db";

Expand Down Expand Up @@ -88,6 +91,17 @@ export default function App() {

useSubscribeToSocket(queryClient);

const handleTriggerRun = async () => {
try {
const result = await triggerRun();
if (!result.success) {
console.error('Failed to trigger run:', result.message);
}
} catch (error) {
console.error('Error triggering run:', error);
}
};

return (
<SidebarProvider>
<Sidebar className="border-r-0">
Expand Down Expand Up @@ -116,6 +130,18 @@ export default function App() {
resultStatus={undefined}
/>
</div>
<div className="mt-2">
<Button
variant="secondary"
size="sm"
disabled={serverState.type === "running"}
onClick={() => handleTriggerRun()}
className="w-full"
>
<Play className="size-4 mr-1" />
Run all
</Button>
</div>
</div>
</SidebarGroup>
<SidebarGroup>
Expand Down
13 changes: 13 additions & 0 deletions apps/evalite-ui/app/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,16 @@ export const serveFile = (filepath: string) => {
export const downloadFile = (filepath: string) => {
return `${BASE_URL}/api/file?path=${filepath}&download=true`;
};

export const triggerRun = async (): Promise<{ success: boolean; message?: string }> => {
return safeFetch<{ success: boolean; message?: string }>(
`${BASE_URL}/api/trigger-run`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({}), // Add empty body to make post request work
}
);
};
76 changes: 76 additions & 0 deletions packages/evalite/src/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ describe("createCommand", () => {
it("evalite without path", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, [], { process });

expect(watch).not.toHaveBeenCalled();
expect(serve).not.toHaveBeenCalled();

expect(runOnceAtPath).toHaveBeenCalled();
expect(runOnceAtPath).toHaveBeenCalledWith({
Expand All @@ -24,14 +27,17 @@ describe("createCommand", () => {
it("evalite with path", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["./src"], { process });

expect(watch).not.toHaveBeenCalled();
expect(serve).not.toHaveBeenCalled();
expect(runOnceAtPath).toHaveBeenCalledWith({
path: "./src",
});
Expand All @@ -40,9 +46,11 @@ describe("createCommand", () => {
it("evalite watch", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["watch"], { process });
Expand All @@ -51,14 +59,17 @@ describe("createCommand", () => {
path: undefined,
});
expect(runOnceAtPath).not.toHaveBeenCalled();
expect(serve).not.toHaveBeenCalled();
});

it("evalite watch with path", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["watch", "./src"], { process });
Expand All @@ -67,19 +78,61 @@ describe("createCommand", () => {
path: "./src",
});
expect(runOnceAtPath).not.toHaveBeenCalled();
expect(serve).not.toHaveBeenCalled();
});

it("evalite serve", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["serve"], { process });

expect(serve).toHaveBeenCalledWith({
path: undefined,
});
expect(watch).not.toHaveBeenCalled();
expect(runOnceAtPath).not.toHaveBeenCalled();
});

it("evalite serve with path", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["serve", "./src"], { process });

expect(serve).toHaveBeenCalledWith({
path: "./src",
});
expect(watch).not.toHaveBeenCalled();
expect(runOnceAtPath).not.toHaveBeenCalled();
});

it("evalite --threshold", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["--threshold=50"], { process });

expect(watch).not.toHaveBeenCalled();
expect(serve).not.toHaveBeenCalled();
expect(runOnceAtPath).toHaveBeenCalledWith({
path: undefined,
threshold: 50,
Expand All @@ -89,9 +142,11 @@ describe("createCommand", () => {
it("evalite watch --threshold", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["watch", "--threshold=50"], { process });
Expand All @@ -101,5 +156,26 @@ describe("createCommand", () => {
threshold: 50,
});
expect(runOnceAtPath).not.toHaveBeenCalled();
expect(serve).not.toHaveBeenCalled();
});

it("evalite serve --threshold", async () => {
const watch = vitest.fn();
const runOnceAtPath = vitest.fn();
const serve = vitest.fn();
const program = createProgram({
watch,
runOnceAtPath,
serve,
});

await run(program, ["serve", "--threshold=50"], { process });

expect(serve).toHaveBeenCalledWith({
path: undefined,
threshold: 50,
});
expect(watch).not.toHaveBeenCalled();
expect(runOnceAtPath).not.toHaveBeenCalled();
});
});
20 changes: 20 additions & 0 deletions packages/evalite/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Flags = {
export const createProgram = (commands: {
watch: (opts: ProgramOpts) => void;
runOnceAtPath: (opts: ProgramOpts) => void;
serve: (opts: ProgramOpts) => void;
}) => {
const runOnce = buildCommand({
parameters: commonParameters,
Expand All @@ -59,10 +60,21 @@ export const createProgram = (commands: {
},
});

const serve = buildCommand({
parameters: commonParameters,
func: (flags: Flags, path: string | undefined) => {
return commands.serve({ path, threshold: flags.threshold });
},
docs: {
brief: "Serve UI without file watching",
},
});

const routes = buildRouteMap({
routes: {
"run-once": runOnce,
watch,
serve,
install: buildInstallCommand("evalite", {
bash: "__evalite_bash_complete",
}),
Expand Down Expand Up @@ -103,4 +115,12 @@ export const program = createProgram({
mode: "run-once-and-exit",
});
},
serve: (path) => {
return runVitest({
path: path.path,
scoreThreshold: path.threshold,
cwd: undefined,
mode: "serve-without-watching",
});
},
});
Loading