From fb09b4666ea20937ff76b441d70f11bd685691d5 Mon Sep 17 00:00:00 2001 From: James Eversole Date: Tue, 5 May 2026 19:16:16 -0500 Subject: [PATCH] Seeded root leaf prep for wire --- AGENTS.md | 8 ++------ src/ContentStore.hs | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 578b11c..f29a66a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -84,13 +84,9 @@ nix flake check # or: nix build .#test | `elimLambdaSingle` | Lambda elimination: eta reduction, SDef binding, semantics preservation | | `stressElimLambda` | Lambda elimination stress test: 200 vars, 800-body curried lambda | -### Adding tests +### Suggesting tests -1. Append a `testCase "Description" $ do ...` block to the appropriate test group in `test/Spec.hs`. -2. Import any modules you need (lexer/parser are available via `runParser` from `Text.Megapparsec`; evaluation via `evalTricu`, `parseTricu`, `result`). -3. Run `nix flake check` to verify. - -> The test-suite in `tricu.cabal` pulls in `src/` as `hs-source-dirs`, so tests import modules directly (e.g., `import Eval`, `import Lexer`). This is intentional — tests exercise the full pipeline end-to-end. +You do not write or modify tests. The user writes tests to constrain your outputs. You must adhere your code to tests or suggest modifications to tests. ## 4. tricu Language Quick Reference diff --git a/src/ContentStore.hs b/src/ContentStore.hs index fd0065c..81e779e 100644 --- a/src/ContentStore.hs +++ b/src/ContentStore.hs @@ -52,6 +52,8 @@ initContentStore = do execute_ conn "CREATE TABLE IF NOT EXISTS merkle_nodes (\ \hash TEXT PRIMARY KEY, \ \node_data BLOB NOT NULL)" + -- Seed canonical Leaf node payload (0x00) + putMerkleNode conn NLeaf return conn getContentStorePath :: IO FilePath @@ -95,13 +97,11 @@ storeTerm conn newNamesStrList term = do -- | Reconstruct a Tree Calculus term from its Merkle root hash. -- Recursively loads nodes and rebuilds the T structure. loadTree :: Connection -> MerkleHash -> IO (Maybe T) -loadTree conn h - | h == nodeHash NLeaf = return (Just Leaf) -- NLeaf is implicit, not stored - | otherwise = do - maybeNode <- getNodeMerkle conn h - case maybeNode of - Nothing -> return Nothing - Just node -> Just <$> buildTree node +loadTree conn h = do + maybeNode <- getNodeMerkle conn h + case maybeNode of + Nothing -> return Nothing + Just node -> Just <$> buildTree node where buildTree :: Node -> IO T buildTree NLeaf = return Leaf @@ -116,7 +116,9 @@ loadTree conn h -- | Store all nodes of a Merkle DAG by traversing the Term and building/storing nodes. -- Returns the hash of the root node. storeMerkleNodes :: Connection -> T -> IO MerkleHash -storeMerkleNodes _ Leaf = return $ nodeHash NLeaf +storeMerkleNodes conn Leaf = do + putMerkleNode conn NLeaf + return $ nodeHash NLeaf storeMerkleNodes conn (Stem t) = do childHash <- storeMerkleNodes conn t let thisNode = NStem childHash