Files
claude-resume-kit/tests/test_resume_system.py
T
dennisthiessenandClaude Opus 5 eecdbdade6 fix(F17): a PDF in a folder is not proof the package can be rebuilt
Build sweep run this session: 48 sources, 46 built, 2 failed. Infineon_AI_Engineer's
cover letter fails on font expansion (the font is not scalable); cv_template.tex
fails on unfilled placeholders, which is expected for the academic legacy path.
Overfull boxes: Microsoft ISE 25.33pt, Isovalent 0.88pt. All historical, all
left alone.

New: resume_builder/helpers/package_manifest.py records, per application
package, what a rebuild would ACTUALLY do - sources, class-file hashes, PDFs
present, and the reasons a rebuild would not reproduce the submitted document.
It is descriptive; nothing in it authorises rewriting a submitted file.

What it found across 21 packages:
- 17 are DATE-DEPENDENT. The cover letters use 	oday, so recompiling a
  historical package silently restamps it with today's date.
- 1 has an INCOMPLETE SOURCE DISTRIBUTION: output/NATO_AI_ENGINEER ships no
  resume.cls. It builds on this machine only because a copy exists elsewhere,
  and the shipped PDF hid that. Not repaired by copying the newest class in -
  the repo carries THREE different resume.cls variants (13/7/1 copies) and older
  macros differ, so that "fix" could silently change a historical document.
- 1 has no PDF at all, so nothing is reviewable without a build.

Classification: 7 application packages were in no reuse category. Added to
historical_revalidate, and the register now records the default explicitly -
anything unlisted is treated as revalidate-before-reuse. Being recent is not the
same as being verified; none of the seven was re-read for this.

Prevention rather than repair: 	oday removed from the cover-letter template so
new packages stop adding to the pile. A test now fails if it comes back, if the
manifest goes stale, or if a package is left unclassified.

Also: scan_document gained a template mode. A placeholder in a TEMPLATE is what
makes it a template; the defect is one surviving into a generated document.

37/37 tests pass; counter-proof still catches all 9.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qej5SBvhcbGXHwLqNWiskM
2026-09-11 20:48:52 +02:00

164 lines
7.3 KiB
Python

from __future__ import annotations
import importlib.util
import json
import sys
import re
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def load_module(name: str, relative_path: str):
spec = importlib.util.spec_from_file_location(name, ROOT / relative_path)
module = importlib.util.module_from_spec(spec)
assert spec and spec.loader
spec.loader.exec_module(module)
return module
validator = load_module("validate_resume_system", "resume_builder/helpers/validate_resume_system.py")
length_helper = load_module("char_count", "resume_builder/helpers/char_count.py")
class CanonicalSystemTests(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.claims = json.loads(
(ROOT / "resume_builder/canonical/claims.json").read_text(encoding="utf-8")
)
cls.history = json.loads(
(ROOT / "resume_builder/canonical/historical_outputs.json").read_text(encoding="utf-8")
)
def test_canonical_and_workflow_checks_have_no_errors(self) -> None:
errors, _warnings = validator.canonical_checks(self.claims, self.history)
errors.extend(validator.workflow_checks())
self.assertEqual([], errors)
def test_claim_and_employment_ids_are_unique(self) -> None:
for collection in ("employment", "claims"):
ids = [item["id"] for item in self.claims[collection]]
self.assertEqual(len(ids), len(set(ids)), collection)
def test_swiss_work_authorization_is_verified(self) -> None:
identity = self.claims["identity"]
self.assertEqual("B residence permit", identity["swiss_permit"])
self.assertIn("no visa or employer sponsorship required", identity["swiss_work_authorization"])
self.assertFalse(identity["swiss_permit"].startswith("UNVERIFIED"))
def test_historical_outputs_are_classified_once(self) -> None:
folders = []
for category in ("unsafe_do_not_reuse", "historical_revalidate"):
folders.extend(
item["folder"] if isinstance(item, dict) else item
for item in self.history[category]
)
self.assertEqual(len(folders), len(set(folders)))
def test_templates_pass_document_claim_scan(self) -> None:
for relative in (
"resume_builder/templates/resume_template.tex",
"resume_builder/templates/coverletter_template.tex",
):
self.assertEqual([], validator.scan_document(ROOT / relative, self.claims, template=True), relative)
class PackageReproducibilityTests(unittest.TestCase):
"""F17: a PDF in a folder is not evidence that the package can be rebuilt."""
def test_manifest_is_current(self):
import subprocess
result = subprocess.run(
[sys.executable, str(ROOT / "resume_builder" / "helpers" / "package_manifest.py"),
"--check"], capture_output=True, text=True)
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
def test_cover_letter_template_does_not_use_today(self):
# \today makes a rebuild date-dependent: recompiling a historical letter
# silently restamps it with the current date.
template = (ROOT / "resume_builder" / "templates" / "coverletter_template.tex").read_text(
encoding="utf-8")
body = "\n".join(
line for line in template.splitlines() if not line.strip().startswith("%"))
self.assertNotIn("\\today", body)
def test_every_application_package_is_classified_for_reuse(self):
manifest = json.loads(
(ROOT / "resume_builder" / "canonical" / "package_manifest.json").read_text(
encoding="utf-8"))
unclassified = [name for name, entry in manifest["packages"].items()
if entry["reuse_classification"] == "UNCLASSIFIED"]
self.assertEqual([], unclassified)
class WorkflowPolicyTests(unittest.TestCase):
def test_agent_entrypoints_resolve_the_same_shared_workflow(self) -> None:
for entry in sorted((ROOT / ".agents/skills").glob("*/SKILL.md")):
other = ROOT / ".claude/skills" / entry.parent.name / "SKILL.md"
bodies = []
for path in (entry, other):
body = re.sub(r"\A---\n.*?\n---\n", "", path.read_text(encoding="utf-8"), count=1, flags=re.S)
bodies.append(body)
links = re.findall(r"\]\(([^)]+\.md)\)", body)
self.assertEqual(1, len(links), path)
workflow = (path.parent / links[0]).resolve()
self.assertEqual(ROOT / "resume_builder/reference/workflows" / (entry.parent.name + ".md"), workflow)
self.assertIn("Shared workflow version:", workflow.read_text(encoding="utf-8"))
self.assertEqual(*bodies)
def test_skills_use_minimal_valid_frontmatter(self) -> None:
for skill_file in sorted((ROOT / ".agents/skills").glob("*/SKILL.md")):
text = skill_file.read_text(encoding="utf-8")
match = re.match(r"^---\n(.*?)\n---", text, re.DOTALL)
self.assertIsNotNone(match, skill_file)
fields = {}
for line in match.group(1).splitlines():
key, separator, value = line.partition(":")
self.assertEqual(":", separator, skill_file)
fields[key.strip()] = value.strip()
self.assertEqual({"name", "description"}, set(fields), skill_file)
self.assertRegex(fields["name"], r"^[a-z0-9]+(?:-[a-z0-9]+)*$")
self.assertLessEqual(len(fields["name"]), 64)
self.assertTrue(fields["description"])
self.assertLessEqual(len(fields["description"]), 1024)
self.assertNotRegex(fields["description"], r"[<>]")
def test_top_level_instructions_expose_new_controls(self) -> None:
for filename in ("AGENTS.md", "CLAUDE.md"):
text = (ROOT / filename).read_text(encoding="utf-8")
for phrase in (
"canonical/claims.json",
"Evidence Fit",
"Document Quality",
"Channel Strength",
"no character targets",
"cover letter is conditional",
):
self.assertIn(phrase.lower(), text.lower(), f"{filename}: {phrase}")
def test_resume_template_has_conventional_hierarchy(self) -> None:
text = (ROOT / "resume_builder/templates/resume_template.tex").read_text(encoding="utf-8")
self.assertIn("Professional Experience", text)
self.assertIn("Technical Skills", text)
self.assertIn("Education", text)
self.assertNotIn("FLIPPED", text)
self.assertNotIn("Selected Publications", text)
def test_length_helper_is_diagnostic_not_target_based(self) -> None:
source = (ROOT / "resume_builder/helpers/char_count.py").read_text(encoding="utf-8")
self.assertNotIn("classify_bullet", source)
rendered, characters, words, clauses = length_helper.diagnose(
r"\item Built governed data products within the company-wide Data Mesh."
)
self.assertEqual("Built governed data products within the company-wide Data Mesh.", rendered)
self.assertGreater(characters, 0)
self.assertEqual(9, words)
self.assertEqual(1, clauses)
if __name__ == "__main__":
unittest.main()