Skip to content

feat(cli): identify the running version on every envelope (WI-P2)#97

Merged
tjdwls101010 merged 2 commits into
mainfrom
wi-p2-version-signal
Jul 19, 2026
Merged

feat(cli): identify the running version on every envelope (WI-P2)#97
tjdwls101010 merged 2 commits into
mainfrom
wi-p2-version-signal

Conversation

@tjdwls101010

Copy link
Copy Markdown
Owner

What

The package never said which version answered. No moleg_api.__version__, no version field on the envelope. Two consequences for a consumer:

  • A missing field is ambiguous — "this release doesn't support it" and "the call went wrong" look identical.
  • A checkout on sys.path shadows site-packages, so python -m moleg_api runs checkout code while the install stays untouched. Nothing in the response revealed which one had answered.

How

  • moleg_api/_version.py holds the version as a literal, not an importlib.metadata lookup. Metadata describes the installed distribution; the code that actually runs may come from somewhere else. A literal travels with the code, so the version on an envelope is always the version that produced it.
  • pyproject.toml reads that attribute through [tool.setuptools.dynamic], making the package the single source of truth. A test pins the wiring — a literal duplicated in pyproject.toml drifts the moment one side is bumped and the other is forgotten, and the resulting wheel reports a version its own code disagrees with.
  • The stamp happens inside _emit, the one funnel all output passes through, so no envelope can ship without it — success, error, catalog, and usage errors raised before a command is even parsed.
  • --version now reports the same literal rather than distribution metadata, so the flag and the envelope cannot disagree.

Verification

  • 352 deterministic tests pass (8 new).
  • python -m build + twine check succeed with the dynamic version (0.2.4 resolved from the package literal).

🤖 Generated with Claude Code

tjdwls101010 and others added 2 commits July 19, 2026 22:29
Nothing in the package identified itself: no `__version__`, no field on the
envelope. A consumer holding a response could not tell whether a missing
field meant "this release doesn't support it" or "the call failed" — and a
checkout on sys.path answers in place of the installed release with no way
to notice, so "which version told me this?" had no answer at all.

`__version__` is a literal in `moleg_api/_version.py`, not an
importlib.metadata lookup, because metadata describes the *installed
distribution* while the code that runs may come from elsewhere. A literal
travels with the code, so the version an envelope reports is always the one
that produced it. pyproject reads that attribute via
[tool.setuptools.dynamic], so build and runtime cannot disagree; a test
pins that wiring, since a duplicated literal drifts the first time one side
is bumped and the other is forgotten.

Stamped inside `_emit` rather than at each call site so no envelope —
success, error, or catalog — can ship without it, including usage errors
raised before a command is even parsed.

`--version` now reports the same literal instead of distribution metadata,
so the flag and the envelope can no longer disagree.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tomllib is stdlib only from 3.11; this package supports 3.10 with zero
dependencies, so the guard has to parse the file without it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tjdwls101010
tjdwls101010 merged commit d44175d into main Jul 19, 2026
5 checks passed
@tjdwls101010
tjdwls101010 deleted the wi-p2-version-signal branch July 19, 2026 13:32
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.

1 participant