Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/ofw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
Sha256Digest,
WorkspaceFile,
)
from ofw.diagnosis import (
ClusterRevisionRef,
ClusterState,
DiagnosisError,
DiagnosisErrorCode,
DiagnosisResult,
DiagnosisRun,
EvidenceAnchor,
EvidenceAnchorKind,
FailureCluster,
MechanismKey,
PythonDiagnoser,
Severity,
TraceDiagnosis,
)
from ofw.harness import EditableFile, Harness, Subagent, Tool, editable
from ofw.mine import (
Mine,
Expand Down Expand Up @@ -109,6 +124,7 @@ class _OfwNamespace:
ServiceName = ServiceName
MiningPolicy = MiningPolicy
ScoreName = ScoreName
PythonDiagnoser = PythonDiagnoser

def editable(self, path: Path) -> EditableFile:
return editable(path)
Expand Down Expand Up @@ -158,6 +174,8 @@ def read_snapshot_content(
"AssetAccess",
"CanaryCase",
"CaseId",
"ClusterState",
"ClusterRevisionRef",
"ComponentKind",
"CollectionError",
"CollectionErrorCode",
Expand All @@ -166,7 +184,14 @@ def read_snapshot_content(
"CommandVerifier",
"ContentCaptureMode",
"DockerCompose",
"DiagnosisResult",
"DiagnosisRun",
"DiagnosisError",
"DiagnosisErrorCode",
"EditableFile",
"EvidenceAnchor",
"EvidenceAnchorKind",
"FailureCluster",
"GitCommit",
"Harness",
"HarnessAsset",
Expand All @@ -187,6 +212,7 @@ def read_snapshot_content(
"MineError",
"MineErrorCode",
"MiningPolicy",
"MechanismKey",
"ObservationContent",
"ObservationContentField",
"ObservationContentHit",
Expand All @@ -199,20 +225,23 @@ def read_snapshot_content(
"ProcessLimits",
"PythonEntrypoint",
"PythonLoop",
"PythonDiagnoser",
"PythonVerifier",
"RunErrorCode",
"RunResult",
"RunStatus",
"ScoreName",
"Sha256Digest",
"ServiceName",
"Severity",
"SecretEnvironmentVariable",
"SnapshotContentReference",
"Subagent",
"Tool",
"TraceWindow",
"TracePartition",
"TraceQualityThreshold",
"TraceDiagnosis",
"VerifierResult",
"VerifierVerdict",
"WorkspaceFile",
Expand Down
46 changes: 46 additions & 0 deletions src/ofw/_diagnosis_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Timed child-process entrypoint for a file-backed trace diagnoser."""

from __future__ import annotations

import importlib
import inspect
import sys
from collections.abc import Callable
from typing import cast

from pydantic import TypeAdapter, ValidationError

from ofw.diagnosis import TraceDiagnosis
from ofw.mine import TraceSnapshot

_SNAPSHOT_ADAPTER: TypeAdapter[TraceSnapshot] = TypeAdapter(TraceSnapshot)
_DIAGNOSIS_ADAPTER: TypeAdapter[TraceDiagnosis] = TypeAdapter(TraceDiagnosis)


def main() -> int:
if len(sys.argv) != 3:
return 2
payload: str = sys.stdin.read()
try:
snapshot = _SNAPSHOT_ADAPTER.validate_json(payload)
except ValidationError:
return 2
module = importlib.import_module(sys.argv[1])
functions = tuple(
function
for name, function in inspect.getmembers(module, inspect.isfunction)
if name == sys.argv[2]
)
if len(functions) != 1:
return 2
function: Callable[[TraceSnapshot], TraceDiagnosis] = cast(
Callable[[TraceSnapshot], TraceDiagnosis],
functions[0],
)
diagnosis: TraceDiagnosis = function(snapshot)
sys.stdout.write(_DIAGNOSIS_ADAPTER.dump_json(diagnosis).decode())
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading