fix(utilities): single session log folder per run via cache in getSessionLogPath#2442
Open
fix(utilities): single session log folder per run via cache in getSessionLogPath#2442
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes multiple log folders being created for a single export/import/clone run by caching the session log path for the process. One CLI run now produces one session folder under the configured log path.
Problem
getSessionLogPath()was called many times per run (Logger constructor ×5, export/import command at end,completeProgressWithMessageper module).new Date()for the folder name (command-YYYYMMDD-HHMMSS-sessionId), so different timestamps created different folders.log.path/2026-03-02/) for one command, with logs only in the first folder.Solution
session-path.ts, cache the computed session path in a module-level variable. The first call creates the folder andsession.jsonand caches the path; subsequent calls in the same process return the cached path.clearSessionLogPathCache()and call it inbeforeEachfor the "Session Log Path" and "Session Metadata" tests so each test gets a fresh path and assertions still pass.Changes
cli/packages/contentstack-utilities/src/logger/session-path.tscachedSessionPathand early return when set; set cache before return; add and exportclearSessionLogPathCache().Behavior
Testing
pnpm testincli/packages/contentstack-utilities: Session Log Path and Session Metadata (session.json) tests pass.cm:stacks:exportwith a custom log path; confirm a single session folder is created per run.