Repository navigation
fix: give top-level anonymous groups Python TTP's result shape (#62) - #115
Merged
Merged
Conversation
A template whose top-level group has no name (an unnamed <group>, or a template with no group tags) used its list of matches as the whole per-input result list: the result was one list level short, every input after the first was dropped, and named groups beside it were lost. Build each input's result the way TTP's template.form_results does (ttp/ttp.py:989-1003): the _anonymous_ matches are the input's result, the rest of that input's results is appended as one more item, and each input keeps its own entry. Both Runtime.Parse and ParseWithSourceMap use the new formResults helper, for per_input and per_template (the source-map per_template path kept a literal _anonymous_ key). Name the implicit group of a tagless template "_anonymous_", as TTP does, so one match gives a dict while an unnamed <group> always gives a list. ParseStream keeps an empty groupPath for it. The table formatter now also combines per-input lists into one table. test/comparison compares strictly (Go result wrapped like result(), no single-item-list unwrapping); the 9 tests that still differ only by a list level are listed in looseListLevels with #98 and #111. TTP 0.10.1 suite: pass 22 -> 48 of 200. The 39 ex-#62 cases that still fail are listed under the issue they hit next (new: #110, #112-#114). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A top-level anonymous group (an unnamed
<group>, or a template with no group tags) gave a result one list level short, dropped every input after the first, and lost named groups next to it. Each input's result is now built the way Python TTP'stemplate.form_resultsbuilds it (ttp/ttp.py:989-1003).What changed:
formResults(internal/compiled/runtime.go): a port ofform_results, used by bothRuntime.ParseandRuntime.ParseWithSourceMapforper_inputandper_template. It replaces the_anonymous_list+goto skipResultsListBuildcode in both paths. The two paths are still separate, so this is not the later refactor. The source-mapper_templatepath had no anonymous handling at all and returned{"_anonymous_": [...]}.internal/parser/template.go): a template with no group tags is now the group_anonymous_, as in TTP (ttp/ttp.py:1388-1394). So one match gives a dict ([{A}]) and an unnamed<group>always gives a list ([[{A}]]). Both match TTP.ParseStreamstill reportsgroupPath ""for it (internal/compiler/streamability.go).processOutputFunctions): a per-input list now counts as table rows, so the anonymous matches still make one table.test/comparisonis strict.normalizeJSONunwrapped every one-item list holding a list (research §3.4), which hid this bug. The Go result is now wrapped likeresult()and compared with list levels included. The 9 tests that still differ only by a list level are listed in a stale-prooflooseListLevelstable: 8 for TTP compat: Formatter output from <output> gets an extra list level #98 (formatter output gets an extra list level) and 1 for the new TTP compat: functions="itemize(...)" flattens a list-valued key #111 (functions="itemize(...)"flattens a list value). Those 9 are still compared loosely, and a listed test that starts matching strictly fails. With a strict comparison, main fails 17 tests; this branch fails only those 9.ParseStreamdoesn't build per-input lists, so it never had this shape bug. It has a new test that the implicit group still streams with an emptygroupPath.Evidence
Regression tests (written first; red on main, green here):
test/anonymous_group_test.goTestAnonymousGroupResultShape: 18 shapes × {source map off, on}, each expected value recorded from Python TTP 0.10.1. Covers implicit vs unnamed vsname="_anonymous_", 0/1/2 matches, 2 inputs, an input with no match, anonymous + named groups, two unnamed groups, nested child groups, andper_template(also with a named group). On main, 28 of the 36 subtests fail, 4 pass and 4 are skipped (the multi-input source-map subtests, for Source map: a group without input= parses only Default_Input (other inputs give an empty result) #105).parsestream_test.goTestParseStream_ImplicitGroupHasEmptyGroupPath.NewParser().Result():csv cascade (
test_output_formatters/test_csv_formatter_simple):test/ttpsuite:26 of the 65 #62 cases pass and were removed from
known_failures.json. The other 39 are re-listed under the issue they hit next. Most of those issues were already filed (#63, #64, #67, #69, #70, #72, #79, #97, #98, #99, …). For 11 cases the next difference was untracked, so I filed #110 (group-specificoutput=results), #112 (a chain stored as a<vars>list), #113 (macro()inside groupchain=) and #114 (groupvalidate=). The README's counts, per-issue table and macro section are updated.sourcemap_divergences.jsonneeded no change.Checks run locally:
go vet ./...,go test ./...,go test -race(all buttest/memory), withGOTTP_PYTHONset to TTP 0.10.1 fortest/comparison;staticcheck@2025.1.1 ./...(clean);GOOS=js GOARCH=wasm go build ./....Merge Danger
This changes the public result shape for every template whose top-level group is anonymous. Templates where every top-level group is named are unaffected.
NewParser().Result()/CompiledTemplate.Parse: one more list level (result[0]is now the input's list of matches, not a match). Inputs after the first and named groups beside the anonymous group now appear where they used to be dropped. Single-match unnamed<group>now gives[[{...}]]instead of[{...}].per_template+EnableSourceMap: was{"_anonymous_": [...]}, now the list of matches.MatchMapping.GroupNamefor the implicit group of a tagless template is now"_anonymous_"(was""). TheResultPathfallback for that group is_anonymous_(was_anonymous_*).ParseStream'sgroupPathis unchanged ("").result[0]as a dict (test/joinmatches_test.go,test/match_condition_test.go) now readresult[0][0].examples/output is unchanged (they use named groups). The editor's source-map navigation keys onGroupName/ResultPath, and its result view will show the extra level for anonymous templates. It has no anonymous-specific code, but click-through on anonymous-template results wasn't tested here.docs/.../Anonymous group.rstdocuments the new top-level shape, and there's a breaking-change entry under[Unreleased]inCHANGELOG.md.ConvertJSONToNotifications) should be checked for templates without named top-level groups before rollout. Anything matching the old shape would silently read the wrong level, or only the first input.🤖 Generated with Claude Code
Fixes #62