package pipeline import ( "context" "database/sql" "encoding/json" "git.a-wan.net/alan/pipelines/internal/protocol" ) // RecordDeliverable appends server-observed evidence without replacing the // visit's existing inventory or its bounds diagnostics. func (s *Store) RecordDeliverable(ctx context.Context, id int64, sequence int, file protocol.StageArtifact) error { tx, err := s.db.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() var data string var evidence stageArtifactsEvidence err = tx.QueryRowContext(ctx, "SELECT artifacts_json FROM step_artifacts WHERE run_id=? AND sequence=?", id, sequence).Scan(&data) if err != nil && err != sql.ErrNoRows { return err } if data != "" { if err := json.Unmarshal([]byte(data), &evidence); err != nil { return err } } evidence.Files = append(evidence.Files, file) body, err := json.Marshal(evidence) if err != nil { return err } _, err = tx.ExecContext(ctx, "INSERT INTO step_artifacts(run_id,sequence,artifacts_json) VALUES(?,?,?) ON CONFLICT(run_id,sequence) DO UPDATE SET artifacts_json=excluded.artifacts_json", id, sequence, string(body)) if err != nil { return err } return tx.Commit() }