template-press 3.2.0__tar.gz → 3.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {template_press-3.2.0 → template_press-3.4.0}/PKG-INFO +1 -1
  2. {template_press-3.2.0 → template_press-3.4.0}/pyproject.toml +4 -2
  3. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/press_cli.py +8 -5
  4. template_press-3.4.0/src/template_press/rebrand/check_tools.py +61 -0
  5. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/cli.py +250 -53
  6. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/config.py +22 -1
  7. template_press-3.4.0/src/template_press/rebrand/doctor.py +336 -0
  8. template_press-3.4.0/src/template_press/rebrand/engine.py +1112 -0
  9. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/identity.py +76 -2
  10. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/receipt.py +45 -1
  11. template_press-3.4.0/src/template_press/rebrand/regen.py +668 -0
  12. template_press-3.4.0/src/template_press/rebrand/reset.py +317 -0
  13. template_press-3.4.0/src/template_press/rebrand/rules.py +549 -0
  14. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/safety.py +19 -18
  15. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/synthesize.py +49 -2
  16. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/verifier.py +133 -9
  17. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/verify_cli.py +123 -7
  18. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/verify_config.py +7 -4
  19. template_press-3.2.0/src/template_press/rebrand/doctor.py +0 -151
  20. template_press-3.2.0/src/template_press/rebrand/engine.py +0 -558
  21. template_press-3.2.0/src/template_press/rebrand/rules.py +0 -90
  22. {template_press-3.2.0 → template_press-3.4.0}/README.md +0 -0
  23. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/__init__.py +0 -0
  24. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/py.typed +0 -0
  25. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/__init__.py +0 -0
  26. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/discovery.py +0 -0
  27. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/ignores.py +0 -0
  28. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/matcher.py +0 -0
  29. {template_press-3.2.0 → template_press-3.4.0}/src/template_press/rebrand/sandbox.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: template_press
3
- Version: 3.2.0
3
+ Version: 3.4.0
4
4
  Summary: Standalone rebrand utility — press a new identity onto an external target repo
5
5
  Author: Steve Morin
6
6
  Author-email: Steve Morin <steve.morin@gmail.com>
@@ -20,7 +20,7 @@
20
20
  [project]
21
21
  name = "template_press"
22
22
  # ITM-070 — static version (ADR-06 cutover). release-please bumps this.
23
- version = "3.2.0"
23
+ version = "3.4.0"
24
24
  description = "Standalone rebrand utility — press a new identity onto an external target repo"
25
25
  readme = "README.md"
26
26
  requires-python = ">=3.12"
@@ -216,10 +216,12 @@ strict_markers = true
216
216
  [tool.codespell]
217
217
  skip = ".git,.venv,build,dist,node_modules,uv.lock,bun.lock,*.lock,docs/_build,*.svg,*.cast,.ruff_cache,.pytest_cache,.mypy_cache,.ty_cache,*.log"
218
218
  # *.log: raw run output, not prose.
219
- ignore-words-list = "ans,porjects"
219
+ ignore-words-list = "ans,porjects,replcae"
220
220
  # ans: variable name used in prompt-handling code; codespell wants to "fix"
221
221
  # it to "and". Whitelist to keep the short variable name.
222
222
  # porjects: intentional typo — the did-you-mean example in cli/groups.py and
223
223
  # its test ("press porjects" must suggest "projects").
224
+ # replcae: intentional typo — the unknown-root-key regression test/message
225
+ # for `[[replcae]]` (rules.py F5a).
224
226
  check-filenames = true
225
227
  check-hidden = false
@@ -10,8 +10,8 @@ from __future__ import annotations
10
10
  import sys
11
11
 
12
12
  from template_press import __version__
13
+ from template_press.rebrand import check_tools, verify_cli
13
14
  from template_press.rebrand import cli as rebrand_cli
14
- from template_press.rebrand import verify_cli
15
15
 
16
16
  _RESERVED = {"provision", "status"}
17
17
 
