Backtestshugorun-20260930-140149#15167
Add classDark and classLight to css.ChromaStyles and "gen chromastyles" (default dark/light)
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches make the same core change and are functionally equivalent. Each adds ClassDark and ClassLight fields to ChromaStylesOptions, falls back to "dark"/"light" when a field is empty, uses them when building the mode-selector prefix, and wires `--classDark`/`--classLight` flags with matching defaults into `hugo gen chromastyles`. Correctness and scope are therefore equal. Patch A resolves the defaults once, before the switch; Patch B resolves them inside each case. Both read cleanly, so craft is roughly a wash. The difference is in testing. Both add essentially the same integration test for the `css.ChromaStyles` template function. Patch B's version also asserts the rendered page output and adds negative assertions that the default `.light .chroma` and `.dark .chroma` selectors are absent. Patch B also extends the CLI testscript to exercise the new `gen chromastyles` flags, with both positive and negative checks. The issue explicitly asks for the options in both `css.ChromaStyles` and `gen chromastyles`, so Patch B tests both surfaces the issue names, while Patch A tests only the template function. Patch B wins on test coverage.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
18m 9s17 turns
Wall-clock time in the container
Full test suite
No new failures
3,692 passed · 99 skipped · 3,800 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
58vs 44 merged
Changed lines, ours vs merged
The issue
View on GitHubI argued with @jmooring that it would be very unlikely that e.g. the CSS dark class would collide with existing classes in a project. After thinking a little, I still don't think that is a likely issue, but:
- I suspect there are JS/CSS frameworks with other naming standards for these mode classes (e.g.
theme-dark) - I would be an annoyed Hugo user if I needed to customise this class and had to do ugly string replacements.
- The cost for us adding these 2 new options is small.
The two patches
commands/gen.goindex f3747722c..678e9f1be 100644@@ -46,6 +46,8 @@ func newGenCommand() *genCommand { style string mode string modeSelector bool+ classDark string+ classLight string highlightStyle string lineNumbersInlineStyle string lineNumbersTableStyle string@@ -70,6 +72,8 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview Style: style, Mode: mode, ModeSelector: modeSelector,+ ClassDark: classDark,+ ClassLight: classLight, HighlightStyle: highlightStyle, LineNumbersInlineStyle: lineNumbersInlineStyle, LineNumbersTableStyle: lineNumbersTableStyle,@@ -91,6 +95,10 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview _ = cmd.RegisterFlagCompletionFunc("mode", cobra.FixedCompletions([]string{"light", "dark"}, cobra.ShellCompDirectiveNoFileComp)) cmd.PersistentFlags().BoolVar(&modeSelector, "modeSelector", false, `scope selectors under a top level mode class, e.g. ".dark .chroma"`) _ = cmd.RegisterFlagCompletionFunc("modeSelector", cobra.NoFileCompletions)+ cmd.PersistentFlags().StringVar(&classDark, "classDark", "dark", `class name for the dark mode selector, used with --modeSelector`)+ _ = cmd.RegisterFlagCompletionFunc("classDark", cobra.NoFileCompletions)+ cmd.PersistentFlags().StringVar(&classLight, "classLight", "light", `class name for the light mode selector, used with --modeSelector`)+ _ = cmd.RegisterFlagCompletionFunc("classLight", cobra.NoFileCompletions) cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "", `foreground and background colors for highlighted lines, e.g. --highlightStyle "#fff000 bg:#000fff"`) _ = cmd.RegisterFlagCompletionFunc("highlightStyle", cobra.NoFileCompletions) cmd.PersistentFlags().StringVar(&lineNumbersInlineStyle, "lineNumbersInlineStyle", "", `foreground and background colors for inline line numbers, e.g. --lineNumbersInlineStyle "#fff000 bg:#000fff"`)markup/highlight/chromastyles.goindex c595c780a..6ec64c441 100644@@ -33,8 +33,15 @@ type ChromaStylesOptions struct { Mode string // Scope selectors under a top level mode class, e.g. ".dark .chroma".+ // See ClassDark and ClassLight. ModeSelector bool + // The class name to use for the dark mode selector when ModeSelector is set. Defaults to "dark".+ ClassDark string++ // The class name to use for the light mode selector when ModeSelector is set. Defaults to "light".+ ClassLight string+ // Foreground and background colors for highlighted lines, e.g. "#fff000 bg:#000fff". HighlightStyle string @@ -108,9 +115,17 @@ func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) { var prefix string switch style.Mode() { case chroma.Light:- prefix = ".light "+ class := opts.ClassLight+ if class == "" {+ class = "light"+ }+ prefix = "." + class + " " case chroma.Dark:- prefix = ".dark "+ class := opts.ClassDark+ if class == "" {+ class = "dark"+ }+ prefix = "." + class + " " default: return "", fmt.Errorf("style %q does not have a light or dark mode", style.Name) }testscripts/commands/gen_chromastyles_mode.txtindex 229f5f8cc..370662f90 100644@@ -22,3 +22,15 @@ stdout '\.light \.chroma' # --modeSelector without --mode on a default dark style. hugo gen chromastyles --style ashen --modeSelector stdout '\.dark \.chroma'++# Dark mode with mode selector and custom dark class: ".theme-dark .chroma".+hugo gen chromastyles --style github --mode dark --modeSelector --classDark theme-dark+stdout '\.theme-dark \.chroma'+stdout '\.theme-dark \.bg \{'+! stdout '(^|[^-])\.dark '++# Light mode with mode selector and custom light class: ".theme-light .chroma".+hugo gen chromastyles --style github --mode light --modeSelector --classLight theme-light+stdout '\.theme-light \.chroma'+stdout '\.theme-light \.bg \{'+! stdout '(^|[^-])\.light 'tpl/css/chromastyles_integration_test.goindex 402ef2ca6..add88bc0c 100644@@ -47,6 +47,25 @@ Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|Default: {{ $def b.AssertFileContent("public/css/chroma.css", "/* Background */ .bg {", "background-color:#272822") } +func TestChromaStylesClassDarkLight(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "rss", "sitemap", "section", "page"]+-- layouts/home.html --+{{ $light := css.ChromaStyles (dict "targetPath" "css/chroma-light.css" "style" "github" "mode" "light" "modeSelector" true "classLight" "theme-light") }}+{{ $dark := css.ChromaStyles (dict "targetPath" "css/chroma-dark.css" "style" "github" "mode" "dark" "modeSelector" true "classDark" "theme-dark") }}+Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html", "Light: /css/chroma-light.css|Dark: /css/chroma-dark.css|")+ b.AssertFileContent("public/css/chroma-light.css", ".theme-light .chroma ", ".theme-light .bg {", "! .light .chroma", "! .dark .chroma")+ b.AssertFileContent("public/css/chroma-dark.css", ".theme-dark .chroma ", ".theme-dark .bg {", "! .dark .chroma", "! .light .chroma")+}+ // Chroma's minifier drops token rules whose color equals the style's default // foreground (e.g. .nx in github-dark). In a paired light/dark setup the light // sheet's explicit rule would then leak into dark mode, so these must be re-emitted.
commands/gen.goindex f3747722c..42b22165d 100644@@ -46,6 +46,8 @@ func newGenCommand() *genCommand { style string mode string modeSelector bool+ classDark string+ classLight string highlightStyle string lineNumbersInlineStyle string lineNumbersTableStyle string@@ -70,6 +72,8 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview Style: style, Mode: mode, ModeSelector: modeSelector,+ ClassDark: classDark,+ ClassLight: classLight, HighlightStyle: highlightStyle, LineNumbersInlineStyle: lineNumbersInlineStyle, LineNumbersTableStyle: lineNumbersTableStyle,@@ -91,6 +95,10 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview _ = cmd.RegisterFlagCompletionFunc("mode", cobra.FixedCompletions([]string{"light", "dark"}, cobra.ShellCompDirectiveNoFileComp)) cmd.PersistentFlags().BoolVar(&modeSelector, "modeSelector", false, `scope selectors under a top level mode class, e.g. ".dark .chroma"`) _ = cmd.RegisterFlagCompletionFunc("modeSelector", cobra.NoFileCompletions)+ cmd.PersistentFlags().StringVar(&classDark, "classDark", "dark", `class name used by --modeSelector for dark styles`)+ _ = cmd.RegisterFlagCompletionFunc("classDark", cobra.NoFileCompletions)+ cmd.PersistentFlags().StringVar(&classLight, "classLight", "light", `class name used by --modeSelector for light styles`)+ _ = cmd.RegisterFlagCompletionFunc("classLight", cobra.NoFileCompletions) cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "", `foreground and background colors for highlighted lines, e.g. --highlightStyle "#fff000 bg:#000fff"`) _ = cmd.RegisterFlagCompletionFunc("highlightStyle", cobra.NoFileCompletions) cmd.PersistentFlags().StringVar(&lineNumbersInlineStyle, "lineNumbersInlineStyle", "", `foreground and background colors for inline line numbers, e.g. --lineNumbersInlineStyle "#fff000 bg:#000fff"`)markup/highlight/chromastyles.goindex c595c780a..f17170ad0 100644@@ -35,6 +35,12 @@ type ChromaStylesOptions struct { // Scope selectors under a top level mode class, e.g. ".dark .chroma". ModeSelector bool + // Class name used by ModeSelector for dark styles, defaults to "dark".+ ClassDark string++ // Class name used by ModeSelector for light styles, defaults to "light".+ ClassLight string+ // Foreground and background colors for highlighted lines, e.g. "#fff000 bg:#000fff". HighlightStyle string @@ -105,12 +111,19 @@ func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) { // them with a parent class on the page. // There's no upstream option for this (I think), so do string replacements for now. // TODO(bep) upstream option for this.+ classDark, classLight := opts.ClassDark, opts.ClassLight+ if classDark == "" {+ classDark = "dark"+ }+ if classLight == "" {+ classLight = "light"+ } var prefix string switch style.Mode() { case chroma.Light:- prefix = ".light "+ prefix = "." + classLight + " " case chroma.Dark:- prefix = ".dark "+ prefix = "." + classDark + " " default: return "", fmt.Errorf("style %q does not have a light or dark mode", style.Name) }tpl/css/chromastyles_integration_test.goindex 402ef2ca6..682f11724 100644@@ -47,6 +47,25 @@ Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|Default: {{ $def b.AssertFileContent("public/css/chroma.css", "/* Background */ .bg {", "background-color:#272822") } +// See issue 15167.+func TestChromaStylesCustomModeClasses(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "rss", "sitemap", "section", "page"]+-- layouts/home.html --+{{ $light := css.ChromaStyles (dict "targetPath" "css/chroma-light.css" "style" "github" "mode" "light" "modeSelector" true "classLight" "theme-light") }}+{{ $dark := css.ChromaStyles (dict "targetPath" "css/chroma-dark.css" "style" "github" "mode" "dark" "modeSelector" true "classDark" "theme-dark") }}+Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/css/chroma-light.css", ".theme-light .chroma ", ".theme-light .bg {")+ b.AssertFileContent("public/css/chroma-dark.css", ".theme-dark .chroma ", ".theme-dark .bg {")+}+ // Chroma's minifier drops token rules whose color equals the style's default // foreground (e.g. .nx in github-dark). In a paired light/dark setup the light // sheet's explicit rule would then leak into dark mode, so these must be re-emitted.
What the agent reported
I added classDark and classLight options to css.ChromaStyles and matching --classDark / --classLight flags to hugo gen chromastyles, defaulting to dark and light. The new tests fail without the change and pass with it, but I ran them directly with go test because ./bt-test couldn't build the code.
What was wrong: with modeSelector on, the top-level class was hard-coded as .dark / .light in markup/highlight/chromastyles.go. The only way to get a different name, such as theme-dark, was to edit the generated CSS text.
What I changed:
markup/highlight/chromastyles.go: two new fields,ClassDarkandClassLight, inChromaStylesOptions. WhenModeSelectoris set, the prefix is"." + class + " ", and an empty value falls back todark/light, so existing output is unchanged. The fields have no effect withoutmodeSelector.commands/gen.go: new--classDark(defaultdark) and--classLight(defaultlight) flags, passed through to the options.tpl/css/css.go: no change needed. The template function already decodes its options map straight intoChromaStylesOptions, soclassDark/classLightwork in templates automatically.
Tests:
TestChromaStylesClassDarkLight(intpl/css/chromastyles_integration_test.go): builds a site with"classLight" "theme-light"and"classDark" "theme-dark". It checks the output contains.theme-light .chroma,.theme-light .bg {,.theme-dark .chromaand.theme-dark .bg {, and does not contain.light .chromaor.dark .chroma.testscripts/commands/gen_chromastyles_mode.txt: two new CLI cases, one using--classDark theme-darkand one using--classLight theme-light, each checking the new prefix appears and the default one doesn't.
Test evidence:
./bt-testcouldn't build anything. Its runs download Go modules from the internet, which the sandbox blocks (dial tcp: lookup proxy.golang.org ... server misbehaving). So there is no./bt-testresult for this change.- Direct runs: instead I ran
go testagainst the local module cache in/bt/cache/go-mod, with the network turned off. - All
TestChromaStyles*tests pass, including the new one. TestCommands/gen_chromastylesandTestCommands/gen_chromastyles_modepass.- The full
./markup/highlight/and./tpl/css/packages pass, andgo vetis clean. - Before the fix: with only the two production files reverted,
TestChromaStylesClassDarkLightfails and the CLI test fails withunknown flag: --classDark. - Blast radius: only the
modeSelectorpath is affected, and the defaults keep its output identical. The existing tests covering.dark .chroma/.light .chromastill pass unchanged.
Requirements:
classDarkoption incss.ChromaStyles: implemented and tested by the template test.classLightoption incss.ChromaStyles: implemented and tested by the template test.--classDark/--classLightinhugo gen chromastyles: implemented and tested by the CLI test (it failed with "unknown flag" before the change).- Defaults of dark / light: implemented, and the existing tests confirm the default output is unchanged.
Not done:
- Docs:
docs/content/en/commands/hugo_gen_chromastyles.mdis generated byhugo gen doc, and it is already missing the existing--mode/--modeSelectorflags. I left it alone rather than hand-edit a generated file; runninghugo gen docwill add the new flags. - Input checking: a value written with a leading dot, like
.theme-dark, produces..theme-dark. I left the class names unchecked to keep the change minimal.
Nothing is committed. AGENTS.md and CLAUDE.md were already deleted in the working tree before this session; I didn't touch them.