Skip to content
Merged
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
12 changes: 8 additions & 4 deletions amplifier_web/runtime_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 37 additions & 0 deletions tests/test_runtime_profile_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading