7.6 KiB
Behavioral Equivalence And Shared Abstraction Audit
Reviewed on 2026-11-24 at source revision
be4aebfedc3ded8d834afc0867692bbe448d77b6.
Scope And Method
Reviewed direct comparisons and repeated behavioral assertions in the CLI, HTTP, configuration, and execution-report tests, then traced the corresponding implementations with codebase-memory-mcp and source inspection. Checked the relationships against the architecture and testing policies and the internal adapter/source documentation. Similar syntax alone was not treated as evidence of a common responsibility.
One consolidation opportunity warrants consideration. It confirms the configuration-diagnostics portion of complexity audit finding 2 with behavioral evidence; it is not a second independent defect or a newly demonstrated runtime mismatch. No production code or tests were changed.
Current Architecture
Scriptorium is a thin CLI/HTTP executable. ConfigKit resolves the shared application/PromptKit document; PromptKit owns definitions, preparation, and execution; CommandKit and its integrations own native CLI inspection, presentation, and outcomes. The HTTP adapter adds transport and deployment policy around a shared engine, with an optional per-request terminal report collector. ReleaseKit owns release mechanics. See the component overview, adapter internals, and source internals.
1. Share The CLI Application-Load Diagnostic Bridge
Scope: A private helper within internal/adapter/cli. This is an optional
maintainability improvement, not a reason to introduce a new package or replace
the native acquisition workflow.
Evidence
TestServeListenAndConfigurationFailures, lines 206–235 of lifecycle_test.go, runs bothrunandserveagainst the same malformed imported framework file. Both must return status 2 and surfaceApplication configurationandyaml.invalid. This directly establishes common application-load failure presentation across the two execution paths. It does not require their complete diagnostic output to be byte-identical.TestBootstrapDiagnosticsOnFailure, lines 165–192 of bootstrap_test.go, checks failed loads through application run and native configuration/PromptKit commands. Diagnostics must be present, retain the synthetic credential key name where expected, and omit its secret value. This supports preserving native safe evidence and the existing bootstrap-report route during any extraction; it does not establish a universal sensitive-content filter.TestNativeLoadFailureEvidenceOnComparisonSides, lines 190–205 of native_config_test.go, independently exercises failed left and right comparison selections. It requires the application validation path, the affected side, and exactly onevalidate.error. This bounds the proposed change: native inspection already owns its evidence presentation and should not acquire an additional application diagnostic pass.
Implementation
runPrompt, lines 77–88 of
native_run.go, and
serveWithListener, lines 23–34 of
server.go, repeat the same bridge:
- obtain sources and diagnostics from the returned ConfigKit result;
- prefer evidence from a wrapped
*configkit.LoadErrorwhen present; - call
ckconfig.AdaptDiagnosticswith the application-configuration heading; - queue the adapted diagnostics and retain the explanation for failure output.
Configuration resolution already shares loadApplication; native formatting
already shares ckconfig.AdaptDiagnostics; delivery already shares
queueDiagnostics. The duplicated responsibility is the selection and
adaptation between those existing boundaries, not configuration loading itself.
frameworkFailure, lines 23–31 of
outcomes.go, performs related
LoadError adaptation after engine construction, but uses a different heading
and appends to an existing explanation. Those differences are meaningful;
the run/serve equivalence test does not establish equivalence for that entire
failure path.
Opportunity And Remediation Approaches
The preferred approach is a small private helper accepting the actual typed
ConfigKit result and load error and returning adapted native diagnostics and
an explanation. Call it from runPrompt and serveWithListener; keep queuing
and outcome selection explicit in the callers. This gives evidence selection
and adaptation one maintenance point, reducing the chance that one command
loses findings or handles a wrapped load error differently after a change.
Alternatively, extract just the source/diagnostic selection and leave adaptation
at the call sites. That keeps heading selection visible, but shares less of
the duplicated bridge. Reuse with frameworkFailure is reasonable only if it
stays simple and preserves that caller's distinct heading and explanation
composition; it need not be forced into the same control flow.
Tradeoffs And Boundaries
- A CLI-local helper introduces little new coupling because both callers already depend on the same native types. A cross-adapter package, generic acquisition framework, or universal error classifier would add unnecessary coupling and mix different presentation policies.
- Preserve typed causes, current evidence-selection precedence, and the
existing bootstrap-report path. Do not rebuild an effective document,
reconstruct evidence, cache loads, or move CLI presentation into
internal/config. - Do not make
loadApplicationqueue these diagnostics unconditionally. Native ckconfig/ckprompt consumers already own presentation, including comparison-side context; doing so risks duplicate output. - Keep the command-level tests independent of the extracted helper. They should continue asserting observable outcomes and native evidence rather than calculating expected output with the same helper as production.
- Retaining this short duplication is viable if extraction would require extra configuration or abstractions. The benefit is a single evidence bridge, not fewer lines at any cost. No broader error-classification rewrite is needed to realize it.
Overall Assessment
The tested preparation/execution and native report-rendering relationships already use upstream implementations rather than competing local copies. Application and focused configuration inspection also share the actual load through the native adapters. The review found no additional test-backed opportunity warranting a shared application package. CLI and HTTP decoding, status mapping, artifact-access policy, and report representations retain intentional boundary-specific responsibilities.
Validation And Limits
The following focused tests passed against unchanged application code:
go test -count=1 ./internal/adapter/cli -run 'TestServeListenAndConfigurationFailures|TestBootstrapDiagnosticsOnFailure|TestNativeLoadFailureEvidenceOnComparisonSides|TestNativeScopesAndHelpUseSharedLoading|TestSeparateReportsUseNativeFormats|TestMaintainedCollectionWorkflow'
The audit used existing tests and real internal collaborators with controlled local provider boundaries. It did not add tests, mutate implementations, or exhaustively compare all input combinations. Findings are opportunities for review, not new contracts or a guarantee that no other duplication exists.