Relay turned Autopilot off (every /autopilot route renders the "not available" page), so the five upstream specs in e2e_tests/autopilot/ are skipped explicitly with that reason. New autopilot-unavailable.spec.ts (runs in the default suite) asserts /autopilot, /autopilot/sessions, /autopilot/sessions/new and a session URL answer 501 with the unavailable heading, and that the home sidebar has no Autopilot links. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
551 lines
19 KiB
TypeScript
551 lines
19 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import type { Page } from "@playwright/test";
|
|
import { execSync } from "child_process";
|
|
import * as fs from "fs";
|
|
import * as path from "path";
|
|
import { parse as parseToml } from "smol-toml";
|
|
import { deterministicTestAndAttempt } from "./helpers";
|
|
|
|
// Relay does not offer Autopilot: it depends on TensorZero's hosted Autopilot
|
|
// service, so every /autopilot route renders the "not available" page
|
|
// (app/routes/autopilot/layout.tsx) and these upstream session flows cannot
|
|
// run. Skipped explicitly; the unavailable page itself is covered by
|
|
// e2e_tests/autopilot-unavailable.spec.ts.
|
|
test.skip(
|
|
true,
|
|
"Autopilot is not available in Relay (/autopilot renders the unavailable page)",
|
|
);
|
|
|
|
// Path to the autopilot repo config directory (from host perspective).
|
|
// Uses AUTOPILOT_REPO env var (documented in ui/AGENTS.md), falling back to ~/autopilot.
|
|
const AUTOPILOT_REPO =
|
|
process.env.AUTOPILOT_REPO || path.join(process.env.HOME || "", "autopilot");
|
|
const AUTOPILOT_CONFIG_DIR = path.join(
|
|
AUTOPILOT_REPO,
|
|
"e2e_tests/fixtures/config",
|
|
);
|
|
|
|
/**
|
|
* Clicks "Apply changes" and waits for the API response to succeed.
|
|
* Returns the parsed TOML config after writing.
|
|
*/
|
|
async function applyAllConfigsAndParse(
|
|
page: Page,
|
|
): Promise<Record<string, unknown>> {
|
|
const writeButton = page.getByRole("button", {
|
|
name: "Apply changes",
|
|
});
|
|
await expect(writeButton).toBeVisible({ timeout: 10000 });
|
|
|
|
const responsePromise = page.waitForResponse(
|
|
(resp) => resp.url().includes("config-apply/apply-all"),
|
|
{ timeout: 60000 },
|
|
);
|
|
await writeButton.click();
|
|
const apiResponse = await responsePromise;
|
|
// Status 200 = success, 500 = write failure (error toast would say "Failed to apply changes to the local filesystem")
|
|
expect(apiResponse.status(), "Apply changes API should succeed").toBe(200);
|
|
|
|
// Brief pause to ensure filesystem writes are visible to this process
|
|
await page.waitForTimeout(500);
|
|
|
|
const configPath = path.join(AUTOPILOT_CONFIG_DIR, "tensorzero.toml");
|
|
const configContent = fs.readFileSync(configPath, "utf-8");
|
|
return parseToml(configContent) as Record<string, unknown>;
|
|
}
|
|
|
|
/**
|
|
* Clicks the individual "Apply this configuration change to the local filesystem." button and waits for the API response to succeed.
|
|
* Returns the parsed TOML config after writing.
|
|
*/
|
|
async function applyIndividualConfigAndParse(
|
|
page: Page,
|
|
): Promise<Record<string, unknown>> {
|
|
const writeButton = page.getByRole("button", {
|
|
name: "Apply this configuration change to the local filesystem.",
|
|
});
|
|
await expect(writeButton).toBeVisible({ timeout: 10000 });
|
|
|
|
const responsePromise = page.waitForResponse(
|
|
(resp) =>
|
|
resp.url().includes("config-apply/apply") &&
|
|
!resp.url().includes("config-apply/apply-all"),
|
|
{ timeout: 60000 },
|
|
);
|
|
await writeButton.click();
|
|
const apiResponse = await responsePromise;
|
|
expect(apiResponse.status(), "Write config to file API should succeed").toBe(
|
|
200,
|
|
);
|
|
|
|
// Brief pause to ensure filesystem writes are visible to this process
|
|
await page.waitForTimeout(500);
|
|
|
|
const configPath = path.join(AUTOPILOT_CONFIG_DIR, "tensorzero.toml");
|
|
const configContent = fs.readFileSync(configPath, "utf-8");
|
|
return parseToml(configContent) as Record<string, unknown>;
|
|
}
|
|
|
|
test.describe("Config applying", () => {
|
|
// Tests must run serially because they all write to the same config file.
|
|
// Parallel execution causes ConfigApplier in one test to overwrite another's changes.
|
|
test.describe.configure({ mode: "serial" });
|
|
|
|
// Clean up after all tests by resetting git state
|
|
test.afterAll(async () => {
|
|
try {
|
|
execSync(`git checkout -- e2e_tests/fixtures/config`, {
|
|
cwd: AUTOPILOT_REPO,
|
|
});
|
|
execSync(`git clean -fd e2e_tests/fixtures/config`, {
|
|
cwd: AUTOPILOT_REPO,
|
|
});
|
|
} catch (e) {
|
|
// eslint-disable-next-line no-console
|
|
console.error("Failed to clean up config directory:", e);
|
|
}
|
|
});
|
|
|
|
test("should write a new variant with template to config files", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
test.setTimeout(180000); // 3 minutes for LLM + file operations
|
|
|
|
const variantName = deterministicTestAndAttempt(testInfo, "variant");
|
|
|
|
// Build the variant JSON with the simplified format expected by set_variant.
|
|
// Templates are plain strings (name → content), not ResolvedTomlPathData objects.
|
|
const templateContent =
|
|
"Extract all named entities (people, organizations, locations) from the given text and return them as JSON.";
|
|
const variantJson = JSON.stringify({
|
|
type: "chat_completion",
|
|
model: "gpt-4o-mini-2024-07-18",
|
|
templates: {
|
|
system: templateContent,
|
|
},
|
|
temperature: 0,
|
|
json_mode: "strict",
|
|
});
|
|
|
|
// 1. Navigate to new session
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
// 2. Enable YOLO mode for auto-approval
|
|
const yoloLabel = page.locator("label").filter({ hasText: "YOLO Mode" });
|
|
await yoloLabel.click();
|
|
await expect(yoloLabel.getByRole("switch")).toHaveAttribute(
|
|
"data-state",
|
|
"checked",
|
|
);
|
|
|
|
// 3. Send message with explicit tool call parameters (matching Rust e2e test pattern)
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
`Call the set_variant tool to add a new variant to the extract_entities function.\n` +
|
|
`Use these exact parameters:\n` +
|
|
`- function_name: "extract_entities"\n` +
|
|
`- variant_name: "${variantName}"\n` +
|
|
`- variant: ${variantJson}\n\n` +
|
|
`Only make this single tool call, nothing else.`,
|
|
);
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
// 4. Wait for redirect to session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// 5. Wait for session to become idle (Ready status)
|
|
await expect(page.getByText("Ready", { exact: true })).toBeVisible({
|
|
timeout: 120000,
|
|
});
|
|
|
|
// 6. Verify no errors occurred
|
|
await expect(page.getByText("Something went wrong")).not.toBeVisible();
|
|
|
|
// 7. Write configs and parse TOML
|
|
const parsedToml = await applyAllConfigsAndParse(page);
|
|
|
|
// 8. Assert variant exists in extract_entities function
|
|
const functionsDefs = parsedToml["functions"] as Record<string, unknown>;
|
|
expect(functionsDefs, "Config should have functions section").toBeDefined();
|
|
|
|
const extractEntities = functionsDefs["extract_entities"] as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(
|
|
extractEntities,
|
|
"Config should have extract_entities function",
|
|
).toBeDefined();
|
|
|
|
const variants = extractEntities.variants as Record<string, unknown>;
|
|
expect(
|
|
variants,
|
|
"extract_entities should have variants section",
|
|
).toBeDefined();
|
|
expect(
|
|
variants[variantName],
|
|
`Variant ${variantName} should exist`,
|
|
).toBeDefined();
|
|
|
|
const variant = variants[variantName] as Record<string, unknown>;
|
|
expect(variant.type, "Variant type should be chat_completion").toBe(
|
|
"chat_completion",
|
|
);
|
|
expect(
|
|
variant.model,
|
|
"Variant model should be gpt-4o-mini-2024-07-18",
|
|
).toBe("gpt-4o-mini-2024-07-18");
|
|
|
|
// 9. Verify template file was created
|
|
// The config writer canonicalizes paths, so read it from the TOML.
|
|
// With simplified types, templates are written under `templates.system.path`.
|
|
const templates = variant.templates as
|
|
| Record<string, Record<string, string>>
|
|
| undefined;
|
|
expect(templates, "Variant should have a templates section").toBeDefined();
|
|
const systemTemplatePath = templates?.system?.path;
|
|
expect(
|
|
systemTemplatePath,
|
|
"Variant should have a templates.system.path",
|
|
).toBeDefined();
|
|
|
|
const fullTemplatePath = path.join(
|
|
AUTOPILOT_CONFIG_DIR,
|
|
systemTemplatePath!,
|
|
);
|
|
expect(
|
|
fs.existsSync(fullTemplatePath),
|
|
`Template file should exist at ${fullTemplatePath}`,
|
|
).toBe(true);
|
|
|
|
const writtenTemplateContent = fs.readFileSync(fullTemplatePath, "utf-8");
|
|
expect(
|
|
writtenTemplateContent.length,
|
|
"Template content should not be empty",
|
|
).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("should write a new evaluation to config files", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
test.setTimeout(180000);
|
|
|
|
const evaluationName = deterministicTestAndAttempt(testInfo, "evaluation");
|
|
|
|
const evaluationJson = JSON.stringify({
|
|
type: "inference",
|
|
function_name: "write_haiku",
|
|
evaluators: {},
|
|
});
|
|
|
|
// 1. Navigate to new session
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
// 2. Enable YOLO mode
|
|
const yoloLabel = page.locator("label").filter({ hasText: "YOLO Mode" });
|
|
await yoloLabel.click();
|
|
await expect(yoloLabel.getByRole("switch")).toHaveAttribute(
|
|
"data-state",
|
|
"checked",
|
|
);
|
|
|
|
// 3. Send message with explicit tool call parameters
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
`Call the set_evaluation tool to create a new evaluation.\n` +
|
|
`Use these exact parameters:\n` +
|
|
`- evaluation_name: "${evaluationName}"\n` +
|
|
`- evaluation: ${evaluationJson}\n\n` +
|
|
`Only make this single tool call, nothing else.`,
|
|
);
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
// 4. Wait for redirect to session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// 5. Wait for session to become idle (Ready status)
|
|
await expect(page.getByText("Ready", { exact: true })).toBeVisible({
|
|
timeout: 120000,
|
|
});
|
|
|
|
// 6. Verify no errors occurred
|
|
await expect(page.getByText("Something went wrong")).not.toBeVisible();
|
|
|
|
// 7. Write configs and parse TOML
|
|
const parsedToml = await applyAllConfigsAndParse(page);
|
|
|
|
// 8. Assert evaluation exists
|
|
const evaluations = parsedToml["evaluations"] as Record<string, unknown>;
|
|
expect(evaluations, "Config should have evaluations section").toBeDefined();
|
|
|
|
const evaluation = evaluations[evaluationName] as Record<string, unknown>;
|
|
expect(
|
|
evaluation,
|
|
`Evaluation ${evaluationName} should exist`,
|
|
).toBeDefined();
|
|
|
|
expect(evaluation.type, "Evaluation type should be inference").toBe(
|
|
"inference",
|
|
);
|
|
expect(
|
|
evaluation.function_name,
|
|
"Evaluation function_name should be write_haiku",
|
|
).toBe("write_haiku");
|
|
});
|
|
|
|
test("should write a new llm_judge evaluator with system_instructions to config files", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
test.setTimeout(180000);
|
|
|
|
const evaluatorName = deterministicTestAndAttempt(testInfo, "evaluator");
|
|
|
|
const instructionsContent =
|
|
"Judge whether the haiku follows the 5-7-5 syllable pattern. Return true if it does, false otherwise.";
|
|
const evaluatorJson = JSON.stringify({
|
|
type: "llm_judge",
|
|
output_type: "boolean",
|
|
optimize: "max",
|
|
variants: {
|
|
mini: {
|
|
type: "chat_completion",
|
|
model: "gpt-4o-mini-2024-07-18",
|
|
json_mode: "off",
|
|
system_instructions: instructionsContent,
|
|
},
|
|
},
|
|
});
|
|
|
|
// 1. Navigate to new session
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
// 2. Enable YOLO mode
|
|
const yoloLabel = page.locator("label").filter({ hasText: "YOLO Mode" });
|
|
await yoloLabel.click();
|
|
await expect(yoloLabel.getByRole("switch")).toHaveAttribute(
|
|
"data-state",
|
|
"checked",
|
|
);
|
|
|
|
// 3. Send message with explicit tool call parameters
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
`Call the set_evaluator tool to add an evaluator to the haiku evaluation.\n` +
|
|
`Use these exact parameters:\n` +
|
|
`- evaluation_name: "haiku"\n` +
|
|
`- evaluator_name: "${evaluatorName}"\n` +
|
|
`- evaluator: ${evaluatorJson}\n\n` +
|
|
`Only make this single tool call, nothing else.`,
|
|
);
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
// 4. Wait for redirect to session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// 5. Wait for session to become idle (Ready status)
|
|
await expect(page.getByText("Ready", { exact: true })).toBeVisible({
|
|
timeout: 120000,
|
|
});
|
|
|
|
// 6. Verify no errors occurred
|
|
await expect(page.getByText("Something went wrong")).not.toBeVisible();
|
|
|
|
// 7. Write configs and parse TOML
|
|
const parsedToml = await applyAllConfigsAndParse(page);
|
|
|
|
// 8. Assert evaluator exists under haiku evaluation
|
|
const evaluations = parsedToml["evaluations"] as Record<string, unknown>;
|
|
expect(evaluations, "Config should have evaluations section").toBeDefined();
|
|
|
|
const haikuEval = evaluations["haiku"] as Record<string, unknown>;
|
|
expect(haikuEval, "Config should have haiku evaluation").toBeDefined();
|
|
|
|
const evaluators = haikuEval.evaluators as Record<string, unknown>;
|
|
expect(
|
|
evaluators,
|
|
"haiku evaluation should have evaluators section",
|
|
).toBeDefined();
|
|
|
|
const evaluator = evaluators[evaluatorName] as Record<string, unknown>;
|
|
expect(evaluator, `Evaluator ${evaluatorName} should exist`).toBeDefined();
|
|
|
|
expect(evaluator.type, "Evaluator type should be llm_judge").toBe(
|
|
"llm_judge",
|
|
);
|
|
expect(
|
|
evaluator.output_type,
|
|
"Evaluator output_type should be boolean",
|
|
).toBe("boolean");
|
|
expect(evaluator.optimize, "Evaluator optimize should be max").toBe("max");
|
|
|
|
// Verify variant exists
|
|
const variants = evaluator.variants as Record<string, unknown>;
|
|
expect(variants, "Evaluator should have variants section").toBeDefined();
|
|
|
|
const miniVariant = variants["mini"] as Record<string, unknown>;
|
|
expect(miniVariant, "Variant mini should exist").toBeDefined();
|
|
expect(
|
|
miniVariant.model,
|
|
"Variant model should be gpt-4o-mini-2024-07-18",
|
|
).toBe("gpt-4o-mini-2024-07-18");
|
|
|
|
// Verify system_instructions file was created
|
|
const writtenInstructions = miniVariant.system_instructions as
|
|
| string
|
|
| undefined;
|
|
expect(
|
|
writtenInstructions,
|
|
"Variant should have a system_instructions path",
|
|
).toBeDefined();
|
|
|
|
const fullInstructionsPath = path.join(
|
|
AUTOPILOT_CONFIG_DIR,
|
|
writtenInstructions!,
|
|
);
|
|
expect(
|
|
fs.existsSync(fullInstructionsPath),
|
|
`Instructions file should exist at ${fullInstructionsPath}`,
|
|
).toBe(true);
|
|
|
|
const writtenInstructionsContent = fs.readFileSync(
|
|
fullInstructionsPath,
|
|
"utf-8",
|
|
);
|
|
expect(
|
|
writtenInstructionsContent.length,
|
|
"Instructions content should not be empty",
|
|
).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("should write a single variant config via individual write button", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
test.setTimeout(180000); // 3 minutes for LLM + file operations
|
|
|
|
const variantName = deterministicTestAndAttempt(
|
|
testInfo,
|
|
"individual_variant",
|
|
);
|
|
|
|
const templateContent =
|
|
"Extract all named entities (people, organizations, locations) from the given text and return them as JSON.";
|
|
const variantJson = JSON.stringify({
|
|
type: "chat_completion",
|
|
model: "gpt-4o-mini-2024-07-18",
|
|
templates: {
|
|
system: templateContent,
|
|
},
|
|
temperature: 0,
|
|
json_mode: "strict",
|
|
});
|
|
|
|
// 1. Navigate to new session
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
// 2. Enable YOLO mode for auto-approval
|
|
const yoloLabel = page.locator("label").filter({ hasText: "YOLO Mode" });
|
|
await yoloLabel.click();
|
|
await expect(yoloLabel.getByRole("switch")).toHaveAttribute(
|
|
"data-state",
|
|
"checked",
|
|
);
|
|
|
|
// 3. Send message with explicit tool call parameters
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
`Call the set_variant tool to add a new variant to the extract_entities function.\n` +
|
|
`Use these exact parameters:\n` +
|
|
`- function_name: "extract_entities"\n` +
|
|
`- variant_name: "${variantName}"\n` +
|
|
`- variant: ${variantJson}\n\n` +
|
|
`Only make this single tool call, nothing else.`,
|
|
);
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
// 4. Wait for redirect to session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// 5. Wait for session to become idle (Ready status)
|
|
await expect(page.getByText("Ready", { exact: true })).toBeVisible({
|
|
timeout: 120000,
|
|
});
|
|
|
|
// 6. Verify no errors occurred
|
|
await expect(page.getByText("Something went wrong")).not.toBeVisible();
|
|
|
|
// 7. Write individual config and parse TOML
|
|
const parsedToml = await applyIndividualConfigAndParse(page);
|
|
|
|
// 8. Assert variant exists in extract_entities function
|
|
const functionsDefs = parsedToml["functions"] as Record<string, unknown>;
|
|
expect(functionsDefs, "Config should have functions section").toBeDefined();
|
|
|
|
const extractEntities = functionsDefs["extract_entities"] as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(
|
|
extractEntities,
|
|
"Config should have extract_entities function",
|
|
).toBeDefined();
|
|
|
|
const variants = extractEntities.variants as Record<string, unknown>;
|
|
expect(
|
|
variants,
|
|
"extract_entities should have variants section",
|
|
).toBeDefined();
|
|
expect(
|
|
variants[variantName],
|
|
`Variant ${variantName} should exist`,
|
|
).toBeDefined();
|
|
|
|
const variant = variants[variantName] as Record<string, unknown>;
|
|
expect(variant.type, "Variant type should be chat_completion").toBe(
|
|
"chat_completion",
|
|
);
|
|
expect(
|
|
variant.model,
|
|
"Variant model should be gpt-4o-mini-2024-07-18",
|
|
).toBe("gpt-4o-mini-2024-07-18");
|
|
|
|
// 9. Verify template file was created
|
|
// With simplified types, templates are written under `templates.system.path`.
|
|
const templates = variant.templates as
|
|
| Record<string, Record<string, string>>
|
|
| undefined;
|
|
expect(templates, "Variant should have a templates section").toBeDefined();
|
|
const systemTemplatePath = templates?.system?.path;
|
|
expect(
|
|
systemTemplatePath,
|
|
"Variant should have a templates.system.path",
|
|
).toBeDefined();
|
|
|
|
const fullTemplatePath = path.join(
|
|
AUTOPILOT_CONFIG_DIR,
|
|
systemTemplatePath!,
|
|
);
|
|
expect(
|
|
fs.existsSync(fullTemplatePath),
|
|
`Template file should exist at ${fullTemplatePath}`,
|
|
).toBe(true);
|
|
|
|
const writtenTemplateContent = fs.readFileSync(fullTemplatePath, "utf-8");
|
|
expect(
|
|
writtenTemplateContent.length,
|
|
"Template content should not be empty",
|
|
).toBeGreaterThan(0);
|
|
});
|
|
});
|