Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

Implementation Plan for Adapter Log Capture in Integration Tests

  • Explore repository structure and understand integration test framework
  • Identify where adapter process is spawned (harness.ts)
  • Modify adapter process spawning to capture stdout/stderr instead of inheriting
  • Create log storage mechanism in TestHarness to store captured logs
  • Parse captured output into structured log objects (level, timestamp, message)
  • Add method getLogs() to return array of log objects
  • Add method assertLog() to check for specific log messages with regex and level
  • Add method clearLogs() to clear captured logs
  • Export AdapterLog interface for external use
  • Add tests to verify log capture functionality
  • Update documentation/README with new methods and examples
  • Run lint, build, and tests to ensure no regressions
  • Run CodeQL security scan - no issues found
  • Validate exports are working correctly
  • Add changelog entry
  • Ready for code review

Summary

This PR implements log capture functionality for integration tests, enabling developers to check for specific error/warning/info messages during adapter startup and execution.

Features Added

  1. Log Capture: Modified TestHarness to capture stdout/stderr from the adapter process
  2. Structured Log Objects: Logs are parsed into objects with level, timestamp, and message properties
  3. Log Retrieval Methods:
    • getLogs(): Returns array of all captured logs
    • assertLog(pattern, level?): Checks if a log matching criteria exists
    • clearLogs(): Clears all captured logs

Implementation Details

  • Changed stdio configuration from ['inherit', 'inherit', 'inherit'] to ['inherit', 'pipe', 'pipe'] to capture output
  • Added log parsing to extract log level, timestamp, and message from ioBroker log format
  • Logs are still output to console for visibility during test runs
  • Falls back to treating unparseable lines as info-level logs
  • Exported AdapterLog interface for TypeScript users

Use Case Example

suite("Check for specific error", (getHarness) => {
    let harness;
    before(() => {
        harness = getHarness();
    });

    it("Should not produce follow-up bug error", async () => {
        await harness.startAdapterAndWait();
        
        // Check that specific error doesn't appear
        const hasFollowUpBug = harness.assertLog(/follow-up-bug detected/, "error");
        expect(hasFollowUpBug).to.be.false;
    });
});

Testing & Validation

✅ All existing tests pass
✅ New unit tests added for log capture functionality
✅ Linting passes with no errors
✅ TypeScript compilation succeeds
✅ CodeQL security scan shows no vulnerabilities
✅ Exports verified to work correctly
✅ Comprehensive documentation added to README.md
✅ Changelog updated

Files Changed

  • src/tests/integration/lib/harness.ts: Core implementation
  • src/tests/integration/lib/harness.test.ts: Unit tests (new)
  • src/tests/index.ts: Export AdapterLog type
  • README.md: Documentation and examples
  • CHANGELOG.md: Added entry for new feature
  • build/: Compiled output
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature request]: Method to read the log of the adapter startup in an integration test.</issue_title>
<issue_description>As a part of the integration test I would like to check for a specific error/warn/info/debug-message to be present (or not present) in the log.

I can think of two possible implementation approaches:

  1. Implement a method that returns the log, e.g. as an array of log messages or log objects (logLevel, timestamp, message) or just the whole dump as string - whichever is easier to implement, though an array of log objects would be the most useful option from a developer side of view.
  2. Implement a method that checks the log for containing a specific Regex with a specific log level.

Use case

During fixing a bug in my adapter I have introduced a follow-up-bug that can be identified by a specific log message. To fix this bug I would like to implement a test case that checks for this specific log message.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add method to read adapter startup log in integration tests Add log capture methods to TestHarness for integration tests Nov 8, 2025
Copilot AI requested a review from Apollon77 November 8, 2025 13:44
Copilot finished work on behalf of Apollon77 November 8, 2025 13:44
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 you missed the changelog

Copy link
Contributor Author

Copilot AI commented Nov 8, 2025

@copilot you missed the changelog

Added changelog entry in commit 0a6e9e5.

Copilot AI requested a review from Apollon77 November 8, 2025 14:41
Copilot finished work on behalf of Apollon77 November 8, 2025 14:41
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.

[Feature request]: Method to read the log of the adapter startup in an integration test.

2 participants