Skip to content

fix: Audit fix progress bar and overwrite confirmation UX#31

Open
cs-raj wants to merge 1 commit intov2-devfrom
fix/DX-5326
Open

fix: Audit fix progress bar and overwrite confirmation UX#31
cs-raj wants to merge 1 commit intov2-devfrom
fix/DX-5326

Conversation

@cs-raj
Copy link
Contributor

@cs-raj cs-raj commented Mar 14, 2026

Audit fix: progress bar and overwrite confirmation UX

Summary

Fixes the issue where the overwrite confirmation prompt (“Would you like to overwrite existing file?”) did not appear on screen when the progress bar was active—it only became visible after pressing Enter. Also improves behavior for assets and entries so the user is prompted once per run instead of once per file, and adds test infrastructure and unit test coverage.

Problem

When running audit:fix with log level info (or when the progress bar is shown), the CLI displays a progress bar during audit. The overwrite confirmation was triggered while the progress bar was still active. The progress UI kept controlling the terminal, so the prompt line was either overwritten or not drawn until the user pressed Enter.

Additionally:

  • Assets and entries could call writeFixContent (and thus prompt) inside the processing loop, leading to multiple prompts when fixing many assets or entries.
  • Unit tests could fail or behave inconsistently when the user had config:set:log --level debug set, because the real logger’s debug path was used.

Solution

1. Clear progress before confirmation (all modules)

Call this.completeProgress(true) immediately before every await cliux.confirm(...) in modules that use the progress bar. That clears the progress bar and releases the terminal so the overwrite prompt is visible on a new line.

Modules updated:

Module File(s) Change
content-types content-types.ts completeProgress(true) before confirm in writeFixContent()
global-fields (uses ContentType) Covered by content-types fix
field_rules field_rules.ts completeProgress(true) before confirm in writeFixContent()
custom-roles custom-roles.ts completeProgress(true) before confirm in writeFixContent()
assets assets.ts completeProgress(true) before confirm; single prompt per run (see below)
entries entries.ts completeProgress(true) before confirm; single prompt per run (see below)
workflows workflows.ts Upfront confirm in fixWorkflowSchema() and writeFixContent(..., preConfirmed) with progress cleared before any prompt
extensions extensions.ts Upfront confirm in fixExtensionsScope() and writeFixContent(..., preConfirmed) with progress cleared before any prompt

2. Single overwrite prompt per run (assets, entries)

  • Assets: Introduced fixOverwriteConfirmed to cache the user’s choice. The overwrite prompt is shown once when the first fix is needed; subsequent writeFixContent calls reuse the cached value. writeFixContent is now invoked once after the asset loop instead of inside it.
  • Entries: Same pattern: fixOverwriteConfirmed caches the result of the first confirm; one prompt per run when multiple entry files are written.

3. Single upfront confirm (workflows, extensions)

  • Workflows: fixWorkflowSchema() now asks for confirmation once at the start (when there are workflows to fix and no skip flags). The result is passed through the fix loop and into writeFixContent(newWorkflowSchema, userConfirm). writeFixContent accepts optional preConfirmed and only prompts when it is undefined and flags don’t skip; progress is cleared before that prompt.
  • Extensions: Same pattern in fixExtensionsScope() and writeFixContent(fixedExtensions, preConfirmed).

4. Test infrastructure and coverage

  • Logger config: Added test/unit/logger-config.js, loaded by Mocha via --file before any test. It forces log config to non-debug so unit tests don’t depend on the user’s config:set:log --level and the real Logger doesn’t take the debug path during tests.
  • package.json: test:unit and test:unit:report now pass --file test/unit/logger-config.js to Mocha.
  • Unit tests: Expanded tests for base-command (external-config), assets, composable-studio, content-types, custom-roles, entries, extensions, field-rules, and workflows. Added mock data (e.g. empty_title_ct) where needed.
  • Workflow test: Removed unused writeStub variable to fix TS6133 (declared but never read).

Files changed

  • package.json – Mocha --file test/unit/logger-config.js in test scripts
  • src/modules/assets.ts – Progress before confirm; overwrite cache; single writeFixContent after loop
  • src/modules/content-types.tscompleteProgress(true) before confirm
  • src/modules/custom-roles.tscompleteProgress(true) before confirm
  • src/modules/entries.ts – Progress before confirm; overwrite cache
  • src/modules/extensions.ts – Upfront confirm; writeFixContent(..., preConfirmed); progress before confirm
  • src/modules/field_rules.tscompleteProgress(true) before confirm
  • src/modules/workflows.ts – Upfront confirm; writeFixContent(..., preConfirmed); progress before confirm
  • test/unit/logger-config.js – New; forces log level for tests
  • test/unit/base-command.test.ts – external-config and init tests
  • test/unit/modules/assets.test.ts – Additional cases
  • test/unit/modules/composable-studio.test.ts – Expanded coverage
  • test/unit/modules/content-types.test.ts – New / expanded tests
  • test/unit/modules/custom-roles.test.ts – Expanded coverage
  • test/unit/modules/entries.test.ts – Expanded coverage
  • test/unit/modules/extensions.test.ts – Additional cases
  • test/unit/modules/field-rules.test.ts – Expanded coverage
  • test/unit/modules/workflow.test.ts – Expanded coverage; removed unused writeStub
  • Mock data under test/unit/mock/ (e.g. empty_title_ct) for new tests

Testing

  • Run pnpm test:unit (or npm run test:unit) in the contentstack-audit package; all tests should pass.
  • Manually: run cm:stacks:audit:fix with log level info and trigger modules that prompt (e.g. content-types, entries, assets). The overwrite prompt should appear as soon as the progress bar clears, without needing to press Enter. For assets/entries with multiple files, the prompt should appear once per run.

Backward compatibility

  • No change to when the overwrite prompt is shown (same flags: --copy-dir, --yes, external-config.skipConfirm still skip or influence confirmation).
  • No change to what gets written or to fix logic; only the order of progress completion and prompt display, and the number of prompts for assets/entries/workflows/extensions.

@github-actions
Copy link

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 0 25 ✅ Passed
🟡 Medium Severity 0 0 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

✅ BUILD PASSED - All security checks passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant