tests/test_hygiene.py — Duplicate File and Photo Report
From version 0.1.0 of Duplicate File and Photo Report, shown publicly by its creator. 3.9 KiB · SHA-256 ba4cf0377863210cc2fe572380af431a7836eae360d6771790b634c05b5ea025.
# By Zero Width Lab (zerowidthlab.com)
"""Check that shipped text stays public and visibly attributed."""
from __future__ import annotations
import re
import tempfile
import unicodedata
import unittest
from pathlib import Path
from unittest.mock import patch
__author__ = "Zero Width Lab"
ROOT = Path(__file__).resolve().parent.parent
SIGNATURE = "By Zero Width Lab (zerowidthlab.com)"
GUID = r"\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b"
EMAIL = r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}"
HOME = r"/(?:Users|home)/[A-Za-z0-9._-]+"
AI_NAMES = (
"Open" + "AI", "Anthro" + "pic", "Chat" + "G" + "PT", "Gem" + "ini",
"Cla" + "ude", "Co" + "dex", "Co" + "pilot", "Son" + "net", "Op" + "us",
)
GPT_TOKEN = "G" + "PT"
SHIPPED = (
"SKILL.md", "README.md", "SETUP.md", "LICENSE.txt",
"agents/duplicate-file-and-photo-report-agent.md", "references/report-format.md",
"scripts/duplicate_file_report.py", "tests/test_duplicate_file_report.py",
"tests/test_hygiene.py", "source-package.json",
)
SOURCE_ONLY = (
"packaging/listing-values.json", "packaging/skills-outpost-listing.md",
"packaging/package-spec.json", "packaging/package-spec-content.json",
)
def contains_ai_name(content: str) -> bool:
lower = content.lower()
return any(name.lower() in lower for name in AI_NAMES) or bool(
re.search(r"\b" + GPT_TOKEN + r"\b", content)
)
class HygieneTests(unittest.TestCase):
def test_name_filter_covers_all_required_names(self) -> None:
for name in (*AI_NAMES, GPT_TOKEN):
with self.subTest(name=name):
self.assertTrue(contains_ai_name(" " + name + " "))
self.assertFalse(contains_ai_name("lowercase " + GPT_TOKEN.lower()))
self.assertFalse(contains_ai_name("prefix" + GPT_TOKEN + "suffix"))
def test_source_only_files_are_checked_when_present(self) -> None:
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
for name in SOURCE_ONLY:
path = root / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("Open" + "AI", encoding="utf-8")
with self.subTest(file=name), patch.dict(globals(), ROOT=root, SHIPPED=()):
result = unittest.TestResult()
HygieneTests("test_shipped_text").run(result)
self.assertEqual(len(result.failures), 1)
path.unlink()
with patch.dict(globals(), ROOT=root, SHIPPED=()):
result = unittest.TestResult()
HygieneTests("test_shipped_text").run(result)
self.assertTrue(result.wasSuccessful())
def test_shipped_text(self) -> None:
self.assertEqual(len(SHIPPED + SOURCE_ONLY), len(set(SHIPPED + SOURCE_ONLY)))
for name in (*SHIPPED, *(name for name in SOURCE_ONLY if (ROOT / name).is_file())):
path = ROOT / name
with self.subTest(file=name):
self.assertTrue(path.is_file())
content = path.read_text(encoding="utf-8")
self.assertIsNone(re.search(GUID, content, re.IGNORECASE))
self.assertIsNone(re.search(EMAIL, content))
self.assertIsNone(re.search(HOME, content))
self.assertNotIn("onmicro" + "soft.com", content.lower())
self.assertNotIn("share" + "point.com", content.lower())
self.assertFalse(contains_ai_name(content))
for character in content:
self.assertFalse(
unicodedata.category(character) == "Cf" or character in (chr(0x2028), chr(0x2029)),
f"invisible code point in {name}",
)
if path.suffix == ".md":
self.assertEqual(content.rstrip().splitlines()[-1], SIGNATURE)
if __name__ == "__main__":
unittest.main()
License: MIT (read it).
MIT
MIT LicenseCopyright (c) 2026 Zero Width Lab
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.