Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { DaemonSessionTaskStatus } from '@qwen-code/sdk/daemon';
import { act, type ReactNode } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { I18nProvider } from '../../i18n';
import { EnvironmentPanel } from './EnvironmentPanel';
import type { SourcesState } from './SourcesSection';
Expand Down Expand Up @@ -44,11 +44,17 @@ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
let container: HTMLDivElement | null = null;
let root: Root | null = null;

beforeEach(() => {
// The add-source button is hidden by default; enable it for these tests.
window.history.replaceState({}, '', '/?addSource=1');
});

afterEach(() => {
act(() => root?.unmount());
container?.remove();
container = null;
root = null;
window.history.replaceState({}, '', '/');
});

function mount(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @vitest-environment jsdom

import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { I18nProvider } from '../../i18n';
import { SourcesSection, type SourcesState } from './SourcesSection';

Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });

let container: HTMLDivElement | null = null;
let root: Root | null = null;

afterEach(() => {
act(() => root?.unmount());
container?.remove();
container = null;
root = null;
window.history.replaceState({}, '', '/');
});

function supportedState(): SourcesState {
return {
supported: true,
sources: [],
owner: { isCurrent: () => true },
revision: 1,
hydrated: true,
loading: false,
error: null,
refresh: vi.fn(),
upsert: vi.fn(),
remove: vi.fn(),
};
}

function mount(): HTMLDivElement {
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);
act(() => {
root!.render(
<I18nProvider language="en">
<SourcesSection state={supportedState()} />
</I18nProvider>,
);
});
return container;
}

describe('SourcesSection add-source button', () => {
it('is hidden by default', () => {
const el = mount();
expect(el.querySelector('button[aria-label="Add source"]')).toBeNull();
});

it('appears when the addSource URL parameter is set', () => {
window.history.replaceState({}, '', '/?addSource=1');
const el = mount();
expect(el.querySelector('button[aria-label="Add source"]')).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import styles from './EnvironmentPanel.module.css';

export type SourcesState = ReturnType<typeof useSessionSources>;

// Escape hatch: the add-source affordance is hidden by default; append
// ?addSource=1 to the URL to bring it back.
function isAddSourceEnabled(): boolean {
if (typeof window === 'undefined') return false;
return new URLSearchParams(window.location.search).get('addSource') === '1';
}

interface SourcesSectionProps {
hidden?: boolean;
state?: SourcesState;
Expand Down Expand Up @@ -97,7 +104,7 @@ export function SourcesSection({
{t('sources.title')}{' '}
<span className="text-muted-foreground">{entries.length}</span>
</h3>
{state?.supported && (
{state?.supported && isAddSourceEnabled() && (
<button
type="button"
className={styles.sectionAction}
Expand Down
Loading