Skip to content

fix: Add worker and expectationManager configuration to troubleshoot#277

Open
nytamin wants to merge 1 commit intomainfrom
fix/troubleshoot-config
Open

fix: Add worker and expectationManager configuration to troubleshoot#277
nytamin wants to merge 1 commit intomainfrom
fix/troubleshoot-config

Conversation

@nytamin
Copy link
Member

@nytamin nytamin commented Mar 18, 2026

About Me

This pull request is posted on behalf of the NRK.

Type of Contribution

This is a: Code improvement

Current Behavior

The troubleshoot data returns various data points, but not the configuration of ExpectationManager or Worker.

New Behavior

Configuration of ExpectationManager or Worker is included in the troubleshoot data.

This is a Quality of Life improvement

Status

  • PR is ready to be reviewed.
  • The functionality has been tested by the author.
  • Relevant unit tests has been added / updated.
  • Relevant documentation (code comments, system documentation) has been added / updated.

@sonarqubecloud
Copy link

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

Walkthrough

This PR converts troubleshooting data collection to asynchronous operations across the package manager, enabling worker configuration fetching during troubleshooting. It adds a new getConfiguration method to the WorkerAgent interface, implements it to return worker configuration, updates ExpectationManager to fetch and include worker configurations in troubleshoot data asynchronously, and adjusts error handling.

Changes

Cohort / File(s) Summary
CoreHandler and PackageManager async conversion
apps/package-manager/packages/generic/src/coreHandler.ts, apps/package-manager/packages/generic/src/packageManager.ts
Converted troubleshoot() and getDataSnapshot() methods from synchronous to asynchronous, with getDataSnapshot() now awaiting troubleshoot data retrieval.
API type definitions
shared/packages/api/src/methods.ts, shared/packages/api/src/worker.ts
Added getConfiguration method to ExpectationManagerWorkerAgent interface and introduced ReturnTypeGetConfiguration type alias mapped to WorkerConfig.
ExpectationManager async implementation
shared/packages/expectationManager/src/expectationManager.ts
Converted getTroubleshootData() to async, made constructor store options as private member, added worker configuration fetching with error handling via Promise.all, and integrated stringifyError for error reporting.
Worker API and Agent
shared/packages/expectationManager/src/workerAgentApi.ts, shared/packages/worker/src/workerAgent.ts
Added getConfiguration() method implementations in both WorkerAgentAPI and WorkerAgent classes, with adjusted result-type handling to broaden benign result shapes.
Type refinement
apps/package-manager/packages/generic/src/generateExpectations/nrk/expectations.ts
Narrowed useTemporaryStorage type by casting to PackageContainer | undefined for explicit optional handling.

Sequence Diagram

sequenceDiagram
    participant Client
    participant CoreHandler
    participant PackageManager
    participant ExpectationManager
    participant WorkerAgent

    Client->>CoreHandler: troubleshoot()
    activate CoreHandler
    CoreHandler->>PackageManager: getDataSnapshot()
    activate PackageManager
    PackageManager->>ExpectationManager: getTroubleshootData()
    activate ExpectationManager
    
    ExpectationManager->>WorkerAgent: getConfiguration()
    activate WorkerAgent
    WorkerAgent-->>ExpectationManager: config (or error)
    deactivate WorkerAgent
    
    Note over ExpectationManager: Promise.all fetches<br/>all worker configs
    
    ExpectationManager-->>PackageManager: { config, workers: [...] }
    deactivate ExpectationManager
    PackageManager-->>CoreHandler: snapshot with troubleshoot data
    deactivate PackageManager
    CoreHandler-->>Client: Promise<any>
    deactivate CoreHandler
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • jstarpl
  • Julusian
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding worker and expectationManager configuration to troubleshoot data.
Description check ✅ Passed The description clearly explains the current behavior, new behavior, and the QoL improvement, all related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/troubleshoot-config
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
shared/packages/worker/src/workerAgent.ts (1)

851-855: Consider documenting the type discriminator pattern.

The wrapper uses property existence checks ('cost' in result, 'wipId' in result, 'process' in result) to determine the return type and skip the knownReason check. While this follows the existing pattern, it's somewhat fragile as it relies on specific properties being unique discriminators.

The comment at line 854 helpfully identifies which type each property maps to. If WorkerConfig is ever refactored to remove the process property, this check would silently break. Consider adding a type guard or ensuring these discriminator properties are documented as API contracts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shared/packages/worker/src/workerAgent.ts` around lines 851 - 855, The
property-existence checks ('cost' in result, 'wipId' in result, 'process' in
result) used in workerAgent.ts to discriminate return types are fragile; replace
or reinforce them by adding explicit type guards and documenting the
discriminator contract for types mapped to ExpectationCost, WorkInProgressInfo,
and ReturnTypeGetConfiguration (e.g., create functions
isExpectationCost(result): result is ExpectationCost,
isWorkInProgressInfo(result): result is WorkInProgressInfo,
isReturnTypeGetConfiguration(result): result is ReturnTypeGetConfiguration) and
use those in place of the inline "'... in result'" checks, and also add a short
comment or exported docstring on WorkerConfig listing the required discriminator
properties so future refactors won’t silently break the knownReason logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@shared/packages/worker/src/workerAgent.ts`:
- Around line 851-855: The property-existence checks ('cost' in result, 'wipId'
in result, 'process' in result) used in workerAgent.ts to discriminate return
types are fragile; replace or reinforce them by adding explicit type guards and
documenting the discriminator contract for types mapped to ExpectationCost,
WorkInProgressInfo, and ReturnTypeGetConfiguration (e.g., create functions
isExpectationCost(result): result is ExpectationCost,
isWorkInProgressInfo(result): result is WorkInProgressInfo,
isReturnTypeGetConfiguration(result): result is ReturnTypeGetConfiguration) and
use those in place of the inline "'... in result'" checks, and also add a short
comment or exported docstring on WorkerConfig listing the required discriminator
properties so future refactors won’t silently break the knownReason logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 396b7f04-41cc-4278-80a2-26eaf223a2bd

📥 Commits

Reviewing files that changed from the base of the PR and between c3d31b1 and 7714f89.

📒 Files selected for processing (8)
  • apps/package-manager/packages/generic/src/coreHandler.ts
  • apps/package-manager/packages/generic/src/generateExpectations/nrk/expectations.ts
  • apps/package-manager/packages/generic/src/packageManager.ts
  • shared/packages/api/src/methods.ts
  • shared/packages/api/src/worker.ts
  • shared/packages/expectationManager/src/expectationManager.ts
  • shared/packages/expectationManager/src/workerAgentApi.ts
  • shared/packages/worker/src/workerAgent.ts

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