-
Notifications
You must be signed in to change notification settings - Fork 6
fix(cli): mute interactions on non tty sessions #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -95,24 +95,23 @@ describe('PackagesService', () => { | |||||||||
| expect((limited as string).length).toBeLessThanOrEqual((full as string).length); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('should expose the same package set in list and changelogs-unknown-package error', async () => { | ||||||||||
| const list = (await PackagesService.list()) as string; | ||||||||||
| const listSet = new Set(Array.from(list.matchAll(/^## (\S+) v/gm), m => m[1])); | ||||||||||
|
|
||||||||||
| it('should expose the same package set in the changelogs schema and unknown-package error', async () => { | ||||||||||
| const schema = (PackagesService.changelogsGet as ToolMethod<unknown>).metadata.inputSchema; | ||||||||||
| const schemaSet = new Set(schema?.properties?.name.enum ?? []); | ||||||||||
|
Comment on lines
+99
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
fd tsconfig.json projects/internals/tools -x cat {}
fd tsconfig.json -x cat {} \; 2>/dev/null | rg -n 'strict'Repository: NVIDIA/elements Length of output: 2036 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== service.test.ts excerpt ==\n'
cat -n projects/internals/tools/src/packages/service.test.ts | sed -n '80,115p'
printf '\n== ToolMethod definition ==\n'
rg -n "type ToolMethod|interface ToolMethod|export .*ToolMethod" projects/internals/tools/src -g '*.ts' -A 8 -B 4
printf '\n== metadata / inputSchema / properties usage ==\n'
rg -n "\.metadata(\?|)\.inputSchema|properties\?\.name\.enum|properties\?\.name\?\.enum|name\.enum" projects/internals/tools/src -g '*.ts' -A 2 -B 2Repository: NVIDIA/elements Length of output: 16152 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== ToolMetadata / Schema definitions ==\n'
cat -n projects/internals/tools/src/internal/tools.ts | sed -n '1,120p'
printf '\n== packages service schema setup ==\n'
rg -n "changelogsGet|inputSchema|properties|enum" projects/internals/tools/src/packages -g '*.ts' -A 4 -B 4Repository: NVIDIA/elements Length of output: 13579 Guard the optional metadata chain here
🛡️ Proposed fix for consistent optional chaining- const schema = (PackagesService.changelogsGet as ToolMethod<unknown>).metadata.inputSchema;
- const schemaSet = new Set(schema?.properties?.name.enum ?? []);
+ const schema = (PackagesService.changelogsGet as ToolMethod<unknown>).metadata?.inputSchema;
+ const schemaSet = new Set(schema?.properties?.name?.enum ?? []);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| const error = await PackagesService.changelogsGet({ name: 'does-not-exist', format: 'markdown' }).catch( | ||||||||||
| e => e as Error | ||||||||||
| ); | ||||||||||
| const available = error.message.split('Available packages:')[1] ?? ''; | ||||||||||
| const errSet = new Set(Array.from(available.matchAll(/"([^"]+)"/g), m => m[1])); | ||||||||||
|
|
||||||||||
| expect(listSet.size).toBeGreaterThan(0); | ||||||||||
| expect(errSet).toEqual(listSet); | ||||||||||
| expect(schemaSet.size).toBeGreaterThan(0); | ||||||||||
| expect(errSet).toEqual(schemaSet); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('should provide versions method', async () => { | ||||||||||
| const result = await PackagesService.versions(); | ||||||||||
| expect(result).toBeDefined(); | ||||||||||
| expect(typeof result).toBe('object'); | ||||||||||
| expect(result['@nvidia-elements/core']).toBe('1.0.0'); | ||||||||||
| expect(result['@nvidia-elements/core']).toMatch(/^\d+\.\d+\.\d+$/); | ||||||||||
| }); | ||||||||||
| }); | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
| import { RuleTester } from 'eslint'; | ||
| import type { JSRuleDefinition } from 'eslint'; | ||
| import htmlParser from '@html-eslint/parser'; | ||
| import { elementsHtmlConfig } from '../configs/html.js'; | ||
| import preferAriaLabelInCompactContainers from './prefer-aria-label-in-compact-containers.js'; | ||
|
|
||
| const rule = preferAriaLabelInCompactContainers as unknown as JSRuleDefinition; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value Double
As per coding guidelines, 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| function compactLabelError(control: string, container: string) { | ||
| return { | ||
| messageId: 'prefer-aria-label' as const, | ||
| data: { control, container } | ||
| }; | ||
| } | ||
|
|
||
| describe('preferAriaLabelInCompactContainers', () => { | ||
| let tester: RuleTester; | ||
|
|
||
| beforeEach(() => { | ||
| tester = new RuleTester({ | ||
| languageOptions: { | ||
| parser: htmlParser, | ||
| parserOptions: { | ||
| frontmatter: true | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('should define rule metadata', () => { | ||
| expect(preferAriaLabelInCompactContainers.meta).toBeDefined(); | ||
| expect(preferAriaLabelInCompactContainers.meta.type).toBe('problem'); | ||
| expect(preferAriaLabelInCompactContainers.meta.docs).toBeDefined(); | ||
| expect(preferAriaLabelInCompactContainers.meta.docs.description).toBe( | ||
| 'Prefer aria-label on form controls inside toolbars and page headers.' | ||
| ); | ||
| expect(preferAriaLabelInCompactContainers.meta.docs.category).toBe('Best Practice'); | ||
| expect(preferAriaLabelInCompactContainers.meta.docs.recommended).toBe(true); | ||
| expect(preferAriaLabelInCompactContainers.meta.docs.url).toContain('/docs/lint/'); | ||
| expect(preferAriaLabelInCompactContainers.meta.schema).toEqual([]); | ||
| expect(preferAriaLabelInCompactContainers.meta.messages['prefer-aria-label']).toBe( | ||
| 'Remove <label> from <{{control}}> inside <{{container}}> and use aria-label instead to preserve the compact layout.' | ||
| ); | ||
| }); | ||
|
|
||
| it('should register the rule as a recommended error', () => { | ||
| const plugin = elementsHtmlConfig.plugins?.['@nvidia-elements/lint']; | ||
|
|
||
| expect(plugin?.rules?.['prefer-aria-label-in-compact-containers']).toBe(preferAriaLabelInCompactContainers); | ||
| expect(elementsHtmlConfig.rules?.['@nvidia-elements/lint/prefer-aria-label-in-compact-containers']).toEqual([ | ||
| 'error' | ||
| ]); | ||
| }); | ||
|
|
||
| it('should allow labels that do not affect compact form controls', () => { | ||
| tester.run('allowed labels', rule, { | ||
| valid: [ | ||
| `<nve-input><label>Name</label><input /></nve-input>`, | ||
| `<nve-toolbar><label nve-text="body sm">1 of 13</label></nve-toolbar>`, | ||
| `<nve-page-header><nve-button><label>Action</label></nve-button></nve-page-header>`, | ||
| `<nve-toolbar><div><label>Caption</label></div></nve-toolbar>` | ||
| ], | ||
| invalid: [] | ||
| }); | ||
| }); | ||
|
|
||
| it('should allow compact form controls without visual labels', () => { | ||
| tester.run('aria labels', rule, { | ||
| valid: [ | ||
| `<nve-toolbar><nve-input><input aria-label="Search" /></nve-input></nve-toolbar>`, | ||
| `<nve-page-header><nve-select><select aria-label="Page"><option>One</option></select></nve-select></nve-page-header>`, | ||
| `<nve-toolbar><nve-input><input /></nve-input></nve-toolbar>` | ||
| ], | ||
| invalid: [] | ||
| }); | ||
| }); | ||
|
|
||
| it('should report labels in compact form controls', () => { | ||
| tester.run('compact control labels', rule, { | ||
| valid: [], | ||
| invalid: [ | ||
| { | ||
| code: `<nve-toolbar><nve-input><label>Search</label><input /></nve-input></nve-toolbar>`, | ||
| errors: [compactLabelError('nve-input', 'nve-toolbar')] | ||
| }, | ||
| { | ||
| code: `<nve-page-header><nve-search slot="suffix"><label>Search</label><input type="search" /></nve-search></nve-page-header>`, | ||
| errors: [compactLabelError('nve-search', 'nve-page-header')] | ||
| }, | ||
| { | ||
| code: `<nve-toolbar><div><nve-select><label>Page</label><select></select></nve-select></div></nve-toolbar>`, | ||
| errors: [compactLabelError('nve-select', 'nve-toolbar')] | ||
| }, | ||
| { | ||
| code: `<nve-page-header><nve-star-rating><span><label>Rating</label></span><input type="range" /></nve-star-rating></nve-page-header>`, | ||
| errors: [compactLabelError('nve-star-rating', 'nve-page-header')] | ||
| }, | ||
| { | ||
| code: `<nve-toolbar><nve-input><label>Name</label><input aria-label="Name" /></nve-input></nve-toolbar>`, | ||
| errors: [compactLabelError('nve-input', 'nve-toolbar')] | ||
| } | ||
| ] | ||
| }); | ||
| }); | ||
|
|
||
| it('should report each label against its nearest form control', () => { | ||
| tester.run('nested form controls', rule, { | ||
| valid: [], | ||
| invalid: [ | ||
| { | ||
| code: `<nve-toolbar> | ||
| <nve-checkbox-group> | ||
| <label>Options</label> | ||
| <nve-checkbox><label>First</label><input type="checkbox" /></nve-checkbox> | ||
| </nve-checkbox-group> | ||
| </nve-toolbar>`, | ||
| errors: [ | ||
| compactLabelError('nve-checkbox-group', 'nve-toolbar'), | ||
| compactLabelError('nve-checkbox', 'nve-toolbar') | ||
| ] | ||
| } | ||
| ] | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Type cast bypasses type safety.
PackagesService.changelogsGet as ToolMethod<unknown>casts around the actual type instead of narrowing it. Consider whetherToolMethodcan be inferred/typed directly onchangelogsGetto avoid the cast, per TypeScript guidance on type safety.As per coding guidelines, "When working with TypeScript code, follow
/projects/site/src/docs/internal/guidelines/typescript.mdfor type safety, type guards, discriminated unions, and exhaustive checking."🤖 Prompt for AI Agents
Source: Coding guidelines