[jsweep] Clean create_labels.cjs and add comprehensive tests#28210
[jsweep] Clean create_labels.cjs and add comprehensive tests#28210
Conversation
- Replace nested for-loops with flatMap + type-guard helper for label collection - Export deterministicLabelColor for testability - Add isNonEmptyString type predicate for clean TypeScript narrowing - Fix JSDoc comment: 128–223 per channel (was 128–191) - Add create_labels.test.cjs with 17 test cases covering: - deterministicLabelColor: hex format, determinism, pastel range, edge cases - main: label creation, dedup, skip existing, max count, error handling Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Great work from the jsweep agentic workflow! 🎉 This PR cleanly refactors
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the create_labels.cjs GitHub Script to simplify label collection and makes the label-color generator independently testable, alongside adding a dedicated Vitest suite for the behavior.
Changes:
- Refactors label extraction to a
flatMap+ type-guard pipeline and trims/dedupes viaSet. - Exports
deterministicLabelColorfor direct unit testing. - Adds
create_labels.test.cjswith coverage for label discovery, deduping, creation, and error handling.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/create_labels.cjs | Simplifies label collection and exports the deterministic color function. |
| actions/setup/js/create_labels.test.cjs | Adds a new test suite covering deterministic color generation and main() behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
| /** | ||
| * Generate a deterministic pastel hex color string from a label name. | ||
| * Produces colors in the pastel range (128–191 per channel) for readability. | ||
| * Produces colors in the pastel range (128–223 per channel) for readability. | ||
| * |
There was a problem hiding this comment.
The JSDoc says the color channels are in the 128–223 range, but the implementation uses & 0x3f (0–63), so each channel is actually 128–191. Either update the comment back to 128–191, or change the bitmask/range logic to match 223 (and adjust tests accordingly).
🧪 Test Quality Sentinel ReportTest Quality Score: 76/100
Test Classification DetailsView all 17 test classifications
Flagged Tests — Requires ReviewNo tests are flagged for behavioral issues. One informational observation: i️ Test Inflation —
|
|
@copilot review all docs |
…0-63) Agent-Logs-Url: https://github.com/github/gh-aw/sessions/9609f19b-fbea-4dda-851c-23b2f390c0af Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Summary
Cleaned
create_labels.cjs(github-script context) and added a comprehensive test suite.Changes to
create_labels.cjsflatMapwith a type-guard helper (isNonEmptyString) instead of nestedforloops — reduces nesting and improves readabilitydeterministicLabelColorto make the pure function independently testableisNonEmptyStringtype predicate — TypeScript-friendly narrowing ofunknown[]→string[]without requiring JSDoc casts that Prettier removes& 0x3fgives 0–63, so 128+63=191 — comment now accurate)All existing
try/catchblocks are preserved as they all use control flow (returnon error).New test file:
create_labels.test.cjs17 test cases covering:
deterministicLabelColor(5 tests)main(12 tests)setFailedwhen compile exits non-zero with no outputsetFailedwhen compile output is not valid JSONcreateLabelerror as already-existing (race condition)Validation
npm run format:cjs✓npm run lint:cjs✓npm run typecheck✓create_labels.test.cjs)