@openai/codex-security 0.1.30 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +386 -37
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +4 -4
- package/_bundled_plugin/references/config-preflight.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -2
- package/_bundled_plugin/references/final-report.md +4 -2
- package/_bundled_plugin/references/scan-artifacts.md +2 -2
- package/_bundled_plugin/references/scan-contract.md +2 -2
- package/_bundled_plugin/references/threat-model.md +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +22 -0
- package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +19 -4
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
- package/_bundled_plugin/scripts/config_preflight.py +4 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
- package/_bundled_plugin/scripts/finding_preview.py +42 -82
- package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
- package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
- package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
- package/_bundled_plugin/scripts/rank_preview.py +86 -68
- package/_bundled_plugin/scripts/report_projection.py +37 -58
- package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
- package/_bundled_plugin/scripts/workbench/storage.py +11 -0
- package/_bundled_plugin/scripts/workbench_cli.py +11 -17
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +116 -228
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
- package/_bundled_plugin/scripts/workbench_progress.py +12 -34
- package/_bundled_plugin/scripts/workbench_publication.py +47 -62
- package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
- package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
- package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
- package/_bundled_plugin/scripts/workbench_schema.py +86 -271
- package/_bundled_plugin/scripts/workbench_severity.py +3 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
- package/_bundled_plugin/scripts/workbench_target.py +98 -10
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +6 -20
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/dist/api.d.ts +3 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +201 -207
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +277 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +9 -4
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +8 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +2 -8
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -5
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +281 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +21 -22
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +673 -701
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +1 -8
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +2 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +30 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +2 -6
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +1 -0
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +31 -9
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -33
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +2 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +63 -122
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +65 -34
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -31
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +4 -4
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +17 -16
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +10 -11
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +2 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +3 -3
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +2 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js +40 -62
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +1 -4
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +2 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +24 -6
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.js.map +1 -1
- package/dist/deduplication/scan.js +3 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +3 -19
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +0 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +22 -40
- package/dist/deep-progress.js.map +1 -1
- package/dist/errors.d.ts +3 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -7
- package/dist/errors.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +22 -22
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +4 -7
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +7 -17
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +2 -3
- package/dist/github.js.map +1 -1
- package/dist/import-scan.js +2 -2
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.js +7 -3
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -3
- package/dist/linear.js.map +1 -1
- package/dist/models.d.ts +24 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +36 -31
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts +29 -0
- package/dist/owner-evidence.d.ts.map +1 -0
- package/dist/owner-evidence.js +192 -0
- package/dist/owner-evidence.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +2 -4
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -0
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +15 -29
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +9 -13
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +11 -14
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +31 -41
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- package/dist/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +10 -13
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +230 -145
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +10 -20
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +8 -22
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +4 -4
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +38 -73
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +0 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +10 -19
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +1 -2
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +2 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +1 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +8 -6
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +8 -4
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +98 -84
- package/dist/security-policy.js.map +1 -1
- package/dist/server/dashboard/app.js +5 -5
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +1 -0
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/routes.d.ts +3 -2
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +19 -7
- package/dist/server/routes.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +2 -3
- package/dist/server/server.js.map +1 -1
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +4 -14
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/severity-store.js +8 -15
- package/dist/severity-store.js.map +1 -1
- package/dist/suggest-owners.d.ts +37 -0
- package/dist/suggest-owners.d.ts.map +1 -0
- package/dist/suggest-owners.js +111 -0
- package/dist/suggest-owners.js.map +1 -0
- package/dist/targets.d.ts +7 -2
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +29 -25
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +1 -0
- package/dist/thread-source.d.ts.map +1 -1
- package/dist/thread-source.js +1 -0
- package/dist/thread-source.js.map +1 -1
- package/dist/trusted-executable.d.ts +5 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +22 -5
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +20 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.js.map +1 -1
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +13 -34
- package/dist/worker-progress.js.map +1 -1
- package/docs/dedupe-records.md +24 -0
- package/package.json +15 -13
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- package/dist/server/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.js.map +0 -1
|
@@ -11,22 +11,16 @@ import sqlite3
|
|
|
11
11
|
import sys
|
|
12
12
|
import tempfile
|
|
13
13
|
import uuid
|
|
14
|
-
from dataclasses import dataclass
|
|
15
14
|
from datetime import datetime, timedelta
|
|
16
15
|
from pathlib import Path
|
|
17
16
|
from typing import Any, Callable
|
|
18
17
|
|
|
19
18
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
20
19
|
from deep_scan_config import resolve_deep_scan_config
|
|
21
|
-
from filesystem_identity import serialize_filesystem_identity
|
|
22
20
|
from finalize_scan_contract import _read_scan_local_json
|
|
23
21
|
from workbench.handoff import require_current_continuation
|
|
24
|
-
from
|
|
25
|
-
|
|
26
|
-
directory_snapshot_regular_file_count,
|
|
27
|
-
git_revision,
|
|
28
|
-
worktree_content_digest,
|
|
29
|
-
)
|
|
22
|
+
from workbench.storage import create_private_directory
|
|
23
|
+
from workbench_target import directory_snapshot_regular_file_count
|
|
30
24
|
from workbench_validation import optional_text, require_uuid, user_context_argument
|
|
31
25
|
|
|
32
26
|
DEEP_SCAN_WORKER_KINDS = ("setup", "discovery", "dedup")
|
|
@@ -136,42 +130,20 @@ def non_negative_int(value: str) -> int:
|
|
|
136
130
|
return parsed
|
|
137
131
|
|
|
138
132
|
|
|
139
|
-
|
|
140
|
-
class DeepScanDependencies:
|
|
141
|
-
now: Callable[[], str]
|
|
142
|
-
state_dir: Callable[[], Path]
|
|
143
|
-
require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row]
|
|
144
|
-
require_workspace: Callable[[sqlite3.Connection, str], sqlite3.Row]
|
|
145
|
-
require_target: Callable[[str], Path]
|
|
146
|
-
require_remediation_target: Callable[[str], Path]
|
|
147
|
-
require_scannable_target: Callable[[Path], None]
|
|
148
|
-
require_scope: Callable[[str, str, Path], str]
|
|
149
|
-
ensure_security_target: Callable[[sqlite3.Connection, str], str]
|
|
150
|
-
require_canonical_scan_directory: Callable[[Path], Path]
|
|
151
|
-
safe_segment: Callable[[str], str]
|
|
152
|
-
compact_timestamp: Callable[[], str]
|
|
153
|
-
scan_completion_lock: Callable[[str], Any]
|
|
154
|
-
preserve_stopped_results: Callable[[sqlite3.Connection, str], None]
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
_dependencies: DeepScanDependencies | None = None
|
|
133
|
+
_dependencies: Any = None
|
|
158
134
|
|
|
159
135
|
|
|
160
|
-
def configure(dependencies:
|
|
136
|
+
def configure(dependencies: Any) -> None:
|
|
161
137
|
global _dependencies
|
|
162
138
|
_dependencies = dependencies
|
|
163
139
|
|
|
164
140
|
|
|
165
|
-
def dependencies() ->
|
|
141
|
+
def dependencies() -> Any:
|
|
166
142
|
if _dependencies is None:
|
|
167
143
|
raise RuntimeError("Deep Scan workbench dependencies are not configured.")
|
|
168
144
|
return _dependencies
|
|
169
145
|
|
|
170
146
|
|
|
171
|
-
def now() -> str:
|
|
172
|
-
return dependencies().now()
|
|
173
|
-
|
|
174
|
-
|
|
175
147
|
def _bounded_error_text(message: str, maximum: int) -> str:
|
|
176
148
|
if len(message) <= maximum:
|
|
177
149
|
return message
|
|
@@ -206,54 +178,6 @@ def _parse_timestamp(value: str) -> datetime:
|
|
|
206
178
|
return datetime.fromisoformat(value)
|
|
207
179
|
|
|
208
180
|
|
|
209
|
-
def state_dir() -> Path:
|
|
210
|
-
return dependencies().state_dir()
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
def require_scan(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Row:
|
|
214
|
-
return dependencies().require_scan(connection, scan_id)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
def require_workspace(connection: sqlite3.Connection, workspace_id: str) -> sqlite3.Row:
|
|
218
|
-
return dependencies().require_workspace(connection, workspace_id)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
def require_target(value: str) -> Path:
|
|
222
|
-
return dependencies().require_target(value)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
def require_remediation_target(value: str) -> Path:
|
|
226
|
-
return dependencies().require_remediation_target(value)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def require_scannable_target(target: Path) -> None:
|
|
230
|
-
dependencies().require_scannable_target(target)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def require_scope(scope: str, mode: str, target: Path) -> str:
|
|
234
|
-
return dependencies().require_scope(scope, mode, target)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def ensure_security_target(connection: sqlite3.Connection, target_path: str) -> str:
|
|
238
|
-
return dependencies().ensure_security_target(connection, target_path)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
242
|
-
return dependencies().require_canonical_scan_directory(scan_dir)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
def safe_segment(value: str) -> str:
|
|
246
|
-
return dependencies().safe_segment(value)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
def compact_timestamp() -> str:
|
|
250
|
-
return dependencies().compact_timestamp()
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def scan_completion_lock(scan_id: str) -> Any:
|
|
254
|
-
return dependencies().scan_completion_lock(scan_id)
|
|
255
|
-
|
|
256
|
-
|
|
257
181
|
def require_deep_scan_run(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Row:
|
|
258
182
|
scan_id = require_uuid(scan_id, "scan-id")
|
|
259
183
|
row = connection.execute(
|
|
@@ -265,7 +189,7 @@ def require_deep_scan_run(connection: sqlite3.Connection, scan_id: str) -> sqlit
|
|
|
265
189
|
|
|
266
190
|
|
|
267
191
|
def deep_scan_deadline_reached(run: sqlite3.Row) -> bool:
|
|
268
|
-
elapsed = _parse_timestamp(now()) - _parse_timestamp(str(run["created_at"]))
|
|
192
|
+
elapsed = _parse_timestamp(dependencies().now()) - _parse_timestamp(str(run["created_at"]))
|
|
269
193
|
return elapsed.total_seconds() / 3600 >= run["max_time_hours"]
|
|
270
194
|
|
|
271
195
|
|
|
@@ -288,8 +212,8 @@ def require_deep_scan_ready_for_parent_completion(
|
|
|
288
212
|
def require_owned_scan(
|
|
289
213
|
connection: sqlite3.Connection, scan_id: str, thread_id: str
|
|
290
214
|
) -> tuple[sqlite3.Row, sqlite3.Row]:
|
|
291
|
-
scan = require_scan(connection, scan_id)
|
|
292
|
-
workspace = require_workspace(connection, scan["workspace_id"])
|
|
215
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
216
|
+
workspace = dependencies().require_workspace(connection, scan["workspace_id"])
|
|
293
217
|
owner = optional_text(thread_id, maximum=512)
|
|
294
218
|
if owner is None:
|
|
295
219
|
raise SystemExit("thread-id is required.")
|
|
@@ -311,7 +235,7 @@ def deep_scan_path(
|
|
|
311
235
|
raise SystemExit(f"{label} must be an absolute path inside the scan directory.")
|
|
312
236
|
try:
|
|
313
237
|
resolved = supplied.resolve(strict=True)
|
|
314
|
-
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
238
|
+
scan_dir = dependencies().require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
315
239
|
resolved.relative_to(scan_dir)
|
|
316
240
|
except (OSError, RuntimeError, ValueError) as exc:
|
|
317
241
|
raise SystemExit(f"{label} must be an existing path inside the scan directory.") from exc
|
|
@@ -395,23 +319,18 @@ def publication_matches_snapshot(publication: Path, snapshot: Path) -> bool:
|
|
|
395
319
|
|
|
396
320
|
def canonical_discovery_artifacts(scan: sqlite3.Row) -> dict[str, str]:
|
|
397
321
|
discovery_dir = Path(scan["scan_dir"]) / "artifacts" / "02_discovery"
|
|
398
|
-
artifacts = {
|
|
399
|
-
"inScopeFilesPath": discovery_dir / "in_scope_files.txt",
|
|
400
|
-
"candidateLedgerPath": discovery_dir / "candidate_ledger.jsonl",
|
|
401
|
-
}
|
|
402
|
-
labels = {
|
|
403
|
-
"inScopeFilesPath": "Canonical in-scope inventory path",
|
|
404
|
-
"candidateLedgerPath": "Canonical candidate ledger path",
|
|
405
|
-
}
|
|
406
322
|
return {
|
|
407
|
-
name: deep_scan_path(scan, str(
|
|
408
|
-
for name,
|
|
323
|
+
name: deep_scan_path(scan, str(discovery_dir / filename), label, kind="file")
|
|
324
|
+
for name, filename, label in (
|
|
325
|
+
("inScopeFilesPath", "in_scope_files.txt", "Canonical in-scope inventory path"),
|
|
326
|
+
("candidateLedgerPath", "candidate_ledger.jsonl", "Canonical candidate ledger path"),
|
|
327
|
+
)
|
|
409
328
|
}
|
|
410
329
|
|
|
411
330
|
|
|
412
331
|
def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, Any]:
|
|
413
332
|
run = require_deep_scan_run(connection, scan_id)
|
|
414
|
-
scan = require_scan(connection, run["scan_id"])
|
|
333
|
+
scan = dependencies().require_scan(connection, run["scan_id"])
|
|
415
334
|
worker_rows = connection.execute(
|
|
416
335
|
"""
|
|
417
336
|
SELECT *
|
|
@@ -686,8 +605,8 @@ def begin_deep_scan_for_scan(
|
|
|
686
605
|
args: argparse.Namespace,
|
|
687
606
|
) -> dict[str, Any]:
|
|
688
607
|
scan_id = require_uuid(scan_id, "scan-id")
|
|
689
|
-
candidate = require_scan(connection, scan_id)
|
|
690
|
-
workspace = require_workspace(connection, candidate["workspace_id"])
|
|
608
|
+
candidate = dependencies().require_scan(connection, scan_id)
|
|
609
|
+
workspace = dependencies().require_workspace(connection, candidate["workspace_id"])
|
|
691
610
|
if (
|
|
692
611
|
candidate["mode"] == "deep"
|
|
693
612
|
and candidate["status"] == "running"
|
|
@@ -701,7 +620,7 @@ def begin_deep_scan_for_scan(
|
|
|
701
620
|
args.claim_token,
|
|
702
621
|
error_message="Deep Scan orchestration is owned by another continuation.",
|
|
703
622
|
)
|
|
704
|
-
timestamp = now()
|
|
623
|
+
timestamp = dependencies().now()
|
|
705
624
|
with connection:
|
|
706
625
|
claimed_workspace = connection.execute(
|
|
707
626
|
"UPDATE workspaces SET thread_id = ?, updated_at = ? "
|
|
@@ -746,45 +665,35 @@ def begin_deep_scan_for_scan(
|
|
|
746
665
|
if workflow_version is None:
|
|
747
666
|
raise SystemExit("workflow-version is required.")
|
|
748
667
|
connection.execute("BEGIN IMMEDIATE")
|
|
749
|
-
|
|
668
|
+
with connection:
|
|
750
669
|
scan, _ = require_owned_scan(connection, scan_id, thread_id)
|
|
751
670
|
require_current_continuation(
|
|
752
671
|
scan,
|
|
753
672
|
args.claim_token,
|
|
754
673
|
error_message="Deep Scan orchestration is owned by another continuation.",
|
|
755
674
|
)
|
|
756
|
-
ensure_deep_scan_run(connection, scan, config, workflow_version, now())
|
|
757
|
-
connection.commit()
|
|
758
|
-
except BaseException:
|
|
759
|
-
connection.rollback()
|
|
760
|
-
raise
|
|
675
|
+
ensure_deep_scan_run(connection, scan, config, workflow_version, dependencies().now())
|
|
761
676
|
return deep_scan_result(connection, scan_id, start_disposition="created")
|
|
762
677
|
|
|
763
678
|
|
|
764
679
|
def begin_deep_scan_for_target(
|
|
765
680
|
connection: sqlite3.Connection, args: argparse.Namespace, thread_id: str
|
|
766
681
|
) -> dict[str, Any]:
|
|
767
|
-
target = require_target(args.target_path)
|
|
768
|
-
require_scannable_target(target)
|
|
769
|
-
scope = require_scope(args.scope, "deep", target)
|
|
682
|
+
target = dependencies().require_target(args.target_path)
|
|
683
|
+
dependencies().require_scannable_target(target)
|
|
684
|
+
scope = dependencies().require_scope(args.scope, "deep", target)
|
|
770
685
|
target_path = str(target)
|
|
771
686
|
existing = existing_deep_scan_for_target(connection, thread_id, target_path, scope)
|
|
772
687
|
if existing is not None:
|
|
773
688
|
return begin_deep_scan_for_scan(connection, existing["id"], thread_id, args)
|
|
774
689
|
target_metadata = target.stat()
|
|
775
|
-
|
|
776
|
-
target_snapshot_digest =
|
|
777
|
-
directory_content_digest(target)
|
|
778
|
-
if revision == "unversioned"
|
|
779
|
-
else worktree_content_digest(target)
|
|
780
|
-
)
|
|
781
|
-
target_device = serialize_filesystem_identity(target_metadata.st_dev)
|
|
782
|
-
target_inode = serialize_filesystem_identity(target_metadata.st_ino)
|
|
690
|
+
target_identity = dependencies().scan_target_identity(target, None, metadata=target_metadata)
|
|
691
|
+
revision, target_snapshot_digest, target_device, target_inode = target_identity
|
|
783
692
|
scope_file_count = directory_snapshot_regular_file_count(
|
|
784
693
|
target if scope == "." else target / scope
|
|
785
694
|
)
|
|
786
695
|
connection.execute("BEGIN IMMEDIATE")
|
|
787
|
-
|
|
696
|
+
with connection:
|
|
788
697
|
existing = existing_deep_scan_for_target(connection, thread_id, target_path, scope)
|
|
789
698
|
if existing is not None:
|
|
790
699
|
existing_run = connection.execute(
|
|
@@ -795,14 +704,16 @@ def begin_deep_scan_for_target(
|
|
|
795
704
|
workflow_version = optional_text(args.workflow_version, maximum=256)
|
|
796
705
|
if workflow_version is None:
|
|
797
706
|
raise SystemExit("workflow-version is required.")
|
|
798
|
-
ensure_deep_scan_run(
|
|
707
|
+
ensure_deep_scan_run(
|
|
708
|
+
connection, existing, config, workflow_version, dependencies().now()
|
|
709
|
+
)
|
|
799
710
|
connection.commit()
|
|
800
711
|
return deep_scan_result(
|
|
801
712
|
connection,
|
|
802
713
|
existing["id"],
|
|
803
714
|
start_disposition="joined" if existing_run is not None else "created",
|
|
804
715
|
)
|
|
805
|
-
current_target = require_remediation_target(target_path)
|
|
716
|
+
current_target = dependencies().require_remediation_target(target_path)
|
|
806
717
|
current_metadata = current_target.stat()
|
|
807
718
|
if (current_metadata.st_dev, current_metadata.st_ino) != (
|
|
808
719
|
target_metadata.st_dev,
|
|
@@ -832,23 +743,21 @@ def begin_deep_scan_for_target(
|
|
|
832
743
|
workflow_version = optional_text(args.workflow_version, maximum=256)
|
|
833
744
|
if workflow_version is None:
|
|
834
745
|
raise SystemExit("workflow-version is required.")
|
|
835
|
-
root = (
|
|
836
|
-
|
|
837
|
-
)
|
|
838
|
-
target_root = (root / safe_segment(target.name)).resolve()
|
|
746
|
+
root = dependencies().resolve_scan_root(args.scan_root)
|
|
747
|
+
target_root = (root / dependencies().safe_segment(target.name)).resolve()
|
|
839
748
|
if target_root == target or target in target_root.parents:
|
|
840
749
|
raise SystemExit("The scan artifact directory must be outside the selected target.")
|
|
841
|
-
target_root
|
|
750
|
+
create_private_directory(target_root)
|
|
842
751
|
user_context = user_context_argument(args)
|
|
843
752
|
model = optional_text(args.model, maximum=200)
|
|
844
753
|
reasoning_effort = optional_text(args.reasoning_effort, maximum=32)
|
|
845
754
|
workspace_id = str(uuid.uuid4())
|
|
846
755
|
scan_id = str(uuid.uuid4())
|
|
847
|
-
timestamp = now()
|
|
848
|
-
target_id = ensure_security_target(connection, target_path)
|
|
756
|
+
timestamp = dependencies().now()
|
|
757
|
+
target_id = dependencies().ensure_security_target(connection, target_path)
|
|
849
758
|
scan_dir = Path(
|
|
850
759
|
tempfile.mkdtemp(
|
|
851
|
-
prefix=f"{safe_segment(revision)}_{compact_timestamp()}_",
|
|
760
|
+
prefix=f"{dependencies().safe_segment(revision)}_{dependencies().compact_timestamp()}_",
|
|
852
761
|
dir=target_root,
|
|
853
762
|
)
|
|
854
763
|
).resolve()
|
|
@@ -871,55 +780,28 @@ def begin_deep_scan_for_target(
|
|
|
871
780
|
timestamp,
|
|
872
781
|
),
|
|
873
782
|
)
|
|
874
|
-
connection.execute(
|
|
875
|
-
""
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
scope,
|
|
894
|
-
user_context,
|
|
895
|
-
thread_id,
|
|
896
|
-
str(scan_dir),
|
|
897
|
-
model,
|
|
898
|
-
reasoning_effort,
|
|
899
|
-
timestamp,
|
|
900
|
-
timestamp,
|
|
901
|
-
timestamp,
|
|
902
|
-
),
|
|
903
|
-
)
|
|
904
|
-
connection.execute(
|
|
905
|
-
"""
|
|
906
|
-
INSERT INTO scan_progress (
|
|
907
|
-
scan_id, scope_file_count, review_items_total, review_items_completed,
|
|
908
|
-
reportable_findings_count, updated_at
|
|
909
|
-
) VALUES (?, ?, 0, 0, 0, ?)
|
|
910
|
-
""",
|
|
911
|
-
(scan_id, scope_file_count, timestamp),
|
|
912
|
-
)
|
|
913
|
-
connection.execute(
|
|
914
|
-
"UPDATE workspaces SET active_scan_id = ?, updated_at = ? WHERE id = ?",
|
|
915
|
-
(scan_id, timestamp, workspace_id),
|
|
783
|
+
workspace = connection.execute(
|
|
784
|
+
"SELECT * FROM workspaces WHERE id = ?", (workspace_id,)
|
|
785
|
+
).fetchone()
|
|
786
|
+
dependencies().insert_running_scan(
|
|
787
|
+
connection,
|
|
788
|
+
scan_id=scan_id,
|
|
789
|
+
workspace=workspace,
|
|
790
|
+
target=target,
|
|
791
|
+
scope=scope,
|
|
792
|
+
diff_target=None,
|
|
793
|
+
target_identity=target_identity,
|
|
794
|
+
target_root=target_root,
|
|
795
|
+
target_summary=None,
|
|
796
|
+
scope_file_count=scope_file_count,
|
|
797
|
+
timestamp=timestamp,
|
|
798
|
+
handoff_status="delivered",
|
|
799
|
+
model=model,
|
|
800
|
+
reasoning_effort=reasoning_effort,
|
|
801
|
+
scan_dir=scan_dir,
|
|
916
802
|
)
|
|
917
|
-
scan = require_scan(connection, scan_id)
|
|
803
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
918
804
|
ensure_deep_scan_run(connection, scan, config, workflow_version, timestamp)
|
|
919
|
-
connection.commit()
|
|
920
|
-
except BaseException:
|
|
921
|
-
connection.rollback()
|
|
922
|
-
raise
|
|
923
805
|
return deep_scan_result(connection, scan_id, start_disposition="created")
|
|
924
806
|
|
|
925
807
|
|
|
@@ -994,7 +876,7 @@ def claim_deep_scan_coordinator(
|
|
|
994
876
|
connection: sqlite3.Connection, args: argparse.Namespace
|
|
995
877
|
) -> dict[str, Any]:
|
|
996
878
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
997
|
-
with scan_completion_lock(scan_id):
|
|
879
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
998
880
|
return claim_deep_scan_coordinator_locked(connection, args, scan_id)
|
|
999
881
|
|
|
1000
882
|
|
|
@@ -1002,7 +884,7 @@ def claim_deep_scan_coordinator_locked(
|
|
|
1002
884
|
connection: sqlite3.Connection, args: argparse.Namespace, scan_id: str
|
|
1003
885
|
) -> dict[str, Any]:
|
|
1004
886
|
connection.execute("BEGIN IMMEDIATE")
|
|
1005
|
-
|
|
887
|
+
with connection:
|
|
1006
888
|
scan, _ = require_owned_scan(connection, scan_id, args.thread_id)
|
|
1007
889
|
require_current_continuation(
|
|
1008
890
|
scan,
|
|
@@ -1010,7 +892,7 @@ def claim_deep_scan_coordinator_locked(
|
|
|
1010
892
|
error_message="Deep Scan orchestration is owned by another continuation.",
|
|
1011
893
|
)
|
|
1012
894
|
run, _ = require_running_deep_scan(connection, scan_id)
|
|
1013
|
-
timestamp = now()
|
|
895
|
+
timestamp = dependencies().now()
|
|
1014
896
|
if args.coordinator_generation is not None:
|
|
1015
897
|
require_current_coordinator(run, args)
|
|
1016
898
|
disposition = "claimed"
|
|
@@ -1034,10 +916,6 @@ def claim_deep_scan_coordinator_locked(
|
|
|
1034
916
|
""",
|
|
1035
917
|
(int(args.coordinator_generation != run["coordinator_generation"]), timestamp, scan_id),
|
|
1036
918
|
)
|
|
1037
|
-
connection.commit()
|
|
1038
|
-
except BaseException:
|
|
1039
|
-
connection.rollback()
|
|
1040
|
-
raise
|
|
1041
919
|
return {
|
|
1042
920
|
**deep_scan_result(connection, scan_id),
|
|
1043
921
|
"coordinatorDisposition": disposition,
|
|
@@ -1122,7 +1000,7 @@ def recover_expired_coordinator(
|
|
|
1122
1000
|
|
|
1123
1001
|
|
|
1124
1002
|
def recover_candidate_ledger_publication(connection: sqlite3.Connection, scan_id: str) -> None:
|
|
1125
|
-
scan = require_scan(connection, scan_id)
|
|
1003
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1126
1004
|
ledger = Path(scan["scan_dir"]) / "artifacts" / "02_discovery" / "candidate_ledger.jsonl"
|
|
1127
1005
|
backups = sorted(
|
|
1128
1006
|
ledger.parent.glob(f".{ledger.name}.*.backup"),
|
|
@@ -1173,7 +1051,7 @@ def require_running_deep_scan(
|
|
|
1173
1051
|
connection: sqlite3.Connection, scan_id: str
|
|
1174
1052
|
) -> tuple[sqlite3.Row, sqlite3.Row]:
|
|
1175
1053
|
run = require_deep_scan_run(connection, scan_id)
|
|
1176
|
-
scan = require_scan(connection, run["scan_id"])
|
|
1054
|
+
scan = dependencies().require_scan(connection, run["scan_id"])
|
|
1177
1055
|
if run["status"] != "running" or run["cancel_requested"]:
|
|
1178
1056
|
raise SystemExit("Only a running Deep Scan can update orchestration state.")
|
|
1179
1057
|
if scan["status"] != "running" or scan["canceled_at"] is not None:
|
|
@@ -1199,10 +1077,10 @@ def upsert_deep_scan_worker(
|
|
|
1199
1077
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1200
1078
|
worker_id = require_uuid(args.worker_id, "worker-id")
|
|
1201
1079
|
connection.execute("BEGIN IMMEDIATE")
|
|
1202
|
-
|
|
1080
|
+
with connection:
|
|
1203
1081
|
run = require_deep_scan_run(connection, scan_id)
|
|
1204
1082
|
require_current_coordinator(run, args)
|
|
1205
|
-
scan = require_scan(connection, scan_id)
|
|
1083
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1206
1084
|
existing = connection.execute(
|
|
1207
1085
|
"SELECT * FROM deep_scan_workers WHERE id = ?", (worker_id,)
|
|
1208
1086
|
).fetchone()
|
|
@@ -1245,7 +1123,7 @@ def upsert_deep_scan_worker(
|
|
|
1245
1123
|
if args.result_manifest_path
|
|
1246
1124
|
else None
|
|
1247
1125
|
)
|
|
1248
|
-
timestamp = now()
|
|
1126
|
+
timestamp = dependencies().now()
|
|
1249
1127
|
if existing is None:
|
|
1250
1128
|
if args.kind == "dedup":
|
|
1251
1129
|
raise SystemExit("Create dedup workers with claim-deep-scan-dedup.")
|
|
@@ -1420,10 +1298,6 @@ def upsert_deep_scan_worker(
|
|
|
1420
1298
|
worker_id,
|
|
1421
1299
|
),
|
|
1422
1300
|
)
|
|
1423
|
-
connection.commit()
|
|
1424
|
-
except BaseException:
|
|
1425
|
-
connection.rollback()
|
|
1426
|
-
raise
|
|
1427
1301
|
return deep_scan_result(connection, scan_id)
|
|
1428
1302
|
|
|
1429
1303
|
|
|
@@ -1436,7 +1310,7 @@ def claim_deep_scan_dedup(
|
|
|
1436
1310
|
if len(set(input_ids)) != len(input_ids):
|
|
1437
1311
|
raise SystemExit("Dedup input worker IDs must be unique.")
|
|
1438
1312
|
connection.execute("BEGIN IMMEDIATE")
|
|
1439
|
-
|
|
1313
|
+
with connection:
|
|
1440
1314
|
run, scan = require_running_deep_scan(connection, scan_id)
|
|
1441
1315
|
require_current_coordinator(run, args)
|
|
1442
1316
|
prompt_path = deep_scan_path(scan, args.prompt_path, "Dedup prompt path", kind="file")
|
|
@@ -1526,7 +1400,7 @@ def claim_deep_scan_dedup(
|
|
|
1526
1400
|
if minimum_inputs == 2
|
|
1527
1401
|
else "A Deep Scan dedup requires at least one buffered discovery result."
|
|
1528
1402
|
)
|
|
1529
|
-
timestamp = now()
|
|
1403
|
+
timestamp = dependencies().now()
|
|
1530
1404
|
connection.execute(
|
|
1531
1405
|
"""
|
|
1532
1406
|
INSERT INTO deep_scan_workers (
|
|
@@ -1565,10 +1439,6 @@ def claim_deep_scan_dedup(
|
|
|
1565
1439
|
""",
|
|
1566
1440
|
(timestamp, scan_id),
|
|
1567
1441
|
)
|
|
1568
|
-
connection.commit()
|
|
1569
|
-
except BaseException:
|
|
1570
|
-
connection.rollback()
|
|
1571
|
-
raise
|
|
1572
1442
|
return deep_scan_result(connection, scan_id)
|
|
1573
1443
|
|
|
1574
1444
|
|
|
@@ -1576,7 +1446,7 @@ def commit_deep_scan_dedup(
|
|
|
1576
1446
|
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1577
1447
|
) -> dict[str, Any]:
|
|
1578
1448
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1579
|
-
with scan_completion_lock(scan_id):
|
|
1449
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
1580
1450
|
return commit_deep_scan_dedup_locked(connection, args, scan_id)
|
|
1581
1451
|
|
|
1582
1452
|
|
|
@@ -1590,7 +1460,7 @@ def commit_deep_scan_dedup_locked(
|
|
|
1590
1460
|
try:
|
|
1591
1461
|
run = require_deep_scan_run(connection, scan_id)
|
|
1592
1462
|
require_current_coordinator(run, args)
|
|
1593
|
-
scan = require_scan(connection, scan_id)
|
|
1463
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1594
1464
|
worker = require_deep_scan_worker(connection, worker_id)
|
|
1595
1465
|
if worker["scan_id"] != scan_id or worker["kind"] != "dedup":
|
|
1596
1466
|
raise SystemExit("Dedup worker does not belong to this Deep Scan.")
|
|
@@ -1652,7 +1522,7 @@ def commit_deep_scan_dedup_locked(
|
|
|
1652
1522
|
str(publication_copy),
|
|
1653
1523
|
canonical_candidate_ledger_path,
|
|
1654
1524
|
)
|
|
1655
|
-
timestamp = now()
|
|
1525
|
+
timestamp = dependencies().now()
|
|
1656
1526
|
connection.execute(
|
|
1657
1527
|
"""
|
|
1658
1528
|
UPDATE deep_scan_workers
|
|
@@ -1702,7 +1572,7 @@ def commit_deep_scan_dedup_locked(
|
|
|
1702
1572
|
|
|
1703
1573
|
def finish_deep_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1704
1574
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1705
|
-
with scan_completion_lock(scan_id):
|
|
1575
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
1706
1576
|
return finish_deep_scan_locked(connection, args, scan_id)
|
|
1707
1577
|
|
|
1708
1578
|
|
|
@@ -1719,7 +1589,7 @@ def finish_deep_scan_locked(
|
|
|
1719
1589
|
try:
|
|
1720
1590
|
run = require_deep_scan_run(connection, scan_id)
|
|
1721
1591
|
require_current_coordinator(run, args)
|
|
1722
|
-
scan = require_scan(connection, scan_id)
|
|
1592
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1723
1593
|
manifest_path = (
|
|
1724
1594
|
deep_scan_output_path(scan, args.manifest_path, "Deep Scan coordinator manifest path")
|
|
1725
1595
|
if args.staged_manifest_path
|
|
@@ -1784,7 +1654,7 @@ def finish_deep_scan_locked(
|
|
|
1784
1654
|
AND reducers.status IN ('failed', 'canceled')
|
|
1785
1655
|
)
|
|
1786
1656
|
""",
|
|
1787
|
-
(now(), scan_id, scan_id),
|
|
1657
|
+
(dependencies().now(), scan_id, scan_id),
|
|
1788
1658
|
)
|
|
1789
1659
|
buffered_worker_ids = [
|
|
1790
1660
|
row["id"]
|
|
@@ -1816,7 +1686,7 @@ def finish_deep_scan_locked(
|
|
|
1816
1686
|
if run["manifest_path"] is None:
|
|
1817
1687
|
connection.execute(
|
|
1818
1688
|
"UPDATE deep_scan_runs SET manifest_path = ?, updated_at = ? WHERE scan_id = ?",
|
|
1819
|
-
(manifest_path, now(), scan_id),
|
|
1689
|
+
(manifest_path, dependencies().now(), scan_id),
|
|
1820
1690
|
)
|
|
1821
1691
|
connection.commit()
|
|
1822
1692
|
return deep_scan_result(connection, scan_id)
|
|
@@ -1910,7 +1780,7 @@ def finish_deep_scan_locked(
|
|
|
1910
1780
|
if args.terminal_reason == "saturated":
|
|
1911
1781
|
# Mark any remaining workers canceled, including those whose own
|
|
1912
1782
|
# cancellation writes failed, so they cannot block completion.
|
|
1913
|
-
cancel_active_workers(connection, scan_id, now())
|
|
1783
|
+
cancel_active_workers(connection, scan_id, dependencies().now())
|
|
1914
1784
|
active_worker = connection.execute(
|
|
1915
1785
|
"""
|
|
1916
1786
|
SELECT 1 FROM deep_scan_workers
|
|
@@ -1950,7 +1820,7 @@ def finish_deep_scan_locked(
|
|
|
1950
1820
|
kind="file",
|
|
1951
1821
|
)
|
|
1952
1822
|
promotion = promote_staged_file(staged_manifest_path, manifest_path)
|
|
1953
|
-
timestamp = now()
|
|
1823
|
+
timestamp = dependencies().now()
|
|
1954
1824
|
connection.execute(
|
|
1955
1825
|
"""
|
|
1956
1826
|
UPDATE deep_scan_runs
|
|
@@ -1974,7 +1844,7 @@ def finish_deep_scan_locked(
|
|
|
1974
1844
|
|
|
1975
1845
|
def fail_deep_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1976
1846
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1977
|
-
with scan_completion_lock(scan_id):
|
|
1847
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
1978
1848
|
return fail_deep_scan_locked(connection, args, scan_id)
|
|
1979
1849
|
|
|
1980
1850
|
|
|
@@ -1989,7 +1859,7 @@ def fail_deep_scan_locked(
|
|
|
1989
1859
|
try:
|
|
1990
1860
|
run = require_deep_scan_run(connection, scan_id)
|
|
1991
1861
|
require_current_coordinator(run, args)
|
|
1992
|
-
scan = require_scan(connection, scan_id)
|
|
1862
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
1993
1863
|
manifest_path = None
|
|
1994
1864
|
if args.manifest_path:
|
|
1995
1865
|
manifest_path = (
|
|
@@ -2036,7 +1906,7 @@ def fail_deep_scan_locked(
|
|
|
2036
1906
|
kind="file",
|
|
2037
1907
|
)
|
|
2038
1908
|
promotion = promote_staged_file(staged_manifest_path, manifest_path)
|
|
2039
|
-
timestamp = now()
|
|
1909
|
+
timestamp = dependencies().now()
|
|
2040
1910
|
connection.execute(
|
|
2041
1911
|
"""
|
|
2042
1912
|
UPDATE deep_scan_runs
|
|
@@ -2080,12 +1950,12 @@ def record_deep_scan_publication_failure(
|
|
|
2080
1950
|
message = optional_text(args.message, maximum=2400)
|
|
2081
1951
|
if message is None:
|
|
2082
1952
|
raise SystemExit("message is required.")
|
|
2083
|
-
with scan_completion_lock(scan_id):
|
|
1953
|
+
with dependencies().scan_completion_lock(scan_id):
|
|
2084
1954
|
connection.execute("BEGIN IMMEDIATE")
|
|
2085
|
-
|
|
1955
|
+
with connection:
|
|
2086
1956
|
run = require_deep_scan_run(connection, scan_id)
|
|
2087
1957
|
require_current_coordinator(run, args)
|
|
2088
|
-
scan = require_scan(connection, scan_id)
|
|
1958
|
+
scan = dependencies().require_scan(connection, scan_id)
|
|
2089
1959
|
if (
|
|
2090
1960
|
run["status"] not in {"failed", "canceled", "interrupted"}
|
|
2091
1961
|
or scan["status"] != "failed"
|
|
@@ -2097,7 +1967,7 @@ def record_deep_scan_publication_failure(
|
|
|
2097
1967
|
connection.commit()
|
|
2098
1968
|
return deep_scan_result(connection, scan_id)
|
|
2099
1969
|
if run["publication_error_message"] != message:
|
|
2100
|
-
timestamp = now()
|
|
1970
|
+
timestamp = dependencies().now()
|
|
2101
1971
|
connection.execute(
|
|
2102
1972
|
"""
|
|
2103
1973
|
UPDATE deep_scan_runs
|
|
@@ -2106,10 +1976,6 @@ def record_deep_scan_publication_failure(
|
|
|
2106
1976
|
""",
|
|
2107
1977
|
(message, timestamp, scan_id),
|
|
2108
1978
|
)
|
|
2109
|
-
connection.commit()
|
|
2110
|
-
except BaseException:
|
|
2111
|
-
connection.rollback()
|
|
2112
|
-
raise
|
|
2113
1979
|
return deep_scan_result(connection, scan_id)
|
|
2114
1980
|
|
|
2115
1981
|
|
|
@@ -2118,7 +1984,7 @@ def clear_deep_scan_publication_failure(connection: sqlite3.Connection, scan_id:
|
|
|
2118
1984
|
connection.execute(
|
|
2119
1985
|
"UPDATE deep_scan_runs SET publication_error_message = NULL, updated_at = ? "
|
|
2120
1986
|
"WHERE scan_id = ? AND publication_error_message IS NOT NULL",
|
|
2121
|
-
(now(), scan_id),
|
|
1987
|
+
(dependencies().now(), scan_id),
|
|
2122
1988
|
)
|
|
2123
1989
|
|
|
2124
1990
|
|
|
@@ -22,9 +22,5 @@ def stored_filesystem_identity_matches(stored: object, current: int) -> bool:
|
|
|
22
22
|
return stored == serialize_filesystem_identity(current)
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def main() -> None:
|
|
26
|
-
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
27
|
-
|
|
28
|
-
|
|
29
25
|
if __name__ == "__main__":
|
|
30
|
-
|
|
26
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|