#!/usr/bin/env bats setup() { REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../../../../../../" && pwd)" load "$REPO_ROOT/tests/test_helper/bats-support/load" load "$REPO_ROOT/tests/test_helper/bats-assert/load" SCRIPT="$(cd "$BATS_TEST_DIRNAME/../scripts" && pwd)/validate-provenance.sh" TMPDIR="$(mktemp -d)" # Helper: create an APM package root at (apm.yml with a top-level # type: line — a real package manifest, not marketplace-only) plus a # single vendor-neutral agent file at /.apm/agents/.agent.md. make_package() { local root="$1" mkdir -p "$root/.apm/agents" cat > "$root/apm.yml" < "$root/.apm/agents/${name}.agent.md" < "$root/.apm/agents/${name}.agent.md" < "$root/sources.md" < "$dir/.apm/agents/my-agent.agent.md" < "$dir/apm.yml" < "$dir/.apm/agents/my-agent.agent.md" < "$dir/plugin.json" cat > "$dir/agents/my-agent.md" < "$dir/apm.yml" < "$dir/sub/.apm/agents/my-agent.agent.md" < "$dir/apm.yml" < "$fake_home/.apm/agents/my-agent.agent.md" < "$dir/apm.yml" < "$dir/sub/.apm/agents/my-agent.agent.md" < "$root/sources.md" <> "$root/sources.md" run bash "$SCRIPT" "$root/.apm/agents/my-agent.agent.md" assert_success } # --------------------------------------------------------------------------- # Check 2: source_keys slug missing from sources.md → FAIL # --------------------------------------------------------------------------- @test "FAIL: source_keys slug in agent file not present as H2 in sources.md" { local root="$TMPDIR/package" make_package "$root" make_agent_with_source_keys "$root" "my-agent" "my-source" make_sources_md "$root" "different-source" "(none)" "(none)" run bash "$SCRIPT" "$root/.apm/agents/my-agent.agent.md" assert_failure assert_output --partial "FAIL" } # --------------------------------------------------------------------------- # Check 3: Contributing file path doesn't exist → FAIL # --------------------------------------------------------------------------- @test "FAIL: Contributing file listed in sources.md does not exist" { local root="$TMPDIR/package" make_package "$root" make_agent_with_source_keys "$root" make_sources_md "$root" "my-source" ".apm/agents/nonexistent.agent.md" run bash "$SCRIPT" "$root/.apm/agents/my-agent.agent.md" assert_failure assert_output --partial "FAIL" } @test "pass: (none) in Contributing files is skipped" { local root="$TMPDIR/package" make_package "$root" make_agent_with_source_keys "$root" make_sources_md "$root" "my-source" "(none — not used directly)" run bash "$SCRIPT" "$root/.apm/agents/my-agent.agent.md" assert_success } # --------------------------------------------------------------------------- # Check 5: Research doc field missing or placeholder → FAIL # --------------------------------------------------------------------------- @test "FAIL: Research doc field missing from sources.md entry" { local root="$TMPDIR/package" make_package "$root" make_agent_with_source_keys "$root" cat > "$root/sources.md" < "$root/sources.md" < "$root/.apm/agents/my-agent.agent.md" < "$root/sources.md" < "$root/sources.md" < "$root/sources.md" < "$root/sources.md" < "$root/sources.md" <