Skip to content

editor — all cases

Every case file under src/clauz3/stdlib/editor/tests/cases/, inlined. _pass cases must prove; _fail cases must not.

See the curated walk-through for the trusted module and contract vocabulary.

src/clauz3/stdlib/editor/tests/cases/edits_at_most_fail.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.edits_at_most(1))
def main() -> None:
    edit_file("/tmp/a", "x")
    edit_file("/tmp/b", "y")

src/clauz3/stdlib/editor/tests/cases/edits_at_most_pass.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import append_file, edit_file

import clauz3


@clauz3.guarantee(ed.edits_at_most(2))
def main() -> None:
    edit_file("/tmp/a", "x")
    append_file("/tmp/a", "y")

src/clauz3/stdlib/editor/tests/cases/must_not_replace_fail.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.must_not_replace("BEGIN PRIVATE KEY"))
def main() -> None:
    edit_file("/tmp/leak", "BEGIN PRIVATE KEY\n...\n")

src/clauz3/stdlib/editor/tests/cases/must_not_replace_pass.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.must_not_replace("BEGIN PRIVATE KEY"))
def main() -> None:
    edit_file("/repo/build/cert.pem", "BEGIN CERTIFICATE\n...\nEND CERTIFICATE\n")

src/clauz3/stdlib/editor/tests/cases/never_edit_under_fail.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.never_edit_under("/etc"))
def main() -> None:
    edit_file("/etc/hosts", "127.0.0.1 evil.example.com\n")

src/clauz3/stdlib/editor/tests/cases/never_edit_under_pass.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.never_edit_under("/etc"))
def main() -> None:
    edit_file("/repo/build/out.txt", "hello")

src/clauz3/stdlib/editor/tests/cases/no_edits_fail.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.no_edits())
def main() -> None:
    edit_file("/tmp/scratch", "anything")

src/clauz3/stdlib/editor/tests/cases/no_edits_pass.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed

import clauz3


@clauz3.guarantee(ed.no_edits())
def main() -> None:
    pass

src/clauz3/stdlib/editor/tests/cases/only_edit_under_fail.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.only_edit_under("/repo/build"))
def main() -> None:
    edit_file("/etc/passwd", "")

src/clauz3/stdlib/editor/tests/cases/only_edit_under_pass.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import append_file, edit_file

import clauz3


@clauz3.guarantee(ed.only_edit_under("/repo/build"))
def main() -> None:
    edit_file("/repo/build/out.txt", "hello")
    append_file("/repo/build/log.txt", "done\n")

src/clauz3/stdlib/editor/tests/cases/replace_length_at_most_fail.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.replace_length_at_most(8))
def main() -> None:
    edit_file("/tmp/a", "this is much longer than eight characters")

src/clauz3/stdlib/editor/tests/cases/replace_length_at_most_pass.py

# ruff: noqa: F821
from tools.editor.trusted import contracts as ed
from tools.editor.trusted.effects import edit_file

import clauz3


@clauz3.guarantee(ed.replace_length_at_most(32))
def main() -> None:
    edit_file("/tmp/a", "short content")