feat(storage): persist verified strategy scenarios
Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
cf79e89efd
commit
7fad9b3b5c
7 files changed
+466
-12
No files matched your search
@@ -114,7 +114,7 @@ func migrate(db *sql.DB) error {
|
||||
if err = conn.QueryRowContext(ctx, "PRAGMA user_version").Scan(&version); err != nil {
|
||||
return err
|
||||
}
|
||||
if version > 2 {
|
||||
if version > 3 {
|
||||
return fmt.Errorf("unsupported database schema version %d", version)
|
||||
}
|
||||
if version == 0 {
|
||||
@@ -222,6 +222,11 @@ PRAGMA user_version = 1;`)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if version < 3 {
|
||||
if _, err := conn.ExecContext(ctx, candidateSchema); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = conn.ExecContext(ctx, "COMMIT")
|
||||
return err
|
||||
}
|
||||
@@ -250,11 +255,7 @@ func strategyFingerprint(args string) (string, error) {
|
||||
// Validation is shared with tune's output path; only combined 3/3 evidence is stored.
|
||||
func saveRun(db *sql.DB, started time.Time, args, output string, report []byte, runErr error) error {
|
||||
var evidence struct {
|
||||
Strategies []struct {
|
||||
Protocol string `json:"protocol"`
|
||||
PassesOK int `json:"passes_ok"`
|
||||
PassesTotal int `json:"passes_total"`
|
||||
} `json:"strategies"`
|
||||
Strategies []json.RawMessage `json:"strategies"`
|
||||
}
|
||||
state := "FAILED"
|
||||
var savedArgs, savedOutput, savedError, fingerprint interface{}
|
||||
@@ -291,10 +292,28 @@ func saveRun(db *sql.DB, started time.Time, args, output string, report []byte,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, row := range evidence.Strategies {
|
||||
var candidateID int64
|
||||
checked := time.Now().UTC()
|
||||
if runErr == nil {
|
||||
candidateID, err = insertStrategyCandidate(tx, "frontend", []string{"youtube.com"}, args, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, raw := range evidence.Strategies {
|
||||
var row struct {
|
||||
candidate
|
||||
Protocol string `json:"protocol"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &row); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(`INSERT INTO protocol_results (run_id, protocol, passes_ok, passes_total) VALUES (?, ?, ?, ?)`, id, normalizeProtocol(row.Protocol), row.PassesOK, row.PassesTotal); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := saveCandidateEvidence(tx, candidateID, "youtube.com", normalizeProtocol(row.Protocol), raw, checked); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user