Repository navigation
feat: add eval:inventory CLI command and reporting logic #28009
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env tsx | ||
|
|
||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @fileoverview CLI entry point for the eval inventory command. | ||
| * | ||
| * Scans all eval source files, runs the static analyzer on each, | ||
| * and prints a human-readable inventory report grouped by policy, | ||
| * file, and suite. | ||
| * | ||
| * Usage: | ||
| * npm run eval:inventory | ||
| * npm run eval:inventory -- --root /path/to/repo | ||
| */ | ||
|
|
||
| import { | ||
| collectInventory, | ||
| formatInventoryReport, | ||
| } from './utils/eval-inventory.js'; | ||
|
|
||
| async function main() { | ||
| const rootFlagIndex = process.argv.indexOf('--root'); | ||
| const repoRoot = | ||
| rootFlagIndex !== -1 && process.argv[rootFlagIndex + 1] | ||
| ? process.argv[rootFlagIndex + 1] | ||
| : process.cwd(); | ||
|
|
||
| const result = await collectInventory(repoRoot); | ||
|
|
||
| if (result.totalFiles === 0) { | ||
| console.error('No eval files found under evals/.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(formatInventoryReport(result)); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error('Fatal error:', error); | ||
| process.exit(1); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import path from 'node:path'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| collectInventory, | ||
| formatInventoryReport, | ||
| type InventoryResult, | ||
| } from '../utils/eval-inventory.js'; | ||
| import type { EvalCaseRecord } from '../utils/eval-analysis.js'; | ||
|
|
||
| function makeCaseRecord( | ||
| overrides: Partial<EvalCaseRecord> = {}, | ||
| ): EvalCaseRecord { | ||
| return { | ||
| filePath: '/repo/evals/test.eval.ts', | ||
| relativePath: 'evals/test.eval.ts', | ||
| helperName: 'evalTest', | ||
| baseHelperName: 'evalTest', | ||
| policy: 'USUALLY_PASSES', | ||
| name: 'test case', | ||
| hasFiles: false, | ||
| hasPrompt: true, | ||
| location: { line: 1, column: 1 }, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('eval-inventory', () => { | ||
| describe('collectInventory', () => { | ||
| it('discovers eval files from the real evals directory', async () => { | ||
| const repoRoot = path.resolve(import.meta.dirname, '../../'); | ||
| const result = await collectInventory(repoRoot); | ||
|
|
||
| expect(result.totalFiles).toBeGreaterThanOrEqual(36); | ||
| expect(result.totalCases).toBeGreaterThanOrEqual(90); | ||
| expect(result.files.length).toBe(result.totalFiles); | ||
| expect(result.cases.length).toBe(result.totalCases); | ||
|
|
||
| for (const evalCase of result.cases) { | ||
| expect(evalCase.name).toBeTruthy(); | ||
| expect(evalCase.relativePath).toBeTruthy(); | ||
| expect(evalCase.relativePath).toMatch(/^evals\//); | ||
| } | ||
| }); | ||
|
|
||
| it('returns zero counts for a directory with no eval files', async () => { | ||
| const result = await collectInventory(import.meta.dirname); | ||
|
|
||
| expect(result.totalFiles).toBe(0); | ||
| expect(result.totalCases).toBe(0); | ||
| expect(result.files).toEqual([]); | ||
| expect(result.cases).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('formatInventoryReport', () => { | ||
| it('includes summary line with correct counts', () => { | ||
| const result: InventoryResult = { | ||
| totalFiles: 2, | ||
| totalCases: 3, | ||
| files: [], | ||
| cases: [ | ||
| makeCaseRecord({ policy: 'ALWAYS_PASSES', name: 'case-1' }), | ||
| makeCaseRecord({ policy: 'USUALLY_PASSES', name: 'case-2' }), | ||
| makeCaseRecord({ policy: 'USUALLY_PASSES', name: 'case-3' }), | ||
| ], | ||
| diagnostics: [], | ||
| }; | ||
|
|
||
| const report = formatInventoryReport(result); | ||
|
|
||
| expect(report).toContain('2 files · 3 cases · 0 diagnostics'); | ||
| }); | ||
|
|
||
| it('groups cases by policy', () => { | ||
| const result: InventoryResult = { | ||
| totalFiles: 1, | ||
| totalCases: 2, | ||
| files: [], | ||
| cases: [ | ||
| makeCaseRecord({ | ||
| policy: 'ALWAYS_PASSES', | ||
| name: 'stable test', | ||
| }), | ||
| makeCaseRecord({ | ||
| policy: 'USUALLY_PASSES', | ||
| name: 'flaky test', | ||
| }), | ||
| ], | ||
| diagnostics: [], | ||
| }; | ||
|
|
||
| const report = formatInventoryReport(result); | ||
|
|
||
| expect(report).toContain('By Policy'); | ||
| expect(report).toContain('ALWAYS_PASSES (1 cases)'); | ||
| expect(report).toContain('USUALLY_PASSES (1 cases)'); | ||
| expect(report).toContain('• stable test'); | ||
| expect(report).toContain('• flaky test'); | ||
| }); | ||
|
|
||
| it('groups cases by suite name', () => { | ||
| const result: InventoryResult = { | ||
| totalFiles: 1, | ||
| totalCases: 2, | ||
| files: [], | ||
| cases: [ | ||
| makeCaseRecord({ suiteName: 'default', name: 'suite-test' }), | ||
| makeCaseRecord({ name: 'no-suite-test' }), | ||
| ], | ||
| diagnostics: [], | ||
| }; | ||
|
|
||
| const report = formatInventoryReport(result); | ||
|
|
||
| expect(report).toContain('By Suite'); | ||
| expect(report).toContain('default (1 cases)'); | ||
| expect(report).toContain('(no suite) (1 cases)'); | ||
| }); | ||
|
|
||
| it('shows diagnostics section when diagnostics exist', () => { | ||
| const result: InventoryResult = { | ||
| totalFiles: 1, | ||
| totalCases: 0, | ||
| files: [], | ||
| cases: [], | ||
| diagnostics: [ | ||
| { | ||
| severity: 'warning', | ||
| message: 'Could not resolve policy', | ||
| filePath: '/repo/evals/bad.eval.ts', | ||
| location: { line: 5, column: 3 }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const report = formatInventoryReport(result); | ||
|
|
||
| expect(report).toContain('Diagnostics'); | ||
| expect(report).toContain('1 diagnostics'); | ||
| expect(report).toContain( | ||
| '⚠ /repo/evals/bad.eval.ts:5:3 — Could not resolve policy', | ||
| ); | ||
| }); | ||
|
|
||
| it('omits diagnostics section when there are none', () => { | ||
| const result: InventoryResult = { | ||
| totalFiles: 1, | ||
| totalCases: 1, | ||
| files: [], | ||
| cases: [makeCaseRecord()], | ||
| diagnostics: [], | ||
| }; | ||
|
|
||
| const report = formatInventoryReport(result); | ||
|
|
||
| expect(report).not.toContain('Diagnostics'); | ||
| expect(report).not.toContain('⚠'); | ||
| }); | ||
|
|
||
| it('includes helper name in case listing', () => { | ||
| const result: InventoryResult = { | ||
| totalFiles: 1, | ||
| totalCases: 1, | ||
| files: [], | ||
| cases: [ | ||
| makeCaseRecord({ | ||
| helperName: 'customHelper', | ||
| name: 'custom test', | ||
| }), | ||
| ], | ||
| diagnostics: [], | ||
| }; | ||
|
|
||
| const report = formatInventoryReport(result); | ||
|
|
||
| expect(report).toContain('• custom test [customHelper]'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
neat! Playing with this a bit I think it'd be even more useful if there were some filters for specific types of tests.