Skip to content

Add schema usage commands#9540

Closed
michaelstaib wants to merge 3 commits intomainfrom
mst/nitro-commands
Closed

Add schema usage commands#9540
michaelstaib wants to merge 3 commits intomainfrom
mst/nitro-commands

Conversation

@michaelstaib
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 13, 2026 10:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 schema analytics subcommands backed by a new ICoordinatesClient and GraphQL operations.
  • Adds session-persisted defaults and a nitro config set|get|unset command 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>
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<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.

Suggested change
<TargetFrameworks></TargetFrameworks>

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +20
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);
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +20
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);
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 1 to 3
using System.Text.Json.Serialization.Metadata;
using ChilliCream.Nitro.CommandLine.Output;
using ChilliCream.Nitro.CommandLine.Services.Configuration;
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +43 to +55
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);
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +20
public ConfigCommand() : base("config")
{
Description = "Manage analytical command defaults (api, stage, format).";

Subcommands.Add(new SetConfigCommand());
Subcommands.Add(new GetConfigCommand());
Subcommands.Add(new UnsetConfigCommand());
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@michaelstaib michaelstaib deleted the mst/nitro-commands branch April 23, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants