Skip to content

Commit e1578a7

Browse files
PhysShellclaude
andcommitted
test(s2-step11): red — L2 exact consumed-schema + L3 strict failure cleanup
L2 Tier A regressions: delta schema=true, reference_dir_count=false, non-string selected_class / closure_kind, boolean / negative reference ordinal, non-string expected id, malformed input / reference SHA, and a duplicate / unsorted reference ordinal are all DELTA_BINDING. L3 Tier A regressions: an ordinary controlled failure after the execution root is claimed re-raises its original category on successful cleanup, becomes PUBLICATION on a cleanup failure (and likewise for an isolation-after-creation failure), and leaves OUTPUT_DIR absent in every case. RED against the current fix_target, which presence-checks (not SHA / ordinal-order / exact-int) the consumed Step 10 shapes and cleans up the work root best-effort (except OSError: pass) so a cleanup failure is silently swallowed rather than PUBLICATION. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JxKjqdGEFzq4UzZupw379G
1 parent 4cc5737 commit e1578a7

1 file changed

Lines changed: 109 additions & 2 deletions

File tree

‎tests/test_verify_target.py‎

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ def _boom(*_a, **_k):
314314
_h4_validators(check)
315315
_h4_run_child(check)
316316
_h4_bind_delta(check)
317+
_l2_schema(check)
318+
_l3_cleanup(check)
317319

318320
total = ok + bad
319321
print(f"verify-target (Tier A): {ok}/{total} checks pass")
@@ -442,7 +444,7 @@ def _h3_revalidation(check) -> None:
442444

443445

444446
def _h3_cleanup_and_publish(check) -> None:
445-
# --- _remove_root: a cleanup failure is PUBLICATION ---
447+
# --- _remove_root_strict: a cleanup failure is PUBLICATION ---
446448
with tempfile.TemporaryDirectory() as tmp:
447449
d = os.path.join(tmp, "work")
448450
os.makedirs(d)
@@ -453,7 +455,7 @@ def _boom(*_a, **_k):
453455

454456
try:
455457
ft.shutil.rmtree = _boom
456-
check(_raises(ft.PUBLICATION, ft._remove_root, d),
458+
check(_raises(ft.PUBLICATION, ft._remove_root_strict, d),
457459
"remove-root: cleanup failure -> PUBLICATION")
458460
finally:
459461
ft.shutil.rmtree = orig
@@ -717,5 +719,110 @@ def _h4_bind_delta(check) -> None:
717719
"bind_delta: malformed reference_closure entry -> DELTA_BINDING")
718720

719721

