TidGi-Desktop/features/defaultWiki.feature
lin onetwo a931058f17
chore: upgrade Electron 39->41 + forge 7.10->7.11 + fix native ABI (#692)
* chore: upgrade Electron 39->41, forge 7.10->7.11, fix native ABI and preload naming

- electron: 39.2.3 -> 41.1.1
- @electron-forge/*: 7.10.2 -> 7.11.1
- better-sqlite3: 12.4.5 -> 12.8.0 (rebuild against Electron 41 ABI 145)
- electron-unhandled: 5.0.0 -> 4.0.1 (v5 uses top-level await, breaks CJS main build)
- vite.preload.config.ts: emit preload.js (not index.js) to avoid collision with main
- viteEntry.ts: getPreloadPath() -> preload.js, renderer path unchanged
- package.json main: .vite/build/main.js (matches forge lib output)
- package.json: strip UTF-8 BOM that broke Volta manifest parsing

* fix: resolve AbortSignal realm mismatch in Electron 41 for streaming tests

In Electron 41, ELECTRON_RUN_AS_NODE mode uses Chromium-based fetch which
requires Blink's AbortSignal. Node.js AbortSignal fails the instanceof check.

Fixes:
- vitest.config.ts: set features/** to node environment via environmentMatchGlobs
  so HTTP-only tests use Node.js fetch (not Chromium fetch)
- setup-vitest.ts: guard all document/window access behind typeof document check
  so setup is safe in both jsdom and node environments
- callProviderAPI.ts: no change needed (signal issue is env-specific)

* ci: increase test timeout to 60min, fix find -o with xargs rm

- timeout-minutes: 25 -> 60 (packaging ~22min + unit tests ~1min + e2e needed)
- fix 'find ... -o ... | xargs rm' -> 'find ... \( -o \) ... -exec rm -rf {} +'
  (the unparenthesized -o with xargs caused 'rm: invalid option -- o' in CI)

* fix: copy tiddlywiki/core-server to packaged output

TiddlyWiki 5.4.0-prerelease introduced core-server/ directory which contains
commander.js (module-type: global). Without it, \.Commander is undefined
when load-modules.js startup runs \.Commander.initCommands(), crashing the
wiki worker with 'Cannot read properties of undefined (reading initCommands)'.

core-server is loaded by boot.js via loadPluginFolder(\.boot.coreServerPath),
which silently returns null when the directory is missing, so the error was
non-obvious and only manifested when actually starting a wiki workspace.

* perf: only screenshot on failure, revert timeout to 25min

AfterStep was capturing a screenshot after every step (~1191 of 1446 steps).
Each screenshot requires IPC round-trip: getFirstWebContentsView  capturePage
 serialize PNG  transfer buffer  fs.writeFile. On CI this costs ~200-400ms
per step, totaling ~6 minutes of pure screenshot overhead.

Now screenshots are only taken for FAILED steps, saving ~6 minutes on CI.
This brings the total test time well within the 25-minute budget.

* fix: flaky tests + merge scenarios to save 8 Electron launches

- crossWindowSync: wait for tiddler to be saved to disk via watch-fs before opening second window
- tidgiMiniWindowWorkspace: add retry backoff to 'should not see elements' step
- tidgiMiniWindow: add explicit window switch after addTiddler
- Merge 5 filesystemPlugin scenarios into 1 (save 4 launches)
- Merge 2 defaultWiki scenarios into 1 (save 1 launch)
- Merge 2 preference scenarios into 1 (save 1 launch)
- Merge smoke + logging into 1 (save 1 launch)
- Merge 2 tiddler scenarios into 1 (save 1 launch)
- Total: 65  57 scenarios (8 fewer Electron launches)

* fix: address CI failures - use IPC for mini window toggle, split talkWithAI clicks

- tidgiMiniWindow: use direct IPC toggle instead of keyboard shortcut after addTiddler
  to avoid race condition between TW syncer and keyboard event dispatch
- talkWithAI: split multi-click step into individual clicks so each gets its own
  25s timeout budget on CI

* fix: await showWindow() in openTidgiMiniWindow to prevent race condition

The two showWindow() calls were using void (fire-and-forget), meaning
toggleTidgiMiniWindow returned before the window was actually shown.
On CI/Xvfb, the test checked isVisible() before show() completed.

* perf: merge scenarios + split CI steps for faster E2E

- Merge 3 defaultWiki scenarios into 1 (save 2 app launches)
- Merge 2 scheduledTask scenarios into 1 (save 1 app launch)
- Split CI test step into unit/prepare/e2e for visibility
- Add pnpm store cache to CI
- Fix viteEntry.ts: remove UTF-8 BOM, update stale JSDoc comment
- Set E2E timeout to 22min (was 25min in single step)

* fix: address Copilot review - main window lookup and comment clarity

- tidgiMiniWindow.ts: use index.html URL pattern to find main window
  (consistent with other step defs, avoids matching preferences window)
- ui.ts: clarify networkidle timeout comment

* fix: use IPC toggle for tidgiMiniWindow sync scenario to avoid flaky keyboard shortcut on CI

---------

Co-authored-by: CI Auto <cidevel@tiddlygit.local>
2026-04-02 21:45:47 +08:00

116 lines
7.8 KiB
Gherkin

Feature: TidGi Default Wiki
As a user
I want app auto create a default wiki workspace for me
So that I can start using wiki immediately
@wiki @create-main-workspace @root-tiddler
Scenario: Default wiki content, create new workspace, and configure root tiddler
Given I cleanup test wiki so it could create a new one on start
When I launch the TidGi application
And I wait for the page to load completely
# --- Part 1: Verify default wiki workspace with TiddlyWiki content ---
Then I should see "page body and wiki workspace" elements with selectors:
| element description | selector |
| page body | body |
| wiki workspace | div[data-testid^='workspace-']:has-text('wiki') |
And the window title should contain ""
And the browser view should be loaded and visible
And I should see " TiddlyWiki" in the browser view content
# --- Part 2: Create new main workspace via UI from top sidebar ---
And I clear log lines containing "[test-id-WORKSPACE_CREATED]"
And I clear log lines containing "[test-id-VIEW_LOADED]"
When I click on an "add workspace button" element with selector "#add-workspace-button"
And I switch to "addWorkspace" window
And I wait for the page to load completely
Then I should see "create new wiki tab and main/sub workspace switch" elements with selectors:
| element description | selector |
| create new wiki tab | button:has-text('') |
| main/sub workspace switch | [data-testid='main-sub-workspace-switch'] |
When I clear text in "wiki folder name input" element with selector "label:has-text('') + div input"
When I type "wiki2" in "wiki folder name input" element with selector "label:has-text('') + div input"
When I click on a "create wiki button" element with selector "button:has-text('')"
Then I wait for "workspace created" log marker "[test-id-WORKSPACE_CREATED]"
When I switch to "main" window
Then I wait for "view loaded" log marker "[test-id-VIEW_LOADED]"
Then I should see a "wiki2 workspace" element with selector "div[data-testid^='workspace-']:has-text('wiki2')"
When I click on a "wiki2 workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki2')"
And the browser view should be loaded and visible
Then I should see " TiddlyWiki" in the browser view content
# --- Part 3: Configure root tiddler to use lazy-load ---
# Switch back to default wiki workspace (exclude wiki2 match)
When I click on a "default wiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki'):not(:has-text('wiki2'))"
And the browser view should be loaded and visible
And I should see " TiddlyWiki" in the browser view content
When I modify file "wiki-test/wiki/tiddlers/Index.tid" to contain "Test content for lazy-all verification after restart"
And I should not see "Test content for lazy-all verification after restart" in the browser view content
When I update workspace "wiki" settings:
| property | value |
| rootTiddler | $:/core/save/lazy-all |
| enableFileSystemWatch | false |
Then I wait for "config file written" log marker "[test-id-TIDGI_CONFIG_WRITTEN]"
When I restart workspace "wiki"
And the browser view should be loaded and visible
Then I should see a "Index tiddler" element in browser view with selector "div[data-tiddler-title='Index']"
And I should see "Test content for lazy-all verification after restart" in the browser view content
@wiki @move-workspace
Scenario: Move workspace to a new location
Given I cleanup test wiki so it could create a new one on start
When I launch the TidGi application
And I wait for the page to load completely
# Enable file system watch for testing (default is false in production)
When I update workspace "wiki" settings:
| property | value |
| enableFileSystemWatch | true |
When I open edit workspace window for workspace with name "wiki"
And I switch to "editWorkspace" window
And I wait for the page to load completely
When I click on a "save and sync options accordion" element with selector "[data-testid='preference-section-saveAndSync']"
Then I should see a "move workspace button" element with selector "button:has-text('')"
# Test the actual move operation - this will trigger a file dialog
When I prepare to select directory in dialog "wiki-test-moved"
And I click on a "move workspace button" element with selector "button:has-text('')"
Then I wait for log markers:
| description | marker |
| workspace moved to wiki-test-moved | [test-id-WORKSPACE_MOVED: |
| workspace restarted after move | [test-id-WORKSPACE_RESTARTED_AFTER_MOVE: |
| watch-fs stabilized after restart | [test-id-WATCH_FS_STABILIZED] |
| SSE ready after restart | [test-id-SSE_READY] |
| view loaded | [test-id-VIEW_LOADED] |
# Verify the workspace was moved to the new location
Then file "wiki/tiddlywiki.info" should exist in "wiki-test-moved"
# Switch back to main window to interact with wiki
Then I switch to "main" window
# Verify Index tiddler is displayed (confirms view is loaded)
Then I should see a "Index tiddler" element in browser view with selector "div[data-tiddler-title='Index']"
# Verify the wiki is working by modifying a file in the new location
When I modify file "wiki-test-moved/wiki/tiddlers/Index.tid" to contain "Content after moving workspace"
Then I wait for tiddler "Index" to be updated by watch-fs
# The content check will automatically wait for IPC to sync
And I should see "Content after moving workspace" in the browser view content
# Move it back to original location for cleanup
# Clear test-id markers to ensure we're waiting for fresh logs from second restart
When I clear test-id markers from logs
And I switch to "editWorkspace" window
And I wait for the page to load completely
# Accordion is still expanded from the first move — do NOT click it again (that would collapse it)
When I prepare to select directory in dialog "wiki-test"
And I click on a "move workspace button" element with selector "button:has-text('')"
Then I wait for log markers:
| description | marker |
| workspace moved back to wiki-test | [test-id-WORKSPACE_MOVED: |
| workspace restarted after move back | [test-id-WORKSPACE_RESTARTED_AFTER_MOVE: |
| watch-fs stabilized after restart back | [test-id-WATCH_FS_STABILIZED] |
| SSE ready after restart back | [test-id-SSE_READY] |
| view loaded after restart back | [test-id-VIEW_LOADED] |
Then file "wiki/tiddlywiki.info" should exist in "wiki-test"
# Switch to main window and wait for view to be ready
Then I switch to "main" window
# Verify the wiki still works after moving back
When I modify file "wiki-test/wiki/tiddlers/Index.tid" to contain "Content after moving back"
Then I wait for tiddler "Index" to be updated by watch-fs
# The content check will automatically wait for IPC to sync
And I should see "Content after moving back" in the browser view content