fix(tools): keep a debt file's note and sub-headings when debt_split rewrites it #13957

Merged
MarcZX10 merged 2 commits from upstream-pr/13957 into main 2026-11-05 19:14:18 +00:00
MarcZX10 commented 2026-10-31 13:56:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T13:56:30Z.


What

tools/debt_split.py rewrites a library's debt file when it moves entries into it. Two cases lost hand-written text:

  • read_debt kept only the entries and paragraphs under a ### heading. A note before the first ### and every #### heading were dropped on rewrite. Reproduced: a libSceFoo.md with the note "Hand-written note about foo that must stay." and a #### Detail heading lost both after debt_split.py split added one entry.
  • write_debt deleted a debt file when none of its sections had entries, so a file that held only a note disappeared.

The fix keeps the note and the #### headings. A new read_preamble reads what comes before the first ### (the file's # title excepted), render and write_debt write it back after the title, and apply_change carries it through resolve. #### headings inside a section are kept in that section. read_debt still returns the same dictionary for the same files.

A second case, found while reproducing: an entry above the first ### of the index was filed under a literal ### None section in its library's file. split now stops with an entry is above the first ### section, so there is no section to file it under: ... and writes nothing.

Tested

Linux, Python 3.11.2, this branch at 4f5c2bab39 on upstream/main 73f4f7e06e:

  • python3 tools/tests/test_debt_split.py: 31 tests, OK. The 28 existing tests plus three new ones: test_split_keeps_the_note_and_sub_headings_of_an_existing_debt_file, test_a_debt_file_with_only_a_note_is_written_and_not_deleted and test_split_refuses_an_entry_above_the_first_section_without_writing.
  • Both reproductions from above, rerun by hand on the fixed tool: the note and the #### heading survive, and the entry above the first section is refused with exit 1.
  • python3 tools/check_conventions.py --base upstream/main: all conventions checks passed.
  • git diff --check upstream/main HEAD: clean.
  • tools/pr_overlap.py --branch: no overlap with open pull requests.

Negative control: the three new tests run against the upstream/main debt_split.py fail, as intended (the note and heading are dropped, the entry above the first section is filed under ### None, and write_debt has no preamble argument, so the empty-section test errors).

Not run: the C++ build and CTest (no C++ changed); Windows, macOS and hosted CI are not run locally.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5098151924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13957). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T13:56:30Z. --- ### What `tools/debt_split.py` rewrites a library's debt file when it moves entries into it. Two cases lost hand-written text: - `read_debt` kept only the entries and paragraphs under a `###` heading. A note before the first `###` and every `####` heading were dropped on rewrite. Reproduced: a `libSceFoo.md` with the note "Hand-written note about foo that must stay." and a `#### Detail heading` lost both after `debt_split.py split` added one entry. - `write_debt` deleted a debt file when none of its sections had entries, so a file that held only a note disappeared. The fix keeps the note and the `####` headings. A new `read_preamble` reads what comes before the first `###` (the file's `# ` title excepted), `render` and `write_debt` write it back after the title, and `apply_change` carries it through `resolve`. `#### ` headings inside a section are kept in that section. `read_debt` still returns the same dictionary for the same files. A second case, found while reproducing: an entry above the first `###` of the index was filed under a literal `### None` section in its library's file. `split` now stops with `an entry is above the first ### section, so there is no section to file it under: ...` and writes nothing. ### Tested Linux, Python 3.11.2, this branch at `4f5c2bab39` on `upstream/main` `73f4f7e06e`: - `python3 tools/tests/test_debt_split.py`: 31 tests, OK. The 28 existing tests plus three new ones: `test_split_keeps_the_note_and_sub_headings_of_an_existing_debt_file`, `test_a_debt_file_with_only_a_note_is_written_and_not_deleted` and `test_split_refuses_an_entry_above_the_first_section_without_writing`. - Both reproductions from above, rerun by hand on the fixed tool: the note and the `####` heading survive, and the entry above the first section is refused with exit 1. - `python3 tools/check_conventions.py --base upstream/main`: all conventions checks passed. - `git diff --check upstream/main HEAD`: clean. - `tools/pr_overlap.py --branch`: no overlap with open pull requests. Negative control: the three new tests run against the `upstream/main` `debt_split.py` fail, as intended (the note and heading are dropped, the entry above the first section is filed under `### None`, and `write_debt` has no preamble argument, so the empty-section test errors). Not run: the C++ build and CTest (no C++ changed); Windows, macOS and hosted CI are not run locally. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-02 04:58:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:58:27Z.

Review: COMMENTED


Reviewed — order proposal checked, one test file named in the reply is missing

janzezno's 2026-10-31 proposal (this PR first, #14212 rebased on it) is consistent with the code at this head, but the reply cites a test file that exists neither here nor on main.

What I ran

Live head 4f5c2bab3992fd5baaf7ee73e02e1bd6536715f7 (matches the batch file). Read the comment with gh api repos/boykopovar/AnyPS5/issues/13957/comments, the check rollup with gh pr view 13957 --json statusCheckRollup, and the files with git -C /marc/AnyPS5 show <ref>:<path> at the head and at 381891927c. Nothing was built or run.

Results

Check Result Note
relinker (ubuntu, windows, macOS x2), relinker-asan SUCCESS hosted
eligibility, conventions, intake, labels SUCCESS hosted
linux, windows, register-context, write-watch SKIPPED hosted

Findings

The reply (2026-10-31T23:47:09Z) says #14212 changes the same line of write_debt and asks whether this PR goes first.

  • At this head render(title, sections, order, preamble=()) takes preamble (tools/debt_split.py line 141). At 381891927c it does not (def render(title, sections, order):, line 141). So this PR is the one that adds it.
  • write_debt calls render(f"# {name} technical debt", sections, order, preamble) at line 190, the line the reply's snippet wraps.
  • space_debt is not defined anywhere in the tree at this head, so it can only come from #14212. Not verified.
  • The reply says tools/tests/test_debt_format.py passes on the merge. That file exists neither at this head nor at 381891927c, so the stated test run cannot be checked as written. The reply's test_debt_split.py claim is not re-run.

Answer: nothing at this head contradicts the order. The conflict is the one line described. Before agreeing, confirm which test file was run.

Sources

Not verified

  • space_debt and #14212's own diff.
  • The merge test run on 381891927c (not re-run).
  • Nothing was built or run.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732255188 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13957#pullrequestreview-5732255188). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:58:27Z. **Review:** COMMENTED --- # Reviewed — order proposal checked, one test file named in the reply is missing janzezno's 2026-10-31 proposal (this PR first, #14212 rebased on it) is consistent with the code at this head, but the reply cites a test file that exists neither here nor on main. ## What I ran Live head `4f5c2bab3992fd5baaf7ee73e02e1bd6536715f7` (matches the batch file). Read the comment with `gh api repos/boykopovar/AnyPS5/issues/13957/comments`, the check rollup with `gh pr view 13957 --json statusCheckRollup`, and the files with `git -C /marc/AnyPS5 show <ref>:<path>` at the head and at `381891927c`. Nothing was built or run. ## Results | Check | Result | Note | |---|---|---| | relinker (ubuntu, windows, macOS x2), relinker-asan | SUCCESS | hosted | | eligibility, conventions, intake, labels | SUCCESS | hosted | | linux, windows, register-context, write-watch | SKIPPED | hosted | ## Findings The reply (2026-10-31T23:47:09Z) says #14212 changes the same line of `write_debt` and asks whether this PR goes first. - At this head `render(title, sections, order, preamble=())` takes `preamble` (`tools/debt_split.py` line 141). At `381891927c` it does not (`def render(title, sections, order):`, line 141). So this PR is the one that adds it. - `write_debt` calls `render(f"# {name} technical debt", sections, order, preamble)` at line 190, the line the reply's snippet wraps. - `space_debt` is not defined anywhere in the tree at this head, so it can only come from #14212. Not verified. - The reply says `tools/tests/test_debt_format.py` passes on the merge. That file exists neither at this head nor at `381891927c`, so the stated test run cannot be checked as written. The reply's `test_debt_split.py` claim is not re-run. Answer: nothing at this head contradicts the order. The conflict is the one line described. Before agreeing, confirm which test file was run. ## Sources - https://github.com/boykopovar/AnyPS5/blob/4f5c2bab3992fd5baaf7ee73e02e1bd6536715f7/tools/debt_split.py#L141-L149 - https://github.com/boykopovar/AnyPS5/blob/4f5c2bab3992fd5baaf7ee73e02e1bd6536715f7/tools/debt_split.py#L182-L190 - https://github.com/boykopovar/AnyPS5/blob/4f5c2bab3992fd5baaf7ee73e02e1bd6536715f7/tools/tests/test_debt_split.py#L474-L500 ## Not verified - `space_debt` and #14212's own diff. - The merge test run on `381891927c` (not re-run). - Nothing was built or run.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13957
No description provided.