fix: improve OCR indexing and evidence review
This commit is contained in:
@@ -26,6 +26,17 @@ def test_json_validation_and_evidence():
|
||||
ScoreResult(criterion_id="x", score=5, max_score=10, reason="无依据", evidence=[], confidence=.5)
|
||||
|
||||
|
||||
def test_evidence_quote_resolves_pdf_line_breaks_and_page():
|
||||
criterion = {"criterion_id": "stage1.problem", "max_score": 25}
|
||||
chunks = [{"chunk_id": 7, "page": 2, "text": "机器人\n控制精度:2 cm。"},
|
||||
{"chunk_id": 8, "page": 3, "text": "其他实验结果"}]
|
||||
result = ScoreResult(criterion_id="stage1.problem", score=19, max_score=25, reason="有指标",
|
||||
evidence=[{"chunk_id": 8, "page": 3, "quote": "机器人控制精度:2 cm"}], confidence=.8)
|
||||
checked = validate_score(result, criterion, chunks)
|
||||
assert checked.evidence[0].chunk_id == 7 and checked.evidence[0].page == 2
|
||||
assert checked.evidence[0].quote in chunks[0]["text"]
|
||||
|
||||
|
||||
def test_deepseek_adapter_mock_and_key_not_in_error(tmp_path):
|
||||
image = tmp_path / "page.png"
|
||||
image.write_bytes(b"png fixture")
|
||||
@@ -56,6 +67,28 @@ def test_project_isolation_and_chunk_metadata(db):
|
||||
assert "秘密" not in str(hits)
|
||||
|
||||
|
||||
def test_short_paragraphs_share_a_page_chunk():
|
||||
text = "\n\n".join(f"实验步骤{i}:采集机器人定位数据。" for i in range(12))
|
||||
chunks = list(split_pages([{"page_number": 4, "section": "实验", "text": text}]))
|
||||
assert len(chunks) == 1
|
||||
assert chunks[0]["page"] == 4
|
||||
assert "实验步骤0" in chunks[0]["text"] and "实验步骤11" in chunks[0]["text"]
|
||||
|
||||
|
||||
def test_stale_knowledge_index_reuses_document_id(db):
|
||||
pages = [{"page_number": 1, "text": "实验方案与测量结果"}]
|
||||
document = ingest(db, course_version_id=1, project_id=101, submission_file_id=None,
|
||||
title="报告", category="stage3", source_hash="same-source", pages=pages, embedder=fake_embed)
|
||||
old_chunk = db.scalar(select(KnowledgeChunk).where(KnowledgeChunk.document_id == document.id))
|
||||
old_chunk.text = "过时片段"
|
||||
document.index_version = 1
|
||||
db.commit()
|
||||
reindexed = ingest(db, course_version_id=1, project_id=101, submission_file_id=None,
|
||||
title="报告", category="stage3", source_hash="same-source", pages=pages, embedder=fake_embed)
|
||||
assert reindexed.id == document.id and reindexed.index_version == 2
|
||||
assert db.scalar(select(KnowledgeChunk.text).where(KnowledgeChunk.document_id == document.id)) == pages[0]["text"]
|
||||
|
||||
|
||||
def test_model_key_is_encrypted_and_hidden(db):
|
||||
result = save_model_config(db, {"model": "deepseek-flash", "api_key": "test-private-key"})
|
||||
assert result["api_key_configured"] is True
|
||||
|
||||
Reference in New Issue
Block a user