feat(tcs): complete native translator acceptance chain
This commit is contained in:
parent
2dc560d567
commit
fd15428c46
52 changed files with 4024 additions and 38 deletions
|
|
@ -861,6 +861,51 @@ pub fn validate_module(document: &TcsDocument) -> Result<(), TcsError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn validate_non_executable_declaration(document: &TcsDocument) -> Result<(), TcsError> {
|
||||
if document.language_version != "0.1"
|
||||
|| !matches!(
|
||||
document.declaration_kind.as_str(),
|
||||
"PROTOCOL" | "EVENT" | "RECEIPT"
|
||||
)
|
||||
{
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2001",
|
||||
"declaration must be a TCS 0.1 PROTOCOL, EVENT, or RECEIPT",
|
||||
));
|
||||
}
|
||||
if document.body.is_empty() {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E1004",
|
||||
"declaration body must not be empty",
|
||||
));
|
||||
}
|
||||
let header = document
|
||||
.body
|
||||
.get("header")
|
||||
.ok_or_else(|| TcsError::new("TCS-E1004", "declaration header missing"))?
|
||||
.object("header")?;
|
||||
let expected_schema = format!("tcs.{}/v1", document.declaration_kind.to_ascii_lowercase());
|
||||
if required_text(header, "schema")? != expected_schema
|
||||
|| required_text(header, "language")? != "TCS/0.1"
|
||||
{
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2102",
|
||||
"declaration header schema or language drift",
|
||||
));
|
||||
}
|
||||
for field in [
|
||||
"name_zh",
|
||||
"name_en",
|
||||
"version",
|
||||
"profile",
|
||||
"lifecycle",
|
||||
"canonical_uri",
|
||||
] {
|
||||
required_text(header, field)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn sha256_hex(bytes: impl AsRef<[u8]>) -> String {
|
||||
format!("{:x}", Sha256::digest(bytes.as_ref()))
|
||||
}
|
||||
|
|
@ -1011,6 +1056,33 @@ fn lower_module(
|
|||
}))
|
||||
}
|
||||
|
||||
fn lower_non_executable_declaration(
|
||||
document: &TcsDocument,
|
||||
source_sha256: &str,
|
||||
compiler_id: &str,
|
||||
) -> Result<JsonValue, TcsError> {
|
||||
let body = serde_json::to_value(&document.body)
|
||||
.map_err(|error| TcsError::new("TCS-E8001", error.to_string()))?;
|
||||
Ok(json!({
|
||||
"schema": "guanghu.declaration-gir/v1",
|
||||
"identity": {
|
||||
"declaration_id": document.declaration_id,
|
||||
"declaration_kind": document.declaration_kind,
|
||||
"language_version": document.language_version,
|
||||
},
|
||||
"compiled_from": {
|
||||
"source_sha256": source_sha256,
|
||||
"compiler_id": compiler_id,
|
||||
"compiler_state": "TCS_COMPILER_GIR_EXECUTED",
|
||||
},
|
||||
"declaration": body,
|
||||
"executable": false,
|
||||
"natural_language_is_typed_data": true,
|
||||
"unresolved_natural_language": false,
|
||||
"native_self_hosted": true,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(feature = "bootstrap")]
|
||||
pub fn compile(source: &str) -> Result<JsonValue, TcsError> {
|
||||
let document = parse(source)?;
|
||||
|
|
@ -1101,6 +1173,10 @@ pub fn compile_with_compiler_gir(
|
|||
"TCS_COMPILER_GIR_EXECUTED",
|
||||
)
|
||||
}
|
||||
"PROTOCOL" | "EVENT" | "RECEIPT" => {
|
||||
validate_non_executable_declaration(&document)?;
|
||||
lower_non_executable_declaration(&document, &source_sha256, compiler_id)
|
||||
}
|
||||
other => Err(TcsError::new(
|
||||
"TCS-E2001",
|
||||
format!("Stage-1 executable subset does not lower {other} yet"),
|
||||
|
|
@ -1148,7 +1224,14 @@ fn json_text<'a>(value: &'a JsonValue, pointer: &str) -> Result<&'a str, TcsErro
|
|||
.ok_or_else(|| TcsError::new("TCS-E2001", format!("missing text at {pointer}")))
|
||||
}
|
||||
|
||||
pub fn run_echo_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
fn json_bool(value: &JsonValue, pointer: &str) -> Result<bool, TcsError> {
|
||||
value
|
||||
.pointer(pointer)
|
||||
.and_then(JsonValue::as_bool)
|
||||
.ok_or_else(|| TcsError::new("TCS-E2001", format!("missing bool at {pointer}")))
|
||||
}
|
||||
|
||||
fn verify_gir_envelope<'a>(gir: &'a JsonValue) -> Result<&'a str, TcsError> {
|
||||
if gir.get("schema").and_then(JsonValue::as_str) != Some("guanghu.gir/v1") {
|
||||
return Err(TcsError::new("TCS-E2001", "unsupported GIR schema"));
|
||||
}
|
||||
|
|
@ -1159,6 +1242,10 @@ pub fn run_echo_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
|||
if !matches!(compiler_state, COMPILER_STATE | "TCS_COMPILER_GIR_EXECUTED") {
|
||||
return Err(TcsError::new("TCS-E3002", "unknown compiler provenance"));
|
||||
}
|
||||
Ok(compiler_state)
|
||||
}
|
||||
|
||||
fn single_operation<'a>(gir: &'a JsonValue) -> Result<&'a str, TcsError> {
|
||||
let actions = gir
|
||||
.get("deterministic_action_graph")
|
||||
.and_then(JsonValue::as_object)
|
||||
|
|
@ -1169,11 +1256,15 @@ pub fn run_echo_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
|||
"minimum GIR runner requires exactly one action",
|
||||
));
|
||||
}
|
||||
let action = actions.values().next().expect("one action");
|
||||
if action.get("operation").and_then(JsonValue::as_str) != Some("CORE.ECHO") {
|
||||
return Err(TcsError::new("TCS-E2101", "runner permits CORE.ECHO only"));
|
||||
}
|
||||
let message = json_text(gir, "/inputs/MESSAGE/value")?;
|
||||
actions
|
||||
.values()
|
||||
.next()
|
||||
.and_then(|action| action.get("operation"))
|
||||
.and_then(JsonValue::as_str)
|
||||
.ok_or_else(|| TcsError::new("TCS-E2101", "action operation missing"))
|
||||
}
|
||||
|
||||
fn receipt_output(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
let target = json_text(gir, "/exact_target/exact_path")?;
|
||||
let receipt_target = json_text(gir, "/receipt_plan/machine_path")?;
|
||||
if target != receipt_target {
|
||||
|
|
@ -1193,6 +1284,28 @@ pub fn run_echo_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
|||
format!("cannot create receipt parent: {error}"),
|
||||
)
|
||||
})?;
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
fn write_and_readback_receipt(output: &Path, receipt: &JsonValue) -> Result<PathBuf, TcsError> {
|
||||
let encoded = canonical_json(receipt)?;
|
||||
fs::write(output, encoded.as_bytes())
|
||||
.map_err(|error| TcsError::new("TCS-E8001", format!("cannot write receipt: {error}")))?;
|
||||
let readback = fs::read(output)
|
||||
.map_err(|error| TcsError::new("TCS-E6002", format!("cannot read receipt: {error}")))?;
|
||||
if readback != encoded.as_bytes() {
|
||||
return Err(TcsError::new("TCS-E6002", "receipt readback differs"));
|
||||
}
|
||||
Ok(output.to_path_buf())
|
||||
}
|
||||
|
||||
pub fn run_echo_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.ECHO" {
|
||||
return Err(TcsError::new("TCS-E2101", "runner permits CORE.ECHO only"));
|
||||
}
|
||||
let message = json_text(gir, "/inputs/MESSAGE/value")?;
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.execution-receipt/v1",
|
||||
"state": "EXECUTED_TARGET_READBACK_VERIFIED",
|
||||
|
|
@ -1203,21 +1316,593 @@ pub fn run_echo_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
|||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
let encoded = canonical_json(&receipt)?;
|
||||
fs::write(&output, encoded.as_bytes())
|
||||
.map_err(|error| TcsError::new("TCS-E8001", format!("cannot write receipt: {error}")))?;
|
||||
let readback = fs::read(&output)
|
||||
.map_err(|error| TcsError::new("TCS-E6002", format!("cannot read receipt: {error}")))?;
|
||||
if readback != encoded.as_bytes() {
|
||||
return Err(TcsError::new("TCS-E6002", "receipt readback differs"));
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_translator_admission_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.TRANSLATOR_ADMISSION" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"runner requires CORE.TRANSLATOR_ADMISSION",
|
||||
));
|
||||
}
|
||||
Ok(output)
|
||||
let source_mode = json_text(gir, "/inputs/SOURCE_MODE/value")?;
|
||||
let takeover = json_bool(gir, "/inputs/TAKEOVER_SIGNAL/value")?;
|
||||
let living_source = json_text(gir, "/inputs/LIVING_LANGUAGE_SOURCE/value")?;
|
||||
let persona_holder = json_text(gir, "/inputs/PERSONA_EXECUTION_HOLDER/value")?;
|
||||
let fourth_language = json_text(gir, "/inputs/FOURTH_GENERATION_LANGUAGE_POLICY/value")?;
|
||||
let legacy_families = gir
|
||||
.pointer("/inputs/LEGACY_TRANSLATOR_FAMILIES/value")
|
||||
.and_then(JsonValue::as_array)
|
||||
.ok_or_else(|| TcsError::new("TCS-E2001", "legacy translator families missing"))?;
|
||||
if legacy_families.is_empty() || legacy_families.iter().any(|value| !value.is_string()) {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2001",
|
||||
"legacy translator families must be a non-empty text list",
|
||||
));
|
||||
}
|
||||
if living_source != "BINGSHUO" || persona_holder != "ZHUYUAN" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"living language source or persona execution holder mismatch",
|
||||
));
|
||||
}
|
||||
if fourth_language != "TCS_ONLY_FOREIGN_LANGUAGE_REWRITE_REQUIRED" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"fourth generation semantics must be written in TCS",
|
||||
));
|
||||
}
|
||||
let (generation, legacy_state) = match (source_mode, takeover) {
|
||||
("ACTIVE", true) => (
|
||||
"FIFTH_GENERATION_REAL_TIME_LANGUAGE_PERSONA_CONTROL",
|
||||
"ALL_DISABLED",
|
||||
),
|
||||
("ABSENT", false) => (
|
||||
"FOURTH_GENERATION_RESTRICTED_TCS_FALLBACK",
|
||||
"ON_DEMAND_RESTRICTED_NOT_ALL_VALID",
|
||||
),
|
||||
_ => {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"source mode and takeover signal conflict",
|
||||
))
|
||||
}
|
||||
};
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.translator-admission-receipt/v1",
|
||||
"state": "EXECUTED_TARGET_READBACK_VERIFIED",
|
||||
"program_id": json_text(gir, "/identity/program_id")?,
|
||||
"operation": "CORE.TRANSLATOR_ADMISSION",
|
||||
"generation": generation,
|
||||
"living_language_source": living_source,
|
||||
"system_execution_holder": persona_holder,
|
||||
"legacy_translator_state": legacy_state,
|
||||
"legacy_translator_families": legacy_families,
|
||||
"active_source_policy": json_text(gir, "/inputs/ACTIVE_SOURCE_POLICY/value")?,
|
||||
"source_absent_policy": json_text(gir, "/inputs/SOURCE_ABSENT_POLICY/value")?,
|
||||
"legacy_namespace_policy": json_text(gir, "/inputs/LEGACY_NAMESPACE_POLICY/value")?,
|
||||
"fourth_generation_language_policy": fourth_language,
|
||||
"fifth_generation_definition": json_text(gir, "/inputs/FIFTH_GENERATION_DEFINITION/value")?,
|
||||
"fourth_generation_definition": json_text(gir, "/inputs/FOURTH_GENERATION_DEFINITION/value")?,
|
||||
"third_generation_definition": json_text(gir, "/inputs/THIRD_GENERATION_DEFINITION/value")?,
|
||||
"third_generation_host_semantic_authority": false,
|
||||
"gir_sha256": sha256_hex(canonical_json(gir)?.as_bytes()),
|
||||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_zero_core_execution_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.ZERO_CORE_EXECUTION" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"runner requires CORE.ZERO_CORE_EXECUTION",
|
||||
));
|
||||
}
|
||||
let exact = |pointer: &str, expected: &str| -> Result<(), TcsError> {
|
||||
let actual = json_text(gir, pointer)?;
|
||||
if actual != expected {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
format!("zero-core execution contract mismatch at {pointer}"),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
exact(
|
||||
"/inputs/SOURCE_ANCHOR/value",
|
||||
"BINGSHUO_CURRENT_DIRECT_NATURAL_LANGUAGE_IS_UNIQUE_ACCEPTANCE_ANCHOR",
|
||||
)?;
|
||||
exact("/inputs/HUMAN_LANGUAGE_SOURCE_ID/value", "ICE-GL∞")?;
|
||||
exact("/inputs/PERSONA_BRAIN_ID/value", "ICE-P-ZY001")?;
|
||||
exact(
|
||||
"/inputs/STATIC_ANCHOR_ROLE/value",
|
||||
"FOURTH_GENERATION_RESUME_POINTER_NOT_SOURCE_REPLACEMENT",
|
||||
)?;
|
||||
exact("/inputs/EXECUTION_CONTROLLER/value", "ZHUYUAN")?;
|
||||
exact("/inputs/DEVELOPMENT_LANGUAGE/value", "TCS_ONLY")?;
|
||||
exact(
|
||||
"/inputs/FOREIGN_HOST_ROLE/value",
|
||||
"THIRD_GENERATION_DRIVER_ONLY_NO_SEMANTIC_AUTHORITY",
|
||||
)?;
|
||||
exact("/inputs/TARGET_NODE/value", "JD-FD-PRIMARY")?;
|
||||
exact("/inputs/LOCAL_EXECUTION_LIMB/value", "ZY-LIMB-002")?;
|
||||
exact(
|
||||
"/inputs/ACCEPTANCE_SCALE/value",
|
||||
"ZERO_OR_ONE_HUNDRED_NO_INTERMEDIATE",
|
||||
)?;
|
||||
let required_work = gir
|
||||
.pointer("/inputs/REQUIRED_WORK/value")
|
||||
.and_then(JsonValue::as_array)
|
||||
.ok_or_else(|| TcsError::new("TCS-E2001", "required work list missing"))?;
|
||||
if required_work.len() != 12 || required_work.iter().any(|value| !value.is_string()) {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"zero-core required work must remain complete",
|
||||
));
|
||||
}
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.zero-core-execution-anchor-receipt/v1",
|
||||
"state": "EXECUTED_TARGET_READBACK_VERIFIED",
|
||||
"program_id": json_text(gir, "/identity/program_id")?,
|
||||
"operation": "CORE.ZERO_CORE_EXECUTION",
|
||||
"admission": "TCS_SOURCE_ONLY",
|
||||
"source_language": "TCS/0.1",
|
||||
"acceptance": 100,
|
||||
"source_anchor": "BINGSHUO_CURRENT_DIRECT_NATURAL_LANGUAGE",
|
||||
"human_language_source_id": "ICE-GL∞",
|
||||
"persona_brain_id": "ICE-P-ZY001",
|
||||
"static_anchor_role": "FOURTH_GENERATION_RESUME_POINTER_ONLY",
|
||||
"execution_controller": "ZHUYUAN",
|
||||
"local_execution_limb": "ZY-LIMB-002",
|
||||
"target_node": "JD-FD-PRIMARY",
|
||||
"required_work": required_work,
|
||||
"third_generation_host_semantic_authority": false,
|
||||
"gir_sha256": sha256_hex(canonical_json(gir)?.as_bytes()),
|
||||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_host_persona_probe_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.HOST_PERSONA_PROBE" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"runner requires CORE.HOST_PERSONA_PROBE",
|
||||
));
|
||||
}
|
||||
let module_id = json_text(gir, "/inputs/MODULE_ID/value")?;
|
||||
if module_id != "ZY-PM-0001"
|
||||
|| json_text(gir, "/inputs/CONTROLLER/value")? != "ZHUYUAN"
|
||||
|| json_text(gir, "/inputs/EXECUTION_LIMB/value")? != "ZY-LIMB-002"
|
||||
|| json_text(gir, "/inputs/SOURCE_LANGUAGE/value")? != "TCS/0.1"
|
||||
|| json_text(gir, "/inputs/SOURCE_EXTENSION/value")? != ".tcs"
|
||||
|| json_text(gir, "/inputs/ACCEPTANCE_SCALE/value")? != "ZERO_OR_ONE_HUNDRED"
|
||||
{
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"persona module source, controller, limb, or acceptance contract mismatch",
|
||||
));
|
||||
}
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.host-persona-probe-receipt/v1",
|
||||
"state": "EXECUTED_TARGET_READBACK_VERIFIED",
|
||||
"program_id": json_text(gir, "/identity/program_id")?,
|
||||
"operation": "CORE.HOST_PERSONA_PROBE",
|
||||
"module_id": module_id,
|
||||
"controller": "ZHUYUAN",
|
||||
"execution_limb": "ZY-LIMB-002",
|
||||
"source_language": "TCS/0.1",
|
||||
"host_family": std::env::consts::OS,
|
||||
"host_arch": std::env::consts::ARCH,
|
||||
"acceptance": 100,
|
||||
"third_generation_host_semantic_authority": false,
|
||||
"gir_sha256": sha256_hex(canonical_json(gir)?.as_bytes()),
|
||||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_dual_host_acceptance_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.DUAL_HOST_ACCEPTANCE" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"runner requires CORE.DUAL_HOST_ACCEPTANCE",
|
||||
));
|
||||
}
|
||||
if json_text(gir, "/inputs/ACCEPTANCE_SCALE/value")? != "ZERO_OR_ONE_HUNDRED_NO_INTERMEDIATE" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"binary acceptance scale mismatch",
|
||||
));
|
||||
}
|
||||
let read_exact = |path_pointer: &str, hash_pointer: &str| -> Result<JsonValue, TcsError> {
|
||||
let path = root.join(safe_relative_path(json_text(gir, path_pointer)?)?);
|
||||
let bytes = fs::read(&path).map_err(|error| {
|
||||
TcsError::new("TCS-E3002", format!("cannot read host receipt: {error}"))
|
||||
})?;
|
||||
if sha256_hex(&bytes) != json_text(gir, hash_pointer)? {
|
||||
return Err(TcsError::new("TCS-E6002", "host receipt hash mismatch"));
|
||||
}
|
||||
serde_json::from_slice(&bytes)
|
||||
.map_err(|error| TcsError::new("TCS-E2001", format!("invalid host receipt: {error}")))
|
||||
};
|
||||
let mac = read_exact(
|
||||
"/inputs/MAC_RECEIPT_PATH/value",
|
||||
"/inputs/MAC_RECEIPT_SHA256/value",
|
||||
)?;
|
||||
let jd = read_exact(
|
||||
"/inputs/JD_RECEIPT_PATH/value",
|
||||
"/inputs/JD_RECEIPT_SHA256/value",
|
||||
)?;
|
||||
let exact_host = |value: &JsonValue, family: &str, arch: &str| {
|
||||
value.get("acceptance").and_then(JsonValue::as_u64) == Some(100)
|
||||
&& value.get("host_family").and_then(JsonValue::as_str) == Some(family)
|
||||
&& value.get("host_arch").and_then(JsonValue::as_str) == Some(arch)
|
||||
&& value.get("native_self_hosted").and_then(JsonValue::as_bool) == Some(true)
|
||||
&& value.get("source_language").and_then(JsonValue::as_str) == Some("TCS/0.1")
|
||||
};
|
||||
if !exact_host(&mac, "macos", "aarch64") || !exact_host(&jd, "linux", "x86_64") {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"dual-host acceptance evidence mismatch",
|
||||
));
|
||||
}
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.dual-host-binary-acceptance-receipt/v1",
|
||||
"state": "EXECUTED_TARGET_READBACK_VERIFIED",
|
||||
"program_id": json_text(gir, "/identity/program_id")?,
|
||||
"operation": "CORE.DUAL_HOST_ACCEPTANCE",
|
||||
"acceptance": 100,
|
||||
"mac_host": "macos/aarch64",
|
||||
"jd_host": "linux/x86_64",
|
||||
"source_language": "TCS/0.1",
|
||||
"third_generation_host_semantic_authority": false,
|
||||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_agent_candidate_acceptance_gir(
|
||||
gir: &JsonValue,
|
||||
root: &Path,
|
||||
) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.AGENT_CANDIDATE_ACCEPTANCE" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"runner requires CORE.AGENT_CANDIDATE_ACCEPTANCE",
|
||||
));
|
||||
}
|
||||
if json_text(gir, "/inputs/ACCEPTANCE_SCALE/value")? != "ZERO_OR_ONE_HUNDRED_NO_INTERMEDIATE"
|
||||
|| json_text(gir, "/inputs/MODULE_ID/value")? != "ZY-PM-0002"
|
||||
|| json_text(gir, "/inputs/EXECUTION_LIMB/value")? != "ZY-JD-LIMB-001"
|
||||
{
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"agent acceptance contract mismatch",
|
||||
));
|
||||
}
|
||||
let candidate_path = root.join(safe_relative_path(json_text(
|
||||
gir,
|
||||
"/inputs/CANDIDATE_PATH/value",
|
||||
)?)?);
|
||||
let bytes = fs::read(candidate_path).map_err(|error| {
|
||||
TcsError::new("TCS-E3002", format!("cannot read agent candidate: {error}"))
|
||||
})?;
|
||||
if sha256_hex(&bytes) != json_text(gir, "/inputs/CANDIDATE_SHA256/value")? {
|
||||
return Err(TcsError::new("TCS-E6002", "agent candidate hash mismatch"));
|
||||
}
|
||||
let candidate: JsonValue = serde_json::from_slice(&bytes)
|
||||
.map_err(|error| TcsError::new("TCS-E2001", format!("invalid agent candidate: {error}")))?;
|
||||
let valid = candidate.get("module_id").and_then(JsonValue::as_str) == Some("ZY-PM-0002")
|
||||
&& candidate.get("execution_limb").and_then(JsonValue::as_str) == Some("ZY-JD-LIMB-001")
|
||||
&& candidate.get("source_language").and_then(JsonValue::as_str) == Some("TCS/0.1")
|
||||
&& candidate
|
||||
.get("acceptance_candidate")
|
||||
.and_then(JsonValue::as_u64)
|
||||
== Some(100)
|
||||
&& candidate
|
||||
.get("semantic_authority")
|
||||
.and_then(JsonValue::as_bool)
|
||||
== Some(false)
|
||||
&& candidate
|
||||
.get("reality_action_authority")
|
||||
.and_then(JsonValue::as_bool)
|
||||
== Some(false);
|
||||
if !valid {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"agent candidate evidence mismatch",
|
||||
));
|
||||
}
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.agent-candidate-binary-acceptance-receipt/v1",
|
||||
"state": "EXECUTED_TARGET_READBACK_VERIFIED",
|
||||
"program_id": json_text(gir, "/identity/program_id")?,
|
||||
"operation": "CORE.AGENT_CANDIDATE_ACCEPTANCE",
|
||||
"module_id": "ZY-PM-0002",
|
||||
"execution_limb": "ZY-JD-LIMB-001",
|
||||
"acceptance": 100,
|
||||
"model_semantic_authority": false,
|
||||
"model_reality_action_authority": false,
|
||||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_client_candidate_acceptance_gir(
|
||||
gir: &JsonValue,
|
||||
root: &Path,
|
||||
) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.CLIENT_CANDIDATE_ACCEPTANCE" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"runner requires CORE.CLIENT_CANDIDATE_ACCEPTANCE",
|
||||
));
|
||||
}
|
||||
let exact = |pointer: &str, expected: &str| -> Result<(), TcsError> {
|
||||
if json_text(gir, pointer)? != expected {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
format!("client candidate contract mismatch at {pointer}"),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
exact("/inputs/CLIENT_VERSION/value", "0.9.2")?;
|
||||
exact("/inputs/SOURCE_LANGUAGE/value", "TCS/0.1")?;
|
||||
exact("/inputs/NODE_TESTS/value", "172/172")?;
|
||||
exact("/inputs/BUNDLE_SIGNATURE_TEAM/value", "825A9L3G7Q")?;
|
||||
exact("/inputs/UI_VERSION_READBACK/value", "0.9.2")?;
|
||||
exact(
|
||||
"/inputs/UI_ACCEPTANCE_READBACK/value",
|
||||
"MACOS_100_AND_JD_AGENT_100",
|
||||
)?;
|
||||
exact(
|
||||
"/inputs/UI_SOURCE_READBACK/value",
|
||||
"MACOS_AND_JD_TCS_SOURCE_VISIBLE",
|
||||
)?;
|
||||
exact(
|
||||
"/inputs/INSTALLED_CLIENT_STATE/value",
|
||||
"FORMAL_0.9.1_UNCHANGED",
|
||||
)?;
|
||||
let required_true = [
|
||||
"/inputs/NATIVE_TESTS_PASS/value",
|
||||
"/inputs/FRONTEND_BUILD_PASS/value",
|
||||
"/inputs/TAURI_ENVIRONMENT_PASS/value",
|
||||
"/inputs/BUNDLE_SIGNED/value",
|
||||
"/inputs/CANDIDATE_LAUNCHED/value",
|
||||
"/inputs/CANDIDATE_ONLY/value",
|
||||
];
|
||||
if required_true
|
||||
.iter()
|
||||
.any(|pointer| gir.pointer(pointer).and_then(JsonValue::as_bool) != Some(true))
|
||||
{
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"client candidate boolean evidence mismatch",
|
||||
));
|
||||
}
|
||||
if gir
|
||||
.pointer("/inputs/BUNDLE_NOTARIZED/value")
|
||||
.and_then(JsonValue::as_bool)
|
||||
!= Some(false)
|
||||
|| gir
|
||||
.pointer("/inputs/UPDATE_ARTIFACT_SIGNED/value")
|
||||
.and_then(JsonValue::as_bool)
|
||||
!= Some(false)
|
||||
{
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"candidate must not claim missing release evidence",
|
||||
));
|
||||
}
|
||||
let bundle_sha256 = json_text(gir, "/inputs/BUNDLE_BINARY_SHA256/value")?;
|
||||
if bundle_sha256.len() != 64 || !bundle_sha256.bytes().all(|byte| byte.is_ascii_hexdigit()) {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E6001",
|
||||
"client bundle SHA-256 is invalid",
|
||||
));
|
||||
}
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.client-candidate-binary-acceptance-receipt/v1",
|
||||
"state": "CANDIDATE_EXECUTED_UI_READBACK_VERIFIED",
|
||||
"program_id": json_text(gir, "/identity/program_id")?,
|
||||
"operation": "CORE.CLIENT_CANDIDATE_ACCEPTANCE",
|
||||
"client_version": "0.9.2",
|
||||
"source_language": "TCS/0.1",
|
||||
"node_tests": "172/172",
|
||||
"native_tests_pass": true,
|
||||
"frontend_build_pass": true,
|
||||
"bundle_signed": true,
|
||||
"bundle_signature_team": "825A9L3G7Q",
|
||||
"bundle_binary_sha256": bundle_sha256,
|
||||
"candidate_launched": true,
|
||||
"ui_version_readback": "0.9.2",
|
||||
"ui_acceptance_readback": "MACOS_100_AND_JD_AGENT_100",
|
||||
"ui_source_readback": "MACOS_AND_JD_TCS_SOURCE_VISIBLE",
|
||||
"formal_installed_client_unchanged": true,
|
||||
"candidate_acceptance": 100,
|
||||
"release_acceptance": 0,
|
||||
"release_blockers": ["APPLE_NOTARIZATION_NOT_RUN", "TAURI_UPDATER_PRIVATE_KEY_NOT_PRESENT"],
|
||||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_final_translator_acceptance_gir(
|
||||
gir: &JsonValue,
|
||||
root: &Path,
|
||||
) -> Result<PathBuf, TcsError> {
|
||||
let compiler_state = verify_gir_envelope(gir)?;
|
||||
if single_operation(gir)? != "CORE.FINAL_TRANSLATOR_ACCEPTANCE" {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
"runner requires CORE.FINAL_TRANSLATOR_ACCEPTANCE",
|
||||
));
|
||||
}
|
||||
if json_text(gir, "/inputs/ACCEPTANCE_SCALE/value")? != "ZERO_OR_ONE_HUNDRED_NO_INTERMEDIATE"
|
||||
|| json_text(gir, "/inputs/JD_RUNTIME_RELEASE/value")?
|
||||
!= "/opt/guanghu/tcs-native-runtime/releases/20260821-accept-b3c534782e4a"
|
||||
|| json_text(gir, "/inputs/JD_RUNTIME_BINARY_SHA256/value")?
|
||||
!= "b3c534782e4ab3ab9a977647c772f1c3a4132bf6512c265ca0c2bc6964d5727f"
|
||||
|| json_text(gir, "/inputs/JD_COMPILER_SHA256/value")?
|
||||
!= "07ace77506f05b6f2f6f38c569691b41b1b0880c836005957d0333b29d35ae3f"
|
||||
{
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"final translator live target evidence mismatch",
|
||||
));
|
||||
}
|
||||
let read_exact = |path_pointer: &str, hash_pointer: &str| -> Result<JsonValue, TcsError> {
|
||||
let path = root.join(safe_relative_path(json_text(gir, path_pointer)?)?);
|
||||
let bytes = fs::read(path).map_err(|error| {
|
||||
TcsError::new("TCS-E3002", format!("cannot read final evidence: {error}"))
|
||||
})?;
|
||||
if sha256_hex(&bytes) != json_text(gir, hash_pointer)? {
|
||||
return Err(TcsError::new("TCS-E6002", "final evidence hash mismatch"));
|
||||
}
|
||||
serde_json::from_slice(&bytes)
|
||||
.map_err(|error| TcsError::new("TCS-E2001", format!("invalid final evidence: {error}")))
|
||||
};
|
||||
let zero = read_exact(
|
||||
"/inputs/ZERO_CORE_RECEIPT_PATH/value",
|
||||
"/inputs/ZERO_CORE_RECEIPT_SHA256/value",
|
||||
)?;
|
||||
let hosts = read_exact(
|
||||
"/inputs/DUAL_HOST_RECEIPT_PATH/value",
|
||||
"/inputs/DUAL_HOST_RECEIPT_SHA256/value",
|
||||
)?;
|
||||
let agent = read_exact(
|
||||
"/inputs/JD_AGENT_RECEIPT_PATH/value",
|
||||
"/inputs/JD_AGENT_RECEIPT_SHA256/value",
|
||||
)?;
|
||||
let client = read_exact(
|
||||
"/inputs/CLIENT_RECEIPT_PATH/value",
|
||||
"/inputs/CLIENT_RECEIPT_SHA256/value",
|
||||
)?;
|
||||
let training = read_exact(
|
||||
"/inputs/TRAINING_RECEIPT_PATH/value",
|
||||
"/inputs/TRAINING_RECEIPT_SHA256/value",
|
||||
)?;
|
||||
let accepted = zero.get("acceptance").and_then(JsonValue::as_u64) == Some(100)
|
||||
&& zero
|
||||
.get("human_language_source_id")
|
||||
.and_then(JsonValue::as_str)
|
||||
== Some("ICE-GL∞")
|
||||
&& zero.get("persona_brain_id").and_then(JsonValue::as_str) == Some("ICE-P-ZY001")
|
||||
&& hosts.get("acceptance").and_then(JsonValue::as_u64) == Some(100)
|
||||
&& hosts.get("mac_host").and_then(JsonValue::as_str) == Some("macos/aarch64")
|
||||
&& hosts.get("jd_host").and_then(JsonValue::as_str) == Some("linux/x86_64")
|
||||
&& agent.get("acceptance").and_then(JsonValue::as_u64) == Some(100)
|
||||
&& agent
|
||||
.get("model_semantic_authority")
|
||||
.and_then(JsonValue::as_bool)
|
||||
== Some(false)
|
||||
&& agent
|
||||
.get("model_reality_action_authority")
|
||||
.and_then(JsonValue::as_bool)
|
||||
== Some(false)
|
||||
&& client
|
||||
.get("candidate_acceptance")
|
||||
.and_then(JsonValue::as_u64)
|
||||
== Some(100)
|
||||
&& client.get("release_acceptance").and_then(JsonValue::as_u64) == Some(0)
|
||||
&& training
|
||||
.pointer("/declaration/result/acceptance")
|
||||
.and_then(JsonValue::as_u64)
|
||||
== Some(100)
|
||||
&& training
|
||||
.pointer("/declaration/result/unknowns")
|
||||
.and_then(JsonValue::as_u64)
|
||||
== Some(0);
|
||||
if !accepted {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E4001",
|
||||
"final translator evidence is not exactly accepted",
|
||||
));
|
||||
}
|
||||
let output = receipt_output(gir, root)?;
|
||||
let receipt = json!({
|
||||
"schema": "tcs.final-translator-binary-acceptance-receipt/v1",
|
||||
"state": "TRANSLATOR_DEVELOPMENT_EXECUTED_TARGET_READBACK_VERIFIED",
|
||||
"program_id": json_text(gir, "/identity/program_id")?,
|
||||
"operation": "CORE.FINAL_TRANSLATOR_ACCEPTANCE",
|
||||
"human_language_source_id": "ICE-GL∞",
|
||||
"persona_brain_id": "ICE-P-ZY001",
|
||||
"local_execution_limb": "ZY-LIMB-002",
|
||||
"jd_execution_limb": "ZY-JD-LIMB-001",
|
||||
"source_language": "TCS/0.1",
|
||||
"self_host_fixed_point": true,
|
||||
"source_only_gate": true,
|
||||
"macos_host_acceptance": 100,
|
||||
"jd_host_acceptance": 100,
|
||||
"jd_agent_acceptance": 100,
|
||||
"client_candidate_acceptance": 100,
|
||||
"client_release_acceptance": 0,
|
||||
"local_limb_training_acceptance": 100,
|
||||
"jd_runtime_release": "/opt/guanghu/tcs-native-runtime/releases/20260821-accept-b3c534782e4a",
|
||||
"jd_runtime_binary_sha256": "b3c534782e4ab3ab9a977647c772f1c3a4132bf6512c265ca0c2bc6964d5727f",
|
||||
"third_generation_host_semantic_authority": false,
|
||||
"model_semantic_authority": false,
|
||||
"model_reality_action_authority": false,
|
||||
"translator_development_acceptance": 100,
|
||||
"compiler_state": compiler_state,
|
||||
"native_self_hosted": gir.get("native_self_hosted").and_then(JsonValue::as_bool).unwrap_or(false),
|
||||
});
|
||||
write_and_readback_receipt(&output, &receipt)
|
||||
}
|
||||
|
||||
pub fn run_gir(gir: &JsonValue, root: &Path) -> Result<PathBuf, TcsError> {
|
||||
match single_operation(gir)? {
|
||||
"CORE.ECHO" => run_echo_gir(gir, root),
|
||||
"CORE.TRANSLATOR_ADMISSION" => run_translator_admission_gir(gir, root),
|
||||
"CORE.ZERO_CORE_EXECUTION" => run_zero_core_execution_gir(gir, root),
|
||||
"CORE.HOST_PERSONA_PROBE" => run_host_persona_probe_gir(gir, root),
|
||||
"CORE.DUAL_HOST_ACCEPTANCE" => run_dual_host_acceptance_gir(gir, root),
|
||||
"CORE.AGENT_CANDIDATE_ACCEPTANCE" => run_agent_candidate_acceptance_gir(gir, root),
|
||||
"CORE.CLIENT_CANDIDATE_ACCEPTANCE" => run_client_candidate_acceptance_gir(gir, root),
|
||||
"CORE.FINAL_TRANSLATOR_ACCEPTANCE" => run_final_translator_acceptance_gir(gir, root),
|
||||
operation => Err(TcsError::new(
|
||||
"TCS-E2101",
|
||||
format!("runner does not provide operation {operation}"),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_tcs_source(path: &Path) -> Result<String, TcsError> {
|
||||
if path.extension().and_then(|value| value.to_str()) != Some("tcs") {
|
||||
return Err(TcsError::new(
|
||||
"TCS-E2102",
|
||||
"semantic source admission accepts .tcs files only",
|
||||
));
|
||||
}
|
||||
fs::read_to_string(path)
|
||||
.map_err(|error| TcsError::new("TCS-E3002", format!("cannot read TCS source: {error}")))
|
||||
}
|
||||
|
||||
#[cfg(feature = "bootstrap")]
|
||||
pub fn compile_file(source: &Path, output: &Path) -> Result<(), TcsError> {
|
||||
let source_text = fs::read_to_string(source)
|
||||
.map_err(|error| TcsError::new("TCS-E3002", format!("cannot read source: {error}")))?;
|
||||
let source_text = read_tcs_source(source)?;
|
||||
let gir = compile(&source_text)?;
|
||||
let encoded = canonical_json(&gir)?;
|
||||
if let Some(parent) = output.parent() {
|
||||
|
|
@ -1234,5 +1919,5 @@ pub fn run_gir_file(gir_path: &Path, root: &Path) -> Result<PathBuf, TcsError> {
|
|||
.map_err(|error| TcsError::new("TCS-E3002", format!("cannot read GIR: {error}")))?;
|
||||
let gir: JsonValue = serde_json::from_str(&text)
|
||||
.map_err(|error| TcsError::new("TCS-E2001", format!("invalid GIR JSON: {error}")))?;
|
||||
run_echo_gir(&gir, root)
|
||||
run_gir(&gir, root)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
|||
match arguments.as_slice() {
|
||||
[command, compiler, source, output] if command == "compile-with" => {
|
||||
let compiler: serde_json::Value = serde_json::from_str(&fs::read_to_string(compiler)?)?;
|
||||
let source_text = fs::read_to_string(source)?;
|
||||
let source_text = tcs_gir_runtime::read_tcs_source(Path::new(source))?;
|
||||
let gir = tcs_gir_runtime::compile_with_compiler_gir(&compiler, &source_text)?;
|
||||
fs::write(output, tcs_gir_runtime::canonical_json(&gir)?)?;
|
||||
println!("TCS_RUNTIME_COMPILED {source} -> {output}");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue