Skip to content

Commit 2bed0a4

Browse files
author
Onur
authored
refactor(routes): remove legacy chat route compatibility (#143)
1 parent 31365e3 commit 2bed0a4

5 files changed

Lines changed: 8 additions & 48 deletions

File tree

api/main_create_owner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ func TestCreateSpritzOwnerUsesIDAndOmitsEmail(t *testing.T) {
6666
if _, exists := owner["email"]; exists {
6767
t.Fatalf("expected owner.email to be omitted from response, got %#v", owner["email"])
6868
}
69-
if data["accessUrl"] != "http://tidal-ember.spritz-test.svc.cluster.local:8080/#chat/tidal-ember" {
69+
if data["accessUrl"] != "http://tidal-ember.spritz-test.svc.cluster.local:8080/c/tidal-ember" {
7070
t.Fatalf("expected accessUrl to prefer chat url, got %#v", data["accessUrl"])
7171
}
72-
if data["chatUrl"] != "http://tidal-ember.spritz-test.svc.cluster.local:8080/#chat/tidal-ember" {
72+
if data["chatUrl"] != "http://tidal-ember.spritz-test.svc.cluster.local:8080/c/tidal-ember" {
7373
t.Fatalf("expected chatUrl in response, got %#v", data["chatUrl"])
7474
}
7575
if data["instanceUrl"] != "http://tidal-ember.spritz-test.svc.cluster.local:8080" {

operator/api/v1/access_url.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func ChatURLForSpritz(spritz *Spritz) string {
6060
return parsed.String()
6161
}
6262

63-
parsed.Path = "/"
64-
parsed.RawPath = "/"
63+
parsed.Path = fmt.Sprintf("/c/%s", name)
64+
parsed.RawPath = parsed.Path
6565
parsed.RawQuery = ""
66-
parsed.Fragment = fmt.Sprintf("chat/%s", name)
66+
parsed.Fragment = ""
6767
return parsed.String()
6868
}
6969

operator/api/v1/access_url_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ func TestAccessURLForSpritzPromotesChatURL(t *testing.T) {
5454
}
5555
}
5656

57-
func TestAccessURLForSpritzPreservesFragmentChatRouteWithoutIngress(t *testing.T) {
57+
func TestAccessURLForSpritzUsesCanonicalPathRouteWithoutIngress(t *testing.T) {
5858
spritz := &Spritz{
5959
ObjectMeta: metav1ObjectMeta("openclaw-tide-wind", "spritz-test"),
6060
Spec: SpritzSpec{
6161
Ports: []SpritzPort{{ContainerPort: 8080}},
6262
},
6363
}
6464

65-
want := "http://openclaw-tide-wind.spritz-test.svc.cluster.local:8080/#chat/openclaw-tide-wind"
65+
want := "http://openclaw-tide-wind.spritz-test.svc.cluster.local:8080/c/openclaw-tide-wind"
6666
if got := AccessURLForSpritz(spritz); got != want {
6767
t.Fatalf("expected access url %q, got %q", want, got)
6868
}

ui/src/App.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function renderAtRoute(path: string) {
3131
<Route path="create" element={<div data-testid="create-page">Create Page</div>} />
3232
<Route path="terminal/:name" element={<div data-testid="terminal-page">Terminal Page</div>} />
3333
<Route path="c/:name?" element={<div data-testid="chat-page">Chat Page</div>} />
34-
<Route path="chat/:name?" element={<div data-testid="chat-page">Chat Page</div>} />
3534
</Routes>
3635
</NoticeProvider>
3736
</ConfigProvider>

ui/src/App.tsx

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,25 @@
1-
import { useEffect } from 'react';
2-
import { BrowserRouter, Routes, Route, useNavigate, useLocation } from 'react-router-dom';
1+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
32
import { ConfigProvider, config } from '@/lib/config';
43
import { BrandingEffects } from '@/components/branding-effects';
54
import { NoticeProvider } from '@/components/notice-banner';
65
import { Layout } from '@/components/layout';
7-
import { chatConversationPath, chatPath } from '@/lib/urls';
86
import { ChatPage } from '@/pages/chat';
97
import { CreatePage } from '@/pages/create';
108
import { TerminalPage } from '@/pages/terminal';
119

12-
function HashRedirect() {
13-
const navigate = useNavigate();
14-
const location = useLocation();
15-
16-
useEffect(() => {
17-
const hash = window.location.hash;
18-
if (!hash || hash === '#') return;
19-
20-
// Convert legacy hash routes to path routes.
21-
// #chat/name → /c/name
22-
// #create → /create
23-
// #terminal/name → /terminal/name
24-
const match = hash.match(/^#(chat|terminal|create)(?:\/(.+?))?(?:\/([^/]+))?$/);
25-
if (match) {
26-
const route = match[1];
27-
const param = match[2] || '';
28-
const subParam = match[3] || '';
29-
const path = route === 'chat'
30-
? subParam
31-
? chatConversationPath(param, subParam)
32-
: chatPath(param)
33-
: subParam
34-
? `/${route}/${param}/${subParam}`
35-
: param
36-
? `/${route}/${param}`
37-
: `/${route}`;
38-
window.history.replaceState(null, '', window.location.pathname + window.location.search);
39-
navigate(path, { replace: true });
40-
}
41-
}, [location, navigate]);
42-
43-
return null;
44-
}
45-
4610
export function App() {
4711
return (
4812
<BrowserRouter>
4913
<ConfigProvider value={config}>
5014
<BrandingEffects />
5115
<NoticeProvider>
52-
<HashRedirect />
5316
<Routes>
5417
<Route element={<Layout />}>
5518
<Route index element={<ChatPage />} />
5619
<Route path="create" element={<CreatePage />} />
5720
<Route path="terminal/:name" element={<TerminalPage />} />
5821
<Route path="c/:name?" element={<ChatPage />} />
5922
<Route path="c/:name/:conversationId" element={<ChatPage />} />
60-
<Route path="chat/:name?" element={<ChatPage />} />
61-
<Route path="chat/:name/:conversationId" element={<ChatPage />} />
6223
</Route>
6324
</Routes>
6425
</NoticeProvider>

0 commit comments

Comments
 (0)