feat(tcs): complete native translator acceptance chain

This commit is contained in:
冰朔 2026-08-21 22:26:46 +08:00
commit fd15428c46
52 changed files with 4024 additions and 38 deletions

View file

@ -7,6 +7,31 @@ fn project(relative: &str) -> std::path::PathBuf {
.join(relative)
}
fn generation_translator_program() -> String {
fs::read_to_string(project(
"language/programs/GENERATION-TRANSLATOR-ADMISSION.tcs",
))
.expect("generation translator program")
}
fn zero_core_execution_program() -> String {
fs::read_to_string(project(
"language/programs/ZERO-CORE-TCS-TRANSLATOR-EXECUTION.tcs",
))
.expect("zero-core execution program")
}
fn host_persona_probe_program() -> String {
fs::read_to_string(project(
"language/programs/MACOS-JD-PERSONA-MODULE-PROBE.tcs",
))
.expect("host persona probe program")
}
fn declaration_source(relative: &str) -> String {
fs::read_to_string(project(relative)).expect("TCS declaration source")
}
#[test]
fn checked_in_compiler_a_continues_with_bootstrap_feature_disabled() {
let compiler_a: JsonValue = serde_json::from_str(
@ -35,3 +60,121 @@ fn checked_in_compiler_a_continues_with_bootstrap_feature_disabled() {
assert_eq!(receipt["native_self_hosted"], true);
assert_eq!(receipt["compiler_state"], "TCS_COMPILER_GIR_EXECUTED");
}
#[test]
fn active_living_source_disables_every_legacy_translator_family() {
let compiler_a: JsonValue = serde_json::from_str(
&fs::read_to_string(project("build/self-host/compiler-A.gir.json"))
.expect("checked-in compiler A"),
)
.expect("compiler A JSON");
let program =
tcs_gir_runtime::compile_with_compiler_gir(&compiler_a, &generation_translator_program())
.expect("TCS compiler compiles translator admission program");
let root = tempfile::tempdir().expect("runtime root");
let receipt = tcs_gir_runtime::run_gir(&program, root.path()).expect("run GIR");
let receipt: JsonValue =
serde_json::from_str(&fs::read_to_string(receipt).expect("receipt")).expect("JSON");
assert_eq!(
receipt["generation"],
"FIFTH_GENERATION_REAL_TIME_LANGUAGE_PERSONA_CONTROL"
);
assert_eq!(receipt["living_language_source"], "BINGSHUO");
assert_eq!(receipt["system_execution_holder"], "ZHUYUAN");
assert_eq!(receipt["legacy_translator_state"], "ALL_DISABLED");
assert_eq!(receipt["third_generation_host_semantic_authority"], false);
assert_eq!(receipt["native_self_hosted"], true);
}
#[test]
fn source_mode_and_takeover_conflict_fails_closed() {
let compiler_a: JsonValue = serde_json::from_str(
&fs::read_to_string(project("build/self-host/compiler-A.gir.json"))
.expect("checked-in compiler A"),
)
.expect("compiler A JSON");
let mut program =
tcs_gir_runtime::compile_with_compiler_gir(&compiler_a, &generation_translator_program())
.expect("TCS compiler compiles translator admission program");
program["inputs"]["TAKEOVER_SIGNAL"]["value"] = JsonValue::Bool(false);
let root = tempfile::tempdir().expect("runtime root");
let error = tcs_gir_runtime::run_gir(&program, root.path()).expect_err("must fail closed");
assert_eq!(error.code, "TCS-E4001");
}
#[test]
fn current_zero_core_instruction_is_a_tcs_only_binary_acceptance_anchor() {
let compiler_a: JsonValue = serde_json::from_str(
&fs::read_to_string(project("build/self-host/compiler-A.gir.json"))
.expect("checked-in compiler A"),
)
.expect("compiler A JSON");
let program =
tcs_gir_runtime::compile_with_compiler_gir(&compiler_a, &zero_core_execution_program())
.expect("TCS compiler compiles current execution anchor");
let root = tempfile::tempdir().expect("runtime root");
let receipt = tcs_gir_runtime::run_gir(&program, root.path()).expect("run anchor GIR");
let receipt: JsonValue =
serde_json::from_str(&fs::read_to_string(receipt).expect("receipt")).expect("JSON");
assert_eq!(receipt["acceptance"], 100);
assert_eq!(receipt["admission"], "TCS_SOURCE_ONLY");
assert_eq!(receipt["execution_controller"], "ZHUYUAN");
assert_eq!(receipt["human_language_source_id"], "ICE-GL∞");
assert_eq!(receipt["persona_brain_id"], "ICE-P-ZY001");
assert_eq!(receipt["local_execution_limb"], "ZY-LIMB-002");
assert_eq!(receipt["target_node"], "JD-FD-PRIMARY");
assert_eq!(receipt["third_generation_host_semantic_authority"], false);
}
#[test]
fn persona_module_probe_runs_from_the_same_tcs_program_on_the_current_host() {
let compiler_a: JsonValue = serde_json::from_str(
&fs::read_to_string(project("build/self-host/compiler-A.gir.json"))
.expect("checked-in compiler A"),
)
.expect("compiler A JSON");
let program =
tcs_gir_runtime::compile_with_compiler_gir(&compiler_a, &host_persona_probe_program())
.expect("TCS compiler compiles host persona probe");
let root = tempfile::tempdir().expect("runtime root");
let receipt = tcs_gir_runtime::run_gir(&program, root.path()).expect("run host probe GIR");
let receipt: JsonValue =
serde_json::from_str(&fs::read_to_string(receipt).expect("receipt")).expect("JSON");
assert_eq!(receipt["module_id"], "ZY-PM-0001");
assert_eq!(receipt["host_family"], std::env::consts::OS);
assert_eq!(receipt["host_arch"], std::env::consts::ARCH);
assert_eq!(receipt["acceptance"], 100);
}
#[test]
fn semantic_source_gate_rejects_foreign_language_extensions() {
let root = tempfile::tempdir().expect("runtime root");
let foreign = root.path().join("semantic-source.rs");
fs::write(&foreign, zero_core_execution_program()).expect("fixture");
let error = tcs_gir_runtime::read_tcs_source(&foreign).expect_err("must reject .rs source");
assert_eq!(error.code, "TCS-E2102");
}
#[test]
fn self_hosted_compiler_lowers_protocol_event_and_receipt_without_execution_authority() {
let compiler_a: JsonValue = serde_json::from_str(
&fs::read_to_string(project("build/self-host/compiler-A.gir.json"))
.expect("checked-in compiler A"),
)
.expect("compiler A JSON");
for (path, kind) in [
("language/examples/MINIMUM-PROTOCOL.tcs", "PROTOCOL"),
("language/events/ZY-LIMB-002-TRAINING-20260821.tcs", "EVENT"),
("language/examples/MINIMUM-RECEIPT.tcs", "RECEIPT"),
] {
let gir =
tcs_gir_runtime::compile_with_compiler_gir(&compiler_a, &declaration_source(path))
.expect("self-hosted compiler lowers declaration");
assert_eq!(gir["schema"], "guanghu.declaration-gir/v1");
assert_eq!(gir["identity"]["declaration_kind"], kind);
assert_eq!(gir["executable"], false);
assert_eq!(gir["natural_language_is_typed_data"], true);
assert_eq!(gir["unresolved_natural_language"], false);
assert_eq!(gir["native_self_hosted"], true);
}
}