722+
def _l2_schema(check) -> None:
723+
"""L2: the exact consumed Step 10 schema — bool-vs-int, value types, SHA form, ordinal order."""
724+
with tempfile.TemporaryDirectory() as tmp:
725+
_root, _bundle, paths, delta_bytes = _manual_fixture(tmp)
726+
with open(paths["candidates.json"], encoding="utf-8") as fh:
727+
cands = json.load(fh)
728+
with open(paths["plan.json"], encoding="utf-8") as fh:
729+
plan = json.load(fh)
730+
auth = validate_gate_authority(plan, cands)
731+
plan_b, cand_b = _reads(paths["plan.json"]), _reads(paths["candidates.json"])
732+
rc0 = {"ordinal": 0, "source_dir_ordinal": 0, "relative_path": "W.dll",
733+
"sha256": "sha256:" + "a" * 64}
734+
735+
def run_bad(fn, label: str) -> None:
736+
d = json.loads(delta_bytes)
737+
fn(d)
738+
check(_raises(ft.DELTA_BINDING, ft.bind_delta, _canonical_bytes(d),
739+
auth, plan_b, cand_b), label)
740+
741+
run_bad(lambda d: d.update(schema=True), "L2: schema=true -> DELTA_BINDING")
742+
run_bad(lambda d: d["analysis_scope"].update(reference_dir_count=False),
743+
"L2: reference_dir_count=false -> DELTA_BINDING")
744+
run_bad(lambda d: d["analysis_scope"].update(selected_class=1),
745+
"L2: selected_class non-string -> DELTA_BINDING")
746+
run_bad(lambda d: d["analysis_scope"].update(closure_kind=1),
747+
"L2: closure_kind non-string -> DELTA_BINDING")
748+
run_bad(lambda d: d["expected"].update(manual_review_ids=[1]),
749+
"L2: non-string expected id -> DELTA_BINDING")
750+
run_bad(lambda d: d["input_hashes"].update(pre_sha256="sha256:ZZ"),
751+
"L2: malformed input hash -> DELTA_BINDING")
752+
run_bad(lambda d: d.update(reference_closure=[{**rc0, "ordinal": True}]),
753+
"L2: boolean reference ordinal -> DELTA_BINDING")
754+
run_bad(lambda d: d.update(reference_closure=[{**rc0, "ordinal": -1}]),
755+
"L2: negative reference ordinal -> DELTA_BINDING")
756+
run_bad(lambda d: d.update(reference_closure=[{**rc0, "sha256": "sha256:zz"}]),
757+
"L2: malformed reference sha -> DELTA_BINDING")
758+
run_bad(lambda d: d.update(reference_closure=[dict(rc0), {**rc0, "ordinal": 0}]),
759+
"L2: duplicate / unsorted reference ordinal -> DELTA_BINDING")
760+
# positive control: a valid, ordered two-entry closure binds.
761+
d = json.loads(delta_bytes)
762+
d["reference_closure"] = [rc0, {"ordinal": 1, "source_dir_ordinal": 1,
763+
"relative_path": "B.dll", "sha256": "sha256:" + "b" * 64}]
764+
try:
765+
ft.bind_delta(_canonical_bytes(d), auth, plan_b, cand_b)
766+
check(True, "L2: a valid ordered two-entry closure binds")
767+
except ft.TargetError:
768+
check(False, "L2: false rejection of a valid closure")
769+
770+
771+
def _l3_cleanup(check) -> None:
772+
"""L3: strict failure-path cleanup — successful cleanup re-raises the original refusal, a
773+
cleanup failure is PUBLICATION, and OUTPUT_DIR is always absent (no ignore_errors)."""
774+
# (a) a controlled failure after the execution root is claimed, cleanup succeeds -> original
775+
# category; (b) same with a cleanup failure -> PUBLICATION. Both leave the out-dir absent.
776+
with tempfile.TemporaryDirectory() as tmp:
777+
root, bundle, paths, _delta = _manual_fixture(tmp)
778+
refdir = os.path.join(tmp, "refs") # a ref-dir the delta's empty closure will not match
779+
os.makedirs(refdir)
780+
with open(os.path.join(refdir, "X.dll"), "wb") as fh:
781+
fh.write(b"MZ")
782+
out_a = os.path.join(tmp, "out-a")
783+
check(_raises(ft.REFERENCE_BINDING, ft.run_verify_target, bundle, root, paths["plan.json"],
784+
paths["candidates.json"], paths["delta.json"], None, out_a, [refdir], None),
785+
"L3: failure + successful cleanup -> original category")
786+
check(not os.path.exists(out_a), "L3: out-dir absent after the original-category failure")
787+
788+
out_b = os.path.join(tmp, "out-b")
789+
orig = ft.shutil.rmtree
790+
791+
def _boom(*_a, **_k):
792+
raise OSError("locked")
793+
794+
try:
795+
ft.shutil.rmtree = _boom
796+
check(_raises(ft.PUBLICATION, ft.run_verify_target, bundle, root, paths["plan.json"],
797+
paths["candidates.json"], paths["delta.json"], None, out_b,
798+
[refdir], None),
799+
"L3: failure + execution-root cleanup failure -> PUBLICATION")
800+
finally:
801+
ft.shutil.rmtree = orig
802+
check(not os.path.exists(out_b), "L3: out-dir absent after the cleanup-failure PUBLICATION")
803+
804+
# (c) a protected root resolves inside the execution root: cleanup success -> ISOLATION;
805+
# cleanup failure -> PUBLICATION.
806+
with tempfile.TemporaryDirectory() as tmp:
807+
base = os.path.join(tmp, "base")
808+
prot = os.path.join(base, "prot")
809+
os.makedirs(prot)
810+
orig_mkdtemp, orig_rmtree = ft.tempfile.mkdtemp, ft.shutil.rmtree
811+
try:
812+
ft.tempfile.mkdtemp = lambda *a, **k: base
813+
check(_raises(ft.ISOLATION, ft._execution_root, [prot]),
814+
"L3: protected-inside-root + cleanup success -> ISOLATION")
815+
os.makedirs(prot, exist_ok=True)
816+
817+
def _boom(*_a, **_k):
818+
raise OSError("locked")
819+
820+
ft.shutil.rmtree = _boom
821+
check(_raises(ft.PUBLICATION, ft._execution_root, [prot]),
822+
"L3: protected-inside-root + cleanup failure -> PUBLICATION")
823+
finally:
824+
ft.tempfile.mkdtemp, ft.shutil.rmtree = orig_mkdtemp, orig_rmtree
825+
826+
720827
if __name__ == "__main__":
721828
raise SystemExit(run())

0 commit comments

Comments
 (0)