Implement the state-file baseline strategy (#1) - #11
Merged
Conversation
The translation moment is the first revision of the document's per-document state file (machine.state_dir/<name>.yml, renames followed) — the engine's own record that it created the translation — instead of the script-ratio jump. When the engine landed a document and its state file as adjacent single-file commits (autodiff.md in programming.zh-cn), the moment falls back to the last document revision not after the state file's creation. A document with no state file is untranslated under this strategy, logged, and correctable via baseline.overrides; config validation requires machine.state_dir. programming-zh-cn.yml adopts the strategy, with one override for the hand-translated _admonition/gpu.md snippet the engine does not track. On that corpus the strategy agrees with script-jump on all 28 documents — the authoritative record validating the heuristic where both apply. Verified: full suite green including the pinned intro.zh-cn regression; new tests cover the same-commit, adjacent-commit, no-state-file and override cases on a synthetic engine-era repository. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Implements the state-file baseline strategy for determining a document’s translation moment based on the first revision of its per-document engine state file, and wires it into scanning/config/docs. This supports engine-managed repositories where the state file is the authoritative provenance record, while keeping baseline.overrides as the escape hatch.
Changes:
- Add
state-filetranslation-moment strategy (translation_moment()/_state_file_moment()) and use it during scans. - Update config validation to require
machine.state_dirwhenbaseline.strategy: state-fileis selected. - Add targeted tests and update documentation/reference config + changelog.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_units.py | Updates config-validation unit test for state-file requirements and adds a passing config case. |
| tests/test_baseline.py | New tests for state-file moments (same-commit, adjacent-commit, missing state file) and override precedence. |
| src/textstrata/scan.py | Introduces translation_moment() with state-file implementation and integrates it into scan(). |
| src/textstrata/config.py | Enables state-file strategy and validates machine.state_dir when selected. |
| docs/method.md | Documents state-file strategy semantics and precedence with overrides. |
| docs/configuration.md | Documents configuration requirements for selecting state-file. |
| configs/quantecon/programming-zh-cn.yml | Switches reference config to baseline.strategy: state-file with an override for a hand-translated doc. |
| CHANGELOG.md | Notes the new state-file baseline strategy and its requirements. |
Suppressed comments (1)
tests/test_baseline.py:91
- Same issue as above: the returned
translation_datecomes from git's%aIand is expected to be offset-formatted (e.g.+00:00), not necessarilyZ.
repo, shas = engine_repo
cfg = make_cfg(repo, overrides={"lectures/c.md": shas["c_doc"][:7]})
assert moment(cfg, repo, "lectures/c.md") == (shas["c_doc"], "2026-05-01T09:00:00Z")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…agnostic test dates A baseline.overrides entry whose sha prefix matches no commit in the document's history now logs a warning instead of silently reading the document as untranslated (behaviour on a matching prefix is unchanged, last match wins). The test date assertions compare parsed instants rather than the Z-form string git's %aI happened to render here, so they hold whichever offset form a git version emits. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the
state-filebaseline strategy, the precursor #1 needs before thestate-filereading can be tried on programming.zh-cn. Part of the sequenced plan in #8 (Phase 2).What it does
The translation moment becomes the first revision of the document's per-document state file (
machine.state_dir/<name>.yml, renames followed) — the engine's own record that it created the translation — instead of the script-ratio heuristic. Three shapes observed in lecture-python-programming.zh-cn are handled:translate init(93dfab0)autodiff.md(5ca0651+2231b45, one second apart)_admonition/gpu.md, hand-translated in #23baseline.overridesConfig validation requires
machine.state_dirwhen the strategy is selected, replacing the previous "planned but not implemented" hard error.baseline.overrideswins regardless of strategy, unchanged.programming-zh-cn.ymladopts the strategy, with one override for the hand-translated gpu.md snippet.Verification
Scanning lecture-python-programming.zh-cn @
403f52aunder both strategies yields identical translation moments for all 28 documents — the authoritative record validating the heuristic on the one corpus where both apply. Corpus results: 28/28 translated, composition ai-initial 83.3% / ai-sync 9.9% / ai-assisted 6.8% / human-editor 0.0%, review state 26 machine-only / 2 human-touched.Full suite green locally, including the pinned intro.zh-cn regression (checkout at
0466562); newtests/test_baseline.pycovers the same-commit, adjacent-commit, no-state-file and override cases on a synthetic engine-era repository built in the fixture.🤖 Generated with Claude Code