Compare commits
30 Commits
integratio
...
integratio
| Author | SHA1 | Date | |
|---|---|---|---|
| 29694ea874 | |||
| 5905399ef3 | |||
| 6b9ccbf88b | |||
| 35e100fd94 | |||
| b1e7c1ee09 | |||
| 3112068722 | |||
| 49fee9f8ee | |||
| 70b3818351 | |||
| 46d63de913 | |||
| d107b1235a | |||
| 8513949c20 | |||
| bf45a3fe2c | |||
| 263dc420b4 | |||
| 6c7d7c90de | |||
| 735b35a0a1 | |||
| 21dac4f89e | |||
| 9b673d0485 | |||
| 8a22dd6a4f | |||
| 20d2924338 | |||
| 2bd216f0d3 | |||
| 1c531e7109 | |||
| b9cede22f9 | |||
| 9d3ffff69f | |||
| a53bf9f916 | |||
| ed6060f344 | |||
| 1e92a87706 | |||
| f369d6a782 | |||
| 64f6453b84 | |||
| 07a329033c | |||
| 1ca660e35f |
83
docs/cli.md
83
docs/cli.md
@@ -477,8 +477,8 @@ records preserve their returned order. No records are
|
|||||||
output begins with the scope heading and prints the same source fields,
|
output begins with the scope heading and prints the same source fields,
|
||||||
quoting labels and paths. These fields come from ConfigKit's source records;
|
quoting labels and paths. These fields come from ConfigKit's source records;
|
||||||
producing the report does not reload files or rerun version checks. See the
|
producing the report does not reload files or rerun version checks. See the
|
||||||
[ConfigKit v1.1.0 source
|
[ConfigKit v1.2.0 source
|
||||||
records](https://forge.maximumdirect.net/base-layer/configkit/src/commit/191015e289d7f2b91abb9fdd9c4f2f5cf75b4de9/records.go)
|
records](https://forge.maximumdirect.net/base-layer/configkit/src/commit/c1c7e87f2cdf77a0cbf3327831ac05578e756b9e/records.go)
|
||||||
for native evidence definitions.
|
for native evidence definitions.
|
||||||
|
|
||||||
### Explain a configuration path
|
### Explain a configuration path
|
||||||
@@ -622,8 +622,9 @@ fields remain distinct.
|
|||||||
|
|
||||||
Without `--check`, successful comparisons return status `0`, including empty
|
Without `--check`, successful comparisons return status `0`, including empty
|
||||||
results. Unsupported scopes and formats are usage errors. Application input
|
results. Unsupported scopes and formats are usage errors. Application input
|
||||||
checks can report usage or operational failures. Load and comparison failures
|
checks can report usage or operational failures. Configuration load failures
|
||||||
use status `1`.
|
follow the [configuration failure classification](#configuration-failure-classification);
|
||||||
|
other comparison failures use status `1`.
|
||||||
|
|
||||||
The bundled adapters load the left side before the right. Diagnostics identify
|
The bundled adapters load the left side before the right. Diagnostics identify
|
||||||
the side and its sources; left-side diagnostics are retained if right loading
|
the side and its sources; left-side diagnostics are retained if right loading
|
||||||
@@ -665,9 +666,10 @@ request overrides. Backend reports describe configured backend fields. An
|
|||||||
`api_key_env` value names an environment variable; it is not a credential
|
`api_key_env` value names an environment variable; it is not a credential
|
||||||
value or a claim that one is available. Neither report resolves references or
|
value or a claim that one is available. Neither report resolves references or
|
||||||
performs a network probe. See the [PromptKit resource inspection
|
performs a network probe. See the [PromptKit resource inspection
|
||||||
contracts](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/resource_inspection.go).
|
contracts](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/resource_inspection.go).
|
||||||
Omitting the ID is a usage error. Lookup failures and cancellation follow the
|
Omitting the ID is a usage error. Configuration loading follows the
|
||||||
shared operational failure rules.
|
[configuration failure classification](#configuration-failure-classification);
|
||||||
|
lookup failures and cancellation are operational.
|
||||||
|
|
||||||
### Resource namespace selection
|
### Resource namespace selection
|
||||||
|
|
||||||
@@ -720,8 +722,10 @@ text output use YAML. Preparation can read resources and include rendered
|
|||||||
application content in the report. It does not guarantee that a later model
|
application content in the report. It does not guarantee that a later model
|
||||||
call will succeed. Application loaders and callbacks may have their own
|
call will succeed. Application loaders and callbacks may have their own
|
||||||
effects. The [PromptKit Prepare
|
effects. The [PromptKit Prepare
|
||||||
API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/engine.go)
|
API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/engine.go)
|
||||||
owns the prepared value and upstream preparation behavior.
|
owns the prepared value and upstream preparation behavior. Configuration failures
|
||||||
|
follow the [configuration failure classification](#configuration-failure-classification);
|
||||||
|
other preparation failures are operational.
|
||||||
|
|
||||||
## PromptKit requirements
|
## PromptKit requirements
|
||||||
|
|
||||||
@@ -754,8 +758,8 @@ identity rather than changing the discovered requirements. An enabled profile
|
|||||||
namespace qualifies an explicitly supplied short profile ID; it does not
|
namespace qualifies an explicitly supplied short profile ID; it does not
|
||||||
rewrite the prompt's stored default reference. Requirements inspection does
|
rewrite the prompt's stored default reference. Requirements inspection does
|
||||||
not require the selected profile to be execution-ready. See the [PromptKit
|
not require the selected profile to be execution-ready. See the [PromptKit
|
||||||
v0.20.0 consumer
|
v0.23.1 consumer
|
||||||
guide](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/docs/consumers/pkg-promptkit.md)
|
guide](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/consumers/pkg-promptkit.md)
|
||||||
for configuration, selection, and requirements behavior. For built-in flags
|
for configuration, selection, and requirements behavior. For built-in flags
|
||||||
other than `--llm-var`, repeating a flag uses its last value.
|
other than `--llm-var`, repeating a flag uses its last value.
|
||||||
Application-defined flags follow their own repetition rules.
|
Application-defined flags follow their own repetition rules.
|
||||||
@@ -806,9 +810,10 @@ issues:
|
|||||||
PromptKit determines these findings and explanations. A partial report can
|
PromptKit determines these findings and explanations. A partial report can
|
||||||
still be a successful command result (status `0`); read `complete` and
|
still be a successful command result (status `0`); read `complete` and
|
||||||
`issues` to understand what remains unknown. A reported issue alone does not
|
`issues` to understand what remains unknown. A reported issue alone does not
|
||||||
fail this command. Load or selection failures, cancellation, and report
|
fail this command. Configuration loading follows the [configuration failure
|
||||||
delivery failures use status `1`. Invalid syntax, arguments, variable
|
classification](#configuration-failure-classification). Selection failures and
|
||||||
assignments, or formats use status `2`.
|
cancellation use status `1`; invalid syntax, arguments, variable assignments,
|
||||||
|
or formats use status `2`. Report delivery follows the [output failure rules](#output-failures).
|
||||||
|
|
||||||
### Concrete request validation
|
### Concrete request validation
|
||||||
|
|
||||||
@@ -865,9 +870,11 @@ applicable. It does not make a model call or retain a prepared execution
|
|||||||
snapshot. A successful report describes this preparation invocation; it does
|
snapshot. A successful report describes this preparation invocation; it does
|
||||||
not certify provider acceptance or guarantee later execution. See PromptKit's
|
not certify provider acceptance or guarantee later execution. See PromptKit's
|
||||||
[`Engine.ValidateRequest`
|
[`Engine.ValidateRequest`
|
||||||
API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/engine.go).
|
API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/engine.go).
|
||||||
|
|
||||||
Request construction, engine loading, and validation failures use status `1`,
|
Configuration errors returned by request construction or engine loading follow
|
||||||
|
the [configuration failure classification](#configuration-failure-classification).
|
||||||
|
Other request construction, loading, and validation failures use status `1`,
|
||||||
retaining available diagnostics. Malformed syntax, missing arguments, and
|
retaining available diagnostics. Malformed syntax, missing arguments, and
|
||||||
unsupported formats use status `2`. Messages follow the common reporting
|
unsupported formats use status `2`. Messages follow the common reporting
|
||||||
policy; report delivery failures follow the shared [output failure
|
policy; report delivery failures follow the shared [output failure
|
||||||
@@ -929,9 +936,10 @@ The entries are:
|
|||||||
A catalog result is an inventory, not a readiness check or execution result.
|
A catalog result is an inventory, not a readiness check or execution result.
|
||||||
The owning provider controls membership and order. Namespace filters are
|
The owning provider controls membership and order. Namespace filters are
|
||||||
passed to PromptKit without local membership interpretation. See the
|
passed to PromptKit without local membership interpretation. See the
|
||||||
[PromptKit v0.20.0 consumer
|
[PromptKit v0.23.1 consumer
|
||||||
guide](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/docs/consumers/pkg-promptkit.md)
|
guide](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/consumers/pkg-promptkit.md)
|
||||||
for resource and selection definitions.
|
for resource and selection definitions. Catalog loading failures follow the
|
||||||
|
[configuration failure classification](#configuration-failure-classification).
|
||||||
|
|
||||||
## PromptKit smoke testing
|
## PromptKit smoke testing
|
||||||
|
|
||||||
@@ -965,10 +973,13 @@ Status `0` means the requested operation and reporting completed without
|
|||||||
error. It does not mean every check passed: inspect the reported facts,
|
error. It does not mean every check passed: inspect the reported facts,
|
||||||
`reason`, and whether the test was supported, applicable, and completed. For
|
`reason`, and whether the test was supported, applicable, and completed. For
|
||||||
`all`, all four operations must return without error for status `0`.
|
`all`, all four operations must return without error for status `0`.
|
||||||
Individual errors use status `1`; the sequence continues after them but stops
|
Configuration errors use the [configuration failure classification](#configuration-failure-classification);
|
||||||
on cancellation, preserving results already obtained. A report returned with
|
other individual errors use status `1`. For `all`, every failing operation must
|
||||||
an error is still shown. Invalid syntax, arguments, formats, or conflicting
|
identify invalid configuration input to select status `2`; an operational
|
||||||
namespace flags use status `2`.
|
failure or cancellation takes precedence. The sequence continues after errors
|
||||||
|
but stops on cancellation, preserving results already obtained. A report
|
||||||
|
returned with an error is still shown. Invalid syntax, arguments, formats, or
|
||||||
|
conflicting namespace flags use status `2`.
|
||||||
|
|
||||||
### Smoke-test flags
|
### Smoke-test flags
|
||||||
|
|
||||||
@@ -1097,19 +1108,35 @@ separately from delivery failures through the [reporting
|
|||||||
API](consumers/guide.md#invocation-reporting).
|
API](consumers/guide.md#invocation-reporting).
|
||||||
|
|
||||||
Native configuration, selection, and diagnostic meanings remain owned by
|
Native configuration, selection, and diagnostic meanings remain owned by
|
||||||
PromptKit. See the [v0.20.0 consumer guide](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/docs/consumers/pkg-promptkit.md),
|
PromptKit. See the [v0.23.1 consumer guide](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/consumers/pkg-promptkit.md),
|
||||||
[smoke API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/smoke_diagnostics.go),
|
[smoke API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/smoke_diagnostics.go),
|
||||||
and [engine API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/engine.go).
|
and [engine API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/engine.go).
|
||||||
|
|
||||||
## Outcome status
|
## Outcome status
|
||||||
|
|
||||||
| Status | Standard meaning |
|
| Status | Standard meaning |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `0` | The operation succeeded. |
|
| `0` | The operation succeeded. |
|
||||||
| `1` | Loading, execution, cancellation, or output failed. |
|
| `1` | An operational loading or execution failure, cancellation, or output failure occurred. |
|
||||||
| `2` | The command syntax or supplied inputs were invalid. |
|
| `2` | The command syntax, supplied inputs, or identifiable configuration input were invalid. |
|
||||||
| `3` | `config diff --check` found differences. |
|
| `3` | `config diff --check` found differences. |
|
||||||
|
|
||||||
|
### Configuration failure classification
|
||||||
|
|
||||||
|
Standard configuration and PromptKit commands classify ConfigKit loading errors
|
||||||
|
using their structured diagnostics. Identifiable invalid configuration input,
|
||||||
|
including malformed YAML, decoding errors, and explicit semantic rejection,
|
||||||
|
selects status `2`. Warnings do not fail a load. Missing or unreadable sources,
|
||||||
|
schema and application wiring errors, callback failures, unknown or ambiguous
|
||||||
|
diagnostics, and other failures select status `1`. An error with multiple
|
||||||
|
failing branches selects status `2` only when every branch identifies invalid
|
||||||
|
input; cancellation or a deadline always selects status `1`. Existing source
|
||||||
|
and validation reports can still be delivered after a failed load. Filters on
|
||||||
|
validation details do not change classification.
|
||||||
|
With the current ckprompt candidate, malformed PromptKit companion YAML from
|
||||||
|
engine construction follows this same classification, with available diagnostics
|
||||||
|
and typed causes retained.
|
||||||
|
|
||||||
Applications may define additional results and decide how CommandKit's status
|
Applications may define additional results and decide how CommandKit's status
|
||||||
maps to the process exit code. A command's successful status does not replace
|
maps to the process exit code. A command's successful status does not replace
|
||||||
reading its report: partial requirements discovery and unsupported smoke
|
reading its report: partial requirements discovery and unsupported smoke
|
||||||
|
|||||||
@@ -14,28 +14,46 @@ applications.
|
|||||||
| `go.maximumdirect.net/ckconfig` | You want operators to view, validate, explain, and compare ConfigKit configuration. |
|
| `go.maximumdirect.net/ckconfig` | You want operators to view, validate, explain, and compare ConfigKit configuration. |
|
||||||
| `go.maximumdirect.net/ckprompt` | You want operators to inspect PromptKit resources, check and preview requests, or run smoke tests. |
|
| `go.maximumdirect.net/ckprompt` | You want operators to inspect PromptKit resources, check and preview requests, or run smoke tests. |
|
||||||
|
|
||||||
The following lists the current release set and earlier module combinations:
|
The v0.8.0 integrations select ConfigKit v1.2.0, and ckprompt selects PromptKit
|
||||||
|
v0.21.0.
|
||||||
|
|
||||||
| Selection | Core | ckconfig | ckprompt | Upstream libraries and status |
|
| Selection | Core | ckconfig | ckprompt | Upstream libraries and status |
|
||||||
| --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- |
|
||||||
| Published core | v0.6.0 | — | — | Usable independently. |
|
| Published core | v0.6.0 | — | — | Usable independently. |
|
||||||
| ConfigKit integration | v0.6.0 | v0.6.0 | — | ConfigKit v1.1.0. |
|
| ConfigKit integration | v0.6.0 | v0.8.0 | — | ConfigKit v1.2.0. |
|
||||||
| PromptKit integration | v0.5.0 | v0.5.0 | v0.5.0 | ConfigKit v1.1.0 and PromptKit v0.20.0. |
|
| PromptKit integration | v0.6.0 | v0.8.0 | v0.8.0 | ConfigKit v1.2.0 and PromptKit v0.21.0. |
|
||||||
| Earlier matched integration set | v0.3.0 | v0.2.0 | v0.2.0 | ConfigKit v0.8.0 and PromptKit v0.16.0, using their earlier import paths. |
|
| Earlier matched integration set | v0.3.0 | v0.2.0 | v0.2.0 | ConfigKit v0.8.0 and PromptKit v0.16.0, using their earlier import paths. |
|
||||||
|
|
||||||
|
The prepared ckprompt v0.9.0 candidate selects core v0.6.0, ckconfig v0.8.0,
|
||||||
|
ConfigKit v1.2.0, and PromptKit v0.23.1. It is not yet published.
|
||||||
|
For applications moving from ckprompt v0.8.0, the
|
||||||
|
[v0.9.0 upgrade notes](../../integrations/ckprompt/docs/releases/v0.9.0.md#compatibility-and-upgrade)
|
||||||
|
cover migration of positional literals for affected native PromptKit structs.
|
||||||
|
|
||||||
Install the published core with:
|
Install the published core with:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go get go.maximumdirect.net/commandkit@v0.6.0
|
go get go.maximumdirect.net/commandkit@v0.6.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Select either integration with `go get go.maximumdirect.net/ckconfig@v0.6.0`
|
Select either integration with `go get go.maximumdirect.net/ckconfig@v0.8.0`
|
||||||
or `go get go.maximumdirect.net/ckprompt@v0.5.0`. The integrations select core
|
or `go get go.maximumdirect.net/ckprompt@v0.8.0`. The published integrations
|
||||||
v0.6.0 for ckconfig and v0.5.0 for ckprompt; ckprompt selects ckconfig v0.5.0,
|
select core v0.6.0. ckprompt v0.8.0 selects ckconfig v0.8.0, which includes
|
||||||
which includes `AdaptDiagnostics`.
|
`AdaptDiagnostics` and `ClassifyConfigurationError`. Both integrations build
|
||||||
They build independently against these released dependencies; a local workspace
|
independently against their released dependencies. An aligned workspace can
|
||||||
is optional for development. Published ckconfig v0.3.0 also uses ConfigKit v1.1.0
|
exercise the local sources together during development.
|
||||||
and does not compose with ckprompt v0.2.0's earlier ConfigKit dependency.
|
Published ckconfig v0.3.0 also uses ConfigKit v1.1.0 and does not compose with
|
||||||
|
ckprompt v0.2.0's earlier ConfigKit dependency.
|
||||||
|
|
||||||
|
ConfigKit v1.2.0 adds fields to `Input` and `LayeredOptions`, so application
|
||||||
|
loaders should use keyed struct literals when constructing them. ConfigKit's
|
||||||
|
release notes describe
|
||||||
|
main-relative imports and overlay contexts. [ConfigKit v1.2.0 upgrade guidance](https://forge.maximumdirect.net/base-layer/configkit/src/tag/v1.2.0/docs/releases/v1.2.0.md#upgrade-notes).
|
||||||
|
|
||||||
|
The current checkout selects PromptKit v0.23.1, which exposes main-relative
|
||||||
|
companion imports through its existing configuration-source API. Applications
|
||||||
|
select those inputs when constructing
|
||||||
|
the engine supplied to ckprompt's loader callback. [PromptKit companion import guidance](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/consumers/pkg-promptkit.md#load-companion-prompts-relative-to-the-main-configuration).
|
||||||
|
|
||||||
Importing a module does not install its commands. Pass commands to
|
Importing a module does not install its commands. Pass commands to
|
||||||
`commandkit.New` or `App.Register` explicitly. ckprompt depends on ckconfig's
|
`commandkit.New` or `App.Register` explicitly. ckprompt depends on ckconfig's
|
||||||
@@ -311,6 +329,10 @@ acquired evidence. See `EffectiveWriter` and `ExplanationReader` in the
|
|||||||
[ckconfig GoDoc](../../integrations/ckconfig/contracts.go) for the provider boundary.
|
[ckconfig GoDoc](../../integrations/ckconfig/contracts.go) for the provider boundary.
|
||||||
`ckconfig.AdaptDiagnostics` captures native diagnostic presentation evidence
|
`ckconfig.AdaptDiagnostics` captures native diagnostic presentation evidence
|
||||||
for applications providing their own ConfigKit-backed CLI integration.
|
for applications providing their own ConfigKit-backed CLI integration.
|
||||||
|
[`ckconfig.ClassifyConfigurationError`](../../integrations/ckconfig/errors.go)
|
||||||
|
provides the standard CLI outcome classification for ConfigKit errors; callers
|
||||||
|
construct their own outcomes, explanations, and causes. The [CLI reference](../cli.md#configuration-failure-classification)
|
||||||
|
describes the standard commands' status behavior.
|
||||||
Set `Scope.Features.Overrides` only when the loader passes
|
Set `Scope.Features.Overrides` only when the loader passes
|
||||||
`Selection.Overrides` to ConfigKit as part of its normal load. The integration
|
`Selection.Overrides` to ConfigKit as part of its normal load. The integration
|
||||||
parses CLI records but cannot add them to an already-loaded result. The
|
parses CLI records but cannot add them to an already-loaded result. The
|
||||||
@@ -400,6 +422,12 @@ and state. `FromEngine` uses PromptKit's public listing and inspection methods,
|
|||||||
including `Engine.InspectRequirements`; validation must be opted into separately
|
including `Engine.InspectRequirements`; validation must be opted into separately
|
||||||
and uses `Engine.ValidateRequest`.
|
and uses `Engine.ValidateRequest`.
|
||||||
|
|
||||||
|
Applications own engine construction and may build complete native requests in
|
||||||
|
callbacks. Preparation and validation use the supplied context; execution owns
|
||||||
|
prepared notifications and operation timeouts. See the [PromptKit consumer
|
||||||
|
guide](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/consumers/pkg-promptkit.md)
|
||||||
|
for conversation and execution capabilities.
|
||||||
|
|
||||||
`ckprompt.WithRequestPreparation` adds a separate callback backed by
|
`ckprompt.WithRequestPreparation` adds a separate callback backed by
|
||||||
`Engine.Prepare`. Its optional builder receives the seeded request and returns
|
`Engine.Prepare`. Its optional builder receives the seeded request and returns
|
||||||
the complete request to prepare. The resulting native report can contain
|
the complete request to prepare. The resulting native report can contain
|
||||||
@@ -460,7 +488,7 @@ These are independent defaults for unqualified caller-supplied prompt, profile,
|
|||||||
and backend names; qualified IDs pass through. Stored references and configuration
|
and backend names; qualified IDs pass through. Stored references and configuration
|
||||||
inspection are unchanged, while namespace and collection inventories remain global.
|
inspection are unchanged, while namespace and collection inventories remain global.
|
||||||
Catalog `--namespace` filters are separate from these defaults. See the released
|
Catalog `--namespace` filters are separate from these defaults. See the released
|
||||||
[namespace API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/namespaces.go).
|
[namespace API](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/namespaces.go).
|
||||||
|
|
||||||
## Outcomes and ownership
|
## Outcomes and ownership
|
||||||
|
|
||||||
@@ -474,8 +502,8 @@ signal handling, and exit mapping; `Execute` never exits the process.
|
|||||||
Go declarations and GoDoc own exact exported contracts. ConfigKit owns
|
Go declarations and GoDoc own exact exported contracts. ConfigKit owns
|
||||||
configuration decoding, validation, and provenance. PromptKit owns prompt
|
configuration decoding, validation, and provenance. PromptKit owns prompt
|
||||||
formats, profile resolution, and inspection details. See the
|
formats, profile resolution, and inspection details. See the
|
||||||
[ConfigKit v1.1.0 source records](https://forge.maximumdirect.net/base-layer/configkit/src/commit/191015e289d7f2b91abb9fdd9c4f2f5cf75b4de9/records.go),
|
[ConfigKit v1.2.0 source records](https://forge.maximumdirect.net/base-layer/configkit/src/commit/c1c7e87f2cdf77a0cbf3327831ac05578e756b9e/records.go),
|
||||||
[PromptKit engine methods](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/engine.go),
|
[PromptKit engine methods](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/engine.go),
|
||||||
[configuration inspection](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/configuration_inspection.go),
|
[configuration inspection](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/configuration_inspection.go),
|
||||||
[smoke diagnostics](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/smoke_diagnostics.go),
|
[smoke diagnostics](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/smoke_diagnostics.go),
|
||||||
and [PromptKit v0.20.0 consumer guidance](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/docs/consumers/pkg-promptkit.md).
|
and [PromptKit v0.23.1 consumer guidance](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/consumers/pkg-promptkit.md).
|
||||||
|
|||||||
@@ -118,14 +118,12 @@ go work init . ./integrations/ckconfig ./integrations/ckprompt
|
|||||||
If a workspace already exists, ensure it includes these three modules. Preserve
|
If a workspace already exists, ensure it includes these three modules. Preserve
|
||||||
the ignored `go.work` and `go.work.sum`; do not commit them. Use
|
the ignored `go.work` and `go.work.sum`; do not commit them. Use
|
||||||
`GOWORK=off GOTOOLCHAIN=local` for dependency preparation
|
`GOWORK=off GOTOOLCHAIN=local` for dependency preparation
|
||||||
and independent module suites. ckconfig selects released core v0.6.0 and
|
and independent module suites. Both integrations select released core v0.6.0;
|
||||||
ckprompt selects core v0.5.0;
|
ckprompt also selects released ckconfig v0.8.0. Both integrations support
|
||||||
ckprompt also selects released ckconfig v0.5.0. Their declared dependencies
|
independent builds against their published dependencies. The aligned workspace
|
||||||
support independent builds. The aligned workspace exercises the local sources
|
exercises the local sources together.
|
||||||
together.
|
|
||||||
Run `GOWORK=off GOTOOLCHAIN=local go test ./...` separately from each module
|
Run `GOWORK=off GOTOOLCHAIN=local go test ./...` separately from each module
|
||||||
directory. From the repository root, a workspace containing all three modules can
|
directory. From the repository root, a workspace containing all three modules can also run:
|
||||||
also run:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
GOTOOLCHAIN=local go test ./...
|
GOTOOLCHAIN=local go test ./...
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Future work
|
# Future work
|
||||||
|
|
||||||
Status: optional shell validation and future capability proposals.
|
Status — optional shell validation and future capability proposals.
|
||||||
No delivery dates are selected here.
|
No delivery dates are selected here.
|
||||||
|
|
||||||
## Purpose and authority
|
## Purpose and authority
|
||||||
@@ -25,6 +25,13 @@ and remediation records remain available at the
|
|||||||
[Earlier retired records](https://gitea.maximumdirect.net/eric/CommandKit/src/commit/6bc37e7ba64ca0920b4d0cc77039a18d4006b24e/docs/roadmap)
|
[Earlier retired records](https://gitea.maximumdirect.net/eric/CommandKit/src/commit/6bc37e7ba64ca0920b4d0cc77039a18d4006b24e/docs/roadmap)
|
||||||
also remain in Git history. Completed records are not assignments to restart work.
|
also remain in Git history. Completed records are not assignments to restart work.
|
||||||
|
|
||||||
|
The completed configuration-outcome implementation and remediation are preserved
|
||||||
|
in the [v0.8.0 retirement snapshot](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/6c7d7c90de4deea8be38b2a447b5c957d748d1b0/docs/roadmap).
|
||||||
|
The completed PromptKit v0.23.1 adoption, companion-YAML report, and
|
||||||
|
verification evidence are preserved in the [adoption snapshot](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/b1e7c1ee09bf4fb7845b3b5222ccb448ac7fb468/docs/roadmap).
|
||||||
|
The completed adoption review and upgrade-guidance remediation are preserved
|
||||||
|
in the [remediation snapshot](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/5905399ef3b23ee405bb31a50e534b139cef2e05/docs/roadmap/remediation.md).
|
||||||
|
|
||||||
Accepted [ADRs](../adr/) and the [architecture policy](../policy/architecture.md)
|
Accepted [ADRs](../adr/) and the [architecture policy](../policy/architecture.md)
|
||||||
govern any future implementation. The [CLI reference](../cli.md), public GoDoc,
|
govern any future implementation. The [CLI reference](../cli.md), public GoDoc,
|
||||||
and [consumer guide](../consumers/guide.md) own implemented behavior. Retaining
|
and [consumer guide](../consumers/guide.md) own implemented behavior. Retaining
|
||||||
|
|||||||
119
integrations/ckconfig/config_outcomes_test.go
Normal file
119
integrations/ckconfig/config_outcomes_test.go
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
package ckconfig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNativeConfigurationInputOutcomes(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("malformed-input", []byte("broken: [")))
|
||||||
|
var native *configkit.LoadError
|
||||||
|
if !errors.As(loadErr, &native) || len(native.Diagnostics()) == 0 {
|
||||||
|
t.Fatalf("fixture: %v", loadErr)
|
||||||
|
}
|
||||||
|
wrapped := fmt.Errorf("application loader: %w", loadErr)
|
||||||
|
app := newConfigTestApp(t, AppCommand(func(context.Context, Selection) (*configkit.Result[map[string]any], error) { return nil, wrapped }))
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
report string
|
||||||
|
}{
|
||||||
|
{"show", []string{"config", "show"}, ""},
|
||||||
|
{"sources", []string{"config", "sources", "--format=json"}, `"sources"`},
|
||||||
|
{"validation", []string{"config", "validate", "--details", "--format=json"}, `"code": "yaml.invalid"`},
|
||||||
|
{"filtered validation", []string{"config", "validate", "--details", "--code=not-selected", "--format=json"}, `"state": "filtered"`},
|
||||||
|
{"discovery", []string{"config", "explain", "--list"}, ""},
|
||||||
|
{"diff", []string{"config", "diff"}, ""},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
var out, diag bytes.Buffer
|
||||||
|
result := app.Execute(context.Background(), tc.args, commandkit.Streams{Out: &out, Err: &diag})
|
||||||
|
var got *configkit.LoadError
|
||||||
|
if result.Kind != commandkit.OutcomeUsage || result.Status != 2 || !errors.Is(result.Cause, loadErr) || !errors.As(result.Cause, &got) || got != native {
|
||||||
|
t.Fatalf("outcome: %#v", result)
|
||||||
|
}
|
||||||
|
if !strings.Contains(diag.String(), native.Diagnostics()[0].Message) || !strings.Contains(diag.String(), "malformed-input") {
|
||||||
|
t.Fatalf("diagnostics: %q", diag.String())
|
||||||
|
}
|
||||||
|
if tc.report != "" && !strings.Contains(out.String(), tc.report) {
|
||||||
|
t.Fatalf("report: %q", out.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNativeConfigurationComparisonFailureSides(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("bad-side", []byte("broken: [")))
|
||||||
|
for _, bad := range []string{"left", "right"} {
|
||||||
|
t.Run(bad, func(t *testing.T) {
|
||||||
|
app := newConfigTestApp(t, AppCommand(func(_ context.Context, selection Selection) (*configkit.Result[map[string]any], error) {
|
||||||
|
if selection.Config.Value == bad {
|
||||||
|
return nil, fmt.Errorf("wrapped: %w", loadErr)
|
||||||
|
}
|
||||||
|
return configkit.Load[map[string]any](configkit.Bytes("good-side", []byte("ok: true")))
|
||||||
|
}))
|
||||||
|
var diag bytes.Buffer
|
||||||
|
result := app.Execute(context.Background(), []string{"config", "diff", "--config=left", "--against-config=right"}, commandkit.Streams{Out: io.Discard, Err: &diag})
|
||||||
|
if result.Kind != commandkit.OutcomeUsage || result.Status != 2 || !errors.Is(result.Cause, loadErr) || !strings.Contains(diag.String(), "bad-side") || !strings.Contains(diag.String(), bad) {
|
||||||
|
t.Fatalf("outcome=%#v diagnostics=%q", result, diag.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigurationFailureCancellationAndDelivery(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("bad-input", []byte("broken: [")))
|
||||||
|
for _, args := range [][]string{{"config", "show"}, {"config", "sources"}, {"config", "validate"}, {"config", "explain", "--list"}, {"config", "diff"}} {
|
||||||
|
t.Run(strings.Join(args, "_"), func(t *testing.T) {
|
||||||
|
calls := 0
|
||||||
|
app := newConfigTestApp(t, AppCommand(func(context.Context, Selection) (*configkit.Result[map[string]any], error) {
|
||||||
|
calls++
|
||||||
|
return nil, loadErr
|
||||||
|
}))
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
var out bytes.Buffer
|
||||||
|
result := app.Execute(ctx, args, commandkit.Streams{Out: &out, Err: io.Discard})
|
||||||
|
if result.Status != 1 || !errors.Is(result.Cause, context.Canceled) || calls != 0 || out.Len() != 0 {
|
||||||
|
t.Fatalf("outcome=%#v calls=%d output=%q", result, calls, out.String())
|
||||||
|
}
|
||||||
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
app = newConfigTestApp(t, AppCommand(func(context.Context, Selection) (*configkit.Result[map[string]any], error) {
|
||||||
|
cancel()
|
||||||
|
return nil, loadErr
|
||||||
|
}))
|
||||||
|
result = app.Execute(ctx, args, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||||
|
if result.Status != 1 || !errors.Is(result.Cause, context.Canceled) || !errors.Is(result.Cause, loadErr) {
|
||||||
|
t.Fatalf("joined outcome=%#v", result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
app := newConfigTestApp(t, AppCommand(func(context.Context, Selection) (*configkit.Result[map[string]any], error) { return nil, loadErr }))
|
||||||
|
for _, args := range [][]string{{"config", "sources"}, {"config", "validate"}} {
|
||||||
|
result := app.Execute(context.Background(), args, commandkit.Streams{Out: shortWriter{}, Err: io.Discard})
|
||||||
|
if result.Kind != commandkit.OutcomeOperational || result.Status != 1 || !errors.Is(result.Cause, loadErr) || result.Presentation.Output.State != commandkit.DeliveryIncomplete {
|
||||||
|
t.Fatalf("delivery %v: %#v", args, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigurationOperationalFailures(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.File("/nonexistent-commandkit-outcome-test"))
|
||||||
|
for _, failure := range []error{errors.New("unavailable"), loadErr} {
|
||||||
|
app := newConfigTestApp(t, AppCommand(func(context.Context, Selection) (*configkit.Result[map[string]any], error) { return nil, failure }))
|
||||||
|
result := app.Execute(context.Background(), []string{"config", "show"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||||
|
if result.Status != 1 || !errors.Is(result.Cause, failure) {
|
||||||
|
t.Fatalf("outcome=%#v", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,25 +10,25 @@ import (
|
|||||||
func runConfigDiff[I, S any](invocation commandkit.Invocation, plan *configOperationPlan[I, S], state S) commandkit.Outcome {
|
func runConfigDiff[I, S any](invocation commandkit.Invocation, plan *configOperationPlan[I, S], state S) commandkit.Outcome {
|
||||||
if plan.comparison == nil || plan.comparison.scope == nil {
|
if plan.comparison == nil || plan.comparison.scope == nil {
|
||||||
cause := errors.New("configuration comparison was not prepared")
|
cause := errors.New("configuration comparison was not prepared")
|
||||||
return configFailure("Configuration comparison was not prepared.", commandkit.Explanation{}, cause)
|
return configFailure(invocation.Context, "Configuration comparison was not prepared.", commandkit.Explanation{}, cause)
|
||||||
}
|
}
|
||||||
selected := plan.comparison
|
selected := plan.comparison
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration comparison was canceled.", commandkit.Explanation{}, err)
|
return configFailure(invocation.Context, "Configuration comparison was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
compare := selected.scope.scope.Compare
|
compare := selected.scope.scope.Compare
|
||||||
if compare == nil {
|
if compare == nil {
|
||||||
cause := fmt.Errorf("configuration scope %q has no comparison callback", selected.scope.scope.Name)
|
cause := fmt.Errorf("configuration scope %q has no comparison callback", selected.scope.scope.Name)
|
||||||
return configFailure("Configuration scope does not support comparison.", commandkit.Explanation{}, cause)
|
return configFailure(invocation.Context, "Configuration scope does not support comparison.", commandkit.Explanation{}, cause)
|
||||||
}
|
}
|
||||||
acquired, err := compare(invocation.Context, selected.request, state)
|
acquired, err := compare(invocation.Context, selected.request, state)
|
||||||
reporter := invocation.Reporter()
|
reporter := invocation.Reporter()
|
||||||
queueConfigDiagnostics(reporter, acquired.Diagnostics)
|
queueConfigDiagnostics(reporter, acquired.Diagnostics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return configFailure(fmt.Sprintf("Unable to compare configuration scope %q.", selected.scope.scope.Name), acquired.Explanation, err)
|
return configFailure(invocation.Context, fmt.Sprintf("Unable to compare configuration scope %q.", selected.scope.scope.Name), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration comparison was canceled.", acquired.Explanation, err)
|
return configFailure(invocation.Context, "Configuration comparison was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
outcome := renderPreparedConfigReport(invocation, acquired.Explanation, func() (any, error) {
|
outcome := renderPreparedConfigReport(invocation, acquired.Explanation, func() (any, error) {
|
||||||
if plan.details {
|
if plan.details {
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
## ConfigKit
|
## ConfigKit
|
||||||
|
|
||||||
Selected module: `go.maximumdirect.net/configkit` at `v1.1.0`.
|
Selected module: `go.maximumdirect.net/configkit` at `v1.2.0`.
|
||||||
|
|
||||||
Copyright (C) 2026 Eric Rakestraw
|
Copyright (C) 2026 Eric Rakestraw
|
||||||
|
|
||||||
SPDX-License-Identifier: LGPL-3.0-or-later
|
SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
License and notices: [LGPL v3.0](../../LICENSE) |
|
License and notices: [LGPL v3.0](../../LICENSE) |
|
||||||
[LICENSE](https://forge.maximumdirect.net/base-layer/configkit/src/commit/191015e289d7f2b91abb9fdd9c4f2f5cf75b4de9/LICENSE).
|
[LICENSE](https://forge.maximumdirect.net/base-layer/configkit/src/commit/c1c7e87f2cdf77a0cbf3327831ac05578e756b9e/LICENSE).
|
||||||
|
|
||||||
[Source](https://forge.maximumdirect.net/base-layer/configkit/src/commit/191015e289d7f2b91abb9fdd9c4f2f5cf75b4de9).
|
[Source](https://forge.maximumdirect.net/base-layer/configkit/src/commit/c1c7e87f2cdf77a0cbf3327831ac05578e756b9e).
|
||||||
|
|
||||||
## go-yaml v4
|
## go-yaml v4
|
||||||
|
|
||||||
|
|||||||
20
integrations/ckconfig/docs/releases/v0.7.0.md
Normal file
20
integrations/ckconfig/docs/releases/v0.7.0.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# CommandKit ckconfig v0.7.0
|
||||||
|
|
||||||
|
CommandKit ckconfig v0.7.0 adopts ConfigKit v1.2.0. Application-owned loaders
|
||||||
|
can select main-relative companion imports and overlay contexts through
|
||||||
|
ConfigKit's public APIs, then expose the resulting configuration through
|
||||||
|
ckconfig's existing scope adapter. [ConfigKit v1.2.0 release notes](https://forge.maximumdirect.net/base-layer/configkit/src/tag/v1.2.0/docs/releases/v1.2.0.md)
|
||||||
|
|
||||||
|
## Compatibility and upgrade
|
||||||
|
|
||||||
|
Select `go.maximumdirect.net/ckconfig v0.7.0` with CommandKit core v0.6.0.
|
||||||
|
The consumer minimum is Go 1.27.0.
|
||||||
|
|
||||||
|
Application loaders constructing ConfigKit `Input` or `LayeredOptions` must use
|
||||||
|
field-named struct literals to accommodate the fields added upstream. See the
|
||||||
|
[consumer guide](../../../../docs/consumers/guide.md#module-selection) for module
|
||||||
|
selection and loader guidance.
|
||||||
|
|
||||||
|
[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckconfig/v0.7.0/integrations/ckconfig/COPYRIGHT) |
|
||||||
|
[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckconfig/v0.7.0/integrations/ckconfig/LICENSE) |
|
||||||
|
[ATTRIBUTION](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckconfig/v0.7.0/integrations/ckconfig/docs/oss/attribution.md)
|
||||||
19
integrations/ckconfig/docs/releases/v0.8.0.md
Normal file
19
integrations/ckconfig/docs/releases/v0.8.0.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# CommandKit ckconfig v0.8.0
|
||||||
|
|
||||||
|
CommandKit ckconfig v0.8.0 classifies identifiable invalid ConfigKit input as a
|
||||||
|
usage failure. The new `ClassifyConfigurationError` function exposes the same
|
||||||
|
CLI classification for callers building their own outcomes.
|
||||||
|
|
||||||
|
## Compatibility and upgrade
|
||||||
|
|
||||||
|
Select `go.maximumdirect.net/ckconfig v0.8.0` with CommandKit core v0.6.0. The
|
||||||
|
consumer minimum remains Go 1.27.0. Standard configuration commands now return
|
||||||
|
status `2` for diagnostic evidence identifying invalid configuration input;
|
||||||
|
previously these loading failures returned status `1`. Update scripts that
|
||||||
|
interpret those statuses. Cancellation, operational failures, and ambiguous or
|
||||||
|
unknown evidence remain status `1`. See the [CLI contract](../../../../docs/cli.md#configuration-failure-classification)
|
||||||
|
and the [classifier GoDoc](../../errors.go) for details.
|
||||||
|
|
||||||
|
[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckconfig/v0.8.0/integrations/ckconfig/COPYRIGHT) |
|
||||||
|
[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckconfig/v0.8.0/integrations/ckconfig/LICENSE) |
|
||||||
|
[ATTRIBUTION](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckconfig/v0.8.0/integrations/ckconfig/docs/oss/attribution.md)
|
||||||
102
integrations/ckconfig/errors.go
Normal file
102
integrations/ckconfig/errors.go
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
package ckconfig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClassifyConfigurationError selects a CLI outcome from ConfigKit loading
|
||||||
|
// diagnostics. A nil error is success. A loading error is usage only when it
|
||||||
|
// contains at least one error diagnostic and all error diagnostics identify
|
||||||
|
// invalid configuration input; warnings are ignored. Unknown evidence and
|
||||||
|
// other errors are operational. Wrappers and joined errors are inspected, and
|
||||||
|
// any operational branch, cancellation, or deadline takes precedence.
|
||||||
|
// The caller remains responsible for constructing an outcome and its cause.
|
||||||
|
func ClassifyConfigurationError(err error) commandkit.OutcomeKind {
|
||||||
|
if err == nil {
|
||||||
|
return commandkit.OutcomeSuccess
|
||||||
|
}
|
||||||
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
return commandkit.OutcomeOperational
|
||||||
|
}
|
||||||
|
return classifyConfigurationTree(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func classifyConfigurationTree(err error) commandkit.OutcomeKind {
|
||||||
|
if load, ok := err.(*configkit.LoadError); ok {
|
||||||
|
if load == nil {
|
||||||
|
return commandkit.OutcomeOperational
|
||||||
|
}
|
||||||
|
return classifyConfigurationDiagnostics(load.Diagnostics())
|
||||||
|
}
|
||||||
|
switch wrapped := err.(type) {
|
||||||
|
case interface{ Unwrap() []error }:
|
||||||
|
found := false
|
||||||
|
for _, child := range wrapped.Unwrap() {
|
||||||
|
if child == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
found = true
|
||||||
|
if classifyConfigurationTree(child) != commandkit.OutcomeUsage {
|
||||||
|
return commandkit.OutcomeOperational
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found {
|
||||||
|
return commandkit.OutcomeUsage
|
||||||
|
}
|
||||||
|
case interface{ Unwrap() error }:
|
||||||
|
if child := wrapped.Unwrap(); child != nil {
|
||||||
|
return classifyConfigurationTree(child)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandkit.OutcomeOperational
|
||||||
|
}
|
||||||
|
|
||||||
|
func classifyConfigurationDiagnostics(diagnostics []configkit.Diagnostic) commandkit.OutcomeKind {
|
||||||
|
found := false
|
||||||
|
for _, diagnostic := range diagnostics {
|
||||||
|
switch diagnostic.Severity {
|
||||||
|
case configkit.SeverityWarning:
|
||||||
|
continue
|
||||||
|
case configkit.SeverityError:
|
||||||
|
found = true
|
||||||
|
if !configurationInputCode(diagnostic.Code) {
|
||||||
|
return commandkit.OutcomeOperational
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return commandkit.OutcomeOperational
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found {
|
||||||
|
return commandkit.OutcomeUsage
|
||||||
|
}
|
||||||
|
return commandkit.OutcomeOperational
|
||||||
|
}
|
||||||
|
|
||||||
|
func configurationInputCode(code configkit.Code) bool {
|
||||||
|
switch code {
|
||||||
|
case configkit.CodeYAMLInvalid, configkit.CodeYAMLEmpty, configkit.CodeYAMLMultipleDocuments,
|
||||||
|
configkit.CodeYAMLRootType, configkit.CodeYAMLDuplicateKey, configkit.CodeYAMLTag,
|
||||||
|
configkit.CodeYAMLAnchor, configkit.CodeYAMLAlias, configkit.CodeYAMLMergeKey,
|
||||||
|
configkit.CodeYAMLScalar, configkit.CodeYAMLDepthLimit, configkit.CodeYAMLNodeLimit,
|
||||||
|
configkit.CodeDecodeType, configkit.CodeDecodeNull, configkit.CodeDecodeRange,
|
||||||
|
configkit.CodeDecodeDuration, configkit.CodeDecodeText, configkit.CodeDecodeUnknownField,
|
||||||
|
configkit.CodeDecodeArrayLength, configkit.CodeSourceLimitExceeded,
|
||||||
|
configkit.CodeImportDisabled, configkit.CodeImportCycle, configkit.CodeImportRepeated,
|
||||||
|
configkit.CodeImportVersion, configkit.CodeSequenceInvalid, configkit.CodeSequenceConflict,
|
||||||
|
configkit.CodeComposeInvalid, configkit.CodeComposeConflict, configkit.CodeUnderlayVersion,
|
||||||
|
configkit.CodeOverlayVersion, configkit.CodeOverlayRepeated, configkit.CodeOverlayDirective,
|
||||||
|
configkit.CodeVersionType, configkit.CodeVersionError, configkit.CodeResolveError,
|
||||||
|
configkit.CodeValidateError, configkit.CodeInheritanceInvalid, configkit.CodeInheritanceMissing,
|
||||||
|
configkit.CodeInheritanceCycle, configkit.CodeInheritanceVersion, configkit.CodeOverrideInvalidPath,
|
||||||
|
configkit.CodeOverrideDuplicate, configkit.CodeOverrideOverlap, configkit.CodeOverrideDirective,
|
||||||
|
configkit.CodeOverrideVersion, configkit.CodeOverrideLimitExceeded, configkit.CodeSecretRequired,
|
||||||
|
configkit.CodeSecretInvalidName:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
93
integrations/ckconfig/errors_test.go
Normal file
93
integrations/ckconfig/errors_test.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package ckconfig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfigurationDiagnosticClassification(t *testing.T) {
|
||||||
|
usageCodes := []configkit.Code{
|
||||||
|
configkit.CodeYAMLInvalid, configkit.CodeYAMLEmpty, configkit.CodeYAMLMultipleDocuments, configkit.CodeYAMLRootType, configkit.CodeYAMLDuplicateKey, configkit.CodeYAMLTag, configkit.CodeYAMLAnchor, configkit.CodeYAMLAlias, configkit.CodeYAMLMergeKey, configkit.CodeYAMLScalar, configkit.CodeYAMLDepthLimit, configkit.CodeYAMLNodeLimit,
|
||||||
|
configkit.CodeDecodeType, configkit.CodeDecodeNull, configkit.CodeDecodeRange, configkit.CodeDecodeDuration, configkit.CodeDecodeText, configkit.CodeDecodeUnknownField, configkit.CodeDecodeArrayLength, configkit.CodeSourceLimitExceeded,
|
||||||
|
configkit.CodeImportDisabled, configkit.CodeImportCycle, configkit.CodeImportRepeated, configkit.CodeImportVersion, configkit.CodeSequenceInvalid, configkit.CodeSequenceConflict, configkit.CodeComposeInvalid, configkit.CodeComposeConflict, configkit.CodeUnderlayVersion, configkit.CodeOverlayVersion, configkit.CodeOverlayRepeated, configkit.CodeOverlayDirective,
|
||||||
|
configkit.CodeVersionType, configkit.CodeVersionError, configkit.CodeResolveError, configkit.CodeValidateError, configkit.CodeInheritanceInvalid, configkit.CodeInheritanceMissing, configkit.CodeInheritanceCycle, configkit.CodeInheritanceVersion, configkit.CodeOverrideInvalidPath, configkit.CodeOverrideDuplicate, configkit.CodeOverrideOverlap, configkit.CodeOverrideDirective, configkit.CodeOverrideVersion, configkit.CodeOverrideLimitExceeded, configkit.CodeSecretRequired, configkit.CodeSecretInvalidName,
|
||||||
|
}
|
||||||
|
for _, code := range usageCodes {
|
||||||
|
t.Run(string(code), func(t *testing.T) {
|
||||||
|
ds := []configkit.Diagnostic{{Severity: configkit.SeverityWarning, Code: configkit.CodeSourceRead}, {Severity: configkit.SeverityError, Code: code}}
|
||||||
|
if got := classifyConfigurationDiagnostics(ds); got != commandkit.OutcomeUsage {
|
||||||
|
t.Fatalf("got %s", got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for _, code := range []configkit.Code{configkit.CodeSourceMissing, configkit.CodeSourcePermission, configkit.CodeImportInvalid, configkit.CodeImportOutsideRoot, configkit.CodeImportLimitExceeded, configkit.CodeOverlayInvalid, configkit.CodeOverlayOutsideRoot, configkit.CodeOverlayLimitExceeded, configkit.CodeSchemaRoot, configkit.CodeOptionsInvalid, configkit.CodeHistoryLimitExceeded, configkit.CodeResolveHookFailed, configkit.CodeValidateMutation, configkit.CodeOverrideInvalidLabel, configkit.CodeOverrideInvalidValue, configkit.CodeSecretUnset, configkit.CodeSecretEmpty, configkit.CodeSecretsMissing, "future.code"} {
|
||||||
|
t.Run(string(code), func(t *testing.T) {
|
||||||
|
ds := []configkit.Diagnostic{{Severity: configkit.SeverityError, Code: configkit.CodeYAMLInvalid}, {Severity: configkit.SeverityError, Code: code}}
|
||||||
|
if got := classifyConfigurationDiagnostics(ds); got != commandkit.OutcomeOperational {
|
||||||
|
t.Fatalf("got %s", got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for _, ds := range [][]configkit.Diagnostic{nil, {{Severity: configkit.SeverityWarning, Code: configkit.CodeYAMLInvalid}}, {{Severity: "future", Code: configkit.CodeYAMLInvalid}}, {{Severity: configkit.SeverityError, Code: configkit.CodeYAMLInvalid}, {Severity: "future"}}} {
|
||||||
|
if got := classifyConfigurationDiagnostics(ds); got != commandkit.OutcomeOperational {
|
||||||
|
t.Fatalf("%v: got %s", ds, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type emptyChildren struct{}
|
||||||
|
|
||||||
|
func (emptyChildren) Error() string { return "empty" }
|
||||||
|
func (emptyChildren) Unwrap() []error { return nil }
|
||||||
|
|
||||||
|
func TestClassifyConfigurationError(t *testing.T) {
|
||||||
|
_, invalid := configkit.Load[map[string]any](configkit.Bytes("invalid", []byte("broken: [")))
|
||||||
|
_, missing := configkit.Load[map[string]any](configkit.File("/nonexistent-commandkit-classifier-test"))
|
||||||
|
var load *configkit.LoadError
|
||||||
|
if !errors.As(invalid, &load) || load == nil {
|
||||||
|
t.Fatalf("invalid fixture: %v", invalid)
|
||||||
|
}
|
||||||
|
if missing == nil {
|
||||||
|
t.Fatal("missing fixture unexpectedly succeeded")
|
||||||
|
}
|
||||||
|
var typedNil *configkit.LoadError
|
||||||
|
opaque := errors.New("opaque")
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
err error
|
||||||
|
want commandkit.OutcomeKind
|
||||||
|
}{
|
||||||
|
{"nil", nil, commandkit.OutcomeSuccess},
|
||||||
|
{"invalid", invalid, commandkit.OutcomeUsage},
|
||||||
|
{"wrapped", fmt.Errorf("wrapped: %w", invalid), commandkit.OutcomeUsage},
|
||||||
|
{"all input", errors.Join(invalid, fmt.Errorf("wrapped: %w", invalid)), commandkit.OutcomeUsage},
|
||||||
|
{"mixed first", errors.Join(missing, invalid), commandkit.OutcomeOperational},
|
||||||
|
{"mixed last", errors.Join(invalid, missing), commandkit.OutcomeOperational},
|
||||||
|
{"nested", errors.Join(invalid, errors.Join(invalid, opaque)), commandkit.OutcomeOperational},
|
||||||
|
{"canceled", errors.Join(invalid, context.Canceled), commandkit.OutcomeOperational},
|
||||||
|
{"deadline", fmt.Errorf("deadline: %w", context.DeadlineExceeded), commandkit.OutcomeOperational},
|
||||||
|
{"missing", missing, commandkit.OutcomeOperational},
|
||||||
|
{"opaque", opaque, commandkit.OutcomeOperational},
|
||||||
|
{"empty load", &configkit.LoadError{}, commandkit.OutcomeOperational},
|
||||||
|
{"typed nil", typedNil, commandkit.OutcomeOperational},
|
||||||
|
{"empty children", emptyChildren{}, commandkit.OutcomeOperational},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
if got := ClassifyConfigurationError(tc.err); got != tc.want {
|
||||||
|
t.Fatalf("got %s, want %s", got, tc.want)
|
||||||
|
}
|
||||||
|
if errors.Is(tc.err, invalid) {
|
||||||
|
var got *configkit.LoadError
|
||||||
|
if !errors.As(tc.err, &got) || got == nil {
|
||||||
|
t.Fatal("load identity lost")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -176,11 +176,11 @@ func TestSimpleFailedLoadReportsEvidence(t *testing.T) {
|
|||||||
t.Fatalf("fixture failure = %v", failure)
|
t.Fatalf("fixture failure = %v", failure)
|
||||||
}
|
}
|
||||||
outcome, output, _ := executeSimple(t, "config", "validate", "--config=fixtures/invalid.yml", "--details", "--severity=error", "--format=json")
|
outcome, output, _ := executeSimple(t, "config", "validate", "--config=fixtures/invalid.yml", "--details", "--severity=error", "--format=json")
|
||||||
if outcome.Kind != commandkit.OutcomeOperational || !strings.Contains(output, `"state": "present"`) || !strings.Contains(output, `"severity": "error"`) {
|
if outcome.Kind != commandkit.OutcomeUsage || !strings.Contains(output, `"state": "present"`) || !strings.Contains(output, `"severity": "error"`) {
|
||||||
t.Fatalf("detailed failure = %#v %q", outcome, output)
|
t.Fatalf("detailed failure = %#v %q", outcome, output)
|
||||||
}
|
}
|
||||||
outcome, output, _ = executeSimple(t, "config", "sources", "--config=fixtures/invalid.yml", "--source-id="+native.Sources()[0].ID, "--format=json")
|
outcome, output, _ = executeSimple(t, "config", "sources", "--config=fixtures/invalid.yml", "--source-id="+native.Sources()[0].ID, "--format=json")
|
||||||
if outcome.Kind != commandkit.OutcomeOperational || !strings.Contains(output, `"id":`) || !strings.Contains(output, "invalid.yml") {
|
if outcome.Kind != commandkit.OutcomeUsage || !strings.Contains(output, `"id":`) || !strings.Contains(output, "invalid.yml") {
|
||||||
t.Fatalf("source failure = %#v %q", outcome, output)
|
t.Fatalf("source failure = %#v %q", outcome, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,11 +108,11 @@ func runConfigExplanation[I, S any](invocation commandkit.Invocation, plan *conf
|
|||||||
name := selected.scope.scope.Name
|
name := selected.scope.scope.Name
|
||||||
reporter := invocation.Reporter()
|
reporter := invocation.Reporter()
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration explanation was canceled.", commandkit.Explanation{}, err)
|
return configFailure(invocation.Context, "Configuration explanation was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
if selected.scope.scope.Acquire == nil {
|
if selected.scope.scope.Acquire == nil {
|
||||||
cause := fmt.Errorf("configuration scope %q has no acquisition callback", name)
|
cause := fmt.Errorf("configuration scope %q has no acquisition callback", name)
|
||||||
return configFailure(fmt.Sprintf("Unable to explain configuration scope %q.", name), commandkit.Explanation{}, cause)
|
return configFailure(invocation.Context, fmt.Sprintf("Unable to explain configuration scope %q.", name), commandkit.Explanation{}, cause)
|
||||||
}
|
}
|
||||||
acquired, acquireErr := selected.scope.scope.Acquire(invocation.Context, Request{
|
acquired, acquireErr := selected.scope.scope.Acquire(invocation.Context, Request{
|
||||||
Operation: Explain,
|
Operation: Explain,
|
||||||
@@ -120,14 +120,14 @@ func runConfigExplanation[I, S any](invocation commandkit.Invocation, plan *conf
|
|||||||
}, selected.input, state)
|
}, selected.input, state)
|
||||||
queueConfigAcquisition(reporter, acquired)
|
queueConfigAcquisition(reporter, acquired)
|
||||||
if acquireErr != nil {
|
if acquireErr != nil {
|
||||||
return configFailure(fmt.Sprintf("Unable to explain configuration scope %q.", name), acquired.Explanation, acquireErr)
|
return configFailure(invocation.Context, fmt.Sprintf("Unable to explain configuration scope %q.", name), acquired.Explanation, acquireErr)
|
||||||
}
|
}
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration explanation was canceled.", acquired.Explanation, err)
|
return configFailure(invocation.Context, "Configuration explanation was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if plan.list {
|
if plan.list {
|
||||||
if acquired.Value.Metadata == nil {
|
if acquired.Value.Metadata == nil {
|
||||||
return configFailure("Configuration scope did not provide path metadata.", acquired.Explanation, fmt.Errorf("configuration scope %q declared path discovery without metadata", name))
|
return configFailure(invocation.Context, "Configuration scope did not provide path metadata.", acquired.Explanation, fmt.Errorf("configuration scope %q declared path discovery without metadata", name))
|
||||||
}
|
}
|
||||||
report := pathDiscoveryReport{Scope: name, Paths: []pathDiscoveryEntry{}}
|
report := pathDiscoveryReport{Scope: name, Paths: []pathDiscoveryEntry{}}
|
||||||
var prefix []string
|
var prefix []string
|
||||||
@@ -157,16 +157,16 @@ func runConfigExplanation[I, S any](invocation commandkit.Invocation, plan *conf
|
|||||||
}
|
}
|
||||||
if acquired.Value.Explanation == nil {
|
if acquired.Value.Explanation == nil {
|
||||||
cause := fmt.Errorf("configuration scope %q did not provide an explanation reader", name)
|
cause := fmt.Errorf("configuration scope %q did not provide an explanation reader", name)
|
||||||
return configFailure("Configuration scope did not provide explanation data.", acquired.Explanation, cause)
|
return configFailure(invocation.Context, "Configuration scope did not provide explanation data.", acquired.Explanation, cause)
|
||||||
}
|
}
|
||||||
|
|
||||||
explanation, found := acquired.Value.Explanation.Explain(plan.path)
|
explanation, found := acquired.Value.Explanation.Explain(plan.path)
|
||||||
if !found {
|
if !found {
|
||||||
cause := fmt.Errorf("configuration path %q is not known in scope %q", plan.path.String(), name)
|
cause := fmt.Errorf("configuration path %q is not known in scope %q", plan.path.String(), name)
|
||||||
return configFailure("The requested configuration path is not available.", acquired.Explanation, cause)
|
return configFailure(invocation.Context, "The requested configuration path is not available.", acquired.Explanation, cause)
|
||||||
}
|
}
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration explanation was canceled.", acquired.Explanation, err)
|
return configFailure(invocation.Context, "Configuration explanation was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
report := makeExplanationReport(name, explanation)
|
report := makeExplanationReport(name, explanation)
|
||||||
if acquired.Value.Metadata != nil {
|
if acquired.Value.Metadata != nil {
|
||||||
@@ -192,7 +192,7 @@ func runConfigExplanation[I, S any](invocation commandkit.Invocation, plan *conf
|
|||||||
}
|
}
|
||||||
renderErr := reporter.Report(commandkit.Report{Value: report, TextTemplate: explanationTemplate})
|
renderErr := reporter.Report(commandkit.Report{Value: report, TextTemplate: explanationTemplate})
|
||||||
if renderErr != nil && invocation.Context.Err() != nil {
|
if renderErr != nil && invocation.Context.Err() != nil {
|
||||||
return configFailure("Configuration explanation was canceled.", acquired.Explanation, invocation.Context.Err())
|
return configFailure(invocation.Context, "Configuration explanation was canceled.", acquired.Explanation, invocation.Context.Err())
|
||||||
}
|
}
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ go 1.27.0
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
go.maximumdirect.net/commandkit v0.6.0
|
go.maximumdirect.net/commandkit v0.6.0
|
||||||
go.maximumdirect.net/configkit v1.1.0
|
go.maximumdirect.net/configkit v1.2.0
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6
|
go.yaml.in/yaml/v4 v4.0.0-rc.6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ go.maximumdirect.net/commandkit v0.6.0 h1:4PHhMIlZuuvreIxZhUazeweg6zoYixEvhM9LJn
|
|||||||
go.maximumdirect.net/commandkit v0.6.0/go.mod h1:ZS98DewKNVBygKVDoh5MFD09CnPlP37dS9pVsID5Eoc=
|
go.maximumdirect.net/commandkit v0.6.0/go.mod h1:ZS98DewKNVBygKVDoh5MFD09CnPlP37dS9pVsID5Eoc=
|
||||||
go.maximumdirect.net/configkit v1.1.0 h1:UzXN2ZMnEkcL0O4YSLqD9qd9M1gb/NWCHQR/H8AaQzA=
|
go.maximumdirect.net/configkit v1.1.0 h1:UzXN2ZMnEkcL0O4YSLqD9qd9M1gb/NWCHQR/H8AaQzA=
|
||||||
go.maximumdirect.net/configkit v1.1.0/go.mod h1:s1zLJ9GGB/1Q4a+aOHMLISonJxWFgNWpA6SpPlOafeA=
|
go.maximumdirect.net/configkit v1.1.0/go.mod h1:s1zLJ9GGB/1Q4a+aOHMLISonJxWFgNWpA6SpPlOafeA=
|
||||||
|
go.maximumdirect.net/configkit v1.2.0 h1:c4tDJ6Xeh/Jg90UZplLxsnf500lvrZBVj0E3i1ysir8=
|
||||||
|
go.maximumdirect.net/configkit v1.2.0/go.mod h1:s1zLJ9GGB/1Q4a+aOHMLISonJxWFgNWpA6SpPlOafeA=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
|
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package ckconfig
|
package ckconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@@ -15,7 +17,7 @@ func runConfigOperation[I, S any](invocation commandkit.Invocation, operation Op
|
|||||||
return invocation.Help()
|
return invocation.Help()
|
||||||
}
|
}
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration operation was canceled.", commandkit.Explanation{}, err)
|
return configFailure(invocation.Context, "Configuration operation was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
plan := input.plan
|
plan := input.plan
|
||||||
var state S
|
var state S
|
||||||
@@ -64,11 +66,23 @@ func queueConfigAcquisition(reporter *commandkit.Reporter, acquired commandkit.A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func configFailure(message string, explanation commandkit.Explanation, cause error) commandkit.Outcome {
|
func configFailure(ctx context.Context, message string, explanation commandkit.Explanation, cause error) commandkit.Outcome {
|
||||||
if explanation.Message != "" || len(explanation.Details) > 0 {
|
if explanation.Message != "" || len(explanation.Details) > 0 {
|
||||||
message = explanation.Message
|
message = explanation.Message
|
||||||
}
|
}
|
||||||
|
if ctx != nil {
|
||||||
|
if canceled := ctx.Err(); canceled != nil {
|
||||||
|
if cause == nil {
|
||||||
|
cause = canceled
|
||||||
|
} else if !errors.Is(cause, canceled) {
|
||||||
|
cause = errors.Join(cause, canceled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
outcome := commandkit.Failure(message, explanation.Details...)
|
outcome := commandkit.Failure(message, explanation.Details...)
|
||||||
|
if cause != nil && ClassifyConfigurationError(cause) == commandkit.OutcomeUsage {
|
||||||
|
outcome = commandkit.Usage(message, explanation.Details...)
|
||||||
|
}
|
||||||
if cause != nil {
|
if cause != nil {
|
||||||
outcome = outcome.WithCause(cause)
|
outcome = outcome.WithCause(cause)
|
||||||
}
|
}
|
||||||
@@ -76,6 +90,7 @@ func configFailure(message string, explanation commandkit.Explanation, cause err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func configAcquisitionFailure(
|
func configAcquisitionFailure(
|
||||||
|
ctx context.Context,
|
||||||
reporter *commandkit.Reporter,
|
reporter *commandkit.Reporter,
|
||||||
operation, scope string,
|
operation, scope string,
|
||||||
acquired commandkit.Acquired[View],
|
acquired commandkit.Acquired[View],
|
||||||
@@ -83,7 +98,7 @@ func configAcquisitionFailure(
|
|||||||
) commandkit.Outcome {
|
) commandkit.Outcome {
|
||||||
queueConfigAcquisition(reporter, acquired)
|
queueConfigAcquisition(reporter, acquired)
|
||||||
message := fmt.Sprintf("Unable to %s configuration scope %q.", operation, scope)
|
message := fmt.Sprintf("Unable to %s configuration scope %q.", operation, scope)
|
||||||
return configFailure(message, acquired.Explanation, cause)
|
return configFailure(ctx, message, acquired.Explanation, cause)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preserve the preparation/delivery cancellation checkpoint for buffered reports.
|
// Preserve the preparation/delivery cancellation checkpoint for buffered reports.
|
||||||
@@ -105,7 +120,7 @@ func renderPreparedConfigReport(invocation commandkit.Invocation, explanation co
|
|||||||
canceled = invocation.Context.Err()
|
canceled = invocation.Context.Err()
|
||||||
}
|
}
|
||||||
if canceled != nil {
|
if canceled != nil {
|
||||||
return configFailure("Configuration report preparation was canceled.", explanation, canceled)
|
return configFailure(invocation.Context, "Configuration report preparation was canceled.", explanation, canceled)
|
||||||
}
|
}
|
||||||
if renderErr == nil {
|
if renderErr == nil {
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: value})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: value})
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func TestOverrideNativeLoadErrorAndProvenance(t *testing.T) {
|
|||||||
}
|
}
|
||||||
result = app.Execute(context.Background(), []string{"config", "validate", "--set==1"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
result = app.Execute(context.Background(), []string{"config", "validate", "--set==1"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||||
var loadErr *configkit.LoadError
|
var loadErr *configkit.LoadError
|
||||||
if result.Kind != commandkit.OutcomeOperational || !errors.As(result.Cause, &loadErr) {
|
if result.Kind != commandkit.OutcomeUsage || !errors.As(result.Cause, &loadErr) {
|
||||||
t.Fatalf("native invalid root override: %#v", result)
|
t.Fatalf("native invalid root override: %#v", result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,29 +19,29 @@ func runConfigShow[I, S any](invocation commandkit.Invocation, plan *configOpera
|
|||||||
reporter := invocation.Reporter()
|
reporter := invocation.Reporter()
|
||||||
for _, selected := range plan.scopes {
|
for _, selected := range plan.scopes {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration show was canceled.", commandkit.Explanation{}, err)
|
return configFailure(invocation.Context, "Configuration show was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
if selected.scope.scope.Acquire == nil {
|
if selected.scope.scope.Acquire == nil {
|
||||||
return commandkit.Failure(fmt.Sprintf("Configuration scope %q has no acquisition callback.", selected.scope.scope.Name))
|
return commandkit.Failure(fmt.Sprintf("Configuration scope %q has no acquisition callback.", selected.scope.scope.Name))
|
||||||
}
|
}
|
||||||
acquired, acquireErr := selected.scope.scope.Acquire(invocation.Context, Request{Operation: Show, Selection: selected.selection}, selected.input, state)
|
acquired, acquireErr := selected.scope.scope.Acquire(invocation.Context, Request{Operation: Show, Selection: selected.selection}, selected.input, state)
|
||||||
if acquireErr != nil {
|
if acquireErr != nil {
|
||||||
return configAcquisitionFailure(reporter, "show", selected.scope.scope.Name, acquired, acquireErr)
|
return configAcquisitionFailure(invocation.Context, reporter, "show", selected.scope.scope.Name, acquired, acquireErr)
|
||||||
}
|
}
|
||||||
queueConfigAcquisition(reporter, acquired)
|
queueConfigAcquisition(reporter, acquired)
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration show was canceled.", acquired.Explanation, err)
|
return configFailure(invocation.Context, "Configuration show was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if plan.pathSet {
|
if plan.pathSet {
|
||||||
if acquired.Value.Explanation == nil {
|
if acquired.Value.Explanation == nil {
|
||||||
return configFailure("Configuration scope did not provide explanation data.", acquired.Explanation, fmt.Errorf("configuration scope %q declared path show without an explanation reader", selected.scope.scope.Name))
|
return configFailure(invocation.Context, "Configuration scope did not provide explanation data.", acquired.Explanation, fmt.Errorf("configuration scope %q declared path show without an explanation reader", selected.scope.scope.Name))
|
||||||
}
|
}
|
||||||
explanation, found := acquired.Value.Explanation.Explain(plan.path)
|
explanation, found := acquired.Value.Explanation.Explain(plan.path)
|
||||||
if !found || !explanation.Effective.Present {
|
if !found || !explanation.Effective.Present {
|
||||||
return configFailure("The requested effective configuration path is not available.", acquired.Explanation, fmt.Errorf("configuration path %q is not effective in scope %q", plan.path.String(), selected.scope.scope.Name))
|
return configFailure(invocation.Context, "The requested effective configuration path is not available.", acquired.Explanation, fmt.Errorf("configuration path %q is not effective in scope %q", plan.path.String(), selected.scope.scope.Name))
|
||||||
}
|
}
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration show was canceled.", acquired.Explanation, err)
|
return configFailure(invocation.Context, "Configuration show was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
var value any
|
var value any
|
||||||
err := reporter.RenderOutput(func(io.Writer) error {
|
err := reporter.RenderOutput(func(io.Writer) error {
|
||||||
@@ -51,7 +51,7 @@ func runConfigShow[I, S any](invocation commandkit.Invocation, plan *configOpera
|
|||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if canceled := invocation.Context.Err(); canceled != nil {
|
if canceled := invocation.Context.Err(); canceled != nil {
|
||||||
return configFailure("Configuration show was canceled.", acquired.Explanation, canceled)
|
return configFailure(invocation.Context, "Configuration show was canceled.", acquired.Explanation, canceled)
|
||||||
}
|
}
|
||||||
_ = reporter.Report(commandkit.Report{Value: value})
|
_ = reporter.Report(commandkit.Report{Value: value})
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func runConfigShow[I, S any](invocation commandkit.Invocation, plan *configOpera
|
|||||||
documents = append(documents, effectiveDocument{name: selected.scope.scope.Name, view: acquired.Value})
|
documents = append(documents, effectiveDocument{name: selected.scope.scope.Name, view: acquired.Value})
|
||||||
}
|
}
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration show was canceled.", commandkit.Explanation{}, err)
|
return configFailure(invocation.Context, "Configuration show was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
var value any
|
var value any
|
||||||
var canceled error
|
var canceled error
|
||||||
@@ -92,16 +92,16 @@ func runConfigShow[I, S any](invocation commandkit.Invocation, plan *configOpera
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if canceled != nil {
|
if canceled != nil {
|
||||||
return configFailure("Configuration show was canceled.", commandkit.Explanation{}, canceled)
|
return configFailure(invocation.Context, "Configuration show was canceled.", commandkit.Explanation{}, canceled)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if canceled := invocation.Context.Err(); canceled != nil {
|
if canceled := invocation.Context.Err(); canceled != nil {
|
||||||
return configFailure("Configuration show was canceled.", commandkit.Explanation{}, canceled)
|
return configFailure(invocation.Context, "Configuration show was canceled.", commandkit.Explanation{}, canceled)
|
||||||
}
|
}
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
}
|
}
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration show was canceled.", commandkit.Explanation{}, err)
|
return configFailure(invocation.Context, "Configuration show was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
_ = reporter.Report(commandkit.Report{Value: value})
|
_ = reporter.Report(commandkit.Report{Value: value})
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ func runConfigSources[I, S any](invocation commandkit.Invocation, plan *configOp
|
|||||||
name := selected.scope.scope.Name
|
name := selected.scope.scope.Name
|
||||||
reporter := invocation.Reporter()
|
reporter := invocation.Reporter()
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return configFailure("Configuration source listing was canceled.", commandkit.Explanation{}, err)
|
return configFailure(invocation.Context, "Configuration source listing was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
if selected.scope.scope.Acquire == nil {
|
if selected.scope.scope.Acquire == nil {
|
||||||
cause := fmt.Errorf("configuration scope %q has no acquisition callback", name)
|
cause := fmt.Errorf("configuration scope %q has no acquisition callback", name)
|
||||||
return configFailure(fmt.Sprintf("Unable to list sources for configuration scope %q.", name), commandkit.Explanation{}, cause)
|
return configFailure(invocation.Context, fmt.Sprintf("Unable to list sources for configuration scope %q.", name), commandkit.Explanation{}, cause)
|
||||||
}
|
}
|
||||||
acquired, acquireErr := selected.scope.scope.Acquire(invocation.Context, Request{
|
acquired, acquireErr := selected.scope.scope.Acquire(invocation.Context, Request{
|
||||||
Operation: Sources,
|
Operation: Sources,
|
||||||
@@ -72,15 +72,15 @@ func runConfigSources[I, S any](invocation commandkit.Invocation, plan *configOp
|
|||||||
queueConfigAcquisition(reporter, acquired)
|
queueConfigAcquisition(reporter, acquired)
|
||||||
if acquireErr == nil && invocation.Context.Err() != nil {
|
if acquireErr == nil && invocation.Context.Err() != nil {
|
||||||
err := invocation.Context.Err()
|
err := invocation.Context.Err()
|
||||||
return configFailure("Configuration source listing was canceled.", acquired.Explanation, err)
|
return configFailure(invocation.Context, "Configuration source listing was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if acquired.Value.Sources == nil {
|
if acquired.Value.Sources == nil {
|
||||||
if acquireErr != nil {
|
if acquireErr != nil {
|
||||||
explanation := sourceSelectionExplanation(acquired.Explanation, "Source inventory is unavailable.")
|
explanation := sourceSelectionExplanation(acquired.Explanation, "Source inventory is unavailable.")
|
||||||
return configFailure(fmt.Sprintf("Unable to list sources for configuration scope %q.", name), explanation, acquireErr)
|
return configFailure(invocation.Context, fmt.Sprintf("Unable to list sources for configuration scope %q.", name), explanation, acquireErr)
|
||||||
}
|
}
|
||||||
cause := fmt.Errorf("configuration scope %q did not provide a source reader", name)
|
cause := fmt.Errorf("configuration scope %q did not provide a source reader", name)
|
||||||
return configFailure("Configuration scope did not provide source information.", acquired.Explanation, cause)
|
return configFailure(invocation.Context, "Configuration scope did not provide source information.", acquired.Explanation, cause)
|
||||||
}
|
}
|
||||||
|
|
||||||
sources := acquired.Value.Sources.Sources()
|
sources := acquired.Value.Sources.Sources()
|
||||||
@@ -134,17 +134,17 @@ func runConfigSources[I, S any](invocation commandkit.Invocation, plan *configOp
|
|||||||
if plan.sourceID.Set && len(document.Sources) == 0 {
|
if plan.sourceID.Set && len(document.Sources) == 0 {
|
||||||
message := fmt.Sprintf("Source ID %q was not found in configuration scope %q.", plan.sourceID.Value, name)
|
message := fmt.Sprintf("Source ID %q was not found in configuration scope %q.", plan.sourceID.Value, name)
|
||||||
if acquireErr != nil {
|
if acquireErr != nil {
|
||||||
return configFailure(fmt.Sprintf("Unable to list sources for configuration scope %q.", name), sourceSelectionExplanation(acquired.Explanation, message), acquireErr)
|
return configFailure(invocation.Context, fmt.Sprintf("Unable to list sources for configuration scope %q.", name), sourceSelectionExplanation(acquired.Explanation, message), acquireErr)
|
||||||
}
|
}
|
||||||
return configFailure(message, acquired.Explanation, fmt.Errorf("source ID %q was not found", plan.sourceID.Value))
|
return configFailure(invocation.Context, message, acquired.Explanation, fmt.Errorf("source ID %q was not found", plan.sourceID.Value))
|
||||||
}
|
}
|
||||||
if acquireErr == nil && invocation.Context.Err() != nil {
|
if acquireErr == nil && invocation.Context.Err() != nil {
|
||||||
err := invocation.Context.Err()
|
err := invocation.Context.Err()
|
||||||
return configFailure("Configuration source listing was canceled.", acquired.Explanation, err)
|
return configFailure(invocation.Context, "Configuration source listing was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
_ = reporter.Report(commandkit.Report{Value: document, TextTemplate: sourceTextTemplate})
|
_ = reporter.Report(commandkit.Report{Value: document, TextTemplate: sourceTextTemplate})
|
||||||
if acquireErr != nil {
|
if acquireErr != nil {
|
||||||
return configFailure(fmt.Sprintf("Unable to list sources for configuration scope %q.", name), acquired.Explanation, acquireErr)
|
return configFailure(invocation.Context, fmt.Sprintf("Unable to list sources for configuration scope %q.", name), acquired.Explanation, acquireErr)
|
||||||
}
|
}
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func runConfigValidation[I, S any](invocation commandkit.Invocation, plan *confi
|
|||||||
}
|
}
|
||||||
for _, selected := range plan.scopes {
|
for _, selected := range plan.scopes {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
outcome = configFailure("Configuration validation was canceled.", commandkit.Explanation{}, err)
|
outcome = configFailure(invocation.Context, "Configuration validation was canceled.", commandkit.Explanation{}, err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
name := selected.scope.scope.Name
|
name := selected.scope.scope.Name
|
||||||
@@ -109,7 +109,7 @@ func runConfigValidation[I, S any](invocation commandkit.Invocation, plan *confi
|
|||||||
if entry.Outcome == "canceled" {
|
if entry.Outcome == "canceled" {
|
||||||
message = "Configuration validation was canceled."
|
message = "Configuration validation was canceled."
|
||||||
}
|
}
|
||||||
outcome = configFailure(message, acquired.Explanation, err)
|
outcome = configFailure(invocation.Context, message, acquired.Explanation, err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,8 @@ func WithRequestValidation[I, S any](
|
|||||||
if build != nil {
|
if build != nil {
|
||||||
built, err := build(ctx, request, input, state)
|
built, err := build(ctx, request, input, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return commandkit.Acquired[struct{}]{}, err
|
messages := promptKitLoadErrorDiagnostics(err, "")
|
||||||
|
return commandkit.Acquired[struct{}]{Diagnostics: messages.diagnostics, Explanation: messages.explanation}, err
|
||||||
}
|
}
|
||||||
concreteRequest = built
|
concreteRequest = built
|
||||||
}
|
}
|
||||||
@@ -476,12 +477,7 @@ func loadPromptKitEngine[I, S any](
|
|||||||
) (*promptkit.Engine, *promptkit.ConfigurationInspection, promptKitAcquisition, error) {
|
) (*promptkit.Engine, *promptkit.ConfigurationInspection, promptKitAcquisition, error) {
|
||||||
engine, err := load(ctx, selection, input, state)
|
engine, err := load(ctx, selection, input, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var loadErr *configkit.LoadError
|
return nil, nil, promptKitLoadErrorDiagnostics(err, side), err
|
||||||
if errors.As(err, &loadErr) {
|
|
||||||
messages := promptKitDiagnostics("promptkit", side, loadErr.Sources(), loadErr.Diagnostics())
|
|
||||||
return nil, nil, messages, err
|
|
||||||
}
|
|
||||||
return nil, nil, promptKitAcquisition{}, err
|
|
||||||
}
|
}
|
||||||
if engine == nil {
|
if engine == nil {
|
||||||
return nil, nil, promptKitAcquisition{}, errors.New("PromptKit configuration loader returned a nil engine")
|
return nil, nil, promptKitAcquisition{}, errors.New("PromptKit configuration loader returned a nil engine")
|
||||||
@@ -509,6 +505,14 @@ func appendPromptKitAcquisition(left, right promptKitAcquisition) promptKitAcqui
|
|||||||
return left
|
return left
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func promptKitLoadErrorDiagnostics(err error, side string) promptKitAcquisition {
|
||||||
|
var loadErr *configkit.LoadError
|
||||||
|
if errors.As(err, &loadErr) && loadErr != nil {
|
||||||
|
return promptKitDiagnostics("promptkit", side, loadErr.Sources(), loadErr.Diagnostics())
|
||||||
|
}
|
||||||
|
return promptKitAcquisition{}
|
||||||
|
}
|
||||||
|
|
||||||
func promptKitDiagnostics(scope, side string, sources []configkit.SourceInfo, records []configkit.Diagnostic) promptKitAcquisition {
|
func promptKitDiagnostics(scope, side string, sources []configkit.SourceInfo, records []configkit.Diagnostic) promptKitAcquisition {
|
||||||
heading := "Configuration scope " + strconv.Quote(scope)
|
heading := "Configuration scope " + strconv.Quote(scope)
|
||||||
if side != "" {
|
if side != "" {
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ func newCatalogListCommand[I, S any](suite Suite[I, S], name string) commandkit.
|
|||||||
}
|
}
|
||||||
return runCatalogList(invocation, suite, input, name, list, collectionCatalogReport)
|
return runCatalogList(invocation, suite, input, name, list, collectionCatalogReport)
|
||||||
default:
|
default:
|
||||||
return definitionFailure("Unable to list the selected PromptKit catalog.", commandkit.Explanation{}, fmt.Errorf("unknown PromptKit catalog %q", name))
|
return definitionFailure(invocation.Context, "Unable to list the selected PromptKit catalog.", commandkit.Explanation{}, fmt.Errorf("unknown PromptKit catalog %q", name))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -368,7 +368,7 @@ func runCatalogList[T any, I, S any](
|
|||||||
) commandkit.Outcome {
|
) commandkit.Outcome {
|
||||||
if invocation.Context != nil {
|
if invocation.Context != nil {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return definitionFailure("PromptKit catalog listing was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit catalog listing was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var state S
|
var state S
|
||||||
@@ -377,18 +377,18 @@ func runCatalogList[T any, I, S any](
|
|||||||
}
|
}
|
||||||
if invocation.Context != nil {
|
if invocation.Context != nil {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return definitionFailure("PromptKit catalog listing was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit catalog listing was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
acquired, err := list(invocation.Context, CatalogRequest{Selection: input.selection, Filter: input.filter}, input.selected, state)
|
acquired, err := list(invocation.Context, CatalogRequest{Selection: input.selection, Filter: input.filter}, input.selected, state)
|
||||||
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Unable to list PromptKit %s.", catalog), acquired.Explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Unable to list PromptKit %s.", catalog), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if invocation.Context != nil {
|
if invocation.Context != nil {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return definitionFailure("PromptKit catalog listing was canceled.", acquired.Explanation, err)
|
return definitionFailure(invocation.Context, "PromptKit catalog listing was canceled.", acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: project(acquired.Value)})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: project(acquired.Value)})
|
||||||
@@ -397,14 +397,14 @@ func runCatalogList[T any, I, S any](
|
|||||||
|
|
||||||
func runDefinitionInspection[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *definitionInput[I], kind string) commandkit.Outcome {
|
func runDefinitionInspection[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *definitionInput[I], kind string) commandkit.Outcome {
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit inspection was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit inspection was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
var state S
|
var state S
|
||||||
if suite.NewState != nil {
|
if suite.NewState != nil {
|
||||||
state = suite.NewState()
|
state = suite.NewState()
|
||||||
}
|
}
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit inspection was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit inspection was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
var value any
|
var value any
|
||||||
var diagnostics []commandkit.Diagnostic
|
var diagnostics []commandkit.Diagnostic
|
||||||
@@ -435,13 +435,13 @@ func runDefinitionInspection[I, S any](invocation commandkit.Invocation, suite S
|
|||||||
}
|
}
|
||||||
queuePromptDiagnostics(invocation.Reporter(), diagnostics)
|
queuePromptDiagnostics(invocation.Reporter(), diagnostics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Unable to inspect PromptKit %s %q.", kind, input.id), explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Unable to inspect PromptKit %s %q.", kind, input.id), explanation, err)
|
||||||
}
|
}
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return definitionFailure(fmt.Sprintf("PromptKit %s inspection returned no result.", kind), explanation, nil)
|
return definitionFailure(invocation.Context, fmt.Sprintf("PromptKit %s inspection returned no result.", kind), explanation, nil)
|
||||||
}
|
}
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Inspection of PromptKit %s %q was canceled.", kind, input.id), explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Inspection of PromptKit %s %q was canceled.", kind, input.id), explanation, err)
|
||||||
}
|
}
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: value})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: value})
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
@@ -520,7 +520,7 @@ func requirementsReportFromInspection(inspection *promptkit.RequirementInspectio
|
|||||||
func runRequirementsInspection[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *requirementsInput[I]) commandkit.Outcome {
|
func runRequirementsInspection[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *requirementsInput[I]) commandkit.Outcome {
|
||||||
if invocation.Context != nil {
|
if invocation.Context != nil {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return definitionFailure("PromptKit requirements inspection was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit requirements inspection was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var state S
|
var state S
|
||||||
@@ -529,7 +529,7 @@ func runRequirementsInspection[I, S any](invocation commandkit.Invocation, suite
|
|||||||
}
|
}
|
||||||
if invocation.Context != nil {
|
if invocation.Context != nil {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return definitionFailure("PromptKit requirements inspection was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit requirements inspection was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,14 +537,14 @@ func runRequirementsInspection[I, S any](invocation commandkit.Invocation, suite
|
|||||||
acquired, err := suite.InspectRequirements(invocation.Context, request, input.selected, state)
|
acquired, err := suite.InspectRequirements(invocation.Context, request, input.selected, state)
|
||||||
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Unable to inspect requirements for PromptKit prompt %q.", input.inspection.PromptID), acquired.Explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Unable to inspect requirements for PromptKit prompt %q.", input.inspection.PromptID), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if acquired.Value == nil {
|
if acquired.Value == nil {
|
||||||
return definitionFailure("PromptKit requirements inspection returned no result.", acquired.Explanation, nil)
|
return definitionFailure(invocation.Context, "PromptKit requirements inspection returned no result.", acquired.Explanation, nil)
|
||||||
}
|
}
|
||||||
if invocation.Context != nil {
|
if invocation.Context != nil {
|
||||||
if err := invocation.Context.Err(); err != nil {
|
if err := invocation.Context.Err(); err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Requirements inspection for PromptKit prompt %q was canceled.", input.inspection.PromptID), acquired.Explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Requirements inspection for PromptKit prompt %q was canceled.", input.inspection.PromptID), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: requirementsReportFromInspection(acquired.Value)})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: requirementsReportFromInspection(acquired.Value)})
|
||||||
@@ -602,8 +602,20 @@ func queuePromptDiagnostics(reporter *commandkit.Reporter, diagnostics []command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func definitionFailure(message string, explanation commandkit.Explanation, cause error) commandkit.Outcome {
|
func definitionFailure(ctx context.Context, message string, explanation commandkit.Explanation, cause error) commandkit.Outcome {
|
||||||
|
if ctx != nil {
|
||||||
|
if canceled := ctx.Err(); canceled != nil {
|
||||||
|
if cause == nil {
|
||||||
|
cause = canceled
|
||||||
|
} else if !errors.Is(cause, canceled) {
|
||||||
|
cause = errors.Join(cause, canceled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
outcome := commandkit.Failure(message)
|
outcome := commandkit.Failure(message)
|
||||||
|
if cause != nil && ckconfig.ClassifyConfigurationError(cause) == commandkit.OutcomeUsage {
|
||||||
|
outcome = commandkit.Usage(message)
|
||||||
|
}
|
||||||
if explanation.Message != "" || len(explanation.Details) > 0 {
|
if explanation.Message != "" || len(explanation.Details) > 0 {
|
||||||
outcome = outcome.WithExplanation(explanation.Message, explanation.Details...)
|
outcome = outcome.WithExplanation(explanation.Message, explanation.Details...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ func TestPublicConfigDiffUsesPromptKitPairAndPreparedInputs(t *testing.T) {
|
|||||||
|
|
||||||
var diagnostics bytes.Buffer
|
var diagnostics bytes.Buffer
|
||||||
failure := app.Execute(context.Background(), []string{"config", "diff", "--scope", "promptkit", "--config", "bad-left.yml", "--against-config", "right.yml", "--campaign", "spring", "--against-campaign", "spring"}, commandkit.Streams{Out: io.Discard, Err: &diagnostics})
|
failure := app.Execute(context.Background(), []string{"config", "diff", "--scope", "promptkit", "--config", "bad-left.yml", "--against-config", "right.yml", "--campaign", "spring", "--against-campaign", "spring"}, commandkit.Streams{Out: io.Discard, Err: &diagnostics})
|
||||||
if failure.Kind != commandkit.OutcomeOperational || !strings.Contains(diagnostics.String(), `Configuration scope "promptkit" (left):`) {
|
if failure.Kind != commandkit.OutcomeUsage || !strings.Contains(diagnostics.String(), `Configuration scope "promptkit" (left):`) {
|
||||||
t.Fatalf("installed load failure = %#v, diagnostics %q", failure, diagnostics.String())
|
t.Fatalf("installed load failure = %#v, diagnostics %q", failure, diagnostics.String())
|
||||||
}
|
}
|
||||||
var loadFailure *configkit.LoadError
|
var loadFailure *configkit.LoadError
|
||||||
|
|||||||
100
integrations/ckprompt/configuration_composition_outcomes_test.go
Normal file
100
integrations/ckprompt/configuration_composition_outcomes_test.go
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
package ckprompt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/ckconfig"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
"go.maximumdirect.net/promptkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestComposedConfigurationInputOutcomes(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("prompt-invalid", []byte("broken: [")))
|
||||||
|
engine := adapterEngine(t)
|
||||||
|
calls := 0
|
||||||
|
scope := ConfigScope(func(_ context.Context, selection ckconfig.Selection, _, _ struct{}) (*promptkit.Engine, error) {
|
||||||
|
calls++
|
||||||
|
if selection.Config.Value == "good" {
|
||||||
|
return engine, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("wrapped: %w", loadErr)
|
||||||
|
})
|
||||||
|
app := newPromptTestApp(t, ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{Scopes: []ckconfig.Scope[struct{}, struct{}]{scope}}))
|
||||||
|
cases := []struct {
|
||||||
|
args []string
|
||||||
|
report string
|
||||||
|
side string
|
||||||
|
}{
|
||||||
|
{[]string{"config", "show"}, "", ""},
|
||||||
|
{[]string{"config", "sources", "--format=json"}, `"sources"`, ""},
|
||||||
|
{[]string{"config", "validate", "--details", "--format=json"}, `"code": "yaml.invalid"`, ""},
|
||||||
|
{[]string{"config", "explain", "--list"}, "", ""},
|
||||||
|
{[]string{"config", "diff"}, "", "left"},
|
||||||
|
{[]string{"config", "diff", "--config=good", "--against-config=bad"}, "", "right"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(strings.Join(tc.args, "_"), func(t *testing.T) {
|
||||||
|
var out, diag bytes.Buffer
|
||||||
|
args := append(append([]string{}, tc.args...), "--scope=promptkit")
|
||||||
|
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diag})
|
||||||
|
var native *configkit.LoadError
|
||||||
|
if result.Status != 2 || !errors.Is(result.Cause, loadErr) || !errors.As(result.Cause, &native) || !strings.Contains(diag.String(), "prompt-invalid") || (tc.report != "" && !strings.Contains(out.String(), tc.report)) || (tc.side != "" && !strings.Contains(diag.String(), "("+tc.side+")")) {
|
||||||
|
t.Fatalf("result=%#v output=%q diagnostics=%q", result, out.String(), diag.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
before := calls
|
||||||
|
var out bytes.Buffer
|
||||||
|
args := append(append([]string{}, tc.args...), "--scope=promptkit")
|
||||||
|
result := app.Execute(ctx, args, commandkit.Streams{Out: &out, Err: io.Discard})
|
||||||
|
if result.Status != 1 || !errors.Is(result.Cause, context.Canceled) || calls != before || out.Len() != 0 {
|
||||||
|
t.Fatalf("canceled %v: %#v output=%q", tc.args, result, out.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSmokeConfigurationFailureOutcomes(t *testing.T) {
|
||||||
|
_, first := configkit.Load[map[string]any](configkit.Bytes("first", []byte("broken: [")))
|
||||||
|
_, second := configkit.Load[map[string]any](configkit.Bytes("second", []byte("other: [")))
|
||||||
|
operational := errors.New("provider failure")
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name, command string
|
||||||
|
failures []error
|
||||||
|
cancel bool
|
||||||
|
want int
|
||||||
|
}{
|
||||||
|
{"single", "reachability", []error{first}, false, 2},
|
||||||
|
{"all input", "all", []error{first, second, first, second}, false, 2},
|
||||||
|
{"mixed", "all", []error{first, operational, second, first}, false, 1},
|
||||||
|
{"cancellation", "all", []error{first}, true, 1},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
calls := 0
|
||||||
|
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{SmokeTest: func(_ context.Context, req SmokeRequest, _, _ struct{}) (commandkit.Acquired[*promptkit.SmokeTestReport], error) {
|
||||||
|
err := tc.failures[calls]
|
||||||
|
calls++
|
||||||
|
if tc.cancel {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
return commandkit.Acquired[*promptkit.SmokeTestReport]{Value: &promptkit.SmokeTestReport{Kind: req.Request.Kind}, Explanation: commandkit.Explanation{Message: fmt.Sprintf("context-%d", calls)}}, err
|
||||||
|
}}))
|
||||||
|
var out, diag bytes.Buffer
|
||||||
|
result := app.Execute(ctx, []string{"promptkit", "test", tc.command, "--format=json"}, commandkit.Streams{Out: &out, Err: &diag})
|
||||||
|
if result.Status != tc.want || calls != len(tc.failures) || !errors.Is(result.Cause, first) || (tc.name == "all input" && !errors.Is(result.Cause, second)) || (tc.name == "mixed" && (!errors.Is(result.Cause, second) || !errors.Is(result.Cause, operational))) || (tc.cancel && !errors.Is(result.Cause, context.Canceled)) || out.Len() == 0 || !strings.Contains(diag.String(), "context-1") {
|
||||||
|
t.Fatalf("outcome=%#v calls=%d report=%q diagnostics=%q", result, calls, out.String(), diag.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
209
integrations/ckprompt/configuration_outcomes_test.go
Normal file
209
integrations/ckprompt/configuration_outcomes_test.go
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
package ckprompt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/ckconfig"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
"go.maximumdirect.net/promptkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPromptConfigurationFailureCallbacks(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("prompt-config", []byte("broken: [")))
|
||||||
|
var native *configkit.LoadError
|
||||||
|
if !errors.As(loadErr, &native) {
|
||||||
|
t.Fatalf("fixture: %v", loadErr)
|
||||||
|
}
|
||||||
|
wrapped := fmt.Errorf("load: %w", loadErr)
|
||||||
|
diag := commandkit.Explanation{Message: "configuration diagnostic"}
|
||||||
|
suite := Suite[struct{}, struct{}]{
|
||||||
|
ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||||
|
return commandkit.Acquired[[]promptkit.PromptIdentity]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
ListProfiles: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||||
|
return commandkit.Acquired[[]string]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
ListBackends: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||||
|
return commandkit.Acquired[[]string]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
ListNamespaces: func(context.Context, NamespaceRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||||
|
return commandkit.Acquired[[]string]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
ListCollections: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.CollectionInfo], error) {
|
||||||
|
return commandkit.Acquired[[]promptkit.CollectionInfo]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
InspectPrompt: func(context.Context, PromptRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.PromptInspection], error) {
|
||||||
|
return commandkit.Acquired[*promptkit.PromptInspection]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
InspectProfile: func(context.Context, ProfileRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.ProfileInspection], error) {
|
||||||
|
return commandkit.Acquired[*promptkit.ProfileInspection]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
InspectBackend: func(context.Context, BackendRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.BackendInspection], error) {
|
||||||
|
return commandkit.Acquired[*promptkit.BackendInspection]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
InspectRequirements: func(context.Context, RequirementsRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.RequirementInspection], error) {
|
||||||
|
return commandkit.Acquired[*promptkit.RequirementInspection]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
ValidateRequest: func(context.Context, ValidationRequest, struct{}, struct{}) (commandkit.Acquired[struct{}], error) {
|
||||||
|
return commandkit.Acquired[struct{}]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
PrepareRequest: func(context.Context, PreparationRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.PreparedRun], error) {
|
||||||
|
return commandkit.Acquired[*promptkit.PreparedRun]{Explanation: diag}, wrapped
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app := newPromptTestApp(t, Command(suite))
|
||||||
|
for _, args := range [][]string{{"promptkit", "list", "prompts"}, {"promptkit", "list", "profiles"}, {"promptkit", "list", "backends"}, {"promptkit", "list", "namespaces"}, {"promptkit", "list", "collections"}, {"promptkit", "show", "prompt", "example"}, {"promptkit", "show", "profile", "example"}, {"promptkit", "show", "backend", "example"}, {"promptkit", "requirements", "show", "example"}, {"promptkit", "requirements", "validate", "example"}, {"promptkit", "show", "prepared", "example"}} {
|
||||||
|
t.Run(strings.Join(args, "_"), func(t *testing.T) {
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
var got *configkit.LoadError
|
||||||
|
if result.Kind != commandkit.OutcomeUsage || result.Status != 2 || !errors.Is(result.Cause, loadErr) || !errors.As(result.Cause, &got) || got != native || !strings.Contains(diagnostic.String(), "configuration diagnostic") {
|
||||||
|
t.Fatalf("outcome=%#v diagnostics=%q", result, diagnostic.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPromptNativeConfigurationFailures(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("native-config", []byte("broken: [")))
|
||||||
|
load := func(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) {
|
||||||
|
return nil, fmt.Errorf("wrapped: %w", loadErr)
|
||||||
|
}
|
||||||
|
suite := FromEngine[struct{}, struct{}](load)
|
||||||
|
suite = WithRequestValidation(suite, load, nil)
|
||||||
|
suite = WithRequestPreparation(suite, load, nil)
|
||||||
|
app := newPromptTestApp(t, Command(suite))
|
||||||
|
for _, args := range [][]string{{"promptkit", "list", "prompts"}, {"promptkit", "show", "prompt", "example"}, {"promptkit", "requirements", "show", "example"}, {"promptkit", "requirements", "validate", "example"}, {"promptkit", "show", "prepared", "example"}} {
|
||||||
|
t.Run(strings.Join(args, "_"), func(t *testing.T) {
|
||||||
|
var diag bytes.Buffer
|
||||||
|
result := app.Execute(context.Background(), args, commandkit.Streams{Out: io.Discard, Err: &diag})
|
||||||
|
var native *configkit.LoadError
|
||||||
|
if result.Status != 2 || !errors.Is(result.Cause, loadErr) || !errors.As(result.Cause, &native) || !strings.Contains(diag.String(), "native-config") {
|
||||||
|
t.Fatalf("outcome=%#v diagnostics=%q", result, diag.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuilderConfigurationFailureDiagnostics(t *testing.T) {
|
||||||
|
_, malformed := configkit.Load[map[string]any](configkit.Bytes("builder-config", []byte("broken: [")))
|
||||||
|
path := configkit.Keys("version")
|
||||||
|
_, rejected := configkit.Load(configkit.Bytes("builder-config", []byte("version: 1\n")), configkit.Options[map[string]any]{
|
||||||
|
Definition: configkit.Definition[map[string]any]{Version: &configkit.VersionRule{
|
||||||
|
Path: path,
|
||||||
|
Check: func(_ configkit.Version, validation *configkit.Validation) error {
|
||||||
|
validation.Warning(path, "builder warning")
|
||||||
|
validation.Error(path, "builder rejection")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
for _, fixture := range []struct {
|
||||||
|
name string
|
||||||
|
cause error
|
||||||
|
code string
|
||||||
|
warning string
|
||||||
|
status int
|
||||||
|
}{
|
||||||
|
{"malformed", malformed, "yaml.invalid", "", 2},
|
||||||
|
{"rejected", rejected, "version.error", "builder warning", 2},
|
||||||
|
{"application failure", errors.New("builder unavailable"), "", "", 1},
|
||||||
|
} {
|
||||||
|
if fixture.cause == nil {
|
||||||
|
t.Fatalf("%s fixture succeeded", fixture.name)
|
||||||
|
}
|
||||||
|
for _, args := range [][]string{
|
||||||
|
{"promptkit", "requirements", "validate", "example"},
|
||||||
|
{"promptkit", "show", "prepared", "example"},
|
||||||
|
{"promptkit", "test", "reachability"},
|
||||||
|
{"promptkit", "test", "all"},
|
||||||
|
} {
|
||||||
|
for _, canceled := range []bool{false, true} {
|
||||||
|
name := fmt.Sprintf("%s/%s/canceled=%t", fixture.name, strings.Join(args, "_"), canceled)
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
loaderCalls, builderCalls := 0, 0
|
||||||
|
load := func(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) {
|
||||||
|
loaderCalls++
|
||||||
|
return nil, errors.New("unexpected engine load")
|
||||||
|
}
|
||||||
|
wrapped := fmt.Errorf("builder load: %w", fixture.cause)
|
||||||
|
buildError := func() error {
|
||||||
|
builderCalls++
|
||||||
|
if canceled {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
return wrapped
|
||||||
|
}
|
||||||
|
suite := WithRequestValidation(Suite[struct{}, struct{}]{}, load, func(context.Context, ValidationRequest, struct{}, struct{}) (promptkit.RunRequest, error) {
|
||||||
|
return promptkit.RunRequest{}, buildError()
|
||||||
|
})
|
||||||
|
suite = WithRequestPreparation(suite, load, func(context.Context, PreparationRequest, struct{}, struct{}) (promptkit.RunRequest, error) {
|
||||||
|
return promptkit.RunRequest{}, buildError()
|
||||||
|
})
|
||||||
|
suite = WithSmokeTesting(suite, load, func(context.Context, SmokeRequest, struct{}, struct{}) (promptkit.SmokeTestRequest, error) {
|
||||||
|
return promptkit.SmokeTestRequest{}, buildError()
|
||||||
|
})
|
||||||
|
app := newPromptTestApp(t, Command(suite))
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
result := app.Execute(ctx, append(append([]string{}, args...), "--verbose"), commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
wantStatus, wantCalls := fixture.status, 1
|
||||||
|
if args[len(args)-1] == "all" && !canceled {
|
||||||
|
wantCalls = 4
|
||||||
|
}
|
||||||
|
if canceled {
|
||||||
|
wantStatus = 1
|
||||||
|
if !errors.Is(result.Cause, context.Canceled) {
|
||||||
|
t.Fatalf("lost cancellation: %#v", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if result.Status != wantStatus || !errors.Is(result.Cause, wrapped) || loaderCalls != 0 || builderCalls != wantCalls {
|
||||||
|
t.Fatalf("result=%#v loader calls=%d builder calls=%d", result, loaderCalls, builderCalls)
|
||||||
|
}
|
||||||
|
if fixture.code != "" {
|
||||||
|
var expected, retained *configkit.LoadError
|
||||||
|
if !errors.As(fixture.cause, &expected) || !errors.As(result.Cause, &retained) || retained != expected {
|
||||||
|
t.Fatalf("lost loading error: %#v", result)
|
||||||
|
}
|
||||||
|
if !strings.Contains(diagnostic.String(), fixture.code) || !strings.Contains(diagnostic.String(), "builder-config") || !strings.Contains(diagnostic.String(), fixture.warning) {
|
||||||
|
t.Fatalf("diagnostics: %q", diagnostic.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPromptConfigurationFailureCancellation(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("invalid", []byte("broken: [")))
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
calls := 0
|
||||||
|
suite := Suite[struct{}, struct{}]{InspectPrompt: func(context.Context, PromptRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.PromptInspection], error) {
|
||||||
|
calls++
|
||||||
|
cancel()
|
||||||
|
return commandkit.Acquired[*promptkit.PromptInspection]{}, loadErr
|
||||||
|
}}
|
||||||
|
app := newPromptTestApp(t, Command(suite))
|
||||||
|
var out bytes.Buffer
|
||||||
|
result := app.Execute(ctx, []string{"promptkit", "show", "prompt", "example"}, commandkit.Streams{Out: &out, Err: io.Discard})
|
||||||
|
if result.Status != 1 || !errors.Is(result.Cause, context.Canceled) || !errors.Is(result.Cause, loadErr) || out.Len() != 0 || calls != 1 {
|
||||||
|
t.Fatalf("outcome=%#v calls=%d output=%q", result, calls, out.String())
|
||||||
|
}
|
||||||
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
calls = 0
|
||||||
|
result = app.Execute(ctx, []string{"promptkit", "show", "prompt", "example"}, commandkit.Streams{Out: &out, Err: io.Discard})
|
||||||
|
if result.Status != 1 || !errors.Is(result.Cause, context.Canceled) || calls != 0 || out.Len() != 0 {
|
||||||
|
t.Fatalf("pre-canceled=%#v calls=%d", result, calls)
|
||||||
|
}
|
||||||
|
}
|
||||||
131
integrations/ckprompt/constructor_outcomes_test.go
Normal file
131
integrations/ckprompt/constructor_outcomes_test.go
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package ckprompt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/ckconfig"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
"go.maximumdirect.net/promptkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPromptConstructorConfigurationOutcomes(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
mainPath := filepath.Join(dir, "config.yml")
|
||||||
|
companionPath := filepath.Join(dir, "prompts.yml")
|
||||||
|
for path, data := range map[string]string{mainPath: "companion: prompts.yml\n", companionPath: "profiles: [\n"} {
|
||||||
|
if err := os.WriteFile(path, []byte(data), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
good := adapterEngine(t)
|
||||||
|
var constructorErr error
|
||||||
|
load := func(_ context.Context, selection ckconfig.Selection, _, _ struct{}) (*promptkit.Engine, error) {
|
||||||
|
if selection.Config.Value == "good" {
|
||||||
|
return good, nil
|
||||||
|
}
|
||||||
|
appConfig, err := configkit.Load[struct {
|
||||||
|
Companion string `yaml:"companion"`
|
||||||
|
}](configkit.File(selection.Config.Value))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
companion := filepath.Join(filepath.Dir(selection.Config.Value), appConfig.Config.Companion)
|
||||||
|
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: configkit.File(companion)}}}, promptkit.WithBundledOpenRouter(false))
|
||||||
|
constructorErr = err
|
||||||
|
return engine, err
|
||||||
|
}
|
||||||
|
app := newPromptTestApp(t, Command(FromEngine[struct{}, struct{}](load)), ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{Scopes: []ckconfig.Scope[struct{}, struct{}]{ConfigScope(load)}}))
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
report, side string
|
||||||
|
}{
|
||||||
|
{"catalog", []string{"promptkit", "list", "prompts", "--config", mainPath}, "", ""},
|
||||||
|
{"show", []string{"config", "show", "--scope=promptkit", "--config", mainPath}, "", ""},
|
||||||
|
{"sources", []string{"config", "sources", "--format=json", "--scope=promptkit", "--config", mainPath}, `"sources"`, ""},
|
||||||
|
{"validate", []string{"config", "validate", "--details", "--format=json", "--scope=promptkit", "--config", mainPath}, `"code": "yaml.invalid"`, ""},
|
||||||
|
{"explain", []string{"config", "explain", "--list", "--scope=promptkit", "--config", mainPath}, "", ""},
|
||||||
|
{"diff left", []string{"config", "diff", "--scope=promptkit", "--config", mainPath, "--against-config=good"}, "", "left"},
|
||||||
|
{"diff right", []string{"config", "diff", "--scope=promptkit", "--config=good", "--against-config", mainPath}, "", "right"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
constructorErr = nil
|
||||||
|
var out, diag bytes.Buffer
|
||||||
|
result := app.Execute(context.Background(), tc.args, commandkit.Streams{Out: &out, Err: &diag})
|
||||||
|
var actual, expected *configkit.LoadError
|
||||||
|
if constructorErr == nil || !errors.As(constructorErr, &expected) || !errors.As(result.Cause, &actual) || actual != expected || !errors.Is(result.Cause, constructorErr) || !errors.Is(result.Cause, promptkit.ErrInvalidConfig) || result.Kind != commandkit.OutcomeUsage || result.Status != 2 {
|
||||||
|
t.Fatalf("outcome=%#v constructor=%v diagnostic=%q", result, constructorErr, diag.String())
|
||||||
|
}
|
||||||
|
if !strings.Contains(diag.String(), "yaml.invalid") || !strings.Contains(diag.String(), "prompts.yml") || (tc.report != "" && !strings.Contains(out.String(), tc.report)) || (tc.side != "" && !strings.Contains(diag.String(), "("+tc.side+")")) {
|
||||||
|
t.Fatalf("output=%q diagnostics=%q", out.String(), diag.String())
|
||||||
|
}
|
||||||
|
if tc.name == "sources" && !strings.Contains(out.String(), "prompts.yml") {
|
||||||
|
t.Fatalf("source evidence missing companion: %q", out.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPromptConstructorFailurePrecedence(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
malformed := filepath.Join(dir, "prompts.yml")
|
||||||
|
if err := os.WriteFile(malformed, []byte("profiles: [\n"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, invalid := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: configkit.File(malformed)}}}, promptkit.WithBundledOpenRouter(false))
|
||||||
|
_, missing := promptkit.NewEngine(promptkit.Config{}, promptkit.WithBundledOpenRouter(false), promptkit.WithSchemaFile(filepath.Join(dir, "missing.json")))
|
||||||
|
if invalid == nil || missing == nil || !errors.Is(invalid, promptkit.ErrInvalidConfig) || !errors.Is(missing, promptkit.ErrInvalidConfig) || !errors.Is(missing, os.ErrNotExist) {
|
||||||
|
t.Fatalf("constructor fixtures invalid=%v missing=%v", invalid, missing)
|
||||||
|
}
|
||||||
|
operational := errors.New("independent failure")
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
cause error
|
||||||
|
extra error
|
||||||
|
canceled bool
|
||||||
|
}{
|
||||||
|
{"missing schema", missing, os.ErrNotExist, false},
|
||||||
|
{"joined operational", errors.Join(invalid, operational), operational, false},
|
||||||
|
{"joined cancellation", errors.Join(invalid, context.Canceled), context.Canceled, false},
|
||||||
|
{"already canceled", nil, context.Canceled, true},
|
||||||
|
} {
|
||||||
|
for _, args := range [][]string{{"promptkit", "list", "prompts"}, {"config", "show", "--scope=promptkit"}} {
|
||||||
|
t.Run(tc.name+"/"+strings.Join(args, "_"), func(t *testing.T) {
|
||||||
|
calls := 0
|
||||||
|
load := func(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) {
|
||||||
|
calls++
|
||||||
|
if tc.cause != nil {
|
||||||
|
return nil, tc.cause
|
||||||
|
}
|
||||||
|
return adapterEngine(t), nil
|
||||||
|
}
|
||||||
|
app := newPromptTestApp(t, Command(FromEngine[struct{}, struct{}](load)), ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{Scopes: []ckconfig.Scope[struct{}, struct{}]{ConfigScope(load)}}))
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
if tc.canceled {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
var out bytes.Buffer
|
||||||
|
result := app.Execute(ctx, args, commandkit.Streams{Out: &out})
|
||||||
|
if result.Kind != commandkit.OutcomeOperational || result.Status != 1 || !errors.Is(result.Cause, tc.extra) {
|
||||||
|
t.Fatalf("outcome=%#v output=%q", result, out.String())
|
||||||
|
}
|
||||||
|
if tc.canceled {
|
||||||
|
if calls != 0 || out.Len() != 0 {
|
||||||
|
t.Fatalf("calls=%d output=%q", calls, out.String())
|
||||||
|
}
|
||||||
|
} else if calls != 1 || !errors.Is(result.Cause, tc.cause) || !errors.Is(result.Cause, promptkit.ErrInvalidConfig) {
|
||||||
|
t.Fatalf("outcome=%#v calls=%d", result, calls)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,29 +2,29 @@
|
|||||||
|
|
||||||
## PromptKit
|
## PromptKit
|
||||||
|
|
||||||
Selected module: `go.maximumdirect.net/promptkit` at `v0.20.0`.
|
Selected module: `go.maximumdirect.net/promptkit` at `v0.23.1`.
|
||||||
|
|
||||||
Copyright (C) 2026 Eric Rakestraw
|
Copyright (C) 2026 Eric Rakestraw
|
||||||
|
|
||||||
SPDX-License-Identifier: LGPL-3.0-or-later
|
SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
License and notices: [LGPL v3.0](../../LICENSE) |
|
License and notices: [LGPL v3.0](../../LICENSE) |
|
||||||
[LICENSE](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf/LICENSE).
|
[LICENSE](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/LICENSE).
|
||||||
|
|
||||||
[Source](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/8ff9aa3efdc9f16b9d2729e0a29ea083eb3c3eaf).
|
[Source](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6).
|
||||||
|
|
||||||
## ConfigKit
|
## ConfigKit
|
||||||
|
|
||||||
Selected module: `go.maximumdirect.net/configkit` at `v1.1.0` (direct dependency).
|
Selected module: `go.maximumdirect.net/configkit` at `v1.2.0` (direct dependency).
|
||||||
|
|
||||||
Copyright (C) 2026 Eric Rakestraw
|
Copyright (C) 2026 Eric Rakestraw
|
||||||
|
|
||||||
SPDX-License-Identifier: LGPL-3.0-or-later
|
SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
License and notices: [LGPL v3.0](../../LICENSE) |
|
License and notices: [LGPL v3.0](../../LICENSE) |
|
||||||
[LICENSE](https://forge.maximumdirect.net/base-layer/configkit/src/commit/191015e289d7f2b91abb9fdd9c4f2f5cf75b4de9/LICENSE).
|
[LICENSE](https://forge.maximumdirect.net/base-layer/configkit/src/commit/c1c7e87f2cdf77a0cbf3327831ac05578e756b9e/LICENSE).
|
||||||
|
|
||||||
[Source](https://forge.maximumdirect.net/base-layer/configkit/src/commit/191015e289d7f2b91abb9fdd9c4f2f5cf75b4de9).
|
[Source](https://forge.maximumdirect.net/base-layer/configkit/src/commit/c1c7e87f2cdf77a0cbf3327831ac05578e756b9e).
|
||||||
|
|
||||||
## ReleaseKit
|
## ReleaseKit
|
||||||
|
|
||||||
|
|||||||
16
integrations/ckprompt/docs/releases/v0.6.0.md
Normal file
16
integrations/ckprompt/docs/releases/v0.6.0.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# CommandKit ckprompt v0.6.0
|
||||||
|
|
||||||
|
CommandKit ckprompt v0.6.0 selects CommandKit core and ckconfig v0.6.0.
|
||||||
|
Core adds shared debug input bindings and access to the selected reporting mode.
|
||||||
|
ConfigKit remains at v1.1.0 and PromptKit at v0.20.0.
|
||||||
|
|
||||||
|
## Compatibility and upgrade
|
||||||
|
|
||||||
|
Select `go.maximumdirect.net/ckprompt v0.6.0` with CommandKit core and ckconfig
|
||||||
|
v0.6.0. The consumer minimum remains Go 1.27.0. See the
|
||||||
|
[consumer guide](../../../../docs/consumers/guide.md#invocation-reporting)
|
||||||
|
for the new core reporting and debug input APIs.
|
||||||
|
|
||||||
|
[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.6.0/integrations/ckprompt/COPYRIGHT) |
|
||||||
|
[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.6.0/integrations/ckprompt/LICENSE) |
|
||||||
|
[ATTRIBUTION](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.6.0/integrations/ckprompt/docs/oss/attribution.md)
|
||||||
21
integrations/ckprompt/docs/releases/v0.7.0.md
Normal file
21
integrations/ckprompt/docs/releases/v0.7.0.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# CommandKit ckprompt v0.7.0
|
||||||
|
|
||||||
|
CommandKit ckprompt v0.7.0 adopts PromptKit v0.21.0 and ConfigKit v1.2.0.
|
||||||
|
Application-owned engine loaders can select main-relative companion imports
|
||||||
|
through PromptKit's existing configuration-source API. ckprompt exposes the
|
||||||
|
resulting engine through its inspection, request, and smoke-testing adapters.
|
||||||
|
[PromptKit v0.21.0 release notes](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.21.0/docs/releases/v0.21.0.md)
|
||||||
|
|
||||||
|
## Compatibility and upgrade
|
||||||
|
|
||||||
|
Pair `go.maximumdirect.net/ckprompt v0.7.0` with ckconfig v0.7.0 and CommandKit
|
||||||
|
core v0.6.0. The consumer minimum is Go 1.27.0.
|
||||||
|
|
||||||
|
Application loaders constructing ConfigKit `Input` or `LayeredOptions` must use
|
||||||
|
field-named struct literals to accommodate the fields added upstream. See the
|
||||||
|
[consumer guide](../../../../docs/consumers/guide.md#module-selection) for module
|
||||||
|
selection and loader guidance.
|
||||||
|
|
||||||
|
[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.7.0/integrations/ckprompt/COPYRIGHT) |
|
||||||
|
[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.7.0/integrations/ckprompt/LICENSE) |
|
||||||
|
[ATTRIBUTION](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.7.0/integrations/ckprompt/docs/oss/attribution.md)
|
||||||
25
integrations/ckprompt/docs/releases/v0.8.0.md
Normal file
25
integrations/ckprompt/docs/releases/v0.8.0.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# CommandKit ckprompt v0.8.0
|
||||||
|
|
||||||
|
CommandKit ckprompt v0.8.0 adopts ckconfig v0.8.0's shared configuration-error
|
||||||
|
classification across inspection, catalogs, requirements, request preparation,
|
||||||
|
and smoke testing. ConfigKit loading errors returned by application request
|
||||||
|
builders now provide their source context, warnings, and terminal diagnostics
|
||||||
|
through the same adaptation used for engine-loader failures.
|
||||||
|
|
||||||
|
## Compatibility and upgrade
|
||||||
|
|
||||||
|
Pair `go.maximumdirect.net/ckprompt v0.8.0` with ckconfig v0.8.0 and CommandKit
|
||||||
|
core v0.6.0. The selected upstream versions are ConfigKit v1.2.0 and PromptKit
|
||||||
|
v0.21.0. The consumer minimum is Go 1.27.0.
|
||||||
|
|
||||||
|
Identifiable invalid configuration input now selects status `2`, including
|
||||||
|
configuration errors returned by request builders. These failures previously
|
||||||
|
selected status `1`. Update scripts that interpret those statuses. Operational
|
||||||
|
failures, cancellation, and ambiguous or unknown failure evidence select status
|
||||||
|
`1`. In aggregate smoke testing, operational failures take precedence over input
|
||||||
|
failures. Typed causes and available reports are preserved through the shared
|
||||||
|
reporting lifecycle. See the [CLI contract](../../../../docs/cli.md#configuration-failure-classification).
|
||||||
|
|
||||||
|
[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.8.0/integrations/ckprompt/COPYRIGHT) |
|
||||||
|
[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.8.0/integrations/ckprompt/LICENSE) |
|
||||||
|
[ATTRIBUTION](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.8.0/integrations/ckprompt/docs/oss/attribution.md)
|
||||||
32
integrations/ckprompt/docs/releases/v0.9.0.md
Normal file
32
integrations/ckprompt/docs/releases/v0.9.0.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# CommandKit ckprompt v0.9.0
|
||||||
|
|
||||||
|
This candidate upgrades PromptKit from v0.21.0 to v0.23.1. PromptKit's
|
||||||
|
constructor now preserves configuration causes without treating its category
|
||||||
|
sentinel as a separate failure.
|
||||||
|
|
||||||
|
## Compatibility and upgrade
|
||||||
|
|
||||||
|
Malformed PromptKit companion YAML returned by engine construction now selects
|
||||||
|
status `2` instead of `1`. Update scripts that interpret this status. Available
|
||||||
|
source and validation reports, diagnostics, typed ConfigKit causes, and
|
||||||
|
`promptkit.ErrInvalidConfig` recognition are retained. Operational failures and
|
||||||
|
cancellation continue to select status `1`. See the [configuration failure
|
||||||
|
contract](../../../../docs/cli.md#configuration-failure-classification).
|
||||||
|
|
||||||
|
Pair ckprompt v0.9.0 with ckconfig v0.8.0 and CommandKit core v0.6.0. The
|
||||||
|
selected upstream versions are ConfigKit v1.2.0 and PromptKit v0.23.1; the Go
|
||||||
|
consumer minimum remains 1.27.0. Native request builders continue to pass the
|
||||||
|
whole PromptKit request, including additive fields, and prepared reports carry
|
||||||
|
upstream fields such as parent run identifiers. Applications own construction
|
||||||
|
of engines and requests. See the [consumer guide](../../../../docs/consumers/guide.md#promptkit-configuration-definitions-and-requirements)
|
||||||
|
and [upstream upgrade guidance](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/releases/v0.23.1.md#compatibility-and-upgrade).
|
||||||
|
|
||||||
|
PromptKit v0.22.0 and v0.23.0 added fields to exported request, prepared,
|
||||||
|
result, and observation structs. If your application constructs affected types
|
||||||
|
with positional literals, migrate those literals to keyed fields when upgrading
|
||||||
|
from v0.21.0. See [PromptKit v0.22.0 compatibility](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/releases/v0.22.0.md#efficiency-and-compatibility)
|
||||||
|
and [PromptKit v0.23.0 upgrade guidance](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/74066167942fcf6f70c112359995739ec9789fa6/docs/releases/v0.23.0.md#compatibility-and-upgrade).
|
||||||
|
|
||||||
|
[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.9.0/integrations/ckprompt/COPYRIGHT) |
|
||||||
|
[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.9.0/integrations/ckprompt/LICENSE) |
|
||||||
|
[ATTRIBUTION](https://forge.maximumdirect.net/base-layer/commandkit/src/tag/integrations/ckprompt/v0.9.0/integrations/ckprompt/docs/oss/attribution.md)
|
||||||
@@ -170,7 +170,7 @@ func TestComposedIndependentOverridesAndFailureEvidence(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outcome = app.Execute(context.Background(), []string{"config", "validate", "--scope", "app", "--campaign", "spring", "--limit=0", "--set", `/default_campaign="autumn"`}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
outcome = app.Execute(context.Background(), []string{"config", "validate", "--scope", "app", "--campaign", "spring", "--limit=0", "--set", `/default_campaign="autumn"`}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||||
if outcome.Kind != commandkit.OutcomeOperational || outcome.Cause == nil {
|
if outcome.Kind != commandkit.OutcomeUsage || outcome.Cause == nil {
|
||||||
t.Fatalf("overlapping native overrides: %#v", outcome)
|
t.Fatalf("overlapping native overrides: %#v", outcome)
|
||||||
}
|
}
|
||||||
loads := 0
|
loads := 0
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ module go.maximumdirect.net/ckprompt
|
|||||||
go 1.27.0
|
go 1.27.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
go.maximumdirect.net/ckconfig v0.5.0
|
go.maximumdirect.net/ckconfig v0.8.0
|
||||||
go.maximumdirect.net/commandkit v0.5.0
|
go.maximumdirect.net/commandkit v0.6.0
|
||||||
go.maximumdirect.net/configkit v1.1.0
|
go.maximumdirect.net/configkit v1.2.0
|
||||||
go.maximumdirect.net/promptkit v0.20.0
|
go.maximumdirect.net/promptkit v0.23.1
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6
|
go.yaml.in/yaml/v4 v4.0.0-rc.6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,28 @@ go.maximumdirect.net/ckconfig v0.4.0 h1:7MpI/jIy+3BZrVME5rhKQibh5U9IA3s97BUJ2EOG
|
|||||||
go.maximumdirect.net/ckconfig v0.4.0/go.mod h1:Mk6QOfHrFy00uE0/gw9h6/Y9LcdTShVEzM/oI/HGDns=
|
go.maximumdirect.net/ckconfig v0.4.0/go.mod h1:Mk6QOfHrFy00uE0/gw9h6/Y9LcdTShVEzM/oI/HGDns=
|
||||||
go.maximumdirect.net/ckconfig v0.5.0 h1:5YCPFySTFIFR+gzd0FjqkTPEVB7zkGa8kOEYh4aBvWc=
|
go.maximumdirect.net/ckconfig v0.5.0 h1:5YCPFySTFIFR+gzd0FjqkTPEVB7zkGa8kOEYh4aBvWc=
|
||||||
go.maximumdirect.net/ckconfig v0.5.0/go.mod h1:BONXRSQlHdJvYVw9mN6lMV4G4ldlV/5fRO9EEApA99s=
|
go.maximumdirect.net/ckconfig v0.5.0/go.mod h1:BONXRSQlHdJvYVw9mN6lMV4G4ldlV/5fRO9EEApA99s=
|
||||||
|
go.maximumdirect.net/ckconfig v0.6.0 h1:N7MJKJiXhv+tT4HA7dnINUxC0Uq8hzYmBTFjrpvkbvQ=
|
||||||
|
go.maximumdirect.net/ckconfig v0.6.0/go.mod h1:69HOkR2Jbq7rJz3jlFAL6Oo5qorEiVrxQVLXoqav98s=
|
||||||
|
go.maximumdirect.net/ckconfig v0.7.0 h1:jRmKqgReLYIRHJl7Pr4+TlucifFirGANcsoC+5WrW7A=
|
||||||
|
go.maximumdirect.net/ckconfig v0.7.0/go.mod h1:ZBKCi0Z72+C6kQV+1HJHXFGcZTc11FYyaH1pQDSZFl8=
|
||||||
|
go.maximumdirect.net/ckconfig v0.8.0 h1:ZhHlj2jGv2qXfbUJH/IwuSok/2hhopJEDqZ2fTJMbNU=
|
||||||
|
go.maximumdirect.net/ckconfig v0.8.0/go.mod h1:ZBKCi0Z72+C6kQV+1HJHXFGcZTc11FYyaH1pQDSZFl8=
|
||||||
go.maximumdirect.net/commandkit v0.4.0 h1:bWqflDWDn98FUCgh+0e+w6LGmvWIkaeJK519H7PjD2Y=
|
go.maximumdirect.net/commandkit v0.4.0 h1:bWqflDWDn98FUCgh+0e+w6LGmvWIkaeJK519H7PjD2Y=
|
||||||
go.maximumdirect.net/commandkit v0.4.0/go.mod h1:ZS98DewKNVBygKVDoh5MFD09CnPlP37dS9pVsID5Eoc=
|
go.maximumdirect.net/commandkit v0.4.0/go.mod h1:ZS98DewKNVBygKVDoh5MFD09CnPlP37dS9pVsID5Eoc=
|
||||||
go.maximumdirect.net/commandkit v0.5.0 h1:Ln+bCp+FwCg4tZD3NaMKQXUDB3mPusgwsnRZmb0+3cM=
|
go.maximumdirect.net/commandkit v0.5.0 h1:Ln+bCp+FwCg4tZD3NaMKQXUDB3mPusgwsnRZmb0+3cM=
|
||||||
go.maximumdirect.net/commandkit v0.5.0/go.mod h1:ZS98DewKNVBygKVDoh5MFD09CnPlP37dS9pVsID5Eoc=
|
go.maximumdirect.net/commandkit v0.5.0/go.mod h1:ZS98DewKNVBygKVDoh5MFD09CnPlP37dS9pVsID5Eoc=
|
||||||
|
go.maximumdirect.net/commandkit v0.6.0 h1:4PHhMIlZuuvreIxZhUazeweg6zoYixEvhM9LJnkbGNA=
|
||||||
|
go.maximumdirect.net/commandkit v0.6.0/go.mod h1:ZS98DewKNVBygKVDoh5MFD09CnPlP37dS9pVsID5Eoc=
|
||||||
go.maximumdirect.net/configkit v1.1.0 h1:UzXN2ZMnEkcL0O4YSLqD9qd9M1gb/NWCHQR/H8AaQzA=
|
go.maximumdirect.net/configkit v1.1.0 h1:UzXN2ZMnEkcL0O4YSLqD9qd9M1gb/NWCHQR/H8AaQzA=
|
||||||
go.maximumdirect.net/configkit v1.1.0/go.mod h1:s1zLJ9GGB/1Q4a+aOHMLISonJxWFgNWpA6SpPlOafeA=
|
go.maximumdirect.net/configkit v1.1.0/go.mod h1:s1zLJ9GGB/1Q4a+aOHMLISonJxWFgNWpA6SpPlOafeA=
|
||||||
|
go.maximumdirect.net/configkit v1.2.0 h1:c4tDJ6Xeh/Jg90UZplLxsnf500lvrZBVj0E3i1ysir8=
|
||||||
|
go.maximumdirect.net/configkit v1.2.0/go.mod h1:s1zLJ9GGB/1Q4a+aOHMLISonJxWFgNWpA6SpPlOafeA=
|
||||||
go.maximumdirect.net/promptkit v0.20.0 h1:ZpwbjiCZWXdnnZ26RuWKoOco0jFnaAX8m2tQAX7ZlnM=
|
go.maximumdirect.net/promptkit v0.20.0 h1:ZpwbjiCZWXdnnZ26RuWKoOco0jFnaAX8m2tQAX7ZlnM=
|
||||||
go.maximumdirect.net/promptkit v0.20.0/go.mod h1:kCoyvI0xSax9K9aRPCEkpkyAP5YLs157oBLFLdzgRbM=
|
go.maximumdirect.net/promptkit v0.20.0/go.mod h1:kCoyvI0xSax9K9aRPCEkpkyAP5YLs157oBLFLdzgRbM=
|
||||||
|
go.maximumdirect.net/promptkit v0.21.0 h1:Ws4y28lnW+lIXAq4tGhXVFnQV/6AqkDChhg8knIZFrU=
|
||||||
|
go.maximumdirect.net/promptkit v0.21.0/go.mod h1:pi9acdCi80HWyzY+XYwRvMEoCiTcDWKyeBh3mzHdIFo=
|
||||||
|
go.maximumdirect.net/promptkit v0.23.1 h1:3EUB7p7ycDpWwumlsRU6ZwckvImH0BysuHPbBSGRvTA=
|
||||||
|
go.maximumdirect.net/promptkit v0.23.1/go.mod h1:pi9acdCi80HWyzY+XYwRvMEoCiTcDWKyeBh3mzHdIFo=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
|
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ func WithRequestPreparation[I, S any](
|
|||||||
if build != nil {
|
if build != nil {
|
||||||
built, err := build(ctx, request, input, state)
|
built, err := build(ctx, request, input, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return commandkit.Acquired[*promptkit.PreparedRun]{}, err
|
messages := promptKitLoadErrorDiagnostics(err, "")
|
||||||
|
return commandkit.Acquired[*promptkit.PreparedRun]{Diagnostics: messages.diagnostics, Explanation: messages.explanation}, err
|
||||||
}
|
}
|
||||||
concrete = built
|
concrete = built
|
||||||
}
|
}
|
||||||
@@ -82,26 +83,26 @@ func newPreparationCommand[I, S any](suite Suite[I, S], aliases *[]commandkit.De
|
|||||||
|
|
||||||
func runRequestPreparation[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *concreteRequestInput[I]) commandkit.Outcome {
|
func runRequestPreparation[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *concreteRequestInput[I]) commandkit.Outcome {
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit request preparation was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit request preparation was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
var state S
|
var state S
|
||||||
if suite.NewState != nil {
|
if suite.NewState != nil {
|
||||||
state = suite.NewState()
|
state = suite.NewState()
|
||||||
}
|
}
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit request preparation was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit request preparation was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
request := PreparationRequest{Selection: input.request.Selection, Request: input.request.Request, Namespaces: input.request.Namespaces}
|
request := PreparationRequest{Selection: input.request.Selection, Request: input.request.Request, Namespaces: input.request.Namespaces}
|
||||||
acquired, err := suite.PrepareRequest(invocation.Context, request, input.selected, state)
|
acquired, err := suite.PrepareRequest(invocation.Context, request, input.selected, state)
|
||||||
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Unable to prepare the PromptKit request for prompt %q.", input.promptID), acquired.Explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Unable to prepare the PromptKit request for prompt %q.", input.promptID), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Preparation of the PromptKit request for prompt %q was canceled.", input.promptID), acquired.Explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Preparation of the PromptKit request for prompt %q was canceled.", input.promptID), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if acquired.Value == nil {
|
if acquired.Value == nil {
|
||||||
return definitionFailure("PromptKit request preparation returned no result.", acquired.Explanation, nil)
|
return definitionFailure(invocation.Context, "PromptKit request preparation returned no result.", acquired.Explanation, nil)
|
||||||
}
|
}
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: acquired.Value})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: acquired.Value})
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func TestPreparationCommandForwardsOrderedInputsAndNativeReport(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), key{}, "context")
|
ctx := context.WithValue(context.Background(), key{}, "context")
|
||||||
var received PreparationRequest
|
var received PreparationRequest
|
||||||
calls := 0
|
calls := 0
|
||||||
native := &promptkit.PreparedRun{PromptID: "native", Messages: []promptkit.RenderedMessage{{Content: "rendered"}}}
|
native := &promptkit.PreparedRun{PromptID: "native", ParentRunID: "parent-run", Messages: []promptkit.RenderedMessage{{Content: "rendered"}}}
|
||||||
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{PrepareRequest: func(got context.Context, req PreparationRequest, _, _ struct{}) (commandkit.Acquired[*promptkit.PreparedRun], error) {
|
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{PrepareRequest: func(got context.Context, req PreparationRequest, _, _ struct{}) (commandkit.Acquired[*promptkit.PreparedRun], error) {
|
||||||
if got.Value(key{}) != "context" {
|
if got.Value(key{}) != "context" {
|
||||||
t.Fatal("invocation context lost")
|
t.Fatal("invocation context lost")
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ func WithSmokeTesting[I, S any](
|
|||||||
if build != nil {
|
if build != nil {
|
||||||
built, err := build(ctx, request, input, state)
|
built, err := build(ctx, request, input, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return commandkit.Acquired[*promptkit.SmokeTestReport]{}, err
|
messages := promptKitLoadErrorDiagnostics(err, "")
|
||||||
|
return commandkit.Acquired[*promptkit.SmokeTestReport]{Diagnostics: messages.diagnostics, Explanation: messages.explanation}, err
|
||||||
}
|
}
|
||||||
concreteRequest = built
|
concreteRequest = built
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,14 +91,14 @@ func newSmokeTestCommand[I, S any](suite Suite[I, S], aliases *[]commandkit.Decl
|
|||||||
|
|
||||||
func runSmokeTest[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *smokeCommandInput[I]) commandkit.Outcome {
|
func runSmokeTest[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *smokeCommandInput[I]) commandkit.Outcome {
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit smoke testing was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit smoke testing was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
var state S
|
var state S
|
||||||
if suite.NewState != nil {
|
if suite.NewState != nil {
|
||||||
state = suite.NewState()
|
state = suite.NewState()
|
||||||
}
|
}
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit smoke testing was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit smoke testing was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
if input.kind == "all" {
|
if input.kind == "all" {
|
||||||
return runSmokeAggregate(invocation, suite, input, state)
|
return runSmokeAggregate(invocation, suite, input, state)
|
||||||
@@ -118,12 +118,12 @@ func runSmokeTest[I, S any](invocation commandkit.Invocation, suite Suite[I, S],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if acquired.Value == nil {
|
if acquired.Value == nil {
|
||||||
return definitionFailure(smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
|
return definitionFailure(invocation.Context, smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeReportFromNative(acquired.Value)})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeReportFromNative(acquired.Value)})
|
||||||
if operationErr != nil {
|
if operationErr != nil {
|
||||||
return definitionFailure(smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
|
return definitionFailure(invocation.Context, smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
|
||||||
}
|
}
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ func runSmokeAggregate[I, S any](invocation commandkit.Invocation, suite Suite[I
|
|||||||
for _, kind := range kinds {
|
for _, kind := range kinds {
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
return definitionFailure("PromptKit aggregate smoke testing was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit aggregate smoke testing was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
operationErrors = append(operationErrors, err)
|
operationErrors = append(operationErrors, err)
|
||||||
break
|
break
|
||||||
@@ -182,11 +182,11 @@ func runSmokeAggregate[I, S any](invocation commandkit.Invocation, suite Suite[I
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
return definitionFailure("PromptKit aggregate smoke testing did not produce any results.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
|
return definitionFailure(invocation.Context, "PromptKit aggregate smoke testing did not produce any results.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
|
||||||
}
|
}
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeResultsReport(results)})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeResultsReport(results)})
|
||||||
if len(operationErrors) > 0 {
|
if len(operationErrors) > 0 {
|
||||||
return definitionFailure("One or more PromptKit smoke tests failed.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
|
return definitionFailure(invocation.Context, "One or more PromptKit smoke tests failed.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
|
||||||
}
|
}
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,23 +102,23 @@ func newValidationCommand[I, S any](suite Suite[I, S], aliases *[]commandkit.Dec
|
|||||||
|
|
||||||
func runRequestValidation[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *concreteRequestInput[I]) commandkit.Outcome {
|
func runRequestValidation[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *concreteRequestInput[I]) commandkit.Outcome {
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit request validation was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit request validation was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
var state S
|
var state S
|
||||||
if suite.NewState != nil {
|
if suite.NewState != nil {
|
||||||
state = suite.NewState()
|
state = suite.NewState()
|
||||||
}
|
}
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure("PromptKit request validation was canceled.", commandkit.Explanation{}, err)
|
return definitionFailure(invocation.Context, "PromptKit request validation was canceled.", commandkit.Explanation{}, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
acquired, err := suite.ValidateRequest(invocation.Context, input.request, input.selected, state)
|
acquired, err := suite.ValidateRequest(invocation.Context, input.request, input.selected, state)
|
||||||
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
queuePromptDiagnostics(invocation.Reporter(), acquired.Diagnostics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Unable to validate the PromptKit request for prompt %q.", input.promptID), acquired.Explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Unable to validate the PromptKit request for prompt %q.", input.promptID), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
if err := promptKitContextError(invocation.Context); err != nil {
|
if err := promptKitContextError(invocation.Context); err != nil {
|
||||||
return definitionFailure(fmt.Sprintf("Validation of the PromptKit request for prompt %q was canceled.", input.promptID), acquired.Explanation, err)
|
return definitionFailure(invocation.Context, fmt.Sprintf("Validation of the PromptKit request for prompt %q was canceled.", input.promptID), acquired.Explanation, err)
|
||||||
}
|
}
|
||||||
_ = invocation.Reporter().Report(commandkit.Report{Value: requestValidationReport{PromptID: input.promptID, Valid: true}})
|
_ = invocation.Reporter().Report(commandkit.Report{Value: requestValidationReport{PromptID: input.promptID, Valid: true}})
|
||||||
return commandkit.Success()
|
return commandkit.Success()
|
||||||
|
|||||||
@@ -409,7 +409,7 @@ func TestValidationCommandRetainsProviderDiagnosticsAndClassifiesFailures(t *tes
|
|||||||
}, nil)))
|
}, nil)))
|
||||||
outcome = loadApp.Execute(context.Background(), []string{"promptkit", "requirements", "validate", "briefing"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
outcome = loadApp.Execute(context.Background(), []string{"promptkit", "requirements", "validate", "briefing"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||||
var retained *configkit.LoadError
|
var retained *configkit.LoadError
|
||||||
if outcome.Kind != commandkit.OutcomeOperational || outcome.Status != 1 || !errors.Is(outcome.Cause, loadErr) || !errors.As(outcome.Cause, &retained) || retained != loadErr || outcome.Explanation.Message == "" && len(outcome.Explanation.Details) == 0 {
|
if outcome.Kind != commandkit.OutcomeUsage || outcome.Status != 2 || !errors.Is(outcome.Cause, loadErr) || !errors.As(outcome.Cause, &retained) || retained != loadErr || outcome.Explanation.Message == "" && len(outcome.Explanation.Details) == 0 {
|
||||||
t.Fatalf("loader failure = %#v, want retained ConfigKit error and diagnostics", outcome)
|
t.Fatalf("loader failure = %#v, want retained ConfigKit error and diagnostics", outcome)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user