Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libexpr-tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ sources = files(
'value/context.cc',
'value/print.cc',
'value/value.cc',
'worldtree-pool.cc',
)

include_dirs = [ include_directories('.') ]
Expand Down
82 changes: 81 additions & 1 deletion src/libexpr-tests/tectonix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ class TectonixTest : public ::testing::Test
std::unique_ptr<EvalState> state;

TectonixEvalContext(
const std::filesystem::path & repoPath, const std::string & commitSha, bool withCheckout = false)
const std::filesystem::path & repoPath,
const std::string & commitSha,
bool withCheckout = false,
const std::filesystem::path & worldtreeMount = {})
: store(openStore("dummy://"))
{
evalSettings.nixPath = {};
Expand All @@ -154,6 +157,11 @@ class TectonixTest : public ::testing::Test
if (withCheckout) {
evalSettings.tectonixCheckoutPath = repoPath.string();
}
if (!worldtreeMount.empty()) {
// Deliberately nonexistent: historical mode must never connect to it.
evalSettings.tectonixWorldtreeSocket = (repoPath / "unused-worldtree.sock").string();
evalSettings.tectonixWorldtreeMount = worldtreeMount.string();
}

state = std::make_unique<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr);
}
Expand All @@ -172,6 +180,15 @@ class TectonixTest : public ::testing::Test
{
return std::make_unique<TectonixEvalContext>(repoPath, commitSha, withCheckout);
}

std::unique_ptr<TectonixEvalContext> createHistoricalWorldtreeContext(std::string_view manifest)
{
auto mount = repoPath / "worldtree";
auto manifestDir = mount / "tecnix" / commitSha / "W-000000";
std::filesystem::create_directories(manifestDir);
std::ofstream(manifestDir / "manifest.json") << manifest;
return std::make_unique<TectonixEvalContext>(repoPath, commitSha, false, mount);
}
};

// ============================================================================
Expand Down Expand Up @@ -211,6 +228,69 @@ TEST_F(TectonixTest, manifest_returns_path_to_metadata_mapping)
ASSERT_THAT(*coreId->value, IsStringEq("W-000003"));
}

TEST_F(TectonixTest, historical_worldtree_manifest_and_dirty_set_are_filesystem_only)
{
static constexpr std::string_view historicalManifest = R"({
"//historical/only": { "id": "W-123456" }
})";
auto ctx = createHistoricalWorldtreeContext(historicalManifest);

ASSERT_EQ(ctx->state->getManifestContent(), historicalManifest);
auto & manifest = ctx->state->getManifestJson();
ASSERT_EQ(manifest.size(), 1u);
ASSERT_EQ(manifest.at("//historical/only").at("id"), "W-123456");

auto & dirty = ctx->state->getTectonixDirtyZones();
ASSERT_EQ(dirty.size(), 1u);
ASSERT_FALSE(dirty.at("//historical/only").dirty);
}

TEST_F(TectonixTest, historical_worldtree_explains_malformed_manifest)
{
auto ctx = createHistoricalWorldtreeContext("{");

try {
ctx->state->getManifestJson();
FAIL() << "expected malformed manifest to fail";
} catch (const Error & e) {
ASSERT_THAT(e.what(), testing::HasSubstr("historical World manifest '.meta/manifest.json'"));
ASSERT_THAT(e.what(), testing::HasSubstr(commitSha));
ASSERT_THAT(e.what(), testing::HasSubstr("missing or malformed"));
}
}

TEST_F(TectonixTest, historical_worldtree_explains_missing_manifest)
{
auto mount = repoPath / "worldtree-without-manifest";
auto ctx = std::make_unique<TectonixEvalContext>(repoPath, commitSha, false, mount);

try {
ctx->state->getManifestContent();
FAIL() << "expected missing manifest to fail";
} catch (const Error & e) {
ASSERT_THAT(e.what(), testing::HasSubstr("historical World manifest '.meta/manifest.json'"));
ASSERT_THAT(e.what(), testing::HasSubstr(commitSha));
ASSERT_THAT(e.what(), testing::HasSubstr("missing or malformed"));
}
}

TEST_F(TectonixTest, historical_worldtree_rejects_noncanonical_revision)
{
auto mount = repoPath / "worldtree";
auto ctx = std::make_unique<TectonixEvalContext>(repoPath, "../escape", false, mount);

ASSERT_THROW(ctx->state->getManifestContent(), Error);
}

TEST_F(TectonixTest, historical_worldtree_rejects_noncanonical_zone_id)
{
auto ctx = createHistoricalWorldtreeContext(R"({
"//historical/only": { "id": "../escape" }
})");

ASSERT_THROW(ctx->state->getZoneStorePath("//historical/only"), Error);
}

// ============================================================================
// Phase 4: Builtin Tests - __unsafeTectonixInternalManifestInverted
// ============================================================================
Expand Down
Loading
Loading