From 440b7027927ed5ecc59ddd94a6a680998278afa6 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:04:23 -0400 Subject: [PATCH 001/294] Report success on draft pull requests, keep failing for the merge-train label (#6496) --- .github/scripts/ci-failure-split.py | 4 +- .github/workflows/build.yml | 158 +++++++++++------- .../Darling.Tests/GuardStageWorkflowTests.cs | 2 +- Lite.Tests/CrossAppGuardCiGateTests.cs | 30 ++-- 4 files changed, 115 insertions(+), 79 deletions(-) diff --git a/.github/scripts/ci-failure-split.py b/.github/scripts/ci-failure-split.py index 76521fc52a..a78591d072 100644 --- a/.github/scripts/ci-failure-split.py +++ b/.github/scripts/ci-failure-split.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """Split recent failed Build runs into the deliberate "CI not run" marker and real failures (#5943). -A pull request whose CI is declined (a draft, or the merge-train label) still runs one job that fails on purpose -with the annotation title "CI not run" (build.yml, "Fail when CI did not run"), so the pull request cannot merge +A pull request whose CI is declined by the merge-train label still runs one job that fails on purpose +with the annotation title "CI not run" (build.yml, "Report when CI did not run"), so the pull request cannot merge without an admin override. Counted as an ordinary failure it made up 147 of 200 recent failed runs, and the real failure rate looked far worse than it was. This script counts that marker apart: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26b9e2a420..cc4c544b14 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,12 +74,17 @@ jobs: # - any other pull request: yes. # # A skipped job reports as skipped, and GitHub counts skipped as passing for a required check. A run - # the gate declined therefore must not read as green, so three jobs turn it into a FAILURE on a pull - # request: `build` (its first step), `Darling PostgreSQL tests` and `Lite tests (result)`. Those are the - # required checks, and each keeps its own name. The failure is the intended outcome: a draft or - # merge-train pull request shows red until it is marked ready (or, for a merge-train member, until an - # admin merges it after the train covered it). Branch protection does not bind admins, so - # `gh pr merge --admin` still works. + # the gate declined for a MERGE-TRAIN LABEL therefore must not read as green, so three jobs turn it + # into a FAILURE on a pull request: `build` (its first step), `Darling PostgreSQL tests` and `Lite + # tests (result)`. Those are the required checks, and each keeps its own name. The failure is the + # intended outcome: a merge-train member shows red until an admin merges it after the train covered + # it. Branch protection does not bind admins, so `gh pr merge --admin` still works. + # + # A DRAFT pull request is different: GitHub does not merge a draft whatever its checks say, and + # marking it ready starts a fresh run (`ready_for_review`), so a red check there only taught people + # to ignore red (1,037 of 1,294 failed Build runs in 14 days were drafts). The same three jobs report + # SUCCESS with a notice instead. The `declined` output tells the two causes apart; the label wins + # when a draft carries it, because that member must still fail. gate: name: Decide whether CI runs runs-on: ubuntu-latest @@ -91,6 +96,7 @@ jobs: contents: read outputs: run: ${{ steps.decide.outputs.run }} + declined: ${{ steps.decide.outputs.declined }} lite_timing_run: ${{ steps.timing.outputs.run_id }} lite_timing_artifacts: ${{ steps.timing.outputs.artifacts }} test_map_run: ${{ steps.testmap.outputs.run_id }} @@ -107,19 +113,21 @@ jobs: run: | set -euo pipefail + declined="" if [ "${EVENT_NAME}" != "pull_request" ]; then run=true; why="a ${EVENT_NAME} event always runs." elif [[ "${HEAD_REF}" == train/* ]]; then run=true; why="a merge-train pull request exists to run CI." elif [ "${HAS_MERGE_TRAIN_LABEL}" = "true" ]; then - run=false; why="the pull request carries the merge-train label, so its train run already covered it." + run=false; declined=merge-train; why="the pull request carries the merge-train label, so its train run already covered it." elif [ "${IS_DRAFT}" = "true" ]; then - run=false; why="the pull request is a draft. Marking it ready for review starts the run." + run=false; declined=draft; why="the pull request is a draft. Marking it ready for review starts the run." else run=true; why="a pull request that is ready for review runs." fi echo "run=${run}" >> "$GITHUB_OUTPUT" + echo "declined=${declined}" >> "$GITHUB_OUTPUT" if [ "${run}" = "true" ]; then echo "::notice title=CI runs::${why}" else @@ -844,8 +852,9 @@ jobs: # runs, whatever that job did (`!cancelled()` below), and runs everything when there is no usable selection. needs: [gate, test-map-select] # `build` is a required check, so it has to run to report anything but "skipped" (which counts as - # passing). When the gate declines the run the job still starts, on a cheap Linux runner, and its - # first step fails; no later step has an `always()`/`failure()` condition, so the rest are skipped. + # passing). When the gate declines the run the job still starts, on a cheap Linux runner. Its first + # step fails for a merge-train label and passes for a draft; every later step carries the gate's + # `run == 'true'` in its own `if`, so a declined run does nothing else either way. if: ${{ !cancelled() }} # #5949: `build` no longer waits for the Guard stage, so it cannot read the guard's result. A guard that fails on # a pull request cancels the run (guard-cancel), and the two aggregate result jobs carry the guard's failure. @@ -866,24 +875,30 @@ jobs: docs-fastpath: ${{ steps.fastpath.outputs.engaged }} steps: - - name: Fail when CI did not run + - name: Report when CI did not run if: ${{ needs.gate.outputs.run != 'true' }} shell: bash env: GATE_RESULT: ${{ needs.gate.result }} + DECLINED: ${{ needs.gate.outputs.declined }} run: | if [ "${GATE_RESULT}" != "success" ]; then echo "::error title=CI gate failed::needs.gate.result='${GATE_RESULT}' - the job that decides whether CI runs did not succeed, so nothing ran. Re-run the workflow." exit 1 fi - echo "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). It can be merged only by an admin override after a merge train covered it. (gate result: ${GATE_RESULT})" + if [ "${DECLINED}" = "draft" ]; then + echo "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review." + exit 0 + fi + echo "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped (the train's own run covered it). It can be merged only by an admin override. (gate result: ${GATE_RESULT})" exit 1 - uses: actions/checkout@v7 + if: needs.gate.outputs.run == 'true' - name: Detect changed paths id: filter - if: github.event_name != 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name != 'release') }} uses: dorny/paths-filter@v4 with: # On push events, compare against the previous commit on this branch @@ -1132,6 +1147,7 @@ jobs: # and vetoes the fast path via the areas guard above), so nothing this restore # validates could have moved since the push that last validated it. - name: Classify change for the docs fast path + if: needs.gate.outputs.run == 'true' id: fastpath shell: bash env: @@ -1166,12 +1182,12 @@ jobs: # as success, so the gate would fail open. It runs on every change the docs fast path does not # engage for (about two seconds), so a docs-only change stays fast. - name: Parse and link every wwwroot/js module - if: steps.fastpath.outputs.engaged != 'true' + if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} shell: bash run: bash .github/scripts/check-web-js.sh - name: Setup .NET 10.0 - if: steps.fastpath.outputs.engaged != 'true' + if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} uses: actions/setup-dotnet@v6 with: global-json-file: global.json @@ -1208,7 +1224,7 @@ jobs: # makes this restore mandatory and a second project taking an SDK-coupled reference fails rather than # joining the exemption quietly. - name: Restore dependencies - if: steps.fastpath.outputs.engaged != 'true' + if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} shell: bash run: | set -euo pipefail @@ -1230,11 +1246,11 @@ jobs: dotnet restore tools/ui-smoke-wpf/UiSmokeWpf.csproj --locked-mode - name: Build Lite.Tests - if: steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet build Lite.Tests/Lite.Tests.csproj -c Release --no-restore - name: Build Installer.Tests - if: steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet build deprecated/Installer.Tests/Installer.Tests.csproj -c Release --no-restore # The 'dashboard' path filter was defined when the Full Dashboard moved to deprecated/ (#1612) but @@ -1245,11 +1261,11 @@ jobs: # installer_core too: the Dashboard references Installer.Core, and the filter's own comment says a # change there rebuilds both products, which only held for the CLI Installer until now. - name: Build Dashboard.Tests - if: steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet build deprecated/Dashboard.Tests/Dashboard.Tests.csproj -c Release --no-restore - name: Build Darling - if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: | dotnet build Darling/Darling.Tests/Darling.Tests.csproj -c Release --no-restore dotnet build Darling/PerformanceMonitor.Darling.Viewer/PerformanceMonitor.Darling.Viewer.csproj -c Release --no-restore @@ -1269,17 +1285,17 @@ jobs: # to be maintained. Releases keep this single unsharded # pass so the artifact-producing run still executes the suite whole, in one log. - name: Run Lite tests - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} run: dotnet run --project Lite.Tests/Lite.Tests.csproj -c Release --no-build -- -xml TestResults/lite-timing-release.xml # #5208: per-test timings of the unsharded release pass, same shape as the lite-tests shards. - name: Lite test timing summary - if: always() && github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (always() && github.event_name == 'release') }} continue-on-error: true run: python .github/scripts/lite-timing-top.py TestResults - name: Upload Lite test timings - if: always() && github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (always() && github.event_name == 'release') }} continue-on-error: true uses: actions/upload-artifact@v6 with: @@ -1291,11 +1307,11 @@ jobs: if-no-files-found: ignore - name: Run Installer tests - if: steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet run --project deprecated/Installer.Tests/Installer.Tests.csproj -c Release --no-build -- -class- "Installer.Tests.VersionDetectionTests" -class- "Installer.Tests.IdempotencyTests" -class- "Installer.Tests.AdversarialTests" - name: Run Dashboard tests - if: steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet run --project deprecated/Dashboard.Tests/Dashboard.Tests.csproj -c Release --no-build # #5459 cut 3b: the PostgreSQL shards run EVERY Darling.Tests class, with a live store, whenever the Darling @@ -1305,7 +1321,7 @@ jobs: # .github/scripts/ci-select.py holds the rule (darling_scope); the replay of the failure corpus checks it. - name: Detect the Darling PostgreSQL gate id: darling-gate - if: github.event_name != 'release' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true') + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name != 'release' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true')) }} uses: dorny/paths-filter@v4 with: base: ${{ github.event_name == 'push' && github.event.before || '' }} @@ -1313,7 +1329,7 @@ jobs: - name: Decide the Darling test scope id: darling-scope - if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} shell: bash env: EVENT_NAME: ${{ github.event_name }} @@ -1330,7 +1346,7 @@ jobs: # failed download) leaves TEST_MAP_SELECTION empty in the test step below, and an empty one means every class runs. - name: Download the test map selection id: map-selection - if: github.event_name == 'pull_request' && needs.test-map-select.result == 'success' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'pull_request' && needs.test-map-select.result == 'success') }} continue-on-error: true uses: actions/download-artifact@v6 with: @@ -1339,7 +1355,7 @@ jobs: - name: Run Darling tests id: darling-tests - if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} env: DARLING_SCOPE_FILTER: ${{ steps.darling-scope.outputs.filter }} DARLING_SCOPE: ${{ steps.darling-scope.outputs.scope }} @@ -1410,7 +1426,7 @@ jobs: # variable. Darling.Tests is already built (Release) by the build step above, so this runs # the one test by name and nothing else. - name: Statement filter release gate - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} env: DARLING_RELEASE_CUT: '1' shell: pwsh @@ -1425,7 +1441,7 @@ jobs: } - name: Get version - if: steps.fastpath.outputs.engaged != 'true' + if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} id: version shell: pwsh run: | @@ -1452,23 +1468,23 @@ jobs: # Lite/PerformanceMonitorLite.csproj declares RuntimeIdentifiers so the committed lock # file covers this RID; see the comment there before removing either half. - name: Publish Lite - if: steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet publish Lite/PerformanceMonitorLite.csproj -c Release -r win-x64 --self-contained -o publish/Lite - name: Publish Lite (self-contained for Velopack) - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} run: dotnet publish Lite/PerformanceMonitorLite.csproj -c Release -r win-x64 --self-contained -o publish/Lite-velopack - name: Publish Darling Service - if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet publish Darling/PerformanceMonitor.Darling.Service/PerformanceMonitor.Darling.Service.csproj -c Release -o publish/DarlingService - name: Publish Darling Viewer - if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} run: dotnet publish Darling/PerformanceMonitor.Darling.Viewer/PerformanceMonitor.Darling.Viewer.csproj -c Release -o publish/DarlingViewer - name: Publish Darling Viewer (self-contained for Velopack) - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} run: dotnet publish Darling/PerformanceMonitor.Darling.Viewer/PerformanceMonitor.Darling.Viewer.csproj -c Release -r win-x64 --self-contained -o publish/DarlingViewer-velopack # Darling bundles a PostgreSQL 18 + TimescaleDB runtime (pg-runtime.zip) that ships beside @@ -1478,7 +1494,7 @@ jobs: # unchanged pins restores the assembled zip and skips both the download and the assembly, # and any pin/version bump edits the script and invalidates the cache automatically. - name: Cache Darling pg-runtime.zip - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} id: cache-pg-runtime uses: actions/cache@v6 with: @@ -1486,12 +1502,12 @@ jobs: key: pg-runtime-${{ runner.os }}-${{ hashFiles('Darling/tools/fetch-pg-runtime.ps1') }} - name: Build Darling pg-runtime.zip - if: github.event_name == 'release' && steps.cache-pg-runtime.outputs.cache-hit != 'true' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release' && steps.cache-pg-runtime.outputs.cache-hit != 'true') }} shell: pwsh run: ./Darling/tools/fetch-pg-runtime.ps1 - name: Package release artifacts - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | $version = "${{ steps.version.outputs.VERSION }}" @@ -1507,7 +1523,7 @@ jobs: # bump surfaces at release time — bump only alongside a validated real signing run. # Dependabot is configured to skip this major (see .github/dependabot.yml). - name: Upload Lite for signing - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} id: upload-lite uses: actions/upload-artifact@v6 with: @@ -1515,7 +1531,7 @@ jobs: path: publish/Lite/ - name: Stage Darling for signing - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | $stage = 'publish/Darling-signing' @@ -1525,7 +1541,7 @@ jobs: Copy-Item 'publish/DarlingViewer/*' "$stage/viewer" -Recurse - name: Upload Darling for signing - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} id: upload-darling uses: actions/upload-artifact@v6 with: @@ -1539,7 +1555,7 @@ jobs: # since 2026-09-24. SignPath signs only a run's first 3 attempts: if signing keeps # failing, fix the cause and start a fresh release run instead of re-running this one. - name: Sign Lite - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1552,7 +1568,7 @@ jobs: output-artifact-directory: 'signed/Lite' - name: Sign Darling - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1565,7 +1581,7 @@ jobs: output-artifact-directory: 'signed/Darling' - name: Replace with signed artifacts - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | $version = "${{ steps.version.outputs.VERSION }}" @@ -1574,7 +1590,7 @@ jobs: Compress-Archive -Path 'signed/Lite/*' -DestinationPath "releases/PerformanceMonitorLite-$version.zip" -Force - name: Package Darling (signed) - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | $version = "${{ steps.version.outputs.VERSION }}" @@ -1595,7 +1611,7 @@ jobs: # signature on lib/app/.exe inside each .nupkg and on current/.exe inside each # Portable.zip; `vpk pack` below reads the signed output, not the raw publish directory. - name: Upload Lite (Velopack) for signing - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} id: upload-lite-velopack uses: actions/upload-artifact@v6 with: @@ -1603,7 +1619,7 @@ jobs: path: publish/Lite-velopack/ - name: Upload Darling Viewer (Velopack) for signing - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} id: upload-darlingviewer-velopack uses: actions/upload-artifact@v6 with: @@ -1611,7 +1627,7 @@ jobs: path: publish/DarlingViewer-velopack/ - name: Sign Lite (Velopack) - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1629,7 +1645,7 @@ jobs: # workflow lives outside the repo on signpath.io, and a step naming a slug that does not # exist fails the release — the standing #1340 SignPath prerequisite. - name: Sign Darling Viewer (Velopack) - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1642,7 +1658,7 @@ jobs: output-artifact-directory: 'signed/DarlingViewer-Velopack' - name: Create Velopack releases (Lite + Darling Viewer) - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -1687,13 +1703,13 @@ jobs: # carries. The staging layout gives each product its own subdirectory because both # portable archives contain an Update.exe and a flat batch would collide. - name: Collect the executables Velopack generates - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | python3 .github/scripts/postpack_signing.py collect --stage postpack/unsigned --manifest postpack/manifest.json --product lite=releases/velopack-lite --product darlingviewer=releases/velopack-darlingviewer - name: Upload the Velopack-generated executables for signing - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} id: upload-postpack uses: actions/upload-artifact@v6 with: @@ -1706,7 +1722,7 @@ jobs: # the per-product configurations refuse with min-matches="1"; postpack_signing.py's # collect mode asserts a non-empty staging set for exactly that reason. - name: Sign the executables Velopack generates - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1722,7 +1738,7 @@ jobs: # it does not replace keeps its local header, name, extra field and raw compressed bytes, # and the rebuild is verified against a snapshot of the original before it replaces it. - name: Write the signed Velopack executables back - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | python3 .github/scripts/postpack_signing.py apply --signed postpack/signed --manifest postpack/manifest.json @@ -1733,7 +1749,7 @@ jobs: # here. releases..json is the integrity record for the .nupkg files, and nothing # publishes a checksum for the two files the step above signs. - name: Generate checksums - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | $checksums = Get-ChildItem releases/*.zip | ForEach-Object { @@ -1765,7 +1781,7 @@ jobs: # Darling zip must be there, and it must hold install-, uninstall- and upgrade-darling.ps1 at its # root (status 2 when one is missing, when there is no Darling zip, or when a file cannot be read). - name: Assert every published executable is signed - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: python3 .github/scripts/verify_release_signatures.py --verify-dir releases @@ -1775,7 +1791,7 @@ jobs: # SignPath Foundation certificate the release is signed with. Anything else, or a script that is not there, # fails the release. Each script's signer, thumbprint and timestamper are printed for the log. - name: Assert the Darling scripts carry a valid Authenticode signature - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh run: | $ErrorActionPreference = 'Stop' @@ -1823,14 +1839,14 @@ jobs: } - name: Upload release assets - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release upload ${{ github.event.release.tag_name }} releases/*.zip releases/SHA256SUMS.txt --clobber - name: Upload Lite Velopack artifacts - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -1850,7 +1866,7 @@ jobs: gh release upload "${{ github.event.release.tag_name }}" $files --clobber - name: Upload Darling Viewer Velopack artifacts - if: github.event_name == 'release' + if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} shell: pwsh env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -2503,6 +2519,7 @@ jobs: LINT_RESULT: ${{ needs.workflow-lint.result }} GATE_RESULT: ${{ needs.gate.result }} GATE_RUN: ${{ needs.gate.outputs.run }} + DECLINED: ${{ needs.gate.outputs.declined }} EVENT_NAME: ${{ github.event_name }} run: | set -euo pipefail @@ -2511,9 +2528,14 @@ jobs: echo "::error title=CI gate failed::needs.gate.result='${GATE_RESULT}' - the job that decides whether CI runs did not succeed, so nothing ran. Re-run the workflow." exit 1 fi - # A declined run (draft or merge-train) leaves every job skipped, which would also read as green. + # A declined run leaves every job skipped, which would also read as green. A draft reports success + # with a notice (marking it ready starts the run); a merge-train label must still fail. if [ "${EVENT_NAME}" = "pull_request" ] && [ "${GATE_RUN}" != "true" ]; then - echo "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). It can be merged only by an admin override after a merge train covered it." + if [ "${DECLINED}" = "draft" ]; then + echo "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review." + exit 0 + fi + echo "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped (the train's own run covered it). It can be merged only by an admin override." exit 1 fi # The Guard tests run beside the shards on a pull request (#5949; first, before that). When they did not @@ -3634,6 +3656,7 @@ jobs: LINT_RESULT: ${{ needs.workflow-lint.result }} GATE_RESULT: ${{ needs.gate.result }} GATE_RUN: ${{ needs.gate.outputs.run }} + DECLINED: ${{ needs.gate.outputs.declined }} EVENT_NAME: ${{ github.event_name }} LITE_SCOPE_MODE: ${{ needs.lite-scope.outputs.mode }} run: | @@ -3643,9 +3666,14 @@ jobs: echo "::error title=CI gate failed::needs.gate.result='${GATE_RESULT}' - the job that decides whether CI runs did not succeed, so nothing ran. Re-run the workflow." exit 1 fi - # A declined run (draft or merge-train) leaves every job skipped, which would also read as green. + # A declined run leaves every job skipped, which would also read as green. A draft reports success + # with a notice (marking it ready starts the run); a merge-train label must still fail. if [ "${EVENT_NAME}" = "pull_request" ] && [ "${GATE_RUN}" != "true" ]; then - echo "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). It can be merged only by an admin override after a merge train covered it." + if [ "${DECLINED}" = "draft" ]; then + echo "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review." + exit 0 + fi + echo "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped (the train's own run covered it). It can be merged only by an admin override." exit 1 fi # The Guard tests run beside the shards on a pull request (#5949; first, before that). When they did not diff --git a/Darling/Darling.Tests/GuardStageWorkflowTests.cs b/Darling/Darling.Tests/GuardStageWorkflowTests.cs index cc3c5a611a..09da3d1787 100644 --- a/Darling/Darling.Tests/GuardStageWorkflowTests.cs +++ b/Darling/Darling.Tests/GuardStageWorkflowTests.cs @@ -481,7 +481,7 @@ public void TheBuildJob_DoesNotWaitForTheGuardStage() .Take(2) .ToList(); - Assert.StartsWith("name: Fail when CI did not run", steps[0], StringComparison.Ordinal); + Assert.StartsWith("name: Report when CI did not run", steps[0], StringComparison.Ordinal); Assert.StartsWith("uses: actions/checkout@v7", steps[1], StringComparison.Ordinal); } diff --git a/Lite.Tests/CrossAppGuardCiGateTests.cs b/Lite.Tests/CrossAppGuardCiGateTests.cs index 06be4728cc..4ba0e22b76 100644 --- a/Lite.Tests/CrossAppGuardCiGateTests.cs +++ b/Lite.Tests/CrossAppGuardCiGateTests.cs @@ -3011,40 +3011,48 @@ private static int DaysFrom(string text, string pattern, string whatIsGone) } /// - /// A pull request whose CI the gate declined (a draft, or one carrying the merge-train label) must not - /// read as passing: a skipped job counts as a pass for a required check. build still starts and - /// fails its first step, and both result jobs exit 1 on a pull request whose gate output is not true. + /// A pull request whose CI the gate declined must not read as passing when the cause is the merge-train label: + /// a skipped job counts as a pass for a required check, so build still starts and fails its first step, + /// and both result jobs exit 1 on a pull request whose gate output is not true. A DRAFT is the exception: it + /// reports success with a notice (marking it ready starts the run), so a draft does not teach people to ignore red. /// [Fact] - public void ADeclinedRun_FailsBuildAndBothResultJobs_InsteadOfReadingAsGreen() + public void ADeclinedRun_FailsBuildAndBothResultJobsForTheMergeTrainLabel_AndPassesForADraft() { var yaml = ReadBuildYaml(RepoRoot()); - const string message = - "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). " - + "It can be merged only by an admin override after a merge train covered it."; + const string labelError = + "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped " + + "(the train's own run covered it). It can be merged only by an admin override."; + const string draftNotice = + "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review."; foreach (var jobKey in new[] { "darling-pg-result", "lite-tests-result" }) { var job = JobBlock(yaml, jobKey); Assert.Contains("GATE_RUN: ${{ needs.gate.outputs.run }}", job, StringComparison.Ordinal); + Assert.Contains("DECLINED: ${{ needs.gate.outputs.declined }}", job, StringComparison.Ordinal); Assert.Contains("EVENT_NAME: ${{ github.event_name }}", job, StringComparison.Ordinal); Assert.Contains( "if [ \"${EVENT_NAME}\" = \"pull_request\" ] && [ \"${GATE_RUN}\" != \"true\" ]; then\n" - + " echo \"" + message + "\"\n exit 1\n fi\n", + + " if [ \"${DECLINED}\" = \"draft\" ]; then\n" + + " echo \"" + draftNotice + "\"\n exit 0\n fi\n" + + " echo \"" + labelError + "\"\n exit 1\n fi\n", job, StringComparison.Ordinal); Assert.Contains("needs: [gate, ", job, StringComparison.Ordinal); } /* `build` is a required check that would otherwise be merely skipped. It must start whatever the - gate said, and its first step must fail when the gate declined the run. */ + gate said, and its first step must fail when the gate declined the run for the label. */ var build = JobBlock(yaml, "build"); Assert.Contains("\n if: ${{ !cancelled() }}\n", build, StringComparison.Ordinal); var first = build[build.IndexOf(" steps:\n", StringComparison.Ordinal)..]; first = first[..first.IndexOf("\n - uses: actions/checkout@v7", StringComparison.Ordinal)]; - Assert.Contains("- name: Fail when CI did not run", first, StringComparison.Ordinal); + Assert.Contains("- name: Report when CI did not run", first, StringComparison.Ordinal); Assert.Contains("if: ${{ needs.gate.outputs.run != 'true' }}", first, StringComparison.Ordinal); - Assert.Contains(message, first, StringComparison.Ordinal); + Assert.Contains("if [ \"${DECLINED}\" = \"draft\" ]; then", first, StringComparison.Ordinal); + Assert.Contains(draftNotice, first, StringComparison.Ordinal); + Assert.Contains(labelError, first, StringComparison.Ordinal); Assert.Contains("exit 1", first, StringComparison.Ordinal); } From 2612cf521940f6c9f465b816b5fada270cac7284 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:08:02 -0400 Subject: [PATCH 002/294] Release checklist: merge the dev to main release PR with a merge commit (#6489) Squash-merging a release PR leaves dev's commits out of main's history, so the next release PR conflicts on every file dev changed. Step 10 now says to merge the dev to main release PR with a merge commit, never squash (#6488). --- .claude/skills/release-checklist/SKILL.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.claude/skills/release-checklist/SKILL.md b/.claude/skills/release-checklist/SKILL.md index f30a6d79da..0ddea20e29 100644 --- a/.claude/skills/release-checklist/SKILL.md +++ b/.claude/skills/release-checklist/SKILL.md @@ -237,6 +237,7 @@ Before cutting the release, verify the nightly build has been clean: - Do the version-bump + changelog commits on a branch off `dev` (e.g. `release/v{version}`) — NEVER commit directly to `dev` or `main` (branch protection) - Push the branch and merge it into `dev` first (open that PR with base `dev`) - Then open the release PR **from `dev` to `main`** — the head MUST be `dev`. `check-pr-branch.yml` rejects any PR to `main` whose head is not `dev`, so a `release/*` → `main` PR fails CI (the "all jobs failed" email) +- Merge the `dev` to `main` release PR with **Create a merge commit**, never squash. A squash leaves `dev`'s commits out of `main`'s history, so the next release PR conflicts on every file `dev` changed. 3.10.0 was squashed, and the 3.11.0 release PR could merge only after `main` was merged into `dev` with a merge commit (#6485). An admin merge does not get past a conflict. - At release-PR merge time, dev must equal the sha the field validation ran against (or the delta must be explicitly accepted) ### 11. Tag and Release From ddba670c104a982996853b0a961dd24bc1a4514f Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:22:51 -0400 Subject: [PATCH 003/294] Review guard waits when the jobs API lists only some of the review job's steps (#6490) (#6491) --- .github/workflows/claude-review-guard.yml | 35 ++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/claude-review-guard.yml b/.github/workflows/claude-review-guard.yml index 1797f3ba85..358ccfce80 100644 --- a/.github/workflows/claude-review-guard.yml +++ b/.github/workflows/claude-review-guard.yml @@ -437,38 +437,47 @@ jobs: # per page of the jobs list. It is safe here: a run of the review workflow has two jobs # (decide and review), so the list is one page, and the step and the job named each # appear in it once. - # One read gives three fields: the review job's conclusion, how many steps the API lists - # under that job, and the review step's conclusion ("-" stands for a field that is absent). + # One read gives four fields: the review job's conclusion, how many steps the API lists + # under that job, whether that list includes the job's last step (`Complete job`: 1 or 0), + # and the review step's conclusion ("-" stands for a field that is absent). # The count matters because the jobs API can list a finished job with an EMPTY steps list # for many minutes after the run completed (#5783: a successful run whose bot verdict was # already on the head listed `steps: []` for both its jobs, and so did a Build run of the # same minute). A job that ran always has steps, so an empty list under a review job that - # did not skip means "not listed yet", not "the step was renamed". + # did not skip means "not listed yet", not "the step was renamed". A PARTIAL list does the + # same: run 39787226488 attempt 1 read the jobs 46 seconds after the review job ended and + # got 5 of its 11 steps, without `Claude review`. Every job ends with `Complete job`, so a + # concluded job whose list lacks it is still being listed. # shellcheck disable=SC2016 # the single quotes hold a jq program: $j is a jq variable, not a shell one jobs_jq='([.jobs[] | select(.name == env.REVIEW_JOB)] | .[0]) as $j | "\($j.conclusion // "-") \(($j.steps // []) | length)" + + " \(if ([($j.steps // [])[] | select(.name == "Complete job")] | length) > 0 then 1 else 0 end)" + " \(([.jobs[].steps[]? | select(.name == env.REVIEW_STEP)] | .[0].conclusion) // "-")"' lookup "review-run jobs (step conclusion)" "repos/$R/actions/runs/$run_id/jobs" --paginate \ --jq "$jobs_jq" - read -r review_job review_steps step <<<"$LOOKUP_OUT" + read -r review_job review_steps review_complete step <<<"$LOOKUP_OUT" if [ "$step" = "-" ]; then step=''; fi - # #5783: the review job finished without skipping and the API lists no steps under it. Ask - # again every 30 seconds, for about ten minutes, before deciding anything. A read that fails - # here uses up one try and keeps the last answer, as the run poll above does (#2309). + # #5783: the review job finished without skipping and the API lists no steps under it, or + # lists them without `Complete job`. Ask again every 30 seconds, for about ten minutes, + # before deciding anything. A read that fails here uses up one try and keeps the last + # answer, as the run poll above does (#2309). A partial list that already holds the review + # step does not wait: that step's conclusion is the answer, and the fallback below must + # not replace it. steps_unlisted() { - [ "$review_job" != "-" ] && [ "$review_job" != "skipped" ] && [ "$review_steps" = "0" ] + [ "$review_job" != "-" ] && [ "$review_job" != "skipped" ] \ + && { [ "$review_steps" = "0" ] || { [ "$review_complete" != "1" ] && [ -z "$step" ]; }; } } steps_tries=0 while steps_unlisted && [ "$steps_tries" -lt 20 ]; do steps_tries=$((steps_tries + 1)) echo "::notice title=Waiting for the review job's steps::Try $steps_tries of 20: the"\ - "'$REVIEW_JOB' job of run $run_id concluded '$review_job', but the jobs API lists no"\ - "steps under it yet (#5783). Asking again in 30 seconds." + "'$REVIEW_JOB' job of run $run_id concluded '$review_job', but the jobs API has not"\ + "listed all of its steps yet ($review_steps listed, #5783). Asking again in 30 seconds." sleep 30 if gh_capture "repos/$R/actions/runs/$run_id/jobs" --paginate --jq "$jobs_jq" \ && [ -n "$LOOKUP_OUT" ]; then - read -r review_job review_steps step <<<"$LOOKUP_OUT" + read -r review_job review_steps review_complete step <<<"$LOOKUP_OUT" if [ "$step" = "-" ]; then step=''; fi fi done @@ -479,7 +488,7 @@ jobs: # succeeded and a review on $SHA mean the review step ran and posted, so the checks below # go on as for a step that reported success. Anything else cannot be told apart from a # skipped step or a silent run, so the check fails and says why. - summary "- The jobs API listed no steps under the \`$REVIEW_JOB\` job of run $run_id after"\ + summary "- The jobs API listed no steps, or not all of them, under the \`$REVIEW_JOB\` job of run $run_id after"\ "$steps_tries tries (#5783). Decided from that job's conclusion (\`$review_job\`) and"\ "$REVIEW_BOT's reviews on ${SHA:0:12}." if [ "$review_job" != "success" ]; then @@ -494,7 +503,7 @@ jobs: | select(.commit_id == env.SHA) | .id' if [ -z "$LOOKUP_OUT" ]; then echo "::error title=Review step not listed::The '$REVIEW_JOB' job of run $run_id"\ - "succeeded, but after $steps_tries tries the jobs API still lists no steps under it,"\ + "succeeded, but after $steps_tries tries the jobs API still has not listed all of its steps,"\ "and $REVIEW_BOT submitted no review on $SHA. Without the '$REVIEW_STEP' step this"\ "guard cannot tell a skipped review from one that ran and posted nothing, so the"\ "check fails (#5783). Re-run this guard later; the jobs API fills the steps in late." From daddfaa94304c8637546218447ca9dd3e96c4992 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:45:22 -0400 Subject: [PATCH 004/294] End the compose-gate test's window at max(applied_through, rig.End), like its sibling (#6479) (#6499) The gate refuses a literal end before applied_through and the test saw that as 'not eligible'. Tests only. --- .../QueryStoreLegacyProbeOptInLiveTests.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Darling/Darling.Tests/QueryStoreLegacyProbeOptInLiveTests.cs b/Darling/Darling.Tests/QueryStoreLegacyProbeOptInLiveTests.cs index b36e58e07c..859b89bf46 100644 --- a/Darling/Darling.Tests/QueryStoreLegacyProbeOptInLiveTests.cs +++ b/Darling/Darling.Tests/QueryStoreLegacyProbeOptInLiveTests.cs @@ -177,6 +177,18 @@ await ExecAsync(connection, return new Rig { Scratch = scratch, Connection = connection, Postgres = postgres, End = end }; } + /// + /// The end of a read window that is a literal end: max(applied_through, rig.End). The gate refuses a literal end before + /// the server's applied_through, and the seed's writes can stamp it past on a slow runner (#6479). + /// + private static async Task QueryEndAsync(Rig rig, CancellationToken ct) + { + var appliedThrough = (DateTime)(await new NpgsqlCommand( + "SELECT applied_through FROM collect.query_store_interval_wide_coverage WHERE server_id = " + ServerId.ToString(CultureInfo.InvariantCulture), rig.Connection) + .ExecuteScalarAsync(ct))!; + return appliedThrough > rig.End ? appliedThrough : rig.End; + } + private static async Task HasLegacyRowAsync(NpgsqlConnection connection, DateTime start, DateTime end) { await using var command = new NpgsqlCommand(QueryStoreIntervalWide.HasLegacyRowSql, connection); @@ -309,7 +321,10 @@ public async Task TheComposeGate_KeepsAServerWithLegacyRowsOnTheTable() var ct = TestContext.Current.CancellationToken; await using var rig = await SeedAsync(ct); - var got = await DarlingWebEndpoints.ResolveQueryStoreWideEligibleAsync(rig.Postgres, null, rig.End.AddDays(-6), rig.End, rig.End, ct); + /* The literal end must not fall before the server's applied_through (#6479): the seed stamps it from the clock at write + time, which on a slow runner is past rig.End, and the gate answers that with "not eligible", not an error. */ + var queryEnd = await QueryEndAsync(rig, ct); + var got = await DarlingWebEndpoints.ResolveQueryStoreWideEligibleAsync(rig.Postgres, null, rig.End.AddDays(-6), queryEnd, queryEnd, ct); Assert.True(got.Eligible); Assert.Null(got.RawServerIds); } @@ -323,10 +338,7 @@ public async Task TheMcpTopRead_ReadsTheTable_WithLegacyRowsInTheWindow_AndEqual { var ct = TestContext.Current.CancellationToken; await using var rig = await SeedAsync(ct); - var appliedThrough = (DateTime)(await new NpgsqlCommand( - "SELECT applied_through FROM collect.query_store_interval_wide_coverage WHERE server_id = " + ServerId.ToString(CultureInfo.InvariantCulture), rig.Connection) - .ExecuteScalarAsync(ct))!; - var queryEnd = appliedThrough > rig.End ? appliedThrough : rig.End; + var queryEnd = await QueryEndAsync(rig, ct); var start = rig.End.AddDays(-6); const int top = 50; From 6120747533d95ce8ab25141dd691cb0695ef3cf6 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:48:09 -0400 Subject: [PATCH 005/294] WPF smoke: report on every pull request through a result job so it can be a required check (#6492) (#6494) --- .github/workflows/wpf-smoke.yml | 101 ++++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 13 deletions(-) diff --git a/.github/workflows/wpf-smoke.yml b/.github/workflows/wpf-smoke.yml index ccf18962a5..e6b981d296 100644 --- a/.github/workflows/wpf-smoke.yml +++ b/.github/workflows/wpf-smoke.yml @@ -9,22 +9,20 @@ name: WPF smoke # is taken before anything of ours runs (the probe: proof that the runner gives an interactive desktop), and again when each # app's main window shows, after each walk, and on any failure. No screenshots are compared. # -# Triggers: a pull request touching Lite, the Darling viewer or its storage, the harness or this workflow (a draft pull request is skipped until it is -# marked ready), the nightly (workflow_call), and a manual dispatch. `pull_request`, never `pull_request_target`: the job +# Triggers: every pull request, the nightly (workflow_call), and a manual dispatch. `pull_request`, never `pull_request_target`: the job # runs the pull request's own code, so it runs with the pull request's read-only token and no secrets. # -# Not a required check. A workflow that is skipped by its path filter never reports, so it cannot be one; the job name is -# left free of the names build.yml's ruleset uses. +# Built to be a required check (#6492). The workflow has no `paths:` filter, because a workflow its path filter skips never +# reports, and a required check that never reports blocks the merge. Instead: +# * `changes` works out, on every event, whether the smoke is needed: a non-draft pull request that changes Lite, the Darling +# viewer or its storage, the harness, the seed or this workflow (the list the old filter held), or any event that is not a +# pull request (the nightly, a dispatch). A draft pull request is skipped until it is marked ready. +# * `smoke` runs only when `changes` says so. +# * `WPF smoke (result)` always runs and is the one check to require: success when the smoke passed or was not needed, failure +# when the smoke failed, was cancelled, or `changes` itself failed. on: pull_request: types: [opened, synchronize, reopened, ready_for_review] - paths: - - 'Lite/**' - - 'Darling/**' - - 'tools/ui-smoke-wpf/**' - - 'tools/ui-smoke/**' - - 'Lite.Tests/TestDataSeeder.cs' - - '.github/workflows/wpf-smoke.yml' # The nightly runs it as a reusable workflow (nightly.yml, outside publish's needs). workflow_call: workflow_dispatch: @@ -37,10 +35,55 @@ concurrency: cancel-in-progress: true jobs: + changes: + name: WPF smoke (is it needed) + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + run: ${{ steps.needed.outputs.run }} + steps: + # The pull request's merge commit: its first parent is the base branch tip, so `HEAD^1..HEAD` is exactly what the pull + # request changes. Two commits is all the diff needs. Only a non-draft pull request needs the checkout. + - uses: actions/checkout@v7 + if: github.event_name == 'pull_request' && github.event.pull_request.draft == false + with: + fetch-depth: 2 + + - name: Work out whether the smoke is needed + id: needed + shell: bash + env: + EVENT_NAME: ${{ github.event_name }} + IS_DRAFT: ${{ github.event.pull_request.draft }} + run: | + if [ "$EVENT_NAME" != "pull_request" ]; then + echo "run=true" >> "$GITHUB_OUTPUT" + echo "Not a pull request ($EVENT_NAME): the smoke runs." + exit 0 + fi + if [ "$IS_DRAFT" = "true" ]; then + echo "run=false" >> "$GITHUB_OUTPUT" + echo "Draft pull request: the smoke is skipped until it is marked ready." + exit 0 + fi + # The paths the smoke exercises (the list the old `paths:` filter held). + pattern='^(Lite/|Darling/|tools/ui-smoke-wpf/|tools/ui-smoke/|Lite\.Tests/TestDataSeeder\.cs$|\.github/workflows/wpf-smoke\.yml$)' + files=$(git diff --name-only HEAD^1 HEAD) + echo "Changed files: $(printf '%s\n' "$files" | grep -c .)" + matched=$(printf '%s\n' "$files" | grep -E "$pattern" || true) + if [ -n "$matched" ]; then + echo "run=true" >> "$GITHUB_OUTPUT" + echo "The pull request changes smoke paths, the smoke runs. First matches:" + printf '%s\n' "$matched" | head -5 + else + echo "run=false" >> "$GITHUB_OUTPUT" + echo "The pull request changes none of the smoke paths: the smoke is not needed." + fi + smoke: name: WPF smoke (Lite and the Darling viewer) - # Skip a draft pull request; a dispatch has no pull request and always runs. - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + needs: changes + if: needs.changes.outputs.run == 'true' runs-on: windows-latest # Expected 4 to 6 minutes warm (restore and builds of Lite, the service and the viewer 3, PostgreSQL and the store migration 1, # the two walks under 1); 3 more on a cold pg-runtime cache. @@ -206,3 +249,35 @@ jobs: run: | $bin = "$env:GITHUB_WORKSPACE\Darling\artifacts\pg-runtime\pgsql\bin" if (Test-Path "$bin\pg_ctl.exe") { & "$bin\pg_ctl.exe" -D "$env:RUNNER_TEMP\darling-pgdata" -m fast stop } + + # The one check to require. Always runs, so a pull request the smoke does not apply to (no smoke paths changed, or a draft) + # still reports success; a failed, cancelled or never-started smoke reports failure. + result: + name: WPF smoke (result) + needs: [changes, smoke] + if: ${{ always() }} + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Report + shell: bash + env: + CHANGES_RESULT: ${{ needs.changes.result }} + RUN_NEEDED: ${{ needs.changes.outputs.run }} + SMOKE_RESULT: ${{ needs.smoke.result }} + run: | + echo "changes: $CHANGES_RESULT (smoke needed: ${RUN_NEEDED:-unknown}); smoke: $SMOKE_RESULT" + if [ "$CHANGES_RESULT" != "success" ]; then + echo "::error::Could not work out whether the smoke is needed ($CHANGES_RESULT)." + exit 1 + fi + if [ "$RUN_NEEDED" != "true" ]; then + echo "The smoke was not needed (no smoke paths changed, or a draft pull request): success." + exit 0 + fi + if [ "$SMOKE_RESULT" = "success" ]; then + echo "The smoke passed." + exit 0 + fi + echo "::error::The WPF smoke did not pass ($SMOKE_RESULT)." + exit 1 From a24e4d974c4e641a8a6fb5f1a045fb3726f1f621 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:12:15 -0400 Subject: [PATCH 006/294] Revert "draft PRs report success" (#6496): a draft run's green checks let auto-merge merge before the real run (#6502) This reverts commit 440b70279. GuardStageWorkflowTests fails on the reverted change, and a draft run's success results satisfied the required checks when the PR was marked ready, so auto-merge merged #6496 before its real run finished. Refs #6495. --- .github/scripts/ci-failure-split.py | 4 +- .github/workflows/build.yml | 158 +++++++----------- .../Darling.Tests/GuardStageWorkflowTests.cs | 2 +- Lite.Tests/CrossAppGuardCiGateTests.cs | 30 ++-- 4 files changed, 79 insertions(+), 115 deletions(-) diff --git a/.github/scripts/ci-failure-split.py b/.github/scripts/ci-failure-split.py index a78591d072..76521fc52a 100644 --- a/.github/scripts/ci-failure-split.py +++ b/.github/scripts/ci-failure-split.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """Split recent failed Build runs into the deliberate "CI not run" marker and real failures (#5943). -A pull request whose CI is declined by the merge-train label still runs one job that fails on purpose -with the annotation title "CI not run" (build.yml, "Report when CI did not run"), so the pull request cannot merge +A pull request whose CI is declined (a draft, or the merge-train label) still runs one job that fails on purpose +with the annotation title "CI not run" (build.yml, "Fail when CI did not run"), so the pull request cannot merge without an admin override. Counted as an ordinary failure it made up 147 of 200 recent failed runs, and the real failure rate looked far worse than it was. This script counts that marker apart: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc4c544b14..26b9e2a420 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,17 +74,12 @@ jobs: # - any other pull request: yes. # # A skipped job reports as skipped, and GitHub counts skipped as passing for a required check. A run - # the gate declined for a MERGE-TRAIN LABEL therefore must not read as green, so three jobs turn it - # into a FAILURE on a pull request: `build` (its first step), `Darling PostgreSQL tests` and `Lite - # tests (result)`. Those are the required checks, and each keeps its own name. The failure is the - # intended outcome: a merge-train member shows red until an admin merges it after the train covered - # it. Branch protection does not bind admins, so `gh pr merge --admin` still works. - # - # A DRAFT pull request is different: GitHub does not merge a draft whatever its checks say, and - # marking it ready starts a fresh run (`ready_for_review`), so a red check there only taught people - # to ignore red (1,037 of 1,294 failed Build runs in 14 days were drafts). The same three jobs report - # SUCCESS with a notice instead. The `declined` output tells the two causes apart; the label wins - # when a draft carries it, because that member must still fail. + # the gate declined therefore must not read as green, so three jobs turn it into a FAILURE on a pull + # request: `build` (its first step), `Darling PostgreSQL tests` and `Lite tests (result)`. Those are the + # required checks, and each keeps its own name. The failure is the intended outcome: a draft or + # merge-train pull request shows red until it is marked ready (or, for a merge-train member, until an + # admin merges it after the train covered it). Branch protection does not bind admins, so + # `gh pr merge --admin` still works. gate: name: Decide whether CI runs runs-on: ubuntu-latest @@ -96,7 +91,6 @@ jobs: contents: read outputs: run: ${{ steps.decide.outputs.run }} - declined: ${{ steps.decide.outputs.declined }} lite_timing_run: ${{ steps.timing.outputs.run_id }} lite_timing_artifacts: ${{ steps.timing.outputs.artifacts }} test_map_run: ${{ steps.testmap.outputs.run_id }} @@ -113,21 +107,19 @@ jobs: run: | set -euo pipefail - declined="" if [ "${EVENT_NAME}" != "pull_request" ]; then run=true; why="a ${EVENT_NAME} event always runs." elif [[ "${HEAD_REF}" == train/* ]]; then run=true; why="a merge-train pull request exists to run CI." elif [ "${HAS_MERGE_TRAIN_LABEL}" = "true" ]; then - run=false; declined=merge-train; why="the pull request carries the merge-train label, so its train run already covered it." + run=false; why="the pull request carries the merge-train label, so its train run already covered it." elif [ "${IS_DRAFT}" = "true" ]; then - run=false; declined=draft; why="the pull request is a draft. Marking it ready for review starts the run." + run=false; why="the pull request is a draft. Marking it ready for review starts the run." else run=true; why="a pull request that is ready for review runs." fi echo "run=${run}" >> "$GITHUB_OUTPUT" - echo "declined=${declined}" >> "$GITHUB_OUTPUT" if [ "${run}" = "true" ]; then echo "::notice title=CI runs::${why}" else @@ -852,9 +844,8 @@ jobs: # runs, whatever that job did (`!cancelled()` below), and runs everything when there is no usable selection. needs: [gate, test-map-select] # `build` is a required check, so it has to run to report anything but "skipped" (which counts as - # passing). When the gate declines the run the job still starts, on a cheap Linux runner. Its first - # step fails for a merge-train label and passes for a draft; every later step carries the gate's - # `run == 'true'` in its own `if`, so a declined run does nothing else either way. + # passing). When the gate declines the run the job still starts, on a cheap Linux runner, and its + # first step fails; no later step has an `always()`/`failure()` condition, so the rest are skipped. if: ${{ !cancelled() }} # #5949: `build` no longer waits for the Guard stage, so it cannot read the guard's result. A guard that fails on # a pull request cancels the run (guard-cancel), and the two aggregate result jobs carry the guard's failure. @@ -875,30 +866,24 @@ jobs: docs-fastpath: ${{ steps.fastpath.outputs.engaged }} steps: - - name: Report when CI did not run + - name: Fail when CI did not run if: ${{ needs.gate.outputs.run != 'true' }} shell: bash env: GATE_RESULT: ${{ needs.gate.result }} - DECLINED: ${{ needs.gate.outputs.declined }} run: | if [ "${GATE_RESULT}" != "success" ]; then echo "::error title=CI gate failed::needs.gate.result='${GATE_RESULT}' - the job that decides whether CI runs did not succeed, so nothing ran. Re-run the workflow." exit 1 fi - if [ "${DECLINED}" = "draft" ]; then - echo "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review." - exit 0 - fi - echo "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped (the train's own run covered it). It can be merged only by an admin override. (gate result: ${GATE_RESULT})" + echo "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). It can be merged only by an admin override after a merge train covered it. (gate result: ${GATE_RESULT})" exit 1 - uses: actions/checkout@v7 - if: needs.gate.outputs.run == 'true' - name: Detect changed paths id: filter - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name != 'release') }} + if: github.event_name != 'release' uses: dorny/paths-filter@v4 with: # On push events, compare against the previous commit on this branch @@ -1147,7 +1132,6 @@ jobs: # and vetoes the fast path via the areas guard above), so nothing this restore # validates could have moved since the push that last validated it. - name: Classify change for the docs fast path - if: needs.gate.outputs.run == 'true' id: fastpath shell: bash env: @@ -1182,12 +1166,12 @@ jobs: # as success, so the gate would fail open. It runs on every change the docs fast path does not # engage for (about two seconds), so a docs-only change stays fast. - name: Parse and link every wwwroot/js module - if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} + if: steps.fastpath.outputs.engaged != 'true' shell: bash run: bash .github/scripts/check-web-js.sh - name: Setup .NET 10.0 - if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} + if: steps.fastpath.outputs.engaged != 'true' uses: actions/setup-dotnet@v6 with: global-json-file: global.json @@ -1224,7 +1208,7 @@ jobs: # makes this restore mandatory and a second project taking an SDK-coupled reference fails rather than # joining the exemption quietly. - name: Restore dependencies - if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} + if: steps.fastpath.outputs.engaged != 'true' shell: bash run: | set -euo pipefail @@ -1246,11 +1230,11 @@ jobs: dotnet restore tools/ui-smoke-wpf/UiSmokeWpf.csproj --locked-mode - name: Build Lite.Tests - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet build Lite.Tests/Lite.Tests.csproj -c Release --no-restore - name: Build Installer.Tests - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet build deprecated/Installer.Tests/Installer.Tests.csproj -c Release --no-restore # The 'dashboard' path filter was defined when the Full Dashboard moved to deprecated/ (#1612) but @@ -1261,11 +1245,11 @@ jobs: # installer_core too: the Dashboard references Installer.Core, and the filter's own comment says a # change there rebuilds both products, which only held for the CLI Installer until now. - name: Build Dashboard.Tests - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet build deprecated/Dashboard.Tests/Dashboard.Tests.csproj -c Release --no-restore - name: Build Darling - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: | dotnet build Darling/Darling.Tests/Darling.Tests.csproj -c Release --no-restore dotnet build Darling/PerformanceMonitor.Darling.Viewer/PerformanceMonitor.Darling.Viewer.csproj -c Release --no-restore @@ -1285,17 +1269,17 @@ jobs: # to be maintained. Releases keep this single unsharded # pass so the artifact-producing run still executes the suite whole, in one log. - name: Run Lite tests - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' run: dotnet run --project Lite.Tests/Lite.Tests.csproj -c Release --no-build -- -xml TestResults/lite-timing-release.xml # #5208: per-test timings of the unsharded release pass, same shape as the lite-tests shards. - name: Lite test timing summary - if: ${{ needs.gate.outputs.run == 'true' && (always() && github.event_name == 'release') }} + if: always() && github.event_name == 'release' continue-on-error: true run: python .github/scripts/lite-timing-top.py TestResults - name: Upload Lite test timings - if: ${{ needs.gate.outputs.run == 'true' && (always() && github.event_name == 'release') }} + if: always() && github.event_name == 'release' continue-on-error: true uses: actions/upload-artifact@v6 with: @@ -1307,11 +1291,11 @@ jobs: if-no-files-found: ignore - name: Run Installer tests - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.installer == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet run --project deprecated/Installer.Tests/Installer.Tests.csproj -c Release --no-build -- -class- "Installer.Tests.VersionDetectionTests" -class- "Installer.Tests.IdempotencyTests" -class- "Installer.Tests.AdversarialTests" - name: Run Dashboard tests - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.dashboard == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.installer_core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet run --project deprecated/Dashboard.Tests/Dashboard.Tests.csproj -c Release --no-build # #5459 cut 3b: the PostgreSQL shards run EVERY Darling.Tests class, with a live store, whenever the Darling @@ -1321,7 +1305,7 @@ jobs: # .github/scripts/ci-select.py holds the rule (darling_scope); the replay of the failure corpus checks it. - name: Detect the Darling PostgreSQL gate id: darling-gate - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name != 'release' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true')) }} + if: github.event_name != 'release' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true') uses: dorny/paths-filter@v4 with: base: ${{ github.event_name == 'push' && github.event.before || '' }} @@ -1329,7 +1313,7 @@ jobs: - name: Decide the Darling test scope id: darling-scope - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' shell: bash env: EVENT_NAME: ${{ github.event_name }} @@ -1346,7 +1330,7 @@ jobs: # failed download) leaves TEST_MAP_SELECTION empty in the test step below, and an empty one means every class runs. - name: Download the test map selection id: map-selection - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'pull_request' && needs.test-map-select.result == 'success') }} + if: github.event_name == 'pull_request' && needs.test-map-select.result == 'success' continue-on-error: true uses: actions/download-artifact@v6 with: @@ -1355,7 +1339,7 @@ jobs: - name: Run Darling tests id: darling-tests - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' env: DARLING_SCOPE_FILTER: ${{ steps.darling-scope.outputs.filter }} DARLING_SCOPE: ${{ steps.darling-scope.outputs.scope }} @@ -1426,7 +1410,7 @@ jobs: # variable. Darling.Tests is already built (Release) by the build step above, so this runs # the one test by name and nothing else. - name: Statement filter release gate - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' env: DARLING_RELEASE_CUT: '1' shell: pwsh @@ -1441,7 +1425,7 @@ jobs: } - name: Get version - if: ${{ needs.gate.outputs.run == 'true' && (steps.fastpath.outputs.engaged != 'true') }} + if: steps.fastpath.outputs.engaged != 'true' id: version shell: pwsh run: | @@ -1468,23 +1452,23 @@ jobs: # Lite/PerformanceMonitorLite.csproj declares RuntimeIdentifiers so the committed lock # file covers this RID; see the comment there before removing either half. - name: Publish Lite - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.lite == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet publish Lite/PerformanceMonitorLite.csproj -c Release -r win-x64 --self-contained -o publish/Lite - name: Publish Lite (self-contained for Velopack) - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' run: dotnet publish Lite/PerformanceMonitorLite.csproj -c Release -r win-x64 --self-contained -o publish/Lite-velopack - name: Publish Darling Service - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet publish Darling/PerformanceMonitor.Darling.Service/PerformanceMonitor.Darling.Service.csproj -c Release -o publish/DarlingService - name: Publish Darling Viewer - if: ${{ needs.gate.outputs.run == 'true' && (steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release') }} + if: steps.filter.outputs.darling == 'true' || steps.filter.outputs.core == 'true' || steps.filter.outputs.root == 'true' || github.event_name == 'release' run: dotnet publish Darling/PerformanceMonitor.Darling.Viewer/PerformanceMonitor.Darling.Viewer.csproj -c Release -o publish/DarlingViewer - name: Publish Darling Viewer (self-contained for Velopack) - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' run: dotnet publish Darling/PerformanceMonitor.Darling.Viewer/PerformanceMonitor.Darling.Viewer.csproj -c Release -r win-x64 --self-contained -o publish/DarlingViewer-velopack # Darling bundles a PostgreSQL 18 + TimescaleDB runtime (pg-runtime.zip) that ships beside @@ -1494,7 +1478,7 @@ jobs: # unchanged pins restores the assembled zip and skips both the download and the assembly, # and any pin/version bump edits the script and invalidates the cache automatically. - name: Cache Darling pg-runtime.zip - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' id: cache-pg-runtime uses: actions/cache@v6 with: @@ -1502,12 +1486,12 @@ jobs: key: pg-runtime-${{ runner.os }}-${{ hashFiles('Darling/tools/fetch-pg-runtime.ps1') }} - name: Build Darling pg-runtime.zip - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release' && steps.cache-pg-runtime.outputs.cache-hit != 'true') }} + if: github.event_name == 'release' && steps.cache-pg-runtime.outputs.cache-hit != 'true' shell: pwsh run: ./Darling/tools/fetch-pg-runtime.ps1 - name: Package release artifacts - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | $version = "${{ steps.version.outputs.VERSION }}" @@ -1523,7 +1507,7 @@ jobs: # bump surfaces at release time — bump only alongside a validated real signing run. # Dependabot is configured to skip this major (see .github/dependabot.yml). - name: Upload Lite for signing - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' id: upload-lite uses: actions/upload-artifact@v6 with: @@ -1531,7 +1515,7 @@ jobs: path: publish/Lite/ - name: Stage Darling for signing - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | $stage = 'publish/Darling-signing' @@ -1541,7 +1525,7 @@ jobs: Copy-Item 'publish/DarlingViewer/*' "$stage/viewer" -Recurse - name: Upload Darling for signing - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' id: upload-darling uses: actions/upload-artifact@v6 with: @@ -1555,7 +1539,7 @@ jobs: # since 2026-09-24. SignPath signs only a run's first 3 attempts: if signing keeps # failing, fix the cause and start a fresh release run instead of re-running this one. - name: Sign Lite - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1568,7 +1552,7 @@ jobs: output-artifact-directory: 'signed/Lite' - name: Sign Darling - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1581,7 +1565,7 @@ jobs: output-artifact-directory: 'signed/Darling' - name: Replace with signed artifacts - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | $version = "${{ steps.version.outputs.VERSION }}" @@ -1590,7 +1574,7 @@ jobs: Compress-Archive -Path 'signed/Lite/*' -DestinationPath "releases/PerformanceMonitorLite-$version.zip" -Force - name: Package Darling (signed) - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | $version = "${{ steps.version.outputs.VERSION }}" @@ -1611,7 +1595,7 @@ jobs: # signature on lib/app/.exe inside each .nupkg and on current/.exe inside each # Portable.zip; `vpk pack` below reads the signed output, not the raw publish directory. - name: Upload Lite (Velopack) for signing - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' id: upload-lite-velopack uses: actions/upload-artifact@v6 with: @@ -1619,7 +1603,7 @@ jobs: path: publish/Lite-velopack/ - name: Upload Darling Viewer (Velopack) for signing - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' id: upload-darlingviewer-velopack uses: actions/upload-artifact@v6 with: @@ -1627,7 +1611,7 @@ jobs: path: publish/DarlingViewer-velopack/ - name: Sign Lite (Velopack) - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1645,7 +1629,7 @@ jobs: # workflow lives outside the repo on signpath.io, and a step naming a slug that does not # exist fails the release — the standing #1340 SignPath prerequisite. - name: Sign Darling Viewer (Velopack) - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1658,7 +1642,7 @@ jobs: output-artifact-directory: 'signed/DarlingViewer-Velopack' - name: Create Velopack releases (Lite + Darling Viewer) - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -1703,13 +1687,13 @@ jobs: # carries. The staging layout gives each product its own subdirectory because both # portable archives contain an Update.exe and a flat batch would collide. - name: Collect the executables Velopack generates - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | python3 .github/scripts/postpack_signing.py collect --stage postpack/unsigned --manifest postpack/manifest.json --product lite=releases/velopack-lite --product darlingviewer=releases/velopack-darlingviewer - name: Upload the Velopack-generated executables for signing - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' id: upload-postpack uses: actions/upload-artifact@v6 with: @@ -1722,7 +1706,7 @@ jobs: # the per-product configurations refuse with min-matches="1"; postpack_signing.py's # collect mode asserts a non-empty staging set for exactly that reason. - name: Sign the executables Velopack generates - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' uses: signpath/github-action-submit-signing-request@v3 with: api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' @@ -1738,7 +1722,7 @@ jobs: # it does not replace keeps its local header, name, extra field and raw compressed bytes, # and the rebuild is verified against a snapshot of the original before it replaces it. - name: Write the signed Velopack executables back - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | python3 .github/scripts/postpack_signing.py apply --signed postpack/signed --manifest postpack/manifest.json @@ -1749,7 +1733,7 @@ jobs: # here. releases..json is the integrity record for the .nupkg files, and nothing # publishes a checksum for the two files the step above signs. - name: Generate checksums - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | $checksums = Get-ChildItem releases/*.zip | ForEach-Object { @@ -1781,7 +1765,7 @@ jobs: # Darling zip must be there, and it must hold install-, uninstall- and upgrade-darling.ps1 at its # root (status 2 when one is missing, when there is no Darling zip, or when a file cannot be read). - name: Assert every published executable is signed - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: python3 .github/scripts/verify_release_signatures.py --verify-dir releases @@ -1791,7 +1775,7 @@ jobs: # SignPath Foundation certificate the release is signed with. Anything else, or a script that is not there, # fails the release. Each script's signer, thumbprint and timestamper are printed for the log. - name: Assert the Darling scripts carry a valid Authenticode signature - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh run: | $ErrorActionPreference = 'Stop' @@ -1839,14 +1823,14 @@ jobs: } - name: Upload release assets - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release upload ${{ github.event.release.tag_name }} releases/*.zip releases/SHA256SUMS.txt --clobber - name: Upload Lite Velopack artifacts - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -1866,7 +1850,7 @@ jobs: gh release upload "${{ github.event.release.tag_name }}" $files --clobber - name: Upload Darling Viewer Velopack artifacts - if: ${{ needs.gate.outputs.run == 'true' && (github.event_name == 'release') }} + if: github.event_name == 'release' shell: pwsh env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -2519,7 +2503,6 @@ jobs: LINT_RESULT: ${{ needs.workflow-lint.result }} GATE_RESULT: ${{ needs.gate.result }} GATE_RUN: ${{ needs.gate.outputs.run }} - DECLINED: ${{ needs.gate.outputs.declined }} EVENT_NAME: ${{ github.event_name }} run: | set -euo pipefail @@ -2528,14 +2511,9 @@ jobs: echo "::error title=CI gate failed::needs.gate.result='${GATE_RESULT}' - the job that decides whether CI runs did not succeed, so nothing ran. Re-run the workflow." exit 1 fi - # A declined run leaves every job skipped, which would also read as green. A draft reports success - # with a notice (marking it ready starts the run); a merge-train label must still fail. + # A declined run (draft or merge-train) leaves every job skipped, which would also read as green. if [ "${EVENT_NAME}" = "pull_request" ] && [ "${GATE_RUN}" != "true" ]; then - if [ "${DECLINED}" = "draft" ]; then - echo "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review." - exit 0 - fi - echo "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped (the train's own run covered it). It can be merged only by an admin override." + echo "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). It can be merged only by an admin override after a merge train covered it." exit 1 fi # The Guard tests run beside the shards on a pull request (#5949; first, before that). When they did not @@ -3656,7 +3634,6 @@ jobs: LINT_RESULT: ${{ needs.workflow-lint.result }} GATE_RESULT: ${{ needs.gate.result }} GATE_RUN: ${{ needs.gate.outputs.run }} - DECLINED: ${{ needs.gate.outputs.declined }} EVENT_NAME: ${{ github.event_name }} LITE_SCOPE_MODE: ${{ needs.lite-scope.outputs.mode }} run: | @@ -3666,14 +3643,9 @@ jobs: echo "::error title=CI gate failed::needs.gate.result='${GATE_RESULT}' - the job that decides whether CI runs did not succeed, so nothing ran. Re-run the workflow." exit 1 fi - # A declined run leaves every job skipped, which would also read as green. A draft reports success - # with a notice (marking it ready starts the run); a merge-train label must still fail. + # A declined run (draft or merge-train) leaves every job skipped, which would also read as green. if [ "${EVENT_NAME}" = "pull_request" ] && [ "${GATE_RUN}" != "true" ]; then - if [ "${DECLINED}" = "draft" ]; then - echo "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review." - exit 0 - fi - echo "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped (the train's own run covered it). It can be merged only by an admin override." + echo "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). It can be merged only by an admin override after a merge train covered it." exit 1 fi # The Guard tests run beside the shards on a pull request (#5949; first, before that). When they did not diff --git a/Darling/Darling.Tests/GuardStageWorkflowTests.cs b/Darling/Darling.Tests/GuardStageWorkflowTests.cs index 09da3d1787..cc3c5a611a 100644 --- a/Darling/Darling.Tests/GuardStageWorkflowTests.cs +++ b/Darling/Darling.Tests/GuardStageWorkflowTests.cs @@ -481,7 +481,7 @@ public void TheBuildJob_DoesNotWaitForTheGuardStage() .Take(2) .ToList(); - Assert.StartsWith("name: Report when CI did not run", steps[0], StringComparison.Ordinal); + Assert.StartsWith("name: Fail when CI did not run", steps[0], StringComparison.Ordinal); Assert.StartsWith("uses: actions/checkout@v7", steps[1], StringComparison.Ordinal); } diff --git a/Lite.Tests/CrossAppGuardCiGateTests.cs b/Lite.Tests/CrossAppGuardCiGateTests.cs index 4ba0e22b76..06be4728cc 100644 --- a/Lite.Tests/CrossAppGuardCiGateTests.cs +++ b/Lite.Tests/CrossAppGuardCiGateTests.cs @@ -3011,48 +3011,40 @@ private static int DaysFrom(string text, string pattern, string whatIsGone) } /// - /// A pull request whose CI the gate declined must not read as passing when the cause is the merge-train label: - /// a skipped job counts as a pass for a required check, so build still starts and fails its first step, - /// and both result jobs exit 1 on a pull request whose gate output is not true. A DRAFT is the exception: it - /// reports success with a notice (marking it ready starts the run), so a draft does not teach people to ignore red. + /// A pull request whose CI the gate declined (a draft, or one carrying the merge-train label) must not + /// read as passing: a skipped job counts as a pass for a required check. build still starts and + /// fails its first step, and both result jobs exit 1 on a pull request whose gate output is not true. /// [Fact] - public void ADeclinedRun_FailsBuildAndBothResultJobsForTheMergeTrainLabel_AndPassesForADraft() + public void ADeclinedRun_FailsBuildAndBothResultJobs_InsteadOfReadingAsGreen() { var yaml = ReadBuildYaml(RepoRoot()); - const string labelError = - "::error title=CI not run::This pull request carries the merge-train label, so its CI was skipped " - + "(the train's own run covered it). It can be merged only by an admin override."; - const string draftNotice = - "::notice title=Draft PR::Draft PR: CI runs when the PR is marked ready for review."; + const string message = + "::error title=CI not run::This pull request's CI was skipped (draft or merge-train label). " + + "It can be merged only by an admin override after a merge train covered it."; foreach (var jobKey in new[] { "darling-pg-result", "lite-tests-result" }) { var job = JobBlock(yaml, jobKey); Assert.Contains("GATE_RUN: ${{ needs.gate.outputs.run }}", job, StringComparison.Ordinal); - Assert.Contains("DECLINED: ${{ needs.gate.outputs.declined }}", job, StringComparison.Ordinal); Assert.Contains("EVENT_NAME: ${{ github.event_name }}", job, StringComparison.Ordinal); Assert.Contains( "if [ \"${EVENT_NAME}\" = \"pull_request\" ] && [ \"${GATE_RUN}\" != \"true\" ]; then\n" - + " if [ \"${DECLINED}\" = \"draft\" ]; then\n" - + " echo \"" + draftNotice + "\"\n exit 0\n fi\n" - + " echo \"" + labelError + "\"\n exit 1\n fi\n", + + " echo \"" + message + "\"\n exit 1\n fi\n", job, StringComparison.Ordinal); Assert.Contains("needs: [gate, ", job, StringComparison.Ordinal); } /* `build` is a required check that would otherwise be merely skipped. It must start whatever the - gate said, and its first step must fail when the gate declined the run for the label. */ + gate said, and its first step must fail when the gate declined the run. */ var build = JobBlock(yaml, "build"); Assert.Contains("\n if: ${{ !cancelled() }}\n", build, StringComparison.Ordinal); var first = build[build.IndexOf(" steps:\n", StringComparison.Ordinal)..]; first = first[..first.IndexOf("\n - uses: actions/checkout@v7", StringComparison.Ordinal)]; - Assert.Contains("- name: Report when CI did not run", first, StringComparison.Ordinal); + Assert.Contains("- name: Fail when CI did not run", first, StringComparison.Ordinal); Assert.Contains("if: ${{ needs.gate.outputs.run != 'true' }}", first, StringComparison.Ordinal); - Assert.Contains("if [ \"${DECLINED}\" = \"draft\" ]; then", first, StringComparison.Ordinal); - Assert.Contains(draftNotice, first, StringComparison.Ordinal); - Assert.Contains(labelError, first, StringComparison.Ordinal); + Assert.Contains(message, first, StringComparison.Ordinal); Assert.Contains("exit 1", first, StringComparison.Ordinal); } From 348a2def04b81ee16bbe2ff731eed7b07c313c15 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:52:45 -0400 Subject: [PATCH 007/294] Delete FinOps page and Optimization delegate source-text pins (#6486) (#6493) They read repo .js/.xaml/.cs text and assert strings; they guard no behaviour and broke 15 at once in run 37716703603. The three node --check facts stay as one theory. --- .github/scripts/darling-shard-weights.json | 16 - Darling/Darling.Tests/FinOpsPageShellTests.cs | 229 ---------- ...inOpsTabApplicationConnectionsPageTests.cs | 135 ------ .../FinOpsTabDatabaseResourcesPageTests.cs | 145 ------- .../FinOpsTabDatabaseSizesPageTests.cs | 95 ---- .../FinOpsTabHighImpactPageTests.cs | 95 ---- .../FinOpsTabIndexAnalysisPageTests.cs | 409 ------------------ .../FinOpsTabLockingPageTests.cs | 84 ---- .../FinOpsTabOptimizationPageTests.cs | 208 --------- .../Darling.Tests/FinOpsTabPvsPageTests.cs | 91 ---- .../FinOpsTabRecommendationsPageTests.cs | 177 -------- .../FinOpsTabServerInventoryPageTests.cs | 245 ----------- .../FinOpsTabStorageGrowthPageTests.cs | 269 ------------ .../FinOpsTabSystemEventsColumnsPageTests.cs | 130 ------ .../FinOpsTabUtilizationPageTests.cs | 188 -------- .../FinOpsTabUtilizationRawPageTests.cs | 142 ------ .../FinOpsTabsParseUnderNodeTests.cs | 65 +++ .../ViewerFinOpsOptimizationDelegatesTests.cs | 70 --- 18 files changed, 65 insertions(+), 2728 deletions(-) delete mode 100644 Darling/Darling.Tests/FinOpsPageShellTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabApplicationConnectionsPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabDatabaseResourcesPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabDatabaseSizesPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabHighImpactPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabIndexAnalysisPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabLockingPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabOptimizationPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabPvsPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabRecommendationsPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabServerInventoryPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabStorageGrowthPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabSystemEventsColumnsPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabUtilizationPageTests.cs delete mode 100644 Darling/Darling.Tests/FinOpsTabUtilizationRawPageTests.cs create mode 100644 Darling/Darling.Tests/FinOpsTabsParseUnderNodeTests.cs delete mode 100644 Darling/Darling.Tests/ViewerFinOpsOptimizationDelegatesTests.cs diff --git a/.github/scripts/darling-shard-weights.json b/.github/scripts/darling-shard-weights.json index 4414a061e0..d19b7f5765 100644 --- a/.github/scripts/darling-shard-weights.json +++ b/.github/scripts/darling-shard-weights.json @@ -845,7 +845,6 @@ "Darling.Tests.FinOpsOptimizationTieBreakTests": 0.56, "Darling.Tests.FinOpsOptimizationViewLiveTests": 7.72, "Darling.Tests.FinOpsOptimizationViewTests": 0, - "Darling.Tests.FinOpsPageShellTests": 0.02, "Darling.Tests.FinOpsPostgresTargetTests": 6.02, "Darling.Tests.FinOpsRecommendationFiguresTests": 0.01, "Darling.Tests.FinOpsRecommendationsCharacterizationTests": 0, @@ -859,20 +858,6 @@ "Darling.Tests.FinOpsStorageGrowthViewTests": 0.02, "Darling.Tests.FinOpsStorageGrowthWindowBehaviourTests": 1.71, "Darling.Tests.FinOpsSubTabIndexPinTests": 0, - "Darling.Tests.FinOpsTabApplicationConnectionsPageTests": 0, - "Darling.Tests.FinOpsTabDatabaseResourcesPageTests": 0, - "Darling.Tests.FinOpsTabDatabaseSizesPageTests": 0, - "Darling.Tests.FinOpsTabHighImpactPageTests": 0, - "Darling.Tests.FinOpsTabIndexAnalysisPageTests": 0.03, - "Darling.Tests.FinOpsTabLockingPageTests": 0, - "Darling.Tests.FinOpsTabOptimizationPageTests": 0, - "Darling.Tests.FinOpsTabPvsPageTests": 0, - "Darling.Tests.FinOpsTabRecommendationsPageTests": 0.02, - "Darling.Tests.FinOpsTabServerInventoryPageTests": 0.03, - "Darling.Tests.FinOpsTabStorageGrowthPageTests": 0.01, - "Darling.Tests.FinOpsTabSystemEventsColumnsPageTests": 0.01, - "Darling.Tests.FinOpsTabUtilizationPageTests": 0, - "Darling.Tests.FinOpsTabUtilizationRawPageTests": 0, "Darling.Tests.FinOpsTopAvgRankingTests": 0, "Darling.Tests.FinOpsTopConsumersMergeLiveTests": 0.15, "Darling.Tests.FinOpsUtilizationFiguresLiveTests": 0.85, @@ -2149,7 +2134,6 @@ "Darling.Tests.ViewerFinOpsIntervalHonestLiveTests": 0.2, "Darling.Tests.ViewerFinOpsIntervalHonestTests": 0, "Darling.Tests.ViewerFinOpsInventoryDelegatesTests": 0, - "Darling.Tests.ViewerFinOpsOptimizationDelegatesTests": 0, "Darling.Tests.ViewerFinOpsPickerRefreshPinTests": 0, "Darling.Tests.ViewerFinOpsRecommendationsDelegatesTests": 0, "Darling.Tests.ViewerFinOpsRecommendationsTests": 0, diff --git a/Darling/Darling.Tests/FinOpsPageShellTests.cs b/Darling/Darling.Tests/FinOpsPageShellTests.cs deleted file mode 100644 index 45eec38eb4..0000000000 --- a/Darling/Darling.Tests/FinOpsPageShellTests.cs +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// -/// Source pins for the web viewer's FinOps page shell (#4843): the nav entry, the hash route, the fixed -/// registry of twelve sub-tab modules in the desktop tab strip's order, the shape of each tab module, and the -/// rule that the browser derives no band, score or percentage threshold. The repository has no JavaScript test -/// runner, so these are text scans (the pattern). -/// -public sealed class FinOpsPageShellTests -{ - private static readonly string[] Wwwroot = - ["Darling", "PerformanceMonitor.Darling.Service", "wwwroot"]; - - /// The tab module ids in the order of FinOpsTab.xaml's sub-tab strip. - internal static readonly string[] TabIds = - [ - "utilization", "database-resources", "storage-growth", "locking", "database-sizes", "version-store", - "optimization", "high-impact", "application-connections", "server-inventory", "index-analysis", - "recommendations", - ]; - - /// The headers of FinOpsTab.xaml's sub-tabs, in order, paired with . - private static readonly string[] XamlHeaders = - [ - "Utilization", "Database Resources", "Storage Growth", "Locking & Contention", "Database Sizes", - "Version Store (PVS)", "Optimization", "High Impact", "Application Connections", "Server Inventory", - "Index Analysis", "Recommendations", - ]; - - private static string Js(params string[] rel) => - ReadRepoFileLf(Wwwroot.Concat(new[] { "js" }).Concat(rel).ToArray()); - - private static string TabFile(string id) => Js("pages", "finops", id + ".js"); - - [Fact] - public void RenderFinops_AFailedOrEmptyRereadOnAPollNeverMountsOverThePaintedTab() - { - var js = Js("pages", "finops.js").ReplaceLineEndings("\n"); - Assert.Contains(" const show = (node) => {\n /* A failed re-read on a poll says nothing about the painted page: keep it and the cache. */\n if (hadCache) return;\n lastRows = null;\n", js); - } - - [Fact] - public void IndexHtml_HasTheFinOpsNavEntry() - { - var html = ReadRepoFileLf(Wwwroot.Concat(new[] { "index.html" }).ToArray()); - Assert.Contains("FinOps", html); - } - - [Fact] - public void AppJs_ImportsRenderFinopsAndRoutesServerAndTab() - { - var app = Js("app.js"); - Assert.Contains("import { renderFinops } from \"./pages/finops.js\";", app); - Assert.Contains("h.startsWith(\"#/finops/\")", app); - var start = app.IndexOf("function finopsRoute(", StringComparison.Ordinal); - Assert.True(start >= 0, "finopsRoute must exist"); - var end = app.IndexOf("\n}\n", start, StringComparison.Ordinal); - var body = app.Substring(start, end - start); - Assert.Contains("name: \"finops\"", body); - Assert.Contains("param: safeDecode(rest.slice(0, slash))", body); - Assert.Contains("tab: safeDecode(rest.slice(slash + 1))", body); - Assert.DoesNotContain("decodeURIComponent(", body); - Assert.Contains("catch {", app.Substring(app.IndexOf("function safeDecode(", StringComparison.Ordinal), 120)); - Assert.Contains("renderFinops(main, r.param, r.tab, opts)", app); - } - - [Fact] - public void XamlOrder_MatchesTheRegistryOrder() - { - var xaml = ReadRepoFileLf("Darling", "PerformanceMonitor.Darling.Viewer", "FinOpsTab.xaml"); - var headers = Regex.Matches(xaml, "^\\s{16} m.Groups[1].Value).ToArray(); - Assert.Equal(XamlHeaders, headers); - } - - [Fact] - public void FinopsJs_ImportsAllTwelveTabsInXamlOrder_AndSetsThePanelSignal() - { - var src = Js("pages", "finops.js"); - var imported = Regex.Matches(src, "import \\{ tab as \\w+ \\} from \"\\./finops/([a-z-]+)\\.js\";") - .Select(m => m.Groups[1].Value).ToArray(); - Assert.Equal(TabIds, imported); - Assert.Contains("setPanelSignal(", src); - Assert.Contains("list_servers", src); - Assert.Contains("finops.server", src); - Assert.True(src.IndexOf("setPanelSignal(", StringComparison.Ordinal) < src.IndexOf(".build(", StringComparison.Ordinal), - "the panel signal must be set before a tab is built"); - } - - [Fact] - public void FinopsTabsArray_IsInXamlOrder_AndEachLabelMatchesItsXamlHeader() - { - var src = Js("pages", "finops.js"); - var m = Regex.Match(src, "FINOPS_TABS = \\[(?[^\\]]*)\\];"); - Assert.True(m.Success, "FINOPS_TABS array not found"); - var ids = m.Groups["ids"].Value.Split(',').Select(x => x.Trim()).Where(x => x.Length > 0).ToArray(); - Assert.Equal(TabIds.Select(i => i.Replace('-', '_')).ToArray(), ids); - for (var i = 0; i < TabIds.Length; i++) - Assert.Contains($"label: \"{WebUtility.HtmlDecode(XamlHeaders[i])}\",", TabFile(TabIds[i])); - } - - [Fact] - public void RenderFinops_ResolvesToTheRowKey_PollsOnlyOnOpts_AndOpensTheControllerBeforeAnyAwait() - { - var src = Js("pages", "finops.js"); - var start = src.IndexOf("export function renderFinops(", StringComparison.Ordinal); - var body = src.Substring(start); - Assert.Contains("rows.find((r) => r.display_name === wanted)", src); - // The row is kept (not just its name) because the tabs read the chosen row's engine for the PostgreSQL-target rules. - Assert.Contains("const row = resolveRow(rows, wanted);", body); - Assert.Contains("const chosen = row.server_name;", body); - Assert.DoesNotContain("known(", src); - Assert.Contains("opts.poll === true", body); - Assert.DoesNotContain("keepPainted", body); - var lines = body.ReplaceLineEndings("\n").Split('\n'); - var paintIdx = Array.FindIndex(lines, l => l.Trim() == "if (hit) paint(lastRows);"); - var fetchIdx = Array.FindIndex(lines, l => l.Contains("readTool(\"list_servers\"")); - Assert.True(paintIdx >= 0 && paintIdx < fetchIdx, "the cached paint must run before the list_servers read, on polls too (no !isPoll guard)"); - Assert.Contains("const hit = lastRows !== null && (!server || lastRows.some((r) => r.server_name === server || r.display_name === server));", body); - Assert.Contains("const hadCache = hit;", body); - Assert.Contains("const needFetch = !hit || isPoll;", body); - Assert.Contains("if (!needFetch) return;", body); - var ctrlIdx = Array.FindIndex(lines, l => l.Trim() == "let controller = panelAbort = new AbortController();"); - Assert.True(ctrlIdx > 0 && lines[ctrlIdx - 1].Trim() == "if (panelAbort) panelAbort.abort();", - "the previous render's controller must be aborted on the line right before the new one is created"); - Assert.True(ctrlIdx >= 0 && ctrlIdx < Array.FindIndex(lines, l => l.Contains("await ")), - "the controller must be created unconditionally before the first await"); - Assert.Contains("{ signal: controller.signal, postgres: isPostgresRow(row) }", body); - Assert.Contains("aria-current", src); - Assert.DoesNotContain("role: \"tab", src); - Assert.DoesNotContain("aria-selected", src); - /* An empty registry is a definite answer: the empty branch goes through showEmpty (#6277: the empty envelope, no longer prose read as an error), which is not behind the hadCache guard. */ - Assert.Contains("return showEmpty();", body); - Assert.Single(System.Text.RegularExpressions.Regex.Matches(body, @"return showEmpty\(\);")); - var emptyIdx = Array.FindIndex(lines, l => l.Trim() == "const showEmpty = () => {"); - var showIdx = Array.FindIndex(lines, l => l.Trim() == "const show = (node) => {"); - Assert.True(emptyIdx >= 0 && showIdx >= 0, "showEmpty and show must both exist"); - var emptyBlock = string.Join("\n", lines.Skip(emptyIdx).Take(5)); - Assert.DoesNotContain("hadCache", emptyBlock); - Assert.Contains("lastRows = null;", emptyBlock); - Assert.Contains("controller.abort();", emptyBlock); - } - - [Fact] - public void EveryTabFile_ExportsTabWithIdLabelBuild_AndTheIdIsTheFileName() - { - var onDisk = Directory.GetFiles( - Path.GetDirectoryName(PathTo(Wwwroot.Concat(new[] { "js", "pages", "finops", "utilization.js" }).ToArray()))!, - "*.js") - .Select(Path.GetFileNameWithoutExtension) - // database-box.js is the shared Database box the Index Analysis and Locking tabs import (#5231), not a tab. - // gate.js is the helper the tabs share for their empty and not-collected states on a PostgreSQL target, also not a tab. - // window.js is the rolling-only time range picker the windowed tabs share (#5562), also not a tab. - .Where(name => name != "database-box" && name != "gate" && name != "window") - .OrderBy(x => x, StringComparer.Ordinal).ToArray(); - Assert.Equal(TabIds.OrderBy(x => x, StringComparer.Ordinal).ToArray(), onDisk); - - foreach (var id in TabIds) - { - var src = TabFile(id); - Assert.Contains("export const tab = {", src); - Assert.Contains($"id: \"{id}\",", src); - Assert.Matches("label: \"[^\"]+\",", src); - Assert.Matches("build\\(server, ctx\\) \\{", src); - } - } - - [Fact] - public void FinOpsTabFiles_DeriveNoBandOrThresholdInTheBrowser() - { - var dir = Path.GetDirectoryName(PathTo(Wwwroot.Concat(new[] { "js", "pages", "finops", "utilization.js" }).ToArray()))!; - foreach (var file in Directory.GetFiles(dir, "*.js")) - { - var hits = BrowserDerivedThresholds(File.ReadAllText(file).ReplaceLineEndings("\n")); - Assert.True(hits.Count == 0, Path.GetFileName(file) + " compares a band, score or percent: " + string.Join(" | ", hits)); - } - } - - [Theory] - [InlineData("if (row.score > 50) {", true)] - [InlineData("x = pct >= 0.8 ? a : b;", true)] - [InlineData("if (10 < row.band_value)", true)] - [InlineData("if (row.avg_cpu_percent > 80) {", true)] - [InlineData("if (r.utilization_percent >= 90) {", true)] - [InlineData("if (row.cpu_ratio > 0.5) {", true)] - [InlineData("if (row.cpu_pct > CRIT) {", true)] - [InlineData("if (row.size_gb > MAX_SIZE) {", true)] - [InlineData("const heat = v > 0.8 ? 3 : 2;", true)] - [InlineData("const cls = v > 0.8 ? \"heat-3\" : \"heat-1\";", true)] - [InlineData("const label = row.band;", false)] - [InlineData("const n = rows.length > 0 ? 1 : 2;", false)] - [InlineData("score: row.score,", false)] - [InlineData("rows.map((r) => NUMBER_FMT.format(r.v));", false)] - public void ThresholdScanner_FlagsOnlyNumericComparisons(string line, bool flagged) - { - Assert.Equal(flagged, BrowserDerivedThresholds(line).Count > 0); - } - - /// - /// Lines that compare a number against a band, score or percent identifier. The browser never derives a - /// band: the read returns it. Reused by every FinOps tab's page test. - /// - internal static List BrowserDerivedThresholds(string source) - { - const string ident = "(band|score|pct|percent|ratio|util)"; - var after = new Regex("\\b\\w*" + ident + "\\w*\\b[\\w.\\[\\]()]*\\s*(<=|>=|<|>|===|!==|==|!=)\\s*-?\\d", RegexOptions.IgnoreCase); - var before = new Regex("-?\\d[\\d.]*\\s*(<=|>=|<|>|===|!==|==|!=)\\s*[\\w.\\[\\]()]*" + ident, RegexOptions.IgnoreCase); - var constant = new Regex("(<=|>=|<|(?)\\s*[A-Z][A-Z0-9_]{2,}\\b|\\b[A-Z][A-Z0-9_]{2,}\\s*(<=|>=|<|>)"); - var heatTernary = new Regex("(<=|>=|<|>)\\s*-?\\d[\\d.]*\\s*\\?[^:]*(heat|band)|heat\\w*\\s*=[^;]*(<=|>=|<|>)\\s*-?\\d", RegexOptions.IgnoreCase); - return source.Split('\n').Where(l => after.IsMatch(l) || before.IsMatch(l) || constant.IsMatch(l) || heatTernary.IsMatch(l)).Select(l => l.Trim()).ToList(); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabApplicationConnectionsPageTests.cs b/Darling/Darling.Tests/FinOpsTabApplicationConnectionsPageTests.cs deleted file mode 100644 index dc60b63ef3..0000000000 --- a/Darling/Darling.Tests/FinOpsTabApplicationConnectionsPageTests.cs +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Application Connections tab: it reads get_finops with view application_connections and shows only columns that read emits. -public sealed class FinOpsTabApplicationConnectionsPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "application-connections.js") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.ApplicationConnections.cs") - .ReplaceLineEndings("\n"); - - [Fact] - public void TheTabReadsGetFinOpsWithTheApplicationConnectionsViewWindow() - { - // Pins the exact read: the view refuses a non-default limit, so sending one would turn every load into a refusal. - const string call = "readTool(\"get_finops\", { server, view: \"application_connections\", hours: HOURS }, ctx && ctx.signal)"; - var tab = Tab(); - Assert.Contains(call, tab); - } - - [Fact] - public void TheTabHasNoWindowPickerAndSaysItIs24HoursLikeTheDesktopHeader() - { - var tab = Tab(); - Assert.Contains("el(\"h3\", { text: \"Application Connections (24h)\" })", tab); - Assert.DoesNotContain("= 0); - var end = source.IndexOf("\n };", start, System.StringComparison.Ordinal); - Assert.True(end > start); - return source.Substring(start, end - start); - } - - [Fact] - public void EveryShownColumnKeyIsEmittedByTheApplicationConnectionsRow() - { - var keys = Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - var row = RowSlice(); - foreach (var key in keys) - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", row); - var emitted = Regex.Matches(row, "(?m)^\\s+[a-z_]+ = ").Count; - Assert.Equal(20, emitted); - Assert.Equal(emitted, keys.Count); - } - - [Fact] - public void TheColumnsAreInTheDesktopGridOrder() - { - // Source of the order: the Application Connections grid in Darling/PerformanceMonitor.Darling.Viewer/FinOpsTab.xaml; this is that grid's column order. - var keys = Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value); - Assert.Equal( - "application_name,avg_connections,max_connections,avg_running,max_running,avg_sleeping,max_sleeping,avg_dormant,max_dormant,avg_cpu_time_ms,max_cpu_time_ms,avg_reads,max_reads,avg_writes,max_writes,avg_logical_reads,max_logical_reads,sample_count,first_seen_utc,last_seen_utc", - string.Join(",", keys)); - Assert.Contains("{ key: \"avg_cpu_time_ms\", label: \"Avg CPU\", format: \"ms\" }", Tab()); - Assert.Contains("{ key: \"max_cpu_time_ms\", label: \"Max CPU\", format: \"ms\" }", Tab()); - Assert.Contains("{ key: \"first_seen_utc\", label: \"First seen\", format: \"time\" }", Tab()); - Assert.Contains("{ key: \"last_seen_utc\", label: \"Last seen\", format: \"time\" }", Tab()); - } - - [Fact] - public void TheNoticeCountsTheRowsReturnedAndTakesTheWindowFromTheAnswer() - { - var tab = Tab(); - Assert.Contains("(data.rows || []).length", tab); - Assert.Contains("(n === 1 ? \"1 application\" : n + \" applications\") + \", last \" + (data.hours_back ?? HOURS) + \" hours\";", tab); - } - - [Fact] - public void TheTruncatedNoticeNamesTheShownCountThenTheTotal() - { - Assert.Contains( - "text += data.truncated ? \"; the top \" + n + \" of \" + (data.application_count ?? \"more\") + \" applications by peak connections.\" : \".\";", - Tab()); - } - - [Fact] - public void TheReadStatesAreHandledAbortedAndAuthReturnAndEmptyShowsItsMessage() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return mount\\(body, gatedEmptyStrip\\(res, ctx\\)\\);$", tab); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "./gate.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } - - [Fact] - public void TheErrorAndRenderFailureStatesAreHandled() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"error\"\\) return mount\\(body, readErrorStrip\\(res\\.message\\)\\);$", tab); - Assert.Contains("Could not render this tab: ", tab); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabDatabaseResourcesPageTests.cs b/Darling/Darling.Tests/FinOpsTabDatabaseResourcesPageTests.cs deleted file mode 100644 index 06b2fe1a43..0000000000 --- a/Darling/Darling.Tests/FinOpsTabDatabaseResourcesPageTests.cs +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Database Resources tab: it reads get_finops with view database_resources and shows only columns that read emits. -public sealed class FinOpsTabDatabaseResourcesPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "database-resources.js") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.DatabaseResources.cs") - .ReplaceLineEndings("\n"); - - [Fact] - public void TheTabReadsGetFinOpsWithTheDatabaseResourcesViewWindow() - { - // The exact call is a no-noise guard: a limit would only cap the top lists, which this tab does not show. - const string call = "readTool(\"get_finops\", { server, view: \"database_resources\", hours }, ctx && ctx.signal)"; - var tab = Tab(); - Assert.Contains(call, tab); - } - - [Fact] - public void ThePickerOffersTheDesktopWindowsInOrder() - { - // #5562 R5: the shared picker in its Compact, rolling-only form (finops/window.js), not a hand-listed select. - var tab = Tab(); - Assert.DoesNotContain("WINDOWS", tab); - Assert.Contains("finopsWindowControl({ hours: HOURS, onChange: (hours) => load(hours) })", tab); - } - - [Fact] - public void TheChangeHandlerRereadsWithTheChosenHoursAndTheFirstReadUsesTheDefault() - { - var tab = Tab(); - Assert.Contains("(hours) => load(hours)", tab); - Assert.Contains("load(HOURS);", tab); - } - - [Fact] - public void ThePickerUsesNoInnerHtml() - { - Assert.DoesNotContain("innerHTML", Tab()); - } - - [Fact] - public void TheWindowDefaultsTo24HoursAndThereIsNoLimitConstant() - { - var tab = Tab(); - Assert.Matches("(?m)^const HOURS = 24;$", tab); - Assert.DoesNotContain("LIMIT", tab); - } - - private static string RowSlice() - { - var source = ToolSource(); - var start = source.IndexOf("internal static object DatabaseResourcesRow(", System.StringComparison.Ordinal); - Assert.True(start >= 0); - var end = source.IndexOf("\n };", start, System.StringComparison.Ordinal); - Assert.True(end > start); - return source.Substring(start, end - start); - } - - [Fact] - public void EveryShownColumnKeyIsEmittedByTheDatabaseResourcesRow() - { - var keys = Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - var row = RowSlice(); - foreach (var key in keys) - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", row); - var emitted = Regex.Matches(row, "(?m)^\\s+[a-z_]+ = ").Count; - Assert.Equal(11, emitted); - Assert.Equal(emitted, keys.Count); - } - - [Fact] - public void TheColumnsAreInTheDesktopGridOrder() - { - var keys = Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value); - Assert.Equal( - "database_name,cpu_time_ms,cpu_share_pct,logical_reads,physical_reads,logical_writes,execution_count,io_read_mb,io_write_mb,io_share_pct,io_stall_ms", - string.Join(",", keys)); - Assert.Contains("{ key: \"io_stall_ms\", label: \"I/O stall\", format: \"ms\" }", Tab()); - } - - [Fact] - public void TheNoticeCountsTheRowsReturnedAndTakesTheWindowFromTheAnswer() - { - var tab = Tab(); - Assert.Contains("(data.rows || []).length", tab); - Assert.Contains("(n === 1 ? \"1 database\" : n + \" databases\") + \", last \" + (data.hours_back ?? HOURS) + \" hours\";", tab); - } - - [Fact] - public void TheTruncatedNoticeNamesTheShownCountThenTheTotal() - { - Assert.Contains( - "text += data.truncated ? \"; the top \" + n + \" of \" + data.database_count + \" databases by CPU, then I/O.\" : \".\";", - Tab()); - } - - [Fact] - public void TheReadStatesAreHandledAbortedAndAuthReturnAndEmptyShowsItsMessage() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return mount\\(body, gatedEmptyStrip\\(res, ctx\\)\\);$", tab); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "./gate.js", "./window.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } - - [Fact] - public void TheErrorAndRenderFailureStatesAreHandled() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"error\"\\) return mount\\(body, readErrorStrip\\(res\\.message\\)\\);$", tab); - Assert.Contains("Could not render this tab: ", tab); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabDatabaseSizesPageTests.cs b/Darling/Darling.Tests/FinOpsTabDatabaseSizesPageTests.cs deleted file mode 100644 index bb0282cf57..0000000000 --- a/Darling/Darling.Tests/FinOpsTabDatabaseSizesPageTests.cs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System; -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Database Sizes tab: it reads the get_finops database_sizes view and shows only columns that view emits. -public sealed class FinOpsTabDatabaseSizesPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "database-sizes.js") - .ReplaceLineEndings("\n"); - - private static string ViewSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.DatabaseSizes.cs") - .ReplaceLineEndings("\n"); - - [Fact] - public void TheTabReadsTheDatabaseSizesViewOfGetFinOpsForTheServer() - { - var tab = Tab(); - Assert.Contains("readTool(\"get_finops\", { server, view: \"database_sizes\", limit: MAX_FILES }, ctx && ctx.signal)", tab); - Assert.DoesNotContain("get_database_sizes", tab); - var tabMax = Regex.Match(tab, "const MAX_FILES = (\\d+);").Groups[1].Value; - var viewMax = Regex.Match(ViewSource(), "int MaxDatabaseSizeRows = (\\d+);").Groups[1].Value; - Assert.NotEmpty(viewMax); - Assert.Equal(viewMax, tabMax); - Assert.Contains("DatabaseSizesView = \"database_sizes\"", ViewSource()); - } - - [Fact] - public void EveryShownColumnKeyIsEmittedByTheViewRow() - { - var keys = Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(keys); - var source = ViewSource(); - var rowSlice = source[source.IndexOf("DatabaseSizesRow(DatabaseSizeFileDto", StringComparison.Ordinal)..]; - var rowNoteKey = Regex.Match( - ReadRepoFile("PerformanceMonitor.Common", "AzureSiblingDatabaseSize.cs"), - "const string RowNoteKey = \"([a-z_]+)\"").Groups[1].Value; - Assert.NotEmpty(rowNoteKey); - foreach (var key in keys) - { - if (key == rowNoteKey) - Assert.Contains("[AzureSiblingDatabaseSize.RowNoteKey]", rowSlice); - else - Assert.Contains("[\"" + key + "\"]", rowSlice); - } - foreach (var added in new[] { "auto_growth_mb", "free_space_mb", "used_pct", "recovery_model", "vlf_count", "monthly_cost_usd" }) - Assert.Contains(added, keys); - } - - [Fact] - public void AnAbortedReadReturnsBeforeAnythingIsMounted() - { - var tab = Tab(); - Assert.Contains("if (res.kind === \"aborted\" || res.kind === \"auth\") return;", tab); - } - - [Fact] - public void AMaxSizeOfMinusOneShowsUnlimitedAndTheCaptureTimeIsFormatted() - { - var tab = Tab(); - Assert.Contains("row.max_size_mb === -1 ? \"Unlimited\"", tab); - Assert.Contains("\"Disabled\"", tab); - Assert.Contains("relTime(data.captured_at)", tab); - Assert.Contains("localTime(data.captured_at)", tab); - Assert.Contains("e?.name !== \"AbortError\"", tab); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "./gate.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheTabIsNoLongerTheStub() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabHighImpactPageTests.cs b/Darling/Darling.Tests/FinOpsTabHighImpactPageTests.cs deleted file mode 100644 index 3edf9a168a..0000000000 --- a/Darling/Darling.Tests/FinOpsTabHighImpactPageTests.cs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps High Impact tab: it reads get_finops with view high_impact and shows only columns that read emits. -public sealed class FinOpsTabHighImpactPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "high-impact.js") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.HighImpact.cs") - .ReplaceLineEndings("\n"); - - [Fact] - public void TheTabReadsGetFinOpsWithTheHighImpactViewWindowAndLimit() - { - Assert.Contains("readTool(\"get_finops\", { server, view: \"high_impact\", hours, limit: LIMIT }, ctx && ctx.signal)", Tab()); - } - - [Fact] - public void ThePickerOffersTheDesktopWindowsAndTheStateIsKeptPerServer() - { - var tab = Tab(); - // #5562 R5: the shared picker in its Compact, rolling-only form (finops/window.js), not a hand-listed select. - Assert.DoesNotContain("WINDOWS", tab); - Assert.Contains("finopsWindowControl({ hours: start, onChange: (hours) => load(hours) })", tab); - Assert.Contains("const chosenHours = new Map();", tab); - Assert.Contains("chosenHours.set(server, hours);", tab); - Assert.Contains("chosenHours.get(server) ?? HOURS", tab); - Assert.Contains("(hours) => load(hours)", tab); - Assert.DoesNotContain("innerHTML", tab); - } - - [Fact] - public void EveryShownColumnKeyIsEmittedByTheTool() - { - var keys = Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(keys); - var source = ToolSource(); - foreach (var key in keys) - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", source); - } - - [Fact] - public void TheNoticeCountsTheRowsReturnedAndTakesTheWindowFromTheAnswer() - { - var tab = Tab(); - Assert.DoesNotContain("\"Top \" + LIMIT", tab); - Assert.Contains("queries in the top ", tab); - Assert.Contains("data.hours_back", tab); - Assert.Contains("(data.rows || []).length", tab); - } - - [Fact] - public void TheReadStatesAreHandledAbortedAndAuthReturnAndEmptyShowsItsMessage() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return mount\\(body, gatedEmptyStrip\\(res, ctx\\)\\);$", tab); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "../plan-viewer.js", "./gate.js", "./window.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } - - [Fact] - public void TheTabNeverComparesTheImpactScoreWithANumber() - { - Assert.False(Regex.IsMatch(Tab(), "impact_score\\s*(>=|<=|>|<)"), "impact_score is compared in the browser"); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabIndexAnalysisPageTests.cs b/Darling/Darling.Tests/FinOpsTabIndexAnalysisPageTests.cs deleted file mode 100644 index d4794fc4d1..0000000000 --- a/Darling/Darling.Tests/FinOpsTabIndexAnalysisPageTests.cs +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Index Analysis tab: it reads get_finops with view index_analysis and shows only keys that read emits. -public sealed class FinOpsTabIndexAnalysisPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "index-analysis.js") - .ReplaceLineEndings("\n"); - - // The Database box's draft, caret, focus and commit handling lives in the shared module (#5231). - private static string Box() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "database-box.js") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.IndexAnalysis.cs") - .ReplaceLineEndings("\n"); - - private static string ToolsMain() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.cs") - .ReplaceLineEndings("\n"); - - private static string Slice(string startMarker, string endMarker) - { - var source = ToolSource(); - var start = source.IndexOf(startMarker, System.StringComparison.Ordinal); - Assert.True(start >= 0, startMarker); - var end = source.IndexOf(endMarker, start, System.StringComparison.Ordinal); - Assert.True(end > start, endMarker); - return source.Substring(start, end - start); - } - - private static string DatabaseRowSlice() => - Slice(" return new\n {\n database_name = r.DatabaseName,", "\n };"); - - private static string RecommendationSlice() => Slice(" IndexAnalysisRecommendationRow(", "\n };"); - - private static string EnvelopeSlice() => Slice("return JsonSerializer.Serialize(new", "}, McpHelpers.JsonOptions);"); - - /// The keys of one column array, in order. - private static System.Collections.Generic.List Keys(string constName) - { - var tab = Tab(); - var start = tab.IndexOf("const " + constName + " = [", System.StringComparison.Ordinal); - Assert.True(start >= 0); - var end = tab.IndexOf("\n];", start, System.StringComparison.Ordinal); - Assert.True(end > start); - return Regex.Matches(tab.Substring(start, end - start), "\\bkey: \"([a-z_0-9]+)\"").Select(m => m.Groups[1].Value).ToList(); - } - - private static System.Collections.Generic.List DerivedKeys() - { - var m = Regex.Match(Tab(), "(?m)^const DERIVED_KEYS = \\[(.*)\\];$"); - Assert.True(m.Success); - return Regex.Matches(m.Groups[1].Value, "\"([a-z_0-9]+)\"").Select(x => x.Groups[1].Value).ToList(); - } - - private static string KeyPattern(string key) => "(?m)^\\s+" + Regex.Escape(key) + "( = |,$)"; - - [Fact] - public void TheTabReadsIndexAnalysisWithTheToolMaxLimit() - { - var tab = Tab(); - Assert.Contains("const params = { server, view: \"index_analysis\", limit: LIMIT };", tab); - Assert.Contains("readTool(\"get_finops\", params, ctx && ctx.signal)", tab); - var limit = Regex.Match(tab, "(?m)^const LIMIT = (\\d+);$"); - Assert.True(limit.Success); - // The most the view takes for this view (#5238): the 500 of MaxIndexAnalysisRecommendations, which MaxLimitFor hands to index_analysis, - // not the 50 every other top-N view stops at. - var max = Regex.Match(ToolSource(), "internal const int MaxIndexAnalysisRecommendations = (\\d+);"); - Assert.True(max.Success); - Assert.Equal(500, int.Parse(max.Groups[1].Value)); - Assert.Equal(int.Parse(max.Groups[1].Value), int.Parse(limit.Groups[1].Value)); - Assert.Contains("IndexAnalysisView => MaxIndexAnalysisRecommendations,", ToolsMain()); - Assert.Contains("var maxLimit = MaxLimitFor(normalized);", ToolsMain()); - // The first, unfiltered read sends neither optional parameter: they are added to params only from a choice. - var call = tab.Substring(tab.IndexOf("const params = ", System.StringComparison.Ordinal), 200); - call = call.Substring(0, call.IndexOf(';')); - Assert.DoesNotContain("hours:", call); - Assert.DoesNotContain("database_name:", call); - Assert.DoesNotContain("full_text:", call); - Assert.DoesNotContain("hours:", tab); - Assert.DoesNotContain("full_text:", tab); - } - - [Fact] - public void TheSuggestionListComesOnlyFromAnUnfilteredRead() - { - var tab = Tab(); - Assert.Matches(@"if\s*\(\s*!choice\.db\s*\)\s*\{\s*choice\.names\s*=\s*\(data\.databases\s*\|\|\s*\[\]\)", tab); - Assert.Single(Regex.Matches(tab, @"choice\.names\s*=")); - } - - [Fact] - public void TheDatabaseFilterReReadsWithDatabaseName() - { - var tab = Tab(); - Assert.Contains("if (choice.db) params.database_name = choice.db;", tab); - Assert.DoesNotContain("database_name: choice", tab); - Assert.Contains("databaseBox(choice, { onCommit: () => reread() })", tab); - Assert.Contains("choice.names = (data.databases || []).map((d) => d.database_name)", tab); - var box = Box(); - Assert.Contains("type: \"text\", list: listId", box); - Assert.Contains("el(\"datalist\", { id: listId })", box); - Assert.Contains("el(\"span\", { text: \"Database\" })", box); - Assert.Contains("input.addEventListener(\"change\"", box); - // One name, exactly as typed (no trim, #5244 M3), in the stored spelling when it matches a suggestion ignoring case (#5244 L8c). - Assert.Contains("choice.db = storedSpelling(input.value, known());", box); - Assert.DoesNotContain(".trim();", box.Replace("text.trim() === \"\"", "").Replace("String(typed).trim() === \"\"", "")); - } - - [Fact] - public void TheFullTextToggleReReadsWithFullText() - { - var tab = Tab(); - Assert.Contains("if (choice.full) params.full_text = true;", tab); - Assert.Contains("type: \"checkbox\"", tab); - Assert.Contains("Full script and definition text", tab); - Assert.Contains("fullBox.addEventListener(\"change\"", tab); - Assert.Contains("choice.full = fullBox.checked;", tab); - } - - [Fact] - public void TheFilterAndToggleSurviveAPoll() - { - var tab = Tab(); - Assert.Matches("(?m)^const choices = new Map\\(\\);$", tab); - var build = tab.Substring(tab.IndexOf(" build(server, ctx) {", System.StringComparison.Ordinal)); - Assert.StartsWith(" build(server, ctx) {\n const choice = choiceFor(server);", build); - Assert.DoesNotContain("const choices", build); - Assert.Contains("choices.get(server)", tab); - } - - [Fact] - public void ALateReadDoesNotOverwriteANewerOne() - { - var tab = Tab(); - Assert.Contains("const mine = ++generation;", tab); - Assert.Matches("(?m)^\\s+const res = await readTool\\(.*\\n\\s+if \\(mine !== generation\\) return;$", tab); - } - - [Fact] - public void TheControlsAreNotRemountedByARead() - { - var tab = Tab(); - Assert.Contains("return el(\"div\", {}, [controls, content]);", tab); - Assert.DoesNotContain("mount(controls", tab); - Assert.DoesNotContain("mount(body", tab); - Assert.Contains("mount(content, loadingStrip());", tab); - } - - [Fact] - public void TheCollectedColumnIsLast_AndTheNoticeNamesEachDatabasesSnapshot() - { - var tab = Tab(); - Assert.Contains("{ key: \"captured_at\", label: \"Collected\", format: \"time\" },\n];", tab); - Assert.Contains("Analyzed from each database's newest collected snapshot.", tab); - Assert.DoesNotContain("latest collected snapshot", tab); - /* The overall row is built with no captured_at, so its cell stays blank. */ - Assert.DoesNotContain("captured_at", DatabaseRowSliceOverall()); - } - - private static string DatabaseRowSliceOverall() => - Slice("if (!withWorkload)", " return new"); - - [Fact] - public void AFilteredNoticeNamesTheDatabase() - { - Assert.Contains("\" Database \" + db + \".\"", Tab()); - } - - [Fact] - public void EveryRollupColumnKeyIsEmittedByTheDatabaseRow() - { - var derived = DerivedKeys(); - var keys = Keys("ROLLUP_COLUMNS"); - var row = DatabaseRowSlice(); - foreach (var key in keys.Where(k => !derived.Contains(k))) - Assert.Matches(KeyPattern(key), row); - Assert.Equal(24, Regex.Matches(row, "(?m)^\\s+[a-z_]+ = ").Count); - Assert.Equal(21, keys.Count); - } - - [Fact] - public void EveryRecommendationColumnKeyIsEmitted() - { - var derived = DerivedKeys(); - var keys = Keys("RECOMMENDATION_COLUMNS"); - var row = RecommendationSlice(); - foreach (var key in keys.Where(k => !derived.Contains(k))) - Assert.Matches(KeyPattern(key), row); - // The derived size text is built from this key, so the key itself is pinned too. - Assert.Matches(KeyPattern("index_size_gb"), row); - Assert.Matches(KeyPattern("total_reads"), DatabaseRowSlice()); - Assert.Equal(23, Regex.Matches(row, "(?m)^\\s+[a-z_]+( = |,$)").Count); - Assert.Equal(17, keys.Count); - } - - [Fact] - public void TheColumnsAreInTheDesktopGridOrder() - { - Assert.Equal( - "database_name,tables_analyzed,index_count,total_size_gb,total_rows,indexes_to_disable,indexes_to_merge,compressable_indexes," - + "unused_indexes,unused_size_gb,compression_min_savings_gb,compression_max_savings_gb,total_min_savings_gb,total_max_savings_gb," - + "reads_breakdown,writes,lock_wait_count,avg_lock_wait_ms,latch_wait_count,avg_latch_wait_ms,captured_at", - string.Join(",", Keys("ROLLUP_COLUMNS"))); - Assert.Equal( - "action,result_kind,consolidation_rule,database_name,schema_name,table_name,index_name,index_size_gb_text,index_rows," - + "index_reads,index_writes,target_index_name,superseded_by,additional_info,original_index_definition,script,captured_at", - string.Join(",", Keys("RECOMMENDATION_COLUMNS"))); - } - - [Theory] - [InlineData("overall")] - [InlineData("databases")] - [InlineData("notes")] - [InlineData("recommendations")] - [InlineData("recommendation_count")] - [InlineData("truncated")] - [InlineData("database_count")] - [InlineData("databases_truncated")] - [InlineData("uptime_warning")] - [InlineData("dedupe_only_applied")] - [InlineData("overall_workload_reason")] - public void TheEnvelopeKeysTheTabReadsAreEmitted(string key) - { - Assert.Matches(KeyPattern(key), EnvelopeSlice()); - Assert.Matches(@"data\." + key + @"\b", Tab()); - } - - [Fact] - public void TheTypedDatabaseTextSurvivesAPoll() - { - var box = Box(); - Assert.Matches(@"addEventListener\(""input"", \(\) => \{\s*choice\.draft = input\.value;", box); - Assert.Contains("choice.caret = [input.selectionStart, input.selectionEnd];", box); - Assert.Contains("input.value = choice.draft ?? choice.db;", box); - Assert.Matches(@"addEventListener\(""change"", \(\) => \{\s*choice\.db = storedSpelling\(input\.value, known\(\)\);\s*choice\.draft = undefined;", box); - } - - [Fact] - public void FocusSurvivesAPoll() - { - var box = Box(); - Assert.Matches(@"addEventListener\(""focus"", \(\) => \{\s*choice\.focused = true;", box); - Assert.Matches(@"addEventListener\(""blur"", \(\) => \{\s*setTimeout\(\(\) => \{\s*if \(input\.isConnected\) choice\.focused = false;\s*\}, 0\);", box); - Assert.Matches(@"if \(choice\.focused\) \{\s*setTimeout\(\(\) => \{\s*if \(input\.isConnected\) \{\s*input\.focus\(\);\s*if \(choice\.caret\) input\.setSelectionRange\(choice\.caret\[0\], choice\.caret\[1\]\);", box); - Assert.DoesNotContain("requestAnimationFrame", box); - } - - [Fact] - public void TheFullTextColumnsKeepTheirLineBreaks() - { - var tab = Tab(); - Assert.Contains("{ key: \"original_index_definition\", label: \"Original Definition\", wrap: true, mono: true, pre: true }", tab); - Assert.Contains("{ key: \"script\", label: \"Script\", wrap: true, mono: true, pre: true }", tab); - var panels = ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "panels.js").ReplaceLineEndings("\n"); - Assert.Equal(2, Regex.Matches(panels, @"if \(c\.pre\) (rcls|cls)\.push\(""pre""\);").Count); - var css = ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "css", "app.css").ReplaceLineEndings("\n"); - var wrap = css.IndexOf("table.data td.wrap {", System.StringComparison.Ordinal); - var pre = css.IndexOf("table.data td.pre { white-space: pre-wrap; }", System.StringComparison.Ordinal); - Assert.True(wrap >= 0 && pre > wrap, "td.pre must follow td.wrap so it wins"); - } - - [Fact] - public void TheLeadNotesAreTheUptimeThenDedupeNotesTheServerEmitsFirst() - { - var source = ToolSource(); - var uptime = source.IndexOf("notes.Add(IndexAnalysisUptimeNote)", System.StringComparison.Ordinal); - var dedupe = source.IndexOf("notes.Add(IndexAnalysisDedupeNote)", System.StringComparison.Ordinal); - var analyzer = source.IndexOf("notes.AddRange(result.Notes)", System.StringComparison.Ordinal); - Assert.True(uptime >= 0 && dedupe > uptime, "uptime note must come before the dedupe note"); - Assert.True(analyzer > dedupe, "analyzer notes must come after both lead notes"); - } - - [Fact] - public void TheOverallRowIsAllDatabasesWithNoWorkloadFigures() - { - var tab = Tab(); - Assert.Contains("{ ...data.overall, database_name: \"ALL DATABASES\" }", tab); - Assert.DoesNotContain("\"N/A\"", tab); - } - - [Fact] - public void TheReadsBreakdownIsBuiltFromTheEmittedCounters() - { - Assert.Contains( - "reads_breakdown: r.total_reads == null ? null : fmtInt(r.total_reads) + \" (\" + fmtInt(r.user_seeks) + \" seeks, \" + fmtInt(r.user_scans) + \" scans, \" + fmtInt(r.user_lookups) + \" lookups)\"", - Tab()); - } - - [Fact] - public void TheSizeShowsThreeDecimalsLikeTheDesktop() - { - Assert.Contains("fmtNum(r.index_size_gb, 3)", Tab()); - } - - [Fact] - public void TheBannerTextComesFromThePayload() - { - var tab = Tab(); - Assert.DoesNotContain("under 14 days", tab); - Assert.DoesNotContain("Dedupe-only mode", tab); - Assert.Contains("data.notes || []", tab); - } - - [Fact] - public void TheTabKeepsThePayloadOrder() - { - Assert.DoesNotContain(".sort(", Tab()); - } - - [Fact] - public void TheTruncatedNoticeNamesShownThenTotal() - { - var tab = Tab(); - Assert.Contains("const rowsCut = n > 0 && data.truncated;", tab); - /* #5238: the count left over is one name, with a singular branch ("1 more is not shown"); the harness test runs the text itself. */ - Assert.Contains("const left = data.recommendation_count - n;", tab); - Assert.Contains("\"Showing the largest \" + n + \" of \" + data.recommendation_count + \" recommendations. The list stops at \" + n + \", so \" + (left === 1 ? \"1 more is\" : left + \" more are\") + \" not shown.\"", tab); - Assert.DoesNotContain("The largest \" + n", tab); - } - - [Fact] - public void TheReadStatesAreHandled() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return mount\\(content, gatedEmptyStrip\\(res, ctx\\)\\);$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"error\"\\) return mount\\(content, readErrorStrip\\(res\\.message\\)\\);$", tab); - Assert.Contains("Could not render this tab: ", tab); - } - - [Fact] - public void TheTabBuildsItsDomFromTextOnly() - { - Assert.DoesNotContain("innerHTML", Tab()); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "./database-box.js", "../../panels.js", "../../util.js", "../../plain-text.js", "./gate.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } - - [Fact] - public async System.Threading.Tasks.Task TheTabParsesUnderNode() - { - var path = Path.Combine(Path.GetTempPath(), "index-analysis-" + System.Guid.NewGuid().ToString("N") + ".mjs"); - File.WriteAllText(path, Tab()); - try - { - var psi = new ProcessStartInfo("node") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; - psi.ArgumentList.Add("--check"); - psi.ArgumentList.Add(path); - Process proc; - try - { - proc = Process.Start(psi)!; - } - catch (Win32Exception) - { - Assert.Skip("Node is not installed, so the tab script cannot be parsed."); - throw; - } - - using (proc) - { - var error = proc.StandardError.ReadToEndAsync(); - if (!proc.WaitForExit(20000)) - { - proc.Kill(entireProcessTree: true); - Assert.Fail("node --check did not finish in 20 s"); - } - - Assert.True(proc.ExitCode == 0, "node --check failed: " + await error); - } - } - finally - { - File.Delete(path); - } - } -} diff --git a/Darling/Darling.Tests/FinOpsTabLockingPageTests.cs b/Darling/Darling.Tests/FinOpsTabLockingPageTests.cs deleted file mode 100644 index 2fd927526b..0000000000 --- a/Darling/Darling.Tests/FinOpsTabLockingPageTests.cs +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Locking & Contention tab (#4843): it reads get_object_locking and -/// shows only keys that read emits. -public sealed class FinOpsTabLockingPageTests -{ - private static string Tab() => ReadRepoFileLf( - "Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "locking.js"); - - private static string ToolSource() => ReadRepoFileLf( - "Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpObjectStatsTools.cs"); - - [Fact] - public void Tab_CallsGetObjectLockingWithTheDesktopRowLimit() - { - var js = Tab(); - Assert.Contains("read: \"get_object_locking\"", js); - Assert.Contains("const params = { server, limit: 200 };", js); - Assert.Contains("if (choice.db) params.database_name = choice.db;", js); - Assert.Contains("rowsKey: \"objects\"", js); - } - - [Fact] - public void Tab_EveryColumnKeyIsEmittedByTheRead() - { - var js = Tab(); - var keys = Regex.Matches(js, "\\{ key: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - Assert.Equal(14, keys.Count); - var src = LockingProjection(); - foreach (var k in keys) - Assert.Contains(" " + k + " = r.", src); - } - - /// Only get_object_locking's own projection: from its core method to the end of the row - /// projection, so a neighbouring read that emits the same column names cannot satisfy a pin. - private static string LockingProjection() - { - var src = ToolSource(); - var start = src.IndexOf("internal static async Task GetObjectLockingCoreAsync(", System.StringComparison.Ordinal); - Assert.True(start >= 0, "GetObjectLockingCoreAsync not found"); - var end = src.IndexOf("objects = objectRows", start, System.StringComparison.Ordinal); - Assert.True(end > start, "the end of the get_object_locking projection was not found"); - return src.Substring(start, end - start); - } - - [Fact] - public void Tab_ShowsTheReadsNotes_AndTheReadEmitsThem() - { - var js = Tab(); - Assert.Contains("noteKey: \"optimized_locking_note\"", js); - Assert.Contains("moreNoteKeys: [\"note\", \"separately_monitored_note\"]", js); - var tail = LockingProjection(); - Assert.Contains("optimized_locking_note = ", tail); - Assert.Contains("separately_monitored_note = ", tail); - Assert.Contains("note = truncated", tail); - Assert.Contains("TRUNCATED: more than", tail); - } - - [Fact] - public void Tab_ImportsOnlyFromTheSharedModules() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\"").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "./database-box.js", "./gate.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void Tab_IsNoLongerTheShellStub() => - Assert.DoesNotContain("Not on the web yet", Tab()); -} diff --git a/Darling/Darling.Tests/FinOpsTabOptimizationPageTests.cs b/Darling/Darling.Tests/FinOpsTabOptimizationPageTests.cs deleted file mode 100644 index 7131a46578..0000000000 --- a/Darling/Darling.Tests/FinOpsTabOptimizationPageTests.cs +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Optimization tab: it reads get_finops with view optimization and each of its five tables shows only keys that section's row function emits. -public sealed class FinOpsTabOptimizationPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "optimization.js") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.Optimization.cs") - .ReplaceLineEndings("\n"); - - /// The keys of one COLUMNS array, in order. - private static System.Collections.Generic.List Keys(string constName) - { - var tab = Tab(); - var start = tab.IndexOf("const " + constName + " = [", System.StringComparison.Ordinal); - Assert.True(start >= 0); - var end = tab.IndexOf("\n];", start, System.StringComparison.Ordinal); - Assert.True(end > start); - return Regex.Matches(tab.Substring(start, end - start), "\\bkey: \"([a-z_0-9]+)\"").Select(m => m.Groups[1].Value).ToList(); - } - - /// - /// One row function's object initializer. The slice starts at the first "new" after the method name and ends at the - /// initializer's close: "\n };" for an expression-bodied method, "\n }).ToList();" for one that selects rows. - /// - private static string RowSlice(string method, string close) - { - var source = ToolSource(); - var at = source.IndexOf(" " + method + "(", System.StringComparison.Ordinal); - Assert.True(at >= 0); - var start = source.IndexOf("new\n", at, System.StringComparison.Ordinal); - Assert.True(start > at); - var end = source.IndexOf(close, start, System.StringComparison.Ordinal); - Assert.True(end > start); - return source.Substring(start, end - start); - } - - private static void AssertKeysMatchRow(string constName, string method, string close, int count, int extraEmitted = 0) - { - var keys = Keys(constName); - var row = RowSlice(method, close); - foreach (var key in keys) - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", row); - var emitted = Regex.Matches(row, "(?m)^\\s+[a-z_0-9]+ = ").Count; - Assert.Equal(count + extraEmitted, emitted); - Assert.Equal(count, keys.Count); - } - - [Fact] - public void ThePickerOffersTheDesktopWindowsAndTheStateIsKeptPerServer() - { - var tab = Tab(); - // #5562 R5: the shared picker in its Compact, rolling-only form (finops/window.js), not a hand-listed select. - Assert.DoesNotContain("WINDOWS", tab); - Assert.Contains("finopsWindowControl({ hours: start, onChange: (hours) => load(hours) })", tab); - Assert.Contains("const chosenHours = new Map();", tab); - Assert.Contains("chosenHours.set(server, hours);", tab); - Assert.Contains("chosenHours.get(server) ?? HOURS", tab); - Assert.Contains("(hours) => load(hours)", tab); - Assert.DoesNotContain("innerHTML", tab); - } - - [Fact] - public void TheTabReadsGetFinOpsWithTheOptimizationViewWindowAndTopTwenty() - { - // Pins the exact read: the view's limit is the expensive-query top-N, and 20 matches the desktop's "Top 20 by CPU". - const string call = "readTool(\"get_finops\", { server, view: \"optimization\", hours, limit: LIMIT }, ctx && ctx.signal)"; - var tab = Tab(); - Assert.Contains(call, tab); - Assert.Matches("(?m)^const HOURS = 24;$", tab); - Assert.Matches("(?m)^const LIMIT = 20;$", tab); - Assert.Single(Regex.Matches(tab, "readTool\\(")); - } - - [Fact] - public void EveryIdleColumnKeyIsEmittedByTheIdleDatabaseRow() => - AssertKeysMatchRow("IDLE_COLUMNS", "IdleDatabaseRow", "\n };", 4); - - [Fact] - public void EveryTempdbColumnKeyIsEmittedByTheTempdbRow() => - AssertKeysMatchRow("TEMPDB_COLUMNS", "TempdbRow", "\n };", 4); - - [Fact] - public void EveryWaitColumnKeyIsEmittedByTheWaitCategoryRows() => - AssertKeysMatchRow("WAIT_COLUMNS", "WaitCategoryRows", "\n }).ToList();", 7); - - [Fact] - public void EveryQueryColumnKeyIsEmittedByTheExpensiveQueryRows() => - AssertKeysMatchRow("QUERY_COLUMNS", "ExpensiveQueryRows", "\n }).ToList();", 9, extraEmitted: 1); - - [Fact] - public void ExpensiveQueryRowsCarryTheQueryHashThePlanColumnReads() => - Assert.Contains("query_hash = r.QueryHash,", RowSlice("ExpensiveQueryRows", "\n }).ToList();")); - - [Fact] - public void EveryMemoryGrantColumnKeyIsEmittedByTheMemoryGrantRows() => - AssertKeysMatchRow("GRANT_COLUMNS", "MemoryGrantRows", "\n }).ToList();", 10); - - [Fact] - public void TheColumnsAreInTheDesktopGridOrder() - { - // Order source: the five Optimization grids in Darling/PerformanceMonitor.Darling.Viewer/FinOpsTab.xaml (~:758-855), in their column order. - // Idle Databases grid: Darling/PerformanceMonitor.Darling.Viewer/FinOpsTab.xaml, FinOpsIdleDatabasesDataGrid (~:758-765). - Assert.Equal("database_name,total_size_mb,file_count,last_execution_server_local", string.Join(",", Keys("IDLE_COLUMNS"))); - // tempdb Pressure grid: FinOpsTab.xaml (~:771-779). - Assert.Equal("metric,current_mb,peak_24h_mb,warning", string.Join(",", Keys("TEMPDB_COLUMNS"))); - // Wait Stats Summary grid: FinOpsTab.xaml (~:797-806). - Assert.Equal("category,total_wait_time_ms,waiting_tasks,pct_of_total,top_wait_type,top_wait_time_ms,est_cost_usd", string.Join(",", Keys("WAIT_COLUMNS"))); - // Expensive Queries grid: FinOpsTab.xaml (~:825-835). - Assert.Equal("database_name,query_preview,total_cpu_ms,avg_cpu_ms_per_exec,total_reads,avg_reads_per_exec,executions,has_plan,est_cost_usd", string.Join(",", Keys("QUERY_COLUMNS"))); - // Memory Grant Efficiency grid: FinOpsTab.xaml (~:844-855). - Assert.Equal("day,avg_granted_mb,avg_used_mb,efficiency_pct,peak_granted_mb,wasted_mb,total_grantees,total_waiters,timeout_errors,forced_grants", string.Join(",", Keys("GRANT_COLUMNS"))); - Assert.Contains("{ key: \"est_cost_usd\", label: \"Est. cost share ($)\", format: \"num2\" }", Tab()); - Assert.Contains("{ key: \"total_cpu_ms\", label: \"Total CPU\", format: \"ms\" }", Tab()); - } - - [Fact] - public void TheServerLocalLastExecutionIsPlainTextNeverTheTimeFormatter() - { - var tab = Tab(); - Assert.Contains("{ key: \"last_execution_server_local\", label: \"Last execution (server time)\" },", tab); - Assert.DoesNotContain("last_execution_server_local\", label: \"Last execution (server time)\", format", tab); - } - - [Fact] - public void EachSectionReadsItsOwnStatusAndMapsTheThreeStates() - { - var tab = Tab(); - Assert.Contains("if (section.status === \"ok\") {", tab); - Assert.Contains("content = [noticeStrip(notice(section)), VIZ.table(section, { rowsKey: \"rows\", columns, emptyText })];", tab); - Assert.Contains("} else if (section.status === \"empty\") {", tab); - Assert.Contains("content = [emptyStrip(emptyText)];", tab); - Assert.Contains("content = [noticeStrip(section.message ?? \"This section was not collected.\")];", tab); - foreach (var field in new[] { "idle_databases", "tempdb_pressure", "wait_categories", "expensive_queries", "memory_grant_efficiency" }) - Assert.Contains("data." + field + ",", tab); - } - - [Fact] - public void TheSectionsAreInTheDesktopOrder() - { - var tab = Tab(); - var titles = new[] { "\"Idle Databases\"", "\"tempdb Pressure\"", "\"Wait Stats Summary\"", "\"Expensive Queries (Top \" + LIMIT + \" by CPU)\"", "\"Memory Grant Efficiency\"" }; - var at = titles.Select(t => tab.IndexOf("sectionView(" + t, System.StringComparison.Ordinal)).ToList(); - Assert.All(at, i => Assert.True(i >= 0)); - Assert.Equal(at.OrderBy(i => i).ToList(), at); - } - - [Fact] - public void TheNoticesAndTheCostLineAreExact() - { - var tab = Tab(); - Assert.Contains("const n = (s.rows || []).length;", tab); - Assert.Contains("let text = (n === 1 ? \"1 idle database\" : n + \" idle databases\") + \" over the last \" + (s.window_days ?? \"?\") + \" days\";", tab); - Assert.Contains("text += s.truncated ? \"; the top \" + n + \" of \" + (s.database_count ?? \"more\") + \".\" : \".\";", tab); - Assert.Contains("return \"last \" + (s.window_hours ?? HOURS) + \" hours\";", tab); - Assert.Contains("let text = \"Top \" + (s.rows || []).length + \" by CPU, last \" + hours + \" hours\";", tab); - Assert.Contains("if (s.effective_start) text += \", from \" + applyFormat(\"time\", s.effective_start) + \" (local time)\";", tab); - Assert.Contains("\"Est. cost shares split the server's $\" + applyFormat(\"num2\", data.monthly_cost_usd) + \" monthly cost pro-rated to this window (\" + hours + \" hours); they are an attribution, not a measured cost.\"", tab); - Assert.Contains(": (data.cost_reason ?? \"monthly cost not set\") + \", so Est. cost share is blank.\";", tab); - } - - [Fact] - public void TheReadStatesAreHandledAbortedAndAuthReturnAndEmptyShowsItsMessage() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return mount\\(body, gatedEmptyStrip\\(res, ctx\\)\\);$", tab); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "../plan-viewer.js", "./gate.js", "./window.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } - - [Fact] - public void TheErrorAndRenderFailureStatesAreHandled() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"error\"\\) return mount\\(body, readErrorStrip\\(res\\.message\\)\\);$", tab); - Assert.Contains("Could not render this tab: ", tab); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabPvsPageTests.cs b/Darling/Darling.Tests/FinOpsTabPvsPageTests.cs deleted file mode 100644 index eab493e9f6..0000000000 --- a/Darling/Darling.Tests/FinOpsTabPvsPageTests.cs +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// -/// Source pins for the web viewer's FinOps Version Store (PVS) tab: it reads get_pvs_stats, shows only keys the -/// tool emits, imports only the shared renderers, and no longer carries the placeholder text. -/// -public sealed class FinOpsTabPvsPageTests -{ - private static string Tab => ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "version-store.js").ReplaceLineEndings("\n"); - - private static string Tool => ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpPvsTools.cs").ReplaceLineEndings("\n"); - - [Fact] - public void Tab_ReadsGetPvsStatsWithATrendWindow() - { - Assert.Contains("readTool(\"get_pvs_stats\", { server, trend_hours_back: TREND_HOURS }, signal)", Tab); - Assert.Contains("const TREND_HOURS = 168;", Tab); - } - - [Fact] - public void Tab_EveryShownKeyIsEmittedByTheTool() - { - var tool = Tool; - var columnKeys = Regex.Matches(Tab, "key: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - Assert.True(columnKeys.Count >= 13, "expected the column keys to be found"); - var keys = columnKeys - .Concat(new[] { "databases", "trend", "points", "collection_time", "pvs_size_mb", "as_of", "database_name", "pct_of_database_reason" }) - .Distinct().ToList(); - foreach (var key in keys) - { - Assert.True(tool.Contains(key + " = ") || tool.Contains("\"" + key + "\"") || tool.Contains(key + ","), - "get_pvs_stats does not emit " + key); - } - } - - [Fact] - public void Tab_ImportsOnlyTheSharedRenderers() - { - var imports = Regex.Matches(Tab, "from \"([^\"]+)\"").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "./gate.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void Tab_IsNoLongerThePlaceholder() - { - Assert.DoesNotContain("Not on the web yet", Tab); - } - - [Fact] - public void Tab_ShowsAbortedLagCleanupAndTheThreeSkippedCountersInTheDesktopOrder() - { - var order = new[] - { - "key: \"oldest_aborted_transaction_id\"", - "key: \"aborted_transaction_lag\", label: \"Aborted Lag\"", - "key: \"cleanup_state\", label: \"Cleanup\"", - "key: \"skipped_low_water_mark\", label: \"Skipped: Secondary\"", - "key: \"skipped_min_useful_xts\", label: \"Skipped: Snapshot\"", - "key: \"skipped_oldest_aborted\", label: \"Skipped: Aborted\"", - }; - var at = -1; - foreach (var pin in order) - { - var next = Tab.IndexOf(pin, System.StringComparison.Ordinal); - Assert.True(next > at, "column missing or out of order: " + pin); - at = next; - } - - foreach (var key in new[] { "aborted_transaction_lag", "cleanup_state", "skipped_low_water_mark", "skipped_min_useful_xts", "skipped_oldest_aborted" }) - { - Assert.Contains(key + " = ", Tool); - } - } -} diff --git a/Darling/Darling.Tests/FinOpsTabRecommendationsPageTests.cs b/Darling/Darling.Tests/FinOpsTabRecommendationsPageTests.cs deleted file mode 100644 index 69faa45d6b..0000000000 --- a/Darling/Darling.Tests/FinOpsTabRecommendationsPageTests.cs +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using PerformanceMonitor.Darling.Service.Mcp; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Recommendations tab: it reads get_finops_recommendations and shows only keys that read emits. -public sealed class FinOpsTabRecommendationsPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "recommendations.js") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsRecommendationsTools.cs") - .ReplaceLineEndings("\n"); - - private static string Slice(string startMarker, string endMarker) - { - var source = ToolSource(); - var start = source.IndexOf(startMarker, System.StringComparison.Ordinal); - Assert.True(start >= 0); - var end = source.IndexOf(endMarker, start, System.StringComparison.Ordinal); - Assert.True(end > start); - return source.Substring(start, end - start); - } - - private static string RowSlice() => Slice("internal static object RecommendationRow(", "\n };"); - - private static string EnvelopeSlice() => Slice("internal static object Envelope(", "\n };"); - - private static System.Collections.Generic.List Keys() => - Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - - [Fact] - public void TheTabReadsTheRecommendationsRoute() - { - Assert.Contains("readTool(\"get_finops_recommendations\", { server }, ctx && ctx.signal)", Tab()); - } - - [Fact] - public void EveryColumnKeyIsEmittedByTheRow() - { - var keys = Keys(); - var row = RowSlice(); - foreach (var key in keys) - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", row); - Assert.Equal(6, Regex.Matches(row, "(?m)^\\s+[a-z_]+ = ").Count); - Assert.Equal(6, keys.Count); - } - - [Fact] - public void TheColumnsAreInTheDesktopGridOrder() - { - Assert.Equal("category,severity,confidence,finding,detail,est_savings_usd_month", string.Join(",", Keys())); - } - - [Theory] - [InlineData("recommendations")] - [InlineData("monthly_cost_usd")] - [InlineData("skipped_checks")] - public void TheEnvelopeKeysTheTabReadsAreEmitted(string key) - { - Assert.Matches("(?m)^\\s+" + key + " = ", EnvelopeSlice()); - Assert.Contains("data." + key, Tab()); - } - - [Fact] - public void SeverityColourMapsTheThreeLevels() - { - Assert.Contains("const SEV = { High: \"Critical\", Medium: \"Warning\", Low: \"Healthy\" };", Tab()); - Assert.Contains("severity and confidence are High, Medium or Low", ToolSource()); - Assert.Contains("{ key: \"severity\", label: \"Severity\", sevKey: \"severity_sev\" }", Tab()); - } - - [Fact] - public void TheTextColumnsAreNotFormatted() - { - var tab = Tab(); - foreach (var key in new[] { "finding", "detail" }) - { - var line = Regex.Match(tab, "(?m)^\\s+\\{ key: \"" + key + "\".*$"); - Assert.True(line.Success); - Assert.DoesNotContain("format:", line.Value); - Assert.Contains("wrap: true", line.Value); - } - } - - [Fact] - public void TheTabKeepsThePayloadOrder() - { - Assert.DoesNotContain(".sort(", Tab()); - } - - [Fact] - public void TheReadStatesAreHandled() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return mount\\(body, gatedEmptyStrip\\(res, ctx\\)\\);$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"error\"\\) return mount\\(body, readErrorStrip\\(res\\.message\\)\\);$", tab); - Assert.Contains("Could not render this tab: ", tab); - } - - [Fact] - public void TheTabBuildsItsDomFromTextOnly() - { - Assert.DoesNotContain("innerHTML", Tab()); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../util.js", "./gate.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } - - [Fact] - public async System.Threading.Tasks.Task TheTabParsesUnderNode() - { - var path = Path.Combine(Path.GetTempPath(), "recommendations-" + System.Guid.NewGuid().ToString("N") + ".mjs"); - File.WriteAllText(path, Tab()); - try - { - var psi = new ProcessStartInfo("node") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; - psi.ArgumentList.Add("--check"); - psi.ArgumentList.Add(path); - Process proc; - try - { - proc = Process.Start(psi)!; - } - catch (Win32Exception) - { - Assert.Skip("Node is not installed, so the tab script cannot be parsed."); - throw; - } - - using (proc) - { - var error = proc.StandardError.ReadToEndAsync(); - if (!proc.WaitForExit(20000)) - { - proc.Kill(entireProcessTree: true); - Assert.Fail("node --check did not finish in 20 s"); - } - - Assert.True(proc.ExitCode == 0, "node --check failed: " + await error); - } - } - finally - { - File.Delete(path); - } - } -} diff --git a/Darling/Darling.Tests/FinOpsTabServerInventoryPageTests.cs b/Darling/Darling.Tests/FinOpsTabServerInventoryPageTests.cs deleted file mode 100644 index 3f8bc5eaae..0000000000 --- a/Darling/Darling.Tests/FinOpsTabServerInventoryPageTests.cs +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using PerformanceMonitor.Common; -using PerformanceMonitor.Darling.Service.Mcp; -using PerformanceMonitor.Darling.Storage.FinOps; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Server Inventory tab: it reads get_finops_inventory with view server_inventory and shows only keys that read emits. -public sealed class FinOpsTabServerInventoryPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "server-inventory.js") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsInventoryTools.cs") - .ReplaceLineEndings("\n"); - - private static string Slice(string startMarker) - { - var source = ToolSource(); - var start = source.IndexOf(startMarker, System.StringComparison.Ordinal); - Assert.True(start >= 0); - var end = source.IndexOf("\n };", start, System.StringComparison.Ordinal); - Assert.True(end > start); - return source.Substring(start, end - start); - } - - private static string RowSlice() => Slice("internal static object InventoryRow("); - - private static string EnvelopeSlice() => Slice("internal static object Envelope("); - - private static System.Collections.Generic.List Keys() => - Regex.Matches(Tab(), "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - - [Fact] - public void TheTabReadsTheFleetInventoryWithTheMaxLimit() - { - var tab = Tab(); - Assert.Contains("readTool(\"get_finops_inventory\", { view: \"server_inventory\", limit: LIMIT, include_removed: showRemoved ? \"true\" : null }, ctx && ctx.signal)", tab); - var limit = Regex.Match(tab, "(?m)^const LIMIT = (\\d+);$"); - Assert.True(limit.Success); - Assert.Equal(DarlingMcpFinOpsInventoryTools.MaxLimit, int.Parse(limit.Groups[1].Value)); - Assert.DoesNotContain("{ server,", tab); - } - - [Fact] - public void TheShowRemovedServersCheckboxIsOffByDefaultAndSendsIncludeRemoved() - { - var tab = Tab(); - // Off by default, labelled, and the tool/route declare the same flag with a false default (Web 11). - Assert.Contains("let showRemoved = false;", tab); - Assert.Contains("\"Show removed servers\"", tab); - Assert.Contains("bool include_removed = false", ToolSource()); - Assert.Contains("PBool(\"include_removed\", false)", ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "DarlingWebEndpoints.cs")); - } - - [Fact] - public void EveryShownColumnKeyIsEmittedByTheInventoryRow() - { - var keys = Keys(); - var row = RowSlice(); - foreach (var key in keys) - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", row); - // engine_edition is emitted but not shown, as on the desktop; so are health_score_note (the words for a dash in place of a score) and cost_reason (why the cost is null, #5633). - Assert.Equal(28, Regex.Matches(row, "(?m)^\\s+[a-z_]+ = ").Count); - Assert.Equal(25, keys.Count); - } - - [Fact] - public void TheColumnsAreInTheDesktopGridOrder() - { - Assert.Equal( - "server,edition,product_version,host_os_version,cpu_count,physical_memory_mb,socket_count,cores_per_socket,hardware_note," - + "provisioning_status,avg_cpu_pct,storage_total_gb,idle_db_count,sqlserver_start_time_local,inventory_as_of,last_collected," - + "monitoring,monthly_cost_usd,annual_cost_usd,health_score,health_band,license_warning,is_hadr_enabled,ag_replica_role,is_clustered", - string.Join(",", Keys())); - } - - [Theory] - [InlineData("servers")] - [InlineData("truncated")] - [InlineData("total_servers")] - [InlineData("hardware_note_legend")] - [InlineData("cpu_window_hours")] - [InlineData("idle_window_days")] - public void TheEnvelopeKeysTheTabReadsAreEmitted(string key) - { - Assert.Matches("(?m)^\\s+" + key + " = ", EnvelopeSlice()); - Assert.Contains("data." + key, Tab()); - } - - [Fact] - public void TheHostScopedCodeShowsTheLegendText() - { - var tab = Tab(); - Assert.Contains("legend[r.hardware_note] ?? r.hardware_note", tab); - Assert.Contains("data.hardware_note_legend", tab); - Assert.DoesNotContain("host_scoped", tab); - Assert.DoesNotContain("Azure SQL Database: memory", tab); - } - - [Fact] - public void AnOmittedKeyShowsAsADashBecauseTheRowIsSpreadAndNeverFilled() - { - var tab = Tab(); - Assert.Contains("return {\n ...r,", tab); - Assert.DoesNotContain("r.edition ??", tab); - Assert.DoesNotContain("?? \"\"", tab.Replace("String(r.ag_replica_role ?? \"\")", "")); - } - - [Fact] - public void TheHealthColourComesFromThePayloadBand() - { - Assert.Contains("const BAND_SEV = { good: \"Healthy\", fair: \"Warning\", poor: \"Critical\" };", Tab()); - Assert.Equal("good", FinOpsUtilizationFigures.BandGood); - Assert.Equal("fair", FinOpsUtilizationFigures.BandFair); - Assert.Equal("poor", FinOpsUtilizationFigures.BandPoor); - } - - [Fact] - public void TheStartTimeShowsMinutesAndAnUnknownStatusDropsUnderscores() - { - var tab = Tab(); - Assert.Contains("r.sqlserver_start_time_local.slice(0, 16).replace(\"T\", \" \")", tab); - Assert.Contains("r.provisioning_status.replace(/_/g, \" \")", tab); - } - - [Fact] - public void TheBandColumnIsColouredByTheHealthSeverity() - { - Assert.Contains("{ key: \"health_band\", label: \"Band\", sevKey: \"health_sev\" }", Tab()); - } - - [Fact] - public void TheStatusLabelsAreTheProvisioningVerdictTokens() - { - var tab = Tab(); - Assert.Contains(ProvisioningVerdict.RightSized + ": [", tab); - Assert.Contains(ProvisioningVerdict.OverProvisioned + ": [", tab); - Assert.Contains(ProvisioningVerdict.UnderProvisioned + ": [", tab); - Assert.Contains(ProvisioningVerdict.NotApplicable + ": [\"" + ProvisioningVerdict.NotApplicableLabel + "\"", tab); - } - - [Fact] - public void TheServerClockStartTimeIsNotParsedAsUtc() - { - Assert.Contains("{ key: \"sqlserver_start_time_local\", label: \"Start time (server clock)\" }", Tab()); - } - - [Fact] - public void TheTabKeepsThePayloadOrder() - { - Assert.DoesNotContain(".sort(", Tab()); - } - - [Fact] - public void TheTruncatedNoticeNamesTheShownCountThenTheTotal() - { - Assert.Contains("(data.truncated ? \" (the first \" + n + \" of \" + data.total_servers + \")\" : \"\")", Tab()); - } - - [Fact] - public void TheReadStatesAreHandled() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return mount\\(body, emptyStrip\\(res\\.message\\)\\);$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"error\"\\) return mount\\(body, readErrorStrip\\(res\\.message\\)\\);$", tab); - Assert.Contains("Could not render this tab: ", tab); - } - - [Fact] - public void TheTabBuildsItsDomFromTextOnly() - { - Assert.DoesNotContain("innerHTML", Tab()); - } - - [Fact] - public void TheTabImportsOnlyTheSharedHelpers() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../util.js" })); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } - - [Fact] - public async System.Threading.Tasks.Task TheTabParsesUnderNode() - { - var path = Path.Combine(Path.GetTempPath(), "server-inventory-" + System.Guid.NewGuid().ToString("N") + ".mjs"); - File.WriteAllText(path, Tab()); - try - { - var psi = new ProcessStartInfo("node") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; - psi.ArgumentList.Add("--check"); - psi.ArgumentList.Add(path); - Process proc; - try - { - proc = Process.Start(psi)!; - } - catch (Win32Exception) - { - Assert.Skip("Node is not installed, so the tab script cannot be parsed."); - throw; - } - - using (proc) - { - var error = proc.StandardError.ReadToEndAsync(); - if (!proc.WaitForExit(20000)) - { - proc.Kill(entireProcessTree: true); - Assert.Fail("node --check did not finish in 20 s"); - } - - Assert.True(proc.ExitCode == 0, "node --check failed: " + await error); - } - } - finally - { - File.Delete(path); - } - } -} diff --git a/Darling/Darling.Tests/FinOpsTabStorageGrowthPageTests.cs b/Darling/Darling.Tests/FinOpsTabStorageGrowthPageTests.cs deleted file mode 100644 index bc802db473..0000000000 --- a/Darling/Darling.Tests/FinOpsTabStorageGrowthPageTests.cs +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Storage Growth tab: it reads get_finops with view storage_growth at three levels, and each table shows the keys its row function emits. -public sealed class FinOpsTabStorageGrowthPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "storage-growth.js") - .ReplaceLineEndings("\n"); - - private static string Css() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "css", "app.css") - .ReplaceLineEndings("\n"); - - private static string ToolSource() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", "DarlingMcpFinOpsTools.StorageGrowth.cs") - .ReplaceLineEndings("\n"); - - /// The keys of one COLUMNS array, in order. - private static System.Collections.Generic.List Keys(string constName) - { - var tab = Tab(); - var start = tab.IndexOf("const " + constName + " = [", System.StringComparison.Ordinal); - Assert.True(start >= 0); - var end = tab.IndexOf("\n];", start, System.StringComparison.Ordinal); - Assert.True(end > start); - return Regex.Matches(tab.Substring(start, end - start), "\\bkey: \"([a-z_0-9]+)\"").Select(m => m.Groups[1].Value).ToList(); - } - - /// One expression-bodied row function's object initializer: from the first "new" after the method name to the given close. - private static string RowSlice(string method, string close) - { - var source = ToolSource(); - var at = source.IndexOf(" " + method + "(", System.StringComparison.Ordinal); - Assert.True(at >= 0); - var start = source.IndexOf("new\n", at, System.StringComparison.Ordinal); - Assert.True(start > at); - var end = source.IndexOf(close, start, System.StringComparison.Ordinal); - Assert.True(end > start); - return source.Substring(start, end - start); - } - - /// Every shown key is emitted by the row; the shown count equals the emitted count less the listed deliberate omissions. - private static void AssertKeysMatchRow(string constName, string method, string close, int emittedCount, params string[] omitted) - { - // captured_at is the indexes section's one snapshot time, copied onto each row by the page, so the row function does not emit it. - var keys = Keys(constName).Where(k => k != "captured_at").ToList(); - var row = RowSlice(method, close); - foreach (var key in keys) - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", row); - foreach (var key in omitted) - { - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + "( = |,\r?$)", row); - Assert.DoesNotContain(key, keys); - } - var emitted = Regex.Matches(row, "(?m)^\\s+[a-z_0-9]+( = |,$)").Count; - Assert.Equal(emittedCount, emitted); - Assert.Equal(emitted - omitted.Length, keys.Count); - } - - [Fact] - public void TheTabReadsGetFinOpsWithTheStorageGrowthViewAtEachLevel() - { - var tab = Tab(); - // Pins the databases-level read: view and the 24 hours it keeps (the databases level ignores the window). - Assert.Contains("const params = { server, view: \"storage_growth\", hours: HOURS };", tab); - Assert.Matches("(?m)^const HOURS = 24;$", tab); - // Pins the databases-level limit (#5238): the 500 the service honours at this level (MaxStorageGrowthDatabaseRows), not its default top 50. - Assert.Contains("if (state.level === \"databases\") params.limit = DATABASE_LIMIT;", tab); - var databaseLimit = Regex.Match(tab, "(?m)^const DATABASE_LIMIT = (\\d+);$"); - var serviceMax = Regex.Match(ToolSource(), "internal const int MaxStorageGrowthDatabaseRows = (\\d+);"); - Assert.True(databaseLimit.Success && serviceMax.Success); - Assert.Equal(500, int.Parse(serviceMax.Groups[1].Value)); - Assert.Equal(serviceMax.Groups[1].Value, databaseLimit.Groups[1].Value); - // Pins the objects-level read: the database plus the desktop's top 20, the most the view allows. - Assert.Contains("if (state.level === \"objects\") Object.assign(params, { database_name: state.database, limit: OBJECT_LIMIT, hours: state.days * 24 });", tab); - Assert.Matches("(?m)^const OBJECT_LIMIT = 20;$", tab); - // Pins the indexes-level read: no limit, because the view refuses any limit at this level. - Assert.Contains("if (state.level === \"indexes\") Object.assign(params, { database_name: state.database, object_name: state.object, hours: state.days * 24 });", tab); - // Pins the one call site that sends them. - Assert.Contains("readTool(\"get_finops\", params, ctx && ctx.signal)", tab); - Assert.Single(Regex.Matches(tab, "readTool\\(")); - } - - [Fact] - public void EveryDatabaseColumnKeyIsEmittedByTheDatabaseRow() => - // has_sibling_row and has_log_service_file are left out on purpose: the desktop grid shows neither, and the note says what they mean. - AssertKeysMatchRow("DATABASE_COLUMNS", "StorageGrowthDatabaseRow", "\n };", 13, "has_sibling_row", "has_log_service_file", "size_7d_ago_note", "size_30d_ago_note"); - - [Fact] - public void EveryObjectColumnKeyIsEmittedByTheObjectRow() => - // object_name and cells are left out on purpose: object_name is schema.table (already two columns), and cells feed the heatmap. - AssertKeysMatchRow("OBJECT_COLUMNS", "StorageGrowthObjectRows", "\n });", 11, "object_name", "cells"); - - [Fact] - public void EveryIndexColumnKeyIsEmittedByTheIndexRow() => - // database_name, schema_name, table_name and index_id are left out on purpose: the drill path already names the first three, and the desktop grid has no id column. - AssertKeysMatchRow("INDEX_COLUMNS", "StorageGrowthIndexRow", "\n };", 15, "database_name", "schema_name", "table_name", "index_id"); - - [Fact] - public void TheIndexCollectedColumnIsTheEnvelopeSnapshotTimeCopiedOntoEachRow() - { - // The read stamps one captured_at on the indexes section, not on each row (the desktop's Collected column, #5079). - Assert.Contains("captured_at: data.indexes.captured_at ?? null", Tab()); - Assert.Contains("{ key: \"captured_at\", label: \"Collected\", format: \"time\" },", Tab()); - Assert.Matches("(?m)^\\s+captured_at = ", ToolSource()); - } - - [Fact] - public void TheObjectViewCarriesTheDesktopsReservationNote() - { - Assert.Contains("Object / reserved footprint (daily). This is per-object reservation, not file allocation \\u2014 it may not fully explain a database's file-level growth (log / free space).", Tab()); - Assert.Contains("noticeStrip(OBJECT_GROWTH_NOTE)", Tab()); - } - - [Fact] - public void TheColumnsAreInTheDesktopGridOrder() - { - // Databases grid: FinOpsTab.xaml FinOpsStorageGrowthDataGrid (~:541-558), Note last. - Assert.Equal("database_name,current_size_mb,size_7d_ago_mb,size_30d_ago_mb,growth_7d_mb,growth_30d_mb,daily_growth_rate_mb,growth_pct_30d,note", string.Join(",", Keys("DATABASE_COLUMNS"))); - // Objects grid: FinOpsTab.xaml FinOpsObjectGrowthDetailGrid (~:571-583). - Assert.Equal("schema_name,table_name,reserved_mb,used_mb,total_rows,index_count,growth_mb,growth_pct,daily_growth_rate_mb", string.Join(",", Keys("OBJECT_COLUMNS"))); - // Indexes grid: FinOpsTab.xaml FinOpsObjectIndexDetailGrid (~:590-601). - Assert.Equal("index_name,classification,index_type_desc,reserved_mb,total_rows,user_seeks,user_scans,user_lookups,total_reads,user_updates,last_user_access_server_local,captured_at", string.Join(",", Keys("INDEX_COLUMNS"))); - } - - [Fact] - public void TheServerLocalLastAccessIsPlainTextNeverTheTimeFormatter() - { - var tab = Tab(); - Assert.Contains("{ key: \"last_user_access_server_local\", label: \"Last access (server time)\" },", tab); - Assert.DoesNotContain("last_user_access_server_local\", label: \"Last access (server time)\", format", tab); - } - - [Fact] - public void TheDayAxisIsLabelledUtcAndShowsTheFirstTenCharacters() - { - var tab = Tab(); - Assert.Contains("el(\"caption\", { text: \"Day (UTC)\" })", tab); - Assert.Contains("String(d).slice(0, 10)", tab); - } - - [Fact] - public void TheNoticesAreExact() - { - var tab = Tab(); - Assert.Contains("let text = n === 1 ? \"1 database\" : n + \" databases\";", tab); - Assert.Contains("text += s.truncated ? \"; the top \" + n + \" of \" + (s.database_count ?? \"more\") + \" by 30-day growth.\" : \".\";", tab); - Assert.Contains("let text = \"Top \" + (s.rows || []).length + \" objects by growth over the last \" + (s.window_days ?? \"?\") + \" days\";", tab); - Assert.Contains("text += s.truncated ? \"; more exist.\" : \".\";", tab); - Assert.Contains("let text = n === 1 ? \"1 index\" : n + \" indexes\";", tab); - Assert.Contains("text += s.truncated ? \"; the first \" + n + \" of \" + (s.index_count ?? \"more\") + \".\" : \".\";", tab); - // The indexes level's one snapshot stamp rides the notice line, worded by the shared helpers; the browser computes nothing. - Assert.Contains("if (typeof s.captured_at === \"string\" && s.captured_at) text += \" Collected \" + relTime(s.captured_at) + \" (\" + localTime(s.captured_at) + \").\";", tab); - Assert.Contains("Shade: the service's size band for each cell (log scale over this table); blank means no sample or zero.", tab); - } - - [Fact] - public void TheHeatmapClassComesOnlyFromTheServiceBandAndTheBrowserComputesNothing() - { - var tab = Tab(); - // The class is built from the band alone; nothing else in the tab mentions the class family. - Assert.Contains("const known = Number.isInteger(shade) && shade >= 0 && shade <= 7;", tab); - Assert.Contains("class: known ? \"num heat-band-\" + shade : \"num\",", tab); - Assert.Single(Regex.Matches(tab, "heat-band")); - Assert.DoesNotContain("Math.", tab); - Assert.Contains("title: r.schema_name + \".\" + r.table_name + \" | \" + String(d).slice(0, 10) + \" | \" + applyFormat(\"num1\", mb) + \" MB reserved\",", tab); - } - - [Fact] - public void TheCssHasExactlyEightBandRulesZeroThroughSeven() - { - var found = Regex.Matches(Css(), "(?m)^\\.heat-band-([0-9]+) \\{").Select(m => m.Groups[1].Value).ToList(); - Assert.Equal("0,1,2,3,4,5,6,7", string.Join(",", found)); - Assert.Equal(8, Regex.Matches(Css(), "heat-band-").Count); - } - - [Fact] - public void TheDrillBackAndBreadcrumbArePresent() - { - var tab = Tab(); - Assert.Contains("const state = drillFor(server);", tab); - Assert.Contains("drillColumn(\"Show objects\", openObjects)", tab); - Assert.Contains("drillColumn(\"Show indexes\", openIndexes)", tab); - Assert.Contains("el(\"button\", { type: \"button\", class: \"btn\", text: \"Back\", onClick: back })", tab); - Assert.Contains("parts.join(\" › \")", tab); - Assert.Contains("const parts = [\"Storage Growth\"];", tab); - // A refusal or error on a drill keeps Back: the error strip goes through the same chrome. - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"error\"\\) return chrome\\(\\[readErrorStrip\\(res\\.message\\)\\]\\);$", tab); - } - - [Fact] - public void TheDrillLivesAtModuleScopeSoTheRepaintKeepsIt() - { - var tab = Tab(); - Assert.Matches("(?m)^const drills = new Map\\(\\);$", tab); - Assert.Contains("drills.get(server)", tab); - var build = tab.Substring(tab.IndexOf("build(server, ctx)", System.StringComparison.Ordinal)); - Assert.DoesNotContain("level: \"databases\"", build); - Assert.DoesNotContain("new Map(", build); - } - - [Fact] - public void ARestoredIndexesReadForAGoneObjectDropsBackToObjects() - { - var tab = Tab(); - Assert.Contains("const OBJECT_GONE = \"is not among the\";", tab); - // The tab's drop-back depends on this refusal wording in the C# message. - Assert.Contains("is not among the", ToolSource()); - Assert.Contains("if (res.kind === \"error\" && state.level === \"indexes\" && String(res.message).includes(OBJECT_GONE)) {\n state.level = \"objects\";", tab.Replace("\r\n", "\n")); - } - - [Fact] - public void LastAccessShowsMinutesAndTheDarkTextSitsOnTheStrongBands() - { - Assert.Contains("String(v).slice(0, 16).replace(\"T\", \" \")", Tab()); - var css = Css(); - foreach (var b in new[] { 5, 6, 7 }) Assert.Matches("(?m)^\\.heat-band-" + b + " \\{ color: var\\(--bg\\);", css); - foreach (var b in new[] { 0, 1, 2, 3, 4 }) Assert.DoesNotMatch("(?m)^\\.heat-band-" + b + " \\{ color:", css); - } - - [Fact] - public void EachSectionReadsItsOwnStatusAndMapsTheThreeStates() - { - var tab = Tab(); - Assert.Contains("if (s.status === \"ok\") return [noticeStrip(notice(s)), VIZ.table(", tab); - Assert.Contains("if (s.status === \"empty\") return [emptyStrip(emptyText)];", tab); - Assert.Contains("return [noticeStrip(s.message ?? \"This section was not collected.\")];", tab); - } - - [Fact] - public void TheReadStatesAreHandled() - { - var tab = Tab(); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$", tab); - Assert.Matches("(?m)^\\s+if \\(res\\.kind === \"empty\"\\) return chrome\\(\\[gatedEmptyStrip\\(res, ctx\\)\\]\\);$", tab); - Assert.Contains("Could not render this tab: ", tab); - } - - [Fact] - public void TheTabImportsOnlyWhatItUses() - { - var tab = Tab(); - var imports = Regex.Matches(tab, "from \"([^\"]+)\";").Select(m => m.Groups[1].Value).ToList(); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../util.js", "./gate.js", "./window.js" })); - Assert.Contains("./gate.js", imports); - var names = Regex.Match(tab, "import \\{([^}]*)\\} from \"../../util.js\"").Groups[1].Value.Split(',').Select(n => n.Trim()); - var body = tab.Substring(tab.IndexOf("const HOURS", System.StringComparison.Ordinal)); - Assert.All(names, n => Assert.Contains(n + "(", body)); - } - - [Fact] - public void TheStubTextIsGone() - { - Assert.DoesNotContain("Not on the web yet", Tab()); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabSystemEventsColumnsPageTests.cs b/Darling/Darling.Tests/FinOpsTabSystemEventsColumnsPageTests.cs deleted file mode 100644 index 8fa7ab2c5c..0000000000 --- a/Darling/Darling.Tests/FinOpsTabSystemEventsColumnsPageTests.cs +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// -/// Source pins for the System Events tab's parsed-row grids: each grid's column keys are fields its read -/// returns, and the wide grids show every field the read returns, in the desktop grid's order. -/// -public sealed class FinOpsTabSystemEventsColumnsPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "server-tabs.js") - .ReplaceLineEndings("\n"); - - private static string Source(string file) => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", file).ReplaceLineEndings("\n"); - - /// The keys of a top-level column constant, in order. - private static List Keys(string constName) - { - var tab = Tab(); - var start = tab.IndexOf("const " + constName + " = [", StringComparison.Ordinal); - Assert.True(start >= 0, constName + " not found"); - var end = tab.IndexOf("\n];", start, StringComparison.Ordinal); - return Regex.Matches(tab[start..end], "\\bkey: \"([a-z_]+)\"").Select(m => m.Groups[1].Value).ToList(); - } - - /// The field names of the anonymous object a read projects with .Select(r => new. - private static List Projection(string file, string tool) - { - var src = Source(file); - var start = src.IndexOf("Name = \"" + tool + "\"", StringComparison.Ordinal); - Assert.True(start >= 0, tool + " not found"); - var next = src.IndexOf("McpServerTool(Name", start + 10, StringComparison.Ordinal); - var seg = next > 0 ? src[start..next] : src[start..]; - var sel = seg.IndexOf("Select(r =>", StringComparison.Ordinal); - Assert.True(sel >= 0, tool + " has no row projection"); - var close = seg.IndexOf("\n })", sel, StringComparison.Ordinal); - if (close < 0) close = seg.IndexOf("\n }", sel, StringComparison.Ordinal); - return Regex.Matches(seg[sel..close], "^\\s+([a-z_]+) = ", RegexOptions.Multiline).Select(m => m.Groups[1].Value).ToList(); - } - - public static IEnumerable Grids() => new[] - { - new object[] { "SEVERE_ERROR_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_severe_errors" }, - new object[] { "SCHEDULER_ISSUE_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_scheduler_issues" }, - new object[] { "IO_ISSUE_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_io_issues" }, - new object[] { "CPU_TASK_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_cpu_tasks" }, - new object[] { "MEMORY_CONDITION_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_memory_conditions" }, - new object[] { "MEMORY_BROKER_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_memory_broker" }, - new object[] { "MEMORY_OOM_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_memory_node_oom" }, - new object[] { "SIGNIFICANT_WAIT_COLUMNS", "DarlingMcpHealthParserTools.cs", "get_health_parser_significant_waits" }, - new object[] { "DEFAULT_TRACE_COLUMNS", "DarlingMcpDefaultTraceTools.cs", "get_default_trace_events" }, - }; - - [Theory] - [MemberData(nameof(Grids))] - public void EveryColumnKeyIsAFieldTheReadReturns(string constName, string file, string tool) - { - var keys = Keys(constName); - var fields = Projection(file, tool); - Assert.NotEmpty(keys); - Assert.NotEmpty(fields); - Assert.Empty(keys.Except(fields)); - Assert.Equal(keys.Count, keys.Distinct().Count()); - } - - [Fact] - public void TheMemoryConditionGridShowsAllThirtyTwoFieldsInTheDesktopOrder() - { - Assert.Equal(new[] - { - "event_time", "last_notification", "name", "out_of_memory_exceptions", "is_any_pool_out_of_memory", - "process_out_of_memory_period", "available_physical_memory_gb", "available_virtual_memory_gb", - "available_paging_file_gb", "working_set_gb", "percent_of_committed_memory_in_ws", "page_faults", - "system_physical_memory_high", "system_physical_memory_low", "process_physical_memory_low", - "process_virtual_memory_low", "vm_reserved_gb", "vm_committed_gb", "locked_pages_allocated", - "large_pages_allocated", "emergency_memory_gb", "emergency_memory_in_use_gb", "target_committed_gb", - "current_committed_gb", "pages_allocated", "pages_reserved", "pages_free", "pages_in_use", - "page_alloc_potential", "numa_growth_phase", "last_oom_factor", "last_os_error", - }, Keys("MEMORY_CONDITION_COLUMNS")); - } - - [Fact] - public void TheNodeOomGridShowsAllTwentyEightFieldsInTheDesktopOrder() - { - Assert.Equal(new[] - { - "event_time", "node_id", "memory_node_id", "memory_utilization_pct", "total_physical_memory_kb", - "available_physical_memory_kb", "total_page_file_kb", "available_page_file_kb", - "total_virtual_address_space_kb", "available_virtual_address_space_kb", "target_kb", "reserved_kb", - "committed_kb", "shared_committed_kb", "awe_kb", "pages_kb", "failure_type", "failure_value", - "resources", "factor_text", "factor_value", "last_error", "pool_metadata_id", "is_process_in_job", - "is_system_physical_memory_high", "is_system_physical_memory_low", "is_process_physical_memory_low", - "is_process_virtual_memory_low", - }, Keys("MEMORY_OOM_COLUMNS")); - } - - [Fact] - public void TheDefaultTraceGridShowsTheDesktopFourteenColumns() - { - Assert.Equal(new[] - { - "event_time", "category", "event_name", "database_name", "object_name", "login_name", "host_name", - "application_name", "spid", "duration_ms", "growth_mb", "severity", "error_number", "text_data", - }, Keys("DEFAULT_TRACE_COLUMNS")); - } - - [Fact] - public void TheOtherParsedGridsShowTheDesktopColumns() - { - Assert.Equal(new[] { "event_time", "error_number", "severity", "state", "database_name", "database_id", "message" }, Keys("SEVERE_ERROR_COLUMNS")); - Assert.Equal(new[] { "event_time", "sql_cpu_utilization", "other_process_cpu", "system_idle", "memory_utilization", "page_faults", "working_set_delta_mb" }, Keys("SCHEDULER_ISSUE_COLUMNS")); - Assert.Equal(new[] { "event_time", "broker_id", "broker", "notification", "pool_metadata_id", "delta_time", "memory_ratio", "new_target", "overall", "rate", "currently_predicated", "currently_allocated", "previously_allocated" }, Keys("MEMORY_BROKER_COLUMNS")); - Assert.Equal(new[] { "event_time", "state", "max_workers", "workers_created", "workers_idle", "tasks_completed_within_interval", "pending_tasks", "oldest_pending_task_waiting_time", "has_unresolvable_deadlock_occurred", "has_deadlocked_schedulers_occurred", "did_blocking_occur" }, Keys("CPU_TASK_COLUMNS")); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabUtilizationPageTests.cs b/Darling/Darling.Tests/FinOpsTabUtilizationPageTests.cs deleted file mode 100644 index dc4afae583..0000000000 --- a/Darling/Darling.Tests/FinOpsTabUtilizationPageTests.cs +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// Source pins for the FinOps Utilization tab's verdict, summary, trend and top-database grids: the reads it makes and the keys it shows. -public sealed class FinOpsTabUtilizationPageTests -{ - private static string Tab() => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", "utilization.js") - .ReplaceLineEndings("\n"); - - private static string Mcp(string name) => - ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "Mcp", name).ReplaceLineEndings("\n"); - - private static string UtilizationSource() => Mcp("DarlingMcpFinOpsTools.Utilization.cs"); - - private static string DatabaseResourcesSource() => Mcp("DarlingMcpFinOpsTools.DatabaseResources.cs"); - - private static string Between(string s, string from, string? to) - { - var a = s.IndexOf(from, System.StringComparison.Ordinal); - Assert.True(a >= 0, from); - var b = to is null ? s.Length : s.IndexOf(to, a, System.StringComparison.Ordinal); - Assert.True(b > a, to); - return s.Substring(a, b - a); - } - - private static System.Collections.Generic.List KeysIn(string block) => - Regex.Matches(block, "\\b(?:key|nullKey|sevKey): \"([a-z_.0-9]+)\"").Select(m => m.Groups[1].Value).ToList(); - - [Fact] - public void TheTabReadsTheUtilizationViewWithNoWindowOrLimit() - { - Assert.Contains("readTool(\"get_finops\", { server, view: \"utilization\" }, ctx && ctx.signal)", Tab()); - } - - [Fact] - public void TheTabReadsDatabaseResourcesForTheDesktopsFixed24HoursAndTop5() - { - var tab = Tab(); - Assert.Contains("const TOP_HOURS = 24;", tab); - Assert.Contains("const TOP_LIMIT = 5;", tab); - Assert.Contains("view: \"database_resources\", hours: TOP_HOURS, limit: TOP_LIMIT", tab); - Assert.DoesNotContain("hours_back", tab); - } - - [Fact] - public void EveryUtilizationKeyShownIsEmittedByTheUtilizationView() - { - var tab = Tab(); - Assert.Contains("const DERIVED_KEYS = [\"verdict_label\", \"verdict_sev\", \"day_label\", \"monthly_cost_text\", \"annual_cost_text\", \"workers_in_use\"];", tab); - var derived = new[] { "verdict_label", "verdict_sev", "day_label", "monthly_cost_text", "annual_cost_text", "workers_in_use" }; - var block = Between(tab, "/* utilization-keys:begin */", "/* utilization-keys:end */"); - var summary = Between(block, "const SUMMARY_STATS", "const TREND_COLUMNS"); - var trendCols = Between(block, "const TREND_COLUMNS", null); - var source = UtilizationSource(); - // Each key is checked inside the object that emits it, so a leaf name that two objects share (avg_cpu_pct in - // cpu and in the trend, memory_ratio in memory and in the trend) cannot be satisfied by the wrong one. - var cpu = Between(source, "cpu = new", "memory = new"); - var memory = Between(source, "memory = new", "monthly_cost_usd = "); - var trend = source.Substring(source.IndexOf("provisioning_trend = ", System.StringComparison.Ordinal)); - var topLevel = string.Join("\n", source.Split('\n').Where(l => Regex.IsMatch(l, "^ {12}[a-z_0-9]+ = "))); - var checkedCount = 0; - void Emitted(string key, string slice) - { - Assert.Matches("(?m)^\\s+" + Regex.Escape(key) + " = ", slice); - checkedCount++; - } - var summaryKeys = KeysIn(summary).Concat( - Regex.Matches(summary, "(?:showWhen|hideWhen): \\{ key: \"([a-z_.]+)\"").Select(m => m.Groups[1].Value)) - .Where(k => !derived.Contains(k)).Distinct().ToList(); - Assert.NotEmpty(summaryKeys); - foreach (var key in summaryKeys) - { - var parts = key.Split('.'); - if (parts.Length == 1) Emitted(key, topLevel); - else if (parts[0] == "cpu") Emitted(parts[1], cpu); - else if (parts[0] == "memory") Emitted(parts[1], memory); - else Assert.Fail("unmapped summary key " + key); - } - var trendKeys = KeysIn(trendCols).Where(k => !derived.Contains(k)).Distinct().ToList(); - Assert.Equal(new[] { "avg_cpu_pct", "max_cpu_pct", "memory_ratio", "p95_cpu_pct" }, trendKeys.OrderBy(k => k, System.StringComparer.Ordinal)); - foreach (var key in trendKeys) Emitted(key, trend); - Assert.True(checkedCount > 10); - foreach (var key in new[] { "provisioning_trend", "verdict_reason", "health_score_note", "monthly_cost_usd", "annual_cost_usd", "current_workers", "health_band" }) - { - Assert.Contains(key, tab); - Assert.Matches("(?m)^\\s+" + key + " = ", source); - } - } - - [Fact] - public void TheSummaryNamesItsWindowAndFormatsMaxCpuAsAnInteger() - { - var tab = Tab(); - Assert.Contains("const SUMMARY_SUBTITLE = \"Last 24 hours\";", tab); - Assert.Contains("el(\"span\", { class: \"panel-sub\", text: \" \" + SUMMARY_SUBTITLE })", tab); - Assert.Contains("{ key: \"cpu.max_cpu_pct\", label: \"Max SQL Server CPU %\", format: \"int\" }", tab); - Assert.True(tab.IndexOf("SUMMARY_SUBTITLE })", System.StringComparison.Ordinal) < tab.IndexOf("VIZ.stat(view", System.StringComparison.Ordinal)); - } - - [Fact] - public void EveryTopDatabaseColumnIsEmittedByItsRowShape() - { - var tab = Tab(); - var block = Between(tab, "/* top-keys:begin */", "/* top-keys:end */"); - var total = KeysIn(Between(block, "const TOP_TOTAL_COLUMNS", "const TOP_AVG_COLUMNS")); - var avg = KeysIn(Between(block, "const TOP_AVG_COLUMNS", null)); - Assert.NotEmpty(total); - Assert.NotEmpty(avg); - var src = DatabaseResourcesSource(); - var totalSlice = Between(src, "TopByTotalRow(", "TopByAvgRow("); - var avgSlice = src.Substring(src.IndexOf("TopByAvgRow(", System.StringComparison.Ordinal)); - foreach (var k in total) Assert.Matches("(?m)^\\s+" + k + " = ", totalSlice); - foreach (var k in avg) Assert.Matches("(?m)^\\s+" + k + " = ", avgSlice); - Assert.Matches("(?m)^\\s+top_by_total = ", src); - Assert.Matches("(?m)^\\s+top_by_avg = ", src); - Assert.Contains("rowsKey: \"top_by_total\"", tab); - Assert.Contains("rowsKey: \"top_by_avg\"", tab); - } - - [Fact] - public void BothReadsHandleAbortAuthErrorAndEmptyOnTheirOwnContainer() - { - var tab = Tab(); - Assert.Equal(2, Regex.Matches(tab, "(?m)^\\s+if \\(res\\.kind === \"aborted\" \\|\\| res\\.kind === \"auth\"\\) return;$").Count); - Assert.Equal(2, Regex.Matches(tab, Regex.Escape("gatedEmptyStrip(res, ctx)")).Count); - Assert.Equal(2, Regex.Matches(tab, Regex.Escape("readErrorStrip(res.message)")).Count); - Assert.Equal(2, Regex.Matches(tab, Regex.Escape("\"Could not render this tab: \"")).Count); - Assert.DoesNotContain("Promise.all", tab); - } - - [Fact] - public void TheVerdictAndBandAreColouredFromServiceLabels() - { - var tab = Tab(); - Assert.Contains("const VERDICT_SEV = { RIGHT_SIZED: \"Healthy\", OVER_PROVISIONED: \"Warning\", UNDER_PROVISIONED: \"Critical\" };", tab); - Assert.Contains("const BAND_SEV = { good: \"Healthy\", fair: \"Warning\", poor: \"Critical\" };", tab); - Assert.Contains("sev: BAND_SEV[data.health_band]", tab); - Assert.Contains("\"N/A\"", tab); - Assert.Contains("health_band = score is int scoreValue ? FinOpsUtilizationFigures.HealthBand(scoreValue) : null", UtilizationSource()); - var figures = ReadRepoFile("Darling", "PerformanceMonitor.Darling.Storage", "FinOps", "FinOpsUtilizationFigures.cs"); - Assert.Contains("BandGood = \"good\"", figures); - Assert.Contains("BandFair = \"fair\"", figures); - Assert.Contains("BandPoor = \"poor\"", figures); - } - - [Fact] - public void CostTilesShowOnlyWhenTheServiceSetsACost() - { - var tab = Tab(); - Assert.Contains("data.monthly_cost_usd != null", tab); - Assert.Contains("\"/mo\"", tab); - Assert.Contains("\"/yr\"", tab); - Assert.Contains("hasCost || (s.key !== \"monthly_cost_text\"", tab); - } - - [Fact] - public void TheTrendIsCollapsedAndHasTheDesktopColumns() - { - var tab = Tab(); - Assert.Contains("el(\"details\"", tab); - Assert.DoesNotContain("el(\"details\", { open", tab); - Assert.Contains("\"7-Day Provisioning Trend\"", tab); - Assert.Contains("timeZone: \"UTC\"", tab); - var cols = KeysIn(Between(tab, "const TREND_COLUMNS", "/* utilization-keys:end */")).Where(k => k != "verdict_sev").ToList(); - Assert.Equal(new[] { "day_label", "verdict_label", "avg_cpu_pct", "p95_cpu_pct", "max_cpu_pct", "memory_ratio" }, cols); - } - - [Fact] - public void TheTabNeverWritesMarkup() - { - var tab = Tab(); - foreach (var bad in new[] { "innerHTML", "insertAdjacentHTML", "html:", "outerHTML" }) - Assert.DoesNotContain(bad, tab); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabUtilizationRawPageTests.cs b/Darling/Darling.Tests/FinOpsTabUtilizationRawPageTests.cs deleted file mode 100644 index 4c3b56f865..0000000000 --- a/Darling/Darling.Tests/FinOpsTabUtilizationRawPageTests.cs +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System; -using System.Linq; -using System.Text.RegularExpressions; -using Xunit; -using static Darling.Tests.RepoFile; - -namespace Darling.Tests; - -/// -/// Source pins for the FinOps Utilization tab's raw panels (#4843): the CPU chart, memory tiles and database -/// size table, each over a read that already exists. Text scans, like . -/// -public sealed class FinOpsTabUtilizationRawPageTests -{ - private static readonly string[] Svc = ["Darling", "PerformanceMonitor.Darling.Service"]; - - private static string Tab() => - ReadRepoFileLf(Svc.Concat(["wwwroot", "js", "pages", "finops", "utilization.js"]).ToArray()).ReplaceLineEndings("\n"); - - private static string Cs(params string[] rel) => - ReadRepoFileLf(rel).ReplaceLineEndings("\n"); - - [Fact] - public void TheTab_CallsTheThreeExistingReadsWithItsParams() - { - var src = Tab(); - Assert.Contains("read: \"get_cpu_utilization\"", src); - Assert.Contains("params: { server, hours: CPU_HOURS }", src); - Assert.Contains("const CPU_HOURS = 24;", src); - Assert.Contains("read: \"get_memory_stats\"", src); - Assert.Contains("read: \"get_database_sizes\"", src); - Assert.Contains("viz: \"line\"", src); - Assert.Contains("viz: \"stat\"", src); - Assert.Contains("viz: \"table\"", src); - } - - /// The text from up to the next occurrence of , so a key is - /// matched inside the one method that emits it and not anywhere in a large file. - private static string Slice(string src, string start, string end) - { - var i = src.IndexOf(start, StringComparison.Ordinal); - Assert.True(i >= 0, "missing: " + start); - var j = src.IndexOf(end, i + start.Length, StringComparison.Ordinal); - Assert.True(j > i, "missing end: " + end); - return src.Substring(i, j - i); - } - - [Fact] - public void EveryColumnKeyShown_IsEmittedByItsReadsSource() - { - var src = Tab(); - var trend = Cs("PerformanceMonitor.Common", "Mcp", "TrendPayloads.cs"); - var data = Cs(Svc.Concat(["Mcp", "DarlingMcpDataTools.cs"]).ToArray()); - var sizes = Cs(Svc.Concat(["Mcp", "DarlingMcpObjectStatsTools.cs"]).ToArray()); - var sibling = Cs("PerformanceMonitor.Common", "AzureSiblingDatabaseSize.cs"); - - // The CPU series come from the shared catalog; pin that, then that the read emits every key the catalog names. - Assert.Contains("READ_FIELDS.get_cpu_utilization.line.series", src); - var cpu = Slice(trend, "public static string CpuUtilization(", "TempDbFiguresNote"); - foreach (var k in new[] { "sample_time", "sql_server_cpu", "other_process_cpu", "total_cpu" }) - Assert.Contains(k + " = ", cpu); - - var memory = Slice(data, "internal static string MemoryStatsPayload(", "[McpServerTool(Name = \"get_memory_clerks\")"); - foreach (var k in new[] - { - "captured_at", "total_physical_memory_mb", "available_physical_memory_mb", "memory_utilization_pct", "total_server_memory_mb", - "target_server_memory_mb", "buffer_pool_mb", "plan_cache_mb", "system_memory_state", "system_memory_state_note", - "sql_memory_model", "engine_edition", - }) - { - Assert.Contains("\"" + k + "\"", src); - Assert.Contains(k + " = ", memory); - } - - Assert.Contains("ServerHardwareScope.WithMemoryNote(", memory); - Assert.Contains("\"memory_note\"", src); - - // The per-database payload only: FilePayload's per-file keys must not satisfy these. - Assert.Contains("READ_FIELDS.get_database_sizes.table.columns", src); - var perDatabase = Slice(sizes, "internal static string DatabaseSizesPayload(", "private static Dictionary FilePayload("); - foreach (var k in new[] { "database_name", "total_size_mb", "used_size_mb" }) - Assert.Contains("[\"" + k + "\"] =", perDatabase); - Assert.Matches(new Regex("\\n\\s+databases\\n"), perDatabase); - Assert.Contains("captured_at = ", perDatabase); - Assert.Contains("AzureSiblingDatabaseSize.RowNoteKey", perDatabase); - Assert.Contains("RowNoteKey = \"size_note\"", sibling); - Assert.Contains("\"captured_at\"", src); - } - - [Fact] - public void TheMemoryTiles_NameTheLimitOnAnAzureSqlDatabase_AndShowTheMemoryNote() - { - var src = Tab().ReplaceLineEndings("\n"); - Assert.Contains("const AZURE_SQL_DATABASE = { key: \"engine_edition\", equals: 5 };", src); - Assert.Contains("{ key: \"total_physical_memory_mb\", label: \"Physical\", format: \"mb\", hideWhen: AZURE_SQL_DATABASE }", src); - Assert.Contains("{ key: \"total_physical_memory_mb\", label: \"Memory limit\", format: \"mb\", showWhen: AZURE_SQL_DATABASE }", src); - Assert.Contains("{ key: \"available_physical_memory_mb\", label: \"Available\", format: \"mb\", hideWhen: AZURE_SQL_DATABASE }", src); - Assert.Contains("{ key: \"available_physical_memory_mb\", label: \"Available under limit\", format: \"mb\", showWhen: AZURE_SQL_DATABASE }", src); - Assert.Contains("noteKey: \"memory_note\"", src); - - // Same predicate as the Server page, so the two cannot drift. - var server = Cs(Svc.Concat(["wwwroot", "js", "pages", "server-tabs.js"]).ToArray()); - Assert.Contains("const AZURE_SQL_DATABASE = { key: \"engine_edition\", equals: 5 };", server); - } - - [Fact] - public void TheMemoryPanel_ShowsWhenItWasCollected_AndTheSizesAreReadOnce() - { - var src = Tab(); - var tile = "{ key: \"captured_at\", label: \"Collected\", format: \"reltime\", small: true }"; - Assert.Single(Regex.Matches(src, Regex.Escape(tile))); - Assert.Single(Regex.Matches(src, "read: \"get_database_sizes\"")); - Assert.Contains("reltime: relTime,", ReadRepoFileLf(Svc.Concat(["wwwroot", "js", "util.js"]).ToArray()).ReplaceLineEndings("\n")); - } - - [Fact] - public void TheTab_ImportsOnlyFromTheSharedModules() - { - var imports = Regex.Matches(Tab(), "from \"([^\"]+)\"").Select(m => m.Groups[1].Value).ToList(); - Assert.NotEmpty(imports); - Assert.All(imports, i => Assert.Contains(i, new[] { "../../panels.js", "../../charts.js", "../../util.js", "../../read-fields.js", "../../plain-text.js", "./gate.js" })); - Assert.Contains("./gate.js", imports); - } - - [Fact] - public void TheTab_IsNoLongerTheShellStub_AndHasOneContainerPerSection() - { - var src = Tab(); - foreach (var id in new[] { "verdict", "top", "cpu", "memory", "sizes" }) - Assert.Contains("section(\"" + id + "\"", src); - Assert.DoesNotContain("Coming:", src); - Assert.DoesNotContain("Not on the web yet", src); - } -} diff --git a/Darling/Darling.Tests/FinOpsTabsParseUnderNodeTests.cs b/Darling/Darling.Tests/FinOpsTabsParseUnderNodeTests.cs new file mode 100644 index 0000000000..192f410f11 --- /dev/null +++ b/Darling/Darling.Tests/FinOpsTabsParseUnderNodeTests.cs @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2026 Erik Darling, Darling Data LLC + * + * This file is part of the SQL Server Performance Monitor. + * + * Licensed under the MIT License. See LICENSE file in the project root for full license information. + */ + +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using Xunit; +using static Darling.Tests.RepoFile; + +namespace Darling.Tests; + +/// +/// Runs node --check on FinOps tab scripts, so a syntax error that would blank the tab in the browser fails here. +/// (The other FinOps page text pins were deleted in #6486; this is the one that executes a tool.) +/// +public sealed class FinOpsTabsParseUnderNodeTests +{ + [Theory] + [InlineData("index-analysis.js")] + [InlineData("recommendations.js")] + [InlineData("server-inventory.js")] + public async System.Threading.Tasks.Task TheTabParsesUnderNode(string tabFile) + { + var source = ReadRepoFile("Darling", "PerformanceMonitor.Darling.Service", "wwwroot", "js", "pages", "finops", tabFile); + var path = Path.Combine(Path.GetTempPath(), "finops-tab-" + System.Guid.NewGuid().ToString("N") + ".mjs"); + File.WriteAllText(path, source); + try + { + var psi = new ProcessStartInfo("node") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; + psi.ArgumentList.Add("--check"); + psi.ArgumentList.Add(path); + Process proc; + try + { + proc = Process.Start(psi)!; + } + catch (Win32Exception) + { + Assert.Skip("Node is not installed, so the tab script cannot be parsed."); + throw; + } + + using (proc) + { + var error = proc.StandardError.ReadToEndAsync(); + if (!proc.WaitForExit(20000)) + { + proc.Kill(entireProcessTree: true); + Assert.Fail("node --check did not finish in 20 s"); + } + + Assert.True(proc.ExitCode == 0, "node --check failed on " + tabFile + ": " + await error); + } + } + finally + { + File.Delete(path); + } + } +} diff --git a/Darling/Darling.Tests/ViewerFinOpsOptimizationDelegatesTests.cs b/Darling/Darling.Tests/ViewerFinOpsOptimizationDelegatesTests.cs deleted file mode 100644 index f2fe8b804b..0000000000 --- a/Darling/Darling.Tests/ViewerFinOpsOptimizationDelegatesTests.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2026 Erik Darling, Darling Data LLC - * - * This file is part of the SQL Server Performance Monitor. - * - * Licensed under the MIT License. See LICENSE file in the project root for full license information. - */ - -using System; -using System.IO; -using PerformanceMonitor.Darling.Storage.FinOps; -using PerformanceMonitor.Darling.Viewer; -using Xunit; - -namespace Darling.Tests; - -/// Source pins: the viewer's four Optimization reads stay thin delegates to the storage reader. -public sealed class ViewerFinOpsOptimizationDelegatesTests -{ - private static string ViewerFile(string name) - { - var dir = AppContext.BaseDirectory; - while (dir != null && !Directory.Exists(Path.Combine(dir, "PerformanceMonitor.Darling.Viewer"))) - dir = Path.GetDirectoryName(dir); - Assert.NotNull(dir); - return File.ReadAllText(Path.Combine(dir!, "PerformanceMonitor.Darling.Viewer", name)).ReplaceLineEndings("\n"); - } - - private static readonly string[] SqlMarkers = - { - "db_activity AS", "v_tempdb_stats", "WITH per_spelling AS", "LEFT(query_text, 200)", - }; - - [Fact] - public void TheViewerPartials_HoldNoneOfTheFourSqlTexts() - { - var combined = ViewerFile("ViewerDataService.FinOps.Storage.cs") + ViewerFile("ViewerDataService.FinOps.Workload.cs"); - foreach (var marker in SqlMarkers) - Assert.DoesNotContain(marker, combined); - } - - [Theory] - /* The idle read is GetIdleDatabaseReadAsync (rows plus whether the last 7 UTC days are covered); GetIdleDatabasesAsync is a one-line wrapper over it. */ - [InlineData("ViewerDataService.FinOps.Storage.cs", "GetIdleDatabaseReadAsync(int serverId", "DarlingFinOpsOptimizationReader.GetIdleDatabaseReadAsync(", "IdleDatabaseRow.From")] - [InlineData("ViewerDataService.FinOps.Storage.cs", "GetTempdbSummaryAsync(", "DarlingFinOpsOptimizationReader.GetTempdbSummaryAsync(", "TempdbSummaryRow.From")] - [InlineData("ViewerDataService.FinOps.Workload.cs", "GetWaitCategorySummaryAsync(", "DarlingFinOpsOptimizationReader.GetWaitCategorySummaryAsync(", "WaitCategorySummaryRow.From")] - [InlineData("ViewerDataService.FinOps.Workload.cs", "GetExpensiveQueriesAsync(", "DarlingFinOpsOptimizationReader.GetExpensiveQueriesAsync(", "ExpensiveQueryRow.From")] - public void EachRead_CallsTheStorageReaderAndMapsThroughFrom(string file, string method, string call, string map) - { - var src = ViewerFile(file); - var at = src.IndexOf("public async Task<", src.IndexOf(method, StringComparison.Ordinal) - 80, StringComparison.Ordinal); - Assert.True(at >= 0); - var tail = src[at..]; - Assert.Contains(call, tail); - Assert.Contains(map, tail); - Assert.Contains("ViewerCommandDeadlines.CurrentInteractiveReadSeconds", tail); - } - - [Fact] - public void EachViewerConstant_IsTheStorageConstant() - { - Assert.Equal(DarlingFinOpsOptimizationReader.IdleDatabasesSql, ViewerDataService.IdleDatabasesSql); - Assert.Equal(DarlingFinOpsOptimizationReader.TempdbSummarySql, ViewerDataService.TempdbSummarySql); - Assert.Equal(DarlingFinOpsOptimizationReader.WaitCategorySummarySql, ViewerDataService.WaitCategorySummarySql); - Assert.Equal(DarlingFinOpsOptimizationReader.ExpensiveQueriesSql, ViewerDataService.ExpensiveQueriesSql); - var combined = ViewerFile("ViewerDataService.FinOps.Storage.cs") + ViewerFile("ViewerDataService.FinOps.Workload.cs"); - foreach (var name in new[] { "IdleDatabasesSql", "TempdbSummarySql", "WaitCategorySummarySql", "ExpensiveQueriesSql" }) - Assert.Contains($"public const string {name} = DarlingFinOpsOptimizationReader.{name};", combined); - } -} From 5e3b491f8fb9c7a8110f9fff72b1f4f40ff86c54 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:30:51 -0400 Subject: [PATCH 008/294] Make ci-select.py read and parse each test file once, so the replay and census tests finish fast (#6346) (#6349) * Give the ci-select replay guard tests a hang guard that a slow disk does not trip (#6346) * Make ci-select.py read and parse each test file once per process (#6346) The replay walked and opened every test source file three times (class scan, slow-class scan, Reads detector), and the symbol index and slow text opened them again. Read each file once into a per-process cache (invalidated by size and mtime), parse each file's classes once, prefetch the opens on a few threads, and test the slow-class odd stems with a substring check before the regex. Output is unchanged. The replay tests' wait goes back to 120 s. --- .github/scripts/ci-select.py | 184 ++++++++++++++++++++++++----------- 1 file changed, 127 insertions(+), 57 deletions(-) diff --git a/.github/scripts/ci-select.py b/.github/scripts/ci-select.py index 3c8ba5b249..25f253cb01 100644 --- a/.github/scripts/ci-select.py +++ b/.github/scripts/ci-select.py @@ -41,6 +41,7 @@ from __future__ import annotations import argparse +import concurrent.futures import datetime import gzip import json @@ -398,48 +399,118 @@ def split_failed_class(cls: str) -> tuple[str, str]: return head.rpartition(".")[0], re.split(r"[.+/]", cls)[-1] +_SOURCES: "dict[str, list]" = {} + + +def _open_text(path: str, errors: str) -> str: + with open(path, encoding="utf-8-sig", errors=errors) as fh: + return fh.read() + + +def read_source(path: str, errors: str = "strict") -> str: + """The text of one test source, read at most once per process (#6346). A replay or a selection reads every test + file for several rules (the class walk, the slow-class text, the Reads detector, the symbol index) and each used + to open it again: about 3,300 files, three or four times over, which a slow disk turned into minutes. The entry + is dropped when the file's size or modification time changes, so a caller that edits a tree and reads it again + sees the new text. Decoding is the same as open(): "replace" returns the strict text when that decodes.""" + st = os.stat(path) + stamp = (st.st_mtime_ns, st.st_size) + ent = _SOURCES.get(path) + if ent is None or ent[0] != stamp: + ent = _SOURCES[path] = [stamp, None, None] + if errors == "strict": + if ent[1] is None: + ent[1] = _open_text(path, "strict") + return ent[1] + if ent[2] is None: + ent[2] = ent[1] if ent[1] is not None else _open_text(path, errors) + return ent[2] + + +_PREFETCH_THREADS = 8 + + +def prefetch_sources(paths: "list[str]", errors: str = "strict") -> None: + """Fill read_source()'s cache for `paths` with a few threads: a file open is latency, not CPU, on a disk with a + virus scanner in front of it, so the opens overlap. A file that cannot be read is left for the caller's own read + to report, as before.""" + todo = [p for p in paths if p not in _SOURCES] + if len(todo) < 16: + return + + def one(path: str) -> None: + try: + read_source(path, errors) + except (OSError, UnicodeDecodeError): + pass + + with concurrent.futures.ThreadPoolExecutor(max_workers=_PREFETCH_THREADS) as pool: + list(pool.map(one, todo)) + + +_CLASS_ROWS: "dict[tuple[str, str], tuple[tuple[int, int], list[tuple[str, set[str]]]]]" = {} + + +def _classes_of_file(root: str, path: str) -> "list[tuple[str, set[str]]] | None": + """[(simple class name, traits)] for every class declaration of one source file, parsed at most once per process; + None when the file cannot be read.""" + try: + text = read_source(path) + st = os.stat(path) + except OSError: + return None + stamp = (st.st_mtime_ns, st.st_size) + hit = _CLASS_ROWS.get((root, path)) + if hit is not None and hit[0] == stamp: + return hit[1] + lines = text.split("\n") + gated = any(GATE_ENV_LITERAL.search(line) for line in lines) + holders = _holders_of(lines) + rows: "list[tuple[str, set[str]]]" = [] + for n, line in enumerate(lines): + m = _CLASS_DECL.match(line) + if not m: + continue + traits: set[str] = {GATE_TRAIT} if gated else set() + # scan_classes() turns these two markers into NO_TESTS_TRAIT and drops them (#5872). + if m.group(1) in holders: + traits.add(_HOLDS_MARK) + tail = line[m.end():] + if ":" not in tail and "{" not in tail and n + 1 < len(lines): + tail += " " + lines[n + 1] + b = _BASE_LIST.match(tail) + if b: + traits.add(_BASE_MARK + b.group(1).split(".")[-1]) + j = n - 1 + while j >= 0: + s = lines[j].strip() + if s.startswith(("[", "///", "//", "*", "/*")) or s.endswith("*/") or s == "" and False: + traits.update(f"{k}={v}" for k, v in _TRAIT.findall(s)) + traits.update(COLLECTION_PREFIX + c for c in _COLLECTION_ATTR.findall(s)) + j -= 1 + else: + break + rows.append((m.group(1), traits)) + _CLASS_ROWS[(root, path)] = (stamp, rows) + return rows + + def _walk_classes(root: str): """Yield (suite, repo-relative file with '/', simple class name, {"Key=Value", ...}) for every class declaration.""" + found: "list[tuple[str, str]]" = [] for suite, rel in SUITE_DIRS.items(): base = os.path.join(root, rel) for dp, dn, fn in os.walk(base): dn[:] = [d for d in dn if d not in ("bin", "obj")] - for f in fn: - if not f.endswith(".cs"): - continue - path = os.path.join(dp, f) - try: - with open(path, encoding="utf-8-sig") as fh: - lines = fh.read().split("\n") - except OSError: - continue - relfile = os.path.relpath(path, root).replace(os.sep, "/") - gated = any(GATE_ENV_LITERAL.search(line) for line in lines) - holders = _holders_of(lines) - for n, line in enumerate(lines): - m = _CLASS_DECL.match(line) - if not m: - continue - traits: set[str] = {GATE_TRAIT} if gated else set() - # scan_classes() turns these two markers into NO_TESTS_TRAIT and drops them (#5872). - if m.group(1) in holders: - traits.add(_HOLDS_MARK) - tail = line[m.end():] - if ":" not in tail and "{" not in tail and n + 1 < len(lines): - tail += " " + lines[n + 1] - b = _BASE_LIST.match(tail) - if b: - traits.add(_BASE_MARK + b.group(1).split(".")[-1]) - j = n - 1 - while j >= 0: - s = lines[j].strip() - if s.startswith(("[", "///", "//", "*", "/*")) or s.endswith("*/") or s == "" and False: - traits.update(f"{k}={v}" for k, v in _TRAIT.findall(s)) - traits.update(COLLECTION_PREFIX + c for c in _COLLECTION_ATTR.findall(s)) - j -= 1 - else: - break - yield suite, relfile, m.group(1), traits + found += [(suite, os.path.join(dp, f)) for f in fn if f.endswith(".cs")] + prefetch_sources([p for _s, p in found if (root, p) not in _CLASS_ROWS]) + for suite, path in found: + rows = _classes_of_file(root, path) + if rows is None: + continue + relfile = os.path.relpath(path, root).replace(os.sep, "/") + for name, traits in rows: + yield suite, relfile, name, set(traits) def scan_classes(root: str = ROOT) -> dict[str, dict[str, set[str]]]: @@ -820,10 +891,11 @@ def reads_classes(root: str = ROOT, suites: "tuple[str, ...]" = ("darling", "lit classes that read a Darling path}. Replaces the [Trait("Reads", "Lite")] and [Trait("Reads", "Darling")] attributes.""" out: dict[str, set[str]] = {"darling": set(), "lite": set()} for suite, detector in (("darling", reads_lite_path), ("lite", reads_darling_path)): - for path in (_rc_suite_files(root, suite) if suite in suites else []): + paths = _rc_suite_files(root, suite) if suite in suites else [] + prefetch_sources(paths) + for path in paths: try: - with open(path, encoding="utf-8-sig") as fh: - text = fh.read().replace("\r\n", "\n") + text = read_source(path).replace("\r\n", "\n") except OSError: continue # A file that names neither tree and calls no file enumeration cannot read a path: skip the character walk. @@ -906,8 +978,7 @@ def text(self, suite: str, name: str) -> str: parts = [] for rel in self.slow[suite][name]: try: - with open(os.path.join(self.root, rel), encoding="utf-8-sig") as fh: - parts.append(fh.read()) + parts.append(read_source(os.path.join(self.root, rel))) except OSError: pass self._text[key] = "\n".join(parts) @@ -952,7 +1023,8 @@ def skip(self, files: list[str], event: str, base_ref: str = "") -> dict[str, li for name, own in classes.items(): text = self.text(suite, name) reached = bool(changed.intersection(own)) or bool(stems & self.words(suite, name)) \ - or any(re.search(r"(? "tuple[dict[str, set[ def test_file_index(root: str = ROOT) -> "list[tuple[str, str, list[str], bool, set[str]]]": """(suite, repo path, [class names], needs a PostgreSQL rig, {words}) for every test source file of SYMBOL_SUITES.""" out = [] + found: "list[tuple[str, str]]" = [] for suite in SYMBOL_SUITES: base = os.path.join(root, SUITE_DIRS[suite]) for dp, dn, fn in os.walk(base): dn[:] = [d for d in dn if d not in ("bin", "obj")] - for f in fn: - if not f.endswith(".cs"): - continue - path = os.path.join(dp, f) - try: - with open(path, encoding="utf-8-sig", errors="replace") as fh: - text = fh.read() - except OSError: - continue - classes = [m.group(1) for m in (_CLASS_DECL.match(ln) for ln in text.split("\n")) if m] - if classes: - out.append((suite, os.path.relpath(path, root).replace(os.sep, "/"), classes, - RIG_LITERAL in text, set(_WORD.findall(text)))) + found += [(suite, os.path.join(dp, f)) for f in fn if f.endswith(".cs")] + prefetch_sources([p for _s, p in found], "replace") + for suite, path in found: + try: + text = read_source(path, "replace") + except OSError: + continue + classes = [m.group(1) for m in (_CLASS_DECL.match(ln) for ln in text.split("\n")) if m] + if classes: + out.append((suite, os.path.relpath(path, root).replace(os.sep, "/"), classes, + RIG_LITERAL in text, set(_WORD.findall(text)))) return out @@ -2147,8 +2218,7 @@ def _test_holders(root: str, index: list, files: set[str]) -> set[str]: if rel not in files: continue try: - with open(os.path.join(root, rel), encoding="utf-8-sig", errors="replace") as fh: - lines = fh.read().split("\n") + lines = read_source(os.path.join(root, rel), "replace").split("\n") except OSError: continue # (indent, class) of the classes open at this line, by indentation: a test attribute belongs to the nearest From e510857e2cb760905632a2ab79719d7a495be0f5 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:44:12 -0400 Subject: [PATCH 009/294] Docs: how-collection-works counts 73 collectors and fixes the timeout, server id and Lite schedule text (#6434) (#6526) --- docs/how-collection-works.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/how-collection-works.md b/docs/how-collection-works.md index 109ee8b79f..ddfbb4c7c3 100644 --- a/docs/how-collection-works.md +++ b/docs/how-collection-works.md @@ -47,7 +47,7 @@ Optional behaviours a definition can opt into, all with sensible defaults on the | `EmitsProbeFailures` | The definition returns a trailing `(item, error)` result set so per-item failures get summarized instead of lost | | `YieldsOnLockTimeout` | Treat a lock timeout as "come back later," not an error (only `query_snapshots`) | | `StateKeys` | Persist a cursor the SQL can't derive — e.g. `default_trace_events` remembering its last trace file | -| `CommandTimeoutSecondsOverride` | Raise the 60-second default (only `index_object_stats`, at 300s) | +| `CommandTimeoutSecondsOverride` | Raise the command timeout above its default (60 seconds in Darling, 30 in Lite). Five definitions do: `index_object_stats` (300 s), `query_store` (500 s), `query_store_forced_plans` (120 s), `pg_buffer_usage` (120 s) and `pg_wait_sampling` (120 s) | | `PerItemTextByteBudget` | Stop a text-heavy drain mid-read and defer the backlog rather than ballooning memory | ### The three registration tables @@ -56,9 +56,9 @@ There is **no DI container for collectors**. A new definition is wired up by add | Concern | File | Shape | | --- | --- | --- | -| Schema catalog — drives DDL generation | [`CollectorCatalog.cs`](../PerformanceMonitor.Collectors/CollectorCatalog.cs) | `IReadOnlyList All` — 48 `XCollector.Instance` entries (41 SQL Server + 7 PostgreSQL) | -| Cadence, retention, default-enabled | [`CollectorScheduleDefaults.cs`](../PerformanceMonitor.Collectors/CollectorScheduleDefaults.cs) | `record Entry(int FrequencyMinutes, int RetentionDays, bool DefaultEnabled = true)` — 48 entries | -| Runtime dispatch (Darling) | [`DarlingWorker.cs`](../Darling/PerformanceMonitor.Darling.Service/DarlingWorker.cs) | `s_dispatch` — 48 typed lambdas | +| Schema catalog — drives DDL generation | [`CollectorCatalog.cs`](../PerformanceMonitor.Collectors/CollectorCatalog.cs) | `IReadOnlyList All` — 73 `XCollector.Instance` entries (44 SQL Server + 29 PostgreSQL) | +| Cadence, retention, default-enabled | [`CollectorScheduleDefaults.cs`](../PerformanceMonitor.Collectors/CollectorScheduleDefaults.cs) | `record Entry(int FrequencyMinutes, int RetentionDays, bool DefaultEnabled = true)` — 73 entries | +| Runtime dispatch (Darling) | [`DarlingWorker.cs`](../Darling/PerformanceMonitor.Darling.Service/DarlingWorker.cs) | `s_dispatch` — 73 typed lambdas | The catalog is deliberately **engine-mixed**: the schema generator walks it to create tables and one store can hold both engines' data, so splitting it per engine would fragment DDL generation. What keeps @@ -124,9 +124,9 @@ server_name text NOT NULL — followed by nullable payload columns. Fact tables have **no primary key** (a hypertable's unique constraint must include the partition column, and COPY ingest doesn't want one) and are indexed `(server_id,