import assert from 'node:assert/strict' import fs from 'node:fs' import test from 'node:test' const read = (path) => fs.readFileSync(new URL('../' + path, import.meta.url), 'utf8') const contract = JSON.parse(read('contracts/education-workspace.json')) const donors = JSON.parse(read('contracts/education-open-source-donor-assessment.json')) const industry = JSON.parse(read('contracts/subdomain-industry-routing.json')) const rust = read('src-tauri/src/education_workspace.rs') const translation = read('src-tauri/src/education_translation.rs') const lib = read('src-tauri/src/lib.rs') const ui = read('src/main.tsx') const documentEngine = read('src/modules/education-document-engine.tsx') const channelDocumentEngine = read('src/modules/channel-workbench/document-engine.tsx') const channelSpreadsheetEngine = read('src/modules/channel-workbench/spreadsheet-engine.tsx') const channelSpreadsheetModel = read('src/modules/channel-workbench/spreadsheet-model.ts') const moduleRuntime = JSON.parse(read('contracts/channel-module-runtime.json')) const marketplaceDevelopmentCatalog = JSON.parse(read('contracts/official-module-marketplace-development-catalog.json')) const adaptiveRendering = read('src/modules/education-adaptive-rendering.ts') const dataCleanup = read('src/modules/education-data.ts') test('education package consumes the built-in account-scoped channel workbench', () => { assert.equal(contract.domain_entry, 'BRANCH_DOMAIN') assert.equal(contract.channel_id, 'GH-EDU-INIT-001') assert.equal(contract.native_storage.owner, 'HOLOLAKE_NATIVE_RUST_CORE') assert.equal(contract.native_storage.engine, 'SQLITE') assert.equal(contract.native_storage.authenticated_account_required, true) assert.equal(contract.native_storage.cross_account_projection_allowed, false) assert.equal(contract.native_storage.restart_readback_required, true) assert.equal(contract.document_module.state, 'DEVELOPMENT_FEATURE_MOUNTED') assert.equal(contract.table_module.state, 'DEVELOPMENT_FEATURE_MOUNTED') assert.equal(contract.foundation_dependency.module_id, 'hololake.builtin.channel-workbench') assert.match(contract.document_module.engine, /^CHANNEL_WORKBENCH_LEXICAL_0_49_0/) assert.match(contract.table_module.engine, /^CHANNEL_WORKBENCH_FORTUNE_SHEET_1_0_4/) assert.equal(contract.table_module.sensitive_field_visibility.local_default, 'VISIBLE') assert.equal(contract.table_module.sensitive_field_visibility.human_can_hide, true) assert.equal(contract.table_module.sensitive_field_visibility.human_can_show_again, true) }) test('education workspace commands require the authenticated storage root', () => { assert.match(rust, /account_storage_root\(app, "education-workspace-v1"\)/) for (const command of [ 'get_education_workspace_snapshot', 'create_education_document', 'read_education_document', 'save_education_document', 'archive_education_document', 'create_education_table', 'read_education_table', 'save_education_table', 'archive_education_table', 'create_education_automation_rule', 'save_education_automation_rule', 'archive_education_automation_rule', 'preview_education_automation_rule', 'execute_education_automation_rule', ]) { assert.match(lib, new RegExp('education_workspace::' + command)) assert.ok(ui.includes("'" + command + "'") || ui.includes('"' + command + '"')) } assert.doesNotMatch(ui, /localStorage.*education/i) }) test('one built-in foundation and five development features are reachable from the education channel', () => { const education = industry.industries.find((item) => item.key === 'EDUCATION') assert.equal(education.initialization_channel.installed_open_source_modules, 0) assert.equal(education.initialization_channel.installed_native_modules, 1) assert.equal(education.initialization_channel.development_mounted_modules, 1) assert.ok(education.initialization_channel.module_slots.every((slot) => slot.state === 'DEVELOPMENT_MOUNTED')) assert.equal(education.initialization_channel.module_slots[1].state_label, '开发态模块 · 使用频道内置工作表引擎') assert.match(ui, /worldStage === 'educationDocuments'/) assert.match(ui, /worldStage === 'educationTables'/) assert.match(ui, /教育文档/) assert.match(ui, /教育表格数据/) assert.match(ui, /worldStage === 'educationAutomation'/) assert.match(ui, /教育自动化/) assert.match(ui, /worldStage === 'educationComposition'/) assert.match(ui, /原生组合视图/) }) test('native persistence enforces revision conflicts and bounded table data', () => { assert.match(rust, /HOLOLAKE_EDUCATION_DOCUMENT_REVISION_CONFLICT/) assert.match(rust, /HOLOLAKE_EDUCATION_TABLE_REVISION_CONFLICT/) assert.match(rust, /MAX_TABLE_COLUMNS: usize = 30/) assert.match(rust, /MAX_TABLE_ROWS: usize = 1_000/) assert.match(rust, /MAX_CELL_BYTES: usize = 10_000/) assert.match(rust, /archived = 1/) }) test('education documents expose formal templates and real title filtering', () => { assert.equal(contract.state, 'DEVELOPMENT_MODULE_SOURCE_MOUNTED_ACCEPTANCE_PENDING') assert.equal(contract.package.official_module_number, null) assert.equal(contract.package.registration_state, 'PENDING_FUNCTIONAL_ACCEPTANCE_AND_NUMBER_REGISTRATION') assert.ok(contract.document_module.capabilities.includes('FORMAL_TEACHING_TEMPLATES')) assert.ok(contract.document_module.capabilities.includes('TITLE_DIRECTORY_FILTER')) assert.match(ui, /EDUCATION_DOCUMENT_TEMPLATES/) assert.match(ui, /教学计划/) assert.match(ui, /教育项目会议纪要/) assert.match(ui, /学员阶段复盘/) assert.match(ui, /检索教育文档标题/) for (const capability of [ 'CREATE_COPY', 'EXPLICIT_READ_AND_EDIT_MODES', 'HUMAN_SETTINGS_MENU', 'BASIC_FORMATTING_TOOLBAR', 'NATIVE_READING_CANVAS', 'EXPORT_MARKDOWN_AND_HTML', ]) assert.ok(contract.document_module.capabilities.includes(capability)) assert.match(ui, /文档设置/) assert.match(ui, /编辑与重命名/) assert.match(ui, /创建副本/) assert.match(ui, /移到可恢复归档/) assert.match(ui, /educationDocumentMode === 'edit'/) assert.match(documentEngine, /ChannelDocumentEngine/) assert.match(channelDocumentEngine, /频道内置文档引擎工具/) }) test('education table has four engine-backed views, filtering, sorting and bounded bulk paste', () => { for (const capability of [ 'CELL_CONTENT_FILTER', 'COLUMN_SORT_ASCENDING_DESCENDING_OR_SOURCE_ORDER', 'BOUNDED_PAGINATION_ROW_MODEL_FOR_LARGE_EDITABLE_TABLES', 'GRID_AND_EDITABLE_CARD_VIEWS', 'GROUPED_CLASSIFICATION_BOARD_FROM_SELECTED_FIELD', 'LIVE_DATA_OVERVIEW_WITH_SELECTED_GROUP_AND_MEASURE', 'HEADLESS_TABLE_DATA_DETACHED_OUTSIDE_TABLE_SURFACE', 'MULTI_ROW_MULTI_COLUMN_TABULAR_PASTE', ]) assert.ok(contract.table_module.capabilities.includes(capability)) assert.match(ui, /parseEducationGridPaste/) assert.match(ui, /pasteEducationTableGrid/) assert.match(ui, />工作表<\/button>/) assert.match(channelSpreadsheetEngine, /Workbook/) assert.match(channelSpreadsheetEngine, /showFormulaBar/) assert.match(channelSpreadsheetEngine, /conditionFormat/) assert.match(channelSpreadsheetModel, /cell\.f/) assert.match(ui, /分类看板/) assert.match(ui, /数据概览/) assert.match(ui, /renderEducationBoard/) assert.match(ui, /renderEducationDashboard/) assert.match(ui, /动态分类对比/) assert.match(ui, /筛选教育表格数据/) assert.match(ui, /升序 ↑/) assert.match(ui, /降序 ↓/) assert.match(ui, /getPaginationRowModel/) assert.match(ui, /const educationTableEngineActive = worldStage === 'educationTables'/) assert.match(ui, /educationTableEngineActive \? activeEducationTable\?\.rows \|\| \[\] : \[\]/) assert.match(adaptiveRendering, /EDUCATION_EDITABLE_CELL_BUDGET = 240/) assert.match(adaptiveRendering, /function educationEditablePageSize/) assert.match(adaptiveRendering, /Math\.floor\(EDUCATION_EDITABLE_CELL_BUDGET \/ boundedColumns\)/) assert.match(adaptiveRendering, /buildEducationBaselineRenderPlan/) assert.match(adaptiveRendering, /validateEducationModelRenderProposal/) assert.match(adaptiveRendering, /MODEL_PROPOSAL_REJECTED/) assert.match(adaptiveRendering, /WAITING_HUMAN_CONFIRMATION/) assert.match(adaptiveRendering, /已优雅退回本地基础算法/) assert.match(ui, /基础算法自适应回执/) assert.match(ui, /教育表格分页/) assert.match(ui, /Math\.min\(30/) assert.match(ui, /Math\.min\(1000/) assert.ok(contract.table_module.capabilities.includes('HUMAN_SETTINGS_MENU')) assert.ok(contract.table_module.capabilities.includes('CREATE_COPY')) assert.match(ui, /表格设置/) assert.match(ui, /duplicateEducationTable/) assert.match(ui, /重命名与编辑/) assert.match(ui, /isSensitiveEducationColumn/) assert.match(ui, /账号\|账户\|手机号/) assert.match(ui, /联系qq\|qq号/) assert.match(ui, /useState\(true\).*educationSensitiveVisible|educationSensitiveVisible, setEducationSensitiveVisible\] = useState\(true\)/) assert.match(ui, /隐藏敏感字段/) assert.match(ui, /显示敏感字段/) assert.doesNotMatch(ui, /setEducationSensitiveVisible\(false\)/) assert.match(ui, /type=\{sensitive && !educationSensitiveVisible \? 'password' : 'text'\}/) }) test('external tables are profiled before atomic native registration and can be translated back out', () => { assert.equal(contract.content_translation_layer.state, 'DETERMINISTIC_RUNTIME_READY_MODEL_ASSIST_SLOT_RESERVED') assert.equal(contract.content_translation_layer.source_file_mutation_allowed, false) assert.equal(contract.content_translation_layer.silent_truncation_allowed, false) assert.equal(contract.content_translation_layer.local_import_without_model_api, 'ENABLED_FOR_ALL_SUPPORTED_FORMATS') assert.equal(contract.content_translation_layer.semantic_focus.current_mode, 'DETERMINISTIC_BASELINE_ONLY') assert.equal(contract.content_translation_layer.semantic_focus.low_confidence_behavior, 'ASK_HUMAN_TO_SELECT_PRIMARY_MEASURE') assert.equal(contract.content_translation_layer.adaptive_rendering.current_mode, 'DETERMINISTIC_BASELINE_WITH_EXPLAINABLE_DEGRADATION') assert.equal(contract.content_translation_layer.adaptive_rendering.editable_cell_budget, 240) assert.equal(contract.content_translation_layer.adaptive_rendering.local_baseline_always_available, true) assert.equal(contract.content_translation_layer.adaptive_rendering.model_adjustment.human_confirmation_before_rule_activation, true) assert.equal(contract.content_translation_layer.adaptive_rendering.model_adjustment.model_can_mutate_source_data, false) assert.equal(contract.content_translation_layer.adaptive_rendering.model_adjustment.failure_behavior, 'RETURN_TO_LOCAL_BASELINE_WITH_RECEIPT') assert.deepEqual(contract.content_translation_layer.model_assist.learning_scopes, ['PRIVATE_ONLY', 'SHARE_ANONYMIZED_RULE']) assert.match(translation, /PROFILED_BEFORE_WRITE/) assert.match(translation, /import_table_batch_at/) assert.match(translation, /source_preserved_read_only: true/) assert.match(translation, /HOLOLAKE_MODEL_RECOGNITION_API\/v1/) assert.match(translation, /infer_semantic_focus/) assert.match(translation, /primary_measure_column/) assert.match(rust, /education_import_registry/) assert.match(ui, /导入外部表格/) assert.match(ui, /导出 Excel/) assert.match(ui, /识别边界回执/) assert.match(ui, /本地导入正常可用/) }) test('audited translation libraries and headless engines stay bounded inside the HoloLake product shell', () => { assert.equal(donors.state, 'FOUR_TRANSLATION_FAMILIES_TWO_HEADLESS_FAMILIES_AND_ONE_REAL_SPREADSHEET_ENGINE_INTEGRATED') assert.equal(donors.current_slice.external_translation_library_families_added, 4) assert.equal(donors.current_slice.external_headless_engine_families_added, 2) assert.equal(donors.current_slice.real_spreadsheet_engine_families_added, 1) assert.equal(donors.current_slice.direct_frontend_engine_packages_added, 10) assert.equal(donors.current_slice.external_source_files_copied, 0) assert.equal(donors.current_slice.source_research_route, 'LOCAL_DIRECT_TO_BS_SG_002_THEN_EXTERNAL_DRIVE') assert.equal(donors.candidates.find((candidate) => candidate.name === 'Calamine').decision, 'INTEGRATE_PINNED_0_26_1_READ_ONLY_NO_OFFICE_RUNTIME') assert.equal(donors.candidates.find((candidate) => candidate.name === 'rust_xlsxwriter').decision, 'INTEGRATE_PINNED_0_64_2_WRITE_NEW_XLSX_ONLY') assert.equal(donors.candidates.find((candidate) => candidate.name === 'AppFlowy').decision, 'DO_NOT_EMBED_WHOLE_APPLICATION_STUDY_WORKSPACE_AND_DATABASE_INTERACTION_LOGIC_ONLY') assert.match(donors.candidates.find((candidate) => candidate.name === 'Lexical').decision, /^INTEGRATE_PINNED_0_49_0/) assert.equal(donors.candidates.find((candidate) => candidate.name === 'TanStack Table').decision, 'INTEGRATE_PINNED_8_21_3_SORT_FILTER_GROUP_AGGREGATE_AND_PAGINATION_ROW_MODELS_ONLY') assert.equal(donors.candidates.find((candidate) => candidate.name === 'Univer').decision, 'SOURCE_STUDY_ONLY_DO_NOT_EMBED_WHOLE_APPLICATION_DEFER_FORMULA_AND_ADVANCED_GRID_PARTS') assert.match(donors.candidates.find((candidate) => candidate.name === 'FortuneSheet').decision, /^INTEGRATE_PINNED_1_0_4/) assert.equal(donors.candidates.find((candidate) => candidate.name === 'Glide Data Grid').decision, 'SOURCE_STUDY_ONLY_GRID_IS_NOT_A_SPREADSHEET_OR_FORMULA_ENGINE') assert.equal(donors.candidates.find((candidate) => candidate.name === 'Vega-Lite').observed_license, 'BSD-3-Clause') assert.equal(donors.candidates.find((candidate) => candidate.name === 'Observable Plot').observed_license, 'ISC') assert.equal(donors.candidates.find((candidate) => candidate.name === 'Apache ECharts').decision, 'DO_NOT_IMPORT_FOR_STAGE_ONE_FIVE_NATIVE_VIEWS_DO_NOT_JUSTIFY_RUNTIME_WEIGHT') assert.match(ui, /useReactTable/) assert.match(ui, /getGroupedRowModel/) assert.match(ui, /lazy\(\(\) => import\('\.\/modules\/education-document-engine'\)\)/) assert.match(channelDocumentEngine, /LexicalComposer/) assert.match(channelDocumentEngine, /HistoryPlugin/) assert.match(channelDocumentEngine, /\$convertFromMarkdownString/) assert.match(channelDocumentEngine, /\$convertToMarkdownString/) }) test('official module marketplace boundary is honest before education acceptance', () => { assert.equal(moduleRuntime.built_in_foundation.module_id, 'hololake.builtin.channel-workbench') assert.equal(moduleRuntime.built_in_foundation.marketplace_registration, 'NOT_A_MARKETPLACE_MODULE') assert.equal(moduleRuntime.current_reality.official_marketplace_service_connected, false) const educationPackage = marketplaceDevelopmentCatalog.packages.find((item) => item.package_key === 'hololake.official.education-workbench') assert.equal(educationPackage.official_module_number, null) assert.equal(educationPackage.distribution_state, 'NOT_PUBLISHED') assert.ok(educationPackage.acceptance_required.includes('CREATE_EDIT_FORMULA_SAVE_REOPEN_SPREADSHEET')) }) test('native composition uses one real account dataset for five read-only human projections', () => { assert.equal(contract.composition_module.state, 'DEVELOPMENT_FEATURE_MOUNTED') assert.equal(contract.composition_module.source, 'CURRENT_AUTHENTICATED_ACCOUNTS_REAL_KNOWLEDGE_CATALOG') assert.equal(contract.composition_module.read_only, true) assert.equal(contract.composition_module.hardcoded_sample_data_used, false) for (const capability of [ 'NATIVE_TYPED_OBJECT', 'REGISTERED_MODULE_EXECUTION_GRAPH', 'DASHBOARD_PROJECTION', 'COMPARISON_PROJECTION', 'VERTICAL_BAR_PROJECTION', 'CLASSIFICATION_PROJECTION', 'TABLE_PROJECTION', 'ONE_EXECUTION_RESULT_MULTIPLE_HUMAN_VIEWS', ]) assert.ok(contract.composition_module.capabilities.includes(capability)) assert.match(lib, /native_composition::execute_knowledge_native_composition/) assert.match(ui, /execute_knowledge_native_composition/) }) test('education data cleanup previews bounded deterministic rules and requires human confirmation before save', () => { assert.equal(contract.data_cleanup_module.state, 'DEVELOPMENT_FEATURE_MOUNTED') assert.equal(contract.data_cleanup_module.automatic_destructive_cleanup_allowed, false) assert.equal(contract.data_cleanup_module.cross_account_data_allowed, false) for (const capability of [ 'TRIM_CELL_BOUNDARY_WHITESPACE', 'REMOVE_FULLY_EMPTY_ROWS', 'REMOVE_EXACT_DUPLICATE_ROWS_KEEP_FIRST', 'PREVIEW_BEFORE_WRITE', 'FULL_TABLE_ANALYSIS_WITH_BOUNDED_CHANGE_PREVIEW', 'ACCESSIBILITY_SAFE_NON_TABLE_CHANGE_LIST', 'HUMAN_CONFIRMATION_BEFORE_SAVE', 'SAVE_WITH_EXPECTED_REVISION', ]) assert.ok(contract.data_cleanup_module.capabilities.includes(capability)) assert.equal(contract.data_cleanup_module.preview_change_limit, 12) assert.equal(contract.data_cleanup_module.preview_cell_value_character_limit, 120) assert.equal(contract.data_cleanup_module.full_table_analysis_is_limited_by_preview, false) assert.match(dataCleanup, /EDUCATION_CLEANUP_CHANGE_PREVIEW_LIMIT = 12/) assert.match(dataCleanup, /changePreview\.length < EDUCATION_CLEANUP_CHANGE_PREVIEW_LIMIT/) assert.match(dataCleanup, /singleLine\.length > 120/) assert.match(ui, /analyzeEducationTableData/) assert.match(ui, /const educationDataAnalysis = useMemo/) assert.match(ui, /已分析全表/) assert.match(ui, /education-cleanup-change-list/) assert.doesNotMatch(ui, /analysis\.cleanedRows\.slice\(0, 12\)/) assert.match(ui, /educationData/) assert.match(ui, /window\.confirm\(`将整理/) assert.match(ui, /确认整理并保存/) assert.match(ui, /保存前不写入数据库/) }) test('education automation is manual, revision-locked, previewed and receipted', () => { assert.equal(contract.automation_module.state, 'DEVELOPMENT_FEATURE_MOUNTED') assert.equal(contract.automation_module.background_or_scheduled_execution_allowed, false) assert.equal(contract.automation_module.cross_account_data_allowed, false) assert.equal(contract.automation_module.model_execution_authority_granted, false) for (const capability of [ 'CREATE_AND_SAVE_RULE', 'PREVIEW_MATCHED_ROWS_AND_CHANGED_CELLS', 'HUMAN_CONFIRMATION_BEFORE_EXECUTION', 'RULE_AND_TABLE_REVISION_LOCK', 'SIGNED_PREVIEW_TOKEN', 'ATOMIC_TABLE_WRITE_AND_EXECUTION_RECEIPT', ]) assert.ok(contract.automation_module.capabilities.includes(capability)) assert.match(rust, /education_automation_rules/) assert.match(rust, /education_automation_runs/) assert.match(rust, /transaction_with_behavior/) assert.match(rust, /HOLOLAKE_EDUCATION_AUTOMATION_PREVIEW_TOKEN_MISMATCH/) assert.match(ui, /预览执行范围/) assert.match(ui, /确认运行并生成回执/) assert.match(ui, /系统不会在后台自行运行/) })