feat: move plugin workspace into project settings

This commit is contained in:
inman
2026-09-07 10:06:37 +08:00
parent f8eee430f4
commit be1764e016
19 changed files with 363 additions and 76 deletions

View File

@@ -1,7 +1,11 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
import { describe, expect, it } from 'vitest';
import { LegacyPluginRedirect } from '@/pages/Plugins/legacy-plugin-redirect';
import {
LegacyPluginRedirect,
PluginWorkspaceRedirect,
PROJECT_SETTINGS_PLUGINS_PATH,
} from '@/pages/Plugins/legacy-plugin-redirect';
import { getGuardedAiModuleForPath, isProgrammingProviderRoute } from '@/lib/ai-modules';
function LocationProbe() {
@@ -17,15 +21,15 @@ function LocationProbe() {
describe('plugin navigation cutover', () => {
it.each([
['/plugin-marketplace', '/plugins?scope=all&source=official'],
['/my-plugins', '/plugins?scope=all&state=mine'],
['/project-plugins', '/plugins?scope=project'],
['/plugin-marketplace', `${PROJECT_SETTINGS_PLUGINS_PATH}?scope=all&source=official`],
['/my-plugins', `${PROJECT_SETTINGS_PLUGINS_PATH}?scope=all&state=mine`],
['/project-plugins', `${PROJECT_SETTINGS_PLUGINS_PATH}?scope=project`],
] as const)('replace-redirects %s to %s', async (legacy, canonical) => {
render(
<MemoryRouter initialEntries={['/previous', legacy]} initialIndex={1}>
<Routes>
<Route path={legacy} element={<LegacyPluginRedirect from={legacy} />} />
<Route path="/plugins" element={<LocationProbe />} />
<Route path={PROJECT_SETTINGS_PLUGINS_PATH} element={<LocationProbe />} />
<Route path="/previous" element={<output data-testid="previous">previous</output>} />
</Routes>
</MemoryRouter>,
@@ -36,8 +40,26 @@ describe('plugin navigation cutover', () => {
expect(await screen.findByTestId('previous')).toBeVisible();
});
it('classifies the canonical page as Code without making it provider-gated', () => {
expect(getGuardedAiModuleForPath('/plugins')).toBe('programming');
expect(isProgrammingProviderRoute('/plugins')).toBe(false);
it('moves the former canonical URL into project settings without losing its query', async () => {
render(
<MemoryRouter initialEntries={['/previous', '/plugins?scope=all&state=mine']} initialIndex={1}>
<Routes>
<Route path="/plugins" element={<PluginWorkspaceRedirect />} />
<Route path={PROJECT_SETTINGS_PLUGINS_PATH} element={<LocationProbe />} />
<Route path="/previous" element={<output data-testid="previous">previous</output>} />
</Routes>
</MemoryRouter>,
);
expect(await screen.findByTestId('location')).toHaveTextContent(
`${PROJECT_SETTINGS_PLUGINS_PATH}?scope=all&state=mine`,
);
fireEvent.click(screen.getByRole('button', { name: '返回' }));
expect(await screen.findByTestId('previous')).toBeVisible();
});
it('classifies the project-settings plugin page as Code without making it provider-gated', () => {
expect(getGuardedAiModuleForPath(PROJECT_SETTINGS_PLUGINS_PATH)).toBe('programming');
expect(isProgrammingProviderRoute(PROJECT_SETTINGS_PLUGINS_PATH)).toBe(false);
});
});