From f61e8ec5d7223e6b858e4d7a8171056f0061c805 Mon Sep 17 00:00:00 2001 From: bkrabach <702425+bkrabach@users.noreply.github.com> Date: Wed, 11 Nov 2026 00:32:31 -0800 Subject: [PATCH] Reuse local source signatures within one profile check --- amplifier_web/runtime_profiles.py | 12 ++++++--- tests/test_runtime_profile_inputs.py | 37 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/amplifier_web/runtime_profiles.py b/amplifier_web/runtime_profiles.py index 7a112e81b2..64ad9e125b 100644 --- a/amplifier_web/runtime_profiles.py +++ b/amplifier_web/runtime_profiles.py @@ -283,11 +283,15 @@ async def report(detail): from amplifier_foundation.modules.preparation import source_signature contents = [] + signatures = {} for path in sorted(local_inputs): - content = await asyncio.to_thread( - source_signature, path if path.is_dir() else path.parent - ) - contents.append([str(path), content]) + root = path if path.is_dir() else path.parent + # Sibling bundle files share the same content observation within + # this check. Keep every declared path in the identity, and rescan + # on the next check so local edits cannot reuse an obsolete wheel. + if root not in signatures: + signatures[root] = await asyncio.to_thread(source_signature, root) + contents.append([str(path), signatures[root]]) key = hashlib.sha256((key + json.dumps(contents)).encode()).hexdigest() if edited is not None: key = hashlib.sha256( diff --git a/tests/test_runtime_profile_inputs.py b/tests/test_runtime_profile_inputs.py index 0e30648a1e..907a0722f0 100644 --- a/tests/test_runtime_profile_inputs.py +++ b/tests/test_runtime_profile_inputs.py @@ -319,6 +319,43 @@ async def test_actual_local_source_content_requalifies(profile_inputs, declarati assert set(h.scans) == {code} +async def test_sibling_local_bundles_share_one_scan_per_check(profile_inputs): + h = profile_inputs + code = h.workspace.parent / "local-code" + code.mkdir() + bundles = [code / f"{name}.yaml" for name in ("one", "two", "three")] + for path in bundles: + path.write_text(f"bundle:\n name: {path.stem}\n") + h.plan["includes"] = [{"bundle": str(path)} for path in bundles] + other = h.workspace.parent / "other-code" + other.mkdir() + payload = other / "implementation.py" + payload.write_text("VALUE = 1\n") + h.plan["tools"][0]["source"] = str(other) + child = h.child("siblings") + + selected = await runtime_profiles.ensure(h.home, h.generation, child) + assert sorted(h.scans) == sorted([code, other]) + h.scans.clear() + assert await runtime_profiles.ensure(h.home, h.generation, child) == selected + assert sorted(h.scans) == sorted([code, other]) + assert len(h.calls) == 3 + + # A later sibling-file edit must invalidate the previously qualified setup. + bundles[-1].write_text("bundle:\n name: changed\n") + h.scans.clear() + changed = await runtime_profiles.ensure(h.home, h.generation, child) + assert changed not in {selected, h.generation} + assert sorted(h.scans) == sorted([code, other]) + assert len(h.calls) == 6 + + # An independent source root remains part of the qualification identity. + payload.write_text("VALUE = 2\n") + assert await runtime_profiles.ensure(h.home, h.generation, child) not in { + selected, changed, h.generation, + } + + async def test_real_module_outward_symlink_still_fails_closed(profile_inputs): h = profile_inputs code = h.workspace.parent / "unsafe-code"