fix: log marker check all log files

This commit is contained in:
linonetwo 2025-12-06 23:41:18 +08:00
parent 5df8ad52c8
commit ea5c14e9ef
3 changed files with 16 additions and 6 deletions

View file

@ -34,8 +34,11 @@ Feature: Filesystem Plugin
Then I wait for "view loaded" log marker "[test-id-VIEW_LOADED]"
# Click SubWiki workspace again to ensure TestTag tiddler is displayed
And I wait for 1 seconds
# Clear previous VIEW_LOADED marker before clicking SubWiki
And I clear log lines containing "[test-id-VIEW_LOADED]"
When I click on a "SubWiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('SubWiki')"
And I wait for 1 seconds
# Wait for the view to reload with SubWiki content
Then I wait for "view loaded after SubWiki click" log marker "[test-id-VIEW_LOADED]"
# Verify TestTag tiddler is visible
And I should see "TestTag" in the browser view content
# Create tiddler with tag to test file system plugin

View file

@ -54,6 +54,8 @@ Feature: Workspace Hibernation
And I wait for 0.2 seconds
Then I should see a "WikiTestTiddler tiddler" element in browser view with selector "div[data-tiddler-title='WikiTestTiddler']"
# Switch to wiki2 - wiki should hibernate, wiki2 should load
# Clear previous VIEW_LOADED markers before waiting for a new one
And I clear log lines containing "[test-id-VIEW_LOADED]"
When I click on a "wiki2 workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki2')"
Then the browser view should be loaded and visible
# Wait for view to be fully loaded
@ -68,6 +70,8 @@ Feature: Workspace Hibernation
Then I should not see a "WikiTestTiddler tiddler" element in browser view with selector "div[data-tiddler-title='WikiTestTiddler']"
# Switch back to wiki - wiki2 should hibernate, wiki should wake up (reproduces issue #556)
# This also tests issue #593 - browser view should persist after wake up
# Clear previous VIEW_LOADED markers before waiting for a new one
And I clear log lines containing "[test-id-VIEW_LOADED]"
When I click on a "wiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki')"
Then the browser view should be loaded and visible
# Wait for view to be fully loaded

View file

@ -19,13 +19,15 @@ const BACKOFF_OPTIONS = {
*/
export async function waitForLogMarker(searchString: string, errorMessage: string, maxWaitMs = 10000, logFilePattern = 'wiki-'): Promise<void> {
const logPath = path.join(process.cwd(), 'userData-test', 'logs');
// Support multiple patterns separated by '|'
const patterns = logFilePattern.split('|');
try {
await backOff(
async () => {
try {
const files = await fs.readdir(logPath);
const logFiles = files.filter(f => f.startsWith(logFilePattern) && f.endsWith('.log'));
const logFiles = files.filter(f => patterns.some(p => f.startsWith(p)) && f.endsWith('.log'));
for (const file of logFiles) {
const content = await fs.readFile(path.join(logPath, file), 'utf-8');
@ -321,7 +323,8 @@ async function clearGitTestData() {
* This searches in TidGi- log files by default
*/
Then('I wait for {string} log marker {string}', async function(this: ApplicationWorld, description: string, marker: string) {
await waitForLogMarker(marker, `Log marker "${marker}" not found. Expected: ${description}`, 10000, 'TidGi-');
// Search in both TidGi- and wiki log files (wiki logs include wiki- and wiki2- etc.)
await waitForLogMarker(marker, `Log marker "${marker}" not found. Expected: ${description}`, 10000, 'TidGi-|wiki');
});
/**
@ -334,7 +337,7 @@ Then('I wait for SSE and watch-fs to be ready', async function(this: Application
});
/**
* Remove log lines containing specific text from all TidGi- log files.
* Remove log lines containing specific text from all log files (TidGi- and wiki- prefixed).
* This is useful when you need to wait for a log marker that may have appeared earlier in the scenario,
* and you want to ensure you're waiting for a new occurrence of that marker.
* @param marker - The text pattern to remove from log files
@ -343,9 +346,9 @@ When('I clear log lines containing {string}', async function(this: ApplicationWo
const logDirectory = path.join(process.cwd(), 'userData-test', 'logs');
if (!fs.existsSync(logDirectory)) return;
const today = new Date().toISOString().split('T')[0];
// Clear from both TidGi- and wiki- prefixed log files
const logFiles = fs.readdirSync(logDirectory).filter(f =>
(f.startsWith('TidGi-') || f === `TidGi-${today}.log`) && f.endsWith('.log')
(f.startsWith('TidGi-') || f.startsWith('wiki')) && f.endsWith('.log')
);
for (const logFile of logFiles) {