just icon indicating copy to clipboard operation
just copied to clipboard

Add namepath to assignments in JSON dump

Open bluefing opened this issue 7 months ago • 7 comments

Hi @casey

Please consider adding namepath to variables in the JSON dump. It exists for recipes but not for variables

I am currently walking the JSON output to reconstruct the namepath manually - it works but would be nice if it was in the dump.

Use case

I use this to test that in recipe body invocations of just are resolvable. Just invocations in a recipe need to use -f to avoid breaking if I am in a directory that has its own just file (e.g. invoking my personal justfile when in a project directory that has its own justfile)

I define just_call* variables

_mod := "docker::compose"
_just_call_pick_services := "just --justfile " + justfile() + "{{ _mod }}::_pick-services"

then in my tests apply two-step verification:

1. ``just --evaluate <module>::<var>`` resolves _just + _mod into a concrete command
2. Execute that command with JUST_DRY_RUN=true to prove the target recipe is reachable

bluefing avatar Apr 06 '26 10:04 bluefing

I'm not sure about this. I see the argument, but then the same thing applies to every other item in a module, and it would be quite noisy and redundant if paths were added to everything.

casey avatar Apr 08 '26 23:04 casey

Hi Casey, you make a very valid point.

Given this, the natural and logical conclusion is to add a module-level namepath attribute. This then can be used to easily derive the namepath for everything within.

If there are backward compatibility concerns, the recipe namepath could remain.

As it stands i have to build up the namepath as i walk the JSON dump.

bluefing avatar Apr 09 '26 08:04 bluefing

To provide a bit of context on my use case, module_path() solves some of my problems e.g. runtime problems but not all.

I am leveraging the just dump to derive a spec yaml (a snapshot of the entire just dependencies, arguments etc) and pytest-just to create a handful of generic tests that verify the specification and dump do not diverge.

The spec is not merely a reformated dump, it is restructured (group by common interface) and includes only the data used to validate.

As per above i am also testing recipe resolution, ensuring that as i refactor my just modules i know earlier if i broke something.

This is all working - it would just be nice if i didn't have to manually construct nanepaths as i traverse the tree.


Example portion of the spec derived from the dump used to drive the tests

Grouped by contract — recipes with identical properties (private, depends, params) share a single entry. Each group lists namepaths first, then contract keys alphabetically.


- namepaths:
  - docker::compose::down
  - docker::compose::restart
  - docker::compose::up
  depends:
  - _require-docker
  - _require-compose
  params:
    interactive:
      long: interactive
      short: i
      value: 'true'
    profile:
      long: profile
      short: p
    services: {}

bluefing avatar Apr 09 '26 08:04 bluefing

Would adding the module path to the justfile be helpful? Then you wouldn't have to reconstruct it manually, you would just look in the module containing the assignment for the module path.

casey avatar Apr 09 '26 19:04 casey

Apologies, I don't understand what you mean by

adding the module path to the justfile

I was thinking a module level attribute module.namepath, with the same value as module_path().

This would allow anyone consuming the dump to create a fully qualified reference to everything within the module, without having to derive the name path either by walking the tree from root concatenating module names with :: during the traversal, or splitting recipe namepath

bluefing avatar Apr 10 '26 08:04 bluefing

Sorry, that's what I meant. Internally, the struct which corresponds to modules is called Justfile. Fixed in #3288. The field was actually already present, it just needed to be exposed in JSON.

casey avatar Apr 11 '26 00:04 casey

thank you.

bluefing avatar Apr 11 '26 01:04 bluefing