@@ -19,10 +19,11 @@ _USAGE = """\
19
19
  usage: press <command> [options]
20
20
 
21
21
  commands:
22
- rebrand press an identity onto a target repo (press rebrand --help)
23
- verify check that a template presses cleanly (press verify --help)
24
- provision configure a target's features (coming in M6)
25
- status report a target's provisioned state (coming in M6)
22
+ rebrand press an identity onto a target repo (press rebrand --help)
23
+ verify check that a template presses cleanly (press verify --help)
24
+ check-tools report whether declared commands resolve (press check-tools --help)
25
+ provision configure a target's features (coming in M6)
26
+ status report a target's provisioned state (coming in M6)
26
27
  """
27
28
 
28
29
 
@@ -39,6 +40,8 @@ def main(argv: list[str] | None = None) -> int:
39
40
  return rebrand_cli.main(rest)
40
41
  if verb == "verify":
41
42
  return verify_cli.verify_command(rest)
43
+ if verb == "check-tools":
44
+ return check_tools.check_tools_command(rest)
42
45
  if verb in _RESERVED:
43
46
  print(
44
47
  f"error: '{verb}' is part of the Provision phase and is not "
@@ -0,0 +1,61 @@
1
+ """press check-tools — declared-tool availability report (P04 D4).
2
+
3
+ Resolves ``argv[0]`` of every declared ``[[regenerate]]`` command plus
4
+ ``git`` — the only tool press itself contributes after D1 — exactly as
5
+ execution would (D2): path-qualified names against the TARGET root, bare
6
+ names on the deny-by-default effective PATH. Reads config, writes
7
+ nothing, executes nothing. Exit 0 all found, 1 any missing, 2
8
+ config/usage error.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import argparse
14
+ import sys
15
+ import tomllib
16
+ from pathlib import Path
17
+
18
+ from template_press.rebrand.regen import command_env, resolve_executable
19
+ from template_press.rebrand.rules import ValidationError, load_rules
20
+
21
+
22
+ def check_tools_command(argv: list[str] | None = None) -> int:
23
+ parser = argparse.ArgumentParser(prog="press check-tools", description=__doc__)
24
+ parser.add_argument("--target", type=Path, required=True)
25
+ args = parser.parse_args(argv)
26
+
27
+ target = args.target.resolve()
28
+ if not target.is_dir():
29
+ print(f"error: target {target} is not a directory", file=sys.stderr)
30
+ return 2
31
+ try:
32
+ rules = load_rules(target)
33
+ except (
34
+ ValidationError,
35
+ tomllib.TOMLDecodeError,
36
+ UnicodeDecodeError,
37
+ OSError,
38
+ ) as exc:
39
+ # The same configuration exception set the rebrand and verify entry
40
+ # points normalize to exit 2 — never a traceback.
41
+ print(f"error: {exc}", file=sys.stderr)
42
+ return 2
43
+
44
+ missing = 0
45
+ reports: list[str] = []
46
+ git = resolve_executable(target, "git", command_env(()))
47
+ if git is None:
48
+ missing += 1
49
+ reports.append("git — missing (press itself needs it)")
50
+ else:
51
+ reports.append(f"git — {git}")
52
+ for rule in rules.regenerate:
53
+ argv0 = rule.command[0]
54
+ found = resolve_executable(target, argv0, command_env(rule.env))
55
+ if found is None:
56
+ missing += 1
57
+ reports.append(f"{argv0} — missing (declared to regenerate {rule.file})")
58
+ else:
59
+ reports.append(f"{argv0} — {found} (regenerates {rule.file})")
60
+ print("\n".join(reports))
61
+ return 1 if missing else 0
@@ -24,19 +24,46 @@ from template_press.rebrand.config import (
24
24
  from template_press.rebrand.discovery import discover, mismatches
25
25
  from template_press.rebrand.doctor import find_leaks, render_leak_report
26
26
  from template_press.rebrand.engine import (
27
- ApplyReport,
28
27
  apply,
29
28
  build_plan,
29
+ rendered_replace_rules,
30
30
  stray_press_dirs,
31
31
  )
32
- from template_press.rebrand.identity import Identity, ValidationError, token_occurs
33
- from template_press.rebrand.receipt import read_receipt, write_receipt
34
- from template_press.rebrand.rules import DEFAULT_RULES, Rules, load_rules
32
+ from template_press.rebrand.identity import (
33
+ DISPLAY_FORM_NAMES,
34
+ Identity,
35
+ ValidationError,
36
+ display_forms,
37
+ token_occurs,
38
+ )
39
+ from template_press.rebrand.receipt import (
40
+ RECEIPT_REL,
41
+ invalidate_receipt,
42
+ read_receipt,
43
+ write_receipt,
44
+ )
45
+ from template_press.rebrand.regen import (
46
+ RegenerationPlan,
47
+ execute_regenerations,
48
+ final_validation_pass,
49
+ plan_regenerate_commands,
50
+ preflight_excluded_files,
51
+ preflight_regenerate_outputs,
52
+ render_regenerate_plan,
53
+ restore_control_files,
54
+ snapshot_control_files,
55
+ validate_control_files,
56
+ )
57
+ from template_press.rebrand.reset import (
58
+ apply_resets,
59
+ preflight_reset_targets,
60
+ render_reset_plan,
61
+ )
62
+ from template_press.rebrand.rules import DEFAULT_RULES, ResetRule, Rules, load_rules
35
63
  from template_press.rebrand.safety import (
36
64
  SafetyError,
37
65
  git_hardening_args,
38
66
  scrubbed_git_env,
39
- scrubbed_uv_env,
40
67
  write_control,
41
68
  )
42
69
 
@@ -130,7 +157,31 @@ def _resolve_source(
130
157
  return source, write_pending
131
158
 
132
159
 
133
- def _collisions(source: Identity, dest: Identity) -> list[str]:
160
+ def _expand_display_forms(values: dict[str, str]) -> dict[str, str]:
161
+ """Replace a raw ``display_name`` entry with its per-form expansions.
162
+
163
+ Mirrors ``replacement_pairs``' display-form handling (engine.py):
164
+ runtime pair tags are ``display_name_spaced/pascal/camel``, never bare
165
+ ``display_name``, so comparing raw dict values alone can miss a derived
166
+ form that embeds a changed source token. Uses the full
167
+ ``DISPLAY_FORM_NAMES`` set (not a rules-configured subset) — a subset
168
+ only narrows what gets REWRITTEN; this preflight stays conservative and
169
+ checks every form regardless.
170
+ """
171
+ if "display_name" not in values:
172
+ return values
173
+ expanded = {k: v for k, v in values.items() if k != "display_name"}
174
+ forms = display_forms(values["display_name"])
175
+ for form in DISPLAY_FORM_NAMES:
176
+ expanded[f"display_name_{form}"] = forms[form]
177
+ return expanded
178
+
179
+
180
+ def _collisions(
181
+ source: Identity,
182
+ dest: Identity,
183
+ substring_fields: frozenset[str] = frozenset(),
184
+ ) -> list[str]:
134
185
  """Destination values that embed a CHANGED source token.
135
186
 
136
187
  Sequential substitution would re-rewrite such output (old app name
@@ -138,13 +189,34 @@ def _collisions(source: Identity, dest: Identity) -> list[str]:
138
189
  would flag correct output as a leak (press → press_two). Refusing up
139
190
  front with guidance beats either silent corruption or a permanent
140
191
  verification failure.
192
+
193
+ Both identities are expanded the same way ``replacement_pairs`` expands
194
+ them (Fix F3): a raw ``display_name`` entry is replaced by its exact
195
+ per-form values, so a destination display name whose DERIVED form (e.g.
196
+ the camel form of "Plbp" is "plbp") embeds a changed source token is
197
+ caught even though the raw display name never contains it verbatim.
198
+
199
+ ``substring_fields`` (Fix F4) — the target's ``[rules]
200
+ substring_rewrite_fields`` — mirrors what the engine will actually do to
201
+ a changed field opted into substring mode: it rewrites that field
202
+ SUBSTRING-wide, with no word-boundary guard, so a destination value that
203
+ embeds the source token WITHOUT a boundary (e.g. dest repo_name
204
+ "myfoo-tools" embedding source app_name "foo") is just as much a
205
+ collision as a boundary-guarded one — checked via plain ``in`` instead of
206
+ the boundary-guarded ``token_occurs``.
141
207
  """
142
208
  out: list[str] = []
143
- src, dst = source.as_dict(), dest.as_dict()
144
- changed = {f: v for f, v in src.items() if v != dst[f]}
209
+ src = _expand_display_forms(source.as_dict())
210
+ dst = _expand_display_forms(dest.as_dict())
211
+ changed = {f: v for f, v in src.items() if v != dst.get(f)}
145
212
  for dest_field, dest_value in dst.items():
146
213
  for src_field, src_value in changed.items():
147
- if token_occurs(dest_value, src_field, src_value):
214
+ hit = (
215
+ src_value in dest_value
216
+ if src_field in substring_fields
217
+ else token_occurs(dest_value, src_field, src_value)
218
+ )
219
+ if hit:
148
220
  out.append(
149
221
  f"destination {dest_field}={dest_value!r} contains the "
150
222
  f"source {src_field} token {src_value!r}"
@@ -152,6 +224,24 @@ def _collisions(source: Identity, dest: Identity) -> list[str]:
152
224
  return out
153
225
 
154
226
 
227
+ def display_name_problem(source: Identity, dest: Identity) -> str | None:
228
+ """Half-specified display identity is refused (codesign sec-06).
229
+
230
+ The press knows what to erase but not what to write — proceeding would
231
+ ship a half-rebrand where every prose mention keeps the old product
232
+ name. The reverse direction is harmless: nothing to rewrite, and the
233
+ post-apply source-config write records the new display name.
234
+ """
235
+ if source.display_name is not None and dest.display_name is None:
236
+ return (
237
+ f"source-config declares display_name "
238
+ f"({source.display_name!r}) but the answers file does not — "
239
+ f"add display_name to [answers]; press cannot know the new "
240
+ f"display name"
241
+ )
242
+ return None
243
+
244
+
155
245
  def main(argv: list[str] | None = None) -> int:
156
246
  parser = argparse.ArgumentParser(prog="press rebrand", description=__doc__)
157
247
  parser.add_argument("--target", type=Path, required=True)
@@ -161,6 +251,11 @@ def main(argv: list[str] | None = None) -> int:
161
251
  parser.add_argument("--dry-run", action="store_true")
162
252
  parser.add_argument("--force", action="store_true")
163
253
  parser.add_argument("--allow-dirty", action="store_true")
254
+ parser.add_argument(
255
+ "--verbose",
256
+ action="store_true",
257
+ help="show the bounded reset content excerpts in the plan",
258
+ )
164
259
  args = parser.parse_args(argv)
165
260
 
166
261
  target = args.target.resolve()
@@ -186,11 +281,23 @@ def main(argv: list[str] | None = None) -> int:
186
281
  return _fail("--config ANSWERS.toml is required")
187
282
  dest = load_answers(args.config)
188
283
 
284
+ display_problem = display_name_problem(source, dest)
285
+ if display_problem is not None:
286
+ return _fail(display_problem)
287
+
189
288
  if source == dest:
190
289
  return _fail(
191
290
  "source and destination identities are identical — nothing to press"
192
291
  )
193
- collisions = _collisions(source, dest)
292
+ # Loaded before the collision preflight (Fix F4): substring_rewrite_fields
293
+ # changes what counts as a collision (a boundary-free embedded token is
294
+ # only a problem for a field the engine will actually rewrite
295
+ # substring-wide) — pure reading, no side effect, so moving it earlier
296
+ # is safe.
297
+ rules = load_rules(target)
298
+ collisions = _collisions(
299
+ source, dest, substring_fields=rules.substring_rewrite_fields
300
+ )
194
301
  if collisions:
195
302
  print(
196
303
  "error: destination identity embeds source tokens — a single "
@@ -202,9 +309,36 @@ def main(argv: list[str] | None = None) -> int:
202
309
  print(f" {c}", file=sys.stderr)
203
310
  return 2
204
311
 
205
- rules = load_rules(target)
206
312
  plan = build_plan(target, source, dest, rules)
313
+ # Plan-time gates for both declared mechanisms (P04 D1/D2/D5, P05
314
+ # D5): output/target state, stale path-bearing argv against THIS
315
+ # plan's rename set, executable resolution under the deny-by-default
316
+ # env, stub scans, and the translated reset-path identity scan — all
317
+ # before any write, under the exit-2-nothing-written contract
318
+ # (dry-run included).
319
+ gate_problems = preflight_excluded_files(target, rules)
320
+ gate_problems += preflight_regenerate_outputs(target, rules)
321
+ regen_plans, plan_problems = plan_regenerate_commands(
322
+ target, rules.regenerate, renamed=frozenset(plan.renames)
323
+ )
324
+ gate_problems += plan_problems
325
+ reset_previews, reset_problems = preflight_reset_targets(
326
+ target, rules, source=source, dest=dest, renames=plan.renames
327
+ )
328
+ gate_problems += reset_problems
329
+ if gate_problems:
330
+ print(
331
+ "error: declared regeneration/reset cannot run — nothing written:",
332
+ file=sys.stderr,
333
+ )
334
+ for problem in gate_problems:
335
+ print(f" {problem}", file=sys.stderr)
336
+ return 2
207
337
  print(plan.render())
338
+ if regen_plans:
339
+ print(render_regenerate_plan(regen_plans))
340
+ if reset_previews:
341
+ print(render_reset_plan(reset_previews, verbose=args.verbose))
208
342
  strays = stray_press_dirs(target)
209
343
  if strays:
210
344
  print(
@@ -223,6 +357,10 @@ def main(argv: list[str] | None = None) -> int:
223
357
  # LAST gate before apply: every exit-2 path (rules/plan included) is
224
358
  # behind us, so the deferred source-config write can no longer be
225
359
  # followed by a "no writes" exit code.
360
+ if args.force and invalidate_receipt(target):
361
+ # Before the first mutation (P04-T16): a failed forced re-press
362
+ # must not leave the old receipt advertising a verified press.
363
+ print(f"prior receipt invalidated ({RECEIPT_REL})")
226
364
  if write_pending:
227
365
  write_control(target, SOURCE_CONFIG_REL, render_source_config(source))
228
366
  print(f"wrote {SOURCE_CONFIG_REL} from discovery")
@@ -234,47 +372,17 @@ def main(argv: list[str] | None = None) -> int:
234
372
  SafetyError,
235
373
  ) as exc:
236
374
  return _fail(str(exc))
237
- outcome = _press(target, source, dest, rules)
375
+ outcome = _press(
376
+ target,
377
+ source,
378
+ dest,
379
+ rules,
380
+ regen_plans,
381
+ [(preview.rule, preview.stub_text) for preview in reset_previews],
382
+ )
238
383
  return 1 if (outcome.env_error is not None or outcome.leaked) else 0
239
384
 
240
385
 
241
- def _regenerate_lockfiles(target: Path, rules: Rules, report: ApplyReport) -> list[str]:
242
- """Regenerate listed lockfiles; return the ones that FAILED to regenerate.
243
-
244
- A lockfile is excluded from both rewriting and the doctor scan, so a
245
- failed regeneration would leave source-identity content behind invisibly.
246
- Callers must treat failures as verification failures (no receipt).
247
- """
248
- failed: list[str] = []
249
- for lockfile in rules.regenerate:
250
- lockpath = target / lockfile
251
- if lockpath.is_symlink(): # lstat-based, no-follow — check first
252
- report.skipped.append(
253
- f"regenerate {lockfile} (symlink — refusing to write through)"
254
- )
255
- failed.append(lockfile)
256
- continue
257
- if not lockpath.is_file():
258
- continue
259
- if lockfile == "uv.lock":
260
- result = subprocess.run( # nosec B603 B607
261
- ["uv", "lock"], # noqa: S607
262
- cwd=target,
263
- capture_output=True,
264
- text=True,
265
- env=scrubbed_uv_env(), # G5: no UV_* override can steer the write
266
- )
267
- if result.returncode == 0:
268
- report.regenerated.append(lockfile)
269
- else:
270
- report.skipped.append(f"regenerate {lockfile} (uv lock failed)")
271
- failed.append(lockfile)
272
- else:
273
- report.skipped.append(f"regenerate {lockfile} (no regenerator)")
274
- failed.append(lockfile)
275
- return failed
276
-
277
-
278
386
  @dataclass
279
387
  class PressOutcome:
280
388
  """Structurally distinguishes an env/tool failure from a doctor leak.
@@ -290,13 +398,41 @@ class PressOutcome:
290
398
 
291
399
 
292
400
  def _press(
293
- target: Path, source: Identity, dest: Identity, rules: Rules
401
+ target: Path,
402
+ source: Identity,
403
+ dest: Identity,
404
+ rules: Rules,
405
+ regen_plans: list[RegenerationPlan],
406
+ resets: list[tuple[ResetRule, str]],
294
407
  ) -> PressOutcome:
295
408
  report = None
296
409
  try:
410
+ # Reset takes position ZERO (P05 D5): declared paths are consumed in
411
+ # SOURCE coordinates before the rename pass moves anything. A raise
412
+ # here aborts the press (no receipt) — git is the undo button.
413
+ reset_done = apply_resets(target, resets)
297
414
  report = apply(target, source, dest, rules)
298
- failed_locks = _regenerate_lockfiles(target, rules, report)
415
+ report.reset.extend(reset_done)
416
+ # Declared commands run against the FINAL tree: declared paths are
417
+ # translated through the apply-time rename report (P04 D1). The
418
+ # press-owned control files are snapshotted before the first
419
+ # command and revalidated after the last (D1 reservation is not
420
+ # protection — a command can mutate arbitrary files).
421
+ control_snapshot = snapshot_control_files(target) if regen_plans else {}
422
+ failed_locks = execute_regenerations(
423
+ target,
424
+ regen_plans,
425
+ dict(report.renamed),
426
+ report,
427
+ source=source,
428
+ dest=dest,
429
+ rules=rules,
430
+ )
299
431
  if failed_locks:
432
+ # A failed command must not leave a tampered/planted control
433
+ # file behind (codex 3654736777) — restore the snapshot before
434
+ # reporting; {} when no commands ran.
435
+ restore_control_files(target, control_snapshot)
300
436
  print(
301
437
  f"error: lockfile regeneration failed for "
302
438
  f"{', '.join(failed_locks)} — the lockfile still carries the old "
@@ -312,6 +448,35 @@ def _press(
312
448
  report.regenerated,
313
449
  env_error=f"lockfile regeneration failed for {', '.join(failed_locks)}",
314
450
  )
451
+ if regen_plans:
452
+ # Final validation pass (D3): outputs, reset stubs, and the
453
+ # control-file snapshot — a later command corrupting an earlier
454
+ # result is invisible to every downstream inventory.
455
+ post_problems = final_validation_pass(
456
+ target,
457
+ regen_plans,
458
+ resets,
459
+ dict(report.renamed),
460
+ source=source,
461
+ dest=dest,
462
+ rules=rules,
463
+ )
464
+ post_problems += validate_control_files(target, control_snapshot)
465
+ if post_problems:
466
+ restore_control_files(target, control_snapshot)
467
+ print(
468
+ "error: post-regeneration validation failed — no receipt written:",
469
+ file=sys.stderr,
470
+ )
471
+ for problem in post_problems:
472
+ print(f" {problem}", file=sys.stderr)
473
+ print(report.render(), file=sys.stderr)
474
+ return PressOutcome(
475
+ False,
476
+ report.renamed,
477
+ report.regenerated,
478
+ env_error="post-regeneration validation failed",
479
+ )
315
480
  # Verification never honors target-side REWRITE exclusions (EMP-01):
316
481
  # neither extra_exclude_files nor extra_exclude_dirs can hide content
317
482
  # from the doctor. The only sanctioned exemption is the explicit,
@@ -322,14 +487,46 @@ def _press(
322
487
  regenerate=rules.regenerate,
323
488
  verify_ignore=rules.verify_ignore,
324
489
  )
325
- leaks = find_leaks(target, source, doctor_rules, dest=dest)
490
+ leaks = find_leaks(
491
+ target,
492
+ source,
493
+ doctor_rules,
494
+ dest=dest,
495
+ display_form_names=rules.display_forms,
496
+ substring_fields=rules.substring_rewrite_fields,
497
+ rendered_rules=rendered_replace_rules(rules, source, dest),
498
+ renamed=report.renamed,
499
+ )
326
500
  if leaks:
327
501
  print(render_leak_report(leaks), file=sys.stderr)
328
502
  print(report.render(), file=sys.stderr)
329
503
  return PressOutcome(
330
504
  True, report.renamed, report.regenerated, env_error=None
331
505
  )
332
- receipt_path = write_receipt(target, source, dest, report)
506
+ receipt_path = write_receipt(
507
+ target,
508
+ source,
509
+ dest,
510
+ report,
511
+ regenerations=[
512
+ (plan.rule.file, (plan.executable, *plan.rule.command[1:]))
513
+ for plan in regen_plans
514
+ ],
515
+ exempt=[
516
+ *(
517
+ (
518
+ rel,
519
+ "regenerated by declared command; validated by the "
520
+ "press's post-command scan (hermetic verify skips it)",
521
+ )
522
+ for rel in report.regenerated
523
+ ),
524
+ *(
525
+ (rel, "reset to the declared stub (scanned at plan time)")
526
+ for rel in report.reset
527
+ ),
528
+ ],
529
+ )
333
530
  write_control(target, SOURCE_CONFIG_REL, render_source_config(dest))
334
531
  print(report.render())
335
532
  if report.skipped:
@@ -12,7 +12,12 @@ import tomllib
12
12
  from pathlib import Path
13
13
 
14
14
  from template_press.rebrand.engine import ROOT_CONTROL
15
- from template_press.rebrand.identity import Identity, ValidationError
15
+ from template_press.rebrand.identity import (
16
+ OPTIONAL_FIELDS,
17
+ REQUIRED_FIELDS,
18
+ Identity,
19
+ ValidationError,
20
+ )
16
21
  from template_press.rebrand.safety import ContainmentError, assert_under_root
17
22
 
18
23
  SOURCE_CONFIG_REL = Path("press") / "press-source.toml"
@@ -64,6 +69,22 @@ def load_identity_toml(path: Path, table: str) -> Identity:
64
69
  section = data.get(table)
65
70
  if not isinstance(section, dict):
66
71
  raise ValidationError(f"{path}: missing [{table}] table")
72
+ # F3: an unknown key (typo'd optional field, e.g. `display_nam`) must
73
+ # fail loud — the dict-comprehension below silently drops any key it
74
+ # doesn't recognize, so a typo would otherwise pass through as if the
75
+ # field were simply absent, and press proceeds none the wiser.
76
+ known = frozenset(REQUIRED_FIELDS) | frozenset(OPTIONAL_FIELDS)
77
+ unknown = set(section) - known
78
+ if unknown:
79
+ raise ValidationError(
80
+ f"{path}: [{table}] unknown key(s): {', '.join(sorted(unknown))}"
81
+ )
82
+ for key in (*REQUIRED_FIELDS, *OPTIONAL_FIELDS):
83
+ if key in section and not isinstance(section[key], str):
84
+ raise ValidationError(
85
+ f"{path}: [{table}] {key} must be a string, got "
86
+ f"{type(section[key]).__name__}"
87
+ )
67
88
  identity = Identity.from_mapping(
68
89
  {k: v for k, v in section.items() if isinstance(v, str)}
69
90
  )