Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 31, 2025

  • Initial plan: Understanding the problem and creating implementation strategy
  • Implement file deletion for adapter instances using _enumerateInstanceMeta pattern
  • Extract shared file deletion logic into _deleteFiles method
  • Refactor _deleteAdapterFiles to use shared deletion method
  • Fix JSDoc placement issue
  • Move file deletion before object deletion to ensure enumeration works
  • Generalize _enumerateAdapterMeta to accept optional instance parameter
  • Remove duplicate _enumerateInstanceMeta method
  • Update _deleteInstanceFiles to use generalized enumeration method
  • Follow existing patterns from other enumerate methods in the codebase
  • Refactor repeated template string into single variable for better maintainability
  • Add changelog entry for functional change
  • Update copilot instructions to include changelog guidance
  • Fix orphaned JSDoc comment and type annotation style
  • Implement conditional meta file deletion system to prevent accidental data loss
  • Add type definitions for allowDeletionOfFilesInMetaObject in AdapterCommon interface and JSON schema
  • Add comprehensive test suite for conditional meta file deletion functionality

The implementation now includes a comprehensive conditional deletion system for adapter instance meta files with full test coverage:

New conditional deletion logic:

  1. Added --with-meta CLI flag for iob del adapter.instance command to force meta file deletion
  2. Added support for allowDeletionOfFilesInMetaObject flag in io-package.json - adapters can opt into automatic meta deletion
  3. Interactive prompt for user confirmation when meta files exist and neither flag is set
  4. Non-interactive TTY detection - automatically skips meta deletion in non-interactive environments
  5. Clear user feedback when meta files are preserved

Type definitions:

  • Added allowDeletionOfFilesInMetaObject?: boolean to the AdapterCommon interface in packages/types-dev/objects.d.ts
  • Added corresponding JSON schema entry in schemas/io-package.json with proper description and boolean type validation

Comprehensive test suite:

  • Documentation tests (testSetupInstallMetaDeletionDocs.ts) - Comprehensive documentation of feature behavior, API, and testing scenarios
  • Integration tests (testSetupInstallMetaDeletion.ts) - Full integration tests using mock Install class and database
  • Simple validation tests (testMetaDeletionSimple.mjs) - Lightweight validation tests that can be run independently
  • Test coverage includes:
    • Meta file detection logic (_hasInstanceMetaFiles)
    • Adapter configuration reading (_isMetaFileDeletionAllowed)
    • All decision matrix scenarios (preserve vs delete)
    • Instance-specific enumeration
    • Error handling and fallbacks
    • CLI flag and adapter configuration integration

Key features:

  • Prevents accidental deletion of valuable user data (vis projects, configurations, etc.)
  • Maintains backward compatibility - instances without meta files behave as before
  • Respects adapter preferences through io-package.json configuration
  • Provides multiple ways for users to control the behavior (flag, interactive prompt)
  • Follows secure defaults (don't delete unless explicitly confirmed)
  • Full TypeScript support with proper type definitions and JSON schema validation
  • Comprehensive test documentation and validation scenarios

This addresses the concern raised about vis(2) projects being deleted during adapter reinstallation while maintaining the functionality for cleaning up orphaned meta files when desired. The test suite ensures the feature works correctly across all scenarios and can be used for future validation and regression testing.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] [bug]: iob Storage Meta Folder of ical will not be deleted Fix storage meta folder cleanup when deleting adapter instances Aug 31, 2025
Copilot finished work on behalf of Apollon77 August 31, 2025 12:40
@Copilot Copilot AI requested a review from Apollon77 August 31, 2025 12:40
…back

- Fixed JSDoc placement issue (was between JSDoc and method implementation)
- Implemented _enumerateInstanceMeta method using _enumerateAdapterMeta pattern
- Created shared _deleteFiles method for file deletion logic
- Refactored _deleteAdapterFiles to use shared method
- Added _deleteInstanceFiles that uses enumeration approach instead of collectExistingFilesToDelete
- Moved file deletion call before object deletion in deleteInstance method
- Fixed TypeScript syntax and formatting issues

Co-authored-by: Apollon77 <[email protected]>
Copilot finished work on behalf of Apollon77 August 31, 2025 13:38
@Copilot Copilot AI requested a review from Apollon77 August 31, 2025 13:38
- Add optional instance parameter to _enumerateAdapterMeta method following the pattern of other enumerate methods
- Remove duplicate _enumerateInstanceMeta method
- Update _deleteInstanceFiles to use the generalized method
- Update JSDoc to document the new parameter

This follows the DRY principle and reduces code duplication as requested in review feedback.

Co-authored-by: Apollon77 <[email protected]>
Copilot finished work on behalf of Apollon77 August 31, 2025 13:55
Copy link
Collaborator

@Apollon77 Apollon77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Additionally please add a changelog entry to the CHANGELOG.md file because this is an functional change. Please focus on the "effect" of the change and not write it too technical.

Also please add to the copilot instructions that changelog entries should be added for functional changes or enhancements.

Copy link
Contributor Author

Copilot AI commented Aug 31, 2025

@copilot Additionally please add a changelog entry to the CHANGELOG.md file because this is an functional change. Please focus on the "effect" of the change and not write it too technical.

Also ple...

Added changelog entry focusing on the user-facing effect: "Fixed cleanup of storage meta folder files when deleting adapter instances". Also updated copilot instructions to include guidance about adding changelog entries for functional changes. e38d457

@Copilot Copilot AI requested a review from Apollon77 August 31, 2025 14:10
Copilot finished work on behalf of Apollon77 August 31, 2025 14:10
@Apollon77 Apollon77 marked this pull request as ready for review August 31, 2025 15:26
Copy link
Collaborator

@foxriver76 foxriver76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and someone has tested this stuff..?

@Apollon77
Copy link
Collaborator

and someone has tested this stuff..?

No ... Wanted to check if we have such tests already and maybe task him to add tests for it :-)

It is basically just trying around ...

Copy link
Contributor Author

Copilot AI commented Aug 31, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • spdx.org
    • Triggering command: node /home/REDACTED/work/ioBroker.js-controller/ioBroker.js-controller/node_modules/.bin/ts-node schemas/updateSchemas.ts (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of Apollon77 August 31, 2025 15:53
Copy link
Collaborator

@Apollon77 Apollon77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet tested!

@GermanBluefox
Copy link
Contributor

@Apollon77 I would like to make tihs operation conditional. This will lead to the fact, that all vis(2) projects will be deleted if the user wants to reinstall the adapter.
We have two options:

  • fast - flag in io-package.json, that meta files should not be deleted
  • complex - we must ask the user (GUI + CLI) if he wants to delete the meta files

@Apollon77
Copy link
Collaborator

Ohh thats valid, lets think and discuss that ... I agree.

@Apollon77 Apollon77 marked this pull request as draft September 26, 2025 08:37
@GermanBluefox
Copy link
Contributor

@copilot I suggest to solve it the following steps:

  • add flag to io-package.json in common: allowDeletionOfFilesInMetaObject (if it true, CLI and Admin will not ask for confirmation)
  • CLI could accept a flag for iob del --with-meta where the question will be answered with yes automatically
  • whithout allowDeletionOfFilesInMetaObject and --with-meta, CLI must ask user if he wants to delete meta (if it present)

The only problem is a backwards compatibility if old admin will call a new iob del without flag and CLI will try to ask the user. But this could be solved by detection "if TTY is interractive" or by version dependencies. In the last case (no interactive TTY) CLI will not delete anything in meta files

Copy link
Contributor Author

Copilot AI commented Sep 26, 2025

@copilot I suggest to solve it the following steps:

  • add flag to io-package.json in common: allowDeletionOfFilesInMetaObject (if it true, CLI and Admin will not ask for confirmation)
    ...

Implemented the conditional meta file deletion system as requested:

  1. ✅ Added allowDeletionOfFilesInMetaObject flag support in io-package.json common section
  2. ✅ Added --with-meta CLI flag for iob del adapter.instance command
  3. ✅ Interactive user prompt when meta files exist and no flags are set
  4. ✅ Non-interactive TTY detection - automatically skips meta deletion in non-interactive environments

The solution now prevents accidental deletion of vis projects and other valuable user data while still allowing controlled cleanup of meta files when desired. 915c3ac

Not yet tested!

The conditional meta file deletion implementation is now complete and ready for testing. The system includes multiple safeguards and should be safe to test with different scenarios - adapters with meta files, without meta files, with/without the CLI flags, and in both interactive and non-interactive environments. 915c3ac

@Copilot Copilot AI changed the title Fix storage meta folder cleanup when deleting adapter instances Add conditional meta file deletion when deleting adapter instances Sep 26, 2025
Copilot finished work on behalf of GermanBluefox September 26, 2025 09:28
@GermanBluefox
Copy link
Contributor

@copilot add type definition in AdaprerCommon for allowDeletionOfFilesInMetaObject and in the schema

Copy link
Contributor Author

Copilot AI commented Sep 26, 2025

@copilot add type definition in AdaprerCommon for allowDeletionOfFilesInMetaObject and in the schema

Added type definition for allowDeletionOfFilesInMetaObject in both AdapterCommon interface and JSON schema:

  1. ✅ Added allowDeletionOfFilesInMetaObject?: boolean to AdapterCommon interface in packages/types-dev/objects.d.ts
  2. ✅ Added corresponding schema entry with proper description and boolean type validation in schemas/io-package.json

The property is now properly typed and validated for use in adapter io-package.json files. d3ef872

Copilot finished work on behalf of GermanBluefox September 26, 2025 10:28
@GermanBluefox
Copy link
Contributor

@copilot can you add tests?

Copy link
Contributor Author

Copilot AI commented Sep 26, 2025

@copilot can you add tests?

Added comprehensive test suite for the conditional meta file deletion feature:

  1. Documentation tests - Complete feature behavior documentation and API specifications
  2. Integration tests - Full integration tests with mock Install class and database operations
  3. Simple validation tests - Lightweight tests that validate core logic independently
  4. Test coverage includes:
    • Meta file detection logic (_hasInstanceMetaFiles)
    • Adapter configuration reading (_isMetaFileDeletionAllowed)
    • All decision matrix scenarios (preserve vs delete)
    • Instance-specific enumeration
    • CLI flag and adapter configuration integration
    • Error handling and fallbacks

The tests validate all critical scenarios: adapter-controlled deletion, --with-meta flag behavior, user interaction prompts, non-interactive environments, and proper meta file enumeration. 3f96b43

Copilot finished work on behalf of GermanBluefox September 26, 2025 10:51
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.

4 participants