Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test(workbench): reuse historical migration fixtures (#1403)

mldangelo-oai9e019e3ba009
diff --git a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
index 79d9ee897..5c505148a 100644
--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
@@ -25,8 +25,12 @@ from workbench_test_support import (
create_saved_workspace,
initialize_git_repository,
run_workbench,
+ scan_command,
start_delivered_scan,
+ start_scan_command,
start_workspace_scan,
+ update_progress,
+ workspace_command,
write_completed_contract,
)
@@ -75,6 +79,18 @@ EXPECTED_MIGRATIONS = [
]
+def create_migration_history(connection: sqlite3.Connection) -> None:
+ connection.execute(
+ """
+ CREATE TABLE schema_migrations (
+ version INTEGER PRIMARY KEY,
+ name TEXT NOT NULL,
+ applied_at TEXT NOT NULL
+ )
+ """
+ )
+
+
def apply_historical_migrations(
connection: sqlite3.Connection,
namespace: dict[str, Any],
@@ -90,6 +106,115 @@ def apply_historical_migrations(
)
+def add_legacy_profile_columns(connection: sqlite3.Connection, *, dynamic: bool) -> tuple[str, str]:
+ if dynamic:
+ model = "codex-next/security-pro"
+ effort = "adaptive_depth"
+ model_definition = """
+ TEXT CHECK (
+ execution_model IS NULL
+ OR (
+ execution_model = trim(execution_model)
+ AND length(execution_model) BETWEEN 1 AND 128
+ )
+ )
+ """
+ effort_definition = """
+ TEXT CHECK (
+ (reasoning_effort IS NULL
+ OR (
+ reasoning_effort = trim(reasoning_effort)
+ AND length(reasoning_effort) BETWEEN 1 AND 64
+ ))
+ AND ((execution_model IS NULL) = (reasoning_effort IS NULL))
+ )
+ """
+ else:
+ model = "gpt-5.5"
+ effort = "high"
+ model_definition = """
+ TEXT CHECK (
+ execution_model IS NULL
+ OR execution_model IN ('gpt-5.4-mini', 'gpt-5.4', 'gpt-5.5')
+ )
+ """
+ effort_definition = """
+ TEXT CHECK (
+ (reasoning_effort IS NULL
+ OR reasoning_effort IN ('low', 'medium', 'high', 'xhigh'))
+ AND ((execution_model IS NULL) = (reasoning_effort IS NULL))
+ )
+ """
+ for table in ("workspaces", "scans"):
+ connection.execute(f"ALTER TABLE {table} ADD COLUMN execution_model {model_definition}")
+ connection.execute(f"ALTER TABLE {table} ADD COLUMN reasoning_effort {effort_definition}")
+ return model, effort
+
+
+def insert_legacy_profile_scan(
+ connection: sqlite3.Connection,
+ tmp_path: Path,
+ model: str,
+ effort: str,
+ timestamp: str,
+) -> tuple[str, str]:
+ workspace_id, scan_id = str(uuid.uuid4()), str(uuid.uuid4())
+ connection.execute(
+ """
+ INSERT INTO workspaces (
+ id, target_path, default_mode, execution_model, reasoning_effort,
+ created_at, updated_at
+ ) VALUES (?, ?, 'standard', ?, ?, ?, ?)
+ """,
+ (workspace_id, str(tmp_path / "target"), model, effort, timestamp, timestamp),
+ )
+ connection.execute(
+ """
+ INSERT INTO scans (
+ id, workspace_id, target_path, target_revision, scope, mode, scan_dir,
+ status, phase, started_at, created_at, updated_at, execution_model, reasoning_effort
+ ) VALUES (?, ?, ?, 'legacy-revision', '.', 'standard', ?, 'running',
+ 'discovery', ?, ?, ?, ?, ?)
+ """,
+ (
+ scan_id,
+ workspace_id,
+ str(tmp_path / "target"),
+ str(tmp_path / "legacy-scan"),
+ timestamp,
+ timestamp,
+ timestamp,
+ model,
+ effort,
+ ),
+ )
+ return workspace_id, scan_id
+
+
+def assert_new_scan_model_is_independent(state_dir: Path, target: Path, scan_root: Path) -> None:
+ current_workspace = create_saved_workspace(state_dir, target)
+ current_scan = start_delivered_scan(
+ state_dir,
+ "--workspace-id",
+ str(current_workspace["id"]),
+ "--scan-root",
+ str(scan_root),
+ "--model",
+ "gpt-5.6-sol",
+ )
+ current_scan_id = str(current_scan["results"]["scanId"])
+ assert current_scan["results"]["reasoningEffort"] is None
+ update_progress(state_dir, current_scan_id, "--reasoning-effort", "high")
+ with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
+ assert connection.execute(
+ """
+ SELECT legacy_execution_model, legacy_reasoning_effort, model, reasoning_effort
+ FROM scans WHERE id = ?
+ """,
+ (current_scan_id,),
+ ).fetchone() == (None, None, "gpt-5.6-sol", "high")
+
+
def test_sqlite_snapshot_includes_uncheckpointed_wal_rows(tmp_path: Path) -> None:
source = tmp_path / "source.sqlite3"
snapshot = tmp_path / "snapshot.sqlite3"
@@ -515,7 +640,7 @@ def test_workbench_retries_writer_admission_and_legacy_backfill(tmp_path: Path)
workspace = create_saved_workspace(state_dir, target)
scan_id, scan_dir = start_workspace_scan(state_dir, str(workspace["id"]), tmp_path / "scans")
write_completed_contract(scan_dir, scan_id, target)
- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)
+ scan_command(state_dir, "complete-scan", scan_id)
database = state_dir / "workbench.sqlite3"
with sqlite3.connect(database) as connection:
connection.execute(
@@ -1136,13 +1261,8 @@ def test_workbench_repairs_recorded_deep_scan_migration(
target = tmp_path / "target"
target.mkdir()
workspace = create_saved_workspace(state_dir, target, thread_id="thread-deep-scan", mode="deep")
- started = run_workbench(
- state_dir,
- "start-scan",
- "--workspace-id",
- str(workspace["id"]),
- "--scan-root",
- str(tmp_path / "scans"),
+ started = start_scan_command(
+ state_dir, str(workspace["id"]), "--scan-root", str(tmp_path / "scans")
)
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
@@ -1279,22 +1399,10 @@ def test_workbench_repairs_pre_release_scan_continuation_migration(tmp_path: Pat
with sqlite3.connect(database) as connection:
connection.execute("PRAGMA foreign_keys = ON")
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
+ create_migration_history(connection)
+ apply_historical_migrations(
+ connection, namespace, (*migrations[:10], *legacy_migrations), timestamp
)
- for version, name, sql in (*migrations[:10], *legacy_migrations):
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, timestamp),
- )
connection.execute(
"""
INSERT INTO workspaces (
@@ -1359,8 +1467,8 @@ def test_workbench_repairs_pre_release_scan_continuation_migration(tmp_path: Pat
(scan_id, timestamp, timestamp),
)
- first = run_workbench(state_dir, "get-workspace", "--workspace-id", workspace_id)
- second = run_workbench(state_dir, "get-workspace", "--workspace-id", workspace_id)
+ first = workspace_command(state_dir, "get-workspace", workspace_id)
+ second = workspace_command(state_dir, "get-workspace", workspace_id)
assert first == second
assert first["results"]["continuationThreadId"] is None
@@ -1408,7 +1516,7 @@ def test_workbench_repairs_recorded_scan_scope_file_count_migration(tmp_path: Pa
target = tmp_path / "target"
target.mkdir()
workspace = create_saved_workspace(state_dir, target)
- started = run_workbench(state_dir, "start-scan", "--workspace-id", str(workspace["id"]))
+ started = start_scan_command(state_dir, str(workspace["id"]))
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
@@ -1419,8 +1527,8 @@ def test_workbench_repairs_recorded_scan_scope_file_count_migration(tmp_path: Pa
("linear scan phase enforcement",),
)
- first = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
- second = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
+ first = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
+ second = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
assert first == second
assert first["results"]["progress"]["coverage"]["filesTotal"] is None
@@ -1496,22 +1604,13 @@ def test_workbench_upgrades_stable_scan_target_identity_migration(tmp_path: Path
with sqlite3.connect(database) as connection:
connection.execute("PRAGMA foreign_keys = ON")
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
+ create_migration_history(connection)
+ apply_historical_migrations(
+ connection,
+ namespace,
+ (*migrations[:10], legacy_migration, *migrations[11:15]),
+ timestamp,
)
- for version, name, sql in (*migrations[:10], legacy_migration, *migrations[11:15]):
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, timestamp),
- )
connection.execute(
"""
INSERT INTO workspaces (
@@ -1547,8 +1646,8 @@ def test_workbench_upgrades_stable_scan_target_identity_migration(tmp_path: Path
"UPDATE workspaces SET active_scan_id = ? WHERE id = ?", (scan_id, workspace_id)
)
- first = run_workbench(state_dir, "get-workspace", "--workspace-id", workspace_id)
- second = run_workbench(state_dir, "get-workspace", "--workspace-id", workspace_id)
+ first = workspace_command(state_dir, "get-workspace", workspace_id)
+ second = workspace_command(state_dir, "get-workspace", workspace_id)
repositories = run_workbench(state_dir, "list-repositories")["repositories"]
assert first == second
@@ -1592,7 +1691,7 @@ def test_workbench_applies_shadowed_delivered_claim_cleanup_once(tmp_path: Path)
target = tmp_path / "target"
target.mkdir()
workspace = create_saved_workspace(state_dir, target)
- started = run_workbench(state_dir, "start-scan", "--workspace-id", str(workspace["id"]))
+ started = start_scan_command(state_dir, str(workspace["id"]))
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
@@ -1670,7 +1769,7 @@ def test_workbench_repairs_shadowed_phase_progress_migration(
target = tmp_path / "target"
target.mkdir()
workspace = create_saved_workspace(state_dir, target)
- started = run_workbench(state_dir, "start-scan", "--workspace-id", str(workspace["id"]))
+ started = start_scan_command(state_dir, str(workspace["id"]))
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
@@ -1683,8 +1782,8 @@ def test_workbench_repairs_shadowed_phase_progress_migration(
(legacy_name,),
)
- first = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
- second = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
+ first = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
+ second = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
assert first == second
with sqlite3.connect(database) as connection:
@@ -1719,7 +1818,7 @@ def test_workbench_repairs_shadowed_preflight_progress_migration(
target = tmp_path / "target"
target.mkdir()
saved = create_saved_workspace(state_dir, target)
- started = run_workbench(state_dir, "start-scan", "--workspace-id", str(saved["id"]))
+ started = start_scan_command(state_dir, str(saved["id"]))
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
with sqlite3.connect(database) as connection:
@@ -1760,7 +1859,7 @@ def test_workbench_repairs_shadowed_scan_recipe_migration(tmp_path: Path) -> Non
target = tmp_path / "target"
target.mkdir()
workspace = create_saved_workspace(state_dir, target)
- started = run_workbench(state_dir, "start-scan", "--workspace-id", str(workspace["id"]))
+ started = start_scan_command(state_dir, str(workspace["id"]))
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
@@ -1772,8 +1871,8 @@ def test_workbench_repairs_shadowed_scan_recipe_migration(tmp_path: Path) -> Non
("dynamic scan execution profiles",),
)
- first = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
- second = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
+ first = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
+ second = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
assert first == second
with sqlite3.connect(database) as connection:
@@ -1796,7 +1895,7 @@ def test_workbench_reconciles_released_completion_warning_version(tmp_path: Path
target = tmp_path / "target"
target.mkdir()
workspace = create_saved_workspace(state_dir, target)
- started = run_workbench(state_dir, "start-scan", "--workspace-id", str(workspace["id"]))
+ started = start_scan_command(state_dir, str(workspace["id"]))
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
@@ -1813,8 +1912,8 @@ def test_workbench_reconciles_released_completion_warning_version(tmp_path: Path
("persist scan completion warnings",),
)
- first = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
- second = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
+ first = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
+ second = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
assert first == second
with sqlite3.connect(database) as connection:
@@ -1835,7 +1934,7 @@ def test_workbench_repairs_recorded_completion_warnings_migration(tmp_path: Path
target = tmp_path / "target"
target.mkdir()
workspace = create_saved_workspace(state_dir, target)
- started = run_workbench(state_dir, "start-scan", "--workspace-id", str(workspace["id"]))
+ started = start_scan_command(state_dir, str(workspace["id"]))
scan_id = str(started["results"]["scanId"])
database = state_dir / "workbench.sqlite3"
@@ -1847,8 +1946,8 @@ def test_workbench_repairs_recorded_completion_warnings_migration(tmp_path: Path
("recoverable scan attention",),
)
- first = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
- second = run_workbench(state_dir, "get-workspace", "--workspace-id", str(workspace["id"]))
+ first = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
+ second = workspace_command(state_dir, "get-workspace", str(workspace["id"]))
assert first == second
with sqlite3.connect(database) as connection:
@@ -1886,116 +1985,24 @@ def test_workbench_reconciles_legacy_execution_profile_migrations(
database.parent.mkdir(parents=True)
target = tmp_path / "target"
target.mkdir()
- workspace_id = str(uuid.uuid4())
- scan_id = str(uuid.uuid4())
timestamp = "2026-07-01T00:00:00Z"
namespace = runpy.run_path(str(SCRIPT), run_name="codex_security_workbench_schema")
migrations = namespace["MIGRATIONS"]
- if dynamic:
- legacy_model = "codex-next/security-pro"
- legacy_effort = "adaptive_depth"
- model_definition = """
- TEXT CHECK (
- execution_model IS NULL
- OR (
- execution_model = trim(execution_model)
- AND length(execution_model) BETWEEN 1 AND 128
- )
- )
- """
- effort_definition = """
- TEXT CHECK (
- (reasoning_effort IS NULL
- OR (
- reasoning_effort = trim(reasoning_effort)
- AND length(reasoning_effort) BETWEEN 1 AND 64
- ))
- AND ((execution_model IS NULL) = (reasoning_effort IS NULL))
- )
- """
- else:
- legacy_model = "gpt-5.5"
- legacy_effort = "high"
- model_definition = """
- TEXT CHECK (
- execution_model IS NULL
- OR execution_model IN ('gpt-5.4-mini', 'gpt-5.4', 'gpt-5.5')
- )
- """
- effort_definition = """
- TEXT CHECK (
- (reasoning_effort IS NULL
- OR reasoning_effort IN ('low', 'medium', 'high', 'xhigh'))
- AND ((execution_model IS NULL) = (reasoning_effort IS NULL))
- )
- """
with sqlite3.connect(database) as connection:
connection.execute("PRAGMA foreign_keys = ON")
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
- )
+ create_migration_history(connection)
current_migrations = (*migrations[: legacy_version - 1], *migrations[legacy_version:24])
- for version, name, sql in current_migrations:
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, timestamp),
- )
- for table in ("workspaces", "scans"):
- connection.execute(f"ALTER TABLE {table} ADD COLUMN execution_model {model_definition}")
- connection.execute(
- f"ALTER TABLE {table} ADD COLUMN reasoning_effort {effort_definition}"
- )
+ apply_historical_migrations(connection, namespace, current_migrations, timestamp)
+ legacy_model, legacy_effort = add_legacy_profile_columns(connection, dynamic=dynamic)
connection.execute(
"INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
(legacy_version, legacy_name, timestamp),
)
if preexisting_model:
connection.execute("ALTER TABLE scans ADD COLUMN model TEXT")
- connection.execute(
- """
- INSERT INTO workspaces (
- id, target_path, default_mode, execution_model, reasoning_effort,
- created_at, updated_at
- ) VALUES (?, ?, 'standard', ?, ?, ?, ?)
- """,
- (
- workspace_id,
- str(target),
- legacy_model,
- legacy_effort,
- timestamp,
- timestamp,
- ),
- )
- connection.execute(
- """
- INSERT INTO scans (
- id, workspace_id, target_path, target_revision, scope, mode, scan_dir,
- status, phase, started_at, created_at, updated_at,
- execution_model, reasoning_effort
- ) VALUES (?, ?, ?, 'legacy-revision', '.', 'standard', ?, 'running',
- 'discovery', ?, ?, ?, ?, ?)
- """,
- (
- scan_id,
- workspace_id,
- str(target),
- str(tmp_path / "legacy-scan"),
- timestamp,
- timestamp,
- timestamp,
- legacy_model,
- legacy_effort,
- ),
+ workspace_id, scan_id = insert_legacy_profile_scan(
+ connection, tmp_path, legacy_model, legacy_effort, timestamp
)
if preexisting_model:
connection.execute("UPDATE scans SET model = 'current-model' WHERE id = ?", (scan_id,))
@@ -2031,33 +2038,7 @@ def test_workbench_reconciles_legacy_execution_profile_migrations(
).fetchone() == (legacy_model, legacy_effort)
assert connection.execute("PRAGMA foreign_key_check").fetchall() == []
- current_workspace = create_saved_workspace(state_dir, target)
- current_scan = start_delivered_scan(
- state_dir,
- "--workspace-id",
- str(current_workspace["id"]),
- "--scan-root",
- str(tmp_path / "current-scans"),
- "--model",
- "gpt-5.6-sol",
- )
- current_scan_id = str(current_scan["results"]["scanId"])
- run_workbench(
- state_dir,
- "update-progress",
- "--scan-id",
- current_scan_id,
- "--reasoning-effort",
- "high",
- )
- with sqlite3.connect(database) as connection:
- assert connection.execute(
- """
- SELECT legacy_execution_model, legacy_reasoning_effort, model, reasoning_effort
- FROM scans WHERE id = ?
- """,
- (current_scan_id,),
- ).fetchone() == (None, None, "gpt-5.6-sol", "high")
+ assert_new_scan_model_is_independent(state_dir, target, tmp_path / "current-scans")
def test_workbench_upgrades_released_database_schema(tmp_path: Path) -> None:
@@ -2072,22 +2053,8 @@ def test_workbench_upgrades_released_database_schema(tmp_path: Path) -> None:
]
with sqlite3.connect(database) as connection:
connection.row_factory = sqlite3.Row
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
- )
- for version, name, sql in migrations[:2]:
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, "2026-06-01T00:00:00Z"),
- )
+ create_migration_history(connection)
+ apply_historical_migrations(connection, namespace, migrations[:2], "2026-06-01T00:00:00Z")
run_workbench(state_dir, "database-info")
@@ -2108,7 +2075,10 @@ def test_workbench_upgrades_released_database_schema(tmp_path: Path) -> None:
}
-def test_workbench_upgrades_pre_release_phase_progress_migration(tmp_path: Path) -> None:
[email protected]("preflight", [False, True], ids=("phase", "preflight"))
+def test_workbench_upgrades_pre_release_phase_and_preflight_progress_migration(
+ tmp_path: Path, preflight: bool
+) -> None:
state_dir = tmp_path / "state"
database = state_dir / "workbench.sqlite3"
database.parent.mkdir(parents=True)
@@ -2117,92 +2087,26 @@ def test_workbench_upgrades_pre_release_phase_progress_migration(tmp_path: Path)
phase_migration = next(
migration for migration in migrations if migration[1] == "phase-specific scan progress"
)
-
- with sqlite3.connect(database) as connection:
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
- )
- for version, name, sql in migrations[:11]:
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, "2026-07-01T00:00:00Z"),
- )
- for statement in namespace["sql_statements"](phase_migration[2]):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (12, phase_migration[1], "2026-07-01T00:00:00Z"),
+ historical_migrations = [*migrations[:11], (12, *phase_migration[1:])]
+ expected_progress_columns = {
+ "scope_file_count",
+ "phase_items_completed",
+ "phase_items_total",
+ "phase_progress_unit",
+ }
+ if preflight:
+ preflight_migration = next(
+ migration for migration in migrations if migration[1] == "current scan preflight state"
)
-
- run_workbench(state_dir, "database-info")
-
- with sqlite3.connect(database) as connection:
- assert (
- connection.execute(
- "SELECT version, name FROM schema_migrations WHERE version >= 12 ORDER BY version"
- ).fetchall()
- == EXPECTED_MIGRATIONS[11:]
+ historical_migrations.append((13, *preflight_migration[1:]))
+ expected_progress_columns.update(
+ ("preflight_checks_completed", "preflight_checks_total", "preflight_issues_json")
)
- assert "continuation_thread_id" in {
- row[1] for row in connection.execute("PRAGMA table_info(scans)")
- }
- assert {row[1] for row in connection.execute("PRAGMA table_info(scan_progress)")} >= {
- "scope_file_count",
- "phase_items_completed",
- "phase_items_total",
- "phase_progress_unit",
- }
-
-
-def test_workbench_upgrades_pre_release_preflight_progress_migration(tmp_path: Path) -> None:
- state_dir = tmp_path / "state"
- database = state_dir / "workbench.sqlite3"
- database.parent.mkdir(parents=True)
- namespace = runpy.run_path(str(SCRIPT), run_name="codex_security_workbench_schema")
- migrations = namespace["MIGRATIONS"]
- phase_migration = next(
- migration for migration in migrations if migration[1] == "phase-specific scan progress"
- )
- preflight_migration = next(
- migration for migration in migrations if migration[1] == "current scan preflight state"
- )
with sqlite3.connect(database) as connection:
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
- )
- for version, name, sql in migrations[:11]:
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, "2026-07-01T00:00:00Z"),
- )
- for statement in namespace["sql_statements"](phase_migration[2]):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (12, phase_migration[1], "2026-07-01T00:00:00Z"),
- )
- for statement in namespace["sql_statements"](preflight_migration[2]):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (13, preflight_migration[1], "2026-07-01T00:00:00Z"),
+ create_migration_history(connection)
+ apply_historical_migrations(
+ connection, namespace, historical_migrations, "2026-07-01T00:00:00Z"
)
run_workbench(state_dir, "database-info")
@@ -2217,15 +2121,9 @@ def test_workbench_upgrades_pre_release_preflight_progress_migration(tmp_path: P
assert "continuation_thread_id" in {
row[1] for row in connection.execute("PRAGMA table_info(scans)")
}
- assert {row[1] for row in connection.execute("PRAGMA table_info(scan_progress)")} >= {
- "scope_file_count",
- "phase_items_completed",
- "phase_items_total",
- "phase_progress_unit",
- "preflight_checks_completed",
- "preflight_checks_total",
- "preflight_issues_json",
- }
+ assert {row[1] for row in connection.execute("PRAGMA table_info(scan_progress)")} >= (
+ expected_progress_columns
+ )
def test_workbench_normalizes_pre_release_migration_numbers(tmp_path: Path) -> None:
@@ -2402,86 +2300,16 @@ def test_workbench_upgrades_legacy_execution_profile_migrations(
namespace = runpy.run_path(str(SCRIPT), run_name="codex_security_workbench_schema")
migrations = namespace["MIGRATIONS"]
timestamp = "2026-07-01T00:00:00Z"
- workspace_id = str(uuid.uuid4())
- scan_id = str(uuid.uuid4())
- if has_dynamic_profile_migration:
- model = "codex-next/security-pro"
- reasoning_effort = "adaptive_depth"
- model_definition = """
- TEXT CHECK (
- execution_model IS NULL
- OR (
- execution_model = trim(execution_model)
- AND length(execution_model) BETWEEN 1 AND 128
- )
- )
- """
- reasoning_effort_definition = """
- TEXT CHECK (
- (reasoning_effort IS NULL
- OR (
- reasoning_effort = trim(reasoning_effort)
- AND length(reasoning_effort) BETWEEN 1 AND 64
- ))
- AND ((execution_model IS NULL) = (reasoning_effort IS NULL))
- )
- """
- else:
- model = "gpt-5.5"
- reasoning_effort = "high"
- model_definition = """
- TEXT CHECK (
- execution_model IS NULL
- OR execution_model IN ('gpt-5.4-mini', 'gpt-5.4', 'gpt-5.5')
- )
- """
- reasoning_effort_definition = """
- TEXT CHECK (
- (reasoning_effort IS NULL
- OR reasoning_effort IN ('low', 'medium', 'high', 'xhigh'))
- AND ((execution_model IS NULL) = (reasoning_effort IS NULL))
- )
- """
with sqlite3.connect(database) as connection:
connection.row_factory = sqlite3.Row
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
+ create_migration_history(connection)
+ apply_historical_migrations(connection, namespace, migrations[:10], timestamp)
+ model, reasoning_effort = add_legacy_profile_columns(
+ connection, dynamic=has_dynamic_profile_migration
)
- for version, name, sql in migrations[:10]:
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, timestamp),
- )
- for table in ("workspaces", "scans"):
- connection.execute(
- f"""
- ALTER TABLE {table}
- ADD COLUMN execution_model {model_definition}
- """
- )
- connection.execute(
- f"""
- ALTER TABLE {table}
- ADD COLUMN reasoning_effort {reasoning_effort_definition}
- """
- )
if migration_history == "canonical-metadata":
- for version, name, sql in migrations[10:24]:
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, timestamp),
- )
+ apply_historical_migrations(connection, namespace, migrations[10:24], timestamp)
connection.execute("ALTER TABLE scans ADD COLUMN model TEXT")
connection.execute(
"INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
@@ -2522,47 +2350,8 @@ def test_workbench_upgrades_legacy_execution_profile_migrations(
timestamp,
),
)
- connection.execute(
- """
- INSERT INTO workspaces (
- id, target_path, default_mode, execution_model, reasoning_effort,
- created_at, updated_at
- ) VALUES (?, ?, ?, ?, ?, ?, ?)
- """,
- (
- workspace_id,
- str(target),
- "standard",
- model,
- reasoning_effort,
- timestamp,
- timestamp,
- ),
- )
- connection.execute(
- """
- INSERT INTO scans (
- id, workspace_id, target_path, target_revision, scope, mode, scan_dir,
- status, phase, started_at, created_at, updated_at,
- execution_model, reasoning_effort
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- """,
- (
- scan_id,
- workspace_id,
- str(target),
- "legacy-revision",
- ".",
- "standard",
- str(tmp_path / "legacy-scan"),
- "running",
- "discovery",
- timestamp,
- timestamp,
- timestamp,
- model,
- reasoning_effort,
- ),
+ workspace_id, scan_id = insert_legacy_profile_scan(
+ connection, tmp_path, model, reasoning_effort, timestamp
)
if has_completion_warning:
connection.execute(
@@ -2610,36 +2399,7 @@ def test_workbench_upgrades_legacy_execution_profile_migrations(
).fetchone() == (model, reasoning_effort)
assert connection.execute("PRAGMA foreign_key_check").fetchall() == []
- current_workspace = create_saved_workspace(state_dir, target)
- current_scan = start_delivered_scan(
- state_dir,
- "--workspace-id",
- str(current_workspace["id"]),
- "--scan-root",
- str(tmp_path / "current-scans"),
- "--model",
- "gpt-5.6-sol",
- )
- current_scan_id = str(current_scan["results"]["scanId"])
- assert current_scan["results"]["reasoningEffort"] is None
- run_workbench(
- state_dir,
- "update-progress",
- "--scan-id",
- current_scan_id,
- "--reasoning-effort",
- "high",
- )
- with sqlite3.connect(database) as connection:
- assert connection.execute(
- """
- SELECT legacy_execution_model, legacy_reasoning_effort, model,
- reasoning_effort
- FROM scans
- WHERE id = ?
- """,
- (current_scan_id,),
- ).fetchone() == (None, None, "gpt-5.6-sol", "high")
+ assert_new_scan_model_is_independent(state_dir, target, tmp_path / "current-scans")
def test_workbench_rejects_unknown_execution_profile_migration_without_mutating_history() -> None:
@@ -2647,23 +2407,9 @@ def test_workbench_rejects_unknown_execution_profile_migration_without_mutating_
apply_migrations = namespace["apply_migrations"]
connection = sqlite3.connect(":memory:")
connection.row_factory = sqlite3.Row
- connection.execute(
- """
- CREATE TABLE schema_migrations (
- version INTEGER PRIMARY KEY,
- name TEXT NOT NULL,
- applied_at TEXT NOT NULL
- )
- """
- )
+ create_migration_history(connection)
timestamp = "2026-07-01T00:00:00Z"
- for version, name, sql in namespace["MIGRATIONS"][:10]:
- for statement in namespace["sql_statements"](sql):
- connection.execute(statement)
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (version, name, timestamp),
- )
+ apply_historical_migrations(connection, namespace, namespace["MIGRATIONS"][:10], timestamp)
for table in ("workspaces", "scans"):
connection.execute(f"ALTER TABLE {table} ADD COLUMN execution_model TEXT")
connection.execute(f"ALTER TABLE {table} ADD COLUMN reasoning_effort TEXT")