independent-software-check.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Reviewer-owned behavioral checks. Run ONLY inside the documented isolated container."""
  2. import importlib.util
  3. import json
  4. import signal
  5. import sys
  6. CASES = [
  7. ([" Alpha ", "beta", "ALPHA", ""], ["alpha", "beta"]),
  8. ([None, 3, " "], []),
  9. (["A", "B", "a", " b "], ["a", "b"]),
  10. (["x", False, " X "], ["x"]),
  11. ([], []),
  12. ([{}, [], True, 0, 1.2], []),
  13. ([" B ", "a", "b", "A", "c"], ["b", "a", "c"]),
  14. (["\tALPHA\n", "alpha", "\n"], ["alpha"]),
  15. (["Ä", "ä", "中文", " 中文 "], ["ä", "中文"]),
  16. ]
  17. def main():
  18. signal.signal(signal.SIGALRM, lambda *_: (_ for _ in ()).throw(TimeoutError("time limit")))
  19. signal.alarm(10)
  20. spec = importlib.util.spec_from_file_location("candidate", sys.argv[1])
  21. module = importlib.util.module_from_spec(spec)
  22. spec.loader.exec_module(module)
  23. results = []
  24. for index, (values, expected) in enumerate(CASES):
  25. try:
  26. actual = module.normalize_labels(values)
  27. results.append({'case': index + 1, 'passed': isinstance(actual, list) and actual == expected})
  28. except Exception as error:
  29. results.append({'case': index + 1, 'passed': False, 'error': type(error).__name__})
  30. passed = sum(item['passed'] for item in results)
  31. print(json.dumps({'suite': 'reviewer-independent-v1', 'passed': passed, 'total': len(CASES), 'checks': results}))
  32. return 0 if passed == len(CASES) else 1
  33. if __name__ == '__main__':
  34. raise SystemExit(main())