Registry Mirror
Skip to content

‎ui/playwright/helpers/app.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export const routes = {
1818
modelNew: "/models/new",
1919
mcpServers: "/mcp",
2020
mcpServerNew: "/mcp/new",
21-
egressPolicies: "/egress-policies",
22-
egressPolicyNew: "/egress-policies/new",
21+
policies: "/policies",
22+
egressPolicyNew: "/policies/egress/new",
2323
prompts: "/prompts",
2424
promptNew: "/prompts/new",
2525
snapshots: "/snapshots",

‎ui/playwright/helpers/extensions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const CORE_NAV_ORDER = [
5858
"nav-scheduledRuns",
5959
"nav-models",
6060
"nav-mcpServers",
61-
"nav-egressPolicies",
61+
"nav-policies",
6262
"nav-prompts",
6363
"nav-substrate",
6464
];

‎ui/playwright/helpers/nav.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type NavKey =
2020
| "agents"
2121
| "models"
2222
| "mcpServers"
23-
| "egressPolicies"
23+
| "policies"
2424
| "prompts"
2525
| "substrate";
2626

@@ -29,7 +29,7 @@ export const navLabels: Record<NavKey, string> = {
2929
agents: "Agents",
3030
models: "Models",
3131
mcpServers: "MCP Servers",
32-
egressPolicies: "Egress Policies",
32+
policies: "Policies",
3333
prompts: "Prompts",
3434
substrate: "Substrate",
3535
};

‎ui/playwright/tests/egress-policies/egress-policies.spec.ts‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { LIFECYCLE_TIMEOUT, dialog, expectLoading, optionNamed, pressOnce } from
55

66
/**
77
* Egress policies: list, create, attach to an agent, see it in "Used by", edit, delete.
8+
* The created policy has a dotted name, which the API accepts as a DNS subdomain.
89
*
910
* The mock keeps writes in memory per page load, so after the first `goto` every step
1011
* moves in-app. The mock applies the CRD's rules, so a create it accepts is one a cluster
1112
* would accept too.
1213
*/
1314

14-
const CREATED = "suite-policy";
15+
const CREATED = "suite.example.com";
16+
const CREATED_URL = new RegExp(`/policies/egress/kagent/${CREATED.replace(/\./g, "\\.")}$`);
1517
const SEEDED = ["github-api", "internal-tools", "package-mirrors", "warehouse"];
1618

1719
test.describe.configure({ timeout: LIFECYCLE_TIMEOUT });
@@ -23,27 +25,33 @@ async function expectUsersCounted(page: Page) {
2325

2426
async function backToListSettled(page: Page) {
2527
await page.getByRole("link", { name: "Back to policies" }).click();
26-
await expect(page).toHaveURL(/\/egress-policies$/);
28+
await expect(page).toHaveURL(/\/policies\?tab=egress$/);
2729
await expectUsersCounted(page);
2830
}
2931

3032
test("egress policies: a policy is created, attached, edited and deleted", async ({ page }) => {
3133
await test.step("1. an empty list and a failed read say different things", async () => {
32-
await loadPage(page, routes.egressPolicies, { scenario: "empty" });
34+
await loadPage(page, routes.policies, { scenario: "empty" });
3335
await expect(page.getByText("No egress policies yet.")).toBeVisible();
3436

35-
await loadPage(page, routes.egressPolicies, { scenario: "error" });
37+
await loadPage(page, routes.policies, { scenario: "error" });
3638
await expect(page.getByTestId("egress-policies-error")).toBeVisible();
3739
await expect(page.getByText("No egress policies yet.")).toHaveCount(0);
40+
41+
// A dotted last segment still loads the app rather than a missing file.
42+
await loadPage(page, "/policies/egress/kagent/missing.example.com");
43+
await expect(page.getByTestId("egress-policy-not-found")).toContainText("kagent/missing.example.com");
3844
});
3945

4046
// Last of the full loads: it ends on `?mock=ok`, which step 3 waits out before acting.
4147
await test.step("2. a loading state precedes the data", async () => {
42-
await expectLoading(page, routes.egressPolicies);
48+
await expectLoading(page, routes.policies);
4349
});
4450

4551
await test.step("3. every policy is listed with its origins, auth and users", async () => {
46-
await expectPageTitle(page, "Egress policies");
52+
await expectPageTitle(page, "Policies");
53+
await expect(page.getByTestId("policies-tabs").getByRole("tab", { name: "Egress Policies" })).toHaveAttribute("aria-selected", "true");
54+
await expect(page.getByRole("img", { name: "An agent or sandbox template lists a policy, and the policy lets it reach HTTP(S) hosts." })).toBeVisible();
4755
await expect(dataRows(page)).toHaveCount(SEEDED.length);
4856
// github-api is used by the release-notes agent and the python-sandbox template.
4957
const github = rowNamed(page, "github-api");
@@ -63,7 +71,7 @@ test("egress policies: a policy is created, attached, edited and deleted", async
6371
});
6472

6573
await test.step("5. the form checks the CRD's rules before saving", async () => {
66-
await page.getByTestId("egress-policies-new").click();
74+
await page.getByRole("button", { name: "Create egress policy" }).click();
6775
await expectPageTitle(page, "New egress policy");
6876
await page.getByTestId("egress-form-submit").click();
6977
await expect(page.getByTestId("egress-form-errors")).toContainText("Enter a name.");
@@ -76,7 +84,7 @@ test("egress policies: a policy is created, attached, edited and deleted", async
7684
await page.getByTestId("egress-destination-0-secret-key").fill("token");
7785
await page.getByTestId("egress-form-submit").click();
7886
await expect(page.getByTestId("egress-destination-0-problems")).toContainText("can't carry a credential");
79-
await expect(page).toHaveURL(/\/egress-policies\/new$/);
87+
await expect(page).toHaveURL(/\/policies\/egress\/new$/);
8088

8189
// A wildcard origin offers no credential source.
8290
await page.getByTestId("egress-form-add-destination").click();
@@ -89,7 +97,7 @@ test("egress policies: a policy is created, attached, edited and deleted", async
8997
await page.getByTestId("egress-destination-0-header").fill("Authorization");
9098
await page.getByTestId("egress-destination-0-prefix").fill("Bearer ");
9199
await page.getByTestId("egress-form-submit").click();
92-
await expect(page).toHaveURL(new RegExp(`/egress-policies/kagent/${CREATED}$`));
100+
await expect(page).toHaveURL(CREATED_URL);
93101

94102
const destinations = page.getByTestId("egress-policy-destinations");
95103
await expect(rowNamed(page, "https://api.example.com")).toContainText("example-credentials/token");
@@ -117,7 +125,8 @@ test("egress policies: a policy is created, attached, edited and deleted", async
117125
});
118126

119127
await test.step("8. the policy lists the agent, and the agent applied it", async () => {
120-
await page.getByRole("link", { name: "Egress Policies" }).click();
128+
await page.getByRole("link", { name: "Policies", exact: true }).click();
129+
await expect(page).toHaveURL(/\/policies$/);
121130
await expectUsersCounted(page);
122131
await rowNamed(page, CREATED).getByRole("link", { name: CREATED, exact: true }).click();
123132
const user = rowNamed(page, "release-notes");
@@ -145,7 +154,7 @@ test("egress policies: a policy is created, attached, edited and deleted", async
145154
await expect(page.getByTestId("egress-form-add-destination")).toBeFocused();
146155
await page.getByTestId("egress-destination-0-origin").fill("https://api2.example.com");
147156
await page.getByTestId("egress-form-submit").click();
148-
await expect(page).toHaveURL(new RegExp(`/egress-policies/kagent/${CREATED}$`));
157+
await expect(page).toHaveURL(CREATED_URL);
149158
await expect(rowNamed(page, "https://api2.example.com")).toHaveCount(1);
150159
await expect(page.getByTestId("egress-policy-destinations")).not.toContainText("example.org");
151160
});
@@ -155,7 +164,7 @@ test("egress policies: a policy is created, attached, edited and deleted", async
155164
// release-notes attached it in step 7.
156165
await expect(dialog(page)).toContainText("This policy is in use by 1 agent or sandbox template you can see.");
157166
await pressOnce(dialog(page).getByRole("button", { name: "Delete" }));
158-
await expect(page).toHaveURL(/\/egress-policies$/);
167+
await expect(page).toHaveURL(/\/policies\?tab=egress$/);
159168
await expectSettled(page);
160169
await expect(rowNamed(page, CREATED)).toHaveCount(0);
161170
await expect(dataRows(page)).toHaveCount(SEEDED.length);

‎ui/playwright/tests/routing.spec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ test("routing: in-app navigation, deep links, 404, and standalone routes", async
7373
// And somewhere to go that is not just "back to the dashboard", which is the right
7474
// destination only if that is where they were headed.
7575
await expect(page.getByTestId("not-found-link-agents")).toBeVisible();
76+
await expect(page.getByTestId("not-found-link-policies")).toHaveAttribute("href", "/policies?tab=egress");
7677
// Still inside the app: a wrong URL should not strand the user with no
7778
// way back.
7879
await expectShell(page);

‎ui/src/components/Structure/navItems.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export const coreNavItems: NavItem[] = [
4545
order: 400,
4646
},
4747
{
48-
key: "egressPolicies",
49-
label: "Egress Policies",
50-
path: paths.egressPolicies,
48+
key: "policies",
49+
label: "Policies",
50+
path: paths.policies,
5151
icon: ShieldCheck,
5252
order: 450,
5353
},

‎ui/src/components/egress-policy-form/egressPolicyCopy.ts‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
/** Every user-facing string for the egress policy pages, in one place. */
22
export const egressCopy = {
3-
nav: "Egress Policies",
3+
page: {
4+
title: "Policies",
5+
tab: "Egress Policies",
6+
createButton: "Create egress policy",
7+
notFoundHint: "which hosts agents can reach",
8+
},
9+
concepts: {
10+
title: "Overview",
11+
what: "A policy lists extra HTTP(S) hosts that agents and sandbox templates can reach.",
12+
credential: "The gateway can add a credential to requests. The agent never sees it.",
13+
noPolicyNeeded: "Model and MCP server hosts work without a policy.",
14+
diagramLabel: "An agent or sandbox template lists a policy, and the policy lets it reach HTTP(S) hosts.",
15+
boxes: {
16+
agent: { kind: "Agent", detail: "Lists the policies it needs." },
17+
sandboxTemplate: { kind: "SandboxTemplate", detail: "Lists the policies its sandboxes need." },
18+
policy: { kind: "EgressPolicy", detail: "Origins it allows, and any credential." },
19+
hosts: { kind: "HTTP(S) hosts", detail: "What the agent can now reach." },
20+
},
21+
},
422
list: {
523
title: "Egress policies",
6-
intro:
7-
"A policy lets the agents and sandbox templates that list it reach more HTTP(S) hosts. You don't need one for models or MCP servers. Those are reachable already.",
8-
newButton: "New policy",
924
search: "Search by name or origin",
1025
loadError: "Could not load egress policies",
1126
empty: "No egress policies yet.",
@@ -27,7 +42,7 @@ export const egressCopy = {
2742
actorJwt: "Actor JWT",
2843
},
2944
details: {
30-
description: (namespace: string) => `Extra hosts that agents and sandboxes in ${namespace} can reach.`,
45+
description: (namespace: string) => `Egress policy in ${namespace}.`,
3146
back: "Back to policies",
3247
edit: "Edit",
3348
destinations: "Destinations",
@@ -64,6 +79,11 @@ export const egressCopy = {
6479
name: "Name",
6580
namespace: "Namespace",
6681
identityLocked: "Fixed once the policy exists.",
82+
nameRequired: "Enter a name.",
83+
nameInvalid: "Use lowercase letters, numbers, hyphens and dots. Start and end each part with a letter or number.",
84+
nameTooLong: (max: number) => `Keep the name to ${max} characters or fewer.`,
85+
namespaceRequired: "Choose a namespace.",
86+
namespaceInvalid: "Choose a namespace made of lowercase letters, numbers and hyphens.",
6787
destinations: "Destinations",
6888
destinationsHelp: (max: number) => `Each destination allows one origin and all its paths. You can add up to ${max}.`,
6989
destinationTitle: (n: number) => `Destination ${n}`,

‎ui/src/components/egress-policy-form/egressPolicyDraft.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { describe, expect, it } from "vitest";
22
import type { EgressPolicy } from "@/api";
3-
import { draftFromPolicy, draftIssues, emptyDestination, emptyPolicyDraft, resourceFromDraft } from "./egressPolicyDraft";
3+
import {
4+
POLICY_NAME_MAX,
5+
draftFromPolicy,
6+
draftIssues,
7+
emptyDestination,
8+
emptyPolicyDraft,
9+
policyNameProblem,
10+
resourceFromDraft,
11+
} from "./egressPolicyDraft";
12+
import { egressCopy } from "./egressPolicyCopy";
413

514
const policy: EgressPolicy = {
615
ref: "kagent/github",
@@ -49,4 +58,54 @@ describe("egress policy draft", () => {
4958
"The Cookie header can't carry a credential.",
5059
]);
5160
});
61+
62+
it("accepts a dotted name on edit and sends it back unchanged", () => {
63+
const dotted: EgressPolicy = {
64+
...policy,
65+
ref: "kagent/api.github.com",
66+
name: "api.github.com",
67+
resource: { ...policy.resource, metadata: { ...policy.resource.metadata, name: "api.github.com" } },
68+
};
69+
const draft = draftFromPolicy(dotted);
70+
expect(draftIssues(draft).count).toBe(0);
71+
expect(resourceFromDraft(draft, dotted.resource)).toEqual(dotted.resource);
72+
});
73+
74+
it("refuses a namespace that is not a single DNS label", () => {
75+
const draft = emptyPolicyDraft("team.a");
76+
draft.name = "github";
77+
draft.destinations = [{ ...emptyDestination(), origin: "https://api.github.com" }];
78+
expect(draftIssues(draft).policy).toEqual([egressCopy.form.namespaceInvalid]);
79+
});
80+
});
81+
82+
describe("policyNameProblem", () => {
83+
it.each([
84+
["a single label", "github"],
85+
["dotted labels", "api.github.com"],
86+
["hyphens inside labels", "my-team.api-v2"],
87+
["the length limit", "a".repeat(POLICY_NAME_MAX)],
88+
])("accepts %s", (_case, name) => {
89+
expect(policyNameProblem(name)).toBeUndefined();
90+
});
91+
92+
it.each([
93+
["consecutive dots", "api..github"],
94+
["a leading dot", ".github"],
95+
["a trailing dot", "github."],
96+
["a leading hyphen", "-github"],
97+
["a trailing hyphen", "github-"],
98+
["a hyphen at a dot", "api-.github"],
99+
["uppercase", "GitHub"],
100+
])("refuses %s", (_case, name) => {
101+
expect(policyNameProblem(name)).toBe(egressCopy.form.nameInvalid);
102+
});
103+
104+
it("refuses a name past the length limit", () => {
105+
expect(policyNameProblem("a".repeat(POLICY_NAME_MAX + 1))).toBe(egressCopy.form.nameTooLong(POLICY_NAME_MAX));
106+
});
107+
108+
it("asks for a name when it is blank", () => {
109+
expect(policyNameProblem(" ")).toBe(egressCopy.form.nameRequired);
110+
});
52111
});

‎ui/src/components/egress-policy-form/egressPolicyDraft.ts‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@/api/domain/egressPolicies";
88
import { KAGENT_API_VERSION } from "@/api/grpc/wire";
99
import { DEFAULT_NAMESPACE, isValidResourceName } from "@/components/common/resourceName";
10+
import { egressCopy } from "./egressPolicyCopy";
1011

1112
export type AuthChoice = "none" | "secret" | "actorJwt";
1213

@@ -108,6 +109,20 @@ export function resourceFromDraft(
108109
};
109110
}
110111

112+
// The proto's ResourceReference rules: a DNS-1123 subdomain name and a DNS-1123 label namespace.
113+
const DNS_1123_SUBDOMAIN = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/;
114+
export const POLICY_NAME_MAX = 253;
115+
const NAMESPACE_MAX = 63;
116+
117+
/** Why a policy name is refused, or undefined when the API would accept it. */
118+
export function policyNameProblem(value: string): string | undefined {
119+
const name = value.trim();
120+
if (!name) return egressCopy.form.nameRequired;
121+
if (name.length > POLICY_NAME_MAX) return egressCopy.form.nameTooLong(POLICY_NAME_MAX);
122+
if (!DNS_1123_SUBDOMAIN.test(name)) return egressCopy.form.nameInvalid;
123+
return undefined;
124+
}
125+
111126
export interface DraftIssues {
112127
/** Name, namespace and spec-level problems. */
113128
policy: string[];
@@ -118,11 +133,13 @@ export interface DraftIssues {
118133

119134
export function draftIssues(draft: EgressPolicyDraft): DraftIssues {
120135
const policy: string[] = [];
121-
if (!draft.name.trim()) policy.push("Enter a name.");
122-
else if (!isValidResourceName(draft.name) || draft.name.trim().length > 253) {
123-
policy.push("Use lowercase letters, numbers and hyphens in the name.");
136+
const nameProblem = policyNameProblem(draft.name);
137+
if (nameProblem) policy.push(nameProblem);
138+
const namespace = draft.namespace.trim();
139+
if (!namespace) policy.push(egressCopy.form.namespaceRequired);
140+
else if (namespace.length > NAMESPACE_MAX || !isValidResourceName(namespace)) {
141+
policy.push(egressCopy.form.namespaceInvalid);
124142
}
125-
if (!draft.namespace.trim()) policy.push("Choose a namespace.");
126143
const spec = { destinations: draft.destinations.map(destinationFromDraft) };
127144
policy.push(...specProblems(spec));
128145

‎ui/src/pages/NotFoundPage.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Button, Space, Typography } from "antd";
22
import { Compass } from "lucide-react";
33
import { useTheme } from "@emotion/react";
44
import { Link, useLocation } from "react-router-dom";
5-
import { agentTemplatesTab, paths } from "@/router/routes";
5+
import { agentTemplatesTab, egressPoliciesTab, paths } from "@/router/routes";
6+
import { egressCopy } from "@/components/egress-policy-form/egressPolicyCopy";
67

78
const { Text, Title } = Typography;
89

@@ -35,6 +36,7 @@ export function NotFoundPage() {
3536
{ to: agentTemplatesTab, label: "Agent templates", hint: "what an agent does" },
3637
{ to: paths.models, label: "Model configurations", hint: "what an agent thinks with" },
3738
{ to: paths.mcpServers, label: "MCP servers", hint: "the tools agents can reach" },
39+
{ to: egressPoliciesTab, label: egressCopy.page.title, hint: egressCopy.page.notFoundHint },
3840
{ to: paths.prompts, label: "Prompts", hint: "reusable prompt libraries" },
3941
];
4042

0 commit comments

Comments
 (0)