From 67ca5ea2756a920aa048986556630b3b5997a38f Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sun, 6 Dec 2026 03:34:26 +0300 Subject: [PATCH] Record the digest algorithm in the index snapshot Snapshot schema 4 stores digestAlgorithm inside the digested payload. Restore accepts schemas 1-4, verifies the digest for 3 and 4, and classifies an unknown algorithm as incompatible instead of corrupt so a future digest change is not misread as corruption. Registered tests cover the migration and the rejection. --- docs/agent-workflow/VERIFICATION.md | 10 ++++++++++ src/index/SymbolIndex.cpp | 10 ++++++++-- tests/index/SymbolIndexTests.cpp | 31 ++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 00f02cc..90c2626 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -61,6 +61,16 @@ start coordinate only, so ranges are zero-width until an end is available. LSP adapters and index/rename/debugging integration remain open. `vbs test` passed all 17 native suites; CMake passed the reflection and trace suites. +## December 6 index snapshot schema 4 + +The symbol-index snapshot is now schema 4 and records `digestAlgorithm` inside +the digested payload. Restore accepts schemas 1-4 (older ones report +`migrated`), verifies the digest for schemas 3 and 4, and classifies an unknown +algorithm as `incompatible` rather than `corrupt`, so a future digest change +cannot be misread as corruption. Registered `vls_index_tests` cover the +migration path and the unknown-algorithm rejection (30 cases). All 18 native +suites and all 18 CMake tests passed. + ## December 6 reflection references `reflection::references_at` collects every source link of the entity covering a diff --git a/src/index/SymbolIndex.cpp b/src/index/SymbolIndex.cpp index 99fa29f..9e72d5e 100644 --- a/src/index/SymbolIndex.cpp +++ b/src/index/SymbolIndex.cpp @@ -24,7 +24,7 @@ using Json = P::Json; namespace { constexpr std::size_t max_json_depth = 8; -constexpr std::int64_t snapshot_schema = 3; +constexpr std::int64_t snapshot_schema = 4; constexpr std::int64_t oldest_snapshot_schema = 1; const char *backend_name = "vls-symbol-index"; @@ -189,7 +189,12 @@ SnapshotStatus parse_snapshot(std::string_view bytes, const Limits &limits, Pars if (!schema_value || !backend || *backend != backend_name || (*schema_value < oldest_snapshot_schema || *schema_value > snapshot_schema)) return SnapshotStatus::incompatible; - if (*schema_value == snapshot_schema) { + if (*schema_value >= 3) { + if (*schema_value == snapshot_schema) { + const auto *algorithm = P::as_string(P::find_member(*root, "digestAlgorithm")); + if (!algorithm || *algorithm != "sha256") + return SnapshotStatus::incompatible; + } const auto *digest = P::as_string(P::find_member(*root, "digest")); if (!digest || digest->size() != 64) return SnapshotStatus::corrupt; @@ -571,6 +576,7 @@ bool SymbolIndex::save(const fs::path &path) const { root = Json{Json::Object{{"schema", Json{snapshot_schema}}, {"backend", Json{std::string{backend_name}}}, {"generation", Json{static_cast(state.generation)}}, + {"digestAlgorithm", Json{std::string{"sha256"}}}, {"contexts", Json{std::move(contexts)}}, {"overlays", Json{std::move(overlays)}}}}; } diff --git a/tests/index/SymbolIndexTests.cpp b/tests/index/SymbolIndexTests.cpp index 22c482d..b42f3a3 100644 --- a/tests/index/SymbolIndexTests.cpp +++ b/tests/index/SymbolIndexTests.cpp @@ -134,7 +134,7 @@ VOID_TEST(SymbolIndex, rejects_incompatible_or_corrupt_snapshots) { return std::string{std::istreambuf_iterator{stream}, {}}; }(); auto incompatible = bytes; - const auto schema = incompatible.find("\"schema\":3"); + const auto schema = incompatible.find("\"schema\":4"); require(schema != std::string::npos); incompatible.replace(schema, 10, "\"schema\":9"); { @@ -210,7 +210,7 @@ VOID_TEST(SymbolIndex, quarantines_incompatible_snapshots_and_rebuilds) { std::ifstream stream{path, std::ios::binary}; return std::string{std::istreambuf_iterator{stream}, {}}; }(); - const auto schema = bytes.find("\"schema\":3"); + const auto schema = bytes.find("\"schema\":4"); require(schema != std::string::npos); bytes.replace(schema, 10, "\"schema\":9"); { @@ -350,7 +350,7 @@ std::string downgrade(std::string bytes) { const auto end = bytes.find('"', digest + 12); require(end != std::string::npos); bytes.erase(digest, end + 1 - digest); - const auto schema = bytes.find("\"schema\":3"); + const auto schema = bytes.find("\"schema\":4"); require(schema != std::string::npos); bytes.replace(schema, 10, "\"schema\":1"); return bytes; @@ -373,7 +373,7 @@ VOID_TEST(SymbolIndex, snapshot_schema_migration_is_reported_and_rewritten) { const auto upgraded = temp.path() / "upgraded.json"; require(loaded.save(upgraded)); const auto bytes = file_text(upgraded); - expect(bytes.find("\"schema\":3") != std::string::npos); + expect(bytes.find("\"schema\":4") != std::string::npos); expect(bytes.find("\"digest\":\"") != std::string::npos); SymbolIndex reread; expect(reread.load(upgraded)); @@ -394,7 +394,7 @@ VOID_TEST(SymbolIndex, generation_restore_persists_the_migrated_schema) { expect(restored->migrated); expect(count(loaded.find({.name = "a"})) == 1); const auto bytes = file_text(root / "snapshot.json"); - expect(bytes.find("\"schema\":3") != std::string::npos); + expect(bytes.find("\"schema\":4") != std::string::npos); expect(bytes.find("\"digest\":\"") != std::string::npos); expect(fs::is_regular_file(root / "snapshot.prev.json")); SymbolIndex reread; @@ -482,7 +482,7 @@ VOID_TEST(SymbolIndex, schema_2_snapshots_migrate_with_their_records) { require(index.publish(context("debug:unit", {record("f", "/project/unit.cpp", 3)}))); require(index.save(path)); auto bytes = file_text(path); - const auto schema = bytes.find("\"schema\":3"); + const auto schema = bytes.find("\"schema\":4"); require(schema != std::string::npos); bytes.replace(schema, 10, "\"schema\":2"); put_text(path, bytes); @@ -493,7 +493,7 @@ VOID_TEST(SymbolIndex, schema_2_snapshots_migrate_with_their_records) { expect(restored->migrated); expect(count(loaded.find({.name = "f"})) == 1); require(loaded.save(path)); - expect(file_text(path).find("\"schema\":3") != std::string::npos); + expect(file_text(path).find("\"schema\":4") != std::string::npos); } VOID_TEST(SymbolIndex, rejects_an_oversized_signature) { @@ -529,3 +529,20 @@ VOID_TEST(SymbolIndex, selector_records_the_previous_generation_name) { SymbolIndex rejected; expect(!rejected.restore_generation(root).has_value()); } + +VOID_TEST(SymbolIndex, schema_4_rejects_an_unknown_digest_algorithm) { + Void::FileSystem::TempDir temp{"vls_symbol_index_"}; + const auto path = temp.path() / "index.json"; + SymbolIndex index; + require(index.publish(context("debug:unit", {record("f", "/project/unit.cpp", 3)}))); + require(index.save(path)); + auto bytes = file_text(path); + const auto algorithm = bytes.find("\"digestAlgorithm\":\"sha256\""); + require(algorithm != std::string::npos); + bytes.replace(algorithm, 26, "\"digestAlgorithm\":\"blake3\""); + put_text(path, bytes); + const auto restored = index.restore(path); + require(restored.has_value()); + expect(restored->status == SymbolIndex::LoadStatus::incompatible); + expect(restored->quarantine.has_value()); +}