统一:DSH 智能分析、Top100 与图表静默恢复
接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import sys
|
||||
import hashlib
|
||||
import tempfile
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path[:0] = [str(ROOT / 'scripts'), str(ROOT / 'verification')]
|
||||
import verify_dsh_formal as fixture
|
||||
import isolated_runtime
|
||||
|
||||
|
||||
class DshFormalFixtureTests(unittest.TestCase):
|
||||
def test_seed_is_three_months_two_stages_two_org_groups_and_six_products(self):
|
||||
rows = fixture.fixture_rows()
|
||||
self.assertEqual(len(rows), 36)
|
||||
self.assertEqual({row.month for row in rows}, {'2026-08', '2026-09', '2026-10'})
|
||||
self.assertEqual({row.stage for row in rows}, {'black', 'bright'})
|
||||
self.assertEqual({row.department for row in rows}, set(fixture.DEPARTMENTS))
|
||||
self.assertEqual({row.group for row in rows}, set(fixture.GROUPS))
|
||||
self.assertEqual({row.product for row in rows}, set(fixture.PRODUCTS))
|
||||
for month in fixture.PERIODS:
|
||||
for stage in ('black', 'bright'):
|
||||
selected = [row for row in rows if row.month == month and row.stage == stage]
|
||||
self.assertEqual({row.product for row in selected}, set(fixture.PRODUCTS))
|
||||
|
||||
def test_missing_detail_is_explicit_and_formal_rollup_stays_complete(self):
|
||||
rows = fixture.fixture_rows()
|
||||
missing = [row for row in rows if row.month == '2026-09' and row.stage == 'black'
|
||||
and row.product == '合成产品06']
|
||||
self.assertEqual(len(missing), 1)
|
||||
self.assertIn('责废尺寸重量', missing[0].raw)
|
||||
self.assertIsNone(missing[0].raw['责废尺寸重量'])
|
||||
self.assertGreater(missing[0].components['black_responsibility_scrap'], 0)
|
||||
self.assertEqual(fixture.fixture_totals(rows, 'black', '2026-10')['rows'], 6)
|
||||
self.assertEqual(fixture.fixture_totals(rows, 'bright', '2026-10')['rows'], 6)
|
||||
|
||||
def test_generated_archive_is_a_hashed_synthetic_xlsx_with_source_fields(self):
|
||||
rows = [row for row in fixture.fixture_rows()
|
||||
if row.stage == 'black' and row.month == '2026-09']
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
path = Path(temporary) / 'synthetic.xlsx'
|
||||
digest, size = fixture._write_workbook(path, rows)
|
||||
self.assertEqual(digest, hashlib.sha256(path.read_bytes()).hexdigest())
|
||||
self.assertEqual(size, path.stat().st_size)
|
||||
with ZipFile(path) as archive:
|
||||
self.assertTrue({'[Content_Types].xml', '_rels/.rels', 'xl/workbook.xml',
|
||||
'xl/worksheets/sheet1.xml'}.issubset(set(archive.namelist())))
|
||||
worksheet = ET.fromstring(archive.read('xl/worksheets/sheet1.xml'))
|
||||
cells = [element.text for element in worksheet.iter() if element.tag.endswith('}t')]
|
||||
self.assertIn('责废尺寸重量', cells)
|
||||
self.assertIn('责废缺角重量', cells)
|
||||
|
||||
def test_source_physical_rows_restart_for_each_source_workbook(self):
|
||||
values = list(fixture.source_physical_rows(fixture.fixture_rows()))
|
||||
first_file = [row_no for row, row_no in values if row.stage == 'black' and row.month == '2026-08']
|
||||
next_file = [row_no for row, row_no in values if row.stage == 'bright' and row.month == '2026-08']
|
||||
self.assertEqual(first_file, list(range(2, 8)))
|
||||
self.assertEqual(next_file, list(range(2, 8)))
|
||||
|
||||
def test_private_sql_literals_are_hex_encoded(self):
|
||||
self.assertEqual(fixture._literal("模型'; DROP DATABASE nope;"),
|
||||
'CONVERT(0x' + "模型'; DROP DATABASE nope;".encode().hex() + ' USING utf8mb4)')
|
||||
self.assertIn('CAST(CONVERT(0x', fixture._json_sql({'来源': '合成值'}))
|
||||
|
||||
def test_isolated_runtime_accepts_only_scoped_engine_and_protocol_overrides(self):
|
||||
signature = isolated_runtime.isolated_api.__wrapped__.__code__.co_varnames
|
||||
self.assertIn('env_overrides', signature)
|
||||
self.assertIn('auth_credentials', signature)
|
||||
source = (ROOT / 'verification/isolated_runtime.py').read_text(encoding='utf-8')
|
||||
self.assertIn("'QUALITY_ARCHIVE_ROOT'", source)
|
||||
self.assertIn("'SERVER_SERVLET_SESSION_COOKIE_NAME'", source)
|
||||
self.assertTrue(callable(isolated_runtime.sql))
|
||||
self.assertTrue(callable(isolated_runtime.clone_database))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user