v0.7.2: Merkle audit — audit-verify-hash with hash integrity check — TDD
audit-verify-hash counts total objects and those with missing/empty hashes. /audit verify uses it to report VERIFY PASS or MISSING HASHES count. fboundp-guarded. - core-memory: audit-verify-hash fn, 1 test - channel-tui-main: updated /audit verify handler - Core: 90/90 TUI Main: 102/102
This commit is contained in:
@@ -355,16 +355,16 @@ Event handlers + daemon I/O + main loop.
|
||||
(add-msg :system "No snapshots available"))))
|
||||
;; /audit verify — memory integrity
|
||||
((string-equal text "/audit verify")
|
||||
(let ((count 0) (hashed 0))
|
||||
(maphash (lambda (k v) (declare (ignore k))
|
||||
(when v
|
||||
(incf count)
|
||||
(when (passepartout::memory-object-hash v)
|
||||
(incf hashed))))
|
||||
passepartout::*memory-store*)
|
||||
(add-msg :system (format nil "Audit: ~d objects, ~d hashed, ~d snapshots"
|
||||
count hashed
|
||||
(length passepartout::*memory-snapshots*)))))
|
||||
(if (fboundp 'passepartout::audit-verify-hash)
|
||||
(let* ((result (funcall 'passepartout::audit-verify-hash))
|
||||
(total (car result))
|
||||
(missing (cdr result)))
|
||||
(add-msg :system (format nil "Audit: ~d objects, ~d missing hashes, ~d snapshots~@[ — VERIFY PASS~]~@[ — ~d MISSING HASHES~]"
|
||||
total missing
|
||||
(length passepartout::*memory-snapshots*)
|
||||
(zerop missing)
|
||||
(unless (zerop missing) missing))))
|
||||
(add-msg :system "Memory audit not available")))
|
||||
;; /resume <n> — resume from snapshot
|
||||
((and (>= (length text) 8) (string-equal (subseq text 0 8) "/resume "))
|
||||
(let* ((n-str (string-trim '(#\Space) (subseq text 8)))
|
||||
|
||||
@@ -415,6 +415,20 @@ Restores memory state from a previously saved snapshot file. Called during boot
|
||||
:version (memory-object-version obj)
|
||||
:hash (or (memory-object-hash obj) "(none)")
|
||||
:scope (memory-object-scope obj)))))
|
||||
|
||||
(defun audit-verify-hash ()
|
||||
"Count memory objects and report any with missing/empty hashes.
|
||||
Returns (total . missing-hashes)."
|
||||
(let ((total 0) (missing 0))
|
||||
(maphash (lambda (id obj)
|
||||
(declare (ignore id))
|
||||
(when obj
|
||||
(incf total)
|
||||
(let ((h (memory-object-hash obj)))
|
||||
(when (or (null h) (string= h ""))
|
||||
(incf missing)))))
|
||||
*memory-store*)
|
||||
(cons total missing)))
|
||||
#+end_src
|
||||
|
||||
* Test Suite
|
||||
@@ -542,4 +556,13 @@ Verifies that the Merkle hash is deterministic and consistent across independent
|
||||
(test test-audit-node-not-found
|
||||
"Contract v0.7.2: audit-node returns nil for nonexistent id."
|
||||
(is (null (passepartout::audit-node "nonexistent-xxxx"))))
|
||||
|
||||
(test test-audit-verify-hash
|
||||
"Contract v0.7.2: audit-verify-hash returns (total . missing)."
|
||||
(clrhash passepartout::*memory-store*)
|
||||
(setf (gethash "a" passepartout::*memory-store*)
|
||||
(passepartout::make-memory-object :id "a" :type :HEADLINE :hash "abc"))
|
||||
(let ((result (passepartout::audit-verify-hash)))
|
||||
(is (= 1 (car result)))
|
||||
(is (= 0 (cdr result)))))
|
||||
#+end_src
|
||||
Reference in New Issue
Block a user