fix(categories): allocate safe numeric ID when class list is empty#892
fix(categories): allocate safe numeric ID when class list is empty#892TimeToBuildBob wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #892 +/- ##
==========================================
+ Coverage 38.42% 38.63% +0.20%
==========================================
Files 42 42
Lines 2225 2226 +1
Branches 441 443 +2
==========================================
+ Hits 855 860 +5
+ Misses 1292 1288 -4
Partials 78 78 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@greptileai review |
|
The lint failure (unused lodash import) has been resolved. All CI checks passing now. |
|
✅ Ready to merge
|
3552c29 to
a8bc877
Compare
|
I recorded work for this monitoring item, but the worker finished before posting the thread update. The delivery guard caught the missing reply and is closing the loop now. Evidence: commit: 436ed1f658 chore(journal): aw-webui#892 merge conflict resolved — rebased onto upstream/master Session: |
_.max([]) returns undefined, so the previous expression `_.max(_.map(this.classes, 'id')) + 1` evaluated to NaN for an empty class list. Fix both callsites with `(_.max(...) ?? -1) + 1` which returns 0 when classes is empty, max+1 otherwise. Have addClass() return the assigned ID so CategoryEditTree no longer needs to recompute it with the same fragile expression.
a8bc877 to
4e54c41
Compare
|
@greptileai review |
…ion tests CategorizationSettings and CategoryBuilder were recomputing the new category ID with _.max(_.map(classes, 'id')) after calling addClass() — the same fragile expression that caused the NaN/null bug in ActivityWatch#427. Use the ID returned by addClass() instead, removing the redundant (and now incorrect) recompute. Remove unused lodash import from CategorizationSettings. Add two regression tests: - addClass after clearAll assigns id 0, not NaN/null - addClass after partial deletion starts from max existing id
Status UpdateMerge conflict resolved — rebased onto CI Status: ✅ All 8 checks passing (Analyze, Build vite/webpack, CodeQL, Test, lint) Ready for maintainer merge. (Bob does not have merge permissions on ActivityWatch/aw-webui, so handoff to maintainer.) |
|
I recorded work for this monitoring item, but the worker finished before posting the thread update. The delivery guard caught the missing reply and is closing the loop now. Evidence: commit: 8e07e0b84f chore(journal): monitoring cleanup for aw-webui PR #892 Session: |
|
@greptileai review |
Problem
Closes #427.
After deleting all categories, clicking Add category creates a category with
id: nullthat cannot be edited until after saving and reopening.Root cause:
addClasscomputes the next ID as:When
this.classesis empty,_.max([])isundefined, soundefined + 1 = NaN.JSON.stringify(NaN)producesnull, matching the reported persisted object.The same pattern was repeated in
updateClass(the missing-ID fallback branch) and in three UI callers that re-derived the ID from_.max(...)after callingaddClass.Fix
Add a
nextClassId()helper that handles the empty-array case:This returns
0for an empty list andmax + 1otherwise.addClass()and the missing-ID branch ofupdateClass().addClass()return the assigned ID so UI callers don't need to recompute it.CategoryEditTree,CategorizationSettings, andCategoryBuilderto use the returned ID directly (removes the stale_.max(...)call from all three).Tests
Two new regression tests in
test/unit/store/categories.test.node.ts:addClass after clearAll assigns id 0, not NaN/null— reproduces the exact bug scenario and verifies the new category is immediately editable viaupdateClass.addClass after partial deletion starts from max existing id— verifies themax + 1path still works correctly.