import assert from 'node:assert/strict' import fs from 'node:fs' import test from 'node:test' const read = (relative) => fs.readFileSync(new URL(`../${relative}`, import.meta.url), 'utf8') const contract = JSON.parse(read('contracts/persona-time-authority.json')) const stageOne = JSON.parse(read('contracts/stage-one-platform.json')) const rust = read('src-tauri/src/persona_time_authority.rs') const broker = read('src-tauri/src/direct_local_broker.rs') const lib = read('src-tauri/src/lib.rs') const numberedDispatcher = read('src-tauri/src/numbered_ipc_dispatch.rs') const personalChannel = read('src-tauri/src/personal_channel.rs') const frontend = read('src/main.tsx') test('Guanghu era is anchored to Beijing reality time without inventing an exact historical instant', () => { assert.equal(contract.era_name, '曜冥纪元') assert.equal(contract.calendar_name, '光湖历') assert.equal(contract.reality_time.canonical_zone, 'Asia/Shanghai') assert.equal(contract.reality_time.continues_while_application_is_closed, true) assert.equal(contract.guanghu_era.epoch_date, '2025-04-26') assert.equal(contract.guanghu_era.epoch_day, 1) assert.equal(contract.guanghu_era.epoch_exact_time, null) assert.equal(contract.guanghu_era.epoch_precision, 'DAY_ONLY_EXACT_TIME_UNKNOWN') assert.equal(contract.guanghu_era.millisecond_precision_transition_date, '2026-08-17') }) test('persona time tickets are durable unique and available to authenticated local carriers', () => { assert.equal(contract.ticket.atomic_storage, 'SQLITE_IMMEDIATE_TRANSACTION_SYNCHRONOUS_FULL') assert.equal(contract.ticket.idempotent_request_id, true) assert.equal(contract.ticket.clock_rollback_never_reverses_issued_time, true) assert.equal(contract.entries.external_ticket_issue_requires_authenticated_non_visitor_session, true) assert.match(rust, /TransactionBehavior::Immediate/) assert.match(rust, /logical_counter/) assert.match(rust, /millisecond_chain_origin_ticket_id/) assert.match(broker, /GetBeijingTime/) assert.match(broker, /IssuePersonaTimeTicket/) assert.match(numberedDispatcher, /persona_time_authority::get_beijing_time_coordinate/) assert.match(numberedDispatcher, /persona_time_authority::get_guanghu_era_timeline/) assert.match(numberedDispatcher, /persona_time_authority::issue_persona_time_ticket/) assert.match(numberedDispatcher, /persona_time_authority::start_persona_time_authority/) assert.match(lib, /persona_time_authority::start_on_application_open\(\)/) }) test('the public home timeline and personal channel module share the same time authority', () => { assert.equal(contract.homepage_timeline.projection, 'PUBLIC_FACT_TIMELINE') assert.equal(contract.homepage_timeline.event_count, 12) assert.equal(contract.homepage_timeline.external_reality_claims, false) assert.equal(contract.homepage_timeline.permanent_idle_polling, false) assert.equal(contract.homepage_timeline.early_evolution_period.starts_after_epoch_date, '2025-04-26') assert.equal(contract.homepage_timeline.early_evolution_period.ends_inclusive_month, '2026-02') assert.equal(contract.homepage_timeline.early_evolution_period.display_date, '2025-04-26 后—2026-02') assert.equal(contract.homepage_timeline.early_evolution_period.public_tone, 'OFFICIAL_FACTUAL_RESTRAINED') assert.equal(contract.homepage_timeline.early_evolution_period.must_not_be_omitted, true) assert.match(rust, /GH-ERA-20250426-202602-LANGUAGE-WORLD-CONSTRUCTION/) assert.match(rust, /语言世界早期构建与系统演化期/) assert.match(rust, /由冰朔一人持续建设/) assert.doesNotMatch(rust, /最漫长、最艰难也最黑暗/) assert.doesNotMatch(frontend, /setInterval\s*\(/) assert.equal(contract.personal_channel_module.installation, 'ATOMIC_WITH_PERSONAL_CHANNEL_INITIALIZATION') assert.equal(contract.personal_channel_module.existing_channel_migration, 'IDEMPOTENT_ADDITIVE') assert.match(personalChannel, /install_time_authority_module\(&transaction, created_at\)/) assert.match(personalChannel, /INSERT OR IGNORE INTO channel_modules/) assert.match(frontend, /EraTimelineOverlay/) assert.match(frontend, /time-module-strip/) assert.match(frontend, /打开软件时已联网校时/) }) test('unverified clock persona and host claims remain explicit truth boundaries', () => { assert.equal(contract.reality_time.primary_verification, 'NETWORK_HTTPS_DATE_SYNCHRONIZED_COARSE') assert.equal(contract.reality_time.offline_fallback_verification, 'LOCAL_CLOCK_NOT_NETWORK_ATTESTED') assert.equal(contract.truth_boundary.network_time_sync_on_application_open, true) assert.equal(contract.truth_boundary.network_clock_attestation, false) assert.equal(contract.event_coordinate.persona_current_verification, 'UNVERIFIED_CALLER_CLAIM') assert.equal(contract.event_coordinate.host_software_current_verification, 'UNVERIFIED_CALLER_CLAIM') assert.equal(contract.truth_boundary.installed_runtime_acceptance, false) assert.equal(contract.truth_boundary.world_lighthouse_authority_registration, false) assert.equal(stageOne.persona_time_authority.network_clock_attestation, false) assert.equal(stageOne.persona_time_authority.network_time_sync_on_application_open, true) assert.equal(stageOne.persona_time_authority.installed_runtime_acceptance, false) })