diff --git a/spec/functional/FR-009-schema-subcommand.md b/spec/functional/FR-009-schema-subcommand.md index 988e4b0..6d41b6e 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,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 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/schema.rs b/src/commands/schema.rs index 06cf785..2842198 100644 --- a/src/commands/schema.rs +++ b/src/commands/schema.rs @@ -33,15 +33,28 @@ pub struct Args { #[implements("FR-009-AC-3")] #[implements("FR-009-AC-4")] #[implements("FR-009-AC-5")] +#[implements("FR-009-AC-6")] pub fn run(ctx: &Ctx, args: Args) -> 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/tests/cli_schema.rs b/tests/cli_schema.rs index feceffb..aa8f404 100644 --- a/tests/cli_schema.rs +++ b/tests/cli_schema.rs @@ -113,3 +113,93 @@ 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_064_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()), + ); +} + +// 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")); +}