1+ // @index Eval runner orchestration for parser and search benchmark suites.
12package eval
23
34import (
@@ -13,6 +14,8 @@ import (
1314 "github.com/tae2089/code-context-graph/internal/parse/treesitter"
1415)
1516
17+ // RunOptions collects corpus paths, parser walkers, and output settings for one eval invocation.
18+ // @intent configure parser/search evaluation suites from CLI without leaking command details.
1619type RunOptions struct {
1720 CorpusDir string
1821 Suite string
@@ -23,6 +26,8 @@ type RunOptions struct {
2326 Writer io.Writer
2427}
2528
29+ // Run executes the requested evaluation suites and writes the chosen report format.
30+ // @intent provide one orchestration entry point for CLI-driven parser and search evaluation.
2631func Run (ctx context.Context , opts RunOptions ) (* Report , error ) {
2732 report := & Report {Suite : opts .Suite }
2833
@@ -44,13 +49,15 @@ func Run(ctx context.Context, opts RunOptions) (*Report, error) {
4449 return report , writeTable (opts .Writer , report )
4550}
4651
52+ // @intent route parser evaluation into update or comparison mode without duplicating top-level flow control.
4753func runParserEval (ctx context.Context , opts RunOptions , report * Report ) error {
4854 if opts .Update {
4955 return runParserUpdate (ctx , opts )
5056 }
5157 return runParserCompare (ctx , opts , report )
5258}
5359
60+ // @intent regenerate golden parser snapshots from the current parser implementation.
5461func runParserUpdate (ctx context.Context , opts RunOptions ) error {
5562 entries , err := os .ReadDir (opts .CorpusDir )
5663 if err != nil {
@@ -102,6 +109,7 @@ func runParserUpdate(ctx context.Context, opts RunOptions) error {
102109 return nil
103110}
104111
112+ // @intent compare current parser output against stored golden corpora and accumulate language reports.
105113func runParserCompare (ctx context.Context , opts RunOptions , report * Report ) error {
106114 corpora , err := LoadGoldenDir (opts .CorpusDir )
107115 if err != nil {
@@ -158,6 +166,7 @@ func runParserCompare(ctx context.Context, opts RunOptions, report *Report) erro
158166 return nil
159167}
160168
169+ // @intent run ranking metrics over the search corpus when a search backend is available.
161170func runSearchEval (_ context.Context , opts RunOptions , report * Report ) error {
162171 queryPath := fmt .Sprintf ("%s/queries.json" , opts .CorpusDir )
163172 qc , err := LoadQueryCorpus (queryPath )
@@ -177,6 +186,7 @@ func runSearchEval(_ context.Context, opts RunOptions, report *Report) error {
177186 return nil
178187}
179188
189+ // @intent map parsed node IDs to qualified names so edge normalization can avoid DB lookups.
180190func buildNodeMap (nodes []model.Node ) map [uint ]string {
181191 m := make (map [uint ]string , len (nodes ))
182192 for _ , n := range nodes {
@@ -185,16 +195,19 @@ func buildNodeMap(nodes []model.Node) map[uint]string {
185195 return m
186196}
187197
198+ // @intent centralize file reads used by parser evaluation so tests can characterize failures consistently.
188199func readFileContent (path string ) ([]byte , error ) {
189200 return os .ReadFile (path )
190201}
191202
203+ // @intent emit the eval report as pretty-printed JSON for machine consumption.
192204func writeJSON (w io.Writer , report * Report ) error {
193205 enc := json .NewEncoder (w )
194206 enc .SetIndent ("" , " " )
195207 return enc .Encode (report )
196208}
197209
210+ // @intent render a compact human-readable summary of parser and search evaluation metrics.
198211func writeTable (w io.Writer , report * Report ) error {
199212 if len (report .Languages ) > 0 {
200213 fmt .Fprintf (w , "=== Parser Evaluation ===\n \n " )
0 commit comments