Add schema usage commands#9540
Conversation
There was a problem hiding this comment.
Pull request overview
Adds new schema analytics commands (usage/clients/operations/unused/impact) plus a nitro config command group to persist defaults (api/stage/format) for these analytical commands.
Changes:
- Introduces new
nitro schemaanalytics subcommands backed by a newICoordinatesClientand GraphQL operations. - Adds session-persisted defaults and a
nitro config set|get|unsetcommand group to manage them. - Extends CLI option set with analytics-focused global options (
--format,--from,--to,--record,--replay) and related filters.
Reviewed changes
Copilot reviewed 64 out of 65 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Nitro/CommandLine/test/CommandLine.Tests/Commands/Schemas/Analytics/UsageSchemaCommandTests.cs | Adds tests for nitro schema usage output (help/markdown/json/table). |
| src/Nitro/CommandLine/test/CommandLine.Tests/Commands/Schemas/Analytics/UnusedSchemaCommandTests.cs | Adds tests for nitro schema unused output (markdown/json/table). |
| src/Nitro/CommandLine/test/CommandLine.Tests/Commands/Schemas/Analytics/OperationsSchemaCommandTests.cs | Adds tests for nitro schema operations output (markdown/json/table). |
| src/Nitro/CommandLine/test/CommandLine.Tests/Commands/Schemas/Analytics/ImpactSchemaCommandTests.cs | Adds tests for nitro schema impact output and verdict behavior. |
| src/Nitro/CommandLine/test/CommandLine.Tests/Commands/Schemas/Analytics/ClientsSchemaCommandTests.cs | Adds tests for nitro schema clients output (markdown/json/table). |
| src/Nitro/CommandLine/test/CommandLine.Tests/Commands/Schemas/Analytics/AnalyticsCommandTestBase.cs | Introduces a base class for analytics command tests. |
| src/Nitro/CommandLine/test/CommandLine.Tests/Commands/CommandTestBase.cs | Adds a strict ICoordinatesClient mock and registers/verifies it. |
| src/Nitro/CommandLine/src/CommandLine/Services/Sessions/SessionService.cs | Adds SetDefaultsAsync to persist analytics defaults to the session. |
| src/Nitro/CommandLine/src/CommandLine/Services/Sessions/Session.cs | Adds DefaultApiId, DefaultStage, and DefaultFormat session properties. |
| src/Nitro/CommandLine/src/CommandLine/Services/Sessions/ISessionService.cs | Extends session service API to set/clear defaults and adds SessionDefault<T>. |
| src/Nitro/CommandLine/src/CommandLine/Options/ToOption.cs | Adds analytics --to option with environment default support. |
| src/Nitro/CommandLine/src/CommandLine/Options/ReplayOption.cs | Adds analytics --replay option with environment default support. |
| src/Nitro/CommandLine/src/CommandLine/Options/RecordOption.cs | Adds analytics --record option with environment default support. |
| src/Nitro/CommandLine/src/CommandLine/Options/FromOption.cs | Adds analytics --from option with environment default support. |
| src/Nitro/CommandLine/src/CommandLine/Options/FormatOption.cs | Adds analytics --format option intended to support table/json/markdown. |
| src/Nitro/CommandLine/src/CommandLine/Options/EnvironmentVariables.cs | Adds environment variable keys for analytics options/filters. |
| src/Nitro/CommandLine/src/CommandLine/Options/DeprecatedOnlyOption.cs | Adds --deprecated-only filter flag for schema unused. |
| src/Nitro/CommandLine/src/CommandLine/Options/CoordinateOption.cs | Adds repeatable --coordinate option for coordinate-scoped analytics. |
| src/Nitro/CommandLine/src/CommandLine/Options/CoordinateKindsOption.cs | Adds --kinds option for filtering unused coordinate kinds. |
| src/Nitro/CommandLine/src/CommandLine/Options/AnalyticsStageNameOption.cs | Adds optional analytics --stage (intended to fall back to session default). |
| src/Nitro/CommandLine/src/CommandLine/Options/AnalyticsApiIdOption.cs | Adds optional analytics --api-id (intended to fall back to session default). |
| src/Nitro/CommandLine/src/CommandLine/NitroRootCommand.cs | Registers the new top-level config command. |
| src/Nitro/CommandLine/src/CommandLine/Extensions/CommandExtensions.cs | Adds AddAnalyticsGlobalOptions() helper for analytics commands. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/UsageSchemaCommand.cs | Implements nitro schema usage command behavior. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/UnusedSchemaCommand.cs | Implements nitro schema unused command behavior and kind parsing. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/SchemaCommand.cs | Wires new analytics subcommands under nitro schema. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/OperationsSchemaCommand.cs | Implements nitro schema operations command behavior. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/ImpactSchemaCommand.cs | Implements nitro schema impact command behavior and verdict computation. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/ClientsSchemaCommand.cs | Implements nitro schema clients command behavior. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/UnusedCoordinatesResult.cs | Defines output payload model for schema unused. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/UnusedCoordinatesJsonContext.cs | Adds STJ source-gen context for schema unused JSON output. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/UnusedCoordinatesFormatter.cs | Adds table/markdown/json rendering for schema unused. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateUsageResult.cs | Defines output payload model for schema usage. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateUsageJsonContext.cs | Adds STJ source-gen context for schema usage JSON output. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateUsageFormatter.cs | Adds table/markdown/json rendering for schema usage. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateOperationsResult.cs | Defines output payload model for schema operations. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateOperationsJsonContext.cs | Adds STJ source-gen context for schema operations JSON output. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateOperationsFormatter.cs | Adds table/markdown/json rendering for schema operations. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateImpactResult.cs | Defines output payload model for schema impact and verdict logic. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateImpactJsonContext.cs | Adds STJ source-gen context for schema impact JSON output. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateImpactFormatter.cs | Adds table/markdown/json rendering for schema impact. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateClientsResult.cs | Defines output payload model for schema clients. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateClientsJsonContext.cs | Adds STJ source-gen context for schema clients JSON output. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Schemas/Components/CoordinateClientsFormatter.cs | Adds table/markdown/json rendering for schema clients. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/UnsetConfigKeyArgument.cs | Adds key argument for nitro config unset. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/UnsetConfigCommand.cs | Adds nitro config unset implementation to clear defaults. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/SetConfigStageCommand.cs | Adds nitro config set stage implementation. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/SetConfigFormatCommand.cs | Adds nitro config set format implementation. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/SetConfigCommand.cs | Adds nitro config set parent command. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/SetConfigApiCommand.cs | Adds nitro config set api implementation. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/GetConfigCommand.cs | Adds nitro config get implementation to display defaults. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/ConfigStageNameArgument.cs | Adds stage argument for config set stage. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/ConfigFormatArgument.cs | Adds format argument for config set format. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/ConfigCommand.cs | Adds nitro config command group and subcommand wiring. |
| src/Nitro/CommandLine/src/CommandLine/Commands/Config/ConfigApiIdArgument.cs | Adds API id argument for config set api. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Extensions/NitroClientServiceCollectionExtensions.cs | Registers the new ICoordinatesClient in DI. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Coordinates/Operations/UnusedCoordinatesQuery.graphql | Adds GraphQL operation for unused coordinates analytics. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Coordinates/Operations/CoordinateUsageQuery.graphql | Adds GraphQL operation for coordinate usage metrics. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Coordinates/Operations/CoordinateOperationsQuery.graphql | Adds GraphQL operation for per-operation analytics. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Coordinates/Operations/CoordinateImpactQuery.graphql | Adds GraphQL operation for combined impact analytics. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Coordinates/Operations/CoordinateClientsQuery.graphql | Adds GraphQL operation for per-client analytics. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Coordinates/ICoordinatesClient.cs | Introduces the public client interface for coordinate analytics queries. |
| src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Coordinates/CoordinatesClient.cs | Implements coordinate analytics client against generated GraphQL operations. |
| src/Mocha/test/Demo.Catalog.Tests/Demo.Catalog.Tests.csproj | Updates test project reference path (and modifies target framework properties). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <TargetFrameworks></TargetFrameworks> |
There was a problem hiding this comment.
<TargetFrameworks></TargetFrameworks> is set to an empty value while <TargetFramework> is also specified. In SDK-style projects this typically causes MSBuild to error because TargetFramework and TargetFrameworks cannot both be set (even if TargetFrameworks is empty). Remove the empty TargetFrameworks element, or populate it and drop TargetFramework if multi-targeting is intended.
| <TargetFrameworks></TargetFrameworks> |
| Description = | ||
| "The lower bound of the time window for analytical commands " | ||
| + "as an ISO-8601 date or date-time. " | ||
| + "Defaults to seven days before --to."; | ||
| Required = false; | ||
|
|
||
| this.DefaultFromEnvironmentValue<DateTimeOffset?>(EnvironmentVariables.From); | ||
| } |
There was a problem hiding this comment.
DefaultFromEnvironmentValue<DateTimeOffset?> relies on OptionExtensions.ConvertEnvironmentValue, which currently falls back to Convert.ChangeType(...). DateTimeOffset does not implement IConvertible, so setting NITRO_FROM/BARISTA_FROM will throw at runtime when the default value factory runs. Consider extending ConvertEnvironmentValue to explicitly parse DateTimeOffset (e.g., DateTimeOffset.Parse(...) / ParseExact with round-trip formats).
| Description = | ||
| "The upper bound of the time window for analytical commands " | ||
| + "as an ISO-8601 date or date-time. " | ||
| + "Defaults to the current time."; | ||
| Required = false; | ||
|
|
||
| this.DefaultFromEnvironmentValue<DateTimeOffset?>(EnvironmentVariables.To); | ||
| } |
There was a problem hiding this comment.
Same as FromOption: DefaultFromEnvironmentValue<DateTimeOffset?> will throw at runtime if NITRO_TO/BARISTA_TO is set because ConvertEnvironmentValue falls back to Convert.ChangeType(...), which cannot convert to DateTimeOffset. Add explicit DateTimeOffset parsing in OptionExtensions.ConvertEnvironmentValue.
| using System.Text.Json.Serialization.Metadata; | ||
| using ChilliCream.Nitro.CommandLine.Output; | ||
| using ChilliCream.Nitro.CommandLine.Services.Configuration; |
There was a problem hiding this comment.
This file (and many others in this PR) references ChilliCream.Nitro.CommandLine.Output.OutputFormat, but the only OutputFormat currently present in the repo is ChilliCream.Nitro.CommandLine.Results.OutputFormat (and it only contains Json). As-is, this won’t compile. Either introduce the new ChilliCream.Nitro.CommandLine.Output output model (including OutputFormat with Table/Json/Markdown) or update these new session defaults to use the existing output types/namespaces consistently.
| parseResult.AssertHasAuthentication(sessionService); | ||
|
|
||
| var context = OutputContextResolver.Resolve(parseResult, console, sessionService); | ||
| var coordinates = parseResult.GetRequiredValue(Opt<CoordinateOption>.Instance); | ||
|
|
||
| if (coordinates.Count == 0) | ||
| { | ||
| throw new ExitException("At least one '--coordinate' is required."); | ||
| } | ||
|
|
||
| var formatter = new CoordinateUsageFormatter(context.Format); | ||
|
|
||
| var tasks = new List<Task<(string Coordinate, CoordinateUsageResult? Result)>>(coordinates.Count); |
There was a problem hiding this comment.
OutputContextResolver, OutputContext, OutputEnvelope, OutputEnvelopeError, and ErrorCodes are used here but don’t exist anywhere in the current repository (searching the codebase only finds these symbols in the newly added analytics commands). This will not compile until the new output/analytics infrastructure is added, or these commands are refactored to use the existing console/output abstractions already in the project.
| public ConfigCommand() : base("config") | ||
| { | ||
| Description = "Manage analytical command defaults (api, stage, format)."; | ||
|
|
||
| Subcommands.Add(new SetConfigCommand()); | ||
| Subcommands.Add(new GetConfigCommand()); | ||
| Subcommands.Add(new UnsetConfigCommand()); | ||
| } |
There was a problem hiding this comment.
There are extensive command tests in CommandLine.Tests, but this new nitro config command group (set/get/unset) doesn’t appear to have any tests. Adding tests that validate session persistence and output for these subcommands would help prevent regressions (e.g., ensuring defaults are saved/cleared and reflected in config get).
No description provided.