Files
devvm/testdata/script/layer.txtar
T
w3cjandClaude Opus 5.5 fe32d2a01c feat(cli): reserved command names, and did-you-mean for devvm WORD
A word after devvm that's neither a command nor an image (no +, and not
base, a shared tool or a layer) is a usage error, exit 2, suggesting the
closest command (Cobra's SuggestionsFor, distance 2) and the closest image
name. devvm help WORD and devvm WORD --help fail the same way instead of
printing the root's help. Layers can't take a word devvm keeps for its
commands.

- internal/image/reserved.go: Reserved (every command and subcommand
  name, hidden ones and help, and link, group, join, leave, publish,
  unpublish kept for later), IsReserved; LayerName refuses them, so
  Layers() and completion leave such files out.
- build.CheckLayerName refuses one (layer_name_command); CheckLayers
  refuses a layer file named with one wherever an image names it
  (layer_is_command, naming the file).
- internal/cli/word.go: checkWord (the root's Args), closest and
  levenshtein, addHelp (devvm's own help command, and a help func that
  panics with wordPanic for execute to recover), helpTarget, printUsage.
- Messages: layer_name_command, layer_is_command, no_command_or_image,
  no_command_or_image_command, no_command_or_image_image,
  no_command_or_image_both, with doc links.
- Tests: TestEveryCommandReserved, TestImagesNotReserved,
  TestLevenshtein, TestUnknownWord; layer.txtar and up_checks.txtar; e2e
  checks a mistyped command exits 2 with its suggestion.
- Docs: customizing (layer names), commands (devvm WORD), contributing,
  AGENTS.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-01 02:54:41 -08:00

79 lines
2.8 KiB
Plaintext

# devvm layer new NAME: a starter script and allowlist in the layers folder;
# bad, taken and existing names are refused.
env DEVVM_MESSAGES=names
env LAYERS=$XDG_CONFIG_HOME/devvm/layers
exec devvm layer new pg
stdout '^==> layer_created layer=pg policy=\S*/devvm/layers/pg\.policy script=\S*/devvm/layers/pg\.sh$'
exec bash -n $LAYERS/pg.sh
grep '^set -euo pipefail$' $LAYERS/pg.sh
grep '^# Hosts a VM with the pg layer can reach' $LAYERS/pg.policy
# It's a layer at once: images complete it, and it's among the environments.
exec devvm __complete build p
stdout '^pg$'
! exec devvm build nope
stderr '^devvm: unknown_layer agents=.* envs=base node python rust go docker nix pg layer=nope$'
# An existing script is kept; an existing allowlist is kept for a new script.
! exec devvm layer new pg
stderr '^devvm: layer_exists file=\S*/devvm/layers/pg\.sh$'
cp mine.policy $LAYERS/db.policy
exec devvm layer new db
cmp $LAYERS/db.policy mine.policy
! exec devvm layer new node
stderr '^devvm: layer_name_reserved layer=node$'
! exec devvm layer new claude
stderr '^devvm: layer_name_reserved layer=claude$'
! exec devvm layer new base
stderr '^devvm: layer_name_reserved layer=base$'
! exec devvm layer new docker
stderr '^devvm: layer_name_reserved layer=docker$'
! exists $LAYERS/docker.sh
! exec devvm layer new nix
stderr '^devvm: layer_name_reserved layer=nix$'
! exists $LAYERS/nix.sh
! exec devvm layer new stop
stderr '^devvm: layer_name_command layer=stop$'
! exec devvm layer new add
stderr '^devvm: layer_name_command layer=add$'
! exec devvm layer new link
stderr '^devvm: layer_name_command layer=link$'
! exists $LAYERS/stop.sh
! exec devvm layer new My_DB
stderr '^devvm: layer_name_invalid layer=My_DB$'
! exec devvm layer new ../x
stderr '^devvm: layer_name_invalid layer=\.\./x$'
! exec devvm layer new -- -x
stderr '^devvm: layer_name_invalid layer=-x$'
! exec devvm layer new
stderr '^devvm: arg_missing args=NAME command=devvm layer new$'
! exec devvm layer pg
stderr '^devvm: no_subcommand command=devvm layer commands=new given=pg$'
! exists $LAYERS/node.sh
! exists $LAYERS/My_DB.sh
# A layer file named with a word devvm keeps for its commands is refused
# wherever an image names it, and images don't complete it; devvm stop
# stays the command.
cp $LAYERS/pg.sh $LAYERS/log.sh
! exec devvm build log
stderr '^devvm: layer_is_command file=\S*/devvm/layers/log\.sh layer=log$'
! exec devvm build node+log
stderr '^devvm: layer_is_command file=\S*/devvm/layers/log\.sh layer=log$'
! exec devvm log
stderr '^devvm: layer_is_command file=\S*/devvm/layers/log\.sh layer=log$'
exec devvm __complete build l
! stdout '^log$'
rm $LAYERS/log.sh
# A layers folder that can't be written to fails it.
rm $LAYERS
exec sh -c 'printf x > "$LAYERS"'
! exec devvm layer new web
stderr '^devvm: layer_new_failed reason='
-- mine.policy --
db.example.com