From 53d3dc55e6bdb2a09d56dfe8d834db29bba1db5b Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 23 May 2025 21:31:39 +0000 Subject: [PATCH] fix(logging): Fix log file naming to prevent collisions and update logging system documentation. --- changelog.md | 7 +++++++ readme.hints.md | 19 +++++++++++++++++-- ts/00_commitinfo_data.ts | 2 +- ts/tstest.logging.ts | 12 ++++++++++-- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 78797e7..4103d21 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-05-23 - 1.9.2 - fix(logging) +Fix log file naming to prevent collisions and update logging system documentation. + +- Enhance safe filename generation in tstest logging to preserve directory structure using double underscores. +- Update readme.hints.md to include detailed logging system documentation and behavior. +- Add .claude/settings.local.json with updated permissions for build tools. + ## 2025-05-23 - 1.9.1 - fix(dependencies) Update dependency versions and add local configuration files diff --git a/readme.hints.md b/readme.hints.md index 097673b..3a9e7a9 100644 --- a/readme.hints.md +++ b/readme.hints.md @@ -12,7 +12,7 @@ This project integrates tstest with tapbundle through a modular architecture: ### Test Execution Flow -1. **CLI Entry Point** (`cli.js` ’ `cli.ts.js` ’ `cli.child.ts`) +1. **CLI Entry Point** (`cli.js` � `cli.ts.js` � `cli.child.ts`) - The CLI uses tsx to run TypeScript files directly - Accepts glob patterns to find test files - Supports options like `--verbose`, `--quiet`, `--web` @@ -59,4 +59,19 @@ The framework automatically detects the runtime environment: - Browser tests are compiled and served via a local server - WebHelpers are only enabled in browser environment -This architecture allows for seamless testing across both Node.js and browser environments while maintaining a clean separation of concerns. \ No newline at end of file +This architecture allows for seamless testing across both Node.js and browser environments while maintaining a clean separation of concerns. + +## Logging System + +### Log File Naming (Fixed in v1.9.1) + +When using the `--logfile` flag, tstest creates log files in `.nogit/testlogs/`. The log file naming was updated to preserve directory structure and prevent collisions: + +- **Old behavior**: `test/tapbundle/test.ts` → `.nogit/testlogs/test.log` +- **New behavior**: `test/tapbundle/test.ts` → `.nogit/testlogs/test__tapbundle__test.log` + +This fix ensures that test files with the same basename in different directories don't overwrite each other's logs. The implementation: +1. Takes the relative path from the current working directory +2. Replaces path separators (`/`) with double underscores (`__`) +3. Removes the `.ts` extension +4. Creates a flat filename that preserves the directory structure \ No newline at end of file diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 75b8ee3..31459ac 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tstest', - version: '1.9.1', + version: '1.9.2', description: 'a test utility to run tests that match test/**/*.ts' } diff --git a/ts/tstest.logging.ts b/ts/tstest.logging.ts index 153e232..c0af145 100644 --- a/ts/tstest.logging.ts +++ b/ts/tstest.logging.ts @@ -153,8 +153,16 @@ export class TsTestLogger { // Only set up test log file if --logfile option is specified if (this.options.logFile) { - const baseFilename = path.basename(filename, '.ts'); - this.currentTestLogFile = path.join('.nogit', 'testlogs', `${baseFilename}.log`); + // Create a safe filename that preserves directory structure + // Convert relative path to a flat filename by replacing separators with __ + const relativeFilename = path.relative(process.cwd(), filename); + const safeFilename = relativeFilename + .replace(/\\/g, '/') // Normalize Windows paths + .replace(/\//g, '__') // Replace path separators with double underscores + .replace(/\.ts$/, '') // Remove .ts extension + .replace(/^\.\.__|^\.__|^__/, ''); // Clean up leading separators from relative paths + + this.currentTestLogFile = path.join('.nogit', 'testlogs', `${safeFilename}.log`); // Ensure the directory exists const logDir = path.dirname(this.currentTestLogFile);