Repository navigation
Conversation
fixes FlowFuse/engineering#534 Allow catalogue URLS to be added to team types and only added to devices and instance is they are not already present
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8946 +/- ##
==========================================
+ Coverage 80.01% 80.71% +0.70%
==========================================
Files 476 477 +1
Lines 26191 26390 +199
Branches 6982 7029 +47
==========================================
+ Hits 20958 21302 +344
+ Misses 5233 5088 -145
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The failing UI tests appear to pass locally |
There was a problem hiding this comment.
Whilst this works, had some feedback for bits that might need tidying up.
In both deviceLive.js and project.js
- Accesses
team.TeamType?.properties?.extraCataloguesdirectory. Should beteam.getProperty("extraCatalogues", null)so that it could be overridden at the team level - The check for that property assumes
response.palette.cataloguesexists. Earlier in the function is a check that initialises that property based on other properties. Not sure if there's a combination there that will trip us up - We only apply this setting if cert nodes is enabled - but at the TeamType dialog this is presented as a general option for additional catalogues that don't need to be certified. Either we want to make this option truly about adding catalogues without it being specific to cert nodes (move the work to append the catalogues out of the containing if block), or we update the dialog to be explicit this is about cert nodes.
URL.parse(cat)was flagged as a new API that cuts off Safari 17 which isn't that old. We don't use it in the code base already, so potentially breaking.
|
I've fixed 1, 3 and 4 As for 2, I think we are safe as cert nodes or ffnodes has to be enabled, so we will have injected at least one catalogue. |
knolleary
left a comment
There was a problem hiding this comment.
Need to try/catch url constructor to handle invalid entries.
Co-authored-by: Nick O'Leary <nick.oleary@gmail.com>
Steve-Mcl
left a comment
There was a problem hiding this comment.
Works as described - requesting changes mainly on validation:
extraCataloguesis not validated by the API (server side). The create/update team type routes (forge/routes/api/teamType.js,properties: { type: 'object' }on the POST and PUT schemas) accept any shape, and only the dialog checks for URLs. I can't comment inline cos those lines arent in the diff, but I recomend we add add server side validation (array of http(s) URL strings, 400 otherwise) and make the runtime loops (for (const cat of xxx) defensive (cos a string value is iterated per character and a non iterable would throw in to the catch block).
Thinks of note
- The dialog doesn't say one URL per line, and invalid lines are dropped silently.
- Dedupe compares bare strings, and the test dont assert form diffs.
- Tests mutate shared default team type (I think! eye scan only).
- The team type GET returns
extraCataloguesto non-admin users (the view only strips price/product IDs). Catalogue URLs might carry tokens?
| updateSettingsForCatalogue('@flowfuse-certified-nodes', cat) | ||
| } | ||
| } | ||
| if (team.getProperty('extraCatalogues', null)) { |
There was a problem hiding this comment.
getProperty('extraCatalogues')is the guard, but the loop readsteam.TeamType.properties.extraCataloguesdirectly. If a team-level override ever exists, the check and the value come from different places. Use one source, e.g.const extra = team.getProperty('extraCatalogues', null)and loop overextra.- Add
Array.isArray(extra)and skip entries that are not valid URL strings, so bad stored data can't break the block (or add a character per iteration if it is a string).
There was a problem hiding this comment.
Also this only runs inside the platformNPMEnabled && (certifiedNodes || ffNodes) block, but the UI disables the field based on certifiedNodes only.
There was a problem hiding this comment.
Also this only runs inside the platformNPMEnabled && (certifiedNodes || ffNodes) block, but the UI disables the field based on certifiedNodes only.
Yes, because ffNodes adds a URL to the list, but the override box is to ONLY add more certified nodes catalogues
| async function setTeamTypeCatalogues (cats) { | ||
| const defaultTeamTypeProperties = app.defaultTeamType.properties | ||
| defaultTeamTypeProperties.extraCatalogues = cats | ||
| app.defaultTeamType.properties = defaultTeamTypeProperties | ||
| await app.defaultTeamType.save() | ||
| } |
There was a problem hiding this comment.
I think this mutates deaullt team type. Maybe a before (to store original) and an afterEach (to reset it) is needed?
| async function setTeamTypeCatalogues (cats) { | ||
| const defaultTeamTypeProperties = app.defaultTeamType.properties | ||
| defaultTeamTypeProperties.extraCatalogues = cats | ||
| app.defaultTeamType.properties = defaultTeamTypeProperties |
There was a problem hiding this comment.
same mutation as device tests - should we have before (to capture starting value) and afterEach (to restoire)?
| settings.palette.should.have.property('catalogue') | ||
| settings.palette.catalogue.should.containEql('https://example.com/team-type-cat.json') | ||
| }) | ||
| it('Should add extra catalogue to project only if not present', async function () { |
There was a problem hiding this comment.
This sends a duplicate but never asserts it appears. It splices the two entries out and then asserts cat2 is gone, which passes regardless of dedupe. I think we should assert the count of team-type-cat.json is exactly 1.
Noted the device spec has no dedupe test either.
Additionally, I think a test that uses URLs which differ only in form but resolve to the same catalogue (e.g. https://example.com/cat.json and https://EXAMPLE.com/cat.json, or https://example.com and https://example.com/) would be worthwhile. Existing entries are normalised with new URL(...).toString(), but the extra catalogues are compared and pushed as raw strings, so indexOf treats these as different and both end up in the list. Asserting that only one entry remains should fail as it stands.
Nope, catalogue URLs can not hold tokens |
fixes FlowFuse/engineering#534
Description
Allow catalogue URLS to be added to team types and only added to devices and instance is they are not already present
Related Issue(s)
FlowFuse/engineering#534
Checklist
flowforge.yml?FlowFuse/helmto update ConfigMap TemplateFlowFuse/CloudProjectto update values for Staging/ProductionLabels
area:migrationlabel