TidGi-Desktop/features/preference.feature
lin onetwo 64cc965a4a
Feat/discuss note with agent (#685)
* Add wiki tiddler attachment support to agent chat

Implements the ability to attach wiki tiddlers to agent chat messages. Updates the UI to allow selection of tiddlers from active wiki workspaces, fetches and renders tiddler content as plain text, and appends it to the user message sent to the AI. Includes e2e tests, updates to store actions, service interfaces, and prompt concatenation logic to support this feature.

* fix: callback not useCallback cause autocomplete panel flash

* Add wiki tiddler attachments to message bubbles

Message bubbles now display attached wiki tiddlers as clickable chips, allowing users to navigate directly to the referenced tiddler in the appropriate workspace. Metadata handling and persistence for wiki tiddlers has been updated to include workspaceId, and tests have been added to verify the new UI behavior. The chat view also now closes the TiddlyWiki sidebar for better focus when navigating from a selection.

* Support split view navigation for wiki tiddler attachments

Adds isSplitView prop to ChatTabContent and related components to distinguish between split view and normal tab modes. Wiki tiddler attachment navigation now uses a different strategy in split view, opening tiddlers directly in the browser view. Updates types and tests to reflect the new behavior, and improves robustness of response handling in several places.

* docs: move to .github/instructions/testing.instructions.md

* test: view loading slow on mac

* refactor(e2e): move wiki load steps to Background in talkWithAI.feature; remove all sidebar close delays and polling, only set state when TiddlyWiki is ready; clean up code and logs for sidebar auto-close in split view

* docs: make test inst shorter

* lint

* refactor(view): slim ViewService, move menu to separate file, orchestrate view logic in WorkspaceViewService, update all callers, fix lint floating promise, all unit and e2e tests pass

* fix: add data-testid to attachment listbox for E2E test

- Add slotProps to MUI Autocomplete to ensure attachment-listbox is rendered with correct test-id
- Fix E2E test timeout when waiting for attachment listbox element

* lint

* put 'Talk with AI' menu on top and attachment i18n

Introduce a reusable createTalkWithAIMenuItems helper to build "Talk with AI" menu entries (default agent + other agents submenu) and integrate it into workspace menu generation. Add new i18n keys for Agent.Attachment and WikiEmbed across locales and update UI to use translation keys (remove hardcoded fallback strings). Improve chat input/attachment behavior: expose a test-id for the attachment listbox, use i18n for labels/placeholders, and tweak input component wiring. Fix Cucumber step handling by normalizing expected newline sequences and safely handling empty message content. Also adjust memo deps in SortableWorkspaceSelectorButton to include id.

* feat: enhance AI interaction in workspace context menu with local trigger support

* feat: add tool approval and timeout settings

- Introduced ToolApprovalConfig and related types for managing tool execution approvals.
- Implemented WebFetch and ZxScript tools for fetching web content and executing scripts, respectively.
- Added token estimation utilities for context window management.
- Enhanced ModelInfo interface with context window size and max output tokens.
- Created API Retry Utility for handling transient failures with exponential backoff.
- Updated AIAgent preferences section to include Tool Approval & Timeout Settings dialog.
- Developed ToolApprovalSettingsDialog for configuring tool-specific approval rules and retry settings.
- Modified vitest configuration to support aliasing for easier imports and stubbing.

* Refactor agent instance tools and services for improved modularity and maintainability

- Extracted type definitions and tool registry from defineTool.ts into separate files (defineToolTypes.ts, toolRegistry.ts) to reduce file size and enhance importability.
- Implemented a retry mechanism in ExternalAPIService for stream creation to handle transient failures.
- Updated ToolApprovalSettingsDialog to persist settings using localStorage instead of a preference service.
- Created agentMessagePersistence.ts and agentRepository.ts to manage agent message and instance CRUD operations, reducing the size of AgentInstanceService.
- Added a progress tracker document (AgentTODO.md) for the ongoing enhancement plan of the TidGi Agent.

* feat: add AgentSwitcher component for agent definition switching

- Implemented AgentSwitcher component with dropdown functionality for selecting agent definitions.
- Integrated loading of agent definitions on dropdown open.
- Added visual feedback for current selection and disabled state.

feat: create ToolResultRenderer for generic tool result messages

- Developed ToolResultRenderer to handle rendering of <functions_result> messages.
- Included collapsible parameters and result display with error handling.
- Added truncation for long results in collapsed view.

test: add comprehensive tests for MessageRenderer components

- Implemented tests for AskQuestionRenderer, ToolResultRenderer, ToolApprovalRenderer, and BaseMessageRenderer.
- Ensured proper rendering and functionality for various message types and states.
- Included pattern routing tests for MessageRenderer.

feat: introduce TurnActionBar for action management in agent turns

- Created TurnActionBar component for managing actions like rollback, retry, delete, and copy.
- Integrated visual feedback for file changes and rollback status.
- Added functionality for copying agent responses and full conversation to clipboard.

feat: implement askQuestionPending for managing user responses

- Developed infrastructure for handling pending ask-question requests.
- Implemented promise-based blocking until user responds to agent questions.
- Added timeout handling for ask-question requests.

* feat: Implement background task management for agent instances

- Added functionality to restore heartbeat timers and alarms for active agents upon service initialization.
- Introduced methods to retrieve active background tasks and cancel them via the UI.
- Enhanced alarm clock tool to persist alarm data in the database, ensuring alarms survive app restarts.
- Updated agent instance schema to include scheduled alarm data.
- Modified prompt concatenation logic to support context window size for message history.
- Removed system prompt parameter from model parameters schema and related components.
- Improved UI to display and manage background tasks, including heartbeat and alarm details.

* feat: Implement Scheduled Tasks Management and Background Task Settings

- Add feature for managing scheduled tasks for agents, including viewing, adding, and editing tasks.
- Create tests for agent repository and background task settings APIs.
- Introduce ScheduledTaskManager for unified scheduling of tasks with interval, at, and cron schedules.
- Implement edit-agent-definition tool for modifying agent configurations, including heartbeat and prompt settings.
- Ensure tasks persist across app restarts and respect active hours filtering.

* Update wiki

* fix(security): harden htmlToText against XSS via encoded tags

- Use tolerant script/style regex that handles </script > with spaces
- Stop decoding &lt;/&gt; entities to prevent reintroducing HTML tags
- Decode &amp; last to avoid double-unescaping (&amp;lt;  &lt;  <)
- Fixes all 4 CodeQL findings (bad filtering, incomplete sanitization,
  double escaping, incomplete multi-character sanitization)

* fix: lint and format errors (eslint naming, dprint formatting, stub classes)

* fix: exclude tidgi.config.json from template copy and fix log marker pattern

- Skip tidgi.config.json when copying wiki template to prevent overriding workspace name
- Change waitForLogMarker default pattern from 'wiki-' to '*' to match actual log filenames
- Filter tidgi.config.json in e2e step too (fs.copy in wiki creation step)

* perf(e2e): merge 5 scheduledTask scenarios into 2 to reduce app restarts

* perf(e2e): merge crossWindowSync and streamingStatus scenarios to reduce CI time

* ci: increase test timeout to 20min for larger e2e scenario count

* perf(e2e): merge agent scenarios and enable parallel on CI

- Merge agent.feature wiki-search + wiki-operation into one scenario
- Merge agent.feature create-agent-from-newtab + create-agent-from-fallback into one
- Enable cucumber parallel: 2 on CI (7GB RAM, dynamic ports for mock servers)
- Total scenarios: 66 -> 61

* fix: cleanup MCP client processes when deleting or closing agent

* ci: disable parallel (CPU contention), increase timeout to 30min for 61 scenarios

* perf(e2e): merge 3 preference background-task scenarios into 1, increase timeout to 45min

- Preference alarm/heartbeat CRUD merged into single scenario (saves 2 app restarts)
- Total scenarios: 59 (was 66)
- CI timeout 45min for the expanded e2e suite

* fix: restructure e2e scenarios, fix subscription leak and debounce cleanup

- Restructure agent/talkWithAI/streamingStatus feature files for reliability
- Fix talkWithAI scenarios missing mock server startup and app launch
- Remove duplicate subscription in handleSwitchAgent (useEffect already handles it)
- Clean up debounced update functions when agent is deleted/closed
- Use agentId:messageId key for debounced functions to enable per-agent cleanup

* fix(e2e): remove :last-child selectors broken by TurnActionBar, fix tab/dialog selectors, increase CI timeout to 25min

* fix: use const for non-reassigned variable (lint)

* fix(e2e): fix close-all-tabs opacity issue, scheduledTask undefined steps, MUI multiline textarea targeting

* fix(e2e): use tab-list-dropdown to close all tabs, fix selector for actual TabListDropdown component

* fix(e2e): add timing waits for BrowserView repositioning and git log UI refresh

* fix(e2e): make 'should not see' step wait for element to disappear instead of instant check

* fix(e2e): increase executeInBrowserView default timeout from 500ms to 2000ms
2026-03-09 04:07:39 +08:00

134 lines
12 KiB
Gherkin

Feature: TidGi Preference
As a user
I want to configure my preferences for the intelligent agent and so on
So that I can customize its behavior and improve my experience
Background:
Given I launch the TidGi application
And I wait for the page to load completely
And I should see a "page body" element with selector "body"
@ai-setting
Scenario: Configure AI provider and default model
# Step 1: Configure AI settings first - Open preferences window, wait a second so its URL settle down.
When I click on a "settings button" element with selector "#open-preferences-button"
When I switch to "preferences" window
# Step 2: Navigate to External Services section and add new provider
When I click on "external services section and add provider button" elements with selectors:
| element description | selector |
| external services section | [data-testid='preference-section-externalAPI'] |
| add provider button | [data-testid='add-new-provider-button'] |
# Step 4: Fill provider form with mock server details (interface type already selected as openAICompatible)
When I type "TestProvider" in "provider name input" element with selector "[data-testid='new-provider-name-input']"
And I type "http://127.0.0.1:15121/v1" in "API endpoint input" element with selector "[data-testid='new-provider-base-url-input']"
When I click on an "add provider submit" element with selector "[data-testid='add-provider-submit-button']"
# Step 5: Select the new provider and add a model
When I click on "provider tab and add model button" elements with selectors:
| element description | selector |
| provider tab TestProvider | button[role='tab']:has-text('TestProvider') |
| add model button | [data-testid='add-new-model-button'] |
# Step 6: Add language model (will auto-fill as default language model)
When I type "test-model" in "model name input" element with selector "[data-testid='new-model-name-input']"
When I click on "save model button and add model button" elements with selectors:
| element description | selector |
| save model button | [data-testid='save-model-button'] |
| add model button | [data-testid='add-new-model-button'] |
# Step 7: Add embedding model (will auto-fill as default embedding model)
When I type "test-embedding-model" in "model name input" element with selector "[data-testid='new-model-name-input']"
When I click on "embedding feature checkbox and save model button and add model button" elements with selectors:
| element description | selector |
| embedding feature checkbox | [data-testid='feature-checkbox-embedding'] |
| save model button | [data-testid='save-model-button'] |
| add model button | [data-testid='add-new-model-button'] |
# Step 8: Add speech model (will auto-fill as default speech model)
When I type "test-speech-model" in "model name input" element with selector "[data-testid='new-model-name-input']"
# Uncheck language feature first (it's checked by default)
When I click on "language feature checkbox and speech feature checkbox and save model button" elements with selectors:
| element description | selector |
| language feature checkbox | [data-testid='feature-checkbox-language'] |
| speech feature checkbox | [data-testid='feature-checkbox-speech'] |
| save model button | [data-testid='save-model-button'] |
# Step 9: Verify auto-fill worked by checking that autocomplete inputs have the correct selected values
# MUI Autocomplete shows selected value in the input, we check by looking for the model name in the visible text
Then I should see "model values and autocomplete inputs" elements with selectors:
| element description | selector |
| default language model value test-model | text='test-model' |
| default embedding model value test-embedding-model | text='test-embedding-model' |
| default speech model value test-speech-model | text='test-speech-model' |
| first autocomplete input with test-model | xpath=(//div[contains(@class,'MuiAutocomplete-root')]//input[@value='test-model'])[1] |
| second autocomplete input with test-embedding-model | xpath=(//div[contains(@class,'MuiAutocomplete-root')]//input[@value='test-embedding-model'])[1] |
| third autocomplete input with test-speech-model | xpath=(//div[contains(@class,'MuiAutocomplete-root')]//input[@value='test-speech-model'])[1] |
# Verify the autocomplete is not empty and negative case remain explicit
Then I should not see a "empty first autocomplete placeholder" element with selector "xpath=(//label[contains(text(),'Preference.SelectModel')])[1]"
Then I should not see a "test-model after test-embedding-model (wrong order)" element with selector "xpath=//input[@value='test-embedding-model']/following::input[@value='test-model']"
# Step 10: Add ComfyUI provider with workflow path
When I click on "add provider button and select from preset dropdown and comfyui preset option and add provider submit and provider tab and add model button" elements with selectors:
| element description | selector |
| add provider button | [data-testid='add-new-provider-button'] |
| select from preset dropdown | div[role='combobox'] |
| comfyui preset option | li:has-text('comfyui') |
| add provider submit button | [data-testid='add-provider-submit-button'] |
| provider tab comfyui | button[role='tab']:has-text('comfyui') |
| add model button | [data-testid='add-new-model-button'] |
When I type "test-flux" in "model name input" element with selector "[data-testid='new-model-name-input']"
When I click on "language feature checkbox and imageGeneration feature checkbox" elements with selectors:
| element description | selector |
| language feature checkbox | [data-testid='feature-checkbox-language'] |
| imageGeneration feature checkbox | [data-testid='feature-checkbox-imageGeneration'] |
When I type "C:/test/mock/workflow.json" in "workflow path input" element with selector "[data-testid='workflow-path-input']"
When I click on a "save model button" element with selector "[data-testid='save-model-button']"
Then I should see a "test-flux model chip" element with selector "[data-testid='model-chip-test-flux']"
# Verify workflow path was saved by clicking to edit
When I click on a "test-flux model chip" element with selector "[data-testid='model-chip-test-flux']"
Then I should see a "workflow path input with value" element with selector "[data-testid='workflow-path-input'][value='C:/test/mock/workflow.json']"
When I press "Escape" key
# Step 11: Close preferences window
When I close "preferences" window
And I ensure test ai settings exists
@ai-setting
Scenario: Background tasks — create alarm, edit-to-interval, cancel, create heartbeat, disable
When I click on "agent workspace button and new tab button and create default agent button" elements with selectors:
| element description | selector |
| agent workspace | [data-testid='workspace-agent'] |
| new tab button | [data-tab-id='new-tab-button'] |
| create default agent button | [data-testid='create-default-agent-button'] |
And I should see a "message input box" element with selector "[data-testid='agent-message-input']"
When I click on a "settings button" element with selector "#open-preferences-button"
And I switch to "preferences" window
And I click on a "ai agent section" element with selector "[data-testid='preference-section-aiAgent']"
# --- Part A: Create countdown alarm ---
And I click on a "add background task button" element with selector "[data-testid='bg-task-add-button']"
Then I should see "countdown and message input" elements with selectors:
| element description | selector |
| countdown input | [data-testid='bg-task-countdown-input'] |
| message input | [data-testid='bg-task-message-input'] |
When I type "2" in "countdown input" element with selector "[data-testid='bg-task-countdown-input'] input"
And I type "Preference-created countdown task" in "message input" element with selector "[data-testid='bg-task-message-input'] input"
And I click on a "save background task button" element with selector "[data-testid='bg-task-save-button']"
Then I should see a "created alarm cancel button" element with selector "[data-testid^='cancel-bg-task-'][data-testid$='-alarm']"
# --- Part B: Create another alarm, edit to interval, then cancel ---
And I click on a "add background task button" element with selector "[data-testid='bg-task-add-button']"
When I type "3" in "countdown input" element with selector "[data-testid='bg-task-countdown-input'] input"
And I type "Alarm task for edit" in "message input" element with selector "[data-testid='bg-task-message-input'] input"
And I click on a "save background task button" element with selector "[data-testid='bg-task-save-button']"
Then I should see a "created alarm edit button" element with selector "[data-testid^='edit-bg-task-'][data-testid$='-alarm']"
When I click on a "alarm edit button" element with selector "[data-testid^='edit-bg-task-'][data-testid$='-alarm']"
And I click on a "schedule mode select" element with selector "[data-testid='bg-task-mode-select']"
And I click on a "interval mode option" element with selector "li[role='option']:has-text('Interval')"
And I type "5" in "interval input" element with selector "[data-testid='bg-task-interval-input'] input"
And I click on a "save background task button" element with selector "[data-testid='bg-task-save-button']"
Then I should see a "repeat interval text" element with selector "*:has-text('repeat every 5min')"
When I click on a "alarm cancel button" element with selector "[data-testid^='cancel-bg-task-'][data-testid$='-alarm']"
Then I should not see a "alarm cancel button" element with selector "[data-testid^='cancel-bg-task-'][data-testid$='-alarm']"
# --- Part C: Create heartbeat and disable it ---
And I click on a "add heartbeat button" element with selector "[data-testid='bg-heartbeat-add-button']"
When I type "120" in "heartbeat interval input" element with selector "[data-testid='bg-heartbeat-interval-input'] input"
And I type "Heartbeat from preferences" in "heartbeat message input" element with selector "[data-testid='bg-heartbeat-message-input'] input"
And I click on a "save heartbeat button" element with selector "[data-testid='bg-heartbeat-save-button']"
Then I should see a "heartbeat cancel button" element with selector "[data-testid^='cancel-bg-task-'][data-testid$='-heartbeat']"
When I click on a "heartbeat edit button" element with selector "[data-testid^='edit-bg-task-'][data-testid$='-heartbeat']"
And I click on a "heartbeat enabled select" element with selector "[data-testid='bg-heartbeat-enabled-select']"
And I click on a "heartbeat disabled option" element with selector "li[role='option']:has-text('Disabled')"
And I click on a "save heartbeat button" element with selector "[data-testid='bg-heartbeat-save-button']"
Then I should not see a "heartbeat cancel button" element with selector "[data-testid^='cancel-bg-task-'][data-testid$='-heartbeat']"