Conversation
mythical-fred
left a comment
There was a problem hiding this comment.
POC looks like a reasonable plugin architecture — virtual module resolution via env var is a clean extensibility approach, and the type definitions in triage.ts are solid. Three code-level things to fix before this ships, and the usual missing-tests note.
Commit messages: both need work before merge. "poc for triage integratino with ui" has a typo, is lowercase, and has no body. "remove dependency as it is resolved via plugin instead" is lowercase and doesn't explain why the approach changed. Please git rebase -i and rewrite them with imperative-mood subjects and a brief body explaining the motivation.
Tests: all checklist boxes are unchecked. The web-console has zero running tests — every PR should be nudging this in the right direction. For this PR, the most testable thing is the triage plugin invocation logic. The recommended stack is Vitest + @testing-library/svelte — runs in Node, no browser, no flake. Setup: npm install -D vitest @testing-library/svelte jsdom. A good first test: pure unit tests for any triage utility functions you extract from the component.
js-packages/web-console/src/lib/components/pipelines/editor/TabProfileVisualizer.svelte
Outdated
Show resolved
Hide resolved
js-packages/web-console/src/lib/components/pipelines/editor/TabProfileVisualizer.svelte
Outdated
Show resolved
Hide resolved
js-packages/web-console/src/lib/components/pipelines/editor/TabProfileVisualizer.svelte
Outdated
Show resolved
Hide resolved
|
If you are adding the tests, please use |
2084877 to
47b1feb
Compare
|
Thanks @Karakatiza666 — duly noted. |
mythical-fred
left a comment
There was a problem hiding this comment.
Good progress — all the blockers from my last pass are resolved. The new triage-types package is well-structured with solid JSDoc, error handling now surfaces via toast, the unused import and console.log are gone. One last minor nit inline.
| @@ -92,6 +97,19 @@ | |||
| ;(async () => { | |||
| try { | |||
There was a problem hiding this comment.
.map() is being used for its side effects — each .triage() call mutates triageResults but the mapped array is discarded. Use .forEach() instead:
triagePlugins.forEach((p) => p.triage(bundle, triageResults))
Karakatiza666
left a comment
There was a problem hiding this comment.
Nice integration. Please run bun run format to revert formatting changes in TabProfileVisualizer.svelte, and refactor to one of the two API suggestions. They have different tradeoffs, but both are better than the current approach.
Other than that - LGTM
| } | ||
|
|
||
| /** Accumulator for triage findings produced across one or more plugins. */ | ||
| export class TriageResults { |
There was a problem hiding this comment.
Right now class TriageResults introduces indirection for no benefit. Let's refactor the API to either of the two approaches:
- Simplify the interface
DropTriageResults, refactorinterface TriagePlugintotriage: (bundle: DecodedBundle) => TriageResult[].
This will let us replace
const results = new TriageResults()
triagePlugins.map((p) => p.triage(bundle, results))
triageResults = results.results
with
triageResults = triagePlugins.flatMap((p) => p.triage(bundle))
- Keep TriageResults class to future-proof against more complicated functionality, but make it more ergonomic
Refactorinterface TriagePlugintotriage: (bundle: DecodedBundle) => TriageResults, instead ofpublic readonly results-get results: () => TriageRuleResult[], drop TriageResults::push;
Add toclass TriageResultsstatic concat: (a: TriageResults, b: TriageResults) => TriageResults, which makes the code that executes the triage:
triageResults = triagePlugins.map((p) => p.triage(bundle)).reduce(TriageResults.concat, new TriageResults()).results
or
concat: (...rs: TriageResults[]) => TriageResults
triageResults = TriageResults.concat(...triagePlugins.map((p) => p.triage(bundle))).results
Option 1 is cleaner, but option 2 is better if you already know of possible future triage features beyound a simple list of results
There was a problem hiding this comment.
I had a discussion with @mihaibudiu on the TriageResults class. His suggestion was that the triage rules should not return the TriageResults object because the object can just function as an accumulator directly. The current implementation no longer includes triageResults = results.results. I replaced each instance of TriageResult[] with an instance of the TriageResults class. Take a look and let me know what you think!
There was a problem hiding this comment.
The thing is mutating the object passed as an argument (as an explicit feature, not an optimization) is less obvious behavior than an explicit function output. I can open a separate PR for this, but we might as well decide on it now.
I'm not against merging the PR as-is, but it is a simple change and p.triage() mutating the passed TriageResults is both less obvious behavior and increases coupling between TriageResults and .triage function. Instead of constructing a clean TriageResults instance, .triage() needs to know how to mutate it properly.
You may think this difference is inconsequential, but when the codebase becomes overgrown with implicit behavior it becomes difficult to reason about.
@mihaibudiu please approve if you are fine with the current API
There was a problem hiding this comment.
I really don't see how appending to a list is different from calling a method on an object that holds the list. They both mutate the object.
The object approach is more general if you plan to do more than just add diagnostic messages. For example, you could have errors and warnings as a separate class of objects. (But for now I suggested keeping them as diagnostic messages too).
There was a problem hiding this comment.
I agree that the object as a response is more future proof.
If we look at option 2 i suggested, the idea is to separate concerns: plugin.triage() just wraps its own conclusions as a TriageResults. It does not need to concern itself with any pre-existing TriageResults state. Then, aggregating all TriageResults is a separate concern
There was a problem hiding this comment.
That works as long as the results are always a TriageResult.
There was a problem hiding this comment.
I assumed TriageResults is there to encapsulate the set of any triage output - list of suggestions, some overview performance graph, etc.
2d9415f to
a1e9659
Compare
now that you are at least three people working on the typescript code-base please add a formatting rule you all can agree on to pre-commit |
Karakatiza666
left a comment
There was a problem hiding this comment.
Approving as the approach is functional. My suggestions for improvement are not blockers to deliver the feature
Describe Manual Test Plan
Test with and without plugin from cloud package
Checklist
Breaking Changes?
Mark if you think the answer is yes for any of these components:
Describe Incompatible Changes