fix(cache): allow layout-less cache hits and clarify miss comment

covers() no longer treats a cached layout as a miss for a no-layout
request: materialize() now drops the layout when it is not wanted. Tags
remain a miss because a tags-enabled document has already had
false-positive strings removed. Move the --analyze-functions comment
inline with the caching guard it documents.
This commit is contained in:
lakshit verma 2026-08-18 01:06:59 +05:30
parent fba96b0fb6
commit bc94b6cb27
No known key found for this signature in database
3 changed files with 23 additions and 6 deletions

View file

@ -194,9 +194,10 @@ def test_covers_layout_enabled_mismatch_is_miss():
assert not floss.cache.covers(doc, wanted(enable_layout=True), 4)
def test_covers_layout_disabled_mismatch_is_miss():
def test_covers_layout_disabled_is_hit():
# a cached layout can satisfy a no-layout request: materialize() drops it
doc = make_doc(enable_layout=True)
assert not floss.cache.covers(doc, wanted(enable_layout=False), 4)
assert floss.cache.covers(doc, wanted(enable_layout=False), 4)
def test_covers_tags_enabled_mismatch_is_miss():
@ -221,3 +222,15 @@ def test_materialize_sets_file_path_and_filters(tmp_path):
assert mat.metadata.file_path == str(sample)
# "hello" is 5 chars, below the requested -n 8
assert mat.strings.static_strings == []
def test_materialize_drops_layout_when_disabled(tmp_path):
doc = make_doc(enable_layout=True)
key = floss.cache.compute_key(doc.metadata.sha256, __version__)
floss.cache.store(tmp_path, key, doc)
loaded = floss.cache.load(tmp_path, key, doc.metadata.sha256, __version__)
assert loaded is not None
assert loaded.layout is not None
mat = floss.cache.materialize(loaded, tmp_path / "sample.exe", wanted(enable_layout=False), 4)
assert mat.layout is None