Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

test(ui): resolve nested application routes

Max72d16dc89df3
diff --git a/ui/src/lib/applicationRoutes.test.ts b/ui/src/lib/applicationRoutes.test.ts
index e775347b5..993ddf0f8 100644
--- a/ui/src/lib/applicationRoutes.test.ts
+++ b/ui/src/lib/applicationRoutes.test.ts
@@ -1,5 +1,6 @@
import { readFileSync } from 'node:fs';
+import * as ts from 'typescript';
import { describe, expect, it } from 'vitest';
import {
@@ -8,10 +9,56 @@ import {
isApplicationRouteHref,
} from './applicationRoutes';
+function routePath(element: ts.JsxOpeningLikeElement): string | null {
+ if (element.tagName.getText() !== 'Route') return null;
+ const path = element.attributes.properties.find(
+ (property): property is ts.JsxAttribute =>
+ ts.isJsxAttribute(property) && property.name.getText() === 'path',
+ );
+ return path?.initializer && ts.isStringLiteral(path.initializer)
+ ? path.initializer.text
+ : null;
+}
+
+function resolveRoutePath(path: string, parentPath: string | null): string {
+ if (path.startsWith('/') || path === '*') return path;
+ return parentPath ? `${parentPath.replace(/\/$/, '')}/${path}` : path;
+}
+
+function declaredRoutePaths(sourceText: string): string[] {
+ const source = ts.createSourceFile(
+ 'App.tsx',
+ sourceText,
+ ts.ScriptTarget.Latest,
+ true,
+ ts.ScriptKind.TSX,
+ );
+ const declared: string[] = [];
+
+ const visit = (node: ts.Node, parentPath: string | null) => {
+ if (ts.isJsxElement(node)) {
+ const path = routePath(node.openingElement);
+ const resolvedPath = path === null ? parentPath : resolveRoutePath(path, parentPath);
+ if (path !== null) declared.push(resolvedPath as string);
+ node.children.forEach((child) => visit(child, resolvedPath));
+ return;
+ }
+ if (ts.isJsxSelfClosingElement(node)) {
+ const path = routePath(node);
+ if (path !== null) declared.push(resolveRoutePath(path, parentPath));
+ return;
+ }
+ ts.forEachChild(node, (child) => visit(child, parentPath));
+ };
+
+ visit(source, null);
+ return declared;
+}
+
describe('AppShell route policy', () => {
it('matches every path declared by App.tsx', () => {
const appSource = readFileSync(new URL('../App.tsx', import.meta.url), 'utf8');
- const declared = Array.from(appSource.matchAll(/<Route\s+path="([^"]+)"/g), (match) => match[1]);
+ const declared = declaredRoutePaths(appSource);
const catalog = [...APPLICATION_ROUTE_PATHS, ...APPLICATION_DYNAMIC_ROUTE_PATHS];
expect([...declared].sort()).toEqual([...catalog].sort());