Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

refactor(webui): migrate remaining route literals to registry, add drift test

Sergey Kozyrenko1cc7d2698793
diff --git a/frontend/src/features/flows/use-flow-detail-navigation.ts b/frontend/src/features/flows/use-flow-detail-navigation.ts
index b88f2f5d..81be9ef8 100644
--- a/frontend/src/features/flows/use-flow-detail-navigation.ts
+++ b/frontend/src/features/flows/use-flow-detail-navigation.ts
@@ -1,10 +1,11 @@
import { useDetailNavigation } from '@/components/shared/detail-navigation';
+import { routes } from '@/lib/routes';
import { type Flow, useFlows } from '@/providers/flows-provider';
const getLabel = (item: Flow) => item.title || `Flow #${item.id}`;
const getSearchableText = (item: Flow) => item.title;
const getId = (item: Flow) => String(item.id);
-const getHref = (item: Flow) => `/flows/${item.id}`;
+const getHref = (item: Flow) => routes.flow(item.id);
/**
* Detail-page navigation wired up for flows. Encapsulates the getter
diff --git a/frontend/src/features/knowledges/use-knowledge-detail-navigation.ts b/frontend/src/features/knowledges/use-knowledge-detail-navigation.ts
index 38241a6f..b9e0b073 100644
--- a/frontend/src/features/knowledges/use-knowledge-detail-navigation.ts
+++ b/frontend/src/features/knowledges/use-knowledge-detail-navigation.ts
@@ -1,8 +1,9 @@
import { useDetailNavigation } from '@/components/shared/detail-navigation';
+import { routes } from '@/lib/routes';
import { type Knowledge, useKnowledges } from '@/providers/knowledges-provider';
const getLabel = (item: Knowledge) => item.question;
-const getHref = (item: Knowledge) => `/knowledges/${item.id}`;
+const getHref = (item: Knowledge) => routes.knowledge(item.id);
/**
* Detail-page navigation wired up for knowledge documents. Returns a
diff --git a/frontend/src/features/templates/use-template-detail-navigation.ts b/frontend/src/features/templates/use-template-detail-navigation.ts
index 26ef3369..e8aa77c0 100644
--- a/frontend/src/features/templates/use-template-detail-navigation.ts
+++ b/frontend/src/features/templates/use-template-detail-navigation.ts
@@ -1,9 +1,10 @@
import { useDetailNavigation } from '@/components/shared/detail-navigation';
+import { routes } from '@/lib/routes';
import { type Template, useTemplates } from '@/providers/templates-provider';
const getLabel = (item: Template) => item.title;
const getId = (item: Template) => String(item.id);
-const getHref = (item: Template) => `/templates/${item.id}`;
+const getHref = (item: Template) => routes.template(item.id);
/**
* Detail-page navigation wired up for templates. Returns a
diff --git a/frontend/src/lib/routes.test.ts b/frontend/src/lib/routes.test.ts
new file mode 100644
index 00000000..b4f818cb
--- /dev/null
+++ b/frontend/src/lib/routes.test.ts
@@ -0,0 +1,51 @@
+import { matchPath } from 'react-router-dom';
+import { describe, expect, it } from 'vitest';
+
+import { routes } from './routes';
+
+// Mirrors the absolute route patterns from app.tsx; keep in sync when routes change there.
+const builtUrlToPattern: [string, string][] = [
+ [routes.dashboard, '/dashboard'],
+ [routes.flows, '/flows'],
+ [routes.newFlow, '/flows/new'],
+ [routes.flow('abc'), '/flows/:flowId'],
+ [routes.flowReport('abc'), '/flows/:flowId/report'],
+ [routes.templates, '/templates'],
+ [routes.newTemplate, '/templates/:templateId'],
+ [routes.template('t1'), '/templates/:templateId'],
+ [routes.knowledges, '/knowledges'],
+ [routes.newKnowledge, '/knowledges/:knowledgeId'],
+ [routes.knowledge('k1'), '/knowledges/:knowledgeId'],
+ [routes.resources, '/resources'],
+ [routes.settings.root, '/settings'],
+ [routes.settings.account, '/settings/account'],
+ [routes.settings.providers, '/settings/providers'],
+ [routes.settings.provider('p1'), '/settings/providers/:providerId'],
+ [routes.settings.newProvider(), '/settings/providers/:providerId'],
+ [routes.settings.prompts, '/settings/prompts'],
+ [routes.settings.prompt('p1'), '/settings/prompts/:promptId'],
+ [routes.settings.apiTokens, '/settings/api-tokens'],
+ [routes.login(), '/login'],
+ [routes.oauthResult, '/oauth/result'],
+ [routes.root, '/'],
+];
+
+describe('routes registry', () => {
+ it.each(builtUrlToPattern)('builds %s, matched by route pattern %s', (url, pattern) => {
+ expect(matchPath(pattern, url)).not.toBeNull();
+ });
+
+ it('encodes query params for builders that accept them', () => {
+ expect(routes.flow('1', { tab: 'chat' })).toBe('/flows/1?tab=chat');
+ expect(routes.flow('1')).toBe('/flows/1');
+ expect(routes.settings.newProvider({ id: 'a', type: 'b' })).toBe('/settings/providers/new?id=a&type=b');
+ expect(routes.settings.newProvider()).toBe('/settings/providers/new');
+ });
+
+ it('builds the login url with an encoded return path, except for non-returnable origins', () => {
+ expect(routes.login('/dashboard')).toBe('/login?returnUrl=%2Fdashboard');
+ expect(routes.login()).toBe('/login');
+ expect(routes.login('/flows/new')).toBe('/login');
+ expect(routes.login('/login')).toBe('/login');
+ });
+});
diff --git a/frontend/src/pages/flows/flow.tsx b/frontend/src/pages/flows/flow.tsx
index d16e71e5..36dbd64a 100644
--- a/frontend/src/pages/flows/flow.tsx
+++ b/frontend/src/pages/flows/flow.tsx
@@ -481,7 +481,7 @@ function FlowReportDropdown() {
return;
}
- const url = `/flows/${flowId}/report?download=true&silent=true`;
+ const url = `${routes.flowReport(flowId)}?download=true&silent=true`;
window.open(url, '_blank');
};
@@ -490,7 +490,7 @@ function FlowReportDropdown() {
return;
}
- const url = `/flows/${flowId}/report`;
+ const url = routes.flowReport(flowId);
window.open(url, '_blank');
};
diff --git a/frontend/src/pages/flows/flows.tsx b/frontend/src/pages/flows/flows.tsx
index 011d8f7b..cadc9e97 100644
--- a/frontend/src/pages/flows/flows.tsx
+++ b/frontend/src/pages/flows/flows.tsx
@@ -79,7 +79,7 @@ function Flows() {
const handleFlowOpen = useCallback(
(flowId: string) => {
- navigate(mergeHrefWithSearchParams(`/flows/${flowId}`, new URLSearchParams(location.search)));
+ navigate(mergeHrefWithSearchParams(routes.flow(flowId), new URLSearchParams(location.search)));
},
[navigate, location.search],
);
diff --git a/frontend/src/pages/knowledges/knowledge.tsx b/frontend/src/pages/knowledges/knowledge.tsx
index b686a141..84172b4b 100644
--- a/frontend/src/pages/knowledges/knowledge.tsx
+++ b/frontend/src/pages/knowledges/knowledge.tsx
@@ -57,7 +57,7 @@ function Knowledge() {
return {
document: created ?? undefined,
- redirectTo: created?.id ? `/knowledges/${created.id}` : '/knowledges',
+ redirectTo: created?.id ? routes.knowledge(created.id) : routes.knowledges,
};
}
diff --git a/frontend/src/pages/knowledges/knowledges.tsx b/frontend/src/pages/knowledges/knowledges.tsx
index 97de279e..fe8d67cf 100644
--- a/frontend/src/pages/knowledges/knowledges.tsx
+++ b/frontend/src/pages/knowledges/knowledges.tsx
@@ -102,7 +102,7 @@ function Knowledges() {
const handleOpen = useCallback(
(id: string) => {
- navigate(mergeHrefWithSearchParams(`/knowledges/${id}`, new URLSearchParams(location.search)));
+ navigate(mergeHrefWithSearchParams(routes.knowledge(id), new URLSearchParams(location.search)));
},
[navigate, location.search],
);
diff --git a/frontend/src/pages/templates/templates.tsx b/frontend/src/pages/templates/templates.tsx
index e22f2e5b..ea86b721 100644
--- a/frontend/src/pages/templates/templates.tsx
+++ b/frontend/src/pages/templates/templates.tsx
@@ -42,7 +42,7 @@ function Templates() {
const handleTemplateOpen = useCallback(
(templateId: string) => {
- navigate(mergeHrefWithSearchParams(`/templates/${templateId}`, new URLSearchParams(location.search)));
+ navigate(mergeHrefWithSearchParams(routes.template(templateId), new URLSearchParams(location.search)));
},
[navigate, location.search],
);
diff --git a/frontend/src/providers/user-provider.tsx b/frontend/src/providers/user-provider.tsx
index 181466d4..a3375ab6 100644
--- a/frontend/src/providers/user-provider.tsx
+++ b/frontend/src/providers/user-provider.tsx
@@ -215,7 +215,7 @@ export function UserProvider({ children }: { children: ReactNode }) {
const loginWithOAuth = useCallback(
async (provider: OAuthProvider): Promise<LoginResult> => {
- const returnOAuthUri = '/oauth/result';
+ const returnOAuthUri = routes.oauthResult;
const width = 500;
const height = 600;
const left = window.screenX + (window.outerWidth - width) / 2;