保存完整任务报告及完成审计原子化基线,最新回归待确认

This commit is contained in:
xuans committed 2026-10-02 17:51:37 +08:00
1 parent 8a8b1a5e0e
commit 4e8d50919a
21 files changed
+505 -52

No files matched your search

+5 -2
View File
@@ -20,6 +20,7 @@ import (
//go:embed migrations/sqlite/0016_task_deployment_results.sql migrations/mysql/0016_task_deployment_results.sql migrations/postgres/0016_task_deployment_results.sql
//go:embed migrations/sqlite/0017_deployment_transactions.sql migrations/mysql/0017_deployment_transactions.sql migrations/postgres/0017_deployment_transactions.sql
//go:embed migrations/sqlite/0018_recovery_evidence.sql migrations/mysql/0018_recovery_evidence.sql migrations/postgres/0018_recovery_evidence.sql migrations/sqlite/0019_password_auth_only.sql migrations/mysql/0019_password_auth_only.sql migrations/postgres/0019_password_auth_only.sql
//go:embed migrations/sqlite/0020_task_deployment_reports.sql migrations/mysql/0020_task_deployment_reports.sql migrations/postgres/0020_task_deployment_reports.sql
var migrationFiles embed.FS
func Migrate(ctx context.Context, db *sql.DB, driver string) error {
@@ -44,7 +45,7 @@ func Migrate(ctx context.Context, db *sql.DB, driver string) error {
return nil
}
const latestMigrationVersion = 19
const latestMigrationVersion = 20
// currentMigrationVersion 在执行业务迁移前拒绝新版数据库及不连续的迁移历史。
func currentMigrationVersion(ctx context.Context, db *sql.DB) (int, error) {
@@ -84,7 +85,7 @@ func applyMigration(ctx context.Context, db *sql.DB, driver string, version int)
return applySQLiteTaskMigration(ctx, db, statements, version)
}
if driver == "mysql" {
if version >= 15 && version <= 17 {
if (version >= 15 && version <= 17) || version == 20 {
return applyMySQLDeploymentMigration(ctx, db, version, statements)
}
if version == 14 {
@@ -237,6 +238,8 @@ func migrationName(version int) string {
return "recovery_evidence"
case 19:
return "password_auth_only"
case 20:
return "task_deployment_reports"
default:
return "unknown"
}
@@ -0,0 +1,8 @@
CREATE TABLE task_deployment_reports (
task_id VARCHAR(36) NOT NULL,
attempt_id VARCHAR(36) NOT NULL,
attempt_number INT NOT NULL,
report_json MEDIUMTEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (task_id, attempt_id)
);
@@ -0,0 +1,8 @@
CREATE TABLE task_deployment_reports (
task_id TEXT NOT NULL,
attempt_id TEXT NOT NULL,
attempt_number INTEGER NOT NULL,
report_json TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (task_id, attempt_id)
);
@@ -0,0 +1,8 @@
CREATE TABLE task_deployment_reports (
task_id TEXT NOT NULL,
attempt_id TEXT NOT NULL,
attempt_number INTEGER NOT NULL,
report_json TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (task_id, attempt_id)
);
@@ -57,7 +57,7 @@ type mysqlDeploymentShape struct {
var (
mysqlDeploymentTablePattern = regexp.MustCompile(`^CREATE TABLE ([a-z_]+) \($`)
mysqlDeploymentColumnPattern = regexp.MustCompile(`^([a-z_]+) (VARCHAR\([0-9]+\)|INT|TEXT|DATETIME) NOT NULL(?: DEFAULT (CURRENT_TIMESTAMP|0))?( PRIMARY KEY)?$`)
mysqlDeploymentColumnPattern = regexp.MustCompile(`^([a-z_]+) (VARCHAR\([0-9]+\)|INT|TEXT|MEDIUMTEXT|DATETIME) NOT NULL(?: DEFAULT (CURRENT_TIMESTAMP|0))?( PRIMARY KEY)?$`)
mysqlDeploymentIndexPattern = regexp.MustCompile(`^(PRIMARY KEY|UNIQUE KEY ([a-z_]+)|INDEX ([a-z_]+)) \(([a-z_, ]+)\)$`)
mysqlIntegerWidthPattern = regexp.MustCompile(`^int\([0-9]+\)$`)
)
@@ -8,7 +8,7 @@ import (
)
func TestMySQLDeploymentShapeDefinitions(t *testing.T) {
for version := 15; version <= 17; version++ {
for _, version := range []int{15, 16, 17, 20} {
statements := mysqlDeploymentStatements(t, version)
shape, err := parseMySQLDeploymentShape(statements[0])
if err != nil || len(shape.Columns) == 0 || len(shape.Indexes) == 0 {
@@ -60,6 +60,10 @@ func TestSQLiteCanceledQueriesReleaseFiles(t *testing.T) {
rows, err := query(ctx)
if rows != nil {
for rows.Next() {
// 单执行线程也要覆盖结果集已打开后的取消,保留其余轮次的自然竞争。
if attempt%2 == 0 {
runtime.Gosched()
}
var value int
if scanErr := rows.Scan(&value); scanErr != nil {
err = scanErr