From 96b4ca136a3e65b476e6f0bbce2a1b6cd800cfed Mon Sep 17 00:00:00 2001 From: Verlintas Date: Fri, 13 Nov 2026 01:46:00 +0800 Subject: [PATCH 1/4] fix(presets): resolve script artifacts through the CLI `specify preset resolve` looked at command and template artifacts only, so a preset that registers an executable artifact as `type: script` (e.g. a .mjs adapter) was reported as not found even though the resolver stack holds it. Keep the current precedence (commands for dotted names, templates otherwise) and fall back to the script type before reporting not found. The resolved path is the same top-layer path the command already prints for templates. Adds a regression test that registers a preset with a `type: script` entry and asserts the CLI resolves it; the test fails on main and passes with the change. --- src/specify_cli/presets/command_resolve.py | 13 ++++-- .../presets/test_command_resolve.py | 43 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/specify_cli/presets/command_resolve.py b/src/specify_cli/presets/command_resolve.py index 688b87398d..d726d3d581 100644 --- a/src/specify_cli/presets/command_resolve.py +++ b/src/specify_cli/presets/command_resolve.py @@ -15,10 +15,10 @@ @preset_app.command("resolve") def preset_resolve( template_name: str = typer.Argument( - ..., help="Template name to resolve (e.g., spec-template)" + ..., help="Artifact name to resolve (command, template, or script)" ), ): - """Show which template will be resolved for a given name.""" + """Show which command, template or script will be resolved for a given name.""" from .. import _require_specify_project from . import PresetResolver @@ -43,6 +43,13 @@ def preset_resolve( try: layers = resolver.collect_all_layers(template_name, template_type) + if not layers and not is_command: + # A preset may register an executable artifact as a script (e.g. a + # .mjs adapter). Commands and templates win first, so a shared name + # keeps its current meaning; scripts are the fallback. + layers = resolver.collect_all_layers(template_name, "script") + if layers: + template_type = "script" except PresetSectionValidationError as exc: typer.echo(f"Error: {exc}", err=True) raise typer.Exit(1) from exc @@ -125,5 +132,5 @@ def preset_resolve( else: console.print(f" [yellow]{safe_template_name}[/yellow]: not found") console.print( - " [dim]No template with this name exists in the resolution stack[/dim]" + " [dim]No command, template or script with this name exists in the resolution stack[/dim]" ) diff --git a/tests/specify_cli/presets/test_command_resolve.py b/tests/specify_cli/presets/test_command_resolve.py index b563618726..64773570d6 100644 --- a/tests/specify_cli/presets/test_command_resolve.py +++ b/tests/specify_cli/presets/test_command_resolve.py @@ -244,3 +244,46 @@ def test_resolve_renders_composition_strategy_labels(self, temp_dir, project_dir assert "Composition chain" in output, output assert "[base]" in output, output assert "[append]" in output, output + + def test_resolve_falls_back_to_script_artifacts(self, temp_dir, project_dir): + """A preset may register an executable artifact as a script. + + ``preset resolve`` used to look at commands and templates only, so a + ``type: script`` entry (e.g. a ``.mjs`` adapter) was reported as not + found even though the resolver stack holds it. + """ + src = temp_dir / "src-script-pack" + (src / "adapters").mkdir(parents=True) + (src / "adapters" / "page-adapter.mjs").write_text("export default {};\n") + (src / "preset.yml").write_text( + yaml.dump( + { + "schema_version": "1.0", + "preset": { + "id": "script-pack", + "name": "script-pack", + "version": "1.0.0", + "description": "script pack", + }, + "requires": {"speckit_version": ">=0.0.1"}, + "provides": { + "templates": [ + { + "type": "script", + "name": "page-adapter", + "file": "adapters/page-adapter.mjs", + "strategy": "replace", + } + ] + }, + } + ) + ) + PresetManager(project_dir).install_from_directory(src, "9.9.9", 10) + + result = self._invoke(project_dir, ["preset", "resolve", "page-adapter"]) + + assert result.exit_code == 0, (result.output, result.exception) + output = " ".join(strip_ansi(result.output).split()) + assert "page-adapter.mjs" in output, output + assert "not found" not in output From b254af10a33833ecc8595e1d53ec57da49d2cbd9 Mon Sep 17 00:00:00 2001 From: Verlintas Date: Fri, 13 Nov 2026 01:56:03 +0800 Subject: [PATCH 2/4] test(presets): pin template precedence over higher-priority scripts The script fallback must keep the backward-compatible lookup order: a template resolves even when a same-named script lives in a higher-priority preset. Covers the negative case requested in review. --- .../presets/test_command_resolve.py | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/specify_cli/presets/test_command_resolve.py b/tests/specify_cli/presets/test_command_resolve.py index 64773570d6..357fbbe0cb 100644 --- a/tests/specify_cli/presets/test_command_resolve.py +++ b/tests/specify_cli/presets/test_command_resolve.py @@ -287,3 +287,79 @@ def test_resolve_falls_back_to_script_artifacts(self, temp_dir, project_dir): output = " ".join(strip_ansi(result.output).split()) assert "page-adapter.mjs" in output, output assert "not found" not in output + + def test_resolve_prefers_template_over_higher_priority_script( + self, temp_dir, project_dir + ): + """A template wins over a same-named script from a higher-priority preset. + + The script fallback must not change the backward-compatible precedence: + commands and templates are still asked for first, so an existing + template keeps resolving even when a script with the same name sits in + a higher-priority preset. + """ + script_src = temp_dir / "src-script-pack" + (script_src / "adapters").mkdir(parents=True) + (script_src / "adapters" / "shared-asset.mjs").write_text("export default {};\n") + (script_src / "preset.yml").write_text( + yaml.dump( + { + "schema_version": "1.0", + "preset": { + "id": "script-pack", + "name": "script-pack", + "version": "1.0.0", + "description": "script pack", + }, + "requires": {"speckit_version": ">=0.0.1"}, + "provides": { + "templates": [ + { + "type": "script", + "name": "shared-asset", + "file": "adapters/shared-asset.mjs", + "strategy": "replace", + } + ] + }, + } + ) + ) + + template_src = temp_dir / "src-template-pack" + (template_src / "templates").mkdir(parents=True) + (template_src / "templates" / "shared-asset.md").write_text("# tmpl\n") + (template_src / "preset.yml").write_text( + yaml.dump( + { + "schema_version": "1.0", + "preset": { + "id": "template-pack", + "name": "template-pack", + "version": "1.0.0", + "description": "template pack", + }, + "requires": {"speckit_version": ">=0.0.1"}, + "provides": { + "templates": [ + { + "type": "template", + "name": "shared-asset", + "file": "templates/shared-asset.md", + "strategy": "replace", + } + ] + }, + } + ) + ) + + PresetManager(project_dir).install_from_directory(script_src, "9.9.9", 20) + PresetManager(project_dir).install_from_directory(template_src, "9.9.9", 5) + + result = self._invoke(project_dir, ["preset", "resolve", "shared-asset"]) + + assert result.exit_code == 0, (result.output, result.exception) + output = " ".join(strip_ansi(result.output).split()) + assert "shared-asset.md" in output, output + assert "shared-asset.mjs" not in output, output From 5ce394103ea607cdbf279030a667d661a5b1c74c Mon Sep 17 00:00:00 2001 From: Verlintas Date: Fri, 13 Nov 2026 07:48:16 +0800 Subject: [PATCH 3/4] test(presets): make the script outrank the template in the precedence test PresetRegistry.list_by_priority() sorts ascending, so the lower number is the higher priority. With the template at priority 5 it already outranked the script at 20, which meant the test passed even for a script-first implementation. Swap them: the script now has priority 5, the template 20. Verified the test fails against a script-first lookup and passes with the template-first order. --- tests/specify_cli/presets/test_command_resolve.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/specify_cli/presets/test_command_resolve.py b/tests/specify_cli/presets/test_command_resolve.py index 357fbbe0cb..6df6dada1a 100644 --- a/tests/specify_cli/presets/test_command_resolve.py +++ b/tests/specify_cli/presets/test_command_resolve.py @@ -354,8 +354,10 @@ def test_resolve_prefers_template_over_higher_priority_script( ) ) - PresetManager(project_dir).install_from_directory(script_src, "9.9.9", 20) - PresetManager(project_dir).install_from_directory(template_src, "9.9.9", 5) + # Lower numbers sort first in the registry, so the script preset (5) + # outranks the template preset (20); the template must still win. + PresetManager(project_dir).install_from_directory(script_src, "9.9.9", 5) + PresetManager(project_dir).install_from_directory(template_src, "9.9.9", 20) result = self._invoke(project_dir, ["preset", "resolve", "shared-asset"]) From a89a80d9bb5e42a984f680fc3e8165b43ce0d6bb Mon Sep 17 00:00:00 2001 From: Verlintas Date: Tue, 24 Nov 2026 23:41:10 +0800 Subject: [PATCH 4/4] test(presets): tolerate wrapped paths in resolve output --- tests/specify_cli/presets/test_command_resolve.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/specify_cli/presets/test_command_resolve.py b/tests/specify_cli/presets/test_command_resolve.py index 6df6dada1a..51e1dc6628 100644 --- a/tests/specify_cli/presets/test_command_resolve.py +++ b/tests/specify_cli/presets/test_command_resolve.py @@ -285,7 +285,9 @@ def test_resolve_falls_back_to_script_artifacts(self, temp_dir, project_dir): assert result.exit_code == 0, (result.output, result.exception) output = " ".join(strip_ansi(result.output).split()) - assert "page-adapter.mjs" in output, output + # Rich may line-wrap a long path, so remove all whitespace for path assertions. + path_output = "".join(output.split()) + assert "page-adapter.mjs" in path_output, output assert "not found" not in output def test_resolve_prefers_template_over_higher_priority_script( @@ -363,5 +365,7 @@ def test_resolve_prefers_template_over_higher_priority_script( assert result.exit_code == 0, (result.output, result.exception) output = " ".join(strip_ansi(result.output).split()) - assert "shared-asset.md" in output, output - assert "shared-asset.mjs" not in output, output + # Rich may line-wrap a long path, so remove all whitespace for path assertions. + path_output = "".join(output.split()) + assert "shared-asset.md" in path_output, output + assert "shared-asset.mjs" not in path_output, output