Skip to content

Commit a768266

Browse files
The documentation samples run in CI, the wiki's and the website's (#1656)
DocSamples compiles every code sample in the wiki, and every one on the website marked with an amcheck comment, against the library in the checkout. It runs them and checks each stated output against the one produced. It fails on a sample that does not compile, throws, or prints something other than its page says. A sample that does not finish fails nothing. It clones the wiki beside itself. CI also checks AngouriMathSite out beside the library and passes it with --site. The job is its own, since it builds a generated project per language. A change to the F# wrapper alone now runs the workflow, because the F# samples compile against it. Its first run, against cd3b27b, found three wiki outputs that master no longer prints. All three were equal values in a new form, and the wiki is corrected (AngouriMath.wiki d23ca13). With that, 89 samples pass: 60 stated outputs verified, 0 failures. Measured.Commit(path) is back in the shared code, because this harness builds the library rather than referencing it. Part of #1256. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 7219aea commit a768266

12 files changed

Lines changed: 1120 additions & 5 deletions

File tree

‎.github/workflows/Harnesses.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ on:
1313
- master
1414
paths:
1515
- 'Sources/AngouriMath/**'
16+
- 'Sources/Wrappers/AngouriMath.FSharp/**'
1617
- 'Sources/Tests/Harnesses/**'
1718
- '.github/workflows/Harnesses.yml'
1819
pull_request:
1920
paths:
2021
- 'Sources/AngouriMath/**'
22+
- 'Sources/Wrappers/AngouriMath.FSharp/**'
2123
- 'Sources/Tests/Harnesses/**'
2224
- '.github/workflows/Harnesses.yml'
2325
workflow_dispatch:
@@ -116,3 +118,38 @@ jobs:
116118
with:
117119
name: crashcheck-report
118120
path: harness-reports
121+
122+
# A job of its own: it checks the website out beside the library, clones the wiki, and builds a
123+
# project per language from their samples.
124+
DocSamples:
125+
runs-on: ubuntu-latest
126+
env:
127+
HARNESS_REPORTS: ${{ github.workspace }}/harness-reports
128+
129+
steps:
130+
- uses: actions/checkout@v6
131+
132+
- name: Check out the website
133+
uses: actions/checkout@v6
134+
with:
135+
repository: asc-community/AngouriMathSite
136+
path: site
137+
138+
- name: Setup .NET 10
139+
uses: actions/setup-dotnet@v5
140+
with:
141+
dotnet-version: '10.x'
142+
dotnet-quality: 'preview'
143+
144+
- name: Build
145+
run: dotnet build -c Release Sources/Tests/Harnesses/DocSamples
146+
147+
- name: DocSamples
148+
run: dotnet Sources/Tests/Harnesses/DocSamples/bin/Release/net10.0/docsamples.dll --site=site
149+
150+
- name: Report
151+
if: always()
152+
uses: actions/upload-artifact@v6
153+
with:
154+
name: docsamples-report
155+
path: harness-reports

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,10 @@ docsamples.md
7777
sympyparity.md
7878
egraph.md
7979

80+
# DocSamples clones the wiki beside itself and generates a project per language there.
81+
Sources/Tests/Harnesses/DocSamples/wiki/
82+
Sources/Tests/Harnesses/DocSamples/generated/
83+
Sources/Tests/Harnesses/DocSamples/generated-fsharp/
84+
8085
# Agent worktrees and local tool state.
8186
.claude/

‎CLAUDE.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ nothing else is read:
1919
[`Contributing/SimplificationContract.md`](Sources/AngouriMath/Docs/Contributing/SimplificationContract.md).
2020
A rule states the assumptions under which it holds, or it is asserting there are none.
2121

22-
Nine measurement harnesses live in `Sources/Tests/Harnesses` and run in CI on every change to the
22+
Ten measurement harnesses live in `Sources/Tests/Harnesses` and run in CI on every change to the
2323
library: the boundary checker, root completeness, the self-verifying solver corpus, the property
2424
checker, the simplification sweep, the rule-set checker, a crash harness that survives a stack
25-
overflow, the canonical-form checker and the arm-order checker. Each fails on a defect, or the last
26-
two on a change to the findings they list; the README says which. The rest are still in the analysis workspace
27-
one directory up (`work/`), among them a checker for the documentation's code samples. Run them before claiming anything is
28-
fixed.
25+
overflow, the canonical-form checker, the arm-order checker, and a checker for the code samples in
26+
the wiki and on the website. Each fails on a defect, or the canonical-form and arm-order checkers on
27+
a change to the findings they list; the README says which. The rest are still in the analysis
28+
workspace one directory up (`work/`). Run them before claiming anything is fixed.
2929

3030
There is also a *gate*, which is not a harness:
3131
`Sources/Tests/UnitTests/Corpus` runs forty problems on every commit and reports **solved / unsolved
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<!--
4+
Does every code sample in the wiki and on the website compile, run, and print what its page
5+
says. A harness, not a test project: it is run by .github/workflows/Harnesses.yml and by hand,
6+
and `dotnet test` does not pick it up. See ../README.md.
7+
8+
It references no library: it generates a project per language beside it, under generated/ and
9+
generated-fsharp/, which reference Sources/AngouriMath and the F# wrapper, and builds those.
10+
Default compile items are off so that neither those nor the wiki clone are compiled into it.
11+
-->
12+
13+
<PropertyGroup>
14+
<OutputType>Exe</OutputType>
15+
<TargetFramework>net10.0</TargetFramework>
16+
<Nullable>disable</Nullable>
17+
<LangVersion>preview</LangVersion>
18+
<AssemblyName>docsamples</AssemblyName>
19+
<RootNamespace>DocSamples</RootNamespace>
20+
<InvariantGlobalization>true</InvariantGlobalization>
21+
<IsPackable>false</IsPackable>
22+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<Compile Include="Program.cs" />
27+
<Compile Include="Snippets.cs" />
28+
<Compile Include="Generator.cs" />
29+
<Compile Include="FSharpGenerator.cs" />
30+
<Compile Include="Report.cs" />
31+
<Compile Include="../Shared/*.cs" />
32+
</ItemGroup>
33+
</Project>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using System.Collections.Generic;
10+
using System.IO;
11+
using System.Linq;
12+
using System.Text;
13+
14+
namespace DocSamples;
15+
16+
/// <summary>
17+
/// The F# side of the same check. `AngouriMath.FSharp` is a published package, and the wiki
18+
/// page for it is the only documentation of the wrapper's names, so a wrong name there --
19+
/// `dy/dx` for `d/dx` -- has nothing else to catch it.
20+
///
21+
/// One file, one module per sample, so each sample keeps its own `open` directives. F#
22+
/// wants `open` before anything else in a module, so they are hoisted out of the body.
23+
/// </summary>
24+
static class FSharpGenerator
25+
{
26+
public static Dictionary<string, int> Write(string dir, string wrapperFsproj,
27+
IEnumerable<Snippet> snippets, ISet<string> exclude)
28+
{
29+
var wanted = snippets.Where(s => s.Mode != Mode.Skip && !exclude.Contains(s.Id)).ToList();
30+
Directory.CreateDirectory(dir);
31+
32+
var sb = new StringBuilder();
33+
var offsets = new Dictionary<string, int>();
34+
sb.AppendLine("module DocSamples.Generated.FSharpSamples");
35+
sb.AppendLine();
36+
37+
foreach (var s in wanted)
38+
{
39+
var opens = s.Body.Where(l => l.TrimStart().StartsWith("open ")).ToList();
40+
sb.AppendLine($"module {s.Id} =");
41+
foreach (var o in opens) sb.AppendLine(" " + o.Trim());
42+
sb.AppendLine(" let run () =");
43+
offsets[s.Id] = sb.ToString().Count(c => c == '\n') + 1;
44+
var wrote = false;
45+
foreach (var line in s.Body)
46+
{
47+
if (opens.Contains(line)) { sb.AppendLine(); continue; }
48+
sb.AppendLine(line.Trim().Length == 0 ? "" : " " + line);
49+
if (line.Trim().Length > 0) wrote = true;
50+
}
51+
if (!wrote) sb.AppendLine(" ()");
52+
sb.AppendLine();
53+
}
54+
55+
sb.AppendLine("module Runner =");
56+
sb.AppendLine(" open System");
57+
sb.AppendLine(" open System.IO");
58+
sb.AppendLine(" open System.Text.Json");
59+
sb.AppendLine();
60+
sb.AppendLine(" type Result = { Id: string; Status: string; Output: string }");
61+
sb.AppendLine();
62+
sb.AppendLine(" let samples : (string * (unit -> unit) * bool) list =");
63+
if (wanted.Count == 0) sb.AppendLine(" []");
64+
else
65+
sb.AppendLine(" [ " + string.Join("\n ",
66+
wanted.Select(s => $"(\"{s.Id}\", {s.Id}.run, {(s.Mode == Mode.Run ? "true" : "false")})"))
67+
+ " ]");
68+
sb.AppendLine("""
69+
70+
[<EntryPoint>]
71+
let main argv =
72+
let real = Console.Out
73+
let results =
74+
samples
75+
|> List.map (fun (id, run, execute) ->
76+
if not execute then { Id = id; Status = "compiled"; Output = "" }
77+
else
78+
let captured = new StringWriter()
79+
Console.SetOut(captured)
80+
let status =
81+
try
82+
run ()
83+
"ok"
84+
with e -> "threw " + e.GetType().Name + ": " + e.Message.Split('\n').[0]
85+
Console.SetOut(real)
86+
{ Id = id; Status = status; Output = captured.ToString() })
87+
let path = if argv.Length > 0 then argv.[0] else "results.json"
88+
File.WriteAllText(path, JsonSerializer.Serialize(results))
89+
0
90+
""");
91+
92+
File.WriteAllText(Path.Combine(dir, "Samples.fs"), sb.ToString());
93+
File.WriteAllText(Path.Combine(dir, "generated-fsharp.fsproj"), $"""
94+
<Project Sdk="Microsoft.NET.Sdk">
95+
<PropertyGroup>
96+
<OutputType>Exe</OutputType>
97+
<TargetFramework>net10.0</TargetFramework>
98+
<AssemblyName>generatedfsharp</AssemblyName>
99+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
100+
<WarningLevel>0</WarningLevel>
101+
<NoWarn>FS0025;FS0049;FS0064;FS0193;FS1182</NoWarn>
102+
</PropertyGroup>
103+
<ItemGroup>
104+
<Compile Include="Samples.fs" />
105+
</ItemGroup>
106+
<ItemGroup>
107+
<ProjectReference Include="{wrapperFsproj}" />
108+
</ItemGroup>
109+
</Project>
110+
""");
111+
return offsets;
112+
}
113+
}

0 commit comments

Comments
 (0)