@@ -145,7 +145,10 @@ class TectonixTest : public ::testing::Test
145145 std::unique_ptr<EvalState> state;
146146
147147 TectonixEvalContext (
148- const std::filesystem::path & repoPath, const std::string & commitSha, bool withCheckout = false )
148+ const std::filesystem::path & repoPath,
149+ const std::string & commitSha,
150+ bool withCheckout = false ,
151+ const std::filesystem::path & worldtreeMount = {})
149152 : store(openStore(" dummy://" ))
150153 {
151154 evalSettings.nixPath = {};
@@ -154,6 +157,11 @@ class TectonixTest : public ::testing::Test
154157 if (withCheckout) {
155158 evalSettings.tectonixCheckoutPath = repoPath.string ();
156159 }
160+ if (!worldtreeMount.empty ()) {
161+ // Deliberately nonexistent: historical mode must never connect to it.
162+ evalSettings.tectonixWorldtreeSocket = (repoPath / " unused-worldtree.sock" ).string ();
163+ evalSettings.tectonixWorldtreeMount = worldtreeMount.string ();
164+ }
157165
158166 state = std::make_unique<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr );
159167 }
@@ -172,6 +180,15 @@ class TectonixTest : public ::testing::Test
172180 {
173181 return std::make_unique<TectonixEvalContext>(repoPath, commitSha, withCheckout);
174182 }
183+
184+ std::unique_ptr<TectonixEvalContext> createHistoricalWorldtreeContext (std::string_view manifest)
185+ {
186+ auto mount = repoPath / " worldtree" ;
187+ auto manifestDir = mount / " tecnix" / commitSha / " W-000000" ;
188+ std::filesystem::create_directories (manifestDir);
189+ std::ofstream (manifestDir / " manifest.json" ) << manifest;
190+ return std::make_unique<TectonixEvalContext>(repoPath, commitSha, false , mount);
191+ }
175192};
176193
177194// ============================================================================
@@ -211,6 +228,69 @@ TEST_F(TectonixTest, manifest_returns_path_to_metadata_mapping)
211228 ASSERT_THAT (*coreId->value , IsStringEq (" W-000003" ));
212229}
213230
231+ TEST_F (TectonixTest, historical_worldtree_manifest_and_dirty_set_are_filesystem_only)
232+ {
233+ static constexpr std::string_view historicalManifest = R"( {
234+ "//historical/only": { "id": "W-123456" }
235+ })" ;
236+ auto ctx = createHistoricalWorldtreeContext (historicalManifest);
237+
238+ ASSERT_EQ (ctx->state ->getManifestContent (), historicalManifest);
239+ auto & manifest = ctx->state ->getManifestJson ();
240+ ASSERT_EQ (manifest.size (), 1u );
241+ ASSERT_EQ (manifest.at (" //historical/only" ).at (" id" ), " W-123456" );
242+
243+ auto & dirty = ctx->state ->getTectonixDirtyZones ();
244+ ASSERT_EQ (dirty.size (), 1u );
245+ ASSERT_FALSE (dirty.at (" //historical/only" ).dirty );
246+ }
247+
248+ TEST_F (TectonixTest, historical_worldtree_explains_malformed_manifest)
249+ {
250+ auto ctx = createHistoricalWorldtreeContext (" {" );
251+
252+ try {
253+ ctx->state ->getManifestJson ();
254+ FAIL () << " expected malformed manifest to fail" ;
255+ } catch (const Error & e) {
256+ ASSERT_THAT (e.what (), testing::HasSubstr (" historical World manifest '.meta/manifest.json'" ));
257+ ASSERT_THAT (e.what (), testing::HasSubstr (commitSha));
258+ ASSERT_THAT (e.what (), testing::HasSubstr (" missing or malformed" ));
259+ }
260+ }
261+
262+ TEST_F (TectonixTest, historical_worldtree_explains_missing_manifest)
263+ {
264+ auto mount = repoPath / " worldtree-without-manifest" ;
265+ auto ctx = std::make_unique<TectonixEvalContext>(repoPath, commitSha, false , mount);
266+
267+ try {
268+ ctx->state ->getManifestContent ();
269+ FAIL () << " expected missing manifest to fail" ;
270+ } catch (const Error & e) {
271+ ASSERT_THAT (e.what (), testing::HasSubstr (" historical World manifest '.meta/manifest.json'" ));
272+ ASSERT_THAT (e.what (), testing::HasSubstr (commitSha));
273+ ASSERT_THAT (e.what (), testing::HasSubstr (" missing or malformed" ));
274+ }
275+ }
276+
277+ TEST_F (TectonixTest, historical_worldtree_rejects_noncanonical_revision)
278+ {
279+ auto mount = repoPath / " worldtree" ;
280+ auto ctx = std::make_unique<TectonixEvalContext>(repoPath, " ../escape" , false , mount);
281+
282+ ASSERT_THROW (ctx->state ->getManifestContent (), Error);
283+ }
284+
285+ TEST_F (TectonixTest, historical_worldtree_rejects_noncanonical_zone_id)
286+ {
287+ auto ctx = createHistoricalWorldtreeContext (R"( {
288+ "//historical/only": { "id": "../escape" }
289+ })" );
290+
291+ ASSERT_THROW (ctx->state ->getZoneStorePath (" //historical/only" ), Error);
292+ }
293+
214294// ============================================================================
215295// Phase 4: Builtin Tests - __unsafeTectonixInternalManifestInverted
216296// ============================================================================
0 commit comments