Skip to content

Latest commit

 

History

History
180 lines (118 loc) · 11.1 KB

AGENTS.md

File metadata and controls

180 lines (118 loc) · 11.1 KB

AGENTS.md

This file provides guidance to coding agents when working with this repository.

Attribution

  • Do not add Co-authored-by trailers or other co-author attribution for agents.

Commit Messages

  • Wrap every @-prefixed token in backticks, so GitHub does not turn it into a mention. This covers directive names, package scopes, and user handles: Fix pruning of list-wrapped `@require` input types.

Pull Requests

  • Start a bug fix PR title with Fix: Fix the gateway ignoring subgraph timeouts. The title becomes the squash commit subject and the release note entry.
  • Area prefixes are optional. Write them in title case ([Fusion], not [fusion]), and put Fix after one: [Fusion] Fix the gateway ignoring subgraph timeouts.

Build

Website

Use npm.

cd website
npm ci

npm 11 before 11.21.1 and npm 12 before 12.2.1 write allowScripts entries from npm install-scripts approve that npm cannot match under the linked install strategy (npm/cli#9939), so on those versions add approvals by hand as "<package>@<version>": true.

C# Source Code

Builds report IDE code-style violations (IDE*) as build errors, the same as CI does. Fix every reported style error.

Build the full solution:

dotnet build src/All.slnx

Each area has its own solution file, so you can build or test a subset directly:

dotnet test src/HotChocolate/Fusion

Updating .NET

When a change edits TargetFrameworks in src/Directory.Build.props or the SDK version in global.json, work through docs/updating-dotnet.md before handoff.

Code Quality

C# / .NET

  • Always use curly braces for loops and conditionals, no exceptions.
  • Use file-scoped namespaces and 4-space indentation.
  • Test naming: Method_Should_Outcome_When_Condition.
  • No vacuous assertions (Assert.NotNull alone is not a test).
  • If a test requires excessive stubs and reflection, you're at the wrong test tier.
  • Do not use em dash style sentences in docs, comments, or XML documentation. Use commas, periods, parentheses, or colons instead.
  • XML docs should describe the contract and concepts, not internals like pooling or iteration mechanics, and should not leak other implementation details.
  • XML docs and comments are 1-2 sentences stating the contract: what it is, what null or edge values mean. No rationale, no use-case examples, no design justification. If a sentence explains why the design is right instead of what the member promises, delete it. The same applies to docs pages: every sentence must inform the reader, none may justify the design.
  • Do not make new parameters optional just to avoid updating call sites. A parameter should only be optional when it has a sensible semantic default and the API is frequently used (where call-site brevity outweighs explicitness). If a parameter is logically required, make it required and update all call sites.

Testing

  • Use regular Assert APIs for simple checks, with at most 5 Assert.* calls per test method.

  • Use CookieCrumble snapshots for structured or formatted output, such as JSON responses, GraphQL results, generated code, and Markdown documents.

  • Do not create an anonymous object with scalar properties just to snapshot it. Assert those values directly.

  • CookieCrumble has native snapshot support for IExecutionResult, GraphQLHttpResponse, and other core types.

  • For smaller snapshots, prefer inline snapshots (MatchInlineSnapshot) over snapshot files.

  • For a collection of results (for example a stream of subscription events), snapshot the list with MatchInlineSnapshots (a parallel list of per-element inline snapshots). Do NOT concatenate with string.Join("---", values).MatchInlineSnapshot(...): a manual separator hides element boundaries and reinvents what the collection overload does natively.

  • Use Markdown snapshots (MatchMarkdownSnapshot) when a snapshot combines multiple structured or formatted outputs.

  • If a test needs more than 5 Assert.* calls, split it into focused tests or use a snapshot when the output meets the criteria above.

  • Use the AAA section marker style. Each section starts with a single-line comment, the test name documents intent, no paragraph-style block comments above sections:

    // arrange
    // optional one-line description, only when the next code is non-obvious
    ... arrange code ...
    
    // act
    ... act code ...
    
    // assert
    ... assert code ...
  • Avoid Assert.DoesNotContain as it is a weak assertion that easily goes out of date, it only proves something is absent without verifying what is present. Prefer Assert.Equal to check the entire string value, or Assert.Collection to verify the complete contents of a collection.

  • Do not assert on a substring of a message with Assert.Contains. Assert the whole message with Assert.Equal, so a wording change is caught and the expected text is documented in the test.

  • Snapshot tests: update from __mismatch__/ directory, understand ordering issues before updating.

  • Filter tests during iteration, never run the full suite unnecessarily.

  • Use real databases in integration tests, not mocks (unless explicitly instructed otherwise).

Performance

C# / .NET

This is framework code, performance matters. Aim for zero allocations on hot paths.

  • Use ChunkedArrayWriter or PooledArrayWriter when you need an IBufferWriter<byte> for in-memory byte writing.

Tools

C# / .NET

If you need to search for packages on nuget.org, use the dotnet CLI, e.g. dotnet package search HotChocolate.

Profiling

The dev container has dotnet-trace, dotnet-counters, dotnet-gcdump, dotnet-dump, dotnet-symbol, dottrace and dotmemory installed. Versions are pinned in .devcontainer/dockerfile, and docs/profiling.md has the full commands and caveats. The tools attach to a running process in the same container. Write outputs to perf/<label>-<git-short-sha>/, which is gitignored.

OUT=perf/<label>-$(git rev-parse --short HEAD); mkdir -p "$OUT"
dotnet-trace ps
dotnet-trace collect -p <pid> --duration 00:00:00:30 --format speedscope -o "$OUT/cpu.nettrace"
dotnet-trace report "$OUT/cpu.nettrace" topN -n 25 --inclusive
dotnet-trace collect -p <pid> --profile gc-verbose --duration 00:00:00:15 -o "$OUT/alloc.nettrace"
dotnet-gcdump collect -p <pid> -o "$OUT/heap.gcdump" && dotnet-gcdump report "$OUT/heap.gcdump" > "$OUT/heap-report.txt"
dotnet-counters collect -p <pid> --format json -o "$OUT/counters.json" --duration 00:00:00:20 --counters System.Runtime,Microsoft.AspNetCore.Hosting,System.Net.Http
  • Profile Release builds. Debug builds distort time and allocations.
  • Sampling gives time, not call counts. Call counts need dotTrace Tracing mode, which only dottrace start offers; dottrace attach is limited to Sampling and Timeline.
  • On Linux, EventPipe samples measure thread time. Ignore idle thread pool frames such as LowLevelLifoSemaphore.WaitForSignal and WaitHandle.WaitOneNoCheck.
  • .dtp (dotTrace) and .dmw (dotMemory) snapshots are for Rider on the host. Use the dotnet-trace and dotnet-gcdump outputs for analysis inside the container.

Nitro persisted operations (Fusion Aspire)

After adding or editing any .graphql document under src/HotChocolate/Fusion/src/Fusion.Aspire/Nitro/Operations, regenerate the .sha256 sidecars and verify them:

.github/scripts/nitro-aspire-operations.sh update \
    --source src/HotChocolate/Fusion/src/Fusion.Aspire/Nitro/Operations
.github/scripts/nitro-aspire-operations.sh verify \
    --source src/HotChocolate/Fusion/src/Fusion.Aspire/Nitro/Operations \
    --output /tmp/nitro-aspire-operations.json

Never hand-write or hand-edit a .sha256 sidecar. The update command is the only source of sidecar content, and verify must pass before handoff.

Components

All components

Exceptions

Create exceptions through the ThrowHelper class of the project you are editing instead of inlining throw new .... Each project keeps its own, which centralizes exception messages. Example: src/HotChocolate/Fusion/src/Fusion.Execution/Execution/ThrowHelper.cs

GraphQL errors

Create GraphQL errors through the ErrorHelper class of the project you are editing instead of inlining ErrorBuilder calls. Each project keeps its own, which centralizes error messages. Example: src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Utilities/ErrorHelper.cs

src/Fusion

Execution nodes

When you add a value to ExecutionNodeType, map it in two places:

  • ExecutePlanNodeSpan.KindValues in src/HotChocolate/Fusion/src/Fusion.Diagnostics/Spans/ExecutePlanNodeSpan.cs
  • GraphQL.Operation.Step.KindValues in src/HotChocolate/Diagnostics/src/Diagnostics.Core/SemanticConventions.cs, if the kind needs a new constant. Tag values are snake_case.

KindValues supplies the graphql.operation.step.kind tag on the step span. An unmapped type does not fail execution. ExecutePlanNodeSpan.Start falls back to an untagged span, so the node silently loses its kind in traces. The guard test StepSpan_Should_MapEveryExecutionNodeTypeToAKindValue in src/HotChocolate/Fusion/test/Fusion.Diagnostics.Tests/FusionActivityExecutionDiagnosticListenerTests.cs fails until the mapping exists.

Operation planner version

OperationPlanner.Version identifies planning behavior and is independent of the package version. Bump the minor version when an existing operation can plan differently, the major version when consumers must react to a new plan structure. Refactors, performance work and fixes that cannot change a plan do not bump it.

Operation plan JSON format

JsonOperationPlanFormatter in src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Serialization/JsonOperationPlanFormatter.cs writes the plan document that tooling consumes. Its shape is published as a JSON schema, so any change to the emitted JSON is a two part change:

  1. Bump JsonOperationPlanFormatter.FormatVersion. It is written as the root version property and is the discriminator consumers pin against. Additive optional properties bump the minor version, anything that changes or removes an existing property bumps the major version.
  2. Add the matching variant to website/public/schemas/fusion/operation-plan.json, published at https://chillicream.com/schemas/fusion/operation-plan.json. Add a #/$defs/<version>_plan entry and the allOf branch that selects it for that root version, and list the new version in the root version enum. Every other definition is unprefixed and shared across versions. When a version changes one of them, fork only that definition to <version>_<name> and point the new plan at the fork, so a released version keeps validating exactly what it validated before.

The root version enum and the allOf branch that selects v1_0_0_plan are the pattern to copy: a new version adds one enum entry, one branch and one plan definition.

The internal Format(IBufferWriter<byte>, Operation, ImmutableArray<ExecutionNode>) overload feeds the SHA-256 that becomes OperationPlan.Id. It deliberately omits the version property, so leave it alone unless you intend to change every plan id.