(dataDir *string)
| 25 | } |
| 26 | |
| 27 | func intentDiffCmd(dataDir *string) *cobra.Command { |
| 28 | var runID string |
| 29 | var jsonOut bool |
| 30 | cmd := &cobra.Command{ |
| 31 | Use: "diff", |
| 32 | Short: "materialize the Intent-Runtime Diff for a run and show findings", |
| 33 | Args: cobra.NoArgs, |
| 34 | RunE: func(cmd *cobra.Command, args []string) error { |
| 35 | if runID == "" { |
| 36 | return fmt.Errorf("--run is required") |
| 37 | } |
| 38 | paths, err := store.Init(*dataDir) |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | db, err := store.Open(paths) |
| 43 | if err != nil { |
| 44 | return err |
| 45 | } |
| 46 | defer db.Close() |
| 47 | |
| 48 | res, err := intent.Materialize(db, runID) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | if jsonOut { |
| 53 | enc := json.NewEncoder(cmd.OutOrStdout()) |
| 54 | enc.SetIndent("", " ") |
| 55 | return enc.Encode(res) |
| 56 | } |
| 57 | fmt.Fprintf(cmd.OutOrStdout(), "run=%s effects=%d contracts=%d diffs=%d mismatches=%d coverage_gaps=%d\n", |
| 58 | res.RunID, res.Effects, res.Contracts, res.Diffs, res.Mismatches, res.CoverageGaps) |
| 59 | return printIntentDiffs(cmd, db, runID) |
| 60 | }, |
| 61 | } |
| 62 | cmd.Flags().StringVar(&runID, "run", "", "run id") |
| 63 | cmd.Flags().BoolVar(&jsonOut, "json", false, "emit the machine-readable materialize summary") |
| 64 | return cmd |
| 65 | } |
| 66 | |
| 67 | func printIntentDiffs(cmd *cobra.Command, db *sql.DB, runID string) error { |
| 68 | rows, err := db.Query(`SELECT status, finding, contract_kind, operation, agent_id, round(confidence,2), mismatch_reason |
no test coverage detected