Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spec/functional/FR-009-schema-subcommand.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The command SHALL load the module registry, resolve `<ARCHETYPE>`, 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

Expand All @@ -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 <ARCHETYPE>` exits 3 with stderr `module load failed: <reason> (<manifest or file path>)`, 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

Expand Down
19 changes: 16 additions & 3 deletions src/commands/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&registry, &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).
Expand Down
90 changes: 90 additions & 0 deletions tests/cli_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}