From 990ba17f1ec88c6c03de8f260fbee58453d8a280 Mon Sep 17 00:00:00 2001 From: xv1rcn Date: Wed, 22 Jul 2026 14:03:50 +0800 Subject: [PATCH] fix: skip Form B packages in template name resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Form B packages (mcpp = { ... }) have no physical mcpp.toml or templates/ directory — their manifest is synthesized from the index descriptor. The template fetch path now detects this via extract_mcpp_field() and skips to the next namespace candidate. Refs #265 (hardening) --- src/scaffold/create.cppm | 6 ++++++ tests/e2e/69_package_templates.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/scaffold/create.cppm b/src/scaffold/create.cppm index f267d42a..4c359131 100644 --- a/src/scaffold/create.cppm +++ b/src/scaffold/create.cppm @@ -44,6 +44,12 @@ fetch_template_package(const mcpp::scaffold::TemplateSpec& spec) { std::optional lua; for (std::string cand : {std::string{}, std::string{"compat"}}) { if (auto l = fetcher.read_xpkg_lua(cand, spec.pkg)) { + // Form B packages (mcpp = { ... }) are build recipes without + // a source tree — no physical mcpp.toml or templates/. + auto field = mcpp::manifest::extract_mcpp_field(*l); + if (field.kind == mcpp::manifest::McppField::TableBody) { + continue; + } lua = std::move(*l); break; } diff --git a/tests/e2e/69_package_templates.sh b/tests/e2e/69_package_templates.sh index e1b15c8e..514ebc04 100755 --- a/tests/e2e/69_package_templates.sh +++ b/tests/e2e/69_package_templates.sh @@ -133,4 +133,31 @@ grep -qi "not found in the index" out5.log || { cat out5.log; echo "missing inde "$MCPP" new app6 --template gui > out6.log 2>&1 || { cat out6.log; echo "gui builtin broke"; exit 1; } grep -qi "deprecated" out6.log || { cat out6.log; echo "missing gui deprecation"; exit 1; } +# 7. Form B (mcpp = { ... }) compat package → skipped, "not found in the index". +mkdir -p "$MCPP_HOME/registry/data/mcpplibs/pkgs/c" +cat > "$MCPP_HOME/registry/data/mcpplibs/pkgs/c/compat.tpl-repro.lua" <<'EOF' +package = { + spec = "1", + namespace = "compat", + name = "compat.tpl-repro", + type = "package", + xpm = { + linux = { ["0.1.0"] = { url = "https://example.invalid/x.tar.gz", sha256 = "0" } }, + macosx = { ["0.1.0"] = { url = "https://example.invalid/x.tar.gz", sha256 = "0" } }, + windows = { ["0.1.0"] = { url = "https://example.invalid/x.tar.gz", sha256 = "0" } }, + }, + mcpp = { + language = "c++23", + include_dirs = {"*"}, + sources = {"*.cpp"}, + targets = { tpl_repro = { kind = "lib" } }, + }, +} +EOF +mkdir -p "$MCPP_HOME/registry/data/xpkgs/compat-x-compat.tpl-repro/0.1.0" +if "$MCPP" new app7 --template tpl-repro > out7.log 2>&1; then + cat out7.log; echo "L7: Form B template must fail"; exit 1 +fi +grep -qi "not found in the index" out7.log || { cat out7.log; echo "L7: wrong error for Form B skip"; exit 1; } + echo "OK"