diff --git a/.base/activate.sh b/.base/activate.sh index 7d9e854..44c789c 100755 --- a/.base/activate.sh +++ b/.base/activate.sh @@ -2,3 +2,5 @@ export BASE_DEMO_ENV="${BASE_DEMO_ENV:-baseline}" export BASE_DEMO_MESSAGE="${BASE_DEMO_MESSAGE:-Hello from base-demo activation.}" +export BASE_DEMO_ACTIVATED="${BASE_DEMO_ACTIVATED:-true}" +export BASE_DEMO_PROJECT_KIND="${BASE_DEMO_PROJECT_KIND:-reference-demo}" diff --git a/base_manifest.yaml b/base_manifest.yaml index 9600b21..49cd4cd 100644 --- a/base_manifest.yaml +++ b/base_manifest.yaml @@ -11,6 +11,8 @@ activate: commands: hello: ./src/hello.sh + env: ./src/env.sh + manifest: ./src/manifest.sh test: command: ./tests/validate.sh diff --git a/demo/demo.sh b/demo/demo.sh index fd71d85..9e6c4a6 100755 --- a/demo/demo.sh +++ b/demo/demo.sh @@ -121,6 +121,8 @@ project_shape_step() { run_command test -f "$BASE_DEMO_ROOT/base_manifest.yaml" run_command test -f "$BASE_DEMO_ROOT/Brewfile" run_command test -x "$BASE_DEMO_ROOT/src/hello.sh" + run_command test -x "$BASE_DEMO_ROOT/src/env.sh" + run_command test -x "$BASE_DEMO_ROOT/src/manifest.sh" run_command test -x "$BASE_DEMO_ROOT/tests/validate.sh" pause } @@ -129,6 +131,8 @@ manifest_step() { step 2 "Manifest Contracts" run_command grep -n "name: base-demo" "$BASE_DEMO_ROOT/base_manifest.yaml" run_command grep -n "hello: ./src/hello.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" + run_command grep -n "env: ./src/env.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" + run_command grep -n "manifest: ./src/manifest.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" run_command grep -n "command: ./tests/validate.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" run_command grep -n "script: ./demo/demo.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" pause @@ -139,7 +143,11 @@ activation_step() { # shellcheck source=/dev/null source "$BASE_DEMO_ROOT/.base/activate.sh" printf 'BASE_DEMO_ENV=%s\n' "${BASE_DEMO_ENV:-unset}" + printf 'BASE_DEMO_ACTIVATED=%s\n' "${BASE_DEMO_ACTIVATED:-unset}" + printf 'BASE_DEMO_PROJECT_KIND=%s\n' "${BASE_DEMO_PROJECT_KIND:-unset}" require_contains "activation" "${BASE_DEMO_ENV:-}" "baseline" + require_contains "activation" "${BASE_DEMO_ACTIVATED:-}" "true" + require_contains "activation" "${BASE_DEMO_PROJECT_KIND:-}" "reference-demo" pause } @@ -167,6 +175,8 @@ command_discovery_step() { output="$(capture_command "$BASE_DEMO_BASECTL" run "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" --list)" printf '%s\n' "$output" require_contains "run command list" "$output" "hello" + require_contains "run command list" "$output" "env" + require_contains "run command list" "$output" "manifest" pause } @@ -180,10 +190,26 @@ run_step() { pause } +inspection_step() { + local env_output manifest_output + + step 8 "Inspection Commands" + env_output="$(capture_command "$BASE_DEMO_BASECTL" run "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" env)" + printf '%s\n' "$env_output" + require_contains "env command" "$env_output" "BASE_PROJECT=base-demo" + require_contains "env command" "$env_output" "BASE_DEMO_PROJECT_KIND=reference-demo" + + manifest_output="$(capture_command "$BASE_DEMO_BASECTL" run "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" manifest)" + printf '%s\n' "$manifest_output" + require_contains "manifest command" "$manifest_output" "base-demo manifest" + require_contains "manifest command" "$manifest_output" "commands:" + pause +} + test_step() { local output - step 8 "Test Contract" + step 9 "Test Contract" output="$(capture_command "$BASE_DEMO_BASECTL" test "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE")" printf '%s\n' "$output" require_contains "test command" "$output" "Repository baseline is present." @@ -193,7 +219,7 @@ test_step() { demo_step() { local output - step 9 "Demo Contract" + step 10 "Demo Contract" output="$(capture_command "$BASE_DEMO_BASECTL" demo "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" --dry-run -- --non-interactive)" printf '%s\n' "$output" require_contains "demo command" "$output" "Would run demo" @@ -216,6 +242,7 @@ main() { activation_step command_discovery_step run_step + inspection_step test_step demo_step printf '\nbase-demo walkthrough complete.\n' diff --git a/src/env.sh b/src/env.sh new file mode 100755 index 0000000..8bf462a --- /dev/null +++ b/src/env.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +print_var() { + local name="$1" + printf '%s=%s\n' "$name" "${!name:-unset}" +} + +print_var BASE_PROJECT +print_var BASE_PROJECT_ROOT +print_var BASE_PROJECT_MANIFEST +print_var BASE_PROJECT_VENV_DIR +print_var BASE_DEMO_ENV +print_var BASE_DEMO_ACTIVATED +print_var BASE_DEMO_PROJECT_KIND diff --git a/src/manifest.sh b/src/manifest.sh new file mode 100755 index 0000000..dcacd1b --- /dev/null +++ b/src/manifest.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +manifest="${BASE_PROJECT_MANIFEST:-base_manifest.yaml}" + +printf 'base-demo manifest\n' +printf 'path=%s\n' "$manifest" +grep -nE '^(schema_version|brewfile|activate:|commands:|test:|demo:|artifacts:)' "$manifest" diff --git a/tests/demo_test.bats b/tests/demo_test.bats index 66a85c1..4c21e89 100755 --- a/tests/demo_test.bats +++ b/tests/demo_test.bats @@ -42,13 +42,23 @@ case "$*" in printf 'ok project base-demo is healthy.\n' ;; run\ base-demo\ --workspace\ *\ --list) - printf 'hello ./src/hello.sh\n' + printf 'hello ./src/hello.sh\n' + printf 'env ./src/env.sh\n' + printf 'manifest ./src/manifest.sh\n' ;; run\ base-demo\ --workspace\ *\ hello) printf 'hello from base-demo\n' printf 'BASE_PROJECT=base-demo\n' printf 'BASE_DEMO_ENV=%s\n' "${BASE_DEMO_ENV:-unset}" ;; + run\ base-demo\ --workspace\ *\ env) + printf 'BASE_PROJECT=base-demo\n' + printf 'BASE_DEMO_PROJECT_KIND=%s\n' "${BASE_DEMO_PROJECT_KIND:-unset}" + ;; + run\ base-demo\ --workspace\ *\ manifest) + printf 'base-demo manifest\n' + printf 'commands:\n' + ;; test\ base-demo\ --workspace\ *) printf 'Repository baseline is present.\n' ;; @@ -75,8 +85,11 @@ EOF [[ "$output" == *"Workspace Discovery"* ]] [[ "$output" == *"Project Diagnostics"* ]] [[ "$output" == *"Declared Commands"* ]] + [[ "$output" == *"Inspection Commands"* ]] [[ "$output" == *"BASE_DEMO_ENV=baseline"* ]] + [[ "$output" == *"BASE_DEMO_PROJECT_KIND=reference-demo"* ]] [[ "$output" == *"hello from base-demo"* ]] + [[ "$output" == *"base-demo manifest"* ]] [[ "$output" == *"Repository baseline is present."* ]] [[ "$output" == *"base-demo walkthrough complete."* ]] grep -Fq "basectl projects list --workspace " "$state_file" @@ -84,6 +97,8 @@ EOF grep -Fqx "basectl doctor base-demo" "$state_file" grep -Eq "^basectl run base-demo --workspace .+ --list$" "$state_file" grep -Eq "^basectl run base-demo --workspace .+ hello$" "$state_file" + grep -Eq "^basectl run base-demo --workspace .+ env$" "$state_file" + grep -Eq "^basectl run base-demo --workspace .+ manifest$" "$state_file" grep -Eq "^basectl test base-demo --workspace .+$" "$state_file" grep -Eq "^basectl demo base-demo --workspace .+ --dry-run -- --non-interactive$" "$state_file" } diff --git a/tests/validate.sh b/tests/validate.sh index 239b876..3f141bd 100755 --- a/tests/validate.sh +++ b/tests/validate.sh @@ -11,6 +11,8 @@ required_files=( Brewfile .base/activate.sh src/hello.sh + src/env.sh + src/manifest.sh demo/demo.sh tests/demo_test.bats .github/workflows/tests.yml @@ -23,7 +25,7 @@ for file in "${required_files[@]}"; do } done -for executable in tests/validate.sh .base/activate.sh src/hello.sh demo/demo.sh; do +for executable in tests/validate.sh .base/activate.sh src/hello.sh src/env.sh src/manifest.sh demo/demo.sh; do [[ -x "$executable" ]] || { printf 'Required file is not executable: %s\n' "$executable" >&2 exit 1 @@ -50,6 +52,16 @@ grep -Fq 'hello: ./src/hello.sh' base_manifest.yaml || { exit 1 } +grep -Fq 'env: ./src/env.sh' base_manifest.yaml || { + printf 'base_manifest.yaml does not declare the env command.\n' >&2 + exit 1 +} + +grep -Fq 'manifest: ./src/manifest.sh' base_manifest.yaml || { + printf 'base_manifest.yaml does not declare the manifest command.\n' >&2 + exit 1 +} + grep -Fq 'script: ./demo/demo.sh' base_manifest.yaml || { printf 'base_manifest.yaml does not declare the demo script.\n' >&2 exit 1