[PR #547] [MERGED] refactor(domain): own digest and prefixed identifier shapes in one module #2067

Closed
opened 2026-10-16 21:13:53 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/547
Author: @morluto
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @morluto

Base: main ← Head: cleanup/digest-schema-module


📝 Commits (1)

  • 91bafb6 refactor(domain): own digest and prefixed identifier shapes in one module

📊 Changes

56 files changed (+314 additions, -162 deletions)

View changed files

📝 src/application/ProjectPermissionStore.ts (+2 -1)
📝 src/contracts/sessionToolSchemas.ts (+2 -1)
📝 src/contracts/toolOutputSchemaPrimitives.ts (+2 -1)
📝 src/domain/analysisProfile.ts (+1 -2)
📝 src/domain/analysisSnapshot.ts (+3 -2)
📝 src/domain/androidApplication.ts (+5 -4)
📝 src/domain/appleApplication.ts (+5 -4)
📝 src/domain/artifactComparison.ts (+4 -3)
📝 src/domain/artifactGraph.ts (+7 -6)
📝 src/domain/artifactInspection.ts (+13 -12)
📝 src/domain/browserObservationSchemas.ts (+2 -1)
📝 src/domain/browserScenarioCaptureValues.ts (+1 -1)
📝 src/domain/bundleComparison.ts (+3 -2)
📝 src/domain/callPathSchemas.ts (+2 -1)
📝 src/domain/changedBehavior.ts (+2 -1)
📝 src/domain/completionLedgerGeneration.ts (+3 -2)
📝 src/domain/conformancePackage.ts (+2 -1)
➕ src/domain/digests.test.ts (+67 -0)
➕ src/domain/digests.ts (+42 -0)
📝 src/domain/electronObservation.ts (+3 -2)

...and 36 more files

📄 Description

B-1 from the cleanup sweep, and the first of the structural (deepening) items.

What was duplicated

  • 32 local digestSchema definitions — the same z.string().regex(/^[a-f0-9]{64}$/u) re-declared across ~30 modules, plus ~36 further inline uses.
  • ~30 hand-written prefixed-identifier regexes — ev_, art_, jag_, jag_node_, jag_edge_, jsrg_, unk_, project_ and two dozen more, each spelled out as its own literal: 126 regex occurrences in 46 files.
  • One more private isDigest in sourceToBundleSignals, duplicating a check that already existed as a schema.

Nothing enforced agreement between them. Tightening or loosening what counted as a digest meant finding every copy by hand, and a new identifier family could invent its own spelling of "lowercase sha256".

What replaces it

src/domain/digests.ts owns the shapes and nothing else:

  • SHA256_PATTERN for callers that cannot use zod
  • digestSchema for the bare digest
  • prefixedDigestSchema(prefix) — one factory for every identifier family
  • isDigest / isPrefixedDigest predicates

Net -162 lines of duplication across 56 files, with a single place to change the meaning. This is the same shape as #543 and #544: the rule was enforced by convention at each call site, so the fix belongs at the module, not at the call sites.

Note on behaviour

The generated catalog digests are unchanged (mcp-catalog:generate produces no diff), confirming the schemas accept exactly what they did before. The factory also adds a validation message naming the expected prefix, which improves the error text callers already surfaced.

The nested-prefix case is asserted explicitly, because it is the one the factory could plausibly have broken: jag_node_<digest> must not validate as jag_<digest> even though it textually starts with it. It does not, because the prefix is matched as a whole before the underscore.

Tests: digests.test.ts covers the bare digest, the family separation in both directions, the nested-prefix case, and non-string rejection. Full suite green: 1946 passed, typecheck and lint clean.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/547 **Author:** [@morluto](https://github.com/morluto) **Created:** 10/5/2026 **Status:** ✅ Merged **Merged:** 10/5/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `cleanup/digest-schema-module` --- ### 📝 Commits (1) - [`91bafb6`](https://github.com/morluto/rea/commit/91bafb6ef6f0d2f5e9402aec3e2d83dfa79cf11d) refactor(domain): own digest and prefixed identifier shapes in one module ### 📊 Changes **56 files changed** (+314 additions, -162 deletions) <details> <summary>View changed files</summary> 📝 `src/application/ProjectPermissionStore.ts` (+2 -1) 📝 `src/contracts/sessionToolSchemas.ts` (+2 -1) 📝 `src/contracts/toolOutputSchemaPrimitives.ts` (+2 -1) 📝 `src/domain/analysisProfile.ts` (+1 -2) 📝 `src/domain/analysisSnapshot.ts` (+3 -2) 📝 `src/domain/androidApplication.ts` (+5 -4) 📝 `src/domain/appleApplication.ts` (+5 -4) 📝 `src/domain/artifactComparison.ts` (+4 -3) 📝 `src/domain/artifactGraph.ts` (+7 -6) 📝 `src/domain/artifactInspection.ts` (+13 -12) 📝 `src/domain/browserObservationSchemas.ts` (+2 -1) 📝 `src/domain/browserScenarioCaptureValues.ts` (+1 -1) 📝 `src/domain/bundleComparison.ts` (+3 -2) 📝 `src/domain/callPathSchemas.ts` (+2 -1) 📝 `src/domain/changedBehavior.ts` (+2 -1) 📝 `src/domain/completionLedgerGeneration.ts` (+3 -2) 📝 `src/domain/conformancePackage.ts` (+2 -1) ➕ `src/domain/digests.test.ts` (+67 -0) ➕ `src/domain/digests.ts` (+42 -0) 📝 `src/domain/electronObservation.ts` (+3 -2) _...and 36 more files_ </details> ### 📄 Description B-1 from the cleanup sweep, and the first of the structural (deepening) items. ## What was duplicated - **32 local `digestSchema` definitions** — the same `z.string().regex(/^[a-f0-9]{64}$/u)` re-declared across ~30 modules, plus ~36 further inline uses. - **~30 hand-written prefixed-identifier regexes** — `ev_`, `art_`, `jag_`, `jag_node_`, `jag_edge_`, `jsrg_`, `unk_`, `project_` and two dozen more, each spelled out as its own literal: **126 regex occurrences in 46 files**. - One more private `isDigest` in `sourceToBundleSignals`, duplicating a check that already existed as a schema. Nothing enforced agreement between them. Tightening or loosening what counted as a digest meant finding every copy by hand, and a new identifier family could invent its own spelling of "lowercase sha256". ## What replaces it `src/domain/digests.ts` owns the shapes and nothing else: - `SHA256_PATTERN` for callers that cannot use zod - `digestSchema` for the bare digest - `prefixedDigestSchema(prefix)` — one factory for every identifier family - `isDigest` / `isPrefixedDigest` predicates Net -162 lines of duplication across 56 files, with a single place to change the meaning. This is the same shape as #543 and #544: the rule was enforced by convention at each call site, so the fix belongs at the module, not at the call sites. ## Note on behaviour The generated catalog digests are unchanged (`mcp-catalog:generate` produces no diff), confirming the schemas accept exactly what they did before. The factory also adds a validation message naming the expected prefix, which improves the error text callers already surfaced. The nested-prefix case is asserted explicitly, because it is the one the factory could plausibly have broken: `jag_node_<digest>` must **not** validate as `jag_<digest>` even though it textually starts with it. It does not, because the prefix is matched as a whole before the underscore. Tests: `digests.test.ts` covers the bare digest, the family separation in both directions, the nested-prefix case, and non-string rejection. Full suite green: 1946 passed, typecheck and lint clean. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-16 21:13:53 +00:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
morluto/rea#2067
No description provided.