Skip to content

Commit 48a029f

Browse files
ashutosh-rath02anerli
authored andcommitted
fix: add support for desc
1 parent 554c16c commit 48a029f

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/magnitude-test/src/discovery/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TestCaseAgent } from "@/agent";
55

66
export interface TestOptions {
77
url?: string;
8+
prompt?: string;
89
//name?: string;
910
}
1011

packages/magnitude-test/src/worker/localTestRegistry.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TestCaseAgent } from "@/agent";
55
import { TestResult, TestState, TestStateTracker } from "@/runner/state";
66
import { buildDefaultBrowserAgentOptions } from "magnitude-core";
77
import { sendTelemetry } from "@/runner/telemetry";
8+
import { testPromptStack } from "@/worker/testDeclaration";
89

910
// This module has to be separate so it only gets imported once after possible compilation by jiti.
1011

@@ -51,8 +52,10 @@ messageEmitter.on('message', async (message: TestWorkerIncomingMessage) => {
5152
}
5253

5354
try {
55+
const promptStack = testPromptStack[test.title] || [];
56+
const prompt = promptStack.length > 0 ? promptStack.join('\n') : undefined;
5457
const { agentOptions: defaultAgentOptions, browserOptions: defaultBrowserOptions } = buildDefaultBrowserAgentOptions({
55-
agentOptions: { llm },
58+
agentOptions: { llm, ...(prompt ? { prompt } : {}) },
5659
browserOptions: {
5760
url: test.url,
5861
browser: browserOptions,

packages/magnitude-test/src/worker/testDeclaration.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { currentGroupOptions, registerTest, setCurrentGroup } from '@/worker/loc
55

66
const workerData = getTestWorkerData();
77

8+
const testPromptStack: Record<string, string[]> = {};
9+
810
function testDecl(
911
title: string,
1012
optionsOrTestFn: TestOptions | TestFunction,
@@ -25,7 +27,7 @@ function testDecl(
2527
testFn = testFnOrNothing;
2628
}
2729

28-
const groupOptions = currentGroupOptions();
30+
const groupOptions = currentGroupOptions();
2931

3032
const combinedOptions: TestOptions = {
3133
...(workerData.options ?? {}),
@@ -38,6 +40,12 @@ function testDecl(
3840
throw Error("URL must be provided either through (1) env var MAGNITUDE_TEST_URL, (2) via magnitude.config.ts, or (3) in group or test options");
3941
}
4042

43+
// Stack group and test prompts (group first, then test)
44+
const promptStack: string[] = [];
45+
if (groupOptions.prompt) promptStack.push(groupOptions.prompt);
46+
if (options.prompt) promptStack.push(options.prompt);
47+
testPromptStack[title] = promptStack;
48+
4149
registerTest(testFn, title, addProtocolIfMissing(combinedOptions.url));
4250

4351
// TODO: maybe return an object to enable some kind of chaining
@@ -69,3 +77,5 @@ testDecl.group = function (
6977
}
7078

7179
export const test = testDecl as TestDeclaration;
80+
81+
export { testPromptStack };

0 commit comments

Comments
 (0)