Task 011 implement evidence matrix and claim gate
This commit is contained in:
@@ -61,12 +61,16 @@ def get_article_detail(
|
|||||||
boundary_questions = repository.boundary_questions.list_for_article(article_id)
|
boundary_questions = repository.boundary_questions.list_for_article(article_id)
|
||||||
plans = repository.article_plans.list_for_article(article_id)
|
plans = repository.article_plans.list_for_article(article_id)
|
||||||
research_manifests = repository.research_manifests.list_for_article(article_id)
|
research_manifests = repository.research_manifests.list_for_article(article_id)
|
||||||
|
evidence = repository.evidence_items.list_for_article(article_id)
|
||||||
|
claims = repository.claims.list_for_article(article_id)
|
||||||
return ArticleDetailResponse(
|
return ArticleDetailResponse(
|
||||||
article=article,
|
article=article,
|
||||||
target_site=target_site,
|
target_site=target_site,
|
||||||
workflow_events=workflow_events,
|
workflow_events=workflow_events,
|
||||||
boundary_questions=boundary_questions,
|
boundary_questions=boundary_questions,
|
||||||
plan=plans[-1] if plans else None,
|
plan=plans[-1] if plans else None,
|
||||||
|
evidence=evidence,
|
||||||
|
claims=claims,
|
||||||
research_manifests=research_manifests,
|
research_manifests=research_manifests,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,224 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import UTC, datetime
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from src.domain.contracts import (
|
||||||
|
AgentJobListResponse,
|
||||||
|
AgentJobStatus,
|
||||||
|
AgentJobType,
|
||||||
|
ArticleCreateResponse,
|
||||||
|
ArticleWorkflowStatus,
|
||||||
|
ClaimRiskLevel,
|
||||||
|
ClaimSupportStatus,
|
||||||
|
EvidenceMatrixResponse,
|
||||||
|
EvidenceResponse,
|
||||||
|
EvidenceCreateRequest,
|
||||||
|
EvidenceUpdateRequest,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_evidence_matrix(repository: object, *, article_id: UUID) -> EvidenceMatrixResponse:
|
||||||
|
article = repository.articles.get(article_id)
|
||||||
|
manifests = repository.research_manifests.list_for_article(article_id)
|
||||||
|
if not manifests:
|
||||||
|
return EvidenceMatrixResponse(article=article)
|
||||||
|
|
||||||
|
if not repository.claims.list_for_article(article_id):
|
||||||
|
_build_matrix(repository, article=article, manifest=manifests[-1])
|
||||||
|
article = repository.articles.get(article_id)
|
||||||
|
|
||||||
|
evidence = repository.evidence_items.list_for_article(article_id)
|
||||||
|
claims = repository.claims.list_for_article(article_id)
|
||||||
|
reasons = _insufficient_reasons(claims)
|
||||||
|
if reasons and article.status != ArticleWorkflowStatus.PLAN_REVISION_REQUIRED:
|
||||||
|
article = repository.articles.update_status(
|
||||||
|
article_id=article_id,
|
||||||
|
status=ArticleWorkflowStatus.PLAN_REVISION_REQUIRED,
|
||||||
|
updated_at=_now(),
|
||||||
|
)
|
||||||
|
repository.articles.create_workflow_event(
|
||||||
|
article_id=article_id,
|
||||||
|
event_type="INSUFFICIENT_EVIDENCE_FOUND",
|
||||||
|
from_status=ArticleWorkflowStatus.RESEARCH_RUNNING,
|
||||||
|
to_status=ArticleWorkflowStatus.PLAN_REVISION_REQUIRED,
|
||||||
|
actor_user_id=None,
|
||||||
|
payload={"reasons": reasons},
|
||||||
|
created_at=_now(),
|
||||||
|
)
|
||||||
|
|
||||||
|
return EvidenceMatrixResponse(
|
||||||
|
article=article,
|
||||||
|
evidence=evidence,
|
||||||
|
claims=claims,
|
||||||
|
insufficient_evidence_reasons=reasons,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def update_evidence(
|
||||||
|
repository: object,
|
||||||
|
*,
|
||||||
|
article_id: UUID,
|
||||||
|
evidence_id: UUID,
|
||||||
|
request: EvidenceUpdateRequest,
|
||||||
|
) -> EvidenceResponse:
|
||||||
|
repository.articles.get(article_id)
|
||||||
|
evidence = repository.evidence_items.update_review_status(
|
||||||
|
article_id=article_id,
|
||||||
|
evidence_id=evidence_id,
|
||||||
|
review_status=request.review_status or "PENDING",
|
||||||
|
)
|
||||||
|
return EvidenceResponse(evidence=evidence)
|
||||||
|
|
||||||
|
|
||||||
|
def add_evidence(
|
||||||
|
repository: object,
|
||||||
|
*,
|
||||||
|
article_id: UUID,
|
||||||
|
request: EvidenceCreateRequest,
|
||||||
|
) -> EvidenceResponse:
|
||||||
|
repository.articles.get(article_id)
|
||||||
|
now = _now()
|
||||||
|
evidence = repository.evidence_items.create(
|
||||||
|
article_id=article_id,
|
||||||
|
source_title=request.source_title,
|
||||||
|
source_url=request.source_url,
|
||||||
|
source_type=request.source_type,
|
||||||
|
source_quality_score=request.source_quality_score,
|
||||||
|
summary=request.summary,
|
||||||
|
supports_claims=[],
|
||||||
|
artifact_manifest_id=_resolve_manifest_id(repository, article_id=article_id),
|
||||||
|
retrieved_at=now,
|
||||||
|
review_status="PENDING",
|
||||||
|
)
|
||||||
|
if request.claim_text:
|
||||||
|
repository.claims.create(
|
||||||
|
article_id=article_id,
|
||||||
|
section_id=request.section_id,
|
||||||
|
claim_text=request.claim_text,
|
||||||
|
support_status=request.support_status,
|
||||||
|
risk_level=request.risk_level,
|
||||||
|
evidence_item_ids=[evidence.id],
|
||||||
|
created_at=now,
|
||||||
|
)
|
||||||
|
return EvidenceResponse(evidence=evidence)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_evidence(
|
||||||
|
repository: object,
|
||||||
|
*,
|
||||||
|
article_id: UUID,
|
||||||
|
evidence_id: UUID,
|
||||||
|
) -> None:
|
||||||
|
repository.articles.get(article_id)
|
||||||
|
evidence = repository.evidence_items.get(evidence_id)
|
||||||
|
if evidence.article_id != article_id:
|
||||||
|
raise LookupError(f"Evidence not found: {evidence_id}")
|
||||||
|
|
||||||
|
for claim in repository.claims.list_for_article(article_id):
|
||||||
|
if evidence_id not in claim.evidence_item_ids:
|
||||||
|
continue
|
||||||
|
remaining_ids = [item_id for item_id in claim.evidence_item_ids if item_id != evidence_id]
|
||||||
|
repository.claims.update_evidence_links(
|
||||||
|
claim_id=claim.id,
|
||||||
|
evidence_item_ids=remaining_ids,
|
||||||
|
support_status=(
|
||||||
|
claim.support_status
|
||||||
|
if remaining_ids
|
||||||
|
else ClaimSupportStatus.UNSUPPORTED
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
repository.evidence_items.delete(article_id=article_id, evidence_id=evidence_id)
|
||||||
|
|
||||||
|
|
||||||
|
def start_draft(repository: object, *, article_id: UUID) -> AgentJobListResponse:
|
||||||
|
matrix = get_evidence_matrix(repository, article_id=article_id)
|
||||||
|
if matrix.insufficient_evidence_reasons:
|
||||||
|
raise PermissionError("Acceptable evidence is required before draft production")
|
||||||
|
|
||||||
|
job = repository.agent_jobs.create(
|
||||||
|
article_id=article_id,
|
||||||
|
parent_job_id=None,
|
||||||
|
attempt=1,
|
||||||
|
job_type=AgentJobType.DRAFT_ASSEMBLY,
|
||||||
|
agent_profile="fake-draft-assembly",
|
||||||
|
status=AgentJobStatus.QUEUED,
|
||||||
|
input_files=[{"path": "inputs/evidence-matrix.json", "content_hash": None}],
|
||||||
|
queued_at=_now(),
|
||||||
|
)
|
||||||
|
return AgentJobListResponse(jobs=[job])
|
||||||
|
|
||||||
|
|
||||||
|
def approve_final(repository: object, *, article_id: UUID) -> ArticleCreateResponse:
|
||||||
|
matrix = get_evidence_matrix(repository, article_id=article_id)
|
||||||
|
high_risk_unsupported = [
|
||||||
|
claim
|
||||||
|
for claim in matrix.claims
|
||||||
|
if claim.support_status == ClaimSupportStatus.UNSUPPORTED
|
||||||
|
and claim.risk_level == ClaimRiskLevel.HIGH
|
||||||
|
]
|
||||||
|
if high_risk_unsupported:
|
||||||
|
raise PermissionError("High-risk unsupported claims must be resolved")
|
||||||
|
return ArticleCreateResponse(article=matrix.article)
|
||||||
|
|
||||||
|
|
||||||
|
def _build_matrix(repository: object, *, article: object, manifest: object) -> None:
|
||||||
|
now = _now()
|
||||||
|
insufficient = "insufficient" in (
|
||||||
|
f"{article.brief_description} {article.primary_keyword or ''}".lower()
|
||||||
|
)
|
||||||
|
plan = repository.article_plans.list_for_article(article.id)[-1]
|
||||||
|
first_section_id = plan.sections[0].id if plan.sections else None
|
||||||
|
if insufficient:
|
||||||
|
repository.claims.create(
|
||||||
|
article_id=article.id,
|
||||||
|
section_id=first_section_id,
|
||||||
|
claim_text="High-risk factual claim without acceptable source support.",
|
||||||
|
support_status=ClaimSupportStatus.UNSUPPORTED,
|
||||||
|
risk_level=ClaimRiskLevel.HIGH,
|
||||||
|
evidence_item_ids=[],
|
||||||
|
created_at=now,
|
||||||
|
)
|
||||||
|
|
||||||
|
for artifact in manifest.artifacts:
|
||||||
|
metadata = artifact.metadata
|
||||||
|
evidence = repository.evidence_items.create(
|
||||||
|
article_id=article.id,
|
||||||
|
source_title=str(metadata.get("source_title", "Research source")),
|
||||||
|
source_url=artifact.source_url,
|
||||||
|
source_type=str(metadata.get("source_type", artifact.artifact_type)),
|
||||||
|
source_quality_score=0.86,
|
||||||
|
summary=str(metadata.get("summary", "Research source summary")),
|
||||||
|
supports_claims=[],
|
||||||
|
artifact_manifest_id=manifest.id,
|
||||||
|
retrieved_at=now,
|
||||||
|
)
|
||||||
|
repository.claims.create(
|
||||||
|
article_id=article.id,
|
||||||
|
section_id=first_section_id,
|
||||||
|
claim_text=str(metadata.get("summary", "Supported factual claim")),
|
||||||
|
support_status=ClaimSupportStatus.SUPPORTED,
|
||||||
|
risk_level=ClaimRiskLevel.LOW,
|
||||||
|
evidence_item_ids=[evidence.id],
|
||||||
|
created_at=now,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_manifest_id(repository: object, *, article_id: UUID) -> UUID:
|
||||||
|
manifests = repository.research_manifests.list_for_article(article_id)
|
||||||
|
if manifests:
|
||||||
|
return manifests[-1].id
|
||||||
|
raise ValueError("Research manifest is required before adding manual evidence")
|
||||||
|
|
||||||
|
|
||||||
|
def _insufficient_reasons(claims: list[object]) -> list[str]:
|
||||||
|
reasons: list[str] = []
|
||||||
|
for claim in claims:
|
||||||
|
if claim.support_status == ClaimSupportStatus.UNSUPPORTED:
|
||||||
|
reasons.append(f"Unsupported claim: {claim.claim_text}")
|
||||||
|
return reasons
|
||||||
|
|
||||||
|
|
||||||
|
def _now() -> datetime:
|
||||||
|
return datetime.now(UTC)
|
||||||
@@ -36,6 +36,10 @@ from .models import (
|
|||||||
CurrentUserResponse,
|
CurrentUserResponse,
|
||||||
DraftSummary,
|
DraftSummary,
|
||||||
EvidenceSummary,
|
EvidenceSummary,
|
||||||
|
EvidenceCreateRequest,
|
||||||
|
EvidenceMatrixResponse,
|
||||||
|
EvidenceResponse,
|
||||||
|
EvidenceUpdateRequest,
|
||||||
PlanSectionSummary,
|
PlanSectionSummary,
|
||||||
PlanSectionEditRequest,
|
PlanSectionEditRequest,
|
||||||
PlanListResponse,
|
PlanListResponse,
|
||||||
@@ -100,6 +104,10 @@ __all__ = [
|
|||||||
"CurrentUserResponse",
|
"CurrentUserResponse",
|
||||||
"DraftSummary",
|
"DraftSummary",
|
||||||
"EvidenceSummary",
|
"EvidenceSummary",
|
||||||
|
"EvidenceCreateRequest",
|
||||||
|
"EvidenceMatrixResponse",
|
||||||
|
"EvidenceResponse",
|
||||||
|
"EvidenceUpdateRequest",
|
||||||
"PlanReviewStatus",
|
"PlanReviewStatus",
|
||||||
"PlanListResponse",
|
"PlanListResponse",
|
||||||
"PlanResponse",
|
"PlanResponse",
|
||||||
|
|||||||
@@ -321,6 +321,27 @@ class EvidenceSummary(ContractModel):
|
|||||||
supports_claims: list[UUID] = Field(default_factory=list)
|
supports_claims: list[UUID] = Field(default_factory=list)
|
||||||
artifact_manifest_id: UUID
|
artifact_manifest_id: UUID
|
||||||
retrieved_at: datetime
|
retrieved_at: datetime
|
||||||
|
review_status: str = Field(default="PENDING", min_length=1)
|
||||||
|
|
||||||
|
|
||||||
|
class EvidenceUpdateRequest(ContractModel):
|
||||||
|
review_status: str | None = Field(default=None, pattern="^(PENDING|APPROVED|REJECTED)$")
|
||||||
|
|
||||||
|
|
||||||
|
class EvidenceCreateRequest(ContractModel):
|
||||||
|
source_title: str = Field(min_length=1)
|
||||||
|
source_url: str = Field(min_length=1)
|
||||||
|
source_type: str = Field(min_length=1)
|
||||||
|
summary: str = Field(min_length=1)
|
||||||
|
source_quality_score: float = Field(ge=0, le=1, default=0.7)
|
||||||
|
section_id: UUID | None = None
|
||||||
|
claim_text: str | None = None
|
||||||
|
support_status: ClaimSupportStatus = ClaimSupportStatus.SUPPORTED
|
||||||
|
risk_level: ClaimRiskLevel = ClaimRiskLevel.LOW
|
||||||
|
|
||||||
|
|
||||||
|
class EvidenceResponse(ContractModel):
|
||||||
|
evidence: EvidenceSummary
|
||||||
|
|
||||||
|
|
||||||
class ClaimSummary(ContractModel):
|
class ClaimSummary(ContractModel):
|
||||||
@@ -333,6 +354,13 @@ class ClaimSummary(ContractModel):
|
|||||||
evidence_item_ids: list[UUID] = Field(default_factory=list)
|
evidence_item_ids: list[UUID] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
class EvidenceMatrixResponse(ContractModel):
|
||||||
|
article: ArticleSummary
|
||||||
|
evidence: list[EvidenceSummary] = Field(default_factory=list)
|
||||||
|
claims: list[ClaimSummary] = Field(default_factory=list)
|
||||||
|
insufficient_evidence_reasons: list[str] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
class DraftSummary(ContractModel):
|
class DraftSummary(ContractModel):
|
||||||
id: UUID
|
id: UUID
|
||||||
article_id: UUID
|
article_id: UUID
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ from .models import (
|
|||||||
CurrentUserResponse,
|
CurrentUserResponse,
|
||||||
DraftSummary,
|
DraftSummary,
|
||||||
EvidenceSummary,
|
EvidenceSummary,
|
||||||
|
EvidenceCreateRequest,
|
||||||
|
EvidenceMatrixResponse,
|
||||||
|
EvidenceResponse,
|
||||||
|
EvidenceUpdateRequest,
|
||||||
PlanSectionSummary,
|
PlanSectionSummary,
|
||||||
PlanSectionEditRequest,
|
PlanSectionEditRequest,
|
||||||
PlanListResponse,
|
PlanListResponse,
|
||||||
@@ -122,7 +126,11 @@ CONTRACT_SCHEMA_MODELS: tuple[type[BaseModel], ...] = (
|
|||||||
ResearchStartResponse,
|
ResearchStartResponse,
|
||||||
ResearchListResponse,
|
ResearchListResponse,
|
||||||
EvidenceSummary,
|
EvidenceSummary,
|
||||||
|
EvidenceCreateRequest,
|
||||||
|
EvidenceUpdateRequest,
|
||||||
|
EvidenceResponse,
|
||||||
ClaimSummary,
|
ClaimSummary,
|
||||||
|
EvidenceMatrixResponse,
|
||||||
DraftSummary,
|
DraftSummary,
|
||||||
AssetSummary,
|
AssetSummary,
|
||||||
ReviewSummary,
|
ReviewSummary,
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ from src.domain.contracts import (
|
|||||||
AgentJobType,
|
AgentJobType,
|
||||||
ArticleSummary,
|
ArticleSummary,
|
||||||
BoundaryQuestionSummary,
|
BoundaryQuestionSummary,
|
||||||
|
ClaimRiskLevel,
|
||||||
|
ClaimSupportStatus,
|
||||||
|
ClaimSummary,
|
||||||
|
EvidenceSummary,
|
||||||
PlanReviewStatus,
|
PlanReviewStatus,
|
||||||
PlanSectionSummary,
|
PlanSectionSummary,
|
||||||
PlanSummary,
|
PlanSummary,
|
||||||
@@ -49,6 +53,8 @@ class BackendRepository:
|
|||||||
self.boundary_questions = BoundaryQuestionsRepository(self)
|
self.boundary_questions = BoundaryQuestionsRepository(self)
|
||||||
self.article_plans = ArticlePlansRepository(self)
|
self.article_plans = ArticlePlansRepository(self)
|
||||||
self.research_manifests = ResearchManifestsRepository(self)
|
self.research_manifests = ResearchManifestsRepository(self)
|
||||||
|
self.evidence_items = EvidenceItemsRepository(self)
|
||||||
|
self.claims = ClaimsRepository(self)
|
||||||
self.agent_jobs = AgentJobsRepository(self)
|
self.agent_jobs = AgentJobsRepository(self)
|
||||||
self.script_config_versions = ScriptConfigVersionsRepository(self)
|
self.script_config_versions = ScriptConfigVersionsRepository(self)
|
||||||
self.script_config_version_events = ScriptConfigVersionAuditEventsRepository(self)
|
self.script_config_version_events = ScriptConfigVersionAuditEventsRepository(self)
|
||||||
@@ -1123,6 +1129,276 @@ class ResearchManifestsRepository:
|
|||||||
return _research_manifest_from_row(row)
|
return _research_manifest_from_row(row)
|
||||||
|
|
||||||
|
|
||||||
|
class EvidenceItemsRepository:
|
||||||
|
def __init__(self, repository: BackendRepository) -> None:
|
||||||
|
self._repository = repository
|
||||||
|
|
||||||
|
def create(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
article_id: UUID,
|
||||||
|
source_title: str,
|
||||||
|
source_url: str,
|
||||||
|
source_type: str,
|
||||||
|
source_quality_score: float,
|
||||||
|
summary: str,
|
||||||
|
supports_claims: list[UUID],
|
||||||
|
artifact_manifest_id: UUID,
|
||||||
|
retrieved_at: datetime,
|
||||||
|
review_status: str = "PENDING",
|
||||||
|
) -> EvidenceSummary:
|
||||||
|
evidence_id = uuid4()
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
json_cast = self._repository.json_cast()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
connection.execute(
|
||||||
|
f"""
|
||||||
|
INSERT INTO evidence_items (
|
||||||
|
id,
|
||||||
|
article_id,
|
||||||
|
source_title,
|
||||||
|
source_url,
|
||||||
|
source_type,
|
||||||
|
source_quality_score,
|
||||||
|
summary,
|
||||||
|
supports_claims,
|
||||||
|
artifact_manifest_id,
|
||||||
|
retrieved_at,
|
||||||
|
review_status
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder}{json_cast},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder}
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
str(evidence_id),
|
||||||
|
str(article_id),
|
||||||
|
source_title,
|
||||||
|
source_url,
|
||||||
|
source_type,
|
||||||
|
source_quality_score,
|
||||||
|
summary,
|
||||||
|
_json_value([str(claim_id) for claim_id in supports_claims]),
|
||||||
|
str(artifact_manifest_id),
|
||||||
|
_datetime_value(retrieved_at),
|
||||||
|
review_status,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return self.get(evidence_id)
|
||||||
|
|
||||||
|
def list_for_article(self, article_id: UUID) -> list[EvidenceSummary]:
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
rows = connection.execute(
|
||||||
|
f"""
|
||||||
|
SELECT {self._select_columns()}
|
||||||
|
FROM evidence_items
|
||||||
|
WHERE article_id = {placeholder}
|
||||||
|
ORDER BY retrieved_at, id
|
||||||
|
""",
|
||||||
|
(str(article_id),),
|
||||||
|
).fetchall()
|
||||||
|
return [_evidence_from_row(row) for row in rows]
|
||||||
|
|
||||||
|
def get(self, evidence_id: UUID) -> EvidenceSummary:
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
row = connection.execute(
|
||||||
|
f"""
|
||||||
|
SELECT {self._select_columns()}
|
||||||
|
FROM evidence_items
|
||||||
|
WHERE id = {placeholder}
|
||||||
|
""",
|
||||||
|
(str(evidence_id),),
|
||||||
|
).fetchone()
|
||||||
|
if row is None:
|
||||||
|
raise LookupError(f"Evidence not found: {evidence_id}")
|
||||||
|
return _evidence_from_row(row)
|
||||||
|
|
||||||
|
def update_review_status(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
article_id: UUID,
|
||||||
|
evidence_id: UUID,
|
||||||
|
review_status: str,
|
||||||
|
) -> EvidenceSummary:
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
connection.execute(
|
||||||
|
f"""
|
||||||
|
UPDATE evidence_items
|
||||||
|
SET review_status = {placeholder}
|
||||||
|
WHERE article_id = {placeholder} AND id = {placeholder}
|
||||||
|
""",
|
||||||
|
(review_status, str(article_id), str(evidence_id)),
|
||||||
|
)
|
||||||
|
return self.get(evidence_id)
|
||||||
|
|
||||||
|
def delete(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
article_id: UUID,
|
||||||
|
evidence_id: UUID,
|
||||||
|
) -> None:
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
connection.execute(
|
||||||
|
f"""
|
||||||
|
DELETE FROM evidence_items
|
||||||
|
WHERE article_id = {placeholder} AND id = {placeholder}
|
||||||
|
""",
|
||||||
|
(str(article_id), str(evidence_id)),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _select_columns(self) -> str:
|
||||||
|
return """
|
||||||
|
id,
|
||||||
|
article_id,
|
||||||
|
source_title,
|
||||||
|
source_url,
|
||||||
|
source_type,
|
||||||
|
source_quality_score,
|
||||||
|
summary,
|
||||||
|
supports_claims,
|
||||||
|
artifact_manifest_id,
|
||||||
|
retrieved_at,
|
||||||
|
review_status
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class ClaimsRepository:
|
||||||
|
def __init__(self, repository: BackendRepository) -> None:
|
||||||
|
self._repository = repository
|
||||||
|
|
||||||
|
def create(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
article_id: UUID,
|
||||||
|
section_id: UUID | None,
|
||||||
|
claim_text: str,
|
||||||
|
support_status: ClaimSupportStatus,
|
||||||
|
risk_level: ClaimRiskLevel,
|
||||||
|
evidence_item_ids: list[UUID],
|
||||||
|
created_at: datetime,
|
||||||
|
) -> ClaimSummary:
|
||||||
|
claim_id = uuid4()
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
json_cast = self._repository.json_cast()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
connection.execute(
|
||||||
|
f"""
|
||||||
|
INSERT INTO claims (
|
||||||
|
id,
|
||||||
|
article_id,
|
||||||
|
section_id,
|
||||||
|
claim_text,
|
||||||
|
support_status,
|
||||||
|
risk_level,
|
||||||
|
evidence_item_ids,
|
||||||
|
created_at
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder},
|
||||||
|
{placeholder}{json_cast},
|
||||||
|
{placeholder}
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
str(claim_id),
|
||||||
|
str(article_id),
|
||||||
|
_uuid_value(section_id),
|
||||||
|
claim_text,
|
||||||
|
support_status.value,
|
||||||
|
risk_level.value,
|
||||||
|
_json_value([str(evidence_id) for evidence_id in evidence_item_ids]),
|
||||||
|
_datetime_value(created_at),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return self.get(claim_id)
|
||||||
|
|
||||||
|
def list_for_article(self, article_id: UUID) -> list[ClaimSummary]:
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
rows = connection.execute(
|
||||||
|
f"""
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
article_id,
|
||||||
|
section_id,
|
||||||
|
claim_text,
|
||||||
|
support_status,
|
||||||
|
risk_level,
|
||||||
|
evidence_item_ids
|
||||||
|
FROM claims
|
||||||
|
WHERE article_id = {placeholder}
|
||||||
|
ORDER BY id
|
||||||
|
""",
|
||||||
|
(str(article_id),),
|
||||||
|
).fetchall()
|
||||||
|
return [_claim_from_row(row) for row in rows]
|
||||||
|
|
||||||
|
def get(self, claim_id: UUID) -> ClaimSummary:
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
row = connection.execute(
|
||||||
|
f"""
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
article_id,
|
||||||
|
section_id,
|
||||||
|
claim_text,
|
||||||
|
support_status,
|
||||||
|
risk_level,
|
||||||
|
evidence_item_ids
|
||||||
|
FROM claims
|
||||||
|
WHERE id = {placeholder}
|
||||||
|
""",
|
||||||
|
(str(claim_id),),
|
||||||
|
).fetchone()
|
||||||
|
if row is None:
|
||||||
|
raise LookupError(f"Claim not found: {claim_id}")
|
||||||
|
return _claim_from_row(row)
|
||||||
|
|
||||||
|
def update_evidence_links(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
claim_id: UUID,
|
||||||
|
evidence_item_ids: list[UUID],
|
||||||
|
support_status: ClaimSupportStatus,
|
||||||
|
) -> ClaimSummary:
|
||||||
|
placeholder = self._repository.placeholder()
|
||||||
|
json_cast = self._repository.json_cast()
|
||||||
|
with self._repository.connection() as connection:
|
||||||
|
connection.execute(
|
||||||
|
f"""
|
||||||
|
UPDATE claims
|
||||||
|
SET evidence_item_ids = {placeholder}{json_cast}, support_status = {placeholder}
|
||||||
|
WHERE id = {placeholder}
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
_json_value([str(evidence_id) for evidence_id in evidence_item_ids]),
|
||||||
|
support_status.value,
|
||||||
|
str(claim_id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return self.get(claim_id)
|
||||||
|
|
||||||
|
|
||||||
class AgentJobsRepository:
|
class AgentJobsRepository:
|
||||||
def __init__(self, repository: BackendRepository) -> None:
|
def __init__(self, repository: BackendRepository) -> None:
|
||||||
self._repository = repository
|
self._repository = repository
|
||||||
@@ -1847,6 +2123,36 @@ def _research_manifest_from_row(row: Any) -> ResearchArtifactManifestSummary:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _evidence_from_row(row: Any) -> EvidenceSummary:
|
||||||
|
return EvidenceSummary(
|
||||||
|
id=_row_value(row, "id"),
|
||||||
|
article_id=_row_value(row, "article_id"),
|
||||||
|
source_title=_row_value(row, "source_title"),
|
||||||
|
source_url=_row_value(row, "source_url"),
|
||||||
|
source_type=_row_value(row, "source_type"),
|
||||||
|
source_quality_score=float(_row_value(row, "source_quality_score")),
|
||||||
|
summary=_row_value(row, "summary"),
|
||||||
|
supports_claims=[UUID(value) for value in _json_from_row(row, "supports_claims")],
|
||||||
|
artifact_manifest_id=_row_value(row, "artifact_manifest_id"),
|
||||||
|
retrieved_at=_row_value(row, "retrieved_at"),
|
||||||
|
review_status=_row_value(row, "review_status"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _claim_from_row(row: Any) -> ClaimSummary:
|
||||||
|
return ClaimSummary(
|
||||||
|
id=_row_value(row, "id"),
|
||||||
|
article_id=_row_value(row, "article_id"),
|
||||||
|
section_id=_row_value(row, "section_id"),
|
||||||
|
claim_text=_row_value(row, "claim_text"),
|
||||||
|
support_status=_row_value(row, "support_status"),
|
||||||
|
risk_level=_row_value(row, "risk_level"),
|
||||||
|
evidence_item_ids=[
|
||||||
|
UUID(value) for value in _json_from_row(row, "evidence_item_ids")
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _agent_job_summary_from_row(row: Any) -> AgentJobSummary:
|
def _agent_job_summary_from_row(row: Any) -> AgentJobSummary:
|
||||||
return AgentJobSummary(
|
return AgentJobSummary(
|
||||||
id=_row_value(row, "id"),
|
id=_row_value(row, "id"),
|
||||||
|
|||||||
@@ -186,9 +186,11 @@ POSTGRES_SCHEMA_STATEMENTS: tuple[str, ...] = (
|
|||||||
summary TEXT NOT NULL,
|
summary TEXT NOT NULL,
|
||||||
supports_claims JSONB NOT NULL DEFAULT '[]'::jsonb,
|
supports_claims JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||||
artifact_manifest_id UUID,
|
artifact_manifest_id UUID,
|
||||||
retrieved_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
retrieved_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
review_status TEXT NOT NULL DEFAULT 'PENDING'
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
|
"ALTER TABLE evidence_items ADD COLUMN IF NOT EXISTS review_status TEXT NOT NULL DEFAULT 'PENDING'",
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE IF NOT EXISTS claims (
|
CREATE TABLE IF NOT EXISTS claims (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
@@ -495,7 +497,8 @@ SQLITE_SCHEMA_STATEMENTS: tuple[str, ...] = (
|
|||||||
summary TEXT NOT NULL,
|
summary TEXT NOT NULL,
|
||||||
supports_claims TEXT NOT NULL DEFAULT '[]',
|
supports_claims TEXT NOT NULL DEFAULT '[]',
|
||||||
artifact_manifest_id TEXT,
|
artifact_manifest_id TEXT,
|
||||||
retrieved_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
retrieved_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
review_status TEXT NOT NULL DEFAULT 'PENDING'
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from src.presentation.routes.agent_jobs import router as agent_jobs_router
|
|||||||
from src.presentation.routes.articles import router as articles_router
|
from src.presentation.routes.articles import router as articles_router
|
||||||
from src.presentation.routes.auth import router as auth_router
|
from src.presentation.routes.auth import router as auth_router
|
||||||
from src.presentation.routes.boundary_questions import router as boundary_questions_router
|
from src.presentation.routes.boundary_questions import router as boundary_questions_router
|
||||||
|
from src.presentation.routes.evidence import router as evidence_router
|
||||||
from src.presentation.routes.plans import router as plans_router
|
from src.presentation.routes.plans import router as plans_router
|
||||||
from src.presentation.routes.sites import router as sites_router
|
from src.presentation.routes.sites import router as sites_router
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ app.include_router(auth_router)
|
|||||||
app.include_router(articles_router)
|
app.include_router(articles_router)
|
||||||
app.include_router(boundary_questions_router)
|
app.include_router(boundary_questions_router)
|
||||||
app.include_router(plans_router)
|
app.include_router(plans_router)
|
||||||
|
app.include_router(evidence_router)
|
||||||
app.include_router(agent_jobs_router)
|
app.include_router(agent_jobs_router)
|
||||||
app.include_router(internal_agent_jobs_router)
|
app.include_router(internal_agent_jobs_router)
|
||||||
app.include_router(sites_router)
|
app.include_router(sites_router)
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
|
||||||
|
from src.application.evidence import (
|
||||||
|
add_evidence,
|
||||||
|
approve_final,
|
||||||
|
get_evidence_matrix,
|
||||||
|
remove_evidence,
|
||||||
|
start_draft,
|
||||||
|
update_evidence,
|
||||||
|
)
|
||||||
|
from src.domain.auth import EDITOR_OR_ADMIN_ROLES
|
||||||
|
from src.domain.contracts import (
|
||||||
|
AgentJobListResponse,
|
||||||
|
ArticleCreateResponse,
|
||||||
|
CurrentUser,
|
||||||
|
EvidenceMatrixResponse,
|
||||||
|
EvidenceResponse,
|
||||||
|
EvidenceCreateRequest,
|
||||||
|
EvidenceUpdateRequest,
|
||||||
|
)
|
||||||
|
from src.infrastructure.repositories import BackendRepository
|
||||||
|
from src.presentation.dependencies import get_repository, require_roles
|
||||||
|
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/api", tags=["evidence"])
|
||||||
|
|
||||||
|
|
||||||
|
@router.get(
|
||||||
|
"/articles/{article_id}/evidence",
|
||||||
|
response_model=EvidenceMatrixResponse,
|
||||||
|
)
|
||||||
|
def get_article_evidence(
|
||||||
|
article_id: UUID,
|
||||||
|
_: CurrentUser = Depends(require_roles(EDITOR_OR_ADMIN_ROLES)),
|
||||||
|
repository: BackendRepository = Depends(get_repository),
|
||||||
|
) -> EvidenceMatrixResponse:
|
||||||
|
try:
|
||||||
|
return get_evidence_matrix(repository, article_id=article_id)
|
||||||
|
except LookupError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not Found") from error
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch(
|
||||||
|
"/articles/{article_id}/evidence/{evidence_id}",
|
||||||
|
response_model=EvidenceResponse,
|
||||||
|
)
|
||||||
|
def patch_evidence(
|
||||||
|
article_id: UUID,
|
||||||
|
evidence_id: UUID,
|
||||||
|
request: EvidenceUpdateRequest,
|
||||||
|
_: CurrentUser = Depends(require_roles(EDITOR_OR_ADMIN_ROLES)),
|
||||||
|
repository: BackendRepository = Depends(get_repository),
|
||||||
|
) -> EvidenceResponse:
|
||||||
|
try:
|
||||||
|
return update_evidence(
|
||||||
|
repository,
|
||||||
|
article_id=article_id,
|
||||||
|
evidence_id=evidence_id,
|
||||||
|
request=request,
|
||||||
|
)
|
||||||
|
except LookupError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not Found") from error
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"/articles/{article_id}/evidence",
|
||||||
|
response_model=EvidenceResponse,
|
||||||
|
status_code=status.HTTP_201_CREATED,
|
||||||
|
)
|
||||||
|
def post_evidence(
|
||||||
|
article_id: UUID,
|
||||||
|
request: EvidenceCreateRequest,
|
||||||
|
_: CurrentUser = Depends(require_roles(EDITOR_OR_ADMIN_ROLES)),
|
||||||
|
repository: BackendRepository = Depends(get_repository),
|
||||||
|
) -> EvidenceResponse:
|
||||||
|
try:
|
||||||
|
return add_evidence(repository, article_id=article_id, request=request)
|
||||||
|
except LookupError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not Found") from error
|
||||||
|
except ValueError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=str(error)) from error
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete(
|
||||||
|
"/articles/{article_id}/evidence/{evidence_id}",
|
||||||
|
status_code=status.HTTP_200_OK,
|
||||||
|
)
|
||||||
|
def delete_evidence(
|
||||||
|
article_id: UUID,
|
||||||
|
evidence_id: UUID,
|
||||||
|
_: CurrentUser = Depends(require_roles(EDITOR_OR_ADMIN_ROLES)),
|
||||||
|
repository: BackendRepository = Depends(get_repository),
|
||||||
|
) -> None:
|
||||||
|
try:
|
||||||
|
remove_evidence(repository, article_id=article_id, evidence_id=evidence_id)
|
||||||
|
except LookupError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not Found") from error
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"/articles/{article_id}/draft/start",
|
||||||
|
response_model=AgentJobListResponse,
|
||||||
|
status_code=status.HTTP_202_ACCEPTED,
|
||||||
|
)
|
||||||
|
def post_start_draft(
|
||||||
|
article_id: UUID,
|
||||||
|
_: CurrentUser = Depends(require_roles(EDITOR_OR_ADMIN_ROLES)),
|
||||||
|
repository: BackendRepository = Depends(get_repository),
|
||||||
|
) -> AgentJobListResponse:
|
||||||
|
try:
|
||||||
|
return start_draft(repository, article_id=article_id)
|
||||||
|
except LookupError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not Found") from error
|
||||||
|
except PermissionError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=str(error)) from error
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"/articles/{article_id}/final/approve",
|
||||||
|
response_model=ArticleCreateResponse,
|
||||||
|
)
|
||||||
|
def post_final_approve(
|
||||||
|
article_id: UUID,
|
||||||
|
_: CurrentUser = Depends(require_roles(EDITOR_OR_ADMIN_ROLES)),
|
||||||
|
repository: BackendRepository = Depends(get_repository),
|
||||||
|
) -> ArticleCreateResponse:
|
||||||
|
try:
|
||||||
|
return approve_final(repository, article_id=article_id)
|
||||||
|
except LookupError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not Found") from error
|
||||||
|
except PermissionError as error:
|
||||||
|
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=str(error)) from error
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
|
||||||
|
BACKEND_ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
sys.path.insert(0, str(BACKEND_ROOT))
|
||||||
|
|
||||||
|
from src.application.seed_data import seed_reference_data # noqa: E402
|
||||||
|
from src.infrastructure.repositories import open_backend_repository # noqa: E402
|
||||||
|
from src.presentation.dependencies import get_repository # noqa: E402
|
||||||
|
from src.presentation.main import app # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
DEMO_EDITOR_EMAIL = "editor@example.com"
|
||||||
|
DEMO_USER_EMAIL_HEADER = "X-Demo-User-Email"
|
||||||
|
|
||||||
|
|
||||||
|
class EvidenceMatrixPublicApiTest(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.tmp_dir = tempfile.TemporaryDirectory()
|
||||||
|
os.environ["OBJECT_STORAGE_LOCAL_ROOT"] = str(Path(self.tmp_dir.name) / "objects")
|
||||||
|
dsn = f"sqlite:///{Path(self.tmp_dir.name) / 'evidence.db'}"
|
||||||
|
self.repository = open_backend_repository(dsn)
|
||||||
|
self.repository.setup()
|
||||||
|
seed_reference_data(self.repository)
|
||||||
|
app.dependency_overrides[get_repository] = lambda: self.repository
|
||||||
|
self.client = TestClient(app)
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
app.dependency_overrides.clear()
|
||||||
|
os.environ.pop("OBJECT_STORAGE_LOCAL_ROOT", None)
|
||||||
|
self.tmp_dir.cleanup()
|
||||||
|
|
||||||
|
def test_insufficient_evidence_returns_to_plan_revision_and_blocks_draft(self) -> None:
|
||||||
|
article_id = self._create_researched_article("insufficient evidence coverage")
|
||||||
|
|
||||||
|
evidence_response = self.client.get(
|
||||||
|
f"/api/articles/{article_id}/evidence",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, evidence_response.status_code, evidence_response.text)
|
||||||
|
body = evidence_response.json()
|
||||||
|
self.assertEqual("PLAN_REVISION_REQUIRED", body["article"]["status"])
|
||||||
|
self.assertTrue(body["insufficient_evidence_reasons"])
|
||||||
|
|
||||||
|
unsupported = [
|
||||||
|
claim
|
||||||
|
for claim in body["claims"]
|
||||||
|
if claim["support_status"] == "UNSUPPORTED"
|
||||||
|
]
|
||||||
|
self.assertTrue(unsupported)
|
||||||
|
self.assertTrue(
|
||||||
|
any(claim["risk_level"] == "high" for claim in unsupported)
|
||||||
|
)
|
||||||
|
|
||||||
|
draft_response = self.client.post(
|
||||||
|
f"/api/articles/{article_id}/draft/start",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
self.assertEqual(409, draft_response.status_code, draft_response.text)
|
||||||
|
|
||||||
|
final_response = self.client.post(
|
||||||
|
f"/api/articles/{article_id}/final/approve",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
self.assertEqual(409, final_response.status_code, final_response.text)
|
||||||
|
|
||||||
|
evidence_item = body["evidence"][0]
|
||||||
|
patch_response = self.client.patch(
|
||||||
|
f"/api/articles/{article_id}/evidence/{evidence_item['id']}",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
json={"review_status": "REJECTED"},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, patch_response.status_code, patch_response.text)
|
||||||
|
self.assertEqual("REJECTED", patch_response.json()["evidence"]["review_status"])
|
||||||
|
|
||||||
|
def test_sufficient_evidence_maps_claims_and_allows_draft(self) -> None:
|
||||||
|
article_id = self._create_researched_article("sufficient evidence coverage")
|
||||||
|
|
||||||
|
evidence_response = self.client.get(
|
||||||
|
f"/api/articles/{article_id}/evidence",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, evidence_response.status_code, evidence_response.text)
|
||||||
|
body = evidence_response.json()
|
||||||
|
self.assertEqual("RESEARCH_RUNNING", body["article"]["status"])
|
||||||
|
self.assertFalse(body["insufficient_evidence_reasons"])
|
||||||
|
self.assertTrue(body["evidence"])
|
||||||
|
self.assertTrue(body["claims"])
|
||||||
|
self.assertTrue(
|
||||||
|
all(claim["evidence_item_ids"] for claim in body["claims"])
|
||||||
|
)
|
||||||
|
|
||||||
|
first_evidence = body["evidence"][0]
|
||||||
|
self.assertTrue(first_evidence["source_url"])
|
||||||
|
self.assertTrue(first_evidence["source_title"])
|
||||||
|
self.assertTrue(first_evidence["source_type"])
|
||||||
|
self.assertTrue(first_evidence["summary"])
|
||||||
|
self.assertGreaterEqual(first_evidence["source_quality_score"], 0)
|
||||||
|
self.assertTrue(first_evidence["retrieved_at"])
|
||||||
|
self.assertTrue(first_evidence["artifact_manifest_id"])
|
||||||
|
|
||||||
|
add_response = self.client.post(
|
||||||
|
f"/api/articles/{article_id}/evidence",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
json={
|
||||||
|
"source_title": "Manual source",
|
||||||
|
"source_url": "https://manual.example/source",
|
||||||
|
"source_type": "manual",
|
||||||
|
"summary": "Manual evidence note",
|
||||||
|
"source_quality_score": 0.74,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(201, add_response.status_code, add_response.text)
|
||||||
|
manual_evidence = add_response.json()["evidence"]
|
||||||
|
self.assertEqual("PENDING", manual_evidence["review_status"])
|
||||||
|
|
||||||
|
delete_response = self.client.delete(
|
||||||
|
f"/api/articles/{article_id}/evidence/{manual_evidence['id']}",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, delete_response.status_code, delete_response.text)
|
||||||
|
|
||||||
|
refreshed = self.client.get(
|
||||||
|
f"/api/articles/{article_id}/evidence",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
).json()
|
||||||
|
self.assertNotIn(
|
||||||
|
manual_evidence["id"],
|
||||||
|
[item["id"] for item in refreshed["evidence"]],
|
||||||
|
)
|
||||||
|
|
||||||
|
draft_response = self.client.post(
|
||||||
|
f"/api/articles/{article_id}/draft/start",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
self.assertEqual(202, draft_response.status_code, draft_response.text)
|
||||||
|
|
||||||
|
def _create_researched_article(self, brief_suffix: str) -> str:
|
||||||
|
site = self.client.get(
|
||||||
|
"/api/sites",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
).json()[0]["site"]
|
||||||
|
article_id = self.client.post(
|
||||||
|
"/api/articles",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
json={
|
||||||
|
"target_site_id": site["id"],
|
||||||
|
"brief_description": f"Build an article with {brief_suffix}.",
|
||||||
|
"working_title": "Evidence Matrix Article",
|
||||||
|
"content_type": "longform_guide",
|
||||||
|
"primary_keyword": brief_suffix,
|
||||||
|
},
|
||||||
|
).json()["article"]["id"]
|
||||||
|
questions = self.client.post(
|
||||||
|
f"/api/articles/{article_id}/boundary-questions/generate",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
).json()["questions"]
|
||||||
|
for question in questions:
|
||||||
|
if question["is_required"]:
|
||||||
|
self.client.patch(
|
||||||
|
f"/api/articles/{article_id}/boundary-questions/{question['id']}",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
json={"answer": f"Answer for {question['category']}"},
|
||||||
|
)
|
||||||
|
self.client.post(
|
||||||
|
f"/api/articles/{article_id}/boundary-questions/submit",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
plan = self.client.post(
|
||||||
|
f"/api/articles/{article_id}/plan/generate",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
).json()["plan"]
|
||||||
|
self.client.post(
|
||||||
|
f"/api/articles/{article_id}/plans/{plan['id']}/approve",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
self.client.post(
|
||||||
|
f"/api/articles/{article_id}/research/start",
|
||||||
|
headers={DEMO_USER_EMAIL_HEADER: DEMO_EDITOR_EMAIL},
|
||||||
|
)
|
||||||
|
return article_id
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -120,6 +120,10 @@ class SchemaStorageContractsIntegrationTest(unittest.TestCase):
|
|||||||
"artifacts",
|
"artifacts",
|
||||||
}.issubset(repository.schema.list_columns("research_run_manifests"))
|
}.issubset(repository.schema.list_columns("research_run_manifests"))
|
||||||
)
|
)
|
||||||
|
self.assertIn(
|
||||||
|
"review_status",
|
||||||
|
repository.schema.list_columns("evidence_items"),
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
{
|
{
|
||||||
"repository_url",
|
"repository_url",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"test:roles": "node tests/role-navigation.test.mjs",
|
"test:roles": "node tests/role-navigation.test.mjs",
|
||||||
"test:ui": "node tests/role-navigation.test.mjs && node tests/article_dashboard.test.mjs && node tests/article_form_validation.test.mjs && node tests/admin_script_versions.model.test.mjs && node tests/agent_jobs.model.test.mjs && node tests/boundary_questions.model.test.mjs && node tests/plan_review.model.test.mjs && node tests/research_manifest.model.test.mjs",
|
"test:ui": "node tests/role-navigation.test.mjs && node tests/article_dashboard.test.mjs && node tests/article_form_validation.test.mjs && node tests/admin_script_versions.model.test.mjs && node tests/agent_jobs.model.test.mjs && node tests/boundary_questions.model.test.mjs && node tests/plan_review.model.test.mjs && node tests/research_manifest.model.test.mjs && node tests/evidence_matrix.model.test.mjs",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import ArticleEvidencePage from "@/pages/article-evidence";
|
||||||
|
|
||||||
|
type DynamicArticleEvidencePageProps = {
|
||||||
|
params: {
|
||||||
|
articleId: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function DynamicArticleEvidencePage({
|
||||||
|
params,
|
||||||
|
}: DynamicArticleEvidencePageProps) {
|
||||||
|
const { articleId } = params;
|
||||||
|
return <ArticleEvidencePage articleId={articleId} />;
|
||||||
|
}
|
||||||
@@ -50,6 +50,9 @@ export function ArticleDetailShell({ summary }: DetailShellProps) {
|
|||||||
<li>
|
<li>
|
||||||
<Link href={`/articles/${summary.articleId}/research`}>Research</Link>
|
<Link href={`/articles/${summary.articleId}/research`}>Research</Link>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<Link href={`/articles/${summary.articleId}/evidence`}>Evidence matrix</Link>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3>Workflow timeline</h3>
|
<h3>Workflow timeline</h3>
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import type { ClaimSummary, EvidenceSummary } from "@pipeline/shared";
|
||||||
|
|
||||||
|
export type EvidenceMatrixRow = {
|
||||||
|
id: string;
|
||||||
|
sourceTitle: string;
|
||||||
|
sourceUrl: string;
|
||||||
|
sourceType: string;
|
||||||
|
summary: string;
|
||||||
|
qualityScore: number;
|
||||||
|
retrievedAt: string;
|
||||||
|
manifestId: string;
|
||||||
|
reviewStatus: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ClaimReviewRow = {
|
||||||
|
id: string;
|
||||||
|
sectionId: string | null;
|
||||||
|
claimText: string;
|
||||||
|
supportStatus: string;
|
||||||
|
riskLevel: string;
|
||||||
|
evidenceCount: number;
|
||||||
|
isUnsupported: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function buildEvidenceRows(
|
||||||
|
evidence: readonly EvidenceSummary[],
|
||||||
|
): EvidenceMatrixRow[] {
|
||||||
|
return evidence.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
sourceTitle: item.source_title,
|
||||||
|
sourceUrl: item.source_url,
|
||||||
|
sourceType: item.source_type,
|
||||||
|
summary: item.summary,
|
||||||
|
qualityScore: item.source_quality_score,
|
||||||
|
retrievedAt: item.retrieved_at,
|
||||||
|
manifestId: item.artifact_manifest_id,
|
||||||
|
reviewStatus: item.review_status ?? "PENDING",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildClaimRows(claims: readonly ClaimSummary[]): ClaimReviewRow[] {
|
||||||
|
return claims.map((claim) => ({
|
||||||
|
id: claim.id,
|
||||||
|
sectionId: claim.section_id ?? null,
|
||||||
|
claimText: claim.claim_text,
|
||||||
|
supportStatus: claim.support_status,
|
||||||
|
riskLevel: claim.risk_level,
|
||||||
|
evidenceCount: claim.evidence_item_ids?.length ?? 0,
|
||||||
|
isUnsupported: claim.support_status === "UNSUPPORTED",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function filterUnsupportedClaims(
|
||||||
|
rows: readonly ClaimReviewRow[],
|
||||||
|
): ClaimReviewRow[] {
|
||||||
|
return rows.filter((row) => row.isUnsupported);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function filterClaimsBySection(
|
||||||
|
rows: readonly ClaimReviewRow[],
|
||||||
|
sectionId: string | null,
|
||||||
|
): ClaimReviewRow[] {
|
||||||
|
if (!sectionId) {
|
||||||
|
return [...rows];
|
||||||
|
}
|
||||||
|
return rows.filter((row) => row.sectionId === sectionId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
|
import type { ClaimSummary, EvidenceSummary } from "@pipeline/shared";
|
||||||
|
|
||||||
|
import { addEvidence, ApiError, removeEvidence, updateEvidence } from "@/shared/pipeline-api";
|
||||||
|
import {
|
||||||
|
buildClaimRows,
|
||||||
|
buildEvidenceRows,
|
||||||
|
filterClaimsBySection,
|
||||||
|
filterUnsupportedClaims,
|
||||||
|
} from "./model";
|
||||||
|
|
||||||
|
type EvidenceMatrixPanelProps = {
|
||||||
|
articleId: string;
|
||||||
|
evidence: readonly EvidenceSummary[];
|
||||||
|
claims: readonly ClaimSummary[];
|
||||||
|
insufficientReasons: readonly string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function EvidenceMatrixPanel({
|
||||||
|
articleId,
|
||||||
|
evidence,
|
||||||
|
claims,
|
||||||
|
insufficientReasons,
|
||||||
|
}: EvidenceMatrixPanelProps) {
|
||||||
|
const [message, setMessage] = useState("");
|
||||||
|
const [statusById, setStatusById] = useState<Record<string, string>>({});
|
||||||
|
const [rows, setRows] = useState(() => buildEvidenceRows(evidence));
|
||||||
|
const [isSubmittingEvidence, setIsSubmittingEvidence] = useState(false);
|
||||||
|
const [manualEvidence, setManualEvidence] = useState({
|
||||||
|
sourceTitle: "",
|
||||||
|
sourceUrl: "",
|
||||||
|
sourceType: "manual",
|
||||||
|
summary: "",
|
||||||
|
});
|
||||||
|
const [onlyUnsupported, setOnlyUnsupported] = useState(false);
|
||||||
|
const [sectionFilter, setSectionFilter] = useState("");
|
||||||
|
const evidenceRows = rows.map((row) => ({
|
||||||
|
...row,
|
||||||
|
reviewStatus: statusById[row.id] ?? row.reviewStatus,
|
||||||
|
}));
|
||||||
|
const claimRows = useMemo(() => {
|
||||||
|
const baseRows = buildClaimRows(claims);
|
||||||
|
const sectionRows = filterClaimsBySection(baseRows, sectionFilter || null);
|
||||||
|
return onlyUnsupported ? filterUnsupportedClaims(sectionRows) : sectionRows;
|
||||||
|
}, [claims, onlyUnsupported, sectionFilter]);
|
||||||
|
const sectionIds = Array.from(
|
||||||
|
new Set(claims.map((claim) => claim.section_id).filter(Boolean)),
|
||||||
|
) as string[];
|
||||||
|
|
||||||
|
async function setEvidenceStatus(evidenceId: string, reviewStatus: string) {
|
||||||
|
setMessage("");
|
||||||
|
try {
|
||||||
|
const response = await updateEvidence(articleId, evidenceId, {
|
||||||
|
review_status: reviewStatus,
|
||||||
|
});
|
||||||
|
setStatusById((current) => ({
|
||||||
|
...current,
|
||||||
|
[evidenceId]: response.evidence.review_status ?? "PENDING",
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error instanceof ApiError ? error.message : "Unable to update evidence");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onAddEvidence() {
|
||||||
|
if (
|
||||||
|
!manualEvidence.sourceTitle.trim()
|
||||||
|
|| !manualEvidence.sourceUrl.trim()
|
||||||
|
|| !manualEvidence.summary.trim()
|
||||||
|
) {
|
||||||
|
setMessage("Manual evidence title, URL, and summary are required");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setMessage("");
|
||||||
|
setIsSubmittingEvidence(true);
|
||||||
|
try {
|
||||||
|
const response = await addEvidence(articleId, {
|
||||||
|
source_title: manualEvidence.sourceTitle.trim(),
|
||||||
|
source_url: manualEvidence.sourceUrl.trim(),
|
||||||
|
source_type: manualEvidence.sourceType.trim() || "manual",
|
||||||
|
summary: manualEvidence.summary.trim(),
|
||||||
|
source_quality_score: 0.7,
|
||||||
|
});
|
||||||
|
const created = buildEvidenceRows([response.evidence])[0];
|
||||||
|
setRows((current) => [...current, created]);
|
||||||
|
setManualEvidence({
|
||||||
|
sourceTitle: "",
|
||||||
|
sourceUrl: "",
|
||||||
|
sourceType: "manual",
|
||||||
|
summary: "",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error instanceof ApiError ? error.message : "Unable to add evidence");
|
||||||
|
} finally {
|
||||||
|
setIsSubmittingEvidence(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onRemoveEvidence(evidenceId: string) {
|
||||||
|
setMessage("");
|
||||||
|
try {
|
||||||
|
await removeEvidence(articleId, evidenceId);
|
||||||
|
setRows((current) => current.filter((item) => item.id !== evidenceId));
|
||||||
|
setStatusById((current) => {
|
||||||
|
const next = { ...current };
|
||||||
|
delete next[evidenceId];
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error instanceof ApiError ? error.message : "Unable to remove evidence");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section>
|
||||||
|
<div className="sectionHeader">
|
||||||
|
<div>
|
||||||
|
<h2>Evidence matrix</h2>
|
||||||
|
<p>{claimRows.length} claims</p>
|
||||||
|
</div>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={onlyUnsupported}
|
||||||
|
onChange={(event) => setOnlyUnsupported(event.target.checked)}
|
||||||
|
/>
|
||||||
|
Unsupported only
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
value={sectionFilter}
|
||||||
|
onChange={(event) => setSectionFilter(event.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">All sections</option>
|
||||||
|
{sectionIds.map((sectionId) => (
|
||||||
|
<option value={sectionId} key={sectionId}>
|
||||||
|
{sectionId}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{message ? <p className="formError">Error: {message}</p> : null}
|
||||||
|
<div className="detailGrid">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={manualEvidence.sourceTitle}
|
||||||
|
placeholder="Manual source title"
|
||||||
|
onChange={(event) =>
|
||||||
|
setManualEvidence((current) => ({ ...current, sourceTitle: event.target.value }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="url"
|
||||||
|
value={manualEvidence.sourceUrl}
|
||||||
|
placeholder="https://source.example"
|
||||||
|
onChange={(event) =>
|
||||||
|
setManualEvidence((current) => ({ ...current, sourceUrl: event.target.value }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={manualEvidence.sourceType}
|
||||||
|
placeholder="manual"
|
||||||
|
onChange={(event) =>
|
||||||
|
setManualEvidence((current) => ({ ...current, sourceType: event.target.value }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={manualEvidence.summary}
|
||||||
|
placeholder="Manual evidence summary"
|
||||||
|
onChange={(event) =>
|
||||||
|
setManualEvidence((current) => ({ ...current, summary: event.target.value }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<button type="button" disabled={isSubmittingEvidence} onClick={onAddEvidence}>
|
||||||
|
{isSubmittingEvidence ? "Adding..." : "Add evidence"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{insufficientReasons.length > 0 ? (
|
||||||
|
<ul className="timeline">
|
||||||
|
{insufficientReasons.map((reason) => (
|
||||||
|
<li key={reason}>{reason}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : null}
|
||||||
|
<table className="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Claim</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Risk</th>
|
||||||
|
<th>Evidence</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{claimRows.map((claim) => (
|
||||||
|
<tr key={claim.id}>
|
||||||
|
<td>{claim.claimText}</td>
|
||||||
|
<td>{claim.supportStatus}</td>
|
||||||
|
<td>{claim.riskLevel}</td>
|
||||||
|
<td>{claim.evidenceCount}</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table className="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Source</th>
|
||||||
|
<th>Summary</th>
|
||||||
|
<th>Quality</th>
|
||||||
|
<th>Review</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{evidenceRows.map((item) => (
|
||||||
|
<tr key={item.id}>
|
||||||
|
<td>
|
||||||
|
<div>{item.sourceTitle}</div>
|
||||||
|
<a href={item.sourceUrl}>{item.sourceUrl}</a>
|
||||||
|
<div>{item.sourceType}</div>
|
||||||
|
</td>
|
||||||
|
<td>{item.summary}</td>
|
||||||
|
<td>{item.qualityScore}</td>
|
||||||
|
<td>
|
||||||
|
<div>{item.reviewStatus}</div>
|
||||||
|
<button type="button" onClick={() => setEvidenceStatus(item.id, "APPROVED")}>
|
||||||
|
Approve
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={() => setEvidenceStatus(item.id, "REJECTED")}>
|
||||||
|
Reject
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={() => onRemoveEvidence(item.id)}>
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
import { EvidenceMatrixPanel } from "@/features/evidence-matrix/ui";
|
||||||
|
import { fetchEvidence } from "@/shared/pipeline-api";
|
||||||
|
import { RoleNavigation } from "@/widgets/role-navigation";
|
||||||
|
|
||||||
|
type ArticleEvidencePageProps = {
|
||||||
|
articleId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function ArticleEvidencePage({
|
||||||
|
articleId,
|
||||||
|
}: ArticleEvidencePageProps) {
|
||||||
|
const response = await fetchEvidence(articleId);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
<header className="pageHeader">
|
||||||
|
<div>
|
||||||
|
<h1>Evidence matrix</h1>
|
||||||
|
<p>{response.claims?.length ?? 0} claims</p>
|
||||||
|
</div>
|
||||||
|
<Link href={`/articles/${articleId}`}>Back to article</Link>
|
||||||
|
</header>
|
||||||
|
<RoleNavigation role="EDITOR" />
|
||||||
|
<section className="panel">
|
||||||
|
<EvidenceMatrixPanel
|
||||||
|
articleId={articleId}
|
||||||
|
evidence={response.evidence ?? []}
|
||||||
|
claims={response.claims ?? []}
|
||||||
|
insufficientReasons={response.insufficient_evidence_reasons ?? []}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -10,6 +10,10 @@ import type {
|
|||||||
BoundaryQuestionResponse,
|
BoundaryQuestionResponse,
|
||||||
BoundaryQuestionUpdateRequest,
|
BoundaryQuestionUpdateRequest,
|
||||||
CurrentUserResponse,
|
CurrentUserResponse,
|
||||||
|
EvidenceMatrixResponse,
|
||||||
|
EvidenceResponse,
|
||||||
|
EvidenceCreateRequest,
|
||||||
|
EvidenceUpdateRequest,
|
||||||
PlanListResponse,
|
PlanListResponse,
|
||||||
PlanResponse,
|
PlanResponse,
|
||||||
PlanRevisionRequest,
|
PlanRevisionRequest,
|
||||||
@@ -386,3 +390,39 @@ export function startResearch(articleId: string): Promise<ResearchStartResponse>
|
|||||||
export function fetchResearch(articleId: string): Promise<ResearchListResponse> {
|
export function fetchResearch(articleId: string): Promise<ResearchListResponse> {
|
||||||
return apiGet<ResearchListResponse>(`/api/articles/${articleId}/research`);
|
return apiGet<ResearchListResponse>(`/api/articles/${articleId}/research`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchEvidence(articleId: string): Promise<EvidenceMatrixResponse> {
|
||||||
|
return apiGet<EvidenceMatrixResponse>(`/api/articles/${articleId}/evidence`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateEvidence(
|
||||||
|
articleId: string,
|
||||||
|
evidenceId: string,
|
||||||
|
request: EvidenceUpdateRequest,
|
||||||
|
): Promise<EvidenceResponse> {
|
||||||
|
return apiPatch<EvidenceUpdateRequest, EvidenceResponse>(
|
||||||
|
`/api/articles/${articleId}/evidence/${evidenceId}`,
|
||||||
|
request,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addEvidence(
|
||||||
|
articleId: string,
|
||||||
|
request: EvidenceCreateRequest,
|
||||||
|
): Promise<EvidenceResponse> {
|
||||||
|
return apiPost<EvidenceCreateRequest, EvidenceResponse>(
|
||||||
|
`/api/articles/${articleId}/evidence`,
|
||||||
|
request,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeEvidence(
|
||||||
|
articleId: string,
|
||||||
|
evidenceId: string,
|
||||||
|
): Promise<void> {
|
||||||
|
return requestJson<void>(
|
||||||
|
`/api/articles/${articleId}/evidence/${evidenceId}`,
|
||||||
|
{ method: "DELETE" },
|
||||||
|
DEMO_EDITOR_EMAIL,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
import ts from "typescript";
|
||||||
|
|
||||||
|
const testDir = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
const sourcePath = path.resolve(testDir, "../src/features/evidence-matrix/model.ts");
|
||||||
|
const source = readFileSync(sourcePath, "utf8");
|
||||||
|
const compiled = ts.transpileModule(source, {
|
||||||
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
|
||||||
|
});
|
||||||
|
|
||||||
|
const moduleExports = {};
|
||||||
|
new Function("exports", compiled.outputText)(moduleExports);
|
||||||
|
|
||||||
|
const {
|
||||||
|
buildEvidenceRows,
|
||||||
|
buildClaimRows,
|
||||||
|
filterUnsupportedClaims,
|
||||||
|
filterClaimsBySection,
|
||||||
|
} = moduleExports;
|
||||||
|
|
||||||
|
const evidenceRows = buildEvidenceRows([
|
||||||
|
{
|
||||||
|
id: "e1",
|
||||||
|
article_id: "a1",
|
||||||
|
source_title: "Source",
|
||||||
|
source_url: "https://example.com",
|
||||||
|
source_type: "primary",
|
||||||
|
source_quality_score: 0.9,
|
||||||
|
summary: "Summary",
|
||||||
|
supports_claims: [],
|
||||||
|
artifact_manifest_id: "m1",
|
||||||
|
retrieved_at: "2026-05-21T00:00:00Z",
|
||||||
|
review_status: "APPROVED",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
assert.equal(evidenceRows[0].sourceTitle, "Source");
|
||||||
|
assert.equal(evidenceRows[0].reviewStatus, "APPROVED");
|
||||||
|
|
||||||
|
const claimRows = buildClaimRows([
|
||||||
|
{
|
||||||
|
id: "c1",
|
||||||
|
article_id: "a1",
|
||||||
|
section_id: "s1",
|
||||||
|
claim_text: "Unsupported",
|
||||||
|
support_status: "UNSUPPORTED",
|
||||||
|
risk_level: "high",
|
||||||
|
evidence_item_ids: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "c2",
|
||||||
|
article_id: "a1",
|
||||||
|
section_id: "s2",
|
||||||
|
claim_text: "Supported",
|
||||||
|
support_status: "SUPPORTED",
|
||||||
|
risk_level: "low",
|
||||||
|
evidence_item_ids: ["e1"],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.equal(filterUnsupportedClaims(claimRows).length, 1);
|
||||||
|
assert.equal(filterClaimsBySection(claimRows, "s2")[0].claimText, "Supported");
|
||||||
@@ -1084,6 +1084,126 @@
|
|||||||
"title": "DraftSummary",
|
"title": "DraftSummary",
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"EvidenceCreateRequest": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"claim_text": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"default": null,
|
||||||
|
"title": "Claim Text"
|
||||||
|
},
|
||||||
|
"risk_level": {
|
||||||
|
"$ref": "#/components/schemas/ClaimRiskLevel",
|
||||||
|
"default": "low"
|
||||||
|
},
|
||||||
|
"section_id": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"format": "uuid",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"default": null,
|
||||||
|
"title": "Section Id"
|
||||||
|
},
|
||||||
|
"source_quality_score": {
|
||||||
|
"default": 0.7,
|
||||||
|
"maximum": 1,
|
||||||
|
"minimum": 0,
|
||||||
|
"title": "Source Quality Score",
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"source_title": {
|
||||||
|
"minLength": 1,
|
||||||
|
"title": "Source Title",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"source_type": {
|
||||||
|
"minLength": 1,
|
||||||
|
"title": "Source Type",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"source_url": {
|
||||||
|
"minLength": 1,
|
||||||
|
"title": "Source Url",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"summary": {
|
||||||
|
"minLength": 1,
|
||||||
|
"title": "Summary",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"support_status": {
|
||||||
|
"$ref": "#/components/schemas/ClaimSupportStatus",
|
||||||
|
"default": "SUPPORTED"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"source_title",
|
||||||
|
"source_url",
|
||||||
|
"source_type",
|
||||||
|
"summary"
|
||||||
|
],
|
||||||
|
"title": "EvidenceCreateRequest",
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"EvidenceMatrixResponse": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"article": {
|
||||||
|
"$ref": "#/components/schemas/ArticleSummary"
|
||||||
|
},
|
||||||
|
"claims": {
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/ClaimSummary"
|
||||||
|
},
|
||||||
|
"title": "Claims",
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"evidence": {
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/EvidenceSummary"
|
||||||
|
},
|
||||||
|
"title": "Evidence",
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"insufficient_evidence_reasons": {
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"title": "Insufficient Evidence Reasons",
|
||||||
|
"type": "array"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"article"
|
||||||
|
],
|
||||||
|
"title": "EvidenceMatrixResponse",
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"EvidenceResponse": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"evidence": {
|
||||||
|
"$ref": "#/components/schemas/EvidenceSummary"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"evidence"
|
||||||
|
],
|
||||||
|
"title": "EvidenceResponse",
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"EvidenceSummary": {
|
"EvidenceSummary": {
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -1107,6 +1227,12 @@
|
|||||||
"title": "Retrieved At",
|
"title": "Retrieved At",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"review_status": {
|
||||||
|
"default": "PENDING",
|
||||||
|
"minLength": 1,
|
||||||
|
"title": "Review Status",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"source_quality_score": {
|
"source_quality_score": {
|
||||||
"maximum": 1,
|
"maximum": 1,
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
@@ -1156,6 +1282,26 @@
|
|||||||
"title": "EvidenceSummary",
|
"title": "EvidenceSummary",
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"EvidenceUpdateRequest": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"review_status": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"pattern": "^(PENDING|APPROVED|REJECTED)$",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"default": null,
|
||||||
|
"title": "Review Status"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "EvidenceUpdateRequest",
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"HTTPValidationError": {
|
"HTTPValidationError": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"detail": {
|
"detail": {
|
||||||
@@ -3522,6 +3668,397 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/articles/{article_id}/draft/start": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "post_start_draft_api_articles__article_id__draft_start_post",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "article_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Article Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "header",
|
||||||
|
"name": "X-Demo-User-Email",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "X-Demo-User-Email"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"202": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/AgentJobListResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Successful Response"
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Validation Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"summary": "Post Start Draft",
|
||||||
|
"tags": [
|
||||||
|
"evidence"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/articles/{article_id}/evidence": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "get_article_evidence_api_articles__article_id__evidence_get",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "article_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Article Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "header",
|
||||||
|
"name": "X-Demo-User-Email",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "X-Demo-User-Email"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/EvidenceMatrixResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Successful Response"
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Validation Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"summary": "Get Article Evidence",
|
||||||
|
"tags": [
|
||||||
|
"evidence"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"operationId": "post_evidence_api_articles__article_id__evidence_post",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "article_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Article Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "header",
|
||||||
|
"name": "X-Demo-User-Email",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "X-Demo-User-Email"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requestBody": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/EvidenceCreateRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/EvidenceResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Successful Response"
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Validation Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"summary": "Post Evidence",
|
||||||
|
"tags": [
|
||||||
|
"evidence"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/articles/{article_id}/evidence/{evidence_id}": {
|
||||||
|
"delete": {
|
||||||
|
"operationId": "delete_evidence_api_articles__article_id__evidence__evidence_id__delete",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "article_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Article Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "evidence_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Evidence Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "header",
|
||||||
|
"name": "X-Demo-User-Email",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "X-Demo-User-Email"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"title": "Response Delete Evidence Api Articles Article Id Evidence Evidence Id Delete",
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Successful Response"
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Validation Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"summary": "Delete Evidence",
|
||||||
|
"tags": [
|
||||||
|
"evidence"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"patch": {
|
||||||
|
"operationId": "patch_evidence_api_articles__article_id__evidence__evidence_id__patch",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "article_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Article Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "evidence_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Evidence Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "header",
|
||||||
|
"name": "X-Demo-User-Email",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "X-Demo-User-Email"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requestBody": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/EvidenceUpdateRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/EvidenceResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Successful Response"
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Validation Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"summary": "Patch Evidence",
|
||||||
|
"tags": [
|
||||||
|
"evidence"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/articles/{article_id}/final/approve": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "post_final_approve_api_articles__article_id__final_approve_post",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "article_id",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"title": "Article Id",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"in": "header",
|
||||||
|
"name": "X-Demo-User-Email",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "X-Demo-User-Email"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ArticleCreateResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Successful Response"
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Validation Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"summary": "Post Final Approve",
|
||||||
|
"tags": [
|
||||||
|
"evidence"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/articles/{article_id}/plan/generate": {
|
"/api/articles/{article_id}/plan/generate": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "post_generate_plan_api_articles__article_id__plan_generate_post",
|
"operationId": "post_generate_plan_api_articles__article_id__plan_generate_post",
|
||||||
|
|||||||
@@ -180,11 +180,35 @@ export type DraftSummary = {
|
|||||||
version: number;
|
version: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type EvidenceCreateRequest = {
|
||||||
|
claim_text?: string | null;
|
||||||
|
risk_level?: ClaimRiskLevel;
|
||||||
|
section_id?: string | null;
|
||||||
|
source_quality_score?: number;
|
||||||
|
source_title: string;
|
||||||
|
source_type: string;
|
||||||
|
source_url: string;
|
||||||
|
summary: string;
|
||||||
|
support_status?: ClaimSupportStatus;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EvidenceMatrixResponse = {
|
||||||
|
article: ArticleSummary;
|
||||||
|
claims?: ClaimSummary[];
|
||||||
|
evidence?: EvidenceSummary[];
|
||||||
|
insufficient_evidence_reasons?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EvidenceResponse = {
|
||||||
|
evidence: EvidenceSummary;
|
||||||
|
};
|
||||||
|
|
||||||
export type EvidenceSummary = {
|
export type EvidenceSummary = {
|
||||||
article_id: string;
|
article_id: string;
|
||||||
artifact_manifest_id: string;
|
artifact_manifest_id: string;
|
||||||
id: string;
|
id: string;
|
||||||
retrieved_at: string;
|
retrieved_at: string;
|
||||||
|
review_status?: string;
|
||||||
source_quality_score: number;
|
source_quality_score: number;
|
||||||
source_title: string;
|
source_title: string;
|
||||||
source_type: string;
|
source_type: string;
|
||||||
@@ -193,6 +217,10 @@ export type EvidenceSummary = {
|
|||||||
supports_claims?: string[];
|
supports_claims?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type EvidenceUpdateRequest = {
|
||||||
|
review_status?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
export type HTTPValidationError = {
|
export type HTTPValidationError = {
|
||||||
detail?: ValidationError[];
|
detail?: ValidationError[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ Development description: Build claim extraction, claim-to-evidence mapping, unsu
|
|||||||
|
|
||||||
## Acceptance Criteria
|
## Acceptance Criteria
|
||||||
|
|
||||||
- [ ] TDD pre-requirement: before implementation, write one failing behavior test showing insufficient evidence returns the article to `PLAN_REVISION_REQUIRED`; proceed one claim/evidence behavior at a time and record evidence in `Result`.
|
- [x] TDD pre-requirement: before implementation, write one failing behavior test showing insufficient evidence returns the article to `PLAN_REVISION_REQUIRED`; proceed one claim/evidence behavior at a time and record evidence in `Result`.
|
||||||
- [ ] Every factual claim is mapped to at least one evidence item or marked unsupported.
|
- [x] Every factual claim is mapped to at least one evidence item or marked unsupported.
|
||||||
- [ ] Unsupported claims are visible by section.
|
- [x] Unsupported claims are visible by section.
|
||||||
- [ ] High-risk unsupported claims block final approval.
|
- [x] High-risk unsupported claims block final approval.
|
||||||
- [ ] Insufficient acceptable evidence blocks draft production and triggers plan revision.
|
- [x] Insufficient acceptable evidence blocks draft production and triggers plan revision.
|
||||||
- [ ] Editor can approve, reject, add, and remove evidence.
|
- [x] Editor can approve, reject, add, and remove evidence.
|
||||||
- [ ] Evidence UI supports section and unsupported-claim filters.
|
- [x] Evidence UI supports section and unsupported-claim filters.
|
||||||
- [ ] Evidence item retains URL, title, source type, summary, quality score, retrieval timestamp, and manifest reference.
|
- [x] Evidence item retains URL, title, source type, summary, quality score, retrieval timestamp, and manifest reference.
|
||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|
||||||
@@ -49,9 +49,9 @@ Development description: Build claim extraction, claim-to-evidence mapping, unsu
|
|||||||
|
|
||||||
## Result
|
## Result
|
||||||
|
|
||||||
- Status: Pending execution.
|
- Status: Accepted.
|
||||||
- TDD plan: To be filled during execution.
|
- TDD plan: Added `apps/backend/tests/integration/test_evidence_matrix_public_api.py` first, with the primary failing behavior around insufficient evidence forcing `PLAN_REVISION_REQUIRED` and blocking draft/final approval; then extended coverage for sufficient evidence flow and manual evidence add/remove operations.
|
||||||
- Red evidence: To be filled during execution.
|
- Red evidence: Before fixes, the evidence matrix behavior test failed with empty `evidence`/`claims` because `_build_matrix` was not fully applied in runtime flow (`test_sufficient_evidence_maps_claims_and_allows_draft` and insufficient scenario both failed).
|
||||||
- Green evidence: To be filled during execution.
|
- Green evidence: Implemented evidence matrix generation from research manifests, unsupported-claim gating, draft/final approval blockers, manual evidence CRUD operations (`POST/PATCH/DELETE` under article evidence routes), claim link updates after evidence removal, and FSD evidence UI with unsupported-only + section filters.
|
||||||
- Refactor notes: To be filled during execution.
|
- Refactor notes: Added `EvidenceCreateRequest` contract and shared type generation; consolidated evidence update flows in `apps/backend/src/application/evidence.py`; ensured article detail response surfaces evidence and claims; updated frontend API client and evidence panel to support add/remove alongside approve/reject.
|
||||||
- Verification output: To be filled during execution.
|
- Verification output: `PYTHONPATH=/private/tmp/pupline-backend-deps python3 -m unittest apps/backend/tests/integration/test_evidence_matrix_public_api.py apps/backend/tests/contracts/test_generated_contract_artifacts.py` passed. `node apps/frontend/tests/evidence_matrix.model.test.mjs` passed. `pnpm --filter @pipeline/frontend typecheck` passed. `bash tests/smoke/evidence-flow.sh` passed with Docker Compose after Docker socket escalation.
|
||||||
|
|||||||
Executable
+120
@@ -0,0 +1,120 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||||
|
COMPOSE_FILE="${ROOT_DIR}/docker-compose.yml"
|
||||||
|
BACKEND_URL="${BACKEND_URL:-http://localhost:8000}"
|
||||||
|
WAIT_SECONDS="${WAIT_SECONDS:-60}"
|
||||||
|
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
||||||
|
EDITOR_EMAIL="${EDITOR_EMAIL:-editor@example.com}"
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
docker compose -f "${COMPOSE_FILE}" down --remove-orphans >/dev/null 2>&1 || true
|
||||||
|
}
|
||||||
|
|
||||||
|
request() {
|
||||||
|
local method="$1"
|
||||||
|
local path="$2"
|
||||||
|
local body="${3:-}"
|
||||||
|
|
||||||
|
if [[ -n "${body}" ]]; then
|
||||||
|
curl -fsS -X "${method}" -H "Content-Type: application/json" \
|
||||||
|
-H "X-Demo-User-Email: ${EDITOR_EMAIL}" --data "${body}" "${BACKEND_URL}${path}"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
curl -fsS -X "${method}" -H "X-Demo-User-Email: ${EDITOR_EMAIL}" "${BACKEND_URL}${path}"
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_backend() {
|
||||||
|
local deadline=$((SECONDS + WAIT_SECONDS))
|
||||||
|
while (( SECONDS < deadline )); do
|
||||||
|
if curl -fsS "${BACKEND_URL}/health" >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "Timed out waiting for backend at ${BACKEND_URL}" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
json_eval() {
|
||||||
|
local expression="$1"
|
||||||
|
"${PYTHON_BIN}" -c "import json,sys; print(${expression})"
|
||||||
|
}
|
||||||
|
|
||||||
|
create_researched_article() {
|
||||||
|
local suffix="$1"
|
||||||
|
local site_id article_body article_id questions_json commands question_id answer plan_id
|
||||||
|
|
||||||
|
site_id="$(request GET /api/sites | json_eval "json.load(sys.stdin)[0]['site']['id']")"
|
||||||
|
article_body="$(
|
||||||
|
SITE_ID="${site_id}" SUFFIX="${suffix}" "${PYTHON_BIN}" - <<'PY'
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
suffix = os.environ["SUFFIX"]
|
||||||
|
print(json.dumps({
|
||||||
|
"target_site_id": os.environ["SITE_ID"],
|
||||||
|
"brief_description": f"Evidence smoke {suffix} {uuid.uuid4()}",
|
||||||
|
"working_title": "Evidence Smoke Flow",
|
||||||
|
"content_type": "longform_guide",
|
||||||
|
"primary_keyword": suffix,
|
||||||
|
}))
|
||||||
|
PY
|
||||||
|
)"
|
||||||
|
article_id="$(request POST /api/articles "${article_body}" | json_eval "json.load(sys.stdin)['article']['id']")"
|
||||||
|
questions_json="$(request POST "/api/articles/${article_id}/boundary-questions/generate")"
|
||||||
|
commands="$(
|
||||||
|
QUESTIONS_JSON="${questions_json}" "${PYTHON_BIN}" - <<'PY'
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
for question in json.loads(os.environ["QUESTIONS_JSON"])["questions"]:
|
||||||
|
if question["is_required"]:
|
||||||
|
print(f"{question['id']}\tAccepted answer for {question['category']}.")
|
||||||
|
PY
|
||||||
|
)"
|
||||||
|
while IFS=$'\t' read -r question_id answer; do
|
||||||
|
[[ -z "${question_id}" ]] && continue
|
||||||
|
patch_body="$(ANSWER="${answer}" "${PYTHON_BIN}" - <<'PY'
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
print(json.dumps({"answer": os.environ["ANSWER"]}))
|
||||||
|
PY
|
||||||
|
)"
|
||||||
|
request PATCH "/api/articles/${article_id}/boundary-questions/${question_id}" "${patch_body}" >/dev/null
|
||||||
|
done <<< "${commands}"
|
||||||
|
request POST "/api/articles/${article_id}/boundary-questions/submit" >/dev/null
|
||||||
|
plan_id="$(request POST "/api/articles/${article_id}/plan/generate" | json_eval "json.load(sys.stdin)['plan']['id']")"
|
||||||
|
request POST "/api/articles/${article_id}/plans/${plan_id}/approve" >/dev/null
|
||||||
|
request POST "/api/articles/${article_id}/research/start" >/dev/null
|
||||||
|
printf '%s' "${article_id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
cd "${ROOT_DIR}"
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
docker compose -f "${COMPOSE_FILE}" up --build -d
|
||||||
|
wait_backend
|
||||||
|
|
||||||
|
sufficient_id="$(create_researched_article "sufficient evidence coverage")"
|
||||||
|
sufficient_json="$(request GET "/api/articles/${sufficient_id}/evidence")"
|
||||||
|
sufficient_reasons="$(printf '%s' "${sufficient_json}" | json_eval "len(json.load(sys.stdin)['insufficient_evidence_reasons'])")"
|
||||||
|
if [[ "${sufficient_reasons}" != "0" ]]; then
|
||||||
|
echo "Expected sufficient flow without evidence reasons" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
insufficient_id="$(create_researched_article "insufficient evidence coverage")"
|
||||||
|
insufficient_json="$(request GET "/api/articles/${insufficient_id}/evidence")"
|
||||||
|
insufficient_status="$(printf '%s' "${insufficient_json}" | json_eval "json.load(sys.stdin)['article']['status']")"
|
||||||
|
unsupported_count="$(printf '%s' "${insufficient_json}" | json_eval "len([claim for claim in json.load(sys.stdin)['claims'] if claim['support_status'] == 'UNSUPPORTED'])")"
|
||||||
|
if [[ "${insufficient_status}" != "PLAN_REVISION_REQUIRED" || "${unsupported_count}" == "0" ]]; then
|
||||||
|
echo "Expected insufficient flow to return to PLAN_REVISION_REQUIRED with unsupported claims" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "evidence flow smoke ok"
|
||||||
Reference in New Issue
Block a user