Skip to content

tech(hooks): add version compatibility checks and runtime helpers#39

Open
tmustier wants to merge 1 commit intomainfrom
tech/sym-44-hook-version-compatibility
Open

tech(hooks): add version compatibility checks and runtime helpers#39
tmustier wants to merge 1 commit intomainfrom
tech/sym-44-hook-version-compatibility

Conversation

@tmustier
Copy link
Copy Markdown
Owner

@tmustier tmustier commented Apr 3, 2026

Summary

Add runtime version compatibility infrastructure for the hook contract, fulfilling all acceptance criteria from SYM-44.

Changes

extensions/teams/hooks.ts

  • HOOK_CONTRACT_VERSION_MIN — new constant defining the minimum supported version
  • checkHookContractVersion(version) — structured version check returning compatible / newer_minor / unsupported with descriptive messages
  • parseHookContextSafe(json) — combines JSON parse + version validation; recommended entry point for hook scripts
  • HookVersionCheckResult type — structured return for version checks
  • Expanded HOOK_CONTRACT_VERSION JSDoc to codify the full evolution rules (additive vs breaking) directly in code

scripts/smoke-test.mts

54 new tests covering:

  • Version constant invariants (MIN <= CURRENT, both integers ≥ 1)
  • checkHookContractVersion for exact match, future, far-future, zero, negative, fractional, NaN
  • parseHookContextSafe for valid v1, additive fields (future v2), version 0, invalid JSON, missing version, non-object, string version
  • Additive field tolerance (unknown keys survive parsing without breaking typed access)
  • task_failed payload semantics (status = "pending")
  • Drift guards: README references checkHookContractVersion + parseHookContextSafe; hook-contract.md documents version helpers and newer_minor status

docs/hook-contract.md

  • Improved version check example: distinguishes newer_minor (warn, proceed) from unsupported (exit)
  • New "Runtime version helpers" section documenting checkHookContractVersion and parseHookContextSafe with usage examples
  • Note that helpers are optional — plain shell scripts can implement the same logic

README.md

  • Hook section now mentions checkHookContractVersion and parseHookContextSafe

Acceptance Criteria

  • Written versioning policy in docs (including migration expectations)
  • Hook contract evolution rules codified in code comments/tests
  • Smoke tests include version compatibility checks
  • README/docs clearly tell hook authors how to safely parse context
  • No regression in current v1 hook behavior (335 tests pass, 0 failures)

Closes SYM-44

Add checkHookContractVersion() and parseHookContextSafe() utilities so
hook authors can validate contract versions at runtime with structured
results (compatible / newer_minor / unsupported).

Codify the full evolution rules (additive vs breaking changes) in the
HOOK_CONTRACT_VERSION JSDoc and export HOOK_CONTRACT_VERSION_MIN.

Add 54 smoke tests covering:
- Version range checks (exact, future, old, fractional, NaN)
- Safe context parsing with version validation
- Additive field tolerance (unknown keys survive parsing)
- task_failed status semantics
- Hook-contract.md and README drift guards

Update hook-contract.md with runtime helper docs and improved version
check examples that distinguish newer_minor from unsupported.

Closes SYM-44
@tmustier tmustier added the symphony Managed by pi-symphony label Apr 3, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12b9bae797

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/teams/hooks.ts
Comment on lines +140 to +143
if (version > HOOK_CONTRACT_VERSION) {
return {
status: "newer_minor",
requestedVersion: version,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject future contract versions as unsupported

The new compatibility helper treats any version > HOOK_CONTRACT_VERSION as newer_minor, but this repo’s policy states that additive changes do not bump the version and only breaking changes do. In that model, a higher version means the payload may be incompatible, so returning non-fatal status will let hooks continue parsing potentially broken shapes instead of failing fast. This is especially risky because parseHookContextSafe now depends on this check and will accept those future versions as success.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

symphony Managed by pi-symphony

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant