This repository has been archived on 2026-08-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
el-retired/dharma/tests/internal_state/test_body_contains_key.el
T
Will Anderson 90ddbdbfc3 feat: port arbor, dharma, forge El source into monorepo
Brings the remaining foundation repos that were not included in the
original monorepo consolidation:

- arbor/vessels/ — 6 vessels (arbor-cli, arbor-core, arbor-diagram,
  arbor-layout, arbor-parse, arbor-render) with manifests + src/main.el
- dharma/ — CGI Provenance Registry package (flat layout, 14 .el files
  across registry/, sandbox/, training/, validation/, tests/)
- forge/ — consciousness channel tool (8 src .el files + new manifest.el)
- elp/src/ — 36 test fixture files not carried over in original merge
  (dedup_*, realizer_*, semantics_*, morph_*, ext_*, one_extern_* helpers)

el-ide, engram, elql are already complete in ide/, engram/, ql/.
2026-05-05 04:27:34 -05:00

57 lines
2.1 KiB
EmacsLisp

// test_body_contains_key.el verifies body_contains_key correctly
// distinguishes "user asserted this field" from "user did not mention it".
// This is the gate the PATCH endpoint uses to enforce immutability.
fn body_contains_key(body: String, key: String) -> Bool {
return str_contains(body, "\"" + key + "\":")
}
fn assert_true(name: String, got: Bool) -> Bool {
if got {
println("PASS " + name)
return true
}
println("FAIL " + name + " want=true got=false")
return false
}
fn assert_false(name: String, got: Bool) -> Bool {
if got {
println("FAIL " + name + " want=false got=true")
return false
}
println("PASS " + name)
return true
}
fn main() -> Void {
let b1: String = "{\"post_reasoning\":\"x\"}"
assert_true("present-non-empty", body_contains_key(b1, "post_reasoning"))
// Empty value still counts as "asserted" user mentioned the key.
let b2: String = "{\"post_reasoning\":\"\"}"
assert_true("present-empty-string", body_contains_key(b2, "post_reasoning"))
// Key absent.
let b3: String = "{\"gap_summary\":\"x\"}"
assert_false("absent", body_contains_key(b3, "post_reasoning"))
// Substring of another key must NOT match.
// E.g. "tags": vs "tag": distinct.
let b4: String = "{\"tags\":\"a,b,c\"}"
assert_false("substring-distinct", body_contains_key(b4, "tag"))
assert_true("exact-tags", body_contains_key(b4, "tags"))
// Immutable-field detection: PATCH must reject these.
let b5: String = "{\"pre_reasoning\":\"new value\",\"post_reasoning\":\"x\"}"
assert_true("detect-pre_reasoning", body_contains_key(b5, "pre_reasoning"))
assert_true("detect-post_reasoning", body_contains_key(b5, "post_reasoning"))
let b6: String = "{\"cgi_id\":\"x\"}"
assert_true("detect-cgi_id", body_contains_key(b6, "cgi_id"))
// No false-positive if the value happens to contain the same string.
let b7: String = "{\"trigger\":\"contained pre_reasoning string\"}"
assert_false("no-false-positive-from-value", body_contains_key(b7, "pre_reasoning"))
}