From 6bd578f1d20616e577f5c01b8e35b26b090ebd33 Mon Sep 17 00:00:00 2001 From: Peter Krenesky Date: Fri, 4 Dec 2026 10:23:29 -0800 Subject: [PATCH 1/3] spec: schema reports a rejected module manifest instead of UnknownArchetype Co-Authored-By: Claude Sonnet 5.5 --- spec/functional/FR-009-schema-subcommand.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/functional/FR-009-schema-subcommand.md b/spec/functional/FR-009-schema-subcommand.md index 988e4b0b..61c59a13 100644 --- a/spec/functional/FR-009-schema-subcommand.md +++ b/spec/functional/FR-009-schema-subcommand.md @@ -49,6 +49,7 @@ Unknown archetypes SHALL exit 3 with `UnknownArchetype` diagnostics on stderr. S | FR-009-AC-3 | `quire schema NONEXISTENT --module $ISO` exits 3 with `UnknownArchetype` on stderr and empty stdout | Test | | FR-009-AC-4 | Repeated `quire schema FR --module $ISO` calls produce byte-identical stdout | Test | | FR-009-AC-5 | The command performs module and path-safety checks equivalent to `validate` ([FR-005](./FR-005-path-safety.md)) | Test | +| FR-009-AC-6 | When the `--module` manifest is rejected at load (for example an unknown key in its `semantic:` block, or no archetype loaded), `quire schema ` exits 3 with stderr naming the module's `manifest.yaml` path and the load reason (such as the unknown `semantic` key); stderr does not report `UnknownArchetype`; stdout is empty | Test | ## Dependencies From 5c471fca695256b1eb5ba2ff7c08e88a338baddc Mon Sep 17 00:00:00 2001 From: Peter Krenesky Date: Fri, 4 Dec 2026 11:37:59 -0800 Subject: [PATCH 2/3] fix: name the load cause when a module's manifest is rejected schema and the other module-loading commands reported a bare UnknownArchetype when a module loaded with a rejected manifest. A shared check now fails with the recorded reason and manifest path. Co-Authored-By: Claude Sonnet 5.5 --- src/commands/mod.rs | 40 +++++++++++++++++++++++++++++---------- src/commands/validate.rs | 19 ++++--------------- tests/cli_schema.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 9be0cadb..2b6459af 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -67,6 +67,7 @@ use std::path::{Path, PathBuf}; use anyhow::Context; use ix_cli_kit::streams::Diagnostics; +use ix_trace_rs::implements; use quire_cli::io::emit_quire_diagnostics; use quire_rs::Registry; @@ -211,14 +212,37 @@ fn load_module_set_roots(ctx: &Ctx, roots: &[PathBuf]) -> anyhow::Result anyhow::Result<()> { + let nothing_loaded = + registry.module_names().count() == 0 || registry.archetype_names().count() == 0; + let failure = registry + .failures() + .iter() + .find(|failure| failure.reason.starts_with("semantic.")) + .or_else(|| { + nothing_loaded + .then(|| registry.failures().first()) + .flatten() + }); + if let Some(f) = failure { + invalid_request!("module load failed: {} ({})", f.reason, f.path.display()); + } + Ok(()) +} + #[derive(Debug)] struct ModuleSemanticMetadata { root: PathBuf, @@ -313,11 +337,7 @@ pub fn load_module_registry(ctx: &Ctx, module: &Path) -> anyhow::Result anyhow::Res load_scoped_with_defaults(ctx, scope)? }; - // A semantic-block refusal invalidates every archetype in its module, but - // the tolerant Registry still retains the module name. Surface that failure - // before validating documents, whose unknown types would otherwise obscure - // the module defect. - if let Some(failure) = registry - .failures() - .iter() - .find(|failure| failure.reason.starts_with("semantic.")) - { - invalid_request!( - "module load failed: {} ({})", - failure.reason, - failure.path.display() - ); - } + // A semantic-block refusal invalidates every archetype in its module but + // the tolerant Registry keeps the module name; scoped discovery loads + // without the shared refusal, so apply it here before documents are read. + super::refuse_unloadable_module(®istry)?; Ok(registry) } diff --git a/tests/cli_schema.rs b/tests/cli_schema.rs index feceffb3..d9a0e720 100644 --- a/tests/cli_schema.rs +++ b/tests/cli_schema.rs @@ -113,3 +113,44 @@ fn it_058_schema_module_path_safety() { .code(2) .stderr(predicate::str::contains("--module")); } + +// FR-009-AC-6: a module whose manifest is rejected at load (here a +// `semantic:` block with the `semantic_core` key, which the engine does not +// accept) makes `schema` name the manifest path and the cause, not a bare +// `UnknownArchetype`. +#[trace("FR-009-AC-6")] +#[test] +fn it_062_schema_reports_rejected_manifest_cause() { + let temp = tempfile::tempdir().expect("temp dir"); + let module = temp.path().join("module"); + let schemas = module.join("schemas"); + std::fs::create_dir_all(&schemas).expect("schema dir"); + let manifest = + std::fs::read_to_string(validate_module().join("manifest.yaml")).expect("fixture manifest"); + std::fs::write( + module.join("manifest.yaml"), + format!("{manifest} semantic_core: 0.3.3\n"), + ) + .expect("manifest with rejected semantic key"); + std::fs::copy( + validate_module().join("schemas/fr-frontmatter.schema.json"), + schemas.join("fr-frontmatter.schema.json"), + ) + .expect("frontmatter schema"); + + quire() + .arg("schema") + .arg("FR") + .arg("--module") + .arg(&module) + .assert() + .failure() + .code(3) + .stdout(predicate::str::is_empty()) + .stderr( + predicate::str::contains("module load failed") + .and(predicate::str::contains("semantic_core")) + .and(predicate::str::contains("manifest.yaml")) + .and(predicate::str::contains("UnknownArchetype").not()), + ); +} From ca837adc2fb30d537dfb1a089554a355f03d0ba1 Mon Sep 17 00:00:00 2001 From: Peter Krenesky Date: Fri, 4 Dec 2026 11:56:45 -0800 Subject: [PATCH 3/3] fix: report a rejected archetype's cause in schema only Narrow the change to the schema command: it reports the recorded load failure for the requested archetype, whether or not other archetypes load. Shared loaders and validate are unchanged. Co-Authored-By: Claude Sonnet 5.5 --- spec/functional/FR-009-schema-subcommand.md | 4 +- src/commands/mod.rs | 40 ++++------------ src/commands/schema.rs | 19 ++++++-- src/commands/validate.rs | 19 ++++++-- tests/cli_schema.rs | 51 ++++++++++++++++++++- 5 files changed, 93 insertions(+), 40 deletions(-) diff --git a/spec/functional/FR-009-schema-subcommand.md b/spec/functional/FR-009-schema-subcommand.md index 61c59a13..6d41b6e2 100644 --- a/spec/functional/FR-009-schema-subcommand.md +++ b/spec/functional/FR-009-schema-subcommand.md @@ -38,7 +38,7 @@ The command SHALL load the module registry, resolve ``, and write the `schema` SHALL NOT render an artifact and SHALL NOT write files. It is intended for LLM authoring agents and CI tools that need the same input contract quire will enforce. -Unknown archetypes SHALL exit 3 with `UnknownArchetype` diagnostics on stderr. Successful output SHALL follow the stream rules in [FR-006](./FR-006-io-contract.md). +Unknown archetypes SHALL exit 3 with `UnknownArchetype` diagnostics on stderr. An archetype the loader rejected SHALL instead exit 3 with the recorded load reason and path on stderr, naming the cause. Other commands' module-load behavior is unchanged by this requirement. Successful output SHALL follow the stream rules in [FR-006](./FR-006-io-contract.md). ## Acceptance Criteria @@ -49,7 +49,7 @@ Unknown archetypes SHALL exit 3 with `UnknownArchetype` diagnostics on stderr. S | FR-009-AC-3 | `quire schema NONEXISTENT --module $ISO` exits 3 with `UnknownArchetype` on stderr and empty stdout | Test | | FR-009-AC-4 | Repeated `quire schema FR --module $ISO` calls produce byte-identical stdout | Test | | FR-009-AC-5 | The command performs module and path-safety checks equivalent to `validate` ([FR-005](./FR-005-path-safety.md)) | Test | -| FR-009-AC-6 | When the `--module` manifest is rejected at load (for example an unknown key in its `semantic:` block, or no archetype loaded), `quire schema ` exits 3 with stderr naming the module's `manifest.yaml` path and the load reason (such as the unknown `semantic` key); stderr does not report `UnknownArchetype`; stdout is empty | Test | +| FR-009-AC-6 | When the requested archetype was rejected at load (its manifest declaration is refused, for example an unknown key in the `semantic:` block, or a `frontmatter_schema_ref` naming a missing file), `quire schema ` exits 3 with stderr `module load failed: ()`, not `UnknownArchetype`; this holds whether the module's other archetypes load or none do. An archetype absent from the module with no recorded load failure still reports `UnknownArchetype`. Stdout is empty | Test | ## Dependencies diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 2b6459af..9be0cadb 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -67,7 +67,6 @@ use std::path::{Path, PathBuf}; use anyhow::Context; use ix_cli_kit::streams::Diagnostics; -use ix_trace_rs::implements; use quire_cli::io::emit_quire_diagnostics; use quire_rs::Registry; @@ -212,35 +211,12 @@ fn load_module_set_roots(ctx: &Ctx, roots: &[PathBuf]) -> anyhow::Result anyhow::Result<()> { - let nothing_loaded = - registry.module_names().count() == 0 || registry.archetype_names().count() == 0; - let failure = registry - .failures() - .iter() - .find(|failure| failure.reason.starts_with("semantic.")) - .or_else(|| { - nothing_loaded - .then(|| registry.failures().first()) - .flatten() - }); - if let Some(f) = failure { - invalid_request!("module load failed: {} ({})", f.reason, f.path.display()); + if registry.module_names().count() == 0 { + if let Some(f) = registry.failures().first() { + invalid_request!("module load failed: {} ({})", f.reason, f.path.display()); + } } - Ok(()) + Ok(registry) } #[derive(Debug)] @@ -337,7 +313,11 @@ pub fn load_module_registry(ctx: &Ctx, module: &Path) -> anyhow::Result anyhow::Result<()> { let module = safety::validate_module_path(&args.module) .with_context(|| format!("validating --module '{}'", args.module))?; let registry = super::load_module_registry(ctx, &module)?; let contract = quire_rs::input_contract_for(®istry, &args.archetype).map_err(|e| { - // Surface `UnknownArchetype` (and any other contract error) on the - // error path; the leaf message carries the load-bearing identifier. - invalid_error!("{e}") + // An archetype the engine rejected at load is absent from the registry; + // report its recorded cause and manifest path rather than the bare + // `UnknownArchetype`. Any other contract error keeps its own message. + match registry + .failures() + .iter() + .find(|failure| failure.archetype == args.archetype) + { + Some(failure) => invalid_error!( + "module load failed: {} ({})", + failure.reason, + failure.path.display() + ), + None => invalid_error!("{e}"), + } })?; // `to_json()` produces deterministic, sorted-key JSON (FR-009-AC-4). diff --git a/src/commands/validate.rs b/src/commands/validate.rs index ef186922..d054b9ba 100644 --- a/src/commands/validate.rs +++ b/src/commands/validate.rs @@ -661,10 +661,21 @@ pub(crate) fn load_registry(ctx: &Ctx, args: &Args, scope: &Path) -> anyhow::Res load_scoped_with_defaults(ctx, scope)? }; - // A semantic-block refusal invalidates every archetype in its module but - // the tolerant Registry keeps the module name; scoped discovery loads - // without the shared refusal, so apply it here before documents are read. - super::refuse_unloadable_module(®istry)?; + // A semantic-block refusal invalidates every archetype in its module, but + // the tolerant Registry still retains the module name. Surface that failure + // before validating documents, whose unknown types would otherwise obscure + // the module defect. + if let Some(failure) = registry + .failures() + .iter() + .find(|failure| failure.reason.starts_with("semantic.")) + { + invalid_request!( + "module load failed: {} ({})", + failure.reason, + failure.path.display() + ); + } Ok(registry) } diff --git a/tests/cli_schema.rs b/tests/cli_schema.rs index d9a0e720..aa8f4048 100644 --- a/tests/cli_schema.rs +++ b/tests/cli_schema.rs @@ -120,7 +120,7 @@ fn it_058_schema_module_path_safety() { // `UnknownArchetype`. #[trace("FR-009-AC-6")] #[test] -fn it_062_schema_reports_rejected_manifest_cause() { +fn it_064_schema_reports_rejected_manifest_cause() { let temp = tempfile::tempdir().expect("temp dir"); let module = temp.path().join("module"); let schemas = module.join("schemas"); @@ -154,3 +154,52 @@ fn it_062_schema_reports_rejected_manifest_cause() { .and(predicate::str::contains("UnknownArchetype").not()), ); } + +// FR-009-AC-6: one archetype rejected at load (its frontmatter schema file is +// missing) while another loads: asking for the rejected one names the cause +// and the path, the loadable one still succeeds, and a name no one declared +// still reports `UnknownArchetype`. +#[trace("FR-009-AC-6")] +#[test] +fn it_065_schema_reports_one_rejected_archetype_among_loaded() { + let temp = tempfile::tempdir().expect("temp dir"); + let module = temp.path().join("module"); + let schemas = module.join("schemas"); + std::fs::create_dir_all(&schemas).expect("schema dir"); + let manifest = + std::fs::read_to_string(validate_module().join("manifest.yaml")).expect("fixture manifest"); + let bad = "- name: BAD\n frontmatter_schema_ref: schemas/missing.schema.json\n"; + let manifest = manifest.replacen("artifact_types:\n", &format!("artifact_types:\n{bad}"), 1); + assert!(manifest.contains("name: BAD"), "fixture edit applied"); + std::fs::write(module.join("manifest.yaml"), manifest).expect("manifest with BAD"); + std::fs::copy( + validate_module().join("schemas/fr-frontmatter.schema.json"), + schemas.join("fr-frontmatter.schema.json"), + ) + .expect("frontmatter schema"); + + quire() + .args(["schema", "BAD", "--module"]) + .arg(&module) + .assert() + .failure() + .code(3) + .stdout(predicate::str::is_empty()) + .stderr( + predicate::str::contains("module load failed") + .and(predicate::str::contains("missing.schema.json")) + .and(predicate::str::contains("UnknownArchetype").not()), + ); + quire() + .args(["schema", "FR", "--module"]) + .arg(&module) + .assert() + .success(); + quire() + .args(["schema", "NOPE", "--module"]) + .arg(&module) + .assert() + .failure() + .code(3) + .stderr(predicate::str::contains("UnknownArchetype")); +}