Skip to content

Implement the state-file baseline strategy (#1) - #11

Merged
mmcky merged 2 commits into
mainfrom
state-file-baseline
Aug 27, 2026
Merged

Implement the state-file baseline strategy (#1)#11
mmcky merged 2 commits into
mainfrom
state-file-baseline

Conversation

@mmcky

@mmcky mmcky commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Implements the state-file baseline strategy, the precursor #1 needs before the state-file reading 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:

Shape Example Reading
Document and state file land in one commit 25 lectures via translate init (93dfab0) that commit
Adjacent single-file commits (doc, then state) autodiff.md (5ca0651 + 2231b45, one second apart) the last document revision not after the state file's creation
No state file _admonition/gpu.md, hand-translated in #23 untranslated, logged; correctable via baseline.overrides

Config validation requires machine.state_dir when the strategy is selected, replacing the previous "planned but not implemented" hard error. baseline.overrides wins regardless of strategy, unchanged.

programming-zh-cn.yml adopts the strategy, with one override for the hand-translated gpu.md snippet.

Verification

Scanning lecture-python-programming.zh-cn @ 403f52a under 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); new tests/test_baseline.py covers 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

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>
Copilot AI lite review requested due to automatic review settings August 27, 2026 23:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-file translation-moment strategy (translation_moment() / _state_file_moment()) and use it during scans.
  • Update config validation to require machine.state_dir when baseline.strategy: state-file is 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_date comes from git's %aI and is expected to be offset-formatted (e.g. +00:00), not necessarily Z.
    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.

Comment thread src/textstrata/scan.py
Comment thread tests/test_baseline.py Outdated
…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>
@mmcky
mmcky merged commit 50e38f5 into main Aug 27, 2026
3 checks passed
@mmcky
mmcky deleted the state-file-baseline branch August 27, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants