Refine knowledge brain workflow

Align the brain prompts, graph view, and startup defaults with the
latest phase 1 flow so local runs and navigation stay consistent.
This commit is contained in:
2026-03-22 22:42:47 +08:00
parent 67ea3d2682
commit 6f594631e9
23 changed files with 1508 additions and 526 deletions

View File

@@ -0,0 +1,38 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
const { apiGetMock } = vi.hoisted(() => ({
apiGetMock: vi.fn(),
}))
vi.mock('@/api', () => ({
default: {
get: apiGetMock,
post: vi.fn(),
interceptors: {
request: { use: vi.fn() },
response: { use: vi.fn() },
},
},
}))
describe('auth router guard', () => {
beforeEach(() => {
vi.resetModules()
localStorage.clear()
apiGetMock.mockReset()
window.history.replaceState({}, '', '/')
setActivePinia(createPinia())
})
it('redirects to /login when a stored token fails validation during startup', async () => {
localStorage.setItem('access_token', 'stale-token')
apiGetMock.mockRejectedValueOnce({ response: { status: 401 } })
const { default: router } = await import('./index')
await router.push('/chat')
expect(router.currentRoute.value.fullPath).toBe('/login')
})
})

View File

@@ -7,8 +7,11 @@ const router = createRouter({
routes,
})
router.beforeEach((to, _from, next) => {
router.beforeEach(async (to, _from, next) => {
const auth = useAuthStore()
await auth.ensureAuthReady()
if (to.meta.requiresAuth && !auth.isAuthenticated) {
next('/login')
} else if (to.meta.guest && auth.isAuthenticated